dsh-unified-router 0.8.7 → 0.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/QODER-CLI.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Qoder CN:官方 CLI 取目录可行性与集成方案
2
2
 
3
+ ## 上下文档位
4
+
5
+ Qoder 中国版的富目录将默认上下文和逐模型可选档位分开保存。目录给出 200K(默认)、400K、1M 时才会显示这三档;只有单一档或没有档位信息时,不从其他模型推断。旧版缓存只有模型名称和 ID,升级后在「Qoder 中国版 → 模型 → 刷新目录」重新读取富目录。单纯的 CLI 文本列表不提供这些字段。
6
+
7
+ 设置页和独立后端的输入栏快捷档共用模型设置。切换后,DSH 的预算和 Qoder 请求的 `parameters.context_length` 使用同一个已确认档位;不会改写账号、模型 ID 或其他模型参数。共用外部后端仍不提供快捷写入。
8
+
3
9
  2026-11-19 本机官方 CLI 的 `--list-models` 返回 14 条,已按实际名单更新内置目录。已知展示名继续对应原调用 ID。本次新增的 Qwen4 Max、Qwen4 Max Preview 和 Step 5 Preview 只有展示名,CLI 富字段接口要求独立登录,当前保留展示名与已确认的元数据。成功刷新会保存目录,下一次启动和刷新失败时沿用上次成功结果。
4
10
 
5
11
  > 2026-11-17 只读勘察(qoder-feasibility 子代理)。方向由用户拍板:**直接用官方 CLI 登录/拉取,不重实现签名、不造轮子**。
package/lib/backend.js CHANGED
@@ -2244,7 +2244,7 @@ var modelBrands = {
2244
2244
  };
