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 })}
|
||||
/>
|
||||
|
||||
@@ -1585,6 +1585,9 @@
|
||||
"manageModels": "Manage models",
|
||||
"fallbackNotice": "This response used a fallback model: {{model}}.",
|
||||
"checkModelSettings": "Check model settings",
|
||||
"reauthNotice": "{{provider}} authorization expired. Please sign in again.",
|
||||
"reauthFallback": "A fallback model handled this response.",
|
||||
"reauthSettings": "Open sign-in settings",
|
||||
"context": {
|
||||
"tooltip": "Context {{percent}}%",
|
||||
"detailsLabel": "Open context usage",
|
||||
|
||||
@@ -1386,6 +1386,9 @@
|
||||
"manageModels": "Gestionar modelos",
|
||||
"fallbackNotice": "Esta respuesta usó un modelo alternativo: {{model}}.",
|
||||
"checkModelSettings": "Revisar ajustes del modelo",
|
||||
"reauthNotice": "La autorización de {{provider}} caducó. Vuelve a iniciar sesión.",
|
||||
"reauthFallback": "Un modelo alternativo respondió esta vez.",
|
||||
"reauthSettings": "Abrir ajustes de inicio de sesión",
|
||||
"context": {
|
||||
"tooltip": "Contexto {{percent}}%",
|
||||
"detailsLabel": "Abrir uso del contexto",
|
||||
|
||||
@@ -1385,6 +1385,9 @@
|
||||
"manageModels": "Gérer les modèles",
|
||||
"fallbackNotice": "Cette réponse a utilisé un modèle de secours : {{model}}.",
|
||||
"checkModelSettings": "Vérifier les paramètres du modèle",
|
||||
"reauthNotice": "L’autorisation de {{provider}} a expiré. Veuillez vous reconnecter.",
|
||||
"reauthFallback": "Un modèle de secours a traité cette réponse.",
|
||||
"reauthSettings": "Ouvrir les paramètres de connexion",
|
||||
"context": {
|
||||
"tooltip": "Contexte {{percent}} %",
|
||||
"detailsLabel": "Ouvrir l’utilisation du contexte",
|
||||
|
||||
@@ -1385,6 +1385,9 @@
|
||||
"manageModels": "Kelola model",
|
||||
"fallbackNotice": "Respons ini menggunakan model cadangan: {{model}}.",
|
||||
"checkModelSettings": "Periksa pengaturan model",
|
||||
"reauthNotice": "Otorisasi {{provider}} kedaluwarsa. Silakan masuk kembali.",
|
||||
"reauthFallback": "Model cadangan menangani respons ini.",
|
||||
"reauthSettings": "Buka pengaturan masuk",
|
||||
"context": {
|
||||
"tooltip": "Konteks {{percent}}%",
|
||||
"detailsLabel": "Buka penggunaan konteks",
|
||||
|
||||
@@ -1385,6 +1385,9 @@
|
||||
"manageModels": "モデルを管理",
|
||||
"fallbackNotice": "この応答では代替モデルを使用しました:{{model}}。",
|
||||
"checkModelSettings": "モデル設定を確認",
|
||||
"reauthNotice": "{{provider}} の認証が失効しました。再ログインしてください。",
|
||||
"reauthFallback": "今回の応答には代替モデルを使用しました。",
|
||||
"reauthSettings": "ログイン設定を開く",
|
||||
"context": {
|
||||
"tooltip": "コンテキスト {{percent}}%",
|
||||
"detailsLabel": "コンテキスト使用量を開く",
|
||||
|
||||
@@ -1385,6 +1385,9 @@
|
||||
"manageModels": "모델 관리",
|
||||
"fallbackNotice": "이 응답은 대체 모델을 사용했습니다: {{model}}.",
|
||||
"checkModelSettings": "모델 설정 확인",
|
||||
"reauthNotice": "{{provider}} 인증이 만료되었습니다. 다시 로그인해 주세요.",
|
||||
"reauthFallback": "이번 응답은 대체 모델이 처리했습니다.",
|
||||
"reauthSettings": "로그인 설정 열기",
|
||||
"context": {
|
||||
"tooltip": "컨텍스트 {{percent}}%",
|
||||
"detailsLabel": "컨텍스트 사용량 열기",
|
||||
|
||||
@@ -1399,6 +1399,9 @@
|
||||
"manageModels": "Gerenciar modelos",
|
||||
"fallbackNotice": "Esta resposta usou um modelo alternativo: {{model}}.",
|
||||
"checkModelSettings": "Verificar configurações do modelo",
|
||||
"reauthNotice": "A autorização de {{provider}} expirou. Entre novamente.",
|
||||
"reauthFallback": "Um modelo alternativo respondeu desta vez.",
|
||||
"reauthSettings": "Abrir configurações de login",
|
||||
"context": {
|
||||
"tooltip": "Contexto {{percent}}%",
|
||||
"detailsLabel": "Abrir uso do contexto",
|
||||
|
||||
@@ -1385,6 +1385,9 @@
|
||||
"manageModels": "Quản lý mô hình",
|
||||
"fallbackNotice": "Phản hồi này đã sử dụng mô hình dự phòng: {{model}}.",
|
||||
"checkModelSettings": "Kiểm tra cài đặt mô hình",
|
||||
"reauthNotice": "Quyền truy cập {{provider}} đã hết hạn. Vui lòng đăng nhập lại.",
|
||||
"reauthFallback": "Mô hình dự phòng đã xử lý phản hồi này.",
|
||||
"reauthSettings": "Mở cài đặt đăng nhập",
|
||||
"context": {
|
||||
"tooltip": "Ngữ cảnh {{percent}}%",
|
||||
"detailsLabel": "Mở mức sử dụng ngữ cảnh",
|
||||
|
||||
@@ -1584,6 +1584,9 @@
|
||||
"manageModels": "管理模型预设",
|
||||
"fallbackNotice": "本次已使用备用模型:{{model}}。",
|
||||
"checkModelSettings": "检查模型设置",
|
||||
"reauthNotice": "{{provider}} 授权已失效,请重新登录。",
|
||||
"reauthFallback": "本次已由备用模型继续回复。",
|
||||
"reauthSettings": "前往登录设置",
|
||||
"context": {
|
||||
"tooltip": "上下文 {{percent}}%",
|
||||
"detailsLabel": "打开上下文用量",
|
||||
|
||||
@@ -1385,6 +1385,9 @@
|
||||
"manageModels": "管理模型預設",
|
||||
"fallbackNotice": "本次已使用備用模型:{{model}}。",
|
||||
"checkModelSettings": "檢查模型設定",
|
||||
"reauthNotice": "{{provider}} 授權已失效,請重新登入。",
|
||||
"reauthFallback": "本次已由備用模型繼續回覆。",
|
||||
"reauthSettings": "前往登入設定",
|
||||
"context": {
|
||||
"tooltip": "上下文 {{percent}}%",
|
||||
"detailsLabel": "開啟上下文用量",
|
||||
|
||||
@@ -1455,6 +1455,7 @@ export type InboundEvent =
|
||||
model_name: string;
|
||||
model_preset?: string | null;
|
||||
fallback?: boolean;
|
||||
reauth_provider?: string;
|
||||
}
|
||||
| ({
|
||||
event: "turn_end";
|
||||
|
||||
@@ -17,6 +17,7 @@ describe("chat translation resources", () => {
|
||||
"chat.fallbackTitle", "chat.activity.running", "chat.rename", "chat.loading",
|
||||
"message.fallbackResponse",
|
||||
"thread.composer.fallbackNotice", "thread.composer.checkModelSettings",
|
||||
"thread.composer.reauthNotice", "thread.composer.reauthFallback", "thread.composer.reauthSettings",
|
||||
]) {
|
||||
expect(i18n.exists(key), key).toBe(true);
|
||||
expect(i18n.t(key), key).not.toBe(key);
|
||||
|
||||
@@ -1725,6 +1725,7 @@ describe("NanobotClient", () => {
|
||||
model_name: "deepseek/deepseek-chat",
|
||||
model_preset: "Deep Research",
|
||||
fallback: true,
|
||||
reauth_provider: "openai_codex",
|
||||
});
|
||||
|
||||
expect(chatHandler).toHaveBeenCalledWith({
|
||||
@@ -1733,6 +1734,7 @@ describe("NanobotClient", () => {
|
||||
model_name: "deepseek/deepseek-chat",
|
||||
model_preset: "Deep Research",
|
||||
fallback: true,
|
||||
reauth_provider: "openai_codex",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1227,6 +1227,35 @@ describe("ThreadShell", () => {
|
||||
expect(notice()).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("prioritizes the rejected provider's login over fallback details", async () => {
|
||||
const client = makeClient();
|
||||
const openSettings = vi.fn();
|
||||
render(wrap(client, <ThreadShell session={session("reauth")}
|
||||
title="Auth notice" onToggleSidebar={() => {}} onOpenModelSettings={openSettings}
|
||||
settingsSnapshot={modelSettings("openai-codex/gpt-5.5", "openai_codex")} />));
|
||||
await screen.findByTestId("composer-model-logo-openai_codex");
|
||||
const emit = (reauth_provider?: string) => act(() => client._emitChat("reauth", {
|
||||
event: "turn_model_updated", chat_id: "reauth", model_name: "xai-grok/grok-4.5",
|
||||
fallback: true, reauth_provider,
|
||||
}));
|
||||
emit();
|
||||
const generic = screen.getByText(/This response used a fallback model/).closest('[role="status"]')!;
|
||||
fireEvent.click(within(generic as HTMLElement).getByRole("button", { name: "Dismiss" }));
|
||||
emit("openai_codex");
|
||||
const title = screen.getByText("OpenAI Codex authorization expired. Please sign in again.");
|
||||
expect(title).toBeVisible();
|
||||
expect(screen.getByText("A fallback model handled this response.")).toBeVisible();
|
||||
expect(screen.queryByText(/This response used a fallback model/)).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Open sign-in settings" }));
|
||||
expect(openSettings).toHaveBeenCalledOnce();
|
||||
fireEvent.click(within(title.closest('[role="status"]') as HTMLElement).getByRole("button", { name: "Dismiss" }));
|
||||
emit("openai_codex");
|
||||
emit();
|
||||
expect(screen.queryByText(/authorization expired/)).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("composer-model-logo-openai_codex")).toBeInTheDocument();
|
||||
expect(client.sendSystemCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not show a live fallback notice just from replayed response attribution", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => Promise.resolve(
|
||||
String(input).includes("/webui-thread") ? httpJson({
|
||||
|
||||
Reference in new issue
Block a user