mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 22:02:16 +00:00
fix(insights): stop sending German period narratives to fr/es/it/pl readers
The narrative read route narrowed every non-English locale to German, so a French, Spanish, Italian or Polish account read the German narrative row and warmed it from the German prompt body. Carry the resolved locale through instead: the row is keyed (user, period, locale) across the full UI locale union, and the four locales now compose the English instruction body with their language named and the locale's own reply-language directive appended last. The German and English prompts are unchanged apart from the version string. The nightly warm keeps the user's stored locale for the same reason — it has to write the key the read route reads — and the coach and dashboard narrative recalls read that same key. Coach memory stays de/en: it is model-facing context, not user-facing prose, so the four locales compose and key English rather than German. NARRATIVE_PROMPT_VERSION 1.13.0 -> 1.14.0.
This commit is contained in:
1 parent
2032b74fc6
commit
e4ec0eec49
10 files changed
+138
-42
No files matched your search
@@ -60,6 +60,7 @@ import {
|
||||
listConversations,
|
||||
} from "@/lib/ai/coach/persistence";
|
||||
import { enqueueCoachMemoryRefresh } from "@/lib/ai/coach/coach-memory-shared";
|
||||
import { instructionLocale } from "@/lib/ai/prompts/output-language";
|
||||
import { storeDeterministicFacts } from "@/lib/ai/coach/facts";
|
||||
import {
|
||||
buildDateKey,
|
||||
@@ -485,9 +486,12 @@ async function handleChatRequest(request: NextRequest): Promise<Response> {
|
||||
void enqueueCoachMemoryRefresh({
|
||||
conversationId: workingConversationId,
|
||||
userId,
|
||||
// Coach memory prose is composed in de/en only (the snapshot's
|
||||
// coachLocale); collapse the wider UI locale union here.
|
||||
locale: locale === "en" ? "en" : "de",
|
||||
// Coach memory prose is composed in de/en only — it is MODEL-FACING
|
||||
// context (a rolling conversation summary + extracted durable facts),
|
||||
// not user-facing prose, so English is the correct target for every
|
||||
// locale without a reviewed body. The former `=== "en" ? "en" : "de"`
|
||||
// binary composed and keyed a French account's memory in German.
|
||||
locale: instructionLocale(locale),
|
||||
});
|
||||
}
|
||||
// v1.19.1 (C4) — token efficiency. The full SNAPSHOT (now incl. labs,
|
||||
|
||||
@@ -17,6 +17,7 @@ import { apiSuccess, returnAllZodIssues } from "@/lib/api-response";
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { annotate } from "@/lib/logging/context";
|
||||
import { resolveServerLocale } from "@/lib/i18n/server-locale";
|
||||
import { locales, defaultLocale, type Locale } from "@/lib/i18n/config";
|
||||
import { requireAssistantSurface } from "@/lib/feature-flags";
|
||||
import { requireModuleEnabled } from "@/lib/modules/gate";
|
||||
import { readPeriodNarrative } from "@/lib/insights/narrative/period-narrative-generate";
|
||||
@@ -37,8 +38,17 @@ const narrativeQuerySchema = z.object({
|
||||
/** A narrative read this recently is considered fresh; no warm is enqueued. */
|
||||
const NARRATIVE_FRESH_MS = 20 * 60 * 60 * 1000;
|
||||
|
||||
function narrowLocale(locale: string): "de" | "en" {
|
||||
return locale === "en" ? "en" : "de";
|
||||
/**
|
||||
* The narrative row is keyed `(user, period, locale)` across the full UI
|
||||
* locale union, so the resolved locale is carried through as-is.
|
||||
*
|
||||
* This used to be `locale === "en" ? "en" : "de"` — which sent every French,
|
||||
* Spanish, Italian and Polish reader to the German narrative row and the
|
||||
* German prompt behind it. `resolveServerLocale` already returns a validated
|
||||
* `Locale`; an unknown value falls back to the app default (`en`) there.
|
||||
*/
|
||||
function narrowLocale(locale: Locale): Locale {
|
||||
return locales.includes(locale) ? locale : defaultLocale;
|
||||
}
|
||||
|
||||
export const GET = apiHandler(async (request: NextRequest) => {
|
||||
|
||||
Reference in new issue
Block a user