Skip to content
Python

fix(models): Models & Keys says Loading providers… and when they could not load

Devika Verma494d48c89329
diff --git a/surfaces/gui/src/components/models/ProviderGroups.loading.test.tsx b/surfaces/gui/src/components/models/ProviderGroups.loading.test.tsx
new file mode 100644
index 00000000..0eb5df0e
--- /dev/null
+++ b/surfaces/gui/src/components/models/ProviderGroups.loading.test.tsx
@@ -0,0 +1,52 @@
+// T3-2: while /v1/providers is on its way the page says "Loading providers…", and when it
+// fails it says so with Try again, never "No providers match." with an empty search box.
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
+
+vi.mock("../../tauri", () => ({ openExternal: vi.fn() }));
+vi.mock("../../api", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../../api")>()),
+ getProviders: vi.fn(),
+}));
+
+import { getProviders, type ProviderInfo } from "../../api";
+import { useProviderSetup } from "../../providers/ProviderSetup";
+import { ProviderGroups } from "./ProviderGroups";
+
+function Page() {
+ const ps = useProviderSetup();
+ return <ProviderGroups ps={ps} tp="set" models={[]} />;
+}
+
+const flush = () => act(async () => { await Promise.resolve(); await Promise.resolve(); });
+
+afterEach(() => {
+ cleanup();
+ vi.mocked(getProviders).mockReset();
+});
+
+describe("ProviderGroups while the providers load (T3-2)", () => {
+ it("says Loading providers… until the answer comes", async () => {
+ let answer: (p: ProviderInfo[]) => void = () => {};
+ vi.mocked(getProviders).mockReturnValue(new Promise((r) => { answer = r; }));
+ render(<Page />);
+ expect(screen.getByTestId("provider-loading").textContent).toBe("Loading providers…");
+ expect(screen.queryByTestId("provider-search-empty")).toBeNull();
+ await act(async () => answer([{ name: "openai", title: "OpenAI", kind: "api_key", needs_key: true, configured: false, fields: [] } as any]));
+ expect(screen.queryByTestId("provider-loading")).toBeNull();
+ expect(screen.getByTestId("set-provider-openai")).toBeTruthy();
+ });
+
+ it("says it could not load, and Try again asks again", async () => {
+ vi.mocked(getProviders).mockRejectedValueOnce(new Error("offline"));
+ render(<Page />);
+ await flush();
+ expect(screen.getByTestId("provider-load-failed").textContent).toContain("Could not load the providers.");
+ expect(screen.queryByTestId("provider-search-empty")).toBeNull();
+ vi.mocked(getProviders).mockResolvedValueOnce([]);
+ fireEvent.click(screen.getByTestId("provider-load-retry"));
+ await flush();
+ expect(getProviders).toHaveBeenCalledTimes(2);
+ expect(screen.queryByTestId("provider-load-failed")).toBeNull();
+ });
+});
diff --git a/surfaces/gui/src/components/models/ProviderGroups.tsx b/surfaces/gui/src/components/models/ProviderGroups.tsx
index 21dbbc57..6fbabe21 100644
--- a/surfaces/gui/src/components/models/ProviderGroups.tsx
+++ b/surfaces/gui/src/components/models/ProviderGroups.tsx
@@ -103,7 +103,18 @@ export function ProviderGroups({
data-testid="provider-search"
/>
</label>
- {shown.length === 0 && <p className="text-meta text-faint mb-6" data-testid="provider-search-empty">{t("manage.no_providers_match")}</p>}
+ {/* T3-2: while the list is on its way, or when it could not be read, say that, not
+ "No providers match." (which reads as if the search found nothing) */}
+ {ps.providersState === "loading" && ps.providers.length === 0 ? (
+ <p className="text-meta text-faint mb-6" data-testid="provider-loading">{t("manage.providers_loading")}</p>
+ ) : ps.providersState === "failed" && ps.providers.length === 0 ? (
+ <p className="text-meta text-danger mb-6" data-testid="provider-load-failed">
+ {t("manage.providers_failed")}{" "}
+ <button className="underline" data-testid="provider-load-retry" onClick={() => void ps.refreshProviders()}>{t("manage.providers_retry")}</button>
+ </p>
+ ) : (
+ shown.length === 0 && <p className="text-meta text-faint mb-6" data-testid="provider-search-empty">{t("manage.no_providers_match")}</p>
+ )}
{KINDS.map((kind) => {
const inKind = shown.filter((p) => providerKind(p) === kind);
if (inKind.length === 0) return null;
diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.json
index 595455f0..3bb5c4b9 100644
--- a/surfaces/gui/src/locales/en.json
+++ b/surfaces/gui/src/locales/en.json
@@ -1371,7 +1371,6 @@
"models": "Models",
"models_help": "Ticked models show in the composer's picker; the black badge marks the default for new sessions.",
"azure_deployment_help": "On Azure the model id is your deployment name — add each deployment you want to use, as named in the Azure or Foundry portal.",
-
"one_click_coming": "One-click sign-in is coming soon — connect manually below for now:",
"optional": "(optional)",
"or_connect_manually": "or connect manually:",
@@ -1423,6 +1422,9 @@
"group_subscription": "Subscriptions",
"group_api_key": "API keys",
"no_providers_match": "No providers match.",
+ "providers_loading": "Loading providers…",
+ "providers_failed": "Could not load the providers.",
+ "providers_retry": "Try again",
"show_more": "Show {{count}} more",
"show_fewer": "Show fewer",
"search_providers": "Search providers…",
diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.json
index 143d652f..f27ba207 100644
--- a/surfaces/gui/src/locales/zh.json
+++ b/surfaces/gui/src/locales/zh.json
@@ -1350,7 +1350,6 @@
"models": "模型",
"models_help": "已勾选的模型会显示在输入框的选择器中;黑色徽标表示新会话的默认模型。",
"azure_deployment_help": "在 Azure 上,模型 ID 就是你的部署名称——按 Azure 或 Foundry 门户中的名称,逐个添加你要使用的部署。",
-
"one_click_coming": "一键登录即将推出 —— 目前请在下方手动连接:",
"optional": "(可选)",
"or_connect_manually": "或手动连接:",
@@ -1402,6 +1401,9 @@
"group_subscription": "订阅",
"group_api_key": "API 密钥",
"no_providers_match": "没有匹配的提供商。",
+ "providers_loading": "正在加载提供商…",
+ "providers_failed": "无法加载提供商。",
+ "providers_retry": "重试",
"show_more": "再显示 {{count}} 个",
"show_fewer": "收起",
"search_providers": "搜索提供商…",
diff --git a/surfaces/gui/src/providers/ProviderSetup.tsx b/surfaces/gui/src/providers/ProviderSetup.tsx
index cc8dd382..4be33fff 100644
--- a/surfaces/gui/src/providers/ProviderSetup.tsx
+++ b/surfaces/gui/src/providers/ProviderSetup.tsx
@@ -102,6 +102,9 @@ export function relTime(epoch?: number | null, t?: TFunction): string | null {
export interface ProviderSetupState {
providers: ProviderInfo[];
+ /** T3-2: the first /v1/providers answer has not come yet, or it failed. A later refresh
+ * that fails keeps the list it had. */
+ providersState?: "loading" | "ready" | "failed";
ordered: ProviderInfo[];
refreshProviders: () => Promise<void>;
sel: string | null;
@@ -132,6 +135,7 @@ export interface ProviderSetupState {
export function useProviderSetup(opts?: { onSaved?: () => void }): ProviderSetupState {
const { t } = useTranslation();
const [providers, setProviders] = useState<ProviderInfo[]>([]);
+ const [providersState, setProvidersState] = useState<"loading" | "ready" | "failed">("loading");
// null = the gallery; a provider name = that provider's key form.
const [sel, setSel] = useState<string | null>(null);
const [fields, setFields] = useState<Record<string, string>>({});
@@ -150,8 +154,11 @@ export function useProviderSetup(opts?: { onSaved?: () => void }): ProviderSetup
const refreshProviders = () =>
getProviders()
- .then(setProviders)
- .catch(() => {});
+ .then((p) => {
+ setProviders(p);
+ setProvidersState("ready");
+ })
+ .catch(() => setProvidersState((s) => (s === "ready" ? s : "failed")));
useEffect(() => {
refreshProviders();
return () => {
@@ -285,6 +292,7 @@ export function useProviderSetup(opts?: { onSaved?: () => void }): ProviderSetup
return {
providers,
+ providersState,
// Alphabetical by display title (owner ruling 2026-08-21: a curated order reads
// as vendor bias). The old providerRank curation stays only as the tiebreaker
// for identical titles.