diff --git a/docs/providers.md b/docs/providers.md index ce64987a7..c972cfe25 100644 --- a/docs/providers.md +++ b/docs/providers.md @@ -5,12 +5,14 @@ Use this page when the first reply fails because of provider/model mismatch, or For normal local setup, open **Settings → Models** in the WebUI to add provider credentials, create a model preset, and select the active model. Use the JSON below for manual deployments, local endpoints, provider-specific fields, or diagnosis. The model picker fetches online catalogs for OpenAI Codex, xAI Grok, and GitHub -Copilot. If a refresh fails, it labels cached or built-in lists as potentially -out of date. An explicit authorization failure offers **Sign in again** using -the existing provider login flow; successful WebUI sign-in clears the catalog -cache. Network, rate-limit, and service failures instead ask you to try again -later (failed refreshes are cached briefly). Existing presets and manual model -IDs remain available. A successful chat may have used a fallback preset and +Copilot. An explicit authorization failure hides the picker’s search and model +list and offers **Sign in again** using the existing provider login flow. +Successful WebUI sign-in clears the catalog cache and restores model selection. +Existing presets, selected models, and unsaved preset details are preserved. +Network, rate-limit, and service failures instead keep cached or built-in lists +available, label them as potentially out of date, and ask you to try again later +(failed refreshes are cached briefly). Manual model IDs remain available for +these temporary failures. A successful chat may have used a fallback preset and does not prove that the selected provider's authorization is still valid. When a live chat uses a fallback model, a dismissible notice above the composer names that model and links to model settings. If the provider explicitly rejected diff --git a/webui/src/components/settings/shared/ModelControls.tsx b/webui/src/components/settings/shared/ModelControls.tsx index 9e102b168..a8d067524 100644 --- a/webui/src/components/settings/shared/ModelControls.tsx +++ b/webui/src/components/settings/shared/ModelControls.tsx @@ -187,6 +187,7 @@ export function ModelIdPicker({ const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const catalogNoticeId = useId(); + const catalogSignInRef = useRef(null); const effectiveProvider = provider === "auto" ? settings.agent.resolved_provider ?? provider : provider; const hasConcreteProvider = Boolean(effectiveProvider && effectiveProvider !== "auto"); @@ -233,20 +234,25 @@ export function ModelIdPicker({ const waitingForModelSearch = open && canFetchModels && defersModelList && !hasDeferredSearchQuery; const hasModelList = hasStaticModels || payload?.status === "available"; + const catalogNeedsSignIn = !hasStaticModels && payload?.error_kind === "auth_required"; const showModels = Boolean( - hasModelList && (hasStaticModels || (payload && (!isCatalog || normalizedQuery))), + !catalogNeedsSignIn && hasModelList + && (hasStaticModels || (payload && (!isCatalog || normalizedQuery))), ); const customCandidate = query.trim(); - const allowCustomModel = !providerRequiresConfiguration; + const allowCustomModel = !providerRequiresConfiguration && !catalogNeedsSignIn; const exactQueryMatch = providerModels.some((model) => model.id === customCandidate); const showCustomModel = Boolean( allowCustomModel && customCandidate && !exactQueryMatch && customCandidate !== value, ); const providerModelCount = payload?.model_count ?? providerModels.length; const modelUnconfigured = !value.trim() || !providerConfigured; - const showCatalogNotice = !loading && payload?.status === "available" - && (payload.source === "stale" || payload.source === "fallback"); - const catalogNeedsSignIn = payload?.error_kind === "auth_required"; + const showCatalogNotice = !loading && payload && (catalogNeedsSignIn + || (payload.status === "available" && (payload.source === "stale" || payload.source === "fallback"))); + + useEffect(() => { + if (open && catalogNeedsSignIn && !loading) catalogSignInRef.current?.focus(); + }, [open, catalogNeedsSignIn, loading]); useEffect(() => { if (!open) return; @@ -370,7 +376,7 @@ export function ModelIdPicker({ align="end" className="w-[var(--radix-popover-trigger-width)] max-w-[calc(100vw-2rem)] p-1.5" > -
+ {!catalogNeedsSignIn ?
-
+
: null} {showCatalogNotice ? ( -
-
-

- {catalogNeedsSignIn - ? tx("settings.models.catalogAuthRequired", "Authorization expired. Please sign in again.") - : tx("settings.models.catalogUnavailable", "Could not refresh models. Try again later.")} -

-

- {payload.source === "stale" - ? tx("settings.models.catalogStale", "Showing cached models; the list may be out of date.") - : tx("settings.models.catalogFallback", "Showing built-in models; the list may be out of date.")} -

+
+ {catalogNeedsSignIn ? : null} +
+
+

+ {catalogNeedsSignIn + ? tx("settings.models.catalogAuthRequired", "Authorization expired. Please sign in again.") + : tx("settings.models.catalogUnavailable", "Could not refresh models. Try again later.")} +

+ {!catalogNeedsSignIn ?

+ {payload.source === "stale" + ? tx("settings.models.catalogStale", "Showing cached models; the list may be out of date.") + : tx("settings.models.catalogFallback", "Showing built-in models; the list may be out of date.")} +

: null} +
+ {catalogNeedsSignIn && onProviderOAuthLogin && providerRow?.oauth_login_supported ? ( + + ) : null}
- {catalogNeedsSignIn && onProviderOAuthLogin && providerRow?.oauth_login_supported ? ( - - ) : null}
) : null} - {providerRequiresConfiguration ? ( + {catalogNeedsSignIn ? null : providerRequiresConfiguration ? (
{tx("settings.models.providerNotConfigured", "Configure this provider before loading models.")}
diff --git a/webui/src/tests/model-catalog-feedback.test.tsx b/webui/src/tests/model-catalog-feedback.test.tsx index 3ec21deea..87d80f734 100644 --- a/webui/src/tests/model-catalog-feedback.test.tsx +++ b/webui/src/tests/model-catalog-feedback.test.tsx @@ -35,38 +35,65 @@ function catalog( describe("OAuth catalog feedback", () => { installSettingsViewTestHooks(); - it.each(["stale", "fallback"] as const)("explains %s auth failures without hiding models or manual IDs", async (source) => { + it.each(["stale", "fallback"] as const)("replaces %s models and search with sign-in after auth fails", async (source) => { vi.stubGlobal("fetch", vi.fn(async () => jsonResponse(catalog(source, "auth_required")))); const onChange = vi.fn(); const login = vi.fn(); render(); - await openPopover(screen.getByRole("button", { name: "Select model" })); + value="openai-codex/saved-model" showProviderLogos onChange={onChange} onProviderOAuthLogin={login} />); + await openPopover(screen.getByRole("button", { name: "openai-codex/saved-model" })); const notice = await screen.findByRole("status"); expect(notice).toHaveTextContent("Authorization expired. Please sign in again."); + expect(notice).not.toHaveTextContent("out of date"); + expect(screen.queryByText(/private upstream/)).not.toBeInTheDocument(); + expect(screen.queryByRole("option")).not.toBeInTheDocument(); + expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); + expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); + expect(screen.getByRole("button", { name: "openai-codex/saved-model" })).toBeVisible(); + expect(onChange).not.toHaveBeenCalled(); + const signIn = screen.getByRole("button", { name: "Sign in again" }); + expect(signIn).toHaveAttribute("aria-describedby", notice.id); + expect(signIn).toHaveFocus(); + fireEvent.click(signIn); + expect(login).toHaveBeenCalledWith("openai_codex"); + expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); + }); + + it.each([ + ["fallback", "unavailable"], ["fallback", undefined], ["stale", "unavailable"], + ] as const)("keeps %s models for temporary or legacy failures (%s)", async (source, kind) => { + vi.stubGlobal("fetch", vi.fn(async () => jsonResponse(catalog(source, kind)))); + const onChange = vi.fn(); + render(); + await openPopover(screen.getByRole("button", { name: "Select model" })); + const notice = await screen.findByRole("status"); + expect(notice).toHaveTextContent("Could not refresh models. Try again later."); expect(notice).toHaveTextContent(source === "stale" ? "cached models" : "built-in models"); expect(notice).toHaveTextContent("out of date"); - expect(screen.queryByText(/private upstream/)).not.toBeInTheDocument(); + expect(screen.queryByRole("button", { name: "Sign in again" })).not.toBeInTheDocument(); expect(screen.getByRole("option", { name: /Offline model/ })).toBeVisible(); const search = screen.getByRole("combobox"); expect(search).toHaveAttribute("aria-describedby", notice.id); fireEvent.change(search, { target: { value: "openai-codex/custom-model" } }); fireEvent.click(screen.getByRole("option", { name: /Use.*custom-model/ })); expect(onChange).toHaveBeenCalledWith("openai-codex/custom-model"); - await openPopover(screen.getByRole("button", { name: "Select model" })); - fireEvent.click(await screen.findByRole("button", { name: "Sign in again" })); - expect(login).toHaveBeenCalledWith("openai_codex"); - expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); }); - it.each(["unavailable", undefined] as const)("does not request login for temporary or legacy failures (%s)", async (kind) => { - vi.stubGlobal("fetch", vi.fn(async () => jsonResponse(catalog("fallback", kind)))); + it("removes a pending custom choice when an auth failure arrives", async () => { + let finish!: (response: Response) => void; + vi.stubGlobal("fetch", vi.fn(() => new Promise((resolve) => { finish = resolve; }))); + const onChange = vi.fn(); render(); + value="" showProviderLogos onChange={onChange} onProviderOAuthLogin={vi.fn()} />); await openPopover(screen.getByRole("button", { name: "Select model" })); - expect(await screen.findByRole("status")).toHaveTextContent("Could not refresh models. Try again later."); - expect(screen.queryByRole("button", { name: "Sign in again" })).not.toBeInTheDocument(); - expect(screen.getByRole("option", { name: /Offline model/ })).toBeVisible(); + fireEvent.change(screen.getByRole("combobox"), { target: { value: "openai-codex/custom-model" } }); + expect(screen.getByRole("option", { name: /Use.*custom-model/ })).toBeVisible(); + await act(async () => { finish(jsonResponse(catalog("stale", "auth_required"))); }); + expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); + expect(screen.queryByRole("option")).not.toBeInTheDocument(); + expect(screen.getByRole("button", { name: "Sign in again" })).toHaveFocus(); + expect(onChange).not.toHaveBeenCalled(); }); it("reloads an open picker on successful same-account login and clears stale feedback", async () => { @@ -81,9 +108,12 @@ describe("OAuth catalog feedback", () => { const view = render(); await openPopover(screen.getByRole("button", { name: "Select model" })); expect(await screen.findByRole("status")).toHaveTextContent("Authorization expired"); + expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); + expect(screen.queryByRole("option")).not.toBeInTheDocument(); // Login produces a new settings snapshot, even when the account is unchanged. view.rerender(); expect(await screen.findByRole("option", { name: /New model/ })).toBeVisible(); + expect(screen.getByRole("combobox")).toBeVisible(); expect(screen.queryByRole("status")).not.toBeInTheDocument(); expect(fetchMock).toHaveBeenCalledTimes(2); });