diff --git a/packages/gateway/src/routes/completion.ts b/packages/gateway/src/routes/completion.ts index dea4fdb..9563e91 100644 --- a/packages/gateway/src/routes/completion.ts +++ b/packages/gateway/src/routes/completion.ts @@ -147,18 +147,35 @@ 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. + // + // Variable resolution strategy: + // 1. Explicit context fields take priority (callers can pass structured data) + // 2. `input` is used as fallback for ALL common content variables so simple + // one-field callers work without knowing each template's specific var name. const contextVars = context ? Object.fromEntries(Object.entries(context).map(([k, v]) => [k, v as string])) : {}; + + // Common content variable names across all 59 templates — all default to `input` + const inputAliases: Record = { + source_data: input, ocr_text: input, transcription: input, + ticket_content: input, alert_data: input, incident_data: input, + lldp_data: input, cve_data: input, inventory: input, + anomaly_data: input, flagged_input: input, attack_description: input, + bgp_data: input, health_checks: input, market_data: input, + manuscript_text: input, raw_content: input, content: input, + // Additional structured vars with sensible fallbacks + peeringdb_data: input, bgp_routes: input, network_context: input, + alert_context: input, affected_inventory: input, + }; + const resolved = resolvePrompt( taskType ?? decision.prompt_template, { - input, + ...inputAliases, // low priority: input as fallback for all content vars + ...contextVars, // medium priority: explicit context fields override aliases + input, // always available as {{input}} user_context: context, - source_data: (context?.['source_data'] as string | undefined) ?? input, - ...contextVars, }, language ?? 'en', );