From f987efd9f339c82b8d0f7dcbb17a6e760e880767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 22 Oct 2026 15:19:33 +0200 Subject: [PATCH] refactor(insights): move the insights reply-language footers into their own module The per-locale footer table is prompt text, not prompt logic; it moves beside the generator, which drops back under its size baseline after pt-BR joined the table. --- src/lib/ai/prompts/insight-generator.ts | 21 ++++---------------- src/lib/ai/prompts/insights-reply-footers.ts | 21 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/lib/ai/prompts/insights-reply-footers.ts diff --git a/src/lib/ai/prompts/insight-generator.ts b/src/lib/ai/prompts/insight-generator.ts index 98fd20153..8b372f32e 100644 --- a/src/lib/ai/prompts/insight-generator.ts +++ b/src/lib/ai/prompts/insight-generator.ts @@ -48,6 +48,7 @@ import { formattingContract, } from "./shared-contracts"; import { userDayKey } from "@/lib/tz/format"; +import { INSIGHTS_LOCALE_REPLY_FOOTER_FALLBACK } from "./insights-reply-footers"; /** * Stable identifier for the active system prompt revision. @@ -982,23 +983,9 @@ const SYSTEM_PROMPT_DE = composeInsightPrompt("de"); * enum values stay in lowercase EN per the matrix's contract_enums * pin. DE keeps the hand-curated body (two-year calibration * reference). On any matrix-load failure the dispatcher falls back to - * the W9e EN-body-plus-footer path so the surface stays functional. - */ -const INSIGHTS_LOCALE_REPLY_FOOTER_FALLBACK: Record< - Exclude, - string -> = { - fr: "\n\nREPLY LANGUAGE: render all user-facing strings in French. Use natural French health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", - es: "\n\nREPLY LANGUAGE: render all user-facing strings in Spanish (peninsular preferred). Use natural Spanish health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", - it: "\n\nREPLY LANGUAGE: render all user-facing strings in Italian. Use natural Italian health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", - pl: "\n\nREPLY LANGUAGE: render all user-facing strings in Polish. Use natural Polish health vocabulary with formal Pan/Pani register for medical-adjacent topics. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", - nl: "\n\nREPLY LANGUAGE: render all user-facing strings in Dutch, in the informal je/jij register throughout (never formal u). Use natural Dutch health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", - ko: "\n\nREPLY LANGUAGE: render all user-facing strings in Korean, in the 해요체 register throughout (never 합쇼체 or plain 한다체). Use natural Korean health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", - "pt-BR": - "\n\nREPLY LANGUAGE: render all user-facing strings in Brazilian Portuguese (pt-BR, never European Portuguese), addressing the user as você throughout. Use natural Brazilian health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", -}; - -/** + * the W9e EN-body-plus-footer path so the surface stays functional. The + * footers live in `insights-reply-footers.ts`. + * * Returns the active scope-hardened system prompt for a given locale. * Consumed by the comprehensive generation path. */ diff --git a/src/lib/ai/prompts/insights-reply-footers.ts b/src/lib/ai/prompts/insights-reply-footers.ts new file mode 100644 index 000000000..ed33b9caa --- /dev/null +++ b/src/lib/ai/prompts/insights-reply-footers.ts @@ -0,0 +1,21 @@ +/** + * The reply-language footer the insights prompt appends for every locale + * outside German and English: the whole footer for the locales without a + * safety-contract matrix (ko, nl, pt-BR), and the fallback for the matrix + * locales when their native body cannot be built. Prompt text only. + */ +import type { Locale } from "@/lib/i18n/config"; + +export const INSIGHTS_LOCALE_REPLY_FOOTER_FALLBACK: Record< + Exclude, + string +> = { + fr: "\n\nREPLY LANGUAGE: render all user-facing strings in French. Use natural French health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", + es: "\n\nREPLY LANGUAGE: render all user-facing strings in Spanish (peninsular preferred). Use natural Spanish health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", + it: "\n\nREPLY LANGUAGE: render all user-facing strings in Italian. Use natural Italian health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", + pl: "\n\nREPLY LANGUAGE: render all user-facing strings in Polish. Use natural Polish health vocabulary with formal Pan/Pani register for medical-adjacent topics. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", + nl: "\n\nREPLY LANGUAGE: render all user-facing strings in Dutch, in the informal je/jij register throughout (never formal u). Use natural Dutch health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", + ko: "\n\nREPLY LANGUAGE: render all user-facing strings in Korean, in the 해요체 register throughout (never 합쇼체 or plain 한다체). Use natural Korean health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", + "pt-BR": + "\n\nREPLY LANGUAGE: render all user-facing strings in Brazilian Portuguese (pt-BR, never European Portuguese), addressing the user as você throughout. Use natural Brazilian health vocabulary. The severity / sourceWindow / sourceMetric / topic enum values stay in lowercase English exactly as listed in OUTPUT FORMAT — those are contract keys, NOT translations.", +};