feat(prompts): inject palace wake-up context into Smart Actions
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.
This commit is contained in:
parent
06590b9175
commit
7d7e445135
@ -105,7 +105,7 @@ export async function notePromptRoutes(app: FastifyInstance): Promise<void> {
|
|||||||
|
|
||||||
const noteBody = note.body?.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim() ?? '';
|
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;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ export async function notePromptRoutes(app: FastifyInstance): Promise<void> {
|
|||||||
void reply.hijack();
|
void reply.hijack();
|
||||||
|
|
||||||
try {
|
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
|
// Stream the result as a series of SSE events: tokens then done
|
||||||
const chunks = result.content.match(/.{1,80}/g) ?? [result.content];
|
const chunks = result.content.match(/.{1,80}/g) ?? [result.content];
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
import { llm } from '../../lib/llm.js';
|
import { llm } from '../../lib/llm.js';
|
||||||
import { config } from '../../lib/config.js';
|
import { config } from '../../lib/config.js';
|
||||||
import { trackEvent } from '../../lib/telemetry.js';
|
import { trackEvent } from '../../lib/telemetry.js';
|
||||||
|
import { buildNoteLettWakeUp } from '../palace/wakeup.js';
|
||||||
|
import { PRODUCT_ID } from '../../lib/product-config.js';
|
||||||
import {
|
import {
|
||||||
buildVisionMessage,
|
buildVisionMessage,
|
||||||
hasVisionContent,
|
hasVisionContent,
|
||||||
@ -34,6 +36,7 @@ export async function executePrompt(
|
|||||||
template: PromptTemplateDoc,
|
template: PromptTemplateDoc,
|
||||||
input: RunPromptInput,
|
input: RunPromptInput,
|
||||||
noteBody: string,
|
noteBody: string,
|
||||||
|
userId?: string,
|
||||||
): Promise<RunPromptOutput> {
|
): Promise<RunPromptOutput> {
|
||||||
const provider = llm();
|
const provider = llm();
|
||||||
|
|
||||||
@ -52,9 +55,20 @@ export async function executePrompt(
|
|||||||
|
|
||||||
const userPrompt = interpolate(template.userPromptTemplate, vars);
|
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
|
// Build messages
|
||||||
const messages: ChatMessage[] = [
|
const messages: ChatMessage[] = [
|
||||||
{ role: 'system', content: template.systemPrompt },
|
{ role: 'system', content: systemPrompt },
|
||||||
];
|
];
|
||||||
|
|
||||||
if (input.imageUrl && (template.inputType === 'image' || template.inputType === 'text+image')) {
|
if (input.imageUrl && (template.inputType === 'image' || template.inputType === 'text+image')) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user