From f1c1d107caac38235f653699bb1078f678a77c2d Mon Sep 17 00:00:00 2001 From: Rene Fichtmueller Date: Thu, 2 Apr 2026 23:38:22 +0200 Subject: [PATCH] fix: map input to source_data fallback and spread context vars into template variables --- packages/gateway/src/routes/completion.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/gateway/src/routes/completion.ts b/packages/gateway/src/routes/completion.ts index ada9f10..dea4fdb 100644 --- a/packages/gateway/src/routes/completion.ts +++ b/packages/gateway/src/routes/completion.ts @@ -147,12 +147,18 @@ export async function completionRoute(fastify: FastifyInstance): Promise { // Stage 5: Prompt assembly // Use taskType directly for template lookup (so tip_transceiver_enrich.yaml is used, // not the generic_qa fallback from routing). The router only selects the model. + // Spread context fields so templates can reference {{source_data}}, {{source_url}}, etc. + // Fall back to input for {{source_data}} when not explicitly provided in context. + const contextVars = context + ? Object.fromEntries(Object.entries(context).map(([k, v]) => [k, v as string])) + : {}; const resolved = resolvePrompt( taskType ?? decision.prompt_template, { input, user_context: context, - source_data: context?.['source_data'] as string | undefined, + source_data: (context?.['source_data'] as string | undefined) ?? input, + ...contextVars, }, language ?? 'en', );