feat(cn): expose upstream display_name as model id, drop key mapping tables
The CN model picker used to translate Qoder's internal keys (qfmodel, qmodel_latest, ...) into hardcoded "friendly" ids (qwen3.6-flash, ...) via a manual mapping table, with the display label hardcoded alongside. Both sides rotted independently of upstream: when Qoder upgraded qfmodel to Qwen3.8-Flash the label stayed "Qwen 3.6 Flash", and new keys (qmodel_38max, q37fmodel) had no entry so their raw key leaked into the picker as the id. The catalog API already returns every key with its display_name, so the mapping table duplicates data the server provides and can only ever be stale. Rework: use the upstream display_name (whitespace-stripped) directly as the pi-visible Model.id, and read the request-time upstream key back from the cached model config at send time. No key<->friendlyId table is needed. - cosy.ts: remove qoderCNFriendlyModels, getQoderCNDirectModel, getQoderCNFriendlyModelInfo, toQoderCNFriendlyModel, prettifyQoderCNModelName. Add toQoderCNModelId(display) = display with whitespace stripped. - models.ts: updateQoderModelsCache now sets CN model id = toQoderCNModelId(display_name); the original key is still stored in configs (keyed by both key and id) and read back via getCachedModelConfig. Simplify the CN fallback in getCachedModelConfig (drop the stale reasoning set). staticCnModels ids/names rewritten to the display_name form. - stream.ts: the upstream key comes from modelConfig.key (the cached entry) instead of a reverse-lookup table; falls back to model.id for the international site, which already uses the key as id. - index.ts: modelsForProvider no longer re-maps CN models through a friendly transform — the cached/static ids are already the display name. Trade-off: a renamed/upgraded model changes its id, so a previously saved default model may no longer resolve after an upstream rename and the user reselects. This is expected: users should learn about new models. This is accepted. Tests updated for the new contract; e2e against the live CN catalog confirms id=Qwen3.8-Flash resolves to send key=qfmodel with no mapping table.
This commit is contained in:
+14
-76
@@ -3,8 +3,6 @@ import {
|
||||
getQoderBaseUrl,
|
||||
getQoderCenterUrl,
|
||||
getQoderChatURL,
|
||||
getQoderCNDirectModel,
|
||||
getQoderCNFriendlyModelInfo,
|
||||
getQoderExchangeURL,
|
||||
getQoderManageUrl,
|
||||
getQoderMode,
|
||||
@@ -15,7 +13,7 @@ import {
|
||||
getQoderUserEmailFallback,
|
||||
getQoderUserInfoURL,
|
||||
isQoderCNMode,
|
||||
toQoderCNFriendlyModel,
|
||||
toQoderCNModelId,
|
||||
} from "../cosy.js";
|
||||
|
||||
// ── getQoderMode ──────────────────────────────────────────────────────────
|
||||
@@ -160,83 +158,23 @@ describe("getQoderUserEmailFallback", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ── getQoderCNDirectModel ─────────────────────────────────────────────────
|
||||
// ── toQoderCNModelId ──────────────────────────────────────────────────────
|
||||
|
||||
describe("getQoderCNDirectModel", () => {
|
||||
it("maps known model IDs to internal keys", () => {
|
||||
expect(getQoderCNDirectModel("qoder-cn")).toBe("auto");
|
||||
expect(getQoderCNDirectModel("qwen3.7-max")).toBe("qmodel_latest");
|
||||
expect(getQoderCNDirectModel("qwen3.7-plus")).toBe("qmodel");
|
||||
expect(getQoderCNDirectModel("qwen3.6-plus")).toBe("qmodel");
|
||||
expect(getQoderCNDirectModel("qwen3.6-flash")).toBe("q36fmodel");
|
||||
expect(getQoderCNDirectModel("deepseek-v4-pro")).toBe("dmodel");
|
||||
expect(getQoderCNDirectModel("deepseek-v4-flash")).toBe("dfmodel");
|
||||
expect(getQoderCNDirectModel("glm-5.2")).toBe("gm51model");
|
||||
expect(getQoderCNDirectModel("glm-5.1")).toBe("gm51model");
|
||||
expect(getQoderCNDirectModel("kimi-k2.6")).toBe("kmodel");
|
||||
expect(getQoderCNDirectModel("minimax-m2.7")).toBe("mmodel");
|
||||
expect(getQoderCNDirectModel("minimax-m3")).toBe("mmodel");
|
||||
describe("toQoderCNModelId", () => {
|
||||
it("strips whitespace from the upstream display_name", () => {
|
||||
// The display name is used directly as the pi-visible model id, with
|
||||
// whitespace removed so it stays a clean token for persistence keys and
|
||||
// search. "Qwen3.8-Flash" has no spaces already.
|
||||
expect(toQoderCNModelId("Qwen3.8-Flash")).toBe("Qwen3.8-Flash");
|
||||
});
|
||||
|
||||
it("returns the input ID for unknown models", () => {
|
||||
expect(getQoderCNDirectModel("custom-model")).toBe("custom-model");
|
||||
it("collapses internal spaces", () => {
|
||||
expect(toQoderCNModelId("Qwen 3.8 Max")).toBe("Qwen3.8Max");
|
||||
expect(toQoderCNModelId("DeepSeek V4 Pro")).toBe("DeepSeekV4Pro");
|
||||
});
|
||||
|
||||
it('defaults to "auto" when no input', () => {
|
||||
expect(getQoderCNDirectModel()).toBe("auto");
|
||||
expect(getQoderCNDirectModel("")).toBe("auto");
|
||||
});
|
||||
});
|
||||
|
||||
// ── getQoderCNFriendlyModelInfo ───────────────────────────────────────────
|
||||
|
||||
describe("getQoderCNFriendlyModelInfo", () => {
|
||||
it("returns known friendly info for mapped keys", () => {
|
||||
const info = getQoderCNFriendlyModelInfo("qmodel_latest");
|
||||
expect(info.id).toBe("qwen3.7-max");
|
||||
expect(info.name).toBe("Qwen 3.7 Max · Qoder CN");
|
||||
});
|
||||
|
||||
it("returns auto mapping", () => {
|
||||
const info = getQoderCNFriendlyModelInfo("auto");
|
||||
expect(info.id).toBe("auto");
|
||||
expect(info.name).toBe("Auto · Qoder CN");
|
||||
});
|
||||
|
||||
it("generates friendly name for unknown keys", () => {
|
||||
const info = getQoderCNFriendlyModelInfo("my-custom-model", "My Custom Model");
|
||||
expect(info.id).toBe("my-custom-model");
|
||||
expect(info.name).toContain("Qoder CN");
|
||||
});
|
||||
|
||||
it("prettifies model names with version numbers", () => {
|
||||
const info = getQoderCNFriendlyModelInfo("some-model", "Qwen3.7-New");
|
||||
expect(info.name).toContain("Qwen 3.7");
|
||||
expect(info.name).toContain("Qoder CN");
|
||||
});
|
||||
});
|
||||
|
||||
// ── toQoderCNFriendlyModel ────────────────────────────────────────────────
|
||||
|
||||
describe("toQoderCNFriendlyModel", () => {
|
||||
it("maps known model ID to friendly version", () => {
|
||||
const result = toQoderCNFriendlyModel({ id: "qmodel_latest", name: "Original Name" });
|
||||
expect(result.id).toBe("qwen3.7-max");
|
||||
expect(result.name).toBe("Qwen 3.7 Max · Qoder CN");
|
||||
});
|
||||
|
||||
it("preserves extra fields", () => {
|
||||
const result = toQoderCNFriendlyModel({ id: "auto", name: "Auto", extra: "field" } as {
|
||||
id: string;
|
||||
name: string;
|
||||
extra: string;
|
||||
});
|
||||
expect(result.extra).toBe("field");
|
||||
});
|
||||
|
||||
it("handles unknown models by prettifying display name", () => {
|
||||
const result = toQoderCNFriendlyModel({ id: "custom", name: "CustomModel V2-Pro" });
|
||||
expect(result.id).toBe("custom");
|
||||
expect(result.name).toContain("Qoder CN");
|
||||
it("falls back to a default when no display name is given", () => {
|
||||
expect(toQoderCNModelId()).toBe("QoderCNModel");
|
||||
expect(toQoderCNModelId("")).toBe("QoderCNModel");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,8 +43,8 @@ describe("staticCnModels", () => {
|
||||
expect(staticCnModels.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("has auto as first entry", () => {
|
||||
expect(staticCnModels[0].id).toBe("auto");
|
||||
it("has Auto as first entry", () => {
|
||||
expect(staticCnModels[0].id).toBe("Auto");
|
||||
});
|
||||
|
||||
it("every CN model has required fields", () => {
|
||||
|
||||
Reference in New Issue
Block a user