UI Stabilization: Global color theme updates (#75B2D6), AI Assistant styling refactor, and navigation fixes
This commit is contained in:
@@ -214,7 +214,7 @@ async function syncNoteLabels(noteId: string, labelNames: string[], notebookId:
|
||||
if (Array.isArray(parsed)) {
|
||||
parsed.filter((x: any) => typeof x === 'string').forEach((x: string) => namesInUse.add(x.toLowerCase()))
|
||||
}
|
||||
} catch {}
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
// Delete labels not in use
|
||||
@@ -680,91 +680,91 @@ export async function createNote(data: {
|
||||
const notebookId = data.notebookId
|
||||
const hasUserLabels = data.labels && data.labels.length > 0
|
||||
|
||||
// Use setImmediate-like pattern to not block the response
|
||||
;(async () => {
|
||||
try {
|
||||
// Background task 1: Generate embedding
|
||||
const bgConfig = await getSystemConfig()
|
||||
const provider = getAIProvider(bgConfig)
|
||||
const embedding = await provider.getEmbeddings(content)
|
||||
if (embedding) {
|
||||
await prisma.noteEmbedding.upsert({
|
||||
where: { noteId: noteId },
|
||||
create: { noteId: noteId, embedding: JSON.stringify(embedding) },
|
||||
update: { embedding: JSON.stringify(embedding) }
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[BG] Embedding generation failed:', e)
|
||||
}
|
||||
|
||||
// Background task 2: Auto-labeling (only if no user labels and has notebook)
|
||||
if (!hasUserLabels && notebookId) {
|
||||
// Use setImmediate-like pattern to not block the response
|
||||
; (async () => {
|
||||
try {
|
||||
const userAISettings = await getAISettings(userId)
|
||||
const autoLabelingEnabled = userAISettings.autoLabeling !== false
|
||||
const autoLabelingConfidence = await getConfigNumber('AUTO_LABELING_CONFIDENCE_THRESHOLD', 70)
|
||||
// Background task 1: Generate embedding
|
||||
const bgConfig = await getSystemConfig()
|
||||
const provider = getAIProvider(bgConfig)
|
||||
const embedding = await provider.getEmbeddings(content)
|
||||
if (embedding) {
|
||||
await prisma.noteEmbedding.upsert({
|
||||
where: { noteId: noteId },
|
||||
create: { noteId: noteId, embedding: JSON.stringify(embedding) },
|
||||
update: { embedding: JSON.stringify(embedding) }
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[BG] Embedding generation failed:', e)
|
||||
}
|
||||
|
||||
console.log('[BG] Auto-labeling check: enabled=', autoLabelingEnabled, 'confidence=', autoLabelingConfidence, 'notebookId=', notebookId)
|
||||
// Background task 2: Auto-labeling (only if no user labels and has notebook)
|
||||
if (!hasUserLabels && notebookId) {
|
||||
try {
|
||||
const userAISettings = await getAISettings(userId)
|
||||
const autoLabelingEnabled = userAISettings.autoLabeling !== false
|
||||
const autoLabelingConfidence = await getConfigNumber('AUTO_LABELING_CONFIDENCE_THRESHOLD', 70)
|
||||
|
||||
if (autoLabelingEnabled) {
|
||||
// Detect user's language from their existing notes for localized prompts
|
||||
let userLang = 'en'
|
||||
try {
|
||||
const langResult = await prisma.note.groupBy({
|
||||
by: ['language'],
|
||||
where: { userId, language: { not: null } },
|
||||
_count: true,
|
||||
orderBy: { _count: { language: 'desc' } },
|
||||
take: 1,
|
||||
})
|
||||
if (langResult.length > 0 && langResult[0].language) {
|
||||
userLang = langResult[0].language
|
||||
}
|
||||
} catch {}
|
||||
console.log('[BG] Auto-labeling check: enabled=', autoLabelingEnabled, 'confidence=', autoLabelingConfidence, 'notebookId=', notebookId)
|
||||
|
||||
const suggestions = await contextualAutoTagService.suggestLabels(
|
||||
content,
|
||||
notebookId,
|
||||
userId,
|
||||
userLang
|
||||
)
|
||||
if (autoLabelingEnabled) {
|
||||
// Detect user's language from their existing notes for localized prompts
|
||||
let userLang = 'en'
|
||||
try {
|
||||
const langResult = await prisma.note.groupBy({
|
||||
by: ['language'],
|
||||
where: { userId, language: { not: null } },
|
||||
_count: true,
|
||||
orderBy: { _count: { language: 'desc' } },
|
||||
take: 1,
|
||||
})
|
||||
if (langResult.length > 0 && langResult[0].language) {
|
||||
userLang = langResult[0].language
|
||||
}
|
||||
} catch { }
|
||||
|
||||
console.log('[BG] Auto-labeling suggestions:', suggestions.length, suggestions.map(s => s.label))
|
||||
const suggestions = await contextualAutoTagService.suggestLabels(
|
||||
content,
|
||||
notebookId,
|
||||
userId,
|
||||
userLang
|
||||
)
|
||||
|
||||
const appliedLabels = suggestions
|
||||
.filter(s => s.confidence >= autoLabelingConfidence)
|
||||
.map(s => s.label)
|
||||
console.log('[BG] Auto-labeling suggestions:', suggestions.length, suggestions.map(s => s.label))
|
||||
|
||||
if (appliedLabels.length > 0) {
|
||||
// Merge with existing labels
|
||||
const existing = await prisma.note.findUnique({
|
||||
where: { id: noteId },
|
||||
select: { labels: true },
|
||||
})
|
||||
let existingNames: string[] = []
|
||||
if (existing?.labels) {
|
||||
try {
|
||||
const parsed = existing.labels as unknown
|
||||
existingNames = Array.isArray(parsed)
|
||||
? parsed.filter((n): n is string => typeof n === 'string' && n.trim().length > 0)
|
||||
: []
|
||||
} catch { existingNames = [] }
|
||||
}
|
||||
const merged = [...new Set([...existingNames, ...appliedLabels])]
|
||||
await syncNoteLabels(noteId, merged, notebookId ?? null, userId)
|
||||
if (!data.skipRevalidation) {
|
||||
revalidatePath('/')
|
||||
const appliedLabels = suggestions
|
||||
.filter(s => s.confidence >= autoLabelingConfidence)
|
||||
.map(s => s.label)
|
||||
|
||||
if (appliedLabels.length > 0) {
|
||||
// Merge with existing labels
|
||||
const existing = await prisma.note.findUnique({
|
||||
where: { id: noteId },
|
||||
select: { labels: true },
|
||||
})
|
||||
let existingNames: string[] = []
|
||||
if (existing?.labels) {
|
||||
try {
|
||||
const parsed = existing.labels as unknown
|
||||
existingNames = Array.isArray(parsed)
|
||||
? parsed.filter((n): n is string => typeof n === 'string' && n.trim().length > 0)
|
||||
: []
|
||||
} catch { existingNames = [] }
|
||||
}
|
||||
const merged = [...new Set([...existingNames, ...appliedLabels])]
|
||||
await syncNoteLabels(noteId, merged, notebookId ?? null, userId)
|
||||
if (!data.skipRevalidation) {
|
||||
revalidatePath('/')
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[BG] Auto-labeling failed:', error)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[BG] Auto-labeling failed:', error)
|
||||
} else {
|
||||
console.log('[BG] Auto-labeling skipped: hasUserLabels=', hasUserLabels, 'notebookId=', notebookId)
|
||||
}
|
||||
} else {
|
||||
console.log('[BG] Auto-labeling skipped: hasUserLabels=', hasUserLabels, 'notebookId=', notebookId)
|
||||
}
|
||||
})()
|
||||
})()
|
||||
|
||||
return parseNote(note)
|
||||
} catch (error) {
|
||||
@@ -819,21 +819,21 @@ export async function updateNote(id: string, data: {
|
||||
if (data.content !== undefined) {
|
||||
const noteId = id
|
||||
const content = data.content
|
||||
;(async () => {
|
||||
try {
|
||||
const provider = getAIProvider(await getSystemConfig());
|
||||
const embedding = await provider.getEmbeddings(content);
|
||||
if (embedding) {
|
||||
await prisma.noteEmbedding.upsert({
|
||||
where: { noteId: noteId },
|
||||
create: { noteId: noteId, embedding: JSON.stringify(embedding) },
|
||||
update: { embedding: JSON.stringify(embedding) }
|
||||
})
|
||||
; (async () => {
|
||||
try {
|
||||
const provider = getAIProvider(await getSystemConfig());
|
||||
const embedding = await provider.getEmbeddings(content);
|
||||
if (embedding) {
|
||||
await prisma.noteEmbedding.upsert({
|
||||
where: { noteId: noteId },
|
||||
create: { noteId: noteId, embedding: JSON.stringify(embedding) },
|
||||
update: { embedding: JSON.stringify(embedding) }
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[BG] Embedding regeneration failed:', e);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[BG] Embedding regeneration failed:', e);
|
||||
}
|
||||
})()
|
||||
})()
|
||||
}
|
||||
|
||||
if ('checkItems' in data) updateData.checkItems = data.checkItems ? JSON.stringify(data.checkItems) : null
|
||||
|
||||
Reference in New Issue
Block a user