import type { TranslationKey } from "@/i18n"; type Translate = (key: TranslationKey, values?: Record) => string; const PROVIDER_OVERLOADED_RE = /^(.*?): provider is temporarily overloaded\. Please retry in a moment or switch models\.$/i; export function formatUserFacingError( message: string | null | undefined, t: Translate, modelDisplayName?: string | null ): string | null { if (!message) return null; const overloadedMatch = message.match(PROVIDER_OVERLOADED_RE); if (overloadedMatch) { return t("error.providerOverloaded", { model: modelDisplayName?.trim() || (overloadedMatch[1] ?? "Model").trim(), }); } return message; }