feat(models): register every /model/list scenario
Qoder's /model/list groups one account catalog by UI scenario (chat, assistant, quest, qwork, experts, ...). The CLI only read `chat`, so the picker hid models the IDE exposes elsewhere — GLM-5.3, GLM-5.2 and DeepSeek-V4-Pro live under experts/qwork. Register the union of the scenario groups, keeping the first occurrence per upstream key (chat wins) and excluding byok_* groups, which are bring-your-own-key providers rather than part of the shared catalog. Also keep an explicitly enabled `auto` model: live catalogs key `configs` by the whitespace-stripped display name, so it arrives as `Auto` instead of the legacy raw `auto` key. Refresh the lockfile to the 0.4.5 already in package.json.
This commit is contained in:
@@ -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`.
|
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.
|
Context uses the largest live catalog option (often 1M). Output is 128K.
|
||||||
|
|
||||||
## Endpoints
|
## Endpoints
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "pi-provider-qoder",
|
"name": "pi-provider-qoder",
|
||||||
"version": "0.4.4",
|
"version": "0.4.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "pi-provider-qoder",
|
"name": "pi-provider-qoder",
|
||||||
"version": "0.4.4",
|
"version": "0.4.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.5.12",
|
"@biomejs/biome": "2.5.12",
|
||||||
|
|||||||
@@ -82,6 +82,66 @@ describe("Qoder model cache", () => {
|
|||||||
expect(getCachedModelConfig("qfmodel", "global")).toBeNull();
|
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 () => {
|
it("omits catalog entries without a friendly display name", async () => {
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
"fetch",
|
"fetch",
|
||||||
|
|||||||
+63
-6
@@ -538,8 +538,20 @@ export function getCachedModels(mode: QoderMode): QoderModelDef[] {
|
|||||||
});
|
});
|
||||||
// Older releases injected `auto` without a corresponding service config.
|
// Older releases injected `auto` without a corresponding service config.
|
||||||
// Keep an explicitly enabled service model, but drop the legacy fallback.
|
// Keep an explicitly enabled service model, but drop the legacy fallback.
|
||||||
if (data.configs && typeof data.configs === "object" && !data.configs.auto) {
|
// Live catalogs key `configs` by the whitespace-stripped display name, so an
|
||||||
return models.filter((model: QoderModelDef) => model.id.toLowerCase() !== "auto");
|
// 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;
|
return models;
|
||||||
}
|
}
|
||||||
@@ -619,6 +631,49 @@ export function isCacheStale(mode: QoderMode): boolean {
|
|||||||
return Date.now() - data.updatedAt > 3600_000;
|
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<string, unknown>): QoderModelEntry[] {
|
||||||
|
const seen = new Set<string>();
|
||||||
|
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(
|
export async function updateQoderModelsCache(
|
||||||
authToken: string,
|
authToken: string,
|
||||||
userID: string,
|
userID: string,
|
||||||
@@ -647,14 +702,16 @@ export async function updateQoderModelsCache(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resData = (await response.json()) as { chat?: QoderModelEntry[] };
|
// Merge every scenario group (`chat` ∪ `experts` ∪ `qwork` ∪ …) so the
|
||||||
const chatModels = resData.chat || [];
|
// picker matches the IDE instead of the old chat-only CLI subset.
|
||||||
if (chatModels.length === 0) return;
|
const resData = (await response.json()) as Record<string, unknown>;
|
||||||
|
const catalogEntries = collectCatalogEntries(resData);
|
||||||
|
if (catalogEntries.length === 0) return;
|
||||||
|
|
||||||
const newModels: QoderModelDef[] = [];
|
const newModels: QoderModelDef[] = [];
|
||||||
const configs: Record<string, QoderModelEntry> = {};
|
const configs: Record<string, QoderModelEntry> = {};
|
||||||
|
|
||||||
for (const entry of chatModels) {
|
for (const entry of catalogEntries) {
|
||||||
const key = entry.key;
|
const key = entry.key;
|
||||||
if (!key || !entry.enable || !entry.display_name) continue;
|
if (!key || !entry.enable || !entry.display_name) continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user