dsh-connect-workbuddy 5.24.1 → 5.24.4
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 +203 -0
- package/lib/bin.js +1 -1
- package/lib/{host-heartbeat-DeelaI9b.js → host-heartbeat-BbJWHKQq.js} +511 -2
- package/lib/index.d.ts +20 -1
- package/lib/index.js +73 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,208 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.24.4 (2026-11-14)
|
|
4
|
+
|
|
5
|
+
> 版本号是 **patch**:修一处「schema 里某个关键字的值类型不对就整个工具被拒」,并修好 5.24.2
|
|
6
|
+
> 自己引入的一处回归。无新增配置项、无接口变化。来自 issue #253 的第二份报告。
|
|
7
|
+
|
|
8
|
+
### 修复:关键字值类型错误导致 11129(36 种实测)
|
|
9
|
+
|
|
10
|
+
第二次报告给的是**方法**而不是结论,这一步很关键:报告者证明 `normalizeSchemaNode` 的遍历有盲区,
|
|
11
|
+
我顺着「盲区里漏了什么」去测,测出的是**另一类问题**。
|
|
12
|
+
|
|
13
|
+
按关键字逐个、**绕过 `prepareChatBody` 直接发原始 body** 测出来的,是 schema 自身的类型错误:
|
|
14
|
+
|
|
15
|
+
| 写法 | 结果 |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `title: 1`、`description: 5`、`pattern: 123`、`format: 7` | 11129 |
|
|
18
|
+
| `minimum: "0"`、`maxLength: "5"`、`multipleOf: "2"` | 11129 |
|
|
19
|
+
| `uniqueItems: "true"`、`readOnly: "yes"` | 11129 |
|
|
20
|
+
| `allOf: {}`(非数组)、`allOf: []`(空数组) | 11129 |
|
|
21
|
+
| `not: "x"`、`items: "x"`、`additionalProperties: "x"`(非 schema) | 11129 |
|
|
22
|
+
| `type: "thing"`、`type: []` | 11129 |
|
|
23
|
+
|
|
24
|
+
一共 **36 种**,遍布每一个位置。现在会在发出前修掉:**类型不对的注解/约束值直接删除**,`type` 的非法成员
|
|
25
|
+
从联合里剔除(留一个就还原成字符串)。这不改变工具接受哪些参数——被删的都是注解或约束,不是
|
|
26
|
+
`properties` / `required` / 任何 schema 结构——只是让它不再被整体拒收。
|
|
27
|
+
|
|
28
|
+
**刻意没有选择「把整个工具删掉」**:那样更简单,但会静默移除用户装好的能力,模型随后还会去调一个
|
|
29
|
+
已经不存在的工具。
|
|
30
|
+
|
|
31
|
+
**只有真的写错的值才会被动**。完全合法的 schema 逐字节不变(真实 `stagehand_extract` 已钉住),
|
|
32
|
+
这样 prompt 前缀对缓存是稳定的。
|
|
33
|
+
|
|
34
|
+
### 修复:5.24.2 自己引入的回归——空 tuple 换了个 11129
|
|
35
|
+
|
|
36
|
+
5.24.2 把 draft-4 的 `items: []` 改写成 `prefixItems: []`,而**空 `prefixItems` 正是上游拒收的**。
|
|
37
|
+
也就是说那次「修复」对一个本来就是 11129 的输入,产出了另一个 11129,等于没修。
|
|
38
|
+
|
|
39
|
+
draft-4 的 `items: []` 意思是「任意数组」,对应 `items: {}`。现在空 tuple 直接给 `items: {}`,
|
|
40
|
+
并且 `additionalItems` 在 tuple 分支里成为 2020-12 的 `items`(尾元素 schema),才是它原本的语义。
|
|
41
|
+
|
|
42
|
+
### 报告者建议的三种写法:实测**不需要**改
|
|
43
|
+
|
|
44
|
+
报告者给了 3 种 draft-4 写法(`type` 数组、`dependencies`、`additionalItems`)和一份补丁。我逐个
|
|
45
|
+
**绕过规范化**发原始 body 实测,**三种全部 200**:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
type: ["string","null"] 200
|
|
49
|
+
dependencies (array) 200
|
|
50
|
+
dependencies (object) 200
|
|
51
|
+
additionalItems 200 (配合对象 items,或不配合)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
所以迁移它们不会修好任何东西,那份补丁是个 no-op。**没有采纳**,理由写进代码注释。
|
|
55
|
+
|
|
56
|
+
但其中两件事值得留下:
|
|
57
|
+
|
|
58
|
+
- `dependencies` 的对象值**确实**需要被递归遍历(里面可能嵌着别的 draft-4 写法),所以加了遍历项;
|
|
59
|
+
- `additionalItems` 加进 `SCHEMA_CHILD_SINGLE`,只在 tuple 分支里消费。
|
|
60
|
+
|
|
61
|
+
这两处都不改变上游已接受的字节(有测试钉住 `additionalItems` 配合对象 `items` 时原样保留)。
|
|
62
|
+
|
|
63
|
+
### 一处顺序陷阱,写在这里免得下次再踩
|
|
64
|
+
|
|
65
|
+
draft-4 转换必须**先于**类型修复。类型修复会把布尔 `exclusiveMinimum`、tuple `items` 当成「类型错误」
|
|
66
|
+
删掉,转换逻辑就再也看不到它们了。第一版就是反的,`items: []` 被删成「没有 items」、tuple 尾元素
|
|
67
|
+
被静默丢弃,是往返测试抓到的。
|
|
68
|
+
|
|
69
|
+
### 验证
|
|
70
|
+
|
|
71
|
+
真实上游端到端(`deepseek-v4.1-flash`,绕过与经过规范化各测一遍):36 种类型错误**全部从 11129 变 ok**,
|
|
72
|
+
空数组族全部 ok,报告者的 3 种写法仍然 ok,真实 `stagehand_extract` 等 9 个合法 schema 逐字节未变。
|
|
73
|
+
|
|
74
|
+
变异验证五条,各自单独还原:去掉类型修复调用红 7 条;把 `required: []` 也当成非法红 2 条;
|
|
75
|
+
`additionalItems` 不带进尾元素红 1 条;`dependencies` 不遍历红 1 条;空 tuple 分支失效红 1 条。
|
|
76
|
+
|
|
77
|
+
**其中最后一条第一次做变异时是绿的**——因为后跑的类型修复会把 `prefixItems: []` 顺手删掉,掩盖了
|
|
78
|
+
那个分支的缺陷。改成给空 tuple 配一个 `additionalItems` 同级项之后才能区分。这条记在这里,
|
|
79
|
+
因为「测试通过了但证明的不是它自己声称的东西」比没有测试更危险。
|
|
80
|
+
|
|
81
|
+
## 5.24.3 (2026-11-14)
|
|
82
|
+
|
|
83
|
+
> 版本号是 **patch**:修一处「长会话永久 422、只能开新会话」的问题,无新增配置项、无接口变化。
|
|
84
|
+
> 来自 issue #258。
|
|
85
|
+
|
|
86
|
+
### 修复:请求体超过**字节**上限时,历史折叠从未触发
|
|
87
|
+
|
|
88
|
+
长会话在某一刻稳定报:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
HTTP 422 / gate_oversize_refusal_unattributed_bytes
|
|
92
|
+
(8,401,132 B > 8,388,608 B)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
外层看到的是 400,根因是**请求体超过了一个本地字节上限**,请求根本没发到上游。之后每一次重试都带上
|
|
96
|
+
同一份超限历史,于是这一会话永久卡死,只能新建。
|
|
97
|
+
|
|
98
|
+
插件本来就有折叠能力(`context-rescue.ts` → 宿主自带的 compaction),但那套东西**两个环节都接不上**,
|
|
99
|
+
而且它们是**独立失效**的:
|
|
100
|
+
|
|
101
|
+
**一、触发条件只认 token 溢出。** 唯一的判定是 pi-ai 的 `isContextOverflow`,它匹配的是
|
|
102
|
+
「prompt is too long」那一族**token 上下文溢出**文案。字节超限的措辞一条都不在它的模式表里,于是
|
|
103
|
+
`rescue` 一次都没被调用。
|
|
104
|
+
|
|
105
|
+
**二、就算调进去,也一次都不会折叠。** 折叠目标是 `window * 0.6`,而 `window` 是模型**声明的
|
|
106
|
+
token 窗口** 1,000,000 → 目标 600,000。可 8 MiB 这条线大约在 **15 万 token** 就被撞到,于是
|
|
107
|
+
`totalTokens(≈150k) <= target(600k)` 在**第一次测量时就成立**,循环直接返回、原样重发同一个 body。
|
|
108
|
+
**阈值单位是字节,折叠目标是 token,单位不一致时这个循环会被平凡满足。**
|
|
109
|
+
|
|
110
|
+
两条都修了:
|
|
111
|
+
|
|
112
|
+
- **触发**:`rescueCauseOf()` 在 `isContextOverflow` 之外,再按「请求体字节超限」这一**语义**识别一次
|
|
113
|
+
(见下面「按语义匹配」);
|
|
114
|
+
- **目标**:字节超限时目标改为 `当前测量 * 0.9`,从 payload 本身推出来。这样第一轮比较必然不成立,
|
|
115
|
+
折叠一定会真的发生;每轮至少折掉 10%,最多 8 轮,覆盖一次「只超出几个百分点」的越线
|
|
116
|
+
——报告者实测的 8,401,132 对 8,388,608 正是这种形状。
|
|
117
|
+
- **让宿主接手**:回复里补一句 `prompt is too long (request body exceeded the local byte limit)`。
|
|
118
|
+
宿主的溢出恢复只认这句英文(与 issue #101 的 11115 同一机制),不补它,宿主就只看到一个它不会恢复的
|
|
119
|
+
400。**原始错误原样保留在后面**,不伪装成 11115。
|
|
120
|
+
|
|
121
|
+
### 按语义匹配,不点名任何插件
|
|
122
|
+
|
|
123
|
+
识别用的是「请求体字节超限」这一类事实(字节比较形状 `8,401,132 B > 8,388,608 B`、
|
|
124
|
+
`request-body limit`、`byte limit`、`oversize` + `refused locally`),**不匹配任何插件的错误码**。
|
|
125
|
+
|
|
126
|
+
这不是措辞洁癖:`docs/DESIGN.md` §零 第 4 条要求本插件不因别的插件在场而改变行为,判别式是
|
|
127
|
+
「随**数据**走可以,随**代码**走不行」——写死别人的标识符属于后者,对方改名或消失之后那段代码还留着。
|
|
128
|
+
按语义识别的是**一类错误**,换个组件、换套措辞只要说的还是同一件事,仍然覆盖。代价是这一族匹配
|
|
129
|
+
比精确码宽,所以刻意排除了 `too many tokens` / `context length exceeded` / `11115`——那些是 token
|
|
130
|
+
溢出,宿主自己会处理,两边都插手只会互相竞争。
|
|
131
|
+
|
|
132
|
+
已知**不覆盖**:`oversized image attachment rejected` 这类「大」但不是「请求体大」的失败不会被误判
|
|
133
|
+
(有测试钉住),因为折掉历史对它们没有帮助。
|
|
134
|
+
|
|
135
|
+
### 关于原 issue #202 的关闭
|
|
136
|
+
|
|
137
|
+
#202 以「你让 AI 帮你更新插件,问题已经解决」关闭,**这个理由不成立**:代码里从来没有针对这个
|
|
138
|
+
字节上限的任何改动,5.24.1 的发布包里 `bili_gate_oversize` / `BILI_LOCAL_BODY` 这类标识都是零命中。
|
|
139
|
+
报告者这次拿 tarball 逐字核实过,是对的。这一版才是真正的修复。
|
|
140
|
+
|
|
141
|
+
### 仍未解决:bili 侧的归因死锁
|
|
142
|
+
|
|
143
|
+
即使上面都做了,该组件里这条 lane 仍然永远拿不到压缩能力——它在第二跳的归因返回 `none`,而
|
|
144
|
+
`learnConversation` 只在上游归因成功时调用,于是表永远是空的自举死锁。报告者已在
|
|
145
|
+
`ranxianglei/billion-context#6546` 提交实测数据,那一半需要对方提供显式的归属注册 API。
|
|
146
|
+
本插件这边能做的、也已做的,是不让它卡成永久 400。
|
|
147
|
+
|
|
148
|
+
**尚未验证**:报告者明确说明他「还没做」完整重启 DSH 后的真实长会话验证(确认折叠后重发的 body
|
|
149
|
+
确实低于 8 MiB)。8 MiB 是对方组件内部的常量,不在本仓库手里,所以这一条只能由报告者复现确认。
|
|
150
|
+
|
|
151
|
+
## 5.24.2 (2026-11-14)
|
|
152
|
+
|
|
153
|
+
> 版本号是 **patch**:修一处「某些模型完全不可用」的请求字节问题,无新增配置项、无接口变化。
|
|
154
|
+
> 来自 issue #253。
|
|
155
|
+
|
|
156
|
+
### 修复:`deepseek-v4.1-flash` 等 8 个模型在 agent 模式下必定 400
|
|
157
|
+
|
|
158
|
+
报告者的现象是:选 `deepseek-v4.1-flash` 发**一句普通消息**(不提工具)就必报
|
|
159
|
+
`400 / code 11129 / 工具的参数结构不符合当前模型要求`,换账号、重连、重装都不变;同账号换
|
|
160
|
+
`hy3`、`deepseek-v4-pro` 之外的模型又正常。
|
|
161
|
+
|
|
162
|
+
根因不在插件丢没丢 `tools`,也不在 `$ref`——**这两条都是排查过程中的错误结论,已各自被实测推翻**:
|
|
163
|
+
|
|
164
|
+
- 「插件从不处理 tools」不成立:`normalizeToolChoice` 早就会在 `tool_choice: none` 时删掉 `tools`;
|
|
165
|
+
- 「上游不认 `$ref`」也不成立:宿主 `docs/tool-catalog.md` 里 `stagehand_extract` 那份**递归
|
|
166
|
+
`$defs`** schema 实测 200,宿主的**全部 75 个工具**一起发也 200。
|
|
167
|
+
|
|
168
|
+
真正被拒的是 DSH 宿主(zod 生成)与手写 MCP schema 会带出的 **draft-4 遗留写法**,逐条实测如下:
|
|
169
|
+
|
|
170
|
+
| 写法 | 上游怎么答 | 改写后 |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| `items` 写成**元组数组**(draft-4)`items: [{type:'string'}]` | 11129(DeepSeek)/ 11133(GLM、Kimi、MiMo) | `prefixItems: […]` + `items: {}` |
|
|
173
|
+
| `exclusiveMinimum` / `exclusiveMaximum` 写成**布尔**(draft-4) | 11129 | 由同级的 `minimum` / `maximum` 推出的**数值**形式 |
|
|
174
|
+
| `required` 写成**字符串** | 11129 | 单元素数组 |
|
|
175
|
+
| `required` 数组含**重复项** | 11129 | 去重 |
|
|
176
|
+
| **外部** `$ref`(`https://…`、`//host/…`) | 11129 | 删掉该引用 |
|
|
177
|
+
|
|
178
|
+
`prepareChatBody` 现在会在发出去之前递归改写这五种写法。用同一份请求体逐模型验证(2026-11-14,
|
|
179
|
+
CN 网关,本构建自己的凭据):
|
|
180
|
+
|
|
181
|
+
| 模型 | 修复前 | 修复后 |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| `deepseek-v4.1-flash`、`deepseek-v4-pro` | ❌ 11129 | ✅ 200 |
|
|
184
|
+
| `glm-5.3`、`glm-5.3-flash`、`kimi-k3.1-pro`、`kimi-k3-1`、`kimi-k2.8-preview`、`mimo-v2.6-pro` | ❌ 11133 | ✅ 200 |
|
|
185
|
+
| `hy3`、`hy4free`、`hy4std`、`hy3-x`、`glm-5.2`、`space-bunny`、`minimax-m3.1-flash`、`step-5-preview` | ✅ 200(原本就通过) | ✅ 200(未被误伤) |
|
|
186
|
+
|
|
187
|
+
### 刻意**没有**改的四处,理由都在代码注释里
|
|
188
|
+
|
|
189
|
+
- **内部 `$ref`(`#/…`)保留**:实测被接受,展开递归 schema 是一处大得多、且没有任何实测证据支撑的改动。
|
|
190
|
+
- **布尔 `exclusiveMinimum` 没有同级界时直接删掉,不硬造一个 `0`**:硬造等于**发明一个调用方从未写过的约束**,
|
|
191
|
+
而上游会照收——一个语义错误的 schema 比一个明确失败的请求更糟。
|
|
192
|
+
- **11129 不单独成类**:它继续落在 `client`(该类本来就不换号、不重试)。改类别会动到重试与换账号行为,
|
|
193
|
+
证据不足以支撑那么大的主张;这次只改**建议文案**。
|
|
194
|
+
- **探针不加工具**:探针结果会直接让账号出池,往里塞工具 schema 会让「某个工具定义有问题」被记成
|
|
195
|
+
「这个账号坏了」。
|
|
196
|
+
|
|
197
|
+
### 说明:报错现在会指向工具定义
|
|
198
|
+
|
|
199
|
+
原来 11129 的回复照抄上游的 `displayTips`——「工具的参数结构不符合当前模型要求,被服务端拒绝。请新建任务,
|
|
200
|
+
或换个模型。」这两条建议都**不会**让请求变好(换模型只是绕开,新建任务什么也没改),报告者因此在
|
|
201
|
+
换账号、重登、重装里耗了一天。现在这一族会被单独识别,回复改成:点名是**工具定义**被拒、列出插件已经
|
|
202
|
+
改写过的四种写法、并给出最快验证路径(关掉提供该工具的浏览器自动化 / MCP server / 第三方插件后重发)。
|
|
203
|
+
|
|
204
|
+
修复本身不依赖这条文案:即使某个未知写法仍然被拒,至少不会再让人去换账号。
|
|
205
|
+
|
|
3
206
|
## 5.24.1 (2026-11-14)
|
|
4
207
|
|
|
5
208
|
> 版本号是 **patch**:修一处宿主状态回执的清理归属,不动配置键、路由语义与请求字节。
|
package/lib/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Cn as findWorkbuddyAppExecutableWithSource, F as WorkBuddyCredentialStore, J as workbuddyOwnAuthPath, Mn as resolveDshHome, N as WORKBUDDY_AUTH_FILE_ENV, P as WORKBUDDY_VAULT_DIRNAME, R as defaultDesktopAuthCandidates, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, W as legacyWorkbuddyOwnAuthPath, X as APP_VERSION, Y as workbuddyVaultDir, _n as WORKBUDDY_APP_EXECUTABLE_ENV, a as readHostHeartbeat, b as readDeviceSettings, c as WORKBUDDY_CONNECT_VERSION, d as rosterSeenPath, dn as ensureDeviceSalt, et as DEFAULT_WIRE_PROFILE, f as WORKBUDDY_CN_BASE_ENV, fn as readDeviceSalt, g as createTuringSdk, gn as protectCredentialDirectory, hn as inspectCredentialDirectory, jn as hostPeersInfo, ln as WORKBUDDY_DEVICE_TOKEN_FILE_ENV, m as piAiRuntimeInfo, o as workbuddyHostHeartbeatPath, p as resolveCnGateway, pn as deriveDeviceId, r as isHeartbeatProcessAlive, rt as WorkBuddyUpstreamClient, st as describeRequestHeaderNames, u as describeRosterSeenPayload, un as readDeviceTokenFile, w as FALLBACK_WORKBUDDY_MODELS, z as defaultDesktopAuthDirs } from "./host-heartbeat-BbJWHKQq.js";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { realpathSync } from "node:fs";
|
|
@@ -3904,6 +3904,56 @@ const CONTEXT_TOO_LONG_CODE = /"code"\s*:\s*11115(?!\d)|code\s+11115(?!\d)/u;
|
|
|
3904
3904
|
function isContextTooLongBody(body) {
|
|
3905
3905
|
return CONTEXT_TOO_LONG_CODE.test(body);
|
|
3906
3906
|
}
|
|
3907
|
+
/** The tool-schema refusal (issue #253). */
|
|
3908
|
+
const TOOL_SCHEMA_REJECT_CODE = 11129;
|
|
3909
|
+
/**
|
|
3910
|
+
* Whether this body is the upstream refusing a TOOL DEFINITION (issue #253).
|
|
3911
|
+
*
|
|
3912
|
+
* `11129` arrives as `{"code":11129,"msg":"invalid function call parameters"}`
|
|
3913
|
+
* with `extError.code: "invalid_function_parameters"`. Its `param` field is an
|
|
3914
|
+
* EMPTY STRING — the upstream knows the definition is wrong but never says
|
|
3915
|
+
* which tool or which keyword — so the plugin is the only party that can turn
|
|
3916
|
+
* this into an actionable sentence.
|
|
3917
|
+
*
|
|
3918
|
+
* Read by CODE rather than by the wording, for the reason every other code
|
|
3919
|
+
* reader in this module does it: the same `msg` is short and generic enough that
|
|
3920
|
+
* a request id or a prompt could contain the phrase, while `11129` has so far
|
|
3921
|
+
* only ever meant this. Recognising it changes ADVICE ONLY — the kind stays
|
|
3922
|
+
* `client`, which already means "refused on parameters, no account can help" and
|
|
3923
|
+
* already skips failover. Giving it a kind of its own would move it out of that
|
|
3924
|
+
* bucket and silently change retry behaviour, which is a much larger claim than
|
|
3925
|
+
* the evidence supports.
|
|
3926
|
+
*/
|
|
3927
|
+
function isToolSchemaRejectBody(body) {
|
|
3928
|
+
return statesBusinessCode(body, TOOL_SCHEMA_REJECT_CODE);
|
|
3929
|
+
}
|
|
3930
|
+
/**
|
|
3931
|
+
* Which schema keywords the rewrite in {@link normalizeToolSchemas} can fix,
|
|
3932
|
+
* for the reply's advice (issue #253).
|
|
3933
|
+
*
|
|
3934
|
+
* Deliberately a FIXED LIST rather than a parse of the offending body: the
|
|
3935
|
+
* upstream never names the keyword, and the plugin has already rewritten every
|
|
3936
|
+
* one of these on the way out. If a request still gets `11129` after that
|
|
3937
|
+
* rewrite, the cause is a keyword this build does not know — so the advice has to
|
|
3938
|
+
* say "something else", not repeat the four shapes it already handled.
|
|
3939
|
+
*/
|
|
3940
|
+
const TOOL_SCHEMA_REWRITTEN_KEYWORDS = "元组式 `items`、布尔 `exclusiveMinimum`/`exclusiveMaximum`、`required` 非数组或含重复项、外部 `$ref`";
|
|
3941
|
+
/**
|
|
3942
|
+
* One actionable sentence for a `11129` refusal, naming what was already fixed
|
|
3943
|
+
* and what the user can still do.
|
|
3944
|
+
*
|
|
3945
|
+
* WHY THE PLUGIN MUST SPEAK HERE. The upstream's own advice is "请新建任务,或换
|
|
3946
|
+
* 个模型" — and issue #253's reporter spent a day on account swaps, re-logins and
|
|
3947
|
+
* a reinstall because nothing in that sentence points at a TOOL DEFINITION. The
|
|
3948
|
+
* plugin rewrites the four known shapes automatically, so a surviving `11129`
|
|
3949
|
+
* means either (a) the offending definition is one of a further shape this build
|
|
3950
|
+
* does not know, or (b) a tool supplied by a third-party bundle/MCP server is
|
|
3951
|
+
* sending something the gateway will not take. Both are actionable, and neither
|
|
3952
|
+
* is "switch accounts".
|
|
3953
|
+
*/
|
|
3954
|
+
function toolSchemaRejectAdvice() {
|
|
3955
|
+
return `这次是工具定义被拒,与账号、积分、额度、网络都无关,换账号或重试都不会改变结果。插件已自动改写过这些上游不接受的写法:${TOOL_SCHEMA_REWRITTEN_KEYWORDS};仍被拒说明还有别的写法。最快的验证是关掉提供该工具的能力(例如浏览器自动化、某个 MCP server 或第三方插件)后重发同一句话——能通过就说明是那个工具的定义有问题,把它的参数结构贴到 issue 里即可定位`;
|
|
3956
|
+
}
|
|
3907
3957
|
/**
|
|
3908
3958
|
* An English clause the HOST's overflow detector recognises, for issue #101.
|
|
3909
3959
|
*
|
|
@@ -3916,6 +3966,59 @@ function isContextTooLongBody(body) {
|
|
|
3916
3966
|
*/
|
|
3917
3967
|
const CONTEXT_OVERFLOW_MARKER = "prompt is too long (upstream code 11115)";
|
|
3918
3968
|
/**
|
|
3969
|
+
* The marker for a request refused because its BODY BYTES exceed a local limit
|
|
3970
|
+
* (issue #258).
|
|
3971
|
+
*
|
|
3972
|
+
* Deliberately the SAME English head pi-ai's `OVERFLOW_PATTERNS` already
|
|
3973
|
+
* matches (`prompt is too long`), with a parenthetical naming the real cause.
|
|
3974
|
+
* The host's rescue ladder keys on that phrase and on nothing else, so a
|
|
3975
|
+
* refusal it must recover from has to carry it — see the #101 comment in
|
|
3976
|
+
* `src/shim.ts` for how the 11115 case arrived at the same shape.
|
|
3977
|
+
*
|
|
3978
|
+
* The parenthetical is NOT the bili code. Naming another plugin's identifier
|
|
3979
|
+
* here would be plugin-specific code in this plugin's body — the line
|
|
3980
|
+
* `docs/DESIGN.md` §零 draws — and the code would keep describing a dependency
|
|
3981
|
+
* that may be gone tomorrow. What this string states is the fact that matters:
|
|
3982
|
+
* the request was too large to send.
|
|
3983
|
+
*/
|
|
3984
|
+
const BODY_OVERSIZE_MARKER = "prompt is too long (request body exceeded the local byte limit)";
|
|
3985
|
+
/**
|
|
3986
|
+
* Whether this text reports a body-size refusal rather than a token overflow
|
|
3987
|
+
* (issue #258).
|
|
3988
|
+
*
|
|
3989
|
+
* A local proxy/gateway in front of the provider may refuse a request whose
|
|
3990
|
+
* serialized body exceeds some byte ceiling it enforces. Measured shapes, from
|
|
3991
|
+
* a real report:
|
|
3992
|
+
*
|
|
3993
|
+
* bili_gate_oversize_refusal_unattributed_bytes
|
|
3994
|
+
* (8,401,132 B > 8,388,608 B)
|
|
3995
|
+
* "unattributed oversized model request refused locally with a 422"
|
|
3996
|
+
*
|
|
3997
|
+
* MATCHED BY MEANING, NOT BY NAME. That is the crux of the design decision
|
|
3998
|
+
* here: matching a plugin's identifier would be the "special-case another
|
|
3999
|
+
* plugin" this project forbids, while matching "a request body was too large"
|
|
4000
|
+
* is the same kind of reader as every other measured-wording matcher in this
|
|
4001
|
+
* module. A refusal that only says `oversize`/`too large` in BYTES is the class;
|
|
4002
|
+
* which component produced it is not this plugin's business, and a future
|
|
4003
|
+
* component with different wording that still says so is covered for free.
|
|
4004
|
+
*
|
|
4005
|
+
* What is deliberately NOT matched: `too_many_tokens`, `context length
|
|
4006
|
+
* exceeded`, `11115` and friends. Those are TOKEN overflow, which the host
|
|
4007
|
+
* already recovers from on its own; treating them here would make two
|
|
4008
|
+
* authorities compete over the same failure.
|
|
4009
|
+
*/
|
|
4010
|
+
function isBodyOversizeRefusal(text) {
|
|
4011
|
+
if (text === "") return false;
|
|
4012
|
+
const lower = text.toLowerCase();
|
|
4013
|
+
if (/[\d,]{4,}\s*b\s*>\s*[\d,]{4,}\s*b/u.test(lower)) return true;
|
|
4014
|
+
if (lower.includes("request-body limit") || lower.includes("request body limit")) return true;
|
|
4015
|
+
const oversize = lower.includes("oversize");
|
|
4016
|
+
const localByte = lower.includes("byte limit");
|
|
4017
|
+
const localRefusal = lower.includes("refused locally");
|
|
4018
|
+
if (localByte) return true;
|
|
4019
|
+
return oversize && localRefusal;
|
|
4020
|
+
}
|
|
4021
|
+
/**
|
|
3919
4022
|
* Wording that identifies the CHANNEL half of `11128` (the other halves being
|
|
3920
4023
|
* `conversation id missing` and `first message is not system prompt`).
|
|
3921
4024
|
*
|
|
@@ -5596,6 +5699,7 @@ function prepareChatBody(source, options) {
|
|
|
5596
5699
|
rewriteChannelFingerprintPhrasesInBody(obj);
|
|
5597
5700
|
neutralizeChannelFingerprints(obj);
|
|
5598
5701
|
normalizeToolChoice(obj);
|
|
5702
|
+
normalizeToolSchemas(obj);
|
|
5599
5703
|
dropRefusedReasoning(obj);
|
|
5600
5704
|
return JSON.stringify(obj);
|
|
5601
5705
|
}
|
|
@@ -5744,6 +5848,411 @@ function normalizeToolChoice(obj) {
|
|
|
5744
5848
|
delete obj["tool_choice"];
|
|
5745
5849
|
}
|
|
5746
5850
|
/**
|
|
5851
|
+
* Rewrite JSON Schema spellings the CN gateway REFUSES inside `tools[].function.parameters`
|
|
5852
|
+
* (issue #253, business code 11129 / 11133).
|
|
5853
|
+
*
|
|
5854
|
+
* WHY THIS EXISTS. The host builds tool schemas with zod and ships whatever the
|
|
5855
|
+
* library emits; `prepareChatBody` forwarded `tools` untouched. Four shapes
|
|
5856
|
+
* measured on 2026-11-14 as refused by the upstream, each with the same body
|
|
5857
|
+
* answering 200 once rewritten:
|
|
5858
|
+
*
|
|
5859
|
+
* | shape | refused as | rewritten to |
|
|
5860
|
+
* | --- | --- | --- |
|
|
5861
|
+
* | `items` as a TUPLE ARRAY (draft-4 tuple form) | 11129 (DeepSeek) / 11133 (GLM, Kimi, MiMo) | `prefixItems: [...]` + `items: {}` |
|
|
5862
|
+
* | `exclusiveMinimum` / `exclusiveMaximum` as a BOOLEAN (draft-4) | 11129 | the numeric form, derived from the sibling `minimum` / `maximum` |
|
|
5863
|
+
* | `required` as a STRING instead of an array | 11129 | one-element array |
|
|
5864
|
+
* | `required` containing DUPLICATES | 11129 | de-duplicated |
|
|
5865
|
+
* | an EXTERNAL `$ref` (`https://…`, `//host/…`) | 11129 | the reference object removed |
|
|
5866
|
+
*
|
|
5867
|
+
* WHAT IS DELIBERATELY NOT TOUCHED.
|
|
5868
|
+
*
|
|
5869
|
+
* - **Internal `$ref` (`#/…`) stays.** Measured: the recursive
|
|
5870
|
+
* `$defs`/`additionalProperties` schema of `stagehand_extract` — the shape
|
|
5871
|
+
* issue #253 originally blamed — answers 200 on every model tested, as does
|
|
5872
|
+
* the host's whole 75-tool catalog sent at once. Only the EXTERNAL form is
|
|
5873
|
+
* refused. Rewriting internal references would be a large, riskier change
|
|
5874
|
+
* bought with no measured evidence.
|
|
5875
|
+
* - **The boolean `exclusiveMinimum` rewrite is only made when it is safe.** A
|
|
5876
|
+
* draft-4 boolean means "minimum is exclusive"; with no sibling bound there is
|
|
5877
|
+
* nothing to derive, so the key is dropped rather than guessed. Silently
|
|
5878
|
+
* turning `exclusiveMinimum: true` into `exclusiveMinimum: 0` would INVENT a
|
|
5879
|
+
* constraint — a wrong schema that the upstream accepts is worse than a
|
|
5880
|
+
* request that fails loudly.
|
|
5881
|
+
* - **Nothing outside `tools` / `functions` is examined.** `tool_choice`,
|
|
5882
|
+
* messages, and every other body byte keep their existing treatment; a
|
|
5883
|
+
* session-title body or a plain conversation cannot be changed by this.
|
|
5884
|
+
*
|
|
5885
|
+
* Order matters only in that this runs AFTER {@link normalizeToolChoice}: a
|
|
5886
|
+
* suppressed `tools` (from `tool_choice: 'none'`) is already gone, and
|
|
5887
|
+
* normalizing an array that is about to be deleted would be wasted work.
|
|
5888
|
+
*/
|
|
5889
|
+
function normalizeToolSchemas(obj) {
|
|
5890
|
+
normalizeToolArray(obj["tools"]);
|
|
5891
|
+
normalizeToolArray(obj["functions"]);
|
|
5892
|
+
}
|
|
5893
|
+
/** Walk the entries of a `tools` / `functions` array, rewriting each schema. */
|
|
5894
|
+
function normalizeToolArray(value) {
|
|
5895
|
+
if (!Array.isArray(value)) return;
|
|
5896
|
+
for (const entry of value) {
|
|
5897
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
|
|
5898
|
+
const tool = entry;
|
|
5899
|
+
const fn = tool["function"];
|
|
5900
|
+
if (typeof fn === "object" && fn !== null && !Array.isArray(fn)) normalizeSchemaNode(fn["parameters"]);
|
|
5901
|
+
if (tool["function"] === void 0) normalizeSchemaNode(tool["parameters"]);
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
/**
|
|
5905
|
+
* Recursively rewrite ONE schema node in place.
|
|
5906
|
+
*
|
|
5907
|
+
* Recursion is required, not decorative: every one of the measured refusals can
|
|
5908
|
+
* appear at any depth (a tuple `items` inside `properties.a.items`, a bad
|
|
5909
|
+
* `required` inside a nested object). The walk is depth-limited because the
|
|
5910
|
+
* input is arbitrary JSON from a third party — a malformed or pathological
|
|
5911
|
+
* document must not be able to hang a request.
|
|
5912
|
+
*/
|
|
5913
|
+
function normalizeSchemaNode(node, depth = 0) {
|
|
5914
|
+
if (typeof node !== "object" || node === null || Array.isArray(node)) return;
|
|
5915
|
+
if (depth > MAX_SCHEMA_DEPTH) return;
|
|
5916
|
+
const schema = node;
|
|
5917
|
+
normalizeItems(schema);
|
|
5918
|
+
normalizeExclusiveBound(schema, "exclusiveMinimum", "minimum");
|
|
5919
|
+
normalizeExclusiveBound(schema, "exclusiveMaximum", "maximum");
|
|
5920
|
+
normalizeRequired(schema);
|
|
5921
|
+
dropExternalRef(schema);
|
|
5922
|
+
normalizeMetaSchemaTypes(schema);
|
|
5923
|
+
for (const key of SCHEMA_CHILD_MAPS) {
|
|
5924
|
+
const child = schema[key];
|
|
5925
|
+
if (typeof child !== "object" || child === null || Array.isArray(child)) continue;
|
|
5926
|
+
for (const nested of Object.values(child)) normalizeSchemaNode(nested, depth + 1);
|
|
5927
|
+
}
|
|
5928
|
+
for (const key of SCHEMA_CHILD_LISTS) {
|
|
5929
|
+
const list = schema[key];
|
|
5930
|
+
if (!Array.isArray(list)) continue;
|
|
5931
|
+
for (const nested of list) normalizeSchemaNode(nested, depth + 1);
|
|
5932
|
+
}
|
|
5933
|
+
for (const key of SCHEMA_CHILD_DEPENDENCIES) {
|
|
5934
|
+
const child = schema[key];
|
|
5935
|
+
if (typeof child !== "object" || child === null || Array.isArray(child)) continue;
|
|
5936
|
+
for (const nested of Object.values(child)) normalizeSchemaNode(nested, depth + 1);
|
|
5937
|
+
}
|
|
5938
|
+
for (const key of SCHEMA_CHILD_SINGLE) normalizeSchemaNode(schema[key], depth + 1);
|
|
5939
|
+
}
|
|
5940
|
+
/**
|
|
5941
|
+
* Bound the recursion.
|
|
5942
|
+
*
|
|
5943
|
+
* The host's own schemas nest a handful of levels. 64 is far past anything real
|
|
5944
|
+
* and still terminates on a hostile document; the value is a guard against a
|
|
5945
|
+
* hang, not a format rule.
|
|
5946
|
+
*/
|
|
5947
|
+
const MAX_SCHEMA_DEPTH = 64;
|
|
5948
|
+
/** Keywords whose value is a MAP of schemas (each value walked). */
|
|
5949
|
+
const SCHEMA_CHILD_MAPS = [
|
|
5950
|
+
"properties",
|
|
5951
|
+
"patternProperties",
|
|
5952
|
+
"dependentSchemas",
|
|
5953
|
+
"$defs",
|
|
5954
|
+
"definitions"
|
|
5955
|
+
];
|
|
5956
|
+
/** Keywords whose value is a LIST of schemas (each entry walked). */
|
|
5957
|
+
const SCHEMA_CHILD_LISTS = [
|
|
5958
|
+
"allOf",
|
|
5959
|
+
"anyOf",
|
|
5960
|
+
"oneOf",
|
|
5961
|
+
"prefixItems"
|
|
5962
|
+
];
|
|
5963
|
+
/** Keywords whose value is a SINGLE schema (walked directly). */
|
|
5964
|
+
const SCHEMA_CHILD_SINGLE = [
|
|
5965
|
+
"items",
|
|
5966
|
+
"additionalItems",
|
|
5967
|
+
"additionalProperties",
|
|
5968
|
+
"not",
|
|
5969
|
+
"contains",
|
|
5970
|
+
"if",
|
|
5971
|
+
"then",
|
|
5972
|
+
"else",
|
|
5973
|
+
"propertyNames"
|
|
5974
|
+
];
|
|
5975
|
+
/**
|
|
5976
|
+
* Keywords whose value is a MAP whose values may be schemas, where only SOME of
|
|
5977
|
+
* those values are schemas at all (issue #253, second report).
|
|
5978
|
+
*
|
|
5979
|
+
* `dependencies` is draft-4's spelling of two different 2020-12 keywords: an
|
|
5980
|
+
* ARRAY value is `dependentRequired`, an OBJECT value is `dependentSchemas`.
|
|
5981
|
+
* Its object values are therefore descended into like `dependentSchemas`, so a
|
|
5982
|
+
* draft-4 leftover nested inside one is still rewritten.
|
|
5983
|
+
*
|
|
5984
|
+
* Measured raw: `dependencies` itself is ACCEPTED by the upstream, so nothing
|
|
5985
|
+
* here is a refusal fix — it is traversal, so that the rewrites this module owns
|
|
5986
|
+
* reach inside the keyword instead of stopping at it.
|
|
5987
|
+
*/
|
|
5988
|
+
const SCHEMA_CHILD_DEPENDENCIES = ["dependencies"];
|
|
5989
|
+
/**
|
|
5990
|
+
* Repair keyword values whose TYPE the upstream will not take (issue #253).
|
|
5991
|
+
*
|
|
5992
|
+
* THE SECOND REPORT ON #253 WAS A DIFFERENT BUG. The first round migrated
|
|
5993
|
+
* draft-4 SPELLINGS (tuple `items`, boolean exclusive bounds, string `required`,
|
|
5994
|
+
* external `$ref`). The reporter then supplied three more draft-4 spellings
|
|
5995
|
+
* (`type` arrays, `dependencies`, `additionalItems`) and a patch — but all three
|
|
5996
|
+
* were measured ACCEPTED, raw, on `deepseek-v4.1-flash`, so migrating them fixes
|
|
5997
|
+
* nothing. What was actually rejected, measured one keyword at a time against a
|
|
5998
|
+
* raw body, is a class of TYPE errors in the definition itself: 36 of them, in
|
|
5999
|
+
* every position. `title: 1`, `minimum: "0"`, `examples: "x"`, `pattern: 123`,
|
|
6000
|
+
* `allOf: {}`, `additionalProperties: "x"`, `uniqueItems: "true"` — each answers
|
|
6001
|
+
* `11129`, and each answers 200 once the value has the type the keyword takes.
|
|
6002
|
+
*
|
|
6003
|
+
* WHY REPAIR RATHER THAN REPORT. The upstream's own sentence names no keyword
|
|
6004
|
+
* and no tool, and the definition often comes from a third-party bundle or MCP
|
|
6005
|
+
* server the user did not write. Dropping the offending value is what keeps the
|
|
6006
|
+
* tool USABLE: every keyword here is an annotation or a constraint, never
|
|
6007
|
+
* structure — no `properties` map, no `required` list, no schema-valued keyword
|
|
6008
|
+
* is touched — so removing a malformed one cannot change which arguments the
|
|
6009
|
+
* tool accepts. It only stops the definition from being refused outright.
|
|
6010
|
+
*
|
|
6011
|
+
* THE ALTERNATIVE WAS CONSIDERED AND REJECTED: dropping the whole TOOL. It is
|
|
6012
|
+
* simpler, but it silently removes a capability the user installed, and the
|
|
6013
|
+
* model then invents calls to a tool that no longer exists.
|
|
6014
|
+
*
|
|
6015
|
+
* Only values that are WRONG are touched. A schema already carrying correct
|
|
6016
|
+
* types leaves this function byte-identical, which keeps the prompt prefix
|
|
6017
|
+
* stable for caching.
|
|
6018
|
+
*/
|
|
6019
|
+
function normalizeMetaSchemaTypes(schema) {
|
|
6020
|
+
for (const key of SCHEMA_STRING_KEYWORDS) {
|
|
6021
|
+
const value = schema[key];
|
|
6022
|
+
if (value !== void 0 && typeof value !== "string") delete schema[key];
|
|
6023
|
+
}
|
|
6024
|
+
for (const key of SCHEMA_NUMBER_KEYWORDS) {
|
|
6025
|
+
const value = schema[key];
|
|
6026
|
+
if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value))) delete schema[key];
|
|
6027
|
+
}
|
|
6028
|
+
for (const key of SCHEMA_BOOLEAN_KEYWORDS) {
|
|
6029
|
+
const value = schema[key];
|
|
6030
|
+
if (value !== void 0 && typeof value !== "boolean") delete schema[key];
|
|
6031
|
+
}
|
|
6032
|
+
for (const key of SCHEMA_LIST_KEYWORDS) {
|
|
6033
|
+
const value = schema[key];
|
|
6034
|
+
if (value === void 0) continue;
|
|
6035
|
+
if (!Array.isArray(value) || value.length === 0) delete schema[key];
|
|
6036
|
+
}
|
|
6037
|
+
for (const key of SCHEMA_STRING_LIST_KEYWORDS) {
|
|
6038
|
+
const value = schema[key];
|
|
6039
|
+
if (value !== void 0 && !Array.isArray(value)) delete schema[key];
|
|
6040
|
+
}
|
|
6041
|
+
for (const key of SCHEMA_CHILD_SINGLE) {
|
|
6042
|
+
const value = schema[key];
|
|
6043
|
+
if (value === void 0) continue;
|
|
6044
|
+
if (typeof value === "boolean") continue;
|
|
6045
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) delete schema[key];
|
|
6046
|
+
}
|
|
6047
|
+
normalizeTypeKeyword(schema);
|
|
6048
|
+
}
|
|
6049
|
+
/**
|
|
6050
|
+
* Repair `type`, keeping every member the upstream would have taken (issue #253).
|
|
6051
|
+
*
|
|
6052
|
+
* Measured: `type: ["string","null"]` is ACCEPTED as sent, and so is
|
|
6053
|
+
* `dependencies`; only an unknown member (`type: "thing"`) or an empty array is
|
|
6054
|
+
* refused. So this keeps valid members instead of rewriting the array into
|
|
6055
|
+
* `oneOf`, which would be a much larger change to a schema the upstream already
|
|
6056
|
+
* understands.
|
|
6057
|
+
*/
|
|
6058
|
+
function normalizeTypeKeyword(schema) {
|
|
6059
|
+
const type = schema["type"];
|
|
6060
|
+
if (type === void 0) return;
|
|
6061
|
+
const valid = (entry) => typeof entry === "string" && JSON_SCHEMA_TYPES.has(entry);
|
|
6062
|
+
if (typeof type === "string") {
|
|
6063
|
+
if (!valid(type)) delete schema["type"];
|
|
6064
|
+
return;
|
|
6065
|
+
}
|
|
6066
|
+
if (!Array.isArray(type)) {
|
|
6067
|
+
delete schema["type"];
|
|
6068
|
+
return;
|
|
6069
|
+
}
|
|
6070
|
+
const kept = type.filter(valid);
|
|
6071
|
+
if (kept.length === 0) {
|
|
6072
|
+
delete schema["type"];
|
|
6073
|
+
return;
|
|
6074
|
+
}
|
|
6075
|
+
if (kept.length === type.length) return;
|
|
6076
|
+
schema["type"] = kept.length === 1 ? kept[0] : kept;
|
|
6077
|
+
}
|
|
6078
|
+
/** The `type` values JSON Schema defines. */
|
|
6079
|
+
const JSON_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
6080
|
+
"array",
|
|
6081
|
+
"boolean",
|
|
6082
|
+
"integer",
|
|
6083
|
+
"null",
|
|
6084
|
+
"number",
|
|
6085
|
+
"object",
|
|
6086
|
+
"string"
|
|
6087
|
+
]);
|
|
6088
|
+
/** Keywords whose value must be a string. */
|
|
6089
|
+
const SCHEMA_STRING_KEYWORDS = [
|
|
6090
|
+
"title",
|
|
6091
|
+
"description",
|
|
6092
|
+
"pattern",
|
|
6093
|
+
"format",
|
|
6094
|
+
"$comment",
|
|
6095
|
+
"contentMediaType",
|
|
6096
|
+
"contentEncoding",
|
|
6097
|
+
"$id",
|
|
6098
|
+
"$schema",
|
|
6099
|
+
"$anchor",
|
|
6100
|
+
"$dynamicAnchor",
|
|
6101
|
+
"$dynamicRef"
|
|
6102
|
+
];
|
|
6103
|
+
/** Keywords whose value must be a number. */
|
|
6104
|
+
const SCHEMA_NUMBER_KEYWORDS = [
|
|
6105
|
+
"minimum",
|
|
6106
|
+
"maximum",
|
|
6107
|
+
"exclusiveMinimum",
|
|
6108
|
+
"exclusiveMaximum",
|
|
6109
|
+
"multipleOf",
|
|
6110
|
+
"minLength",
|
|
6111
|
+
"maxLength",
|
|
6112
|
+
"minItems",
|
|
6113
|
+
"maxItems",
|
|
6114
|
+
"minProperties",
|
|
6115
|
+
"maxProperties",
|
|
6116
|
+
"minContains",
|
|
6117
|
+
"maxContains"
|
|
6118
|
+
];
|
|
6119
|
+
/** Keywords whose value must be a boolean. */
|
|
6120
|
+
const SCHEMA_BOOLEAN_KEYWORDS = [
|
|
6121
|
+
"uniqueItems",
|
|
6122
|
+
"readOnly",
|
|
6123
|
+
"writeOnly",
|
|
6124
|
+
"deprecated"
|
|
6125
|
+
];
|
|
6126
|
+
/**
|
|
6127
|
+
* Keywords whose value must be a NON-EMPTY array of schemas.
|
|
6128
|
+
*
|
|
6129
|
+
* Measured: an empty `allOf` / `anyOf` / `oneOf` / `prefixItems` is refused
|
|
6130
|
+
* (`11129`), while an empty `required` / `enum` / `examples` is ACCEPTED. Only
|
|
6131
|
+
* these four are repaired, so a legal empty `required: []` keeps its bytes —
|
|
6132
|
+
* which also keeps 5.24.2's "empty required string becomes `[]`" behaviour
|
|
6133
|
+
* intact instead of turning it into an absent keyword.
|
|
6134
|
+
*/
|
|
6135
|
+
const SCHEMA_LIST_KEYWORDS = [
|
|
6136
|
+
"allOf",
|
|
6137
|
+
"anyOf",
|
|
6138
|
+
"oneOf",
|
|
6139
|
+
"prefixItems"
|
|
6140
|
+
];
|
|
6141
|
+
/**
|
|
6142
|
+
* Keywords whose value must be an array, where an EMPTY array is legal.
|
|
6143
|
+
*
|
|
6144
|
+
* `enum` and `examples` are accepted empty and NOT accepted as a scalar;
|
|
6145
|
+
* `required` is accepted empty. Split from {@link SCHEMA_LIST_KEYWORDS} because
|
|
6146
|
+
* that one also drops empties, which is wrong for these.
|
|
6147
|
+
*/
|
|
6148
|
+
const SCHEMA_STRING_LIST_KEYWORDS = [
|
|
6149
|
+
"required",
|
|
6150
|
+
"enum",
|
|
6151
|
+
"examples"
|
|
6152
|
+
];
|
|
6153
|
+
/**
|
|
6154
|
+
* Convert draft-4's tuple `items` into the 2020-12 spelling.
|
|
6155
|
+
*
|
|
6156
|
+
* A tuple `items` is a LIST; the modern spec splits it into `prefixItems` (the
|
|
6157
|
+
* per-position schemas, same order) plus `items` (the schema for everything
|
|
6158
|
+
* past the end). Emitting `items: {}` for the tail is the faithful reading of a
|
|
6159
|
+
* draft-4 tuple: draft-4 said nothing about additional items, so "anything" is
|
|
6160
|
+
* correct — inventing `false` would FORBID extra elements, which the original
|
|
6161
|
+
* never said.
|
|
6162
|
+
*
|
|
6163
|
+
* Measured: `prefixItems` + `items: {}` answers 200 on `deepseek-v4.1-flash`,
|
|
6164
|
+
* `deepseek-v4-pro`, `glm-5.3`, `kimi-k3.1-pro` and `mimo-v2.6-pro` — the five
|
|
6165
|
+
* strictest models in the catalog — and on every model that accepted the tuple
|
|
6166
|
+
* form already.
|
|
6167
|
+
*/
|
|
6168
|
+
function normalizeItems(schema) {
|
|
6169
|
+
const items = schema["items"];
|
|
6170
|
+
if (!Array.isArray(items)) return;
|
|
6171
|
+
if (items.length === 0) {
|
|
6172
|
+
delete schema["items"];
|
|
6173
|
+
delete schema["prefixItems"];
|
|
6174
|
+
delete schema["additionalItems"];
|
|
6175
|
+
schema["items"] = {};
|
|
6176
|
+
return;
|
|
6177
|
+
}
|
|
6178
|
+
if (schema["prefixItems"] === void 0) schema["prefixItems"] = items;
|
|
6179
|
+
const tail = schema["additionalItems"];
|
|
6180
|
+
schema["items"] = typeof tail === "object" && tail !== null && !Array.isArray(tail) ? tail : {};
|
|
6181
|
+
delete schema["additionalItems"];
|
|
6182
|
+
}
|
|
6183
|
+
/**
|
|
6184
|
+
* Rewrite a draft-4 BOOLEAN exclusive bound into the numeric form.
|
|
6185
|
+
*
|
|
6186
|
+
* Draft-4: `{minimum: 0, exclusiveMinimum: true}` means "greater than 0".
|
|
6187
|
+
* 2020-12: `{exclusiveMinimum: 0}` means the same. The value is therefore
|
|
6188
|
+
* DERIVED from the sibling bound — and when that sibling is absent or not a
|
|
6189
|
+
* finite number there is nothing to derive, so the key is dropped.
|
|
6190
|
+
*
|
|
6191
|
+
* Dropping is the safe direction: it WEAKENS a constraint the upstream already
|
|
6192
|
+
* could not read, and every request that fails today fails on the shape, not on
|
|
6193
|
+
* the constraint. Inventing `0` would attach a bound the caller never wrote.
|
|
6194
|
+
*/
|
|
6195
|
+
function normalizeExclusiveBound(schema, exclusiveKey, boundKey) {
|
|
6196
|
+
if (schema[exclusiveKey] !== true) {
|
|
6197
|
+
if (schema[exclusiveKey] === false) delete schema[exclusiveKey];
|
|
6198
|
+
return;
|
|
6199
|
+
}
|
|
6200
|
+
const bound = schema[boundKey];
|
|
6201
|
+
if (typeof bound === "number" && Number.isFinite(bound)) {
|
|
6202
|
+
schema[exclusiveKey] = bound;
|
|
6203
|
+
delete schema[boundKey];
|
|
6204
|
+
return;
|
|
6205
|
+
}
|
|
6206
|
+
delete schema[exclusiveKey];
|
|
6207
|
+
}
|
|
6208
|
+
/**
|
|
6209
|
+
* Force `required` into the de-duplicated string array the upstream accepts.
|
|
6210
|
+
*
|
|
6211
|
+
* A non-array `required` is not JSON Schema at all, so there is no "faithful"
|
|
6212
|
+
* conversion for it: a string is read as one property name, and anything else
|
|
6213
|
+
* (a number, `null`) carries no names and is dropped. Duplicates are removed
|
|
6214
|
+
* because the upstream refuses them (measured) and they never meant anything:
|
|
6215
|
+
* `required` is a set.
|
|
6216
|
+
*/
|
|
6217
|
+
function normalizeRequired(schema) {
|
|
6218
|
+
const required = schema["required"];
|
|
6219
|
+
if (required === void 0) return;
|
|
6220
|
+
if (typeof required === "string") {
|
|
6221
|
+
schema["required"] = required === "" ? [] : [required];
|
|
6222
|
+
return;
|
|
6223
|
+
}
|
|
6224
|
+
if (!Array.isArray(required)) {
|
|
6225
|
+
delete schema["required"];
|
|
6226
|
+
return;
|
|
6227
|
+
}
|
|
6228
|
+
const names = [];
|
|
6229
|
+
for (const entry of required) {
|
|
6230
|
+
if (typeof entry !== "string" || names.includes(entry)) continue;
|
|
6231
|
+
names.push(entry);
|
|
6232
|
+
}
|
|
6233
|
+
if (names.length === required.length) return;
|
|
6234
|
+
schema["required"] = names;
|
|
6235
|
+
}
|
|
6236
|
+
/**
|
|
6237
|
+
* Remove an EXTERNAL `$ref`, which the upstream refuses, while leaving internal
|
|
6238
|
+
* ones alone.
|
|
6239
|
+
*
|
|
6240
|
+
* `#/…` is a reference into the same document and is accepted (measured on the
|
|
6241
|
+
* recursive `$defs` shape of `stagehand_extract`, and on the host's whole
|
|
6242
|
+
* catalog). Anything with a URI part is not resolvable by the upstream at all,
|
|
6243
|
+
* so the pointer is deleted in place: the object degrades to "any value", which
|
|
6244
|
+
* accepts more than the original said rather than rejecting a valid call.
|
|
6245
|
+
*
|
|
6246
|
+
* A sibling `description` / `title` / `default` is kept — deleting the whole
|
|
6247
|
+
* object would throw away author documentation along with the reference.
|
|
6248
|
+
*/
|
|
6249
|
+
function dropExternalRef(schema) {
|
|
6250
|
+
const ref = schema["$ref"];
|
|
6251
|
+
if (typeof ref !== "string" || ref === "") return;
|
|
6252
|
+
if (ref.startsWith("#")) return;
|
|
6253
|
+
delete schema["$ref"];
|
|
6254
|
+
}
|
|
6255
|
+
/**
|
|
5747
6256
|
* What a PREPARED request body declares, as the input to DSML recovery.
|
|
5748
6257
|
*
|
|
5749
6258
|
* This exists so the recovery path can answer the one question its gates turn
|
|
@@ -10602,7 +11111,7 @@ function describeRosterSeenPayload(raw) {
|
|
|
10602
11111
|
//#endregion
|
|
10603
11112
|
//#region src/version.ts
|
|
10604
11113
|
/** The npm package version this build was produced from. */
|
|
10605
|
-
const WORKBUDDY_CONNECT_VERSION = "5.24.
|
|
11114
|
+
const WORKBUDDY_CONNECT_VERSION = "5.24.4";
|
|
10606
11115
|
//#endregion
|
|
10607
11116
|
//#region src/host-heartbeat.ts
|
|
10608
11117
|
/**
|
|
@@ -10836,4 +11345,4 @@ async function clearHostHeartbeat(owner) {
|
|
|
10836
11345
|
if (current === owner.contents) await rm(owner.path, { force: true });
|
|
10837
11346
|
}
|
|
10838
11347
|
//#endregion
|
|
10839
|
-
export {
|
|
11348
|
+
export { CREDENTIAL_REJECTED_CODE as $, isWatermarkFreeImageModel as $t, withoutRouters as A, workbuddyAppExecutableCandidates as An, REFUSES_OFF_MODEL_IDS as At, defaultDesktopAuthPath as B, parseSupportedSecondsRange as Bt, setDeviceMode as C, findWorkbuddyAppExecutableWithSource as Cn, regionOf as Ct, applyContextBudgets as D, macosNestedAppBundles as Dn, attachBusyLevels as Dt, WorkBuddyCatalog as E, macosBundleExecutable as En, toolSchemaRejectAdvice as Et, WorkBuddyCredentialStore as F, recordRefusal as Ft, parseWorkBuddyAuth as G, IMAGE_TAG_TEXT_TO_IMAGE as Gt, isEncryptedCredentialError as H, resolveVideoParams as Ht, WorkBuddyEncryptedCredentialError as I, withEffectiveOff as It, workbuddyOwnAuthPath as J, imageDataUrl as Jt, preferredAccountName as K, MAX_INPUT_IMAGE_BYTES as Kt, authFileName as L, VIDEO_TAG_IMAGE_TO_VIDEO as Lt, WORKBUDDY_AUTH_FILENAME as M, resolveDshHome as Mn, lastRefusalFor as Mt, WORKBUDDY_AUTH_FILE_ENV as N, withFileLock as Nn, offDefaultFor as Nt, deriveCatalog as O, openEncryptedField as On, promoBadgeTone as Ot, WORKBUDDY_VAULT_DIRNAME as P, writeFileAtomic as Pn, offRefused as Pt, CONTEXT_OVERFLOW_MARKER as Q, isBareBase64Image as Qt, defaultDesktopAuthCandidates as R, VIDEO_TAG_TEXT_TO_VIDEO as Rt, saveDeviceSdkSettings as S, findWorkbuddyAppExecutable as Sn, prepareChatBody as St, FALLBACK_WORKBUDDY_MODELS_GLOBAL as T, isWorkbuddyBundle as Tn, rewriteSessionTitleModel as Tt, isVaultAccountId as U, IMAGE_SIZE_LIMITS_WIDE as Ut, hasEncryptedCredentialFields as V, pickVideoModel as Vt, legacyWorkbuddyOwnAuthPath as W, IMAGE_TAG_IMAGE_TO_IMAGE as Wt, APP_VERSION as X, imageModelChoices as Xt, workbuddyVaultDir as Y, imageMimeForPath as Yt, BODY_OVERSIZE_MARKER as Z, imageSizeLimitsOf as Zt, createDeviceProfileLookup as _, WORKBUDDY_APP_EXECUTABLE_ENV as _n, openingEvidenceOfBody as _t, readHostHeartbeat as a, pruneTempDir as an, classifyUpstreamError as at, readDeviceSettings as b, deriveAtRestKeyId as bn, parseUpstreamModel as bt, WORKBUDDY_CONNECT_VERSION as c, nativeModalityOf as cn, forceNeutralHead as ct, rosterSeenPath as d, ensureDeviceSalt as dn, isConversationIdGateBody as dt, parseImageDataUrl as en, DEFAULT_WIRE_PROFILE as et, WORKBUDDY_CN_BASE_ENV as f, readDeviceSalt as fn, isCredentialRejectedError as ft, createTuringSdk as g, protectCredentialDirectory as gn, modelIdOfBody as gt, createDeviceSdkPort as h, inspectCredentialDirectory as hn, knownRegionOf as ht, processStartTimeMs as i, queueNoticeText as in, channelGateMemberOf as it, ENCRYPTED_CREDENTIAL_CODE as j, hostPeersInfo as jn, defaultOffModelIds as jt, fallbackModelsFor as k, readAtRestKey as kn, selectPromoBadge as kt, createFileRosterSeenStore as l, WORKBUDDY_DEVICE_TOKEN_FILE_ENV as ln, isBodyOversizeRefusal as lt, piAiRuntimeInfo as m, isDeviceId as mn, isToolSchemaRejectBody as mt, clearHostHeartbeat as n, sniffImageMime as nn, WorkBuddyCredentialRejectedError as nt, workbuddyHostHeartbeatPath as o, NATIVE_MODALITY_BY_MODEL_ID as on, declaredTools as ot, resolveCnGateway as p, deriveDeviceId as pn, isFirstMessageGateBody as pt, workbuddyAccountId as q, WorkBuddyImageError as qt, isHeartbeatProcessAlive as r, parseQueueAnswer as rn, WorkBuddyUpstreamClient as rt, writeHostHeartbeat as s, imageDefaultFor as sn, describeRequestHeaderNames as st, WORKBUDDY_HOST_HEARTBEAT_FILENAME as t, pickMediaModel as tn, WORKBUDDY_FALLBACK_SYSTEM_PROMPT as tt, describeRosterSeenPayload as u, readDeviceTokenFile as un, isContextTooLongBody as ut, describeDerivedDevices as v, clearAtRestKeyCache as vn, parseCreditMultiplier as vt, FALLBACK_WORKBUDDY_MODELS as w, isEncryptedFieldWrapper as wn, requestEvidenceOf as wt, saveDeviceProfile as x, fetchAtRestKeyPayload as xn, perturbChannelFingerprints as xt, isDeviceMode as y, deriveAtRestKey as yn, parseReasoning as yt, defaultDesktopAuthDirs as z, WorkBuddyVideoError as zt };
|
package/lib/index.d.ts
CHANGED
|
@@ -2711,10 +2711,29 @@ interface ContextRescue {
|
|
|
2711
2711
|
*
|
|
2712
2712
|
* @param sessionId - session whose history should be folded.
|
|
2713
2713
|
* @param window - context window of the route that just overflowed.
|
|
2714
|
+
* @param cause - what refused the request (issue #258).
|
|
2715
|
+
*
|
|
2716
|
+
* `'window'` (the default) is the token overflow this rescue was written
|
|
2717
|
+
* for: the target is a fraction of the model's declared window.
|
|
2718
|
+
*
|
|
2719
|
+
* `'body-bytes'` is a request refused because its SERIALIZED BODY exceeded
|
|
2720
|
+
* a byte ceiling some component enforces. The target is then a fraction of
|
|
2721
|
+
* the CURRENT measurement, never of the window — see
|
|
2722
|
+
* {@link BODY_OVERSIZE_TARGET_FRACTION} for why the window target would
|
|
2723
|
+
* silently fold nothing.
|
|
2724
|
+
*
|
|
2714
2725
|
* @returns whether any history was folded.
|
|
2715
2726
|
*/
|
|
2716
|
-
rescue(sessionId: string, window: number): Promise<boolean>;
|
|
2727
|
+
rescue(sessionId: string, window: number, cause?: RescueCause): Promise<boolean>;
|
|
2717
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* What refused the request.
|
|
2731
|
+
*
|
|
2732
|
+
* Only two values, and the distinction is not cosmetic: it decides which number
|
|
2733
|
+
* the fold target is derived from, and getting it wrong makes the rescue a
|
|
2734
|
+
* no-op rather than a wrong-but-visible action (see the fraction constant).
|
|
2735
|
+
*/
|
|
2736
|
+
type RescueCause = 'window' | 'body-bytes';
|
|
2718
2737
|
//#endregion
|
|
2719
2738
|
//#region src/adapter.d.ts
|
|
2720
2739
|
/** Provider route this bundle owns for the domestic (CN) gateway. */
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $ as CREDENTIAL_REJECTED_CODE, $t as isWatermarkFreeImageModel, A as withoutRouters, An as workbuddyAppExecutableCandidates, At as REFUSES_OFF_MODEL_IDS, B as defaultDesktopAuthPath, Bt as parseSupportedSecondsRange, C as setDeviceMode, Ct as regionOf, D as applyContextBudgets, Dn as macosNestedAppBundles, Dt as attachBusyLevels, E as WorkBuddyCatalog, En as macosBundleExecutable, Et as toolSchemaRejectAdvice, F as WorkBuddyCredentialStore, Ft as recordRefusal, G as parseWorkBuddyAuth, Gt as IMAGE_TAG_TEXT_TO_IMAGE, H as isEncryptedCredentialError, Ht as resolveVideoParams, I as WorkBuddyEncryptedCredentialError, It as withEffectiveOff, J as workbuddyOwnAuthPath, Jt as imageDataUrl, K as preferredAccountName, Kt as MAX_INPUT_IMAGE_BYTES, L as authFileName, Lt as VIDEO_TAG_IMAGE_TO_VIDEO, M as WORKBUDDY_AUTH_FILENAME, Mn as resolveDshHome, Mt as lastRefusalFor, N as WORKBUDDY_AUTH_FILE_ENV, Nn as withFileLock, Nt as offDefaultFor, O as deriveCatalog, On as openEncryptedField, Ot as promoBadgeTone, Pn as writeFileAtomic, Pt as offRefused, Q as CONTEXT_OVERFLOW_MARKER, Qt as isBareBase64Image, R as defaultDesktopAuthCandidates, Rt as VIDEO_TAG_TEXT_TO_VIDEO, S as saveDeviceSdkSettings, Sn as findWorkbuddyAppExecutable, St as prepareChatBody, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, Tn as isWorkbuddyBundle, Tt as rewriteSessionTitleModel, U as isVaultAccountId, Ut as IMAGE_SIZE_LIMITS_WIDE, V as hasEncryptedCredentialFields, Vt as pickVideoModel, W as legacyWorkbuddyOwnAuthPath, Wt as IMAGE_TAG_IMAGE_TO_IMAGE, X as APP_VERSION, Xt as imageModelChoices, Yt as imageMimeForPath, Z as BODY_OVERSIZE_MARKER, Zt as imageSizeLimitsOf, _ as createDeviceProfileLookup, _n as WORKBUDDY_APP_EXECUTABLE_ENV, _t as openingEvidenceOfBody, a as readHostHeartbeat, an as pruneTempDir, at as classifyUpstreamError, b as readDeviceSettings, bn as deriveAtRestKeyId, bt as parseUpstreamModel, c as WORKBUDDY_CONNECT_VERSION, cn as nativeModalityOf, ct as forceNeutralHead, dt as isConversationIdGateBody, en as parseImageDataUrl, ft as isCredentialRejectedError, g as createTuringSdk, gt as modelIdOfBody, h as createDeviceSdkPort, ht as knownRegionOf, i as processStartTimeMs, in as queueNoticeText, it as channelGateMemberOf, j as ENCRYPTED_CREDENTIAL_CODE, jt as defaultOffModelIds, k as fallbackModelsFor, kn as readAtRestKey, kt as selectPromoBadge, l as createFileRosterSeenStore, lt as isBodyOversizeRefusal, m as piAiRuntimeInfo, mn as isDeviceId, mt as isToolSchemaRejectBody, n as clearHostHeartbeat, nn as sniffImageMime, nt as WorkBuddyCredentialRejectedError, o as workbuddyHostHeartbeatPath, on as NATIVE_MODALITY_BY_MODEL_ID, ot as declaredTools, p as resolveCnGateway, pt as isFirstMessageGateBody, q as workbuddyAccountId, qt as WorkBuddyImageError, r as isHeartbeatProcessAlive, rn as parseQueueAnswer, rt as WorkBuddyUpstreamClient, s as writeHostHeartbeat, sn as imageDefaultFor, t as WORKBUDDY_HOST_HEARTBEAT_FILENAME, tn as pickMediaModel, tt as WORKBUDDY_FALLBACK_SYSTEM_PROMPT, ut as isContextTooLongBody, v as describeDerivedDevices, vn as clearAtRestKeyCache, vt as parseCreditMultiplier, w as FALLBACK_WORKBUDDY_MODELS, wn as isEncryptedFieldWrapper, wt as requestEvidenceOf, x as saveDeviceProfile, xn as fetchAtRestKeyPayload, xt as perturbChannelFingerprints, y as isDeviceMode, yn as deriveAtRestKey, yt as parseReasoning, z as defaultDesktopAuthDirs, zt as WorkBuddyVideoError } from "./host-heartbeat-BbJWHKQq.js";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { appendFile, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
4
|
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -2131,6 +2131,28 @@ function withLegacyContext(api, generation, identity = WORKBUDDY_MODEL_IDENTITY,
|
|
|
2131
2131
|
};
|
|
2132
2132
|
}
|
|
2133
2133
|
/**
|
|
2134
|
+
* Which rescue, if any, an error event calls for (issue #258).
|
|
2135
|
+
*
|
|
2136
|
+
* ALL of an error message's text is searched, in the shapes pi-ai hands over:
|
|
2137
|
+
* `errorMessage` on the assistant message is the one that matters, but a
|
|
2138
|
+
* provider that fills only `content` or throws a bare string has been measured,
|
|
2139
|
+
* so the reader is deliberately tolerant. The scan never throws: a message with
|
|
2140
|
+
* no strings in it simply calls for no rescue.
|
|
2141
|
+
*
|
|
2142
|
+
* `'window'` wins when both readings somehow apply, because the token overflow
|
|
2143
|
+
* is the one this rescue was originally written for and its target is the more
|
|
2144
|
+
* conservative of the two.
|
|
2145
|
+
*/
|
|
2146
|
+
function rescueCauseOf(error) {
|
|
2147
|
+
if (isContextOverflow(error)) return "window";
|
|
2148
|
+
const text = [
|
|
2149
|
+
typeof error.errorMessage === "string" ? error.errorMessage : "",
|
|
2150
|
+
typeof error.content === "string" ? error.content : "",
|
|
2151
|
+
...Array.isArray(error.content) ? error.content.map((part) => typeof part === "object" && part !== null && typeof part.text === "string" ? part.text : "") : []
|
|
2152
|
+
].join(" ");
|
|
2153
|
+
return isBodyOversizeRefusal(text) ? "body-bytes" : void 0;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2134
2156
|
* Layer the host-side context-overflow rescue onto a provider's streams.
|
|
2135
2157
|
*
|
|
2136
2158
|
* pi-ai reports a provider failure as an `error` event rather than a throw, so
|
|
@@ -2159,7 +2181,10 @@ function withContextRescue(api, resolve) {
|
|
|
2159
2181
|
for await (const event of source) {
|
|
2160
2182
|
if (event.type === "done") final = event.message;
|
|
2161
2183
|
if (event.type === "error") final = event.error;
|
|
2162
|
-
if (event.type === "error"
|
|
2184
|
+
if (event.type === "error") {
|
|
2185
|
+
const cause = rescueCauseOf(event.error);
|
|
2186
|
+
if (cause !== void 0) await rescue.rescue(sessionId, window, cause);
|
|
2187
|
+
}
|
|
2163
2188
|
out.push(event);
|
|
2164
2189
|
}
|
|
2165
2190
|
out.end(final);
|
|
@@ -2520,6 +2545,30 @@ function createWorkBuddyAdapter(options) {
|
|
|
2520
2545
|
const CHUNK_FRACTION = .35;
|
|
2521
2546
|
/** Post-fold measurement target: comfortably below the window the route allows. */
|
|
2522
2547
|
const TARGET_FRACTION = .6;
|
|
2548
|
+
/**
|
|
2549
|
+
* Post-fold target for a BYTE refusal, as a fraction of the CURRENT measurement
|
|
2550
|
+
* (issue #258).
|
|
2551
|
+
*
|
|
2552
|
+
* WHY NOT THE WINDOW. The ceiling that refuses these requests is in BYTES; the
|
|
2553
|
+
* measurement this rescue reads is in TOKENS. A reporter measured the crossing
|
|
2554
|
+
* point at roughly 150k tokens for an 8 MiB ceiling — while the model declares a
|
|
2555
|
+
* 1,000,000-token window, so `window * 0.6` is 600,000. The first measurement
|
|
2556
|
+
* then already satisfies `totalTokens <= target`, the loop returns on its first
|
|
2557
|
+
* pass, and the identical oversized body is re-sent: a rescue that reports
|
|
2558
|
+
* success while doing nothing is worse than one that reports failure.
|
|
2559
|
+
*
|
|
2560
|
+
* Deriving the target from the measurement itself avoids needing to know the
|
|
2561
|
+
* ceiling at all: one fold always removes at least 10% of what is there, so the
|
|
2562
|
+
* loop cannot be trivially satisfied, and repeated rounds converge on whatever
|
|
2563
|
+
* the ceiling happens to be.
|
|
2564
|
+
*
|
|
2565
|
+
* 0.9 rather than something smaller on purpose: the ceiling is unknown, so
|
|
2566
|
+
* folding aggressively would throw away far more history than necessary on a
|
|
2567
|
+
* request that only just crossed it. 10% per round, up to {@link MAX_ROUNDS},
|
|
2568
|
+
* covers a 57% reduction — enough for a body that overshot by a few percent,
|
|
2569
|
+
* which is the measured shape (8,401,132 B against a 8,388,608 B ceiling).
|
|
2570
|
+
*/
|
|
2571
|
+
const BODY_OVERSIZE_TARGET_FRACTION = .9;
|
|
2523
2572
|
/** A session is never folded more than this many times by one rescue. */
|
|
2524
2573
|
const MAX_ROUNDS = 8;
|
|
2525
2574
|
/** How many times one chunk may shrink its tail edge before giving up. */
|
|
@@ -2534,11 +2583,11 @@ const FOLD_TIMEOUT_MS = 18e4;
|
|
|
2534
2583
|
*/
|
|
2535
2584
|
function createContextRescue(resolve) {
|
|
2536
2585
|
const inflight = /* @__PURE__ */ new Set();
|
|
2537
|
-
return { async rescue(sessionId, window) {
|
|
2586
|
+
return { async rescue(sessionId, window, cause = "window") {
|
|
2538
2587
|
if (inflight.has(sessionId)) return false;
|
|
2539
2588
|
inflight.add(sessionId);
|
|
2540
2589
|
try {
|
|
2541
|
-
return await foldUntilFits(resolve(), sessionId, window);
|
|
2590
|
+
return await foldUntilFits(resolve(), sessionId, window, cause);
|
|
2542
2591
|
} catch (error) {
|
|
2543
2592
|
resolve().log?.("dsh-connect-workbuddy: context rescue failed", error);
|
|
2544
2593
|
return false;
|
|
@@ -2547,16 +2596,29 @@ function createContextRescue(resolve) {
|
|
|
2547
2596
|
}
|
|
2548
2597
|
} };
|
|
2549
2598
|
}
|
|
2550
|
-
|
|
2599
|
+
/**
|
|
2600
|
+
* The fold target for one rescue, in the MEASUREMENT's own unit (tokens).
|
|
2601
|
+
*
|
|
2602
|
+
* Split out and pure so the unit mismatch that caused issue #258 is testable
|
|
2603
|
+
* without a host: the two causes derive the same number from two different
|
|
2604
|
+
* quantities, and only one of them can be trivially satisfied by the first
|
|
2605
|
+
* measurement.
|
|
2606
|
+
*/
|
|
2607
|
+
function rescueTargetOf(cause, window, measuredTokens) {
|
|
2608
|
+
if (cause === "body-bytes") return Math.max(1, Math.floor(measuredTokens * BODY_OVERSIZE_TARGET_FRACTION));
|
|
2609
|
+
return Math.max(1, Math.floor(window * TARGET_FRACTION));
|
|
2610
|
+
}
|
|
2611
|
+
async function foldUntilFits(deps, sessionId, window, cause) {
|
|
2551
2612
|
const { meter, compaction, agents } = deps;
|
|
2552
2613
|
if (meter === void 0 || compaction === void 0 || agents === void 0) return false;
|
|
2553
2614
|
const agent = agents.get(sessionId);
|
|
2554
2615
|
if (agent === void 0) return false;
|
|
2555
|
-
|
|
2616
|
+
let target = NaN;
|
|
2556
2617
|
let foldedAny = false;
|
|
2557
2618
|
let previous = Number.POSITIVE_INFINITY;
|
|
2558
2619
|
for (let round = 0; round < MAX_ROUNDS; round += 1) {
|
|
2559
2620
|
const measurement = meter.measure(agent.session);
|
|
2621
|
+
if (round === 0) target = rescueTargetOf(cause, window, measurement.totalTokens);
|
|
2560
2622
|
if (measurement.totalTokens <= target) return foldedAny;
|
|
2561
2623
|
if (measurement.totalTokens >= previous) return foldedAny;
|
|
2562
2624
|
previous = measurement.totalTokens;
|
|
@@ -6154,9 +6216,11 @@ function createWorkBuddyShim(options) {
|
|
|
6154
6216
|
if (detail?.requestId !== void 0) meta.push(`requestId ${detail.requestId}`);
|
|
6155
6217
|
const stamp = meta.length === 0 ? "" : `(${meta.join(",")})`;
|
|
6156
6218
|
const refusedTier = reasoningTierRefusal(result);
|
|
6157
|
-
const
|
|
6158
|
-
const
|
|
6159
|
-
const
|
|
6219
|
+
const toolSchemaRefused = result.kind === "client" && isToolSchemaRejectBody(result.message);
|
|
6220
|
+
const receipt = refusedTier ?? (toolSchemaRefused ? toolSchemaRejectAdvice() : void 0) ?? detail?.tips ?? detail?.displayMsg ?? clippedUpstreamText(result.message, 400);
|
|
6221
|
+
const advice = refusedTier !== void 0 ? "这不是账号或网络问题:该模型实测拒绝「off」推理档位,请到模型卡片里取消该行的「可关闭思考」勾选后重试" : toolSchemaRefused ? "按上面列出的写法检查工具定义;换模型只是绕开,不会修好它" : result.kind === "client" ? "该请求被上游按参数拒绝:与网络、账号、额度都无关,换账号也不会改变结果,请按上面的提示调整后重试" : shortfall === void 0 ? "" : "建议换一个模型继续,或稍后等待该账号的额度恢复";
|
|
6222
|
+
const bodyOversize = isBodyOversizeRefusal(result.message);
|
|
6223
|
+
const body = `${isContextTooLongBody(result.message) ? `${CONTEXT_OVERFLOW_MARKER}。` : bodyOversize ? `${BODY_OVERSIZE_MARKER}。` : ""}${advice === "" ? receipt : `${receipt.replace(/[。.]$/u, "")}。${advice}`}`;
|
|
6160
6224
|
writeOpenAIError(res, KIND_STATUS[result.kind], result.kind, `workbuddy 上游失败:${failoverReasonText(result)}(http ${result.status})${note}${why}${stamp}。${body}`, hostErrorCode(result.kind));
|
|
6161
6225
|
return;
|
|
6162
6226
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-connect-workbuddy",
|
|
3
3
|
"displayName": "DSH Connect WorkBuddy",
|
|
4
4
|
"description": "把本机登录的 WorkBuddy 模型(国内版与国际版)接入 DeepSeek Harness:每次刷新按上游目录自动读取每个模型的积分倍率,支持逐模型图片输入开关、多账号切换与账号池自动换号,并提供每日签到、卡片与输入框里的胶囊积分读数等只读积分概览。",
|
|
5
|
-
"version": "5.24.
|
|
5
|
+
"version": "5.24.4",
|
|
6
6
|
"author": "dingminhua",
|
|
7
7
|
"copyright": "Copyright (c) 2026 LaoDing",
|
|
8
8
|
"license": "MIT",
|