From 7d7e445135c70398ed9a7c9480726d7a7778bede Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Mon, 13 Apr 2026 12:33:34 -0700 Subject: [PATCH] feat(prompts): inject palace wake-up context into Smart Actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enrich the system prompt with L0/L1/L2 workspace context from the palace when running Smart Actions. Best-effort — failures never block prompt execution. Gives LLM access to decisions, preferences, and semantically relevant memories from the workspace. --- backend/src/modules/note-prompts/routes.ts | 4 ++-- backend/src/modules/note-prompts/runner.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) 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')) {