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
+11 -10
View File
@@ -15,7 +15,6 @@ import {
buildAuthHeaders,
getMachineId,
getQoderChatURL,
getQoderCNDirectModel,
getQoderMode,
getQoderUserEmailFallback,
isQoderCNMode,
@@ -120,18 +119,20 @@ export function streamQoder(
const email = cachedCreds?.email || getQoderUserEmailFallback(providerMode);
const machineID = cachedCreds?.machineID || getMachineId();
const qoderModel = isQoderCNMode(providerMode) ? getQoderCNDirectModel(model.id) : model.id;
const modelConfig = getCachedModelConfig(qoderModel, providerMode) || {
key: qoderModel,
is_reasoning:
qoderModel === "ultimate" ||
qoderModel === "performance" ||
qoderModel.includes("dmodel") ||
qoderModel.includes("dfmodel"),
// The model `id` pi exposes is the upstream display_name (whitespace
// stripped) for CN, or the raw key for the international site. The
// request-time upstream `key` is read back from the cached model config
// (which stores the original entry keyed by both `key` and `id`), so no
// key<->friendlyId mapping table is needed here.
const modelConfig = getCachedModelConfig(model.id, providerMode) || {
key: model.id,
is_reasoning: false,
max_output_tokens: 32768,
source: "system",
};
modelConfig.key = qoderModel;
// Use the cached entry's original upstream key when available; fall back to
// the pi id (international site already uses the key as id).
const qoderModel = modelConfig.key || model.id;
const isReasoning = !!modelConfig.is_reasoning;
const maxOutputTokens = modelConfig.max_output_tokens || 32768;