fix(api): type-safe focusFactValue lookup

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-10-07 10:22:48 +00:00
parent 3a3e0b3e27
commit 90c24c1a56
No known key found for this signature in database

View File

@ -50,7 +50,7 @@ export interface FocusOption {
apps: string[]; apps: string[];
} }
const FOCUS_FACTS: Record<string, Record<FocusOption["id"], string>> = { const FOCUS_FACTS = {
en: { en: {
day: "Wants help with day-to-day work first", day: "Wants help with day-to-day work first",
inbox: "Wants help with inbox and email first", inbox: "Wants help with inbox and email first",
@ -63,14 +63,17 @@ const FOCUS_FACTS: Record<string, Record<FocusOption["id"], string>> = {
research: "Möchte zuerst bei Recherche und Schreiben unterstützt werden", research: "Möchte zuerst bei Recherche und Schreiben unterstützt werden",
crew: "Möchte eine koordinierte Crew aus Spezialisten-Bots", crew: "Möchte eine koordinierte Crew aus Spezialisten-Bots",
}, },
}; } as const satisfies Record<string, Record<FocusOption["id"], string>>;
/** Profile fact text for a focus answer, in the user's locale (defaults to English). */ /** Profile fact text for a focus answer, in the user's locale (defaults to English). */
function isFocusOptionId(id: string): id is FocusOption["id"] {
return FOCUS_OPTIONS.some((option) => option.id === id);
}
export function focusFactValue(focusId: string, locale: string): string { export function focusFactValue(focusId: string, locale: string): string {
const id = focusId as FocusOption["id"]; if (!isFocusOptionId(focusId)) return focusId;
const key = locale.toLowerCase().startsWith("de") ? "de" : "en"; const key = locale.toLowerCase().startsWith("de") ? "de" : "en";
const table = FOCUS_FACTS[key]; return FOCUS_FACTS[key][focusId] ?? FOCUS_FACTS.en[focusId];
return table[id] ?? FOCUS_FACTS.en[id] ?? focusId;
} }
export const FOCUS_OPTIONS: FocusOption[] = [ export const FOCUS_OPTIONS: FocusOption[] = [