fix(webui): notify chats when a fallback model responds
This commit is contained in:
1 parent
024fe8f636
commit
a05f11ba10
15 files changed
+161
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { ArrowRightLeft, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
/** A live fallback is informative, not a failed message or a changed preset. */
|
||||
export function ModelFallbackNotice({ model, onDismiss, onOpenSettings }: {
|
||||
model: string;
|
||||
onDismiss: () => void;
|
||||
onOpenSettings?: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-start gap-2 rounded-control border border-border/60 bg-muted/40 px-3 py-2 text-xs text-foreground/80 animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none"
|
||||
>
|
||||
<ArrowRightLeft className="mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-3 gap-y-1 leading-5">
|
||||
<span className="min-w-0 break-words [overflow-wrap:anywhere]">
|
||||
{t("thread.composer.fallbackNotice", {
|
||||
model,
|
||||
defaultValue: "This response used a fallback model: {{model}}.",
|
||||
})}
|
||||
</span>
|
||||
{onOpenSettings ? (
|
||||
<button type="button" onClick={onOpenSettings} className="shrink-0 rounded-sm font-medium text-foreground underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
{t("thread.composer.checkModelSettings", { defaultValue: "Check model settings" })}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 shrink-0 rounded-full"
|
||||
aria-label={t("common.dismiss")}
|
||||
onClick={onDismiss}
|
||||
>
|
||||
<X className="h-3.5 w-3.5" aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { FilePreviewAvailabilityProvider } from "@/components/FilePreviewAvailab
|
||||
import { FilePreviewPanel } from "@/components/FilePreviewPanel";
|
||||
import { SessionHandleLabel } from "@/components/SessionHandleLabel";
|
||||
import { PromptNavigator } from "@/components/thread/PromptNavigator";
|
||||
import { ModelFallbackNotice } from "@/components/thread/ModelFallbackNotice";
|
||||
import { RecoveryNotice } from "@/components/thread/RecoveryNotice";
|
||||
import { SessionInfoPopover } from "@/components/thread/SessionInfoPopover";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
@@ -690,6 +691,11 @@ export function ThreadShell({
|
||||
selectItems: installedMcpPresetsFromPayload,
|
||||
});
|
||||
const [settings, setSettings] = useState<SettingsPayload | null>(settingsSnapshot);
|
||||
const [modelFallback, setModelFallback] = useState<{
|
||||
chatId: string;
|
||||
model: string;
|
||||
dismissed: boolean;
|
||||
} | null>(null);
|
||||
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
|
||||
const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState<string | null>(null);
|
||||
const [filePreviewPath, setFilePreviewPath] = useState<string | null>(null);
|
||||
@@ -964,6 +970,25 @@ export function ThreadShell({
|
||||
|| settings?.agent.model_preset
|
||||
|| "default"
|
||||
);
|
||||
useEffect(() => {
|
||||
setModelFallback(null);
|
||||
if (!chatId) return;
|
||||
return client.onChat(chatId, (event) => {
|
||||
if (event.event !== "turn_model_updated") return;
|
||||
if (event.fallback !== true) {
|
||||
// The next turn starts with its configured model, not the previous fallback.
|
||||
setModelFallback(null);
|
||||
return;
|
||||
}
|
||||
const model = event.model_name.trim();
|
||||
if (!model) return;
|
||||
// A tool loop may report the same fallback repeatedly. Closing the notice
|
||||
// lasts until the next turn/model change, without changing the actual preset.
|
||||
setModelFallback((current) => current?.chatId === chatId && current.model === model
|
||||
? current
|
||||
: { chatId, model, dismissed: false });
|
||||
});
|
||||
}, [activeModelPreset, chatId, client]);
|
||||
const handleModelPresetChange = useCallback((name: string) => {
|
||||
setLocalModelPreset(name);
|
||||
if (chatId) {
|
||||
@@ -1521,6 +1546,13 @@ export function ThreadShell({
|
||||
|
||||
const composer = (
|
||||
<>
|
||||
{modelFallback?.chatId === chatId && !modelFallback.dismissed ? (
|
||||
<ModelFallbackNotice
|
||||
model={modelFallback.model}
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
onDismiss={() => setModelFallback((current) => current && { ...current, dismissed: true })}
|
||||
/>
|
||||
) : null}
|
||||
{recoveryState ? (
|
||||
<RecoveryNotice
|
||||
state={recoveryState}
|
||||
|
||||
Reference in new issue
Block a user