2245
2245
  var modelAliases = /* @__PURE__ */ new Map([
2246
2246
  ["qmodel_38max", "Qwen 3.8 Max"],
2247
- ["qmodel_latest", "Qwen 3.8 Max"],
2247
+ ["qmodel_latest", "Qwen 4 Max"],
2248
2248
  ["qfmodel", "Qwen 3.8 Flash"],
2249
2249
  ["dmodel", "DeepSeek V4 Pro"],
2250
2250
  ["dfmodel", "DeepSeek Flash"],
@@ -2350,10 +2350,12 @@ var catalogIdentities = {
2350
2350
  qodercn: {
2351
2351
  qmodel_38max: "qwen-3-8-max",
2352
2352
  qfmodel: "qwen-3-8-flash",
2353
+ qmodel_latest: "qwen-4-max",
2353
2354
  dmodel: "deepseek-v4-pro",
2354
2355
  dfmodel: "deepseek-flash",
2355
2356
  gmodel: "glm-5-3",
2356
2357
  gfmodel: "glm-5-3-flash",
2358
+ gmodel_latest: "glm-5-4",
2357
2359
  kmodel_latest: "kimi-k3-1-pro",
2358
2360
  kmodel: "kimi-k2-8-preview",
2359
2361
  mmodel: "minimax-m3-1-flash"
@@ -2419,10 +2421,6 @@ var providerNamedSuccessors = {
2419
2421
  ["qwen-3-6-plus", "qwen-3-8-max"],
2420
2422
  ["minimax-m2-7", "minimax-m3-1-flash"],
2421
2423
  ["kimi-k2-6", "kimi-k3-1-pro"]
2422
- ]),
2423
- workbuddy: /* @__PURE__ */ new Map([
2424
- // 同目录存在完全同型号的免费版 hy4flash-free,收费版 hy4flash 不再默认启用。
2425
- ["hy4flash", "hy4flash-free"]
2426
2424
  ])
2427
2425
  };
2428
2426
  var obsoleteIdentities = /* @__PURE__ */ new Set([
@@ -2520,11 +2518,12 @@ function modelRecommendationExclusions(models, provider) {
2520
2518
  const exclusions = /* @__PURE__ */ new Map();
2521
2519
  const candidates = [];
2522
2520
  const aliveModels = models.filter((model) => !model.dead);
2521
+ const obsolete = (identity) => obsoleteIdentities.has(identity) || provider === "qodercn" && /^qwen-3-8(?:-|$)/.test(identity);
2523
2522
  const hasModernSurvivor = aliveModels.some((model) => {
2524
2523
  if (older.has(model.id) || model.stale) return false;
2525
2524
  const identity = catalogIdentity(model.id, provider);
2526
2525
  const baseIdentity = stripReleaseSuffix(identity);
2527
- return !obsoleteIdentities.has(identity) && !obsoleteIdentities.has(baseIdentity);
2526
+ return !obsolete(identity) && !obsolete(baseIdentity);
2528
2527
  });
2529
2528
  for (const model of aliveModels) {
2530
2529
  const identity = catalogIdentity(model.id, provider);
@@ -2533,7 +2532,7 @@ function modelRecommendationExclusions(models, provider) {
2533
2532
  exclusions.set(model.id, { kind: "older", alternative: older.get(model.id) });
2534
2533
  continue;
2535
2534
  }
2536
- if (hasModernSurvivor && (obsoleteIdentities.has(identity) || obsoleteIdentities.has(baseIdentity))) {
2535
+ if (hasModernSurvivor && (obsolete(identity) || obsolete(baseIdentity))) {
2537
2536
  exclusions.set(model.id, { kind: "older", alternative: void 0 });
2538
2537
  continue;
2539
2538
  }
@@ -5970,11 +5969,29 @@ function mergeQoderCatalog(cli, fallback, requireKey = true) {
5970
5969
  }
5971
5970
  return out;
5972
5971
  }
5972
+ function qoderCachedCapabilities(row) {
5973
+ const validToken = (n) => typeof n === "number" && Number.isSafeInteger(n) && n > 0 && n <= 1e7;
5974
+ const options = Array.isArray(row?.contextOptions) ? [...new Set(row.contextOptions.filter(validToken))].sort((a, b) => a - b).slice(0, 16) : [];
5975
+ const context = row?.contextWindow;
5976
+ const efforts = Array.isArray(row?.efforts) ? [...new Set(row.efforts.filter((e) => typeof e === "string" && /^[a-z0-9_-]{1,32}$/i.test(e)))].slice(0, 16) : void 0;
5977
+ return {
5978
+ ...validToken(context) ? { contextWindow: context } : {},
5979
+ ...validToken(context) && options.includes(context) ? { contextOptions: options } : {},
5980
+ ...typeof row?.supportsImage === "boolean" ? { supportsImage: row.supportsImage } : {},
5981
+ ...typeof row?.supportsThinking === "boolean" ? { supportsThinking: row.supportsThinking } : {},
5982
+ ...typeof row?.supportsDisable === "boolean" ? { supportsDisable: row.supportsDisable } : {},
5983
+ ...efforts !== void 0 ? { efforts } : {},
5984
+ ...typeof row?.defaultEffort === "string" && efforts?.includes(row.defaultEffort) ? { defaultEffort: row.defaultEffort } : {},
5985
+ ...validToken(row?.maxTokens) ? { maxTokens: row.maxTokens } : {}
5986
+ };
5987
+ }
5973
5988
  function readQoderCatalog(file, fallback) {
5974
5989
  try {
5975
5990
  const rows = JSON.parse(readFileSync6(file, "utf8"));
5976
5991
  if (!Array.isArray(rows)) return null;
5977
- const catalog = mergeQoderCatalog(rows.filter((row) => typeof row?.id === "string" && row.id.length <= 256 && typeof row.name === "string" && row.name.length <= 160).slice(0, 512), fallback);
5992
+ const input = rows.filter((row) => typeof row?.id === "string" && row.id.length <= 256 && typeof row.name === "string" && row.name.length <= 160).slice(0, 512);
5993
+ const byId = new Map(input.map((row) => [row.id, row]));
5994
+ const catalog = mergeQoderCatalog(input, fallback).map((model) => ({ ...model, ...qoderCachedCapabilities(byId.get(model.id)) }));
5978
5995
  return catalog.length ? catalog : null;
5979
5996
  } catch {
5980
5997
  return null;
@@ -5984,7 +6001,11 @@ async function saveQoderCatalog(file, catalog) {
5984
6001
  const temporary = file + "." + randomUUID2() + ".tmp";
5985
6002
  try {
5986
6003
  await mkdir(dirname2(file), { recursive: true, mode: 448 });
5987
- await writeFile(temporary, JSON.stringify(catalog.map(({ id, name }) => ({ id, name }))), { mode: 384 });
6004
+ await writeFile(temporary, JSON.stringify(catalog.map((model) => ({
6005
+ id: model.id,
6006
+ name: model.name,
6007
+ ...qoderCachedCapabilities(model)
6008
+ }))), { mode: 384 });
5988
6009
  await rename(temporary, file);
5989
6010
  } finally {
5990
6011
  await unlink(temporary).catch(() => {
@@ -6067,23 +6088,29 @@ function toQoderModelRow(entry) {
6067
6088
  const value = (row.thinking_config?.enabled?.efforts)[effort];
6068
6089
  return value?.is_default === true;
6069
6090
  });
6070
- const defaults = object(row.context_config) ? Object.values(row.context_config) : [];
6071
- const preferred = Number((defaults.find((cfg) => cfg?.is_default === true) ?? defaults[0])?.token_count);
6072
- const contextWindow = Number.isFinite(preferred) && preferred > 0 ? preferred : Number(row.max_input_tokens);
6073
- const priceFactor = Number(row.price_factor);
6091
+ const sizes = object(row.context_config) ? Object.values(row.context_config).flatMap((cfg) => {
6092
+ if (!object(cfg)) return [];
6093
+ const tokens = typeof cfg.token_count === "string" && /^\d+$/.test(cfg.token_count) ? Number(cfg.token_count) : cfg.token_count;
6094
+ return typeof tokens === "number" && Number.isSafeInteger(tokens) && tokens > 0 && tokens <= 1e7 ? [{ tokens, preferred: cfg.is_default === true }] : [];
6095
+ }) : [];
6096
+ const contextOptions = [...new Set(sizes.map((cfg) => cfg.tokens))].sort((a, b) => a - b).slice(0, 16);
6097
+ const contextWindow = sizes.find((cfg) => cfg.preferred && contextOptions.includes(cfg.tokens))?.tokens ?? contextOptions[0] ?? Number(row.max_input_tokens);
6098
+ const rawPrice = row.price_factor;
6099
+ const priceFactor = typeof rawPrice === "number" || typeof rawPrice === "string" && rawPrice.trim() !== "" ? Number(rawPrice) : NaN;
6074
6100
  return {
6075
6101
  id: row.key,
6076
6102
  name: nonEmptyString(row.display_name) ? row.display_name : row.key,
6077
6103
  // `0` 是「未知窗口」哨兵(宿主投影按 `> 0` 过滤),不编造。
6078
- contextWindow: Number.isFinite(contextWindow) && contextWindow > 0 ? contextWindow : 0,
6104
+ contextWindow: Number.isSafeInteger(contextWindow) && contextWindow > 0 && contextWindow <= 1e7 ? contextWindow : 0,
6105
+ ...contextOptions.length ? { contextOptions } : {},
6079
6106
  supportsImage: row.is_vl === true,
6080
6107
  // ⚠️ 上游 `is_reasoning` 与「是否产出 reasoning_content」不完全一致:
6081
6108
  // `dfmodel` 报 `is_reasoning:false` 但实测 50/57 帧有思考,且目录给了
6082
6109
  // 三个档位。有档位即可思考 —— 不要用 `is_reasoning:false` 把档位选择器关掉。
6083
6110
  supportsThinking: row.is_reasoning === true || efforts.length > 0,
6084
- ...efforts.length > 0 ? { efforts } : {},
6111
+ efforts,
6085
6112
  ...defaultEffort !== void 0 ? { defaultEffort } : {},
6086
- ...row.thinking_config?.disabled !== void 0 ? { supportsDisable: true } : {},
6113
+ supportsDisable: row.thinking_config?.disabled !== void 0,
6087
6114
  // ⚠️ `0` 是合法的「免费」倍率,不能当缺失处理(`Number.isFinite` 判据)。
6088
6115
  ...Number.isFinite(priceFactor) && priceFactor >= 0 ? { priceFactor } : {}
6089
6116
  };
@@ -7505,6 +7532,16 @@ var QoderAdapter = class extends LlmAdapter {
7505
7532
  const override = this.options.accountPool?.modelParamsFor?.(this.product.id, model)?.supportsImage;
7506
7533
  return (override ?? this.modelEntry(model)?.supportsImage) === true ? ["text", "image"] : ["text"];
7507
7534
  }
7535
+ outputBudget(entry, contextWindow, requested) {
7536
+ const budget = requested ?? defaultModelOutputTokens(entry?.maxTokens, contextWindow);
7537
+ if (contextWindow === void 0 || budget < contextWindow) return budget;
7538
+ return Math.max(1, Math.min(32768, contextWindow - 1));
7539
+ }
7540
+ contextFor(model, entry = this.modelEntry(model)) {
7541
+ const override = this.options.accountPool?.modelParamsFor?.(this.product.id, model)?.contextWindow;
7542
+ if (override !== void 0 && entry?.contextOptions?.includes(override)) return override;
7543
+ return entry && entry.contextWindow > 0 ? entry.contextWindow : void 0;
7544
+ }
7508
7545
  modelEntry(id) {
7509
7546
  return this.cliCatalog?.find((model) => model.id === id) ?? this.fallbackIndex.get(id);
7510
7547
  }
@@ -7546,10 +7583,11 @@ var QoderAdapter = class extends LlmAdapter {
7546
7583
  return {
7547
7584
  id: model.id,
7548
7585
  name: readableModelName(model.id, qoderDisplayName(model)),
7549
- defaultMaxTokens: defaultModelOutputTokens(model.maxTokens, model.contextWindow),
7586
+ defaultMaxTokens: this.outputBudget(model, model.contextWindow || void 0),
7550
7587
  rateBadge: qoderRateBadge(model),
7551
7588
  ...model.subscriptionOnly === true || fallback?.subscriptionOnly === true ? { subscriptionOnly: true } : {},
7552
- ...typeof model.contextWindow === "number" ? { contextWindow: model.contextWindow } : {},
7589
+ contextWindow: model.contextWindow,
7590
+ contextOptions: model.contextOptions ?? (model.contextWindow > 0 ? [model.contextWindow] : []),
7553
7591
  ...typeof model.maxTokens === "number" ? { maxTokens: model.maxTokens } : {},
7554
7592
  efforts: qoderEffortsFor(model),
7555
7593
  defaultEffort: qoderDefaultEffort(model),
@@ -7586,9 +7624,13 @@ var QoderAdapter = class extends LlmAdapter {
7586
7624
  );
7587
7625
  this.catalogIssue = result.issue;
7588
7626
  if (catalog) {
7589
- this.cliCatalog = catalog;
7627
+ const previous = new Map(this.cliCatalog?.map((model) => [model.id, model]));
7628
+ this.cliCatalog = catalog.map((model) => {
7629
+ const old = previous.get(model.id);
7630
+ return { ...model, ...qoderCachedCapabilities(old) };
7631
+ });
7590
7632
  this.catalogSource = "remote";
7591
- if (this.options.cliCatalogFile) await saveQoderCatalog(this.options.cliCatalogFile, catalog).catch(() => {
7633
+ if (this.options.cliCatalogFile) await saveQoderCatalog(this.options.cliCatalogFile, this.cliCatalog).catch(() => {
7592
7634
  });
7593
7635
  } else {
7594
7636
  this.catalogSource = this.cliCatalog ? "cached" : "fallback";
@@ -7651,14 +7693,16 @@ var QoderAdapter = class extends LlmAdapter {
7651
7693
  */
7652
7694
  async resolveModel(provider, model, _signal) {
7653
7695
  const entry = this.modelEntry(model);
7696
+ const contextWindow = this.contextFor(model, entry);
7697
+ const override = this.options.accountPool?.modelParamsFor?.(provider, model)?.maxTokens;
7654
7698
  const resolved = {
7655
7699
  provider,
7656
7700
  id: model,
7657
7701
  name: readableModelName(model, entry?.name),
7658
7702
  inputModalities: this.inputModalitiesFor(model),
7659
- defaultMaxTokens: defaultModelOutputTokens(entry?.maxTokens, entry?.contextWindow)
7703
+ defaultMaxTokens: this.outputBudget(entry, contextWindow, override)
7660
7704
  };
7661
- if (entry && entry.contextWindow > 0) resolved.context = { contextWindow: entry.contextWindow };
7705
+ if (contextWindow !== void 0) resolved.context = { contextWindow };
7662
7706
  if (entry !== void 0) {
7663
7707
  const efforts = qoderEffortsFor(entry);
7664
7708
  if (efforts.length > 0) {
@@ -7730,10 +7774,12 @@ var QoderAdapter = class extends LlmAdapter {
7730
7774
  const history = buildQoderHistory(messages);
7731
7775
  const tools = buildQoderTools(options.tools);
7732
7776
  const fallback = this.modelEntry(options.model);
7733
- const maxTokens = options.maxTokens ?? defaultModelOutputTokens(fallback?.maxTokens, fallback?.contextWindow);
7777
+ const contextWindow = this.contextFor(options.model, fallback);
7778
+ const configuredMax = this.options.accountPool?.modelParamsFor?.(this.product.id, options.model)?.maxTokens;
7779
+ const maxTokens = this.outputBudget(fallback, contextWindow, options.maxTokens ?? configuredMax);
7734
7780
  const reasoningEffort = options.reasoningEffort ?? (fallback && qoderDefaultEffort(fallback));
7735
7781
  const buildRequest = async (c) => {
7736
- const client = await QoderEncryptedInfer.create({
7782
+ const client = await (this.options.createEncryptedInfer ?? QoderEncryptedInfer.create)({
7737
7783
  user: {
7738
7784
  uid: c.uid,
7739
7785
  securityOauthToken: c.security_oauth_token ?? c.access_token
@@ -7762,6 +7808,7 @@ var QoderAdapter = class extends LlmAdapter {
7762
7808
  ...this.inputModalitiesFor(options.model).includes("image") ? { isVl: true } : fallback?.supportsImage === false ? { isVl: false } : {},
7763
7809
  // 官方 `model_config` 的 display_name / max_input_tokens 必须带上。
7764
7810
  ...fallback?.name !== void 0 ? { displayName: fallback.name } : {},
7811
+ ...fallback?.contextOptions?.includes(contextWindow ?? 0) ? { contextWindow } : {},
7765
7812
  ...fallback && fallback.contextWindow > 0 ? { maxInputTokens: fallback.contextWindow } : {},
7766
7813
  // ⚠️ **`business` 必填**,否则服务端把请求路由到错误的后端节点。
7767
7814
  //
@@ -11548,6 +11595,7 @@ function registerChannelPackEndpoints(ctx, pool, qoder, qoderCn, trae, raccoon,
11548
11595
  ...model.rateBadge === void 0 ? {} : { rateBadge: model.rateBadge },
11549
11596
  // 能力元数据:界面据此只渲染该模型真正支持的档位(不猜、不给做不到的选项)。
11550
11597
  ...model.contextWindow === void 0 ? {} : { contextWindow: model.contextWindow },
11598
+ ...model.contextOptions === void 0 ? {} : { contextOptions: [...model.contextOptions] },
11551
11599
  ...model.maxTokens === void 0 ? {} : { maxTokens: model.maxTokens },
11552
11600
  ...model.defaultMaxTokens === void 0 ? {} : { defaultMaxTokens: model.defaultMaxTokens },
11553
11601
  ...model.stale === true ? { stale: true } : {},
@@ -11677,7 +11725,8 @@ function registerChannelPackEndpoints(ctx, pool, qoder, qoderCn, trae, raccoon,
11677
11725
  const capacity = row?.contextWindow;
11678
11726
  const output = previous?.maxTokens ?? row?.defaultMaxTokens;
11679
11727
  const target = value2 ?? capacity;
11680
- if (capacity === void 0 || capacity <= 0 || target === void 0 || target > capacity || output !== void 0 && target <= output) {
11728
+ const supported = target !== void 0 && (row?.contextOptions !== void 0 ? row.contextOptions.includes(target) : capacity !== void 0 && capacity > 0 && target <= capacity);
11729
+ if (!supported || target !== void 0 && output !== void 0 && target <= output) {
11681
11730
  return { ok: false, error: { code: "bad-request", message: "\u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u51FA\u76EE\u5F55\u5BB9\u91CF\u8303\u56F4\u6216\u5C0F\u4E8E\u7B49\u4E8E\u8F93\u51FA\u9884\u7559" } };
11682
11731
  }
11683
11732
  const merged = { ...previous };
@@ -11687,6 +11736,17 @@ function registerChannelPackEndpoints(ctx, pool, qoder, qoderCn, trae, raccoon,
11687
11736
  } else {
11688
11737
  const params = req.contextOnly === true ? void 0 : req.params;
11689
11738
  const next2 = field === void 0 ? params : { ...previous, [field]: params?.[field] };
11739
+ if (req.provider === "qodercn" && (field === void 0 || field === "maxTokens")) {
11740
+ const row = modelAdapters?.[req.provider]?.listAllModels().find((model) => model.id === req.modelId);
11741
+ const requestedContext = next2?.contextWindow;
11742
+ const explicitlyWritten = field === void 0 && requestedContext !== void 0;
11743
+ const supported = requestedContext !== void 0 && row?.contextOptions?.includes(requestedContext);
11744
+ const context = supported ? requestedContext : row?.contextWindow;
11745
+ const output = next2?.maxTokens ?? row?.defaultMaxTokens;
11746
+ if (explicitlyWritten && !supported || context !== void 0 && context > 0 && output !== void 0 && output >= context) {
11747
+ return { ok: false, error: { code: "bad-request", message: "\u4E0A\u4E0B\u6587\u6863\u4F4D\u672A\u83B7\u76EE\u5F55\u786E\u8BA4\uFF0C\u6216\u7A97\u53E3\u5C0F\u4E8E\u7B49\u4E8E\u8F93\u51FA\u9884\u7559" } };
11748
+ }
11749
+ }
11690
11750
  const requestedEffort = field === void 0 || field === "reasoningEffort" ? next2?.reasoningEffort : void 0;
11691
11751
  if (typeof requestedEffort === "string" && requestedEffort.length > 0) {
11692
11752
  const row = modelAdapters?.[req.provider]?.listAllModels().find((model) => model.id === req.modelId);
@@ -16532,8 +16592,8 @@ function mountBackend(ctx, onRpc, options = {}) {
16532
16592
  if (!info || override === void 0) return info;
16533
16593
  const next = {
16534
16594
  ...info,
16535
- ...override.contextWindow === void 0 ? {} : { context: { ...info.context, contextWindow: override.contextWindow } },
16536
- ...override.maxTokens === void 0 ? {} : { defaultMaxTokens: override.maxTokens }
16595
+ ...args[0] === "qodercn" || override.contextWindow === void 0 ? {} : { context: { ...info.context, contextWindow: override.contextWindow } },
16596
+ ...args[0] === "qodercn" || override.maxTokens === void 0 ? {} : { defaultMaxTokens: override.maxTokens }
16537
16597
  };
16538
16598
  const effort = override.reasoningEffort;
16539
16599
  const efforts = next.reasoning?.efforts;
@@ -92,6 +92,13 @@ export function accountView(wire, provider) {
92
92
  * ⚠️ 能力字段(`contextWindow` / `maxTokens` / `efforts` / `supportsImage`)**缺席即未知**:
93
93
  * 界面据此不给对应控件,不猜模型有什么能力。`stale` / `subscriptionOnly` 同理。
94
94
  */
95
+ function modelContextOptions(value, defaultValue) {
96
+ if (!Array.isArray(value)) return null
97
+ const sizes = [...new Set(value.filter(n => Number.isSafeInteger(n) && n > 0 && n <= 10_000_000))]
98
+ .sort((a, b) => a - b).slice(0, 16)
99
+ return sizes.includes(defaultValue) ? sizes : []
100
+ }
101
+
95
102
  export function modelWire(raw) {
96
103
  const source = raw && typeof raw === 'object' ? raw : {}
97
104
  const contextWindow = wireFinite(source.contextWindow)
@@ -110,6 +117,7 @@ export function modelWire(raw) {
110
117
  isFree: source.isFree === true,
111
118
  ...(source.subscriptionOnly === true ? { subscriptionOnly: true } : {}),
112
119
  ...(contextWindow !== null && contextWindow > 0 ? { contextWindow } : {}),
120
+ ...(Array.isArray(source.contextOptions) ? { contextOptions: modelContextOptions(source.contextOptions, contextWindow) } : {}),
113
121
  ...(maxTokens !== null && maxTokens > 0 ? { maxTokens } : {}),
114
122
  ...(defaultMaxTokens !== null && defaultMaxTokens > 0 ? { defaultMaxTokens } : {}),
115
123
  ...(Array.isArray(source.efforts) ? { efforts: source.efforts.filter(x => typeof x === 'string').slice(0, 8) } : {}),
@@ -161,6 +169,7 @@ export function modelView(wire, provider) {
161
169
  isFree: source.isFree === true,
162
170
  subscriptionOnly: source.subscriptionOnly === true,
163
171
  contextWindow: wireFinite(source.contextWindow),
172
+ ...(Array.isArray(source.contextOptions) ? { contextOptions: modelContextOptions(source.contextOptions, wireFinite(source.contextWindow)) } : {}),
164
173
  maxTokens: wireFinite(source.maxTokens),
165
174
  defaultMaxTokens: wireFinite(source.defaultMaxTokens),
166
175
  efforts: Array.isArray(source.efforts) ? source.efforts.filter(x => typeof x === 'string').slice(0, 8) : [],
package/lib/client.js CHANGED
@@ -97,7 +97,7 @@ const modelBrands = {
97
97
  }
98
98
 
99
99
  const modelAliases = new Map([
100
- ['qmodel_38max', 'Qwen 3.8 Max'], ['qmodel_latest', 'Qwen 3.8 Max'],
100
+ ['qmodel_38max', 'Qwen 3.8 Max'], ['qmodel_latest', 'Qwen 4 Max'],
101
101
  ['qfmodel', 'Qwen 3.8 Flash'], ['dmodel', 'DeepSeek V4 Pro'], ['dfmodel', 'DeepSeek Flash'],
102
102
  ['gmodel', 'GLM 5.3'], ['gfmodel', 'GLM 5.3 Flash'], ['kmodel_latest', 'Kimi K3.1 Pro'],
103
103
  ['kmodel', 'Kimi K2.8 Preview'], ['mmodel', 'MiniMax M3.1 Flash'],
@@ -254,9 +254,9 @@ function modelIdentity(value) {
254
254
  // deployments, aliases or account tiers. Keep ambiguous aliases provider-scoped.
255
255
  const catalogIdentities = {
256
256
  qodercn: {
257
- qmodel_38max: 'qwen-3-8-max', qfmodel: 'qwen-3-8-flash',
257
+ qmodel_38max: 'qwen-3-8-max', qfmodel: 'qwen-3-8-flash', qmodel_latest: 'qwen-4-max',
258
258
  dmodel: 'deepseek-v4-pro', dfmodel: 'deepseek-flash',
259
- gmodel: 'glm-5-3', gfmodel: 'glm-5-3-flash', kmodel_latest: 'kimi-k3-1-pro',
259
+ gmodel: 'glm-5-3', gfmodel: 'glm-5-3-flash', gmodel_latest: 'glm-5-4', kmodel_latest: 'kimi-k3-1-pro',
260
260
  kmodel: 'kimi-k2-8-preview', mmodel: 'minimax-m3-1-flash',
261
261
  },
262
262
  trae: { 'deepseek-v4-pro-official': 'deepseek-v4-pro-0813' },
@@ -326,10 +326,6 @@ const providerNamedSuccessors = {
326
326
  ['minimax-m2-7', 'minimax-m3-1-flash'],
327
327
  ['kimi-k2-6', 'kimi-k3-1-pro'],
328
328
  ]),
329
- workbuddy: new Map([
330
- // 同目录存在完全同型号的免费版 hy4flash-free,收费版 hy4flash 不再默认启用。
331
- ['hy4flash', 'hy4flash-free'],
332
- ]),
333
329
  }
334
330
 
335
331
  // 全平台已明确过时的老一代型号:即使单个渠道目录里没有同族新代,只要目录里还存在
@@ -426,11 +422,13 @@ function modelRecommendationExclusions(models, provider) {
426
422
  const exclusions = new Map()
427
423
  const candidates = []
428
424
  const aliveModels = models.filter(model => !model.dead)
425
+ const obsolete = identity => obsoleteIdentities.has(identity)
426
+ || (provider === 'qodercn' && /^qwen-3-8(?:-|$)/.test(identity))
429
427
  const hasModernSurvivor = aliveModels.some(model => {
430
428
  if (older.has(model.id) || model.stale) return false
431
429
  const identity = catalogIdentity(model.id, provider)
432
430
  const baseIdentity = stripReleaseSuffix(identity)
433
- return !obsoleteIdentities.has(identity) && !obsoleteIdentities.has(baseIdentity)
431
+ return !obsolete(identity) && !obsolete(baseIdentity)
434
432
  })
435
433
  for (const model of aliveModels) {
436
434
  const identity = catalogIdentity(model.id, provider)
@@ -439,7 +437,7 @@ function modelRecommendationExclusions(models, provider) {
439
437
  exclusions.set(model.id, { kind: 'older', alternative: older.get(model.id) })
440
438
  continue
441
439
  }
442
- if (hasModernSurvivor && (obsoleteIdentities.has(identity) || obsoleteIdentities.has(baseIdentity))) {
440
+ if (hasModernSurvivor && (obsolete(identity) || obsolete(baseIdentity))) {
443
441
  exclusions.set(model.id, { kind: 'older', alternative: undefined })
444
442
  continue
445
443
  }
@@ -680,6 +678,13 @@ function accountView(wire, provider) {
680
678
  * ⚠️ 能力字段(`contextWindow` / `maxTokens` / `efforts` / `supportsImage`)**缺席即未知**:
681
679
  * 界面据此不给对应控件,不猜模型有什么能力。`stale` / `subscriptionOnly` 同理。
682
680
  */
681
+ function modelContextOptions(value, defaultValue) {
682
+ if (!Array.isArray(value)) return null
683
+ const sizes = [...new Set(value.filter(n => Number.isSafeInteger(n) && n > 0 && n <= 10_000_000))]
684
+ .sort((a, b) => a - b).slice(0, 16)
685
+ return sizes.includes(defaultValue) ? sizes : []
686
+ }
687
+
683
688
  function modelWire(raw) {
684
689
  const source = raw && typeof raw === 'object' ? raw : {}
685
690
  const contextWindow = wireFinite(source.contextWindow)
@@ -698,6 +703,7 @@ function modelWire(raw) {
698
703
  isFree: source.isFree === true,
699
704
  ...(source.subscriptionOnly === true ? { subscriptionOnly: true } : {}),
700
705
  ...(contextWindow !== null && contextWindow > 0 ? { contextWindow } : {}),
706
+ ...(Array.isArray(source.contextOptions) ? { contextOptions: modelContextOptions(source.contextOptions, contextWindow) } : {}),
701
707
  ...(maxTokens !== null && maxTokens > 0 ? { maxTokens } : {}),
702
708
  ...(defaultMaxTokens !== null && defaultMaxTokens > 0 ? { defaultMaxTokens } : {}),
703
709
  ...(Array.isArray(source.efforts) ? { efforts: source.efforts.filter(x => typeof x === 'string').slice(0, 8) } : {}),
@@ -749,6 +755,7 @@ function modelView(wire, provider) {
749
755
  isFree: source.isFree === true,
750
756
  subscriptionOnly: source.subscriptionOnly === true,
751
757
  contextWindow: wireFinite(source.contextWindow),
758
+ ...(Array.isArray(source.contextOptions) ? { contextOptions: modelContextOptions(source.contextOptions, wireFinite(source.contextWindow)) } : {}),
752
759
  maxTokens: wireFinite(source.maxTokens),
753
760
  defaultMaxTokens: wireFinite(source.defaultMaxTokens),
754
761
  efforts: Array.isArray(source.efforts) ? source.efforts.filter(x => typeof x === 'string').slice(0, 8) : [],
@@ -3877,6 +3884,8 @@ function outputButtons({ choices, value, context, disabled, onChange }) {
3877
3884
 
3878
3885
  function ModelParams({ value, model, providerId, disabled, onSave }) {
3879
3886
  const current = value || {}
3887
+ const contextOverride = model.contextOptions && !model.contextOptions.includes(current.contextWindow)
3888
+ ? null : current.contextWindow
3880
3889
  const outputTiers = outputTiersForModel(model, providerId)
3881
3890
  const efforts = Array.isArray(model.efforts) ? model.efforts : []
3882
3891
  // 即点即存,保存成功或失败都留在当前编辑器,便于连续调整或重试。
@@ -3885,7 +3894,9 @@ function ModelParams({ value, model, providerId, disabled, onSave }) {
3885
3894
  const vision = typeof model.supportsImage === 'boolean' ? model.supportsImage : null
3886
3895
  return h('div', { className: 'eac-params' },
3887
3896
  modelTokenValue(model.contextWindow) || modelTokenValue(current.contextWindow)
3888
- ? ContextWindowField({ capacity: model.contextWindow, override: current.contextWindow, reserve: current.maxTokens ?? model.defaultMaxTokens,
3897
+ ? ContextWindowField({ capacity: model.contextWindow, exact: model.contextOptions,
3898
+ override: contextOverride,
3899
+ reserve: current.maxTokens ?? model.defaultMaxTokens,
3889
3900
  // 渠道自己声明的上下文档位(如 Qoder 的 200K/400K/1M);没声明用默认表。
3890
3901
  tiers: providerCaps(providerId)?.contextTiers,
3891
3902
  disabled, onChange: value => set('contextWindow', value) }) : null,
@@ -3893,7 +3904,7 @@ function ModelParams({ value, model, providerId, disabled, onSave }) {
3893
3904
  h('p', { className: 'eac-group-title' }, '输出上限'),
3894
3905
  h('div', { className: 'eac-tier-row', role: 'group', 'aria-label': '输出上限' },
3895
3906
  ...outputButtons({ choices: outputChoices(outputTiers, model.defaultMaxTokens), value: current.maxTokens,
3896
- context: current.contextWindow ?? model.contextWindow, disabled, onChange: value => set('maxTokens', value) }))) : null,
3907
+ context: contextOverride ?? model.contextWindow, disabled, onChange: value => set('maxTokens', value) }))) : null,
3897
3908
  efforts.length ? h('div', { className: 'eac-param-group' },
3898
3909
  h('p', { className: 'eac-group-title' }, '思考深度'),
3899
3910
  h('div', { className: 'eac-tier-row', role: 'group', 'aria-label': '思考深度' },
@@ -5449,8 +5460,7 @@ const qodercn = {
5449
5460
  pack: true,
5450
5461
  caps: {
5451
5462
  cliCatalog: true,
5452
- // 上游目录(`context_config`)对每个模型都给 200K(默认)/400K/1M 三档;
5453
- // 与默认表的 256K/500K 不同,故按渠道声明,不改全局表。
5463
+ // 仅提供显示名称;实际可选档位由模型各自的 contextOptions 决定。
5454
5464
  contextTiers: [
5455
5465
  { label: '200K', tokens: 200_000, nativeMax: 262_144 },
5456
5466
  { label: '400K', tokens: 400_000, nativeMax: 524_288 },
@@ -6435,7 +6445,15 @@ const CONTEXT_WINDOWS = Object.freeze([
6435
6445
  * @param declared 渠道自己声明的档位(`caps.contextTiers`),如 Qoder 的
6436
6446
  * `200K/400K/1M`。**没声明就用默认表** —— 全局表不该被某个渠道的口径改写。
6437
6447
  */
6438
- function contextWindowTiers(capacity, declared) {
6448
+ function contextWindowTiers(capacity, declared, exact) {
6449
+ if (Array.isArray(exact) && modelTokenValue(capacity)) {
6450
+ const sizes = exact.includes(capacity) ? exact : [capacity]
6451
+ return sizes.map(tokens => ({
6452
+ label: declared?.find(tier => tier.tokens === tokens)?.label
6453
+ ?? (tokens % 1_000_000 === 0 ? `${tokens / 1_000_000}M` : tokens % 1_000 === 0 ? `${tokens / 1_000}K` : tokens.toLocaleString('zh-CN')),
6454
+ tokens, restore: tokens === capacity,
6455
+ }))
6456
+ }
6439
6457
  const known = modelTokenValue(capacity)
6440
6458
  const table = Array.isArray(declared) && declared.length > 0
6441
6459
  ? declared.slice().sort((a, b) => a.tokens - b.tokens)
@@ -6461,8 +6479,8 @@ function moveContextFocus(event) {
6461
6479
  buttons[next].focus()
6462
6480
  }
6463
6481
 
6464
- function ContextSegments({ capacity, override, reserve, disabled, busy, tiers: declared, onChange }) {
6465
- const tiers = contextWindowTiers(capacity, declared)
6482
+ function ContextSegments({ capacity, override, reserve, disabled, busy, tiers: declared, exact, onChange }) {
6483
+ const tiers = contextWindowTiers(capacity, declared, exact)
6466
6484
  const custom = isCustomContext(override, tiers)
6467
6485
  const limitNote = modelTokenValue(reserve) && tiers.some(tier => modelTokenValue(tier.tokens) && tier.tokens <= reserve)
6468
6486
  ? `输出预留 ${formatTokens(reserve)},部分档位需要更大的窗口` : undefined
@@ -6530,8 +6548,10 @@ async function readContextPill(call, kind, provider, modelId, signal) {
6530
6548
  const declared = kind === 'pack' ? row.contextWindow : row.defaultContextWindow ?? row.contextWindow
6531
6549
  const capacity = modelTokenValue(declared) ? declared : null
6532
6550
  const reserve = options.maxTokens ?? row.defaultMaxOutputLength ?? row.defaultMaxTokens ?? row.maxOutputLength
6533
- const override = modelTokenValue(options.contextWindow) ? options.contextWindow : null
6534
- return { capacity, reserve: modelTokenValue(reserve) ? reserve : null, override }
6551
+ const exact = modelContextOptions(row.contextOptions, capacity)
6552
+ const override = modelTokenValue(options.contextWindow) && (exact === null || exact.includes(options.contextWindow))
6553
+ ? options.contextWindow : null
6554
+ return { capacity, exact, tiers: exact === null ? undefined : providerCaps(provider)?.contextTiers, reserve: modelTokenValue(reserve) ? reserve : null, override }
6535
6555
  }
6536
6556
 
6537
6557
  function ContextTierControl({ call, kind, provider, modelId, selecting, directoryModels }) {
@@ -6593,7 +6613,7 @@ function ContextTierControl({ call, kind, provider, modelId, selecting, director
6593
6613
  }
6594
6614
  const error = feedback?.error === true
6595
6615
  const shown = busy ? pending : view.override
6596
- const custom = isCustomContext(shown, contextWindowTiers(view.capacity))
6616
+ const custom = isCustomContext(shown, contextWindowTiers(view.capacity, view.tiers, view.exact))
6597
6617
  return h('span', { className: 'eac-context-pill', ref: section, 'data-disabled': busy || selecting,
6598
6618
  'data-error': error, 'data-error-message': error ? feedback.text : undefined,
6599
6619
  title: error ? feedback.text : custom ? `自定义 ${shown.toLocaleString('zh-CN')} tokens` : '此模型的上下文设置在会话间共享' },
@@ -153,11 +153,11 @@ export async function* guardStream(upstream, options, onCut, observer) {
153
153
  if (step.done) break
154
154
  const decision = guardChunk(watch, open, step.value)
155
155
  for (const event of decision.events) observer?.(event)
156
+ // A consumer can close immediately after reading finish, so bookkeeping
157
+ // must happen before the terminal chunk is handed off.
158
+ if (decision.cut !== undefined) onCut?.(decision.cut)
156
159
  yield* decision.chunks
157
- if (decision.cut !== undefined) {
158
- onCut?.(decision.cut)
159
- return
160
- }
160
+ if (decision.cut !== undefined) return
161
161
  }
162
162
  yield* flushWatch(watch, open, observer)
163
163
  } finally {
@@ -6,7 +6,7 @@ const modelBrands = {
6
6
  }
7
7
 
8
8
  const modelAliases = new Map([
9
- ['qmodel_38max', 'Qwen 3.8 Max'], ['qmodel_latest', 'Qwen 3.8 Max'],
9
+ ['qmodel_38max', 'Qwen 3.8 Max'], ['qmodel_latest', 'Qwen 4 Max'],
10
10
  ['qfmodel', 'Qwen 3.8 Flash'], ['dmodel', 'DeepSeek V4 Pro'], ['dfmodel', 'DeepSeek Flash'],
11
11
  ['gmodel', 'GLM 5.3'], ['gfmodel', 'GLM 5.3 Flash'], ['kmodel_latest', 'Kimi K3.1 Pro'],
12
12
  ['kmodel', 'Kimi K2.8 Preview'], ['mmodel', 'MiniMax M3.1 Flash'],
@@ -163,9 +163,9 @@ function modelIdentity(value) {
163
163
  // deployments, aliases or account tiers. Keep ambiguous aliases provider-scoped.
164
164
  const catalogIdentities = {
165
165
  qodercn: {
166
- qmodel_38max: 'qwen-3-8-max', qfmodel: 'qwen-3-8-flash',
166
+ qmodel_38max: 'qwen-3-8-max', qfmodel: 'qwen-3-8-flash', qmodel_latest: 'qwen-4-max',
167
167
  dmodel: 'deepseek-v4-pro', dfmodel: 'deepseek-flash',
168
- gmodel: 'glm-5-3', gfmodel: 'glm-5-3-flash', kmodel_latest: 'kimi-k3-1-pro',
168
+ gmodel: 'glm-5-3', gfmodel: 'glm-5-3-flash', gmodel_latest: 'glm-5-4', kmodel_latest: 'kimi-k3-1-pro',
169
169
  kmodel: 'kimi-k2-8-preview', mmodel: 'minimax-m3-1-flash',
170
170
  },
171
171
  trae: { 'deepseek-v4-pro-official': 'deepseek-v4-pro-0813' },
@@ -235,10 +235,6 @@ const providerNamedSuccessors = {
235
235
  ['minimax-m2-7', 'minimax-m3-1-flash'],
236
236
  ['kimi-k2-6', 'kimi-k3-1-pro'],
237
237
  ]),
238
- workbuddy: new Map([
239
- // 同目录存在完全同型号的免费版 hy4flash-free,收费版 hy4flash 不再默认启用。
240
- ['hy4flash', 'hy4flash-free'],
241
- ]),
242
238
  }
243
239
 
244
240
  // 全平台已明确过时的老一代型号:即使单个渠道目录里没有同族新代,只要目录里还存在
@@ -335,11 +331,13 @@ export function modelRecommendationExclusions(models, provider) {
335
331
  const exclusions = new Map()
336
332
  const candidates = []
337
333
  const aliveModels = models.filter(model => !model.dead)
334
+ const obsolete = identity => obsoleteIdentities.has(identity)
335
+ || (provider === 'qodercn' && /^qwen-3-8(?:-|$)/.test(identity))
338
336
  const hasModernSurvivor = aliveModels.some(model => {
339
337
  if (older.has(model.id) || model.stale) return false
340
338
  const identity = catalogIdentity(model.id, provider)
341
339
  const baseIdentity = stripReleaseSuffix(identity)
342
- return !obsoleteIdentities.has(identity) && !obsoleteIdentities.has(baseIdentity)
340
+ return !obsolete(identity) && !obsolete(baseIdentity)
343
341
  })
344
342
  for (const model of aliveModels) {
345
343
  const identity = catalogIdentity(model.id, provider)
@@ -348,7 +346,7 @@ export function modelRecommendationExclusions(models, provider) {
348
346
  exclusions.set(model.id, { kind: 'older', alternative: older.get(model.id) })
349
347
  continue
350
348
  }
351
- if (hasModernSurvivor && (obsoleteIdentities.has(identity) || obsoleteIdentities.has(baseIdentity))) {
349
+ if (hasModernSurvivor && (obsolete(identity) || obsolete(baseIdentity))) {
352
350
  exclusions.set(model.id, { kind: 'older', alternative: undefined })
353
351
  continue
354
352
  }
package/lib/web-host.js CHANGED
@@ -44,7 +44,7 @@ const planModelId = id => typeof id === 'string' && id !== '' && id.length <= 25
44
44
  function publicCatalogStatus(value) {
45
45
  return {
46
46
  ...(['remote', 'cached', 'fallback'].includes(value?.source) ? { source: value.source } : {}),
47
- ...(['login-required', 'cli-missing', 'timeout', 'cli-failed', 'empty'].includes(value?.issue) ? { issue: value.issue } : {}),
47
+ ...(['login-required', 'cli-missing', 'timeout', 'cli-failed', 'empty', 'no-model-key'].includes(value?.issue) ? { issue: value.issue } : {}),
48
48
  }
49
49
  }
50
50
  // 设置页模型列表的倍率/免费标签:与 `lib/rate-badge.js`(会话选择器徽标)同一份
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unified-router",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "type": "module",
5
5
  "main": "lib/web-host.js",
6
6
  "license": "MIT",