diff --git a/memento-note/lib/ai/services/agent-executor.service.ts b/memento-note/lib/ai/services/agent-executor.service.ts index c189ac3..3ff7814 100644 --- a/memento-note/lib/ai/services/agent-executor.service.ts +++ b/memento-note/lib/ai/services/agent-executor.service.ts @@ -1286,13 +1286,13 @@ async function executeToolUseAgent( if (specificNoteIds.length > 0) { notes = await prisma.note.findMany({ where: { id: { in: specificNoteIds }, userId: agent.userId, isArchived: false, trashedAt: null }, - select: { id: true, title: true, content: true, createdAt: true } + select: { id: true, title: true, content: true, createdAt: true, language: true } }) } else if (agent.sourceNotebookId) { notes = await prisma.note.findMany({ where: { notebookId: agent.sourceNotebookId, userId: agent.userId, isArchived: false, trashedAt: null }, orderBy: { createdAt: 'desc' }, take: 15, - select: { id: true, title: true, content: true, createdAt: true } + select: { id: true, title: true, content: true, createdAt: true, language: true } }) } else { const notebooks = await prisma.notebook.findMany({ @@ -1305,13 +1305,25 @@ async function executeToolUseAgent( notes = await prisma.note.findMany({ where: { notebookId: best.id, userId: agent.userId, isArchived: false, trashedAt: null }, orderBy: { createdAt: 'desc' }, take: 15, - select: { id: true, title: true, content: true, createdAt: true } + select: { id: true, title: true, content: true, createdAt: true, language: true } }) } } - prompt = lang === 'fr' - ? `Crée une présentation professionnelle sur le sujet "${slideTopic}" en utilisant le contenu des notes ci-dessous. Appelle generate_slides avec un objet JSON structuré (title, theme, slides[]).` - : `Create a professional presentation about "${slideTopic}" using the content from the notes below. Call generate_slides with a structured JSON object (title, theme, slides[]).` + + // Detect content language — use note's detected language, fallback to user lang + const noteLanguage = notes[0]?.language || null + // Map language codes to full names for the prompt + const LANG_NAMES: Record = { + fr: 'French', en: 'English', es: 'Spanish', de: 'German', it: 'Italian', + pt: 'Portuguese', nl: 'Dutch', pl: 'Polish', ru: 'Russian', zh: 'Chinese', + ja: 'Japanese', ko: 'Korean', ar: 'Arabic', fa: 'Persian (Farsi)', hi: 'Hindi', + } + const contentLang = noteLanguage && LANG_NAMES[noteLanguage] + ? LANG_NAMES[noteLanguage] + : (lang === 'fr' ? 'French' : 'English') + + prompt = `Create a professional presentation using the content from the notes below. Call generate_slides with a structured JSON object (title, theme, slides[]).` + prompt += `\n\n⚠️ LANGUAGE RULE: ALL slide text (titles, bullets, labels, subtitles) MUST be written in ${contentLang}. Do NOT translate to another language.` if (notes.length > 0) { const notesContext = notes.map(n =>