From dcdf80978ba82cc9be3fb9bb522980a11bca0f31 Mon Sep 17 00:00:00 2001 From: Devika Verma Date: Mon, 9 Nov 2026 10:09:14 +0530 Subject: [PATCH] fix(models): one list on the provider page; image, music, video and robotics models are not offered as coworker models (OPE-252) Owner's reading of the Gemini page: no split between reviewed rows and the rest (one list, reviewed first, the provider's newest after, new ones above under their own heading), and a question about Nano Banana Pro, Lyria and Robotics-ER showing up with a tick box. Google serves its image, music, video and robotics models through the same generateContent method as its language models, so the method alone did not tell them apart. The chat-only filter now reads ids and display names for those families too. They are not coworker models: a coworker's turns need a model that holds a conversation and calls tools, and a picker row for a generator would only fail in a session. Generation as a capability belongs to a tool, not to the model picker. A listed id that is not a chat model is still "on the key": a user who types it by hand is not told the key lacks it (the listing keeps every id for that check and shows only the chat ones). --- coworker/providers/live_models.py | 59 ++++++++++++++----- coworker/server/manager.py | 5 +- .../components/models/ProviderModels.test.tsx | 23 ++++---- .../src/components/models/ProviderModels.tsx | 15 ++--- surfaces/gui/src/locales/en.json | 2 - surfaces/gui/src/locales/zh.json | 2 - tests/test_live_models.py | 31 ++++++++-- 7 files changed, 93 insertions(+), 44 deletions(-) diff --git a/coworker/providers/live_models.py b/coworker/providers/live_models.py index 91da5448..54a42c27 100644 --- a/coworker/providers/live_models.py +++ b/coworker/providers/live_models.py @@ -23,7 +23,7 @@ import json import os import threading import time -from dataclasses import asdict, dataclass +from dataclasses import asdict, dataclass, field from pathlib import Path from typing import Any, Optional @@ -40,9 +40,14 @@ NO_LISTING: dict[str, str] = { "ark-agent-plan-cn": "BytePlus Ark publishes no model list; the curated rows are shown.", } -# Ids that are not chat models whatever the provider says (embeddings, speech, images, -# moderation, rerankers); a picker row for them would only fail in a session. -_NOT_CHAT = ("embed", "tts", "whisper", "dall-e", "moderation", "rerank", "transcri", "image-", "-image", "audio", "sora", "realtime") +# Ids and names that are not chat models whatever the provider says: embeddings, speech, +# image / music / video generators, robotics, moderation, rerankers. Google serves several +# of these through the same generateContent method as its language models (Nano Banana +# draws, Lyria composes, Veo films, Robotics-ER drives), so the method alone does not tell. +_NOT_CHAT = ( + "embed", "tts", "whisper", "dall-e", "moderation", "rerank", "transcri", "image-", "-image", "imagen", + "audio", "sora", "realtime", "banana", "lyria", "veo", "music", "video", "robotics", "-live", "aqa", +) @dataclass(frozen=True) @@ -59,9 +64,12 @@ class LiveModel: class Listing: provider: str ok: bool - models: list[LiveModel] + models: list[LiveModel] # the chat models, what the page lists error: Optional[str] = None status: Optional[int] = None + # Every id the provider listed, chat or not: an image or music model is not offered + # as a coworker's model, but a user who types its id is not told the key lacks it. + all_ids: list[str] = field(default_factory=list) # -- the request --------------------------------------------------------------------------- @@ -165,10 +173,11 @@ def _row(name: str, item: dict[str, Any]) -> Optional[LiveModel]: kind = item.get("type") if isinstance(kind, str) and kind not in ("chat", "model", "language", "llm"): return None # Together: image / embedding / audio rows - lowered = model_id.lower() - if any(mark in lowered for mark in _NOT_CHAT): - return None display = item.get("display_name") or item.get("displayName") + lowered = model_id.lower() + shown = display.lower() if isinstance(display, str) else "" + if any(mark in lowered or mark in shown for mark in _NOT_CHAT): + return None if not isinstance(display, str) or not display.strip(): display = item.get("name") if isinstance(item.get("name"), str) and item.get("name") != raw_id else None tools: Optional[bool] = None @@ -195,18 +204,38 @@ def _row(name: str, item: dict[str, Any]) -> Optional[LiveModel]: ) -def parse_listing(name: str, payload: Any) -> list[LiveModel]: - """The chat models in a provider's answer, newest first. Tolerant of the three shapes - in use: {"data": [...]} (OpenAI and most), {"models": [...]} (Gemini, Cohere), a bare - list (Together).""" +def _items(payload: Any) -> list[Any]: if isinstance(payload, dict): items = payload.get("data") if not isinstance(items, list): items = payload.get("models") else: items = payload - if not isinstance(items, list): - return [] + return items if isinstance(items, list) else [] + + +def listed_ids(name: str, payload: Any) -> list[str]: + """Every model id in the answer, chat or not, in the provider's order.""" + out: list[str] = [] + for item in _items(payload): + if not isinstance(item, dict): + continue + raw_id = item.get("id") if isinstance(item.get("id"), str) else item.get("name") + if not isinstance(raw_id, str) or not raw_id.strip(): + continue + model_id = raw_id.strip() + if name == "gemini" and model_id.startswith("models/"): + model_id = model_id[len("models/"):] + if model_id not in out: + out.append(model_id) + return out + + +def parse_listing(name: str, payload: Any) -> list[LiveModel]: + """The chat models in a provider's answer, newest first. Tolerant of the three shapes + in use: {"data": [...]} (OpenAI and most), {"models": [...]} (Gemini, Cohere), a bare + list (Together).""" + items = _items(payload) rows: dict[str, LiveModel] = {} for item in items: if not isinstance(item, dict): @@ -242,7 +271,7 @@ def fetch(name: str, profile: dict[str, Any], descriptor: Any, *, timeout: float payload = resp.json() except ValueError: return Listing(name, False, [], error="The provider's model list was not JSON.", status=resp.status_code) - return Listing(name, True, parse_listing(name, payload), status=resp.status_code) + return Listing(name, True, parse_listing(name, payload), status=resp.status_code, all_ids=listed_ids(name, payload)) # -- facts the rest of the app can read without the manager -------------------------------- diff --git a/coworker/server/manager.py b/coworker/server/manager.py index 5a51f29d..a49ad77b 100644 --- a/coworker/server/manager.py +++ b/coworker/server/manager.py @@ -5581,6 +5581,7 @@ class SessionManager: entry = { "fetched_at": now, "ids": ids, + "all_ids": listing.all_ids or ids, "seen": seen, "new": [i for i in ids if i not in seen_set], "models": {m.id: live_models.as_dict(m) for m in listing.models}, @@ -5690,7 +5691,9 @@ class SessionManager: if not ids: return None _prov, bare = split_id(model) - if self._listed(bare, ids) is not None: + # Typed by hand, any id the provider lists is on the key, chat model or not (an + # image or music model is not offered in the list, but it is not refused either). + if self._listed(bare, [str(i) for i in entry.get("all_ids") or ids]) is not None: return None close = difflib.get_close_matches(bare, ids, n=3, cutoff=0.5) return { diff --git a/surfaces/gui/src/components/models/ProviderModels.test.tsx b/surfaces/gui/src/components/models/ProviderModels.test.tsx index b6924a35..4816bf80 100644 --- a/surfaces/gui/src/components/models/ProviderModels.test.tsx +++ b/surfaces/gui/src/components/models/ProviderModels.test.tsx @@ -65,12 +65,11 @@ describe("ProviderModels with a live listing", () => { expect(getProviderCatalog).toHaveBeenCalledWith("openrouter", false); expect(screen.getByTestId("catalog-status").textContent).toContain("4 models on this key"); expect(screen.getByTestId("catalog-new").textContent).toContain("Brand New"); - expect(screen.getByTestId("catalog-recommended").textContent).toContain("GLM-5.2"); - expect(screen.getByTestId("catalog-recommended").textContent).toContain("Kimi K3"); - const all = screen.getByTestId("catalog-all").textContent || ""; - expect(all).toContain("GPT-6 Astra"); - expect(all).toContain("Mystery"); - expect(all).not.toContain("Brand New"); + const list = screen.getByTestId("catalog-list"); + const names = Array.from(list.querySelectorAll(".mlist-name")).map((n) => n.textContent); + expect(names).toEqual(["GLM-5.2 · via OpenRouter", "OpenAI: GPT-6 Astra", "Mystery", "Kimi K3 · via OpenRouter"]); // the backend's order, one list + expect(list.textContent).not.toContain("Brand New"); + expect(screen.queryByText("Reviewed by OpenWorker")).toBeNull(); // the facts and where they came from expect(screen.getByTestId("catalog-tags-lab/brand-new").textContent).toContain("new"); expect(screen.getByTestId("catalog-tags-openai/gpt-6-astra").textContent).toContain("922K context"); @@ -80,8 +79,6 @@ describe("ProviderModels with a live listing", () => { expect(screen.getByTestId("catalog-tags-openai/gpt-6-astra").textContent).not.toContain("PDF"); expect(screen.getByTestId("catalog-tags-z-ai/glm-5.2").textContent).toContain("images + PDF"); expect(screen.getByTestId("catalog-tags-lab/mystery").textContent).toContain("unverified"); - expect(screen.getByTestId("catalog-recommended").textContent).toContain("Reviewed by OpenWorker"); - expect(screen.getByTestId("catalog-all").textContent).toContain("Also on your key"); expect(screen.getByTestId("catalog-tags-moonshotai/kimi-k3").textContent).toContain("not on this key"); expect(screen.getByTestId("catalog-not-on-key").textContent).toContain("1 ticked models are not on this key"); // the default row is ticked and locked @@ -128,7 +125,7 @@ describe("ProviderModels with a live listing", () => { fireEvent.click(screen.getByTestId("catalog-refresh")); await waitFor(() => expect(getProviderCatalog).toHaveBeenLastCalledWith("openrouter", true)); await waitFor(() => expect(screen.getByTestId("catalog-error").textContent).toContain("HTTP 503")); - expect(screen.getByTestId("catalog-recommended").textContent).toContain("GLM-5.2"); + expect(screen.getByTestId("catalog-list").textContent).toContain("GLM-5.2"); }); it("search narrows every section and long lists fold", async () => { @@ -136,12 +133,12 @@ describe("ProviderModels with a live listing", () => { vi.mocked(getProviderCatalog).mockResolvedValue({ ...LIVE, rows: [...LIVE.rows, ...many] }); renderPanel(); await flush(); - expect(screen.getByTestId("catalog-all").querySelectorAll(".mlist-row").length).toBe(12); - expect(screen.getByTestId("catalog-show-all").textContent).toContain("Show all 22"); + expect(screen.getByTestId("catalog-list").querySelectorAll(".mlist-row").length).toBe(12); + expect(screen.getByTestId("catalog-show-all").textContent).toContain("Show all 24"); fireEvent.click(screen.getByTestId("catalog-show-all")); - expect(screen.getByTestId("catalog-all").querySelectorAll(".mlist-row").length).toBe(22); + expect(screen.getByTestId("catalog-list").querySelectorAll(".mlist-row").length).toBe(24); fireEvent.change(screen.getByTestId("catalog-search"), { target: { value: "astra" } }); - expect(screen.getByTestId("catalog-all").querySelectorAll(".mlist-row").length).toBe(1); + expect(screen.getByTestId("catalog-list").querySelectorAll(".mlist-row").length).toBe(1); expect(screen.queryByTestId("catalog-new")).toBeNull(); }); }); diff --git a/surfaces/gui/src/components/models/ProviderModels.tsx b/surfaces/gui/src/components/models/ProviderModels.tsx index a70ef89c..356293be 100644 --- a/surfaces/gui/src/components/models/ProviderModels.tsx +++ b/surfaces/gui/src/components/models/ProviderModels.tsx @@ -89,12 +89,14 @@ export function ProviderModels({ const rows = catalog?.rows || []; const q = query.trim().toLowerCase(); + // One list (owner's call 2026-11-09: no reviewed-versus-rest split): the rows the + // backend ordered, reviewed first, then the provider's own newest first. Models the + // provider added since the last check sit above it under their own heading. const sections = useMemo(() => { const match = (r: ProviderCatalogRow) => !q || r.id.toLowerCase().includes(q) || r.label.toLowerCase().includes(q); const fresh = rows.filter((r) => r.new && match(r)); - const recommended = rows.filter((r) => !r.new && (r.recommended || r.verified === "catalog") && match(r)); - const rest = rows.filter((r) => !r.new && !(r.recommended || r.verified === "catalog") && match(r)); - return { fresh, recommended, rest }; + const rest = rows.filter((r) => !r.new && match(r)); + return { fresh, rest }; }, [rows, q]); const setRow = (model: string, patch: Partial) => @@ -230,12 +232,12 @@ export function ProviderModels({ ); }; - const section = (title: string, items: ProviderCatalogRow[], testid: string, foldable = false) => { + const section = (title: string | null, items: ProviderCatalogRow[], testid: string, foldable = false) => { if (!items.length) return null; const shown = foldable && !showAll && !q ? items.slice(0, FOLD) : items; return (
-
{title}
+ {title &&
{title}
}
{shown.map(rowEl)}
{foldable && !q && items.length > FOLD && (