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:
Loongphy
2026-08-28 08:16:36 +08:00
parent 9820845768
commit b462207447
6 changed files with 77 additions and 199 deletions
+14 -56
View File
@@ -113,62 +113,20 @@ export function getQoderRefreshURL(mode?: string): string {
return `${getQoderCenterUrl(mode)}/algo/api/v3/user/refresh_token`;
}
export function getQoderCNDirectModel(modelID?: string): string {
return (
{
"qoder-cn": "auto",
"qwen3.7-max": "qmodel_latest",
"qwen3.7-plus": "qmodel",
"qwen3.6-plus": "qmodel",
"qwen3.6-flash": "q36fmodel",
"deepseek-v4-pro": "dmodel",
"deepseek-v4-flash": "dfmodel",
"glm-5.2": "gm51model",
"glm-5.1": "gm51model",
"kimi-k2.6": "kmodel",
"minimax-m2.7": "mmodel",
"minimax-m3": "mmodel",
}[modelID || ""] ||
modelID ||
"auto"
);
}
const qoderCNFriendlyModels: Record<string, { id: string; name: string }> = {
auto: { id: "auto", name: "Auto · Qoder CN" },
"qoder-cn": { id: "qoder-cn", name: "Auto · Qoder CN" },
qmodel_latest: { id: "qwen3.7-max", name: "Qwen 3.7 Max · Qoder CN" },
qmodel: { id: "qwen3.7-plus", name: "Qwen 3.7 Plus · Qoder CN" },
q36fmodel: { id: "qwen3.6-flash", name: "Qwen 3.6 Flash · Qoder CN" },
qfmodel: { id: "qwen3.6-flash", name: "Qwen 3.6 Flash · Qoder CN" },
dmodel: { id: "deepseek-v4-pro", name: "DeepSeek V4 Pro · Qoder CN" },
dfmodel: { id: "deepseek-v4-flash", name: "DeepSeek V4 Flash · Qoder CN" },
gm51model: { id: "glm-5.2", name: "GLM 5.2 · Qoder CN" },
kmodel: { id: "kimi-k2.6", name: "Kimi K2.6 · Qoder CN" },
mmodel: { id: "minimax-m2.7", name: "MiniMax M2.7 · Qoder CN" },
};
function prettifyQoderCNModelName(name: string): string {
const pretty = (name || "Qoder CN Model")
.replace(/Qwen(\d)/g, "Qwen $1")
.replace(/Qwen([\d.]+)-/g, "Qwen $1 ")
.replace(/DeepSeek\s*V(\d)-/g, "DeepSeek V$1 ")
.replace(/\s+/g, " ")
.trim();
return pretty.includes("Qoder CN") ? pretty : `${pretty} · Qoder CN`;
}
export function getQoderCNFriendlyModelInfo(key: string, display?: string): { id: string; name: string } {
return qoderCNFriendlyModels[key] || { id: key, name: prettifyQoderCNModelName(display || key) };
}
export function toQoderCNFriendlyModel<T extends { id: string; name: string }>(model: T): T {
const info = getQoderCNFriendlyModelInfo(model.id, model.name);
return {
...model,
id: info.id,
name: info.name,
};
/**
* Derive the model `id` pi exposes in the picker from Qoder's `display_name`.
*
* The picker renders `Model.id`, not `Model.name`, so the display name is used
* directly as the id (with whitespace stripped so it stays a clean token for
* persistence keys, logs, and search). The original upstream `key` (e.g.
* `qfmodel`) is NOT used as the id: it is kept only as the request-time
* identifier, read back from the cached model config at send time. This drops
* the hardcoded key<->friendlyId mapping tables entirely — the label now
* tracks whatever upstream returns, so a renamed/upgraded model is shown
* correctly without a code change.
*/
export function toQoderCNModelId(displayName?: string): string {
return (displayName || "QoderCNModel").replace(/\s+/g, "");
}
export function getQoderManageUrl(mode?: string): string {