fix: map input to source_data fallback and spread context vars into template variables

This commit is contained in:
Rene Fichtmueller 2026-04-02 23:38:22 +02:00
parent 3bb9923255
commit f1c1d107ca

View File

@ -147,12 +147,18 @@ export async function completionRoute(fastify: FastifyInstance): Promise<void> {
// 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',
);