diff --git a/README.md b/README.md index a881365..7cf513f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ Model IDs are the catalog `display_name` with whitespace stripped. After login, Examples: `Lite`, `Qwen3.8-Max`, `Qwen3.7-Plus`, `Qwen3.8-Flash`. +Qoder's `/model/list` groups one account catalog by UI scenario (`chat`, `assistant`, `quest`, `qwork`, `experts`, …). pi registers the **union** of those groups, so the picker matches the models your Qoder IDE shows instead of the old chat-only CLI subset (e.g. `GLM-5.3`, `GLM-5.2`, `DeepSeek-V4-Pro` appear only under `experts`/`qwork`). Duplicate upstream keys keep the `chat` entry. + Context uses the largest live catalog option (often 1M). Output is 128K. ## Endpoints diff --git a/package-lock.json b/package-lock.json index 64437bd..66c2a38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pi-provider-qoder", - "version": "0.4.4", + "version": "0.4.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pi-provider-qoder", - "version": "0.4.4", + "version": "0.4.5", "license": "MIT", "devDependencies": { "@biomejs/biome": "2.5.12", diff --git a/src/__tests__/catalog-cache.test.ts b/src/__tests__/catalog-cache.test.ts index b3240db..e2d0f39 100644 --- a/src/__tests__/catalog-cache.test.ts +++ b/src/__tests__/catalog-cache.test.ts @@ -82,6 +82,66 @@ describe("Qoder model cache", () => { expect(getCachedModelConfig("qfmodel", "global")).toBeNull(); }); + it("merges every catalog scenario and deduplicates by upstream key", async () => { + vi.stubGlobal( + "fetch", + vi.fn().mockResolvedValue({ + ok: true, + json: () => + Promise.resolve({ + chat: [ + { key: "auto", enable: true, display_name: "Auto" }, + { key: "qmodel_38max", enable: true, display_name: "Qwen3.8-Max" }, + ], + // Duplicate keys must not be registered twice, and the chat entry wins. + experts: [ + { key: "auto", enable: true, display_name: "Auto" }, + { key: "gmodel", enable: true, display_name: "GLM-5.3", is_reasoning: true }, + { key: "gm51model", enable: true, display_name: "GLM-5.2" }, + ], + qwork: [{ key: "dmodel", enable: true, display_name: "DeepSeek-V4-Pro", is_reasoning: true }], + byok_teams: [{ key: "byokx", enable: true, display_name: "BYOK X" }], + }), + }), + ); + + await updateQoderModelsCache("access-token", "user-id", "Test User", "test@example.com", "cn"); + + expect(getCachedModels("cn").map((model) => model.id)).toEqual([ + "Auto", + "Qwen3.8-Max", + "DeepSeek-V4-Pro", + "GLM-5.3", + "GLM-5.2", + ]); + expect(getCachedModelConfig("GLM-5.3", "cn")?.key).toBe("gmodel"); + expect(getCachedModelConfig("GLM-5.2", "cn")?.key).toBe("gm51model"); + expect(getCachedModelConfig("DeepSeek-V4-Pro", "cn")?.key).toBe("dmodel"); + // bring-your-own-key scenarios stay out of the shared catalog + expect(getCachedModelConfig("BYOKX", "cn")).toBeNull(); + }); + + it("keeps an enabled auto model from the live catalog", async () => { + vi.stubGlobal( + "fetch", + vi.fn().mockResolvedValue({ + ok: true, + json: () => + Promise.resolve({ + chat: [ + { key: "auto", enable: true, display_name: "Auto", is_default: true }, + { key: "qfmodel", enable: true, display_name: "Qwen3.8-Flash" }, + ], + }), + }), + ); + + await updateQoderModelsCache("access-token", "user-id", "Test User", "test@example.com", "cn"); + + expect(getCachedModels("cn").map((model) => model.id)).toEqual(["Auto", "Qwen3.8-Flash"]); + expect(getCachedModelConfig("Auto", "cn")?.key).toBe("auto"); + }); + it("omits catalog entries without a friendly display name", async () => { vi.stubGlobal( "fetch", diff --git a/src/catalog.ts b/src/catalog.ts index 631d981..155d35d 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -538,8 +538,20 @@ export function getCachedModels(mode: QoderMode): QoderModelDef[] { }); // Older releases injected `auto` without a corresponding service config. // Keep an explicitly enabled service model, but drop the legacy fallback. - if (data.configs && typeof data.configs === "object" && !data.configs.auto) { - return models.filter((model: QoderModelDef) => model.id.toLowerCase() !== "auto"); + // Live catalogs key `configs` by the whitespace-stripped display name, so an + // enabled auto arrives as `Auto` rather than the legacy raw `auto` key. + if (data.configs && typeof data.configs === "object") { + const hasAutoConfig = + "auto" in data.configs || + Object.values(data.configs).some( + (entry) => + entry && + typeof entry === "object" && + toQoderModelId((entry as QoderModelEntry).display_name).toLowerCase() === "auto", + ); + if (!hasAutoConfig) { + return models.filter((model: QoderModelDef) => model.id.toLowerCase() !== "auto"); + } } return models; } @@ -619,6 +631,49 @@ export function isCacheStale(mode: QoderMode): boolean { return Date.now() - data.updatedAt > 3600_000; } +/** + * Qoder's `/model/list` groups one account catalog by UI scenario. The CLI + * historically read only `chat`, which hides models the IDE exposes in other + * modes — e.g. `gmodel` (GLM-5.3), `gm51model` (GLM-5.2) and `dmodel` + * (DeepSeek-V4-Pro) appear in `experts`/`qwork` but not in `chat`. Register the + * union so pi offers the same set the IDE does. + * + * `chat` is scanned first on purpose: it is the most complete default group, so + * first-seen ordering is preserved and duplicate upstream keys keep the chat + * entry's metadata. `byok_*` groups are intentionally excluded — those are + * bring-your-own-key providers, not part of the shared Qoder catalog. + */ +export const QODER_CATALOG_SCENARIOS = [ + "chat", + "assistant", + "developer", + "quest", + "qwork", + "experts", + "qwake", + "app", + "inline", +] as const; + +/** Flatten the scenario groups into one catalog, keeping the first occurrence per upstream key. */ +export function collectCatalogEntries(resData: Record): QoderModelEntry[] { + const seen = new Set(); + const entries: QoderModelEntry[] = []; + for (const scenario of QODER_CATALOG_SCENARIOS) { + const group = resData[scenario]; + if (!Array.isArray(group)) continue; + for (const raw of group as unknown[]) { + if (!raw || typeof raw !== "object") continue; + const entry = raw as QoderModelEntry; + const key = entry.key; + if (!key || seen.has(key)) continue; + seen.add(key); + entries.push(entry); + } + } + return entries; +} + export async function updateQoderModelsCache( authToken: string, userID: string, @@ -647,14 +702,16 @@ export async function updateQoderModelsCache( return; } - const resData = (await response.json()) as { chat?: QoderModelEntry[] }; - const chatModels = resData.chat || []; - if (chatModels.length === 0) return; + // Merge every scenario group (`chat` ∪ `experts` ∪ `qwork` ∪ …) so the + // picker matches the IDE instead of the old chat-only CLI subset. + const resData = (await response.json()) as Record; + const catalogEntries = collectCatalogEntries(resData); + if (catalogEntries.length === 0) return; const newModels: QoderModelDef[] = []; const configs: Record = {}; - for (const entry of chatModels) { + for (const entry of catalogEntries) { const key = entry.key; if (!key || !entry.enable || !entry.display_name) continue;