dsh-connect-trae 4.6.4 → 4.6.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.6.5 (2026-10-30)
4
+
5
+ > **一条没带上下文窗口的目录行,会让整个 `trae` 区域不可用。** 失效的不是
6
+ > 那条模型,而是**整条路由**——DSH 逐模型校验,且校验失败是 provider 级的。
7
+ > 插件早就写好了 `FALLBACK_CONTEXT_WINDOW` 作为「最后防线」,但它被赋给了一个
8
+ > 本插件**从不会走**的字段,于是从未生效过。这一版把回退落到模型行本身。
9
+
10
+ ### 修复
11
+
12
+ - **一条没带上下文窗口的目录行不再拖垮整个区域**(#70,贡献者
13
+ [@beibing173](https://github.com/beibing173))。
14
+ - **现象**:模型选择器里 `trae` 整个区域加载失败,报
15
+ `adapter returned invalid context metadata for provider "trae" model "doubao_1.8"`。
16
+ 失败粒度是 **provider 级**,不是单模型级。
17
+ - **根因**:`FALLBACK_CONTEXT_WINDOW` 只被赋给 profile 的
18
+ `defaultContextWindow`,而那个字段由**内核自己的目录解析步骤**读取——本插件
19
+ 从不走那条路径。它用 `createProvider({ models })` 手工装配 pi-ai provider,
20
+ `Models.getModel()` 直接返回 `toPiModel` 产出的原始行,**不做任何补默认值**;
21
+ 而 `toPiModel` 在 `contextWindow === undefined` 时**省略**该字段。于是
22
+ `PiAiAdapter.modelInfo()` 解析出 `context: { contextWindow: undefined }`,
23
+ DSH 拒绝,且拒绝的是整条路由。常量写了,没有生效点。
24
+ - **修法**:把回退**落到行本身**。新增 `servedContextWindow()`,`toPiModel`
25
+ 现在**总是**输出 `contextWindow`:行自己的正整数窗口原样保留,其余一切
26
+ (缺失、`NaN`、`0`、负数、小数)回退到 `FALLBACK_CONTEXT_WINDOW`——因为
27
+ DSH 只接受正整数。profile 上的 `defaultContextWindow` 保留(内核路径仍会读),
28
+ 但注释改成与事实一致:真正的保证在 `toPiModel`,那只是保险带。
29
+ - **为什么小数也要回退**:目录解析器的 `finitePositive` 只校验 `isFinite` 与
30
+ `> 0`,所以上游若发布 `context_window_tokens.dev = 200000.5`,它会原样进到
31
+ 适配器;DSH 对非整数的拒绝与缺失完全相同。这条此前没有任何用例锁住。
32
+ - **测试**:`tests/context-window-fallback.spec.ts` 走宿主的真实路径
33
+ (`adapter.current()` → `profiles` → `models.getModel()`,以及
34
+ `adapter.resolveModel()`),覆盖未定尺寸行、混合目录逐行可解析、行自带窗口
35
+ 不被覆盖,以及小数/零/负数/NaN 四种畸形窗口一律回退。
36
+ **变异验证**:把 `toPiModel` 的改动回退,8 例中 7 例转红。
37
+ - **不变的部分**:不改变任何已有窗口的行;不改变名称、reasoning、图像能力、
38
+ 计费倍率等元数据;兜底目录本身仍然每行手写真实窗口(`tests/catalog.spec.ts`
39
+ 继续锁这个不变量)。本修复只是让「万一漏了一条」退化成一条保守尺寸的模型,
40
+ 而不是死掉一个区域。
41
+
3
42
  ## 4.6.4 (2026-10-28)
4
43
 
5
44
  > **缓存命中恒为 0% 不是插件丢了数字,是上游没有分配缓存池。** Trae 的
package/lib/index.js CHANGED
@@ -866,8 +866,30 @@ const REQUEST_IMAGE_BUDGETS = {
866
866
  * window of its own. Every fallback row and every live Trae row is expected to
867
867
  * state its real window; this is the backstop that keeps one unsized row from
868
868
  * failing the entire provider route (`INVALID_MODEL_CONTEXT`).
869
+ *
870
+ * APPLIED IN {@link toPiModel}, NOT ONLY ON THE PROFILE. The profile's
871
+ * `defaultContextWindow` is read by the kernel's catalog-resolution step, which
872
+ * this plugin never runs: it builds its pi-ai provider BY HAND through
873
+ * `createProvider({ models })`, and `Models.getModel()` then returns the raw
874
+ * `toPiModel` row with no defaulting applied anywhere. Leaving the fallback on
875
+ * the profile alone is what produced
876
+ * `adapter returned invalid context metadata for provider "trae" model
877
+ * "doubao_1.8"` — a row the live directory published without a window reached
878
+ * DSH unsized and took the whole `trae` route down.
869
879
  */
870
880
  const FALLBACK_CONTEXT_WINDOW = 2e5;
881
+ /**
882
+ * The window a served row is actually advertised with.
883
+ *
884
+ * Positive integers pass through untouched — a row's own window is never
885
+ * second-guessed. Anything else (missing, `NaN`, `0`, a negative or a
886
+ * fractional count from a malformed directory entry) falls back, because DSH
887
+ * accepts ONLY a positive integer and rejects the entire provider otherwise.
888
+ */
889
+ function servedContextWindow(info) {
890
+ const window = info.contextWindow;
891
+ return Number.isInteger(window) && window > 0 ? window : FALLBACK_CONTEXT_WINDOW;
892
+ }
871
893
  function toPiModel(info, baseUrl, providerId, withRate = true) {
872
894
  return {
873
895
  id: info.id,
@@ -906,7 +928,7 @@ thinkingLevelMap: {
906
928
  xhigh: info.reasoningEfforts.xhigh ?? null,
907
929
  max: info.reasoningEfforts.max ?? null
908
930
  } },
909
- ...info.contextWindow === void 0 ? {} : { contextWindow: info.contextWindow },
931
+ contextWindow: servedContextWindow(info),
910
932
  ...info.maxTokens === void 0 ? {} : { maxTokens: info.maxTokens },
911
933
  compat: { supportsReasoningEffort: info.reasoningEfforts !== void 0 }
912
934
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-connect-trae",
3
3
  "displayName": "DSH Connect Trae",
4
4
  "description": "把本机登录的 Trae 模型接入 DeepSeek Harness:国内版与国际版双供应商并行,提供用量/积分概览与每日签到领取。",
5
- "version": "4.6.4",
5
+ "version": "4.6.5",
6
6
  "author": "dingminhua",
7
7
  "copyright": "Copyright (c) 2026 LaoDing",
8
8
  "license": "MIT",