diff --git a/backend/src/modules/note-prompts/routes.ts b/backend/src/modules/note-prompts/routes.ts index f5ff99e..3e2eb71 100644 --- a/backend/src/modules/note-prompts/routes.ts +++ b/backend/src/modules/note-prompts/routes.ts @@ -105,7 +105,7 @@ export async function notePromptRoutes(app: FastifyInstance): Promise { const noteBody = note.body?.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim() ?? ''; - const result = await executePrompt(template, input, noteBody); + const result = await executePrompt(template, input, noteBody, userId); return result; }); @@ -148,7 +148,7 @@ export async function notePromptRoutes(app: FastifyInstance): Promise { void reply.hijack(); try { - const result = await executePrompt(template, input, noteBody); + const result = await executePrompt(template, input, noteBody, userId); // Stream the result as a series of SSE events: tokens then done const chunks = result.content.match(/.{1,80}/g) ?? [result.content]; for (const chunk of chunks) { diff --git a/backend/src/modules/note-prompts/runner.ts b/backend/src/modules/note-prompts/runner.ts index c2ed6ab..8c92387 100644 --- a/backend/src/modules/note-prompts/runner.ts +++ b/backend/src/modules/note-prompts/runner.ts @@ -5,6 +5,8 @@ import { llm } from '../../lib/llm.js'; import { config } from '../../lib/config.js'; import { trackEvent } from '../../lib/telemetry.js'; +import { buildNoteLettWakeUp } from '../palace/wakeup.js'; +import { PRODUCT_ID } from '../../lib/product-config.js'; import { buildVisionMessage, hasVisionContent, @@ -34,6 +36,7 @@ export async function executePrompt( template: PromptTemplateDoc, input: RunPromptInput, noteBody: string, + userId?: string, ): Promise { const provider = llm(); @@ -52,9 +55,20 @@ export async function executePrompt( const userPrompt = interpolate(template.userPromptTemplate, vars); + // Enrich system prompt with palace wake-up context (best-effort) + let systemPrompt = template.systemPrompt; + if (config.PALACE_ENABLED && input.workspaceId) { + try { + const wakeUp = await buildNoteLettWakeUp(userId ?? '', PRODUCT_ID, input.workspaceId); + if (wakeUp.text) { + systemPrompt += `\n\n## Workspace Context\n${wakeUp.text}`; + } + } catch { /* best-effort — don't block prompt execution */ } + } + // Build messages const messages: ChatMessage[] = [ - { role: 'system', content: template.systemPrompt }, + { role: 'system', content: systemPrompt }, ]; if (input.imageUrl && (template.inputType === 'image' || template.inputType === 'text+image')) {