fix(webui): identify OAuth reauthentication behind fallback replies
This commit is contained in:
1 parent
a05f11ba10
commit
448767d147
28 files changed
+269
-40
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import { ArrowRightLeft, X } from "lucide-react";
|
||||
import { ArrowRightLeft, KeyRound, 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 }: {
|
||||
export function ModelFallbackNotice({ model, reauthProviderLabel, onDismiss, onOpenSettings }: {
|
||||
model: string;
|
||||
reauthProviderLabel?: string;
|
||||
onDismiss: () => void;
|
||||
onOpenSettings?: () => void;
|
||||
}) {
|
||||
@@ -15,17 +16,29 @@ export function ModelFallbackNotice({ model, onDismiss, onOpenSettings }: {
|
||||
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 />
|
||||
{reauthProviderLabel
|
||||
? <KeyRound className="mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
|
||||
: <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", {
|
||||
{reauthProviderLabel ? <>
|
||||
<span className="font-medium text-foreground">{t("thread.composer.reauthNotice", {
|
||||
provider: reauthProviderLabel,
|
||||
defaultValue: "{{provider}} authorization expired. Please sign in again.",
|
||||
})}</span>
|
||||
<span className="ml-1.5 text-muted-foreground">{t("thread.composer.reauthFallback", {
|
||||
defaultValue: "A fallback model handled this response.",
|
||||
})}</span>
|
||||
</> : 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" })}
|
||||
{reauthProviderLabel
|
||||
? t("thread.composer.reauthSettings", { defaultValue: "Open sign-in settings" })
|
||||
: t("thread.composer.checkModelSettings", { defaultValue: "Check model settings" })}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -57,6 +57,7 @@ import type {
|
||||
import { projectThreadEvents } from "@/lib/thread-event-projection";
|
||||
import { projectWebuiThreadMessages } from "@/lib/thread-display-projection";
|
||||
import { ThreadMessageCache } from "@/lib/thread-message-cache";
|
||||
import { providerDisplayLabel } from "@/lib/provider-brand";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useClient } from "@/providers/ClientProvider";
|
||||
|
||||
@@ -694,6 +695,7 @@ export function ThreadShell({
|
||||
const [modelFallback, setModelFallback] = useState<{
|
||||
chatId: string;
|
||||
model: string;
|
||||
reauthProvider?: string;
|
||||
dismissed: boolean;
|
||||
} | null>(null);
|
||||
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
|
||||
@@ -982,11 +984,19 @@ export function ThreadShell({
|
||||
}
|
||||
const model = event.model_name.trim();
|
||||
if (!model) return;
|
||||
const reauthProvider = typeof event.reauth_provider === "string"
|
||||
? event.reauth_provider.trim() || undefined : undefined;
|
||||
// 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 });
|
||||
setModelFallback((current) => {
|
||||
if (current?.chatId === chatId && current.model === model) {
|
||||
// An explicit auth rejection is actionable even after dismissing a
|
||||
// generic fallback. A circuit-skipped call must not erase that reason.
|
||||
return reauthProvider && reauthProvider !== current.reauthProvider
|
||||
? { ...current, reauthProvider, dismissed: false } : current;
|
||||
}
|
||||
return { chatId, model, reauthProvider, dismissed: false };
|
||||
});
|
||||
});
|
||||
}, [activeModelPreset, chatId, client]);
|
||||
const handleModelPresetChange = useCallback((name: string) => {
|
||||
@@ -1549,6 +1559,9 @@ export function ThreadShell({
|
||||
{modelFallback?.chatId === chatId && !modelFallback.dismissed ? (
|
||||
<ModelFallbackNotice
|
||||
model={modelFallback.model}
|
||||
reauthProviderLabel={modelFallback.reauthProvider
|
||||
? providerDisplayLabel(settings?.providers ?? [], modelFallback.reauthProvider)
|
||||
: undefined}
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
onDismiss={() => setModelFallback((current) => current && { ...current, dismissed: true })}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user