@zzz0350/our-workbuddy-standalone 5.31.4 → 5.31.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/README.md +17 -2
- package/main.js +413 -45
- package/package.json +20 -1
- package/start-hidden.vbs +9 -5
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
把 WorkBuddy 变成一个**本地 OpenAI 兼容网关**。不依赖 DSH、不依赖 Cordis、不需要 `npm install` —— 一个 Node 进程,一个 `main.js` 文件,双击就能用。
|
|
4
4
|
|
|
5
|
-
当前版本 **5.31.
|
|
5
|
+
当前版本 **5.31.8**(已同步上游 `v5.31.8`)。侧栏显示独立版版本号,账号测试显示中文结果和 HTTP 错误提示,用量页默认显示最近一周。
|
|
6
|
+
|
|
7
|
+
5.31.8 同步上游 `v5.31.5~v5.31.8` 中与独立网关相关的全部修复(跳过只与 DSH 宿主前端有关的 `v5.31.7` #313/#314):企业账号读模型目录补齐身份头(#303);failover 换号后 11128 补跑渠道救援阶梯并修正尝试计数(#302/#307);11128 报错附零隐私指纹线索(#311);网关 HTML 401 不再误判凭据吊销,且实时正余额自动自愈 `credential-rejected`(#305);出站剥离已注入的 `assistant` 中性头且救援第一级只补 `system` 头(#297);同时修复 `start-hidden.vbs` 快捷方式在端口未启动时误判已启动的问题。
|
|
8
|
+
|
|
9
|
+
5.31.4 同步 #293 和 #295 的渠道校验改词修复:将系统消息中的 Claude Code `official CLI` 自述句和 `runtime context` 检出目录说明改为中性表述,解决这两类文本触发的 400 / 11128 错误。#294 的路由鉴权调整仅适用于 DSH 宿主。
|
|
6
10
|
|
|
7
11
|
5.31.2 同步上游至 `v5.31.2`(修复 DSH 0.2.3 图片预算字段与非英文 macOS 宿主 PID 检测);默认改为后台无窗口启动,网关日志统一写入 `%USERPROFILE%\.our-workbuddy\logs\gateway.log`。
|
|
8
12
|
|
|
@@ -221,6 +225,17 @@ npm run release -- 5.32.0 --same/--dry-run
|
|
|
221
225
|
|
|
222
226
|
## 更新日志
|
|
223
227
|
|
|
228
|
+
### v5.31.8 (2026-11-26)
|
|
229
|
+
- 同步上游 v5.31.5~v5.31.8 独立网关相关修复(跳过只与 DSH 宿主前端相关的 v5.31.7 #313/#314)
|
|
230
|
+
- 企业账号读取模型目录带齐身份头,修复企业账号 cli 名册缺行(#303)
|
|
231
|
+
- failover 换号后触发 11128 补跑渠道救援阶梯并修正账号尝试计数(#302/#307);11128 报错附零隐私指纹线索(#311)
|
|
232
|
+
- 网关 HTML 401 不再误判为凭据吊销,且实时查回正余额可自动自愈 credential-rejected(#305)
|
|
233
|
+
- 出站剥离已注入的 assistant 中性头,渠道救援第一级仅补 system 中性头避免模型模仿(#297)
|
|
234
|
+
- 修复 start-hidden.vbs 在未启动时因 VBScript 短路求值误判端口已启动的问题
|
|
235
|
+
|
|
236
|
+
### v5.31.5 (2026-11-25)
|
|
237
|
+
- 同步上游 v5.31.4(#293/#295 渠道校验改词修复,解决 Claude Code official CLI 自述句与 runtime context 触发的 400/11128 错误)
|
|
238
|
+
|
|
224
239
|
### v5.31.4 (2026-11-24)
|
|
225
240
|
- 版本更新内容改为展示中文功能变更说明,自动过滤 npm 临时占位版本
|
|
226
241
|
- 支持从 npm 发布说明与 README 更新日志自动汇总历史版本功能变更
|
|
@@ -480,7 +495,7 @@ logs/gateway.log 日志
|
|
|
480
495
|
|
|
481
496
|
## 同步上游并构建
|
|
482
497
|
|
|
483
|
-
在本仓库的 GitHub **Actions → Build standalone gateway → Run workflow** 里填写 `upstream_ref`。默认取 `dingminhua/dsh-connect-workbuddy` 的 `main`,也可以指定分支、标签或提交 SHA。要选用当前发布的上游基线,填 `
|
|
498
|
+
在本仓库的 GitHub **Actions → Build standalone gateway → Run workflow** 里填写 `upstream_ref`。默认取 `dingminhua/dsh-connect-workbuddy` 的 `main`,也可以指定分支、标签或提交 SHA。要选用当前发布的上游基线,填 `221530ab26450a4caf51eeec7db420c36edfd9f0`(`v5.31.8`)。
|
|
484
499
|
|
|
485
500
|
GitHub runner 取上游源码,逐个应用 `source/patches/` 中的补丁,再复制独立网关和回归测试。一个补丁完整通过反向检查时视为上游已包含。三方合并冲突、构建或测试失败时,先处理日志里列出的错误再重新运行。
|
|
486
501
|
|
package/main.js
CHANGED
|
@@ -4326,6 +4326,54 @@ async function resolveWireIdentity(identity) {
|
|
|
4326
4326
|
deviceSalt: readout.salt
|
|
4327
4327
|
};
|
|
4328
4328
|
}
|
|
4329
|
+
/**
|
|
4330
|
+
* Account identity headers for the catalog reads (`fetchModels` / `fetchMediaModels`).
|
|
4331
|
+
*
|
|
4332
|
+
* `/v3/config` answers PER ACCOUNT, and the account is named by the request:
|
|
4333
|
+
* the official app's REST layer stamps `X-User-Id` + `X-Enterprise-Id` +
|
|
4334
|
+
* `X-Tenant-Id` (+ `X-Domain`) on EVERY outgoing request, the config read
|
|
4335
|
+
* included, so the app is always answered as the signed-in member. This plugin
|
|
4336
|
+
* read the directory with a bearer token alone, and on an enterprise account
|
|
4337
|
+
* that is a DIFFERENT question: the gateway fell back to the personal roster,
|
|
4338
|
+
* which listed none of the enterprise-only rows (measured 2026-11-25, CN
|
|
4339
|
+
* gateway, an `ultimate` account — five `cli`-agent rows were missing,
|
|
4340
|
+
* including a GA model the app offered in its own selector on the same
|
|
4341
|
+
* account minutes earlier).
|
|
4342
|
+
*
|
|
4343
|
+
* The headers travel TOGETHER or not at all. Sending `X-Enterprise-Id` without
|
|
4344
|
+
* `X-User-Id` is worse than sending neither: measured on the same account, the
|
|
4345
|
+
* gateway then answered a document whose `cli` agent had NO models, so the
|
|
4346
|
+
* read resolved to an empty roster and the region degraded to the legacy
|
|
4347
|
+
* directory. Hence one helper for the whole set, and hence `X-Tenant-Id` is
|
|
4348
|
+
* included even though nothing observed required it — it is what the official
|
|
4349
|
+
* client sends, and a partial imitation of a working request is how the empty
|
|
4350
|
+
* roster above was produced.
|
|
4351
|
+
*
|
|
4352
|
+
* `uid`/`enterpriseId` are `undefined` when the credential carries neither and
|
|
4353
|
+
* `''` only when the app wrote an empty value; both mean "absent", and absent
|
|
4354
|
+
* means the header is simply omitted (`chatHeaders` sends the `X-No-*` form
|
|
4355
|
+
* instead, but those are the CLI's chat conventions and were never observed on
|
|
4356
|
+
* the config read).
|
|
4357
|
+
*
|
|
4358
|
+
* THE ENTERPRISE BLOCK IS GATED ON `uid` TOO. `uid === ''` is a reachable
|
|
4359
|
+
* state (`auth.ts` writes `uid: identity['uid'] ?? ''`), so an enterprise
|
|
4360
|
+
* credential with an empty uid would otherwise send `X-Enterprise-Id` /
|
|
4361
|
+
* `X-Tenant-Id` WITHOUT `X-User-Id` — exactly the partial shape that the
|
|
4362
|
+
* measurement above proved yields an empty `cli` roster. The "together or not
|
|
4363
|
+
* at all" rule therefore lives in the CONDITION, not just in this comment:
|
|
4364
|
+
* no uid means no enterprise block either.
|
|
4365
|
+
*/
|
|
4366
|
+
function catalogIdentityHeaders(credential) {
|
|
4367
|
+
const hasUser = credential.uid !== "";
|
|
4368
|
+
return {
|
|
4369
|
+
...hasUser ? { "X-User-Id": credential.uid } : {},
|
|
4370
|
+
...hasUser && credential.enterpriseId !== void 0 && credential.enterpriseId !== "" ? {
|
|
4371
|
+
"X-Enterprise-Id": credential.enterpriseId,
|
|
4372
|
+
"X-Tenant-Id": credential.enterpriseId
|
|
4373
|
+
} : {},
|
|
4374
|
+
...credential.domain === "" ? {} : { "X-Domain": credential.domain }
|
|
4375
|
+
};
|
|
4376
|
+
}
|
|
4329
4377
|
/** Chat request headers, including the X-No-* conventions the official CLI uses. */
|
|
4330
4378
|
function chatHeaders(credential, identity = {}, stableConversationId) {
|
|
4331
4379
|
return {
|
|
@@ -4692,7 +4740,8 @@ const CHANNEL_GATE_PHRASES = [
|
|
|
4692
4740
|
["and do not claim to have inspected it before reading.", "and never claim to have inspected it before reading it."],
|
|
4693
4741
|
["@\"...\" quotes a path containing spaces.", "A path containing spaces is quoted with @\"...\"."],
|
|
4694
4742
|
["without naming another target, they mean this GUI.", "and names no other target, the interface described here is meant."],
|
|
4695
|
-
["they mean this GUI.", "the interface described here is meant."]
|
|
4743
|
+
["they mean this GUI.", "the interface described here is meant."],
|
|
4744
|
+
["The runtime context names the DeepSeek Harness implementation checkout.", "The runtime context names the local implementation checkout."]
|
|
4696
4745
|
];
|
|
4697
4746
|
/**
|
|
4698
4747
|
* Shape-locked rewrites for THIRD-PARTY coding CLIs' self-introduction lines
|
|
@@ -4733,7 +4782,11 @@ const CHANNEL_GATE_PHRASES = [
|
|
|
4733
4782
|
* a digit) in the span patterns, so it can carry `4.6` / `2.1.327` but can never
|
|
4734
4783
|
* jump a sentence boundary.
|
|
4735
4784
|
*/
|
|
4736
|
-
const CHANNEL_GATE_PATTERNS = [
|
|
4785
|
+
const CHANNEL_GATE_PATTERNS = [
|
|
4786
|
+
[/\bYou are\s+(?:an?\s+)?(?:the\s+)?Grok\b(?:[^.\n]|\.(?=[\w])){0,60}?\b(?:(?:released|made|built|created|developed|trained|powered)\s+)?(?:by|from)\s+xAI\b[^.\n]*/gi, "You are an autonomous coding agent"],
|
|
4787
|
+
[/^[ \t]*You are\s+(?:[^.\n]|\.(?=\d)){0,120}?\b(?:released|made|built|created|developed|trained|powered)\s+(?:by|on|from)\s+(?:xAI|Anthropic|OpenAI|Google(?:\s+DeepMind)?|Meta|Mistral)\b[^.\n]*/gm, "You are an autonomous coding agent"],
|
|
4788
|
+
[/^[ \t]*You are\s+[\w-]+(?:\s+[\w.]+)?\s*,\s*(?:xAI|Anthropic|OpenAI|Google(?:\s+DeepMind)?|Meta|Mistral)'s\s+official\s+CLI\s+for\s+[\w-]+\b[^.\n]*/gim, "You are an autonomous coding agent"]
|
|
4789
|
+
];
|
|
4737
4790
|
/**
|
|
4738
4791
|
* Rewrite the measured gate phrases in one text part.
|
|
4739
4792
|
*
|
|
@@ -4902,7 +4955,7 @@ function neutralizeScannedText(text) {
|
|
|
4902
4955
|
* Never throws. A body it cannot read is the upstream's to reject, and a
|
|
4903
4956
|
* parse error must not turn a retry into a crash.
|
|
4904
4957
|
*/
|
|
4905
|
-
function
|
|
4958
|
+
function forceHeadInBody(bodyJson, mode) {
|
|
4906
4959
|
let parsed;
|
|
4907
4960
|
try {
|
|
4908
4961
|
parsed = JSON.parse(bodyJson);
|
|
@@ -4918,6 +4971,7 @@ function forceNeutralHead(bodyJson) {
|
|
|
4918
4971
|
if (typeof value !== "object" || value === null || Array.isArray(value)) continue;
|
|
4919
4972
|
const message = value;
|
|
4920
4973
|
if (!scansOpening(message["role"])) continue;
|
|
4974
|
+
if (mode === "system" && message["role"] !== "system" && message["role"] !== "developer") continue;
|
|
4921
4975
|
const content = message["content"];
|
|
4922
4976
|
if (typeof content === "string") {
|
|
4923
4977
|
if (content.trim() === "" || startsWithNeutralHead(content)) continue;
|
|
@@ -4941,6 +4995,33 @@ function forceNeutralHead(bodyJson) {
|
|
|
4941
4995
|
return JSON.stringify(obj);
|
|
4942
4996
|
}
|
|
4943
4997
|
/**
|
|
4998
|
+
* ISSUE #297 — the FIRST rescue rung: prepend the neutral head to SYSTEM only.
|
|
4999
|
+
*
|
|
5000
|
+
* The gateway's offset-0 gate is a blacklist (measured: Kimi / Cursor / Gemini
|
|
5001
|
+
* openings all answer 200), so system needs only a non-banned opening, and a
|
|
5002
|
+
* system message is not part of the model's own chat history — the model never
|
|
5003
|
+
* imitates it into a future assistant reply. This is enough to rescue the
|
|
5004
|
+
* measured #98 / #189 shapes (system prompt opening refused) WITHOUT planting
|
|
5005
|
+
* the persona line in assistant history, which is what caused #297.
|
|
5006
|
+
*
|
|
5007
|
+
* `undefined` means "nothing changed" — same contract as {@link forceNeutralHead}.
|
|
5008
|
+
*/
|
|
5009
|
+
function forceSystemHead(bodyJson) {
|
|
5010
|
+
return forceHeadInBody(bodyJson, "system");
|
|
5011
|
+
}
|
|
5012
|
+
/**
|
|
5013
|
+
* The LAST rescue rung: prepend the neutral head to EVERY scanned message,
|
|
5014
|
+
* system and assistant. Kept for the unmeasured case of an assistant opening
|
|
5015
|
+
* that is neither in the prefix blacklist nor covered by the phrase rewrites —
|
|
5016
|
+
* moving it off offset 0 is the only known general rescue. It is deliberately
|
|
5017
|
+
* the LAST rung because it is the one that plants the persona line in assistant
|
|
5018
|
+
* history (issue #297): a model sees its own past answers opening with that
|
|
5019
|
+
* line and copies it into new replies, which the host persists.
|
|
5020
|
+
*/
|
|
5021
|
+
function forceNeutralHead(bodyJson) {
|
|
5022
|
+
return forceHeadInBody(bodyJson, "all");
|
|
5023
|
+
}
|
|
5024
|
+
/**
|
|
4944
5025
|
* The invisible character used to break a content fingerprint.
|
|
4945
5026
|
*
|
|
4946
5027
|
* U+200B ZERO WIDTH SPACE: it renders as nothing, it is not whitespace for the
|
|
@@ -5170,6 +5251,81 @@ function openingEvidenceOfBody(bodyJson) {
|
|
|
5170
5251
|
return evidence;
|
|
5171
5252
|
}
|
|
5172
5253
|
/**
|
|
5254
|
+
* ISSUE #311 — zero-privacy diagnostic for a middle-of-prompt channel gate.
|
|
5255
|
+
*
|
|
5256
|
+
* When the gateway matches a fixed span ANYWHERE inside a large system prompt,
|
|
5257
|
+
* "first line + byte count" tells the reader nothing: a 259k prompt has tens of
|
|
5258
|
+
* thousands of candidate lines and the plugin cannot see which one matched.
|
|
5259
|
+
* This trace reports ONLY COUNTS AND LINE NUMBERS of a small set of identity /
|
|
5260
|
+
* brand words — never a byte of message text — so a user can locate a suspect
|
|
5261
|
+
* line in their OWN transcript (which they already have) and bisect it, and a
|
|
5262
|
+
* maintainer can tell at a glance whether an unrewritten brand sentence is
|
|
5263
|
+
* present on the wire.
|
|
5264
|
+
*
|
|
5265
|
+
* TWO HALVES:
|
|
5266
|
+
* 1. brand/identity word occurrences with line numbers, per scanned message;
|
|
5267
|
+
* 2. a rewrite self-check: how many known `CHANNEL_GATE_PHRASES` `from` strings
|
|
5268
|
+
* are STILL present in the prepared body (a rewrite that silently missed
|
|
5269
|
+
* would otherwise be indistinguishable from a new upstream fingerprint).
|
|
5270
|
+
*
|
|
5271
|
+
* No text is ever returned — only the words themselves (a fixed vocabulary),
|
|
5272
|
+
* counts, and line numbers. Safe to paste into a public issue.
|
|
5273
|
+
*/
|
|
5274
|
+
const TRACE_WORDS = [
|
|
5275
|
+
"DeepSeek Harness",
|
|
5276
|
+
"codebuddy",
|
|
5277
|
+
"You are",
|
|
5278
|
+
"powered by",
|
|
5279
|
+
"coding agent"
|
|
5280
|
+
];
|
|
5281
|
+
const TRACE_MAX_LINES_PER_WORD = 6;
|
|
5282
|
+
function channelFingerprintTrace(rawJson, preparedJson) {
|
|
5283
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
5284
|
+
const parse = (json) => {
|
|
5285
|
+
try {
|
|
5286
|
+
return JSON.parse(json);
|
|
5287
|
+
} catch {
|
|
5288
|
+
return;
|
|
5289
|
+
}
|
|
5290
|
+
};
|
|
5291
|
+
const raw = parse(rawJson);
|
|
5292
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
5293
|
+
const messages = raw["messages"];
|
|
5294
|
+
if (Array.isArray(messages)) for (let index = 0; index < messages.length; index++) {
|
|
5295
|
+
const value = messages[index];
|
|
5296
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) continue;
|
|
5297
|
+
const message = value;
|
|
5298
|
+
const role = typeof message["role"] === "string" ? message["role"].trim().toLowerCase() : "";
|
|
5299
|
+
if (role !== "system" && role !== "assistant" && role !== "developer") continue;
|
|
5300
|
+
const texts = [];
|
|
5301
|
+
if (typeof message["content"] === "string") texts.push(message["content"]);
|
|
5302
|
+
else if (Array.isArray(message["content"])) for (const part of message["content"]) {
|
|
5303
|
+
if (typeof part !== "object" || part === null || Array.isArray(part)) continue;
|
|
5304
|
+
const record = part;
|
|
5305
|
+
if ((record["type"] === "text" || record["type"] === void 0) && typeof record["text"] === "string") texts.push(record["text"]);
|
|
5306
|
+
}
|
|
5307
|
+
const combined = texts.join("\n");
|
|
5308
|
+
if (combined === "") continue;
|
|
5309
|
+
const lines = combined.split("\n");
|
|
5310
|
+
const perWord = /* @__PURE__ */ new Map();
|
|
5311
|
+
for (const word of TRACE_WORDS) {
|
|
5312
|
+
const found = [];
|
|
5313
|
+
for (let line = 0; line < lines.length && found.length < TRACE_MAX_LINES_PER_WORD; line++) if (lines[line]?.toLowerCase().includes(word.toLowerCase())) found.push(line + 1);
|
|
5314
|
+
if (found.length > 0) perWord.set(word, found);
|
|
5315
|
+
}
|
|
5316
|
+
if (perWord.size > 0) occurrences.set(index, perWord);
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
const unrewrittenRows = [];
|
|
5320
|
+
if (typeof preparedJson === "string") {
|
|
5321
|
+
for (let row = 0; row < CHANNEL_GATE_PHRASES.length; row++) if (preparedJson.includes(CHANNEL_GATE_PHRASES[row]?.[0] ?? "\0")) unrewrittenRows.push(row + 1);
|
|
5322
|
+
}
|
|
5323
|
+
return {
|
|
5324
|
+
occurrences,
|
|
5325
|
+
unrewrittenRows
|
|
5326
|
+
};
|
|
5327
|
+
}
|
|
5328
|
+
/**
|
|
5173
5329
|
* How many openings the failure path reports.
|
|
5174
5330
|
*
|
|
5175
5331
|
* Eight is generous: the gate scans every system message and every text part
|
|
@@ -5364,6 +5520,70 @@ function stripLeadingAcpTag(content) {
|
|
|
5364
5520
|
changed: false
|
|
5365
5521
|
};
|
|
5366
5522
|
}
|
|
5523
|
+
/**
|
|
5524
|
+
* ISSUE #297 — strip the plugin's OWN neutral head from assistant history on
|
|
5525
|
+
* the outbound copy, so a poisoned session stops reinforcing itself.
|
|
5526
|
+
*
|
|
5527
|
+
* When the gateway refuses a body, `neutralizeScannedText` / `forceNeutralHead`
|
|
5528
|
+
* prepend `You are a helpful assistant.\n\n` to EVERY scanned message — including
|
|
5529
|
+
* past assistant turns. The model sees its own whole history opening with that
|
|
5530
|
+
* persona line and starts copying it into NEW answers, which the host persists
|
|
5531
|
+
* as ordinary model output (restart/upgrade cannot clear it). The reporter
|
|
5532
|
+
* proved the mechanism by swapping the line for a meaningless `Message begins.`
|
|
5533
|
+
* and watching the model copy THAT instead: it is shape mimicry, not a write-
|
|
5534
|
+
* back into the transcript.
|
|
5535
|
+
*
|
|
5536
|
+
* SCOPE — deliberately narrow, because this deletes bytes from the wire:
|
|
5537
|
+
*
|
|
5538
|
+
* - ONLY assistant messages. `system` keeps its head (the gateway wants it, and
|
|
5539
|
+
* it is not the model's own history). `user`/`tool` are never scanned, and
|
|
5540
|
+
* rewriting a user's words has no upstream basis.
|
|
5541
|
+
* - ONLY the exact injected SHAPE: the head followed by a blank line. A user
|
|
5542
|
+
* who genuinely asks for an answer starting with that sentence does not add
|
|
5543
|
+
* the blank line, so their words survive. A bare `Message begins.`-style
|
|
5544
|
+
* string is NOT in the strip table — the plugin never injected it.
|
|
5545
|
+
* - Up to eight layers, so a model that repeated the head cannot make this an
|
|
5546
|
+
* unbounded loop. A part stripped to empty keeps its original text: an empty
|
|
5547
|
+
* assistant text part means nothing on the wire.
|
|
5548
|
+
*
|
|
5549
|
+
* Called AFTER the phrase rewrite (so a newly exposed banned opening can still
|
|
5550
|
+
* be neutralised) and BEFORE `neutralizeChannelFingerprints` (which would
|
|
5551
|
+
* otherwise re-add a head to a just-exposed opening).
|
|
5552
|
+
*/
|
|
5553
|
+
const INJECTED_HEAD = `${WORKBUDDY_FALLBACK_SYSTEM_PROMPT}\n\n`;
|
|
5554
|
+
const MAX_INJECTED_HEAD_LAYERS = 8;
|
|
5555
|
+
function stripInjectedAssistantHead(text) {
|
|
5556
|
+
let out = text;
|
|
5557
|
+
for (let layer = 0; layer < MAX_INJECTED_HEAD_LAYERS && out.startsWith(INJECTED_HEAD); layer++) {
|
|
5558
|
+
const rest = out.slice(INJECTED_HEAD.length);
|
|
5559
|
+
if (rest.trim() === "") break;
|
|
5560
|
+
out = rest;
|
|
5561
|
+
}
|
|
5562
|
+
return out;
|
|
5563
|
+
}
|
|
5564
|
+
function stripInjectedAssistantHeads(obj) {
|
|
5565
|
+
const messages = obj["messages"];
|
|
5566
|
+
if (!Array.isArray(messages)) return;
|
|
5567
|
+
for (const value of messages) {
|
|
5568
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) continue;
|
|
5569
|
+
const message = value;
|
|
5570
|
+
if (message["role"] !== "assistant") continue;
|
|
5571
|
+
const content = message["content"];
|
|
5572
|
+
if (typeof content === "string") {
|
|
5573
|
+
const next = stripInjectedAssistantHead(content);
|
|
5574
|
+
if (next !== content) message["content"] = next;
|
|
5575
|
+
continue;
|
|
5576
|
+
}
|
|
5577
|
+
if (!Array.isArray(content)) continue;
|
|
5578
|
+
for (const part of content) {
|
|
5579
|
+
if (typeof part !== "object" || part === null || Array.isArray(part)) continue;
|
|
5580
|
+
const record = part;
|
|
5581
|
+
if (record["type"] !== "text" || typeof record["text"] !== "string") continue;
|
|
5582
|
+
const next = stripInjectedAssistantHead(record["text"]);
|
|
5583
|
+
if (next !== record["text"]) record["text"] = next;
|
|
5584
|
+
}
|
|
5585
|
+
}
|
|
5586
|
+
}
|
|
5367
5587
|
/** Whether this message is one of the harness's injected context blocks. */
|
|
5368
5588
|
function isInjectedUserMessage(message, pattern) {
|
|
5369
5589
|
if (message["role"] !== "user") return false;
|
|
@@ -5437,6 +5657,7 @@ function prepareChatBody(source, options) {
|
|
|
5437
5657
|
ensureSystemHead(obj);
|
|
5438
5658
|
if (options?.keepPromptLast === true && Array.isArray(obj["messages"])) keepPromptLast(obj["messages"], injectedPrefixPattern(options.extraInjectedPrefixes));
|
|
5439
5659
|
rewriteChannelFingerprintPhrasesInBody(obj);
|
|
5660
|
+
stripInjectedAssistantHeads(obj);
|
|
5440
5661
|
neutralizeChannelFingerprints(obj);
|
|
5441
5662
|
normalizeToolChoice(obj);
|
|
5442
5663
|
normalizeToolSchemas(obj);
|
|
@@ -6117,13 +6338,21 @@ function declaredTools(bodyJson) {
|
|
|
6117
6338
|
};
|
|
6118
6339
|
}
|
|
6119
6340
|
/**
|
|
6120
|
-
* Gateway (openresty/APISIX) rejection
|
|
6341
|
+
* Gateway (openresty/APISIX) edge rejection, detected from its HTML error page.
|
|
6342
|
+
*
|
|
6343
|
+
* The business APIs answer JSON; the gateway answers an HTML error page before
|
|
6344
|
+
* the request is routed. WHAT that rejection means is NOT decidable from the
|
|
6345
|
+
* body alone — issue #305 measured the same APISIX 401 on a chat probe while
|
|
6346
|
+
* the SAME token answered 200 on `/v2/plugin/account` and billing, so the gate
|
|
6347
|
+
* refused that ROUTE, not the token. (An earlier comment here claimed such a
|
|
6348
|
+
* page was "almost always a revoked/expired token"; #305 disproved it.) The
|
|
6349
|
+
* only conclusive revocation signal is a business JSON body carrying
|
|
6350
|
+
* `12153`/`Offline user session not found`, or a 401/403 on the REFRESH hop.
|
|
6121
6351
|
*
|
|
6122
|
-
*
|
|
6123
|
-
*
|
|
6124
|
-
*
|
|
6125
|
-
*
|
|
6126
|
-
* also be HTML) is still described accurately.
|
|
6352
|
+
* Kept as a body-shape test so a caller can tell "the gateway refused at the
|
|
6353
|
+
* edge" from "the business API refused the credential" — but callers MUST NOT
|
|
6354
|
+
* turn the former into a permanent credential rejection on body shape alone.
|
|
6355
|
+
* Exported for `outcomeOfFailure` (`src/probe.ts`), which needs the same split.
|
|
6127
6356
|
*/
|
|
6128
6357
|
function isGatewayAuthRejection(status, text) {
|
|
6129
6358
|
if (status !== 401 && status !== 403) return false;
|
|
@@ -6835,8 +7064,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6835
7064
|
headers: {
|
|
6836
7065
|
"Authorization": `Bearer ${credential.accessToken}`,
|
|
6837
7066
|
"Accept": "application/json",
|
|
6838
|
-
...credential
|
|
6839
|
-
...credential.domain === "" ? {} : { "X-Domain": credential.domain },
|
|
7067
|
+
...catalogIdentityHeaders(credential),
|
|
6840
7068
|
"X-Product": "SaaS",
|
|
6841
7069
|
"X-Requested-With": "XMLHttpRequest",
|
|
6842
7070
|
"Connection": "close",
|
|
@@ -6909,7 +7137,8 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6909
7137
|
"Accept": "application/json",
|
|
6910
7138
|
"Origin": originReferer(credential),
|
|
6911
7139
|
"Referer": `${originReferer(credential)}/`,
|
|
6912
|
-
"User-Agent": PRODUCT_UA
|
|
7140
|
+
"User-Agent": PRODUCT_UA,
|
|
7141
|
+
...catalogIdentityHeaders(credential)
|
|
6913
7142
|
},
|
|
6914
7143
|
signal: timeout
|
|
6915
7144
|
});
|
|
@@ -7006,7 +7235,8 @@ var WorkBuddyUpstreamClient = class {
|
|
|
7006
7235
|
"Accept": "application/json",
|
|
7007
7236
|
"Origin": originReferer(credential),
|
|
7008
7237
|
"Referer": `${originReferer(credential)}/`,
|
|
7009
|
-
"User-Agent": mediaChannelUA
|
|
7238
|
+
"User-Agent": mediaChannelUA,
|
|
7239
|
+
...catalogIdentityHeaders(credential)
|
|
7010
7240
|
},
|
|
7011
7241
|
signal: signal ?? AbortSignal.timeout(JSON_TIMEOUT_MS)
|
|
7012
7242
|
});
|
|
@@ -11974,14 +12204,14 @@ function clippedUpstreamText(text, limit) {
|
|
|
11974
12204
|
* WHAT THAT MARKER MAY NOT SAY (issue #213). It used to read 「网关可能新增了
|
|
11975
12205
|
* 词条」, and a reporter read it as "this opening went out verbatim" — then
|
|
11976
12206
|
* reported that the three `assistant` openings the gate had named were never
|
|
11977
|
-
* neutralised at all.
|
|
11978
|
-
*
|
|
11979
|
-
*
|
|
11980
|
-
*
|
|
11981
|
-
*
|
|
11982
|
-
*
|
|
11983
|
-
*
|
|
11984
|
-
*
|
|
12207
|
+
* neutralised at all. The marker describes the FIRST attempt and only the
|
|
12208
|
+
* opening's FIRST LINE; the gateway matches an exact substring anywhere in
|
|
12209
|
+
* the text, so a first line absent from the snapshot says nothing about the
|
|
12210
|
+
* message as a whole. (Since #297 the common rescue adds the head to SYSTEM
|
|
12211
|
+
* only, so a later refused attempt need not have heads on assistant openings
|
|
12212
|
+
* at all — the blind all-role head is now the last rung.) Both facts are
|
|
12213
|
+
* stated in the reply's closing sentence, which is the part a reporter
|
|
12214
|
+
* actually quotes back at us.
|
|
11985
12215
|
*
|
|
11986
12216
|
* Capped at {@link CHANNEL_EVIDENCE_LIMIT} entries: a session can carry dozens
|
|
11987
12217
|
* of system/assistant messages, and a wall of them would bury the one that
|
|
@@ -11999,6 +12229,27 @@ function channelEvidenceText(bodyJson) {
|
|
|
11999
12229
|
const hidden = entries.length - shown.length;
|
|
12000
12230
|
return `请求里被网关扫描的消息开头:${rendered}${hidden > 0 ? `……另有 ${hidden} 条未列出。` : "。"}`;
|
|
12001
12231
|
}
|
|
12232
|
+
/**
|
|
12233
|
+
* ISSUE #311 — render the zero-privacy fingerprint trace as an APPENDED line.
|
|
12234
|
+
*
|
|
12235
|
+
* Counts and line numbers only, never message text. A reader can open their own
|
|
12236
|
+
* transcript at the reported line and bisect the suspect sentence; a maintainer
|
|
12237
|
+
* can see whether a known rewrite silently missed. Kept as a separate APPEND so
|
|
12238
|
+
* every existing evidence assertion (which matches the prefix) still holds.
|
|
12239
|
+
*/
|
|
12240
|
+
function fingerprintTraceText(raw, prepared) {
|
|
12241
|
+
const trace = channelFingerprintTrace(raw, prepared);
|
|
12242
|
+
const parts = [];
|
|
12243
|
+
for (const [index, perWord] of trace.occurrences) {
|
|
12244
|
+
const words = [...perWord].map(([word, lines]) => `${word} ${lines.length} 处(行 ${lines.join("/")}${lines.length >= TRACE_LINE_CAP_HINT ? "…" : ""})`);
|
|
12245
|
+
parts.push(`消息 ${index}: ${words.join(",")}`);
|
|
12246
|
+
}
|
|
12247
|
+
if (trace.unrewrittenRows.length > 0) parts.push(`改词自检:${trace.unrewrittenRows.length} 条已知指纹仍留在发出的 body 里(改写表第 ${trace.unrewrittenRows.join("/")} 条)`);
|
|
12248
|
+
else parts.push("改词自检:全部已知指纹已从发出的 body 清除");
|
|
12249
|
+
return `零正文指纹线索(仅计数与行号,不含正文):${parts.join(";")}。`;
|
|
12250
|
+
}
|
|
12251
|
+
/** Mirrors the trace's per-word line cap, for the "…" hint only. */
|
|
12252
|
+
const TRACE_LINE_CAP_HINT = 6;
|
|
12002
12253
|
/** How many message openings the channel-gate reply lists. */
|
|
12003
12254
|
const CHANNEL_EVIDENCE_LIMIT = 4;
|
|
12004
12255
|
/**
|
|
@@ -12422,17 +12673,24 @@ function createWorkBuddyShim(options) {
|
|
|
12422
12673
|
* sends the same bytes, so without a rescue the only outcome is a dead end
|
|
12423
12674
|
* the reader cannot get out of.
|
|
12424
12675
|
*
|
|
12425
|
-
*
|
|
12676
|
+
* Four rungs, all on the SAME credential (the gate reads the request, not
|
|
12426
12677
|
* the account, which is why `channel_reject` is not failover-worthy):
|
|
12427
12678
|
*
|
|
12428
|
-
* 1. `
|
|
12429
|
-
*
|
|
12430
|
-
*
|
|
12679
|
+
* 1. `forceSystemHead` — move the SYSTEM opening behind the neutral head.
|
|
12680
|
+
* Measured: whatever the banned opening is, moving it off the start of
|
|
12681
|
+
* the content answers 200. Only system is touched (issue #297): an
|
|
12682
|
+
* assistant head is copied by the model into future replies, so the
|
|
12683
|
+
* common rescue must not plant it in assistant history.
|
|
12431
12684
|
* 2. `perturbChannelFingerprints` — insert zero-width spaces at the
|
|
12432
12685
|
* sentence boundaries of the scanned messages, which breaks an
|
|
12433
12686
|
* exact-substring fingerprint without changing a word the model reads.
|
|
12434
12687
|
* This is the rung that rescues the inside-the-prompt fingerprints,
|
|
12435
12688
|
* where rung 1 is a no-op.
|
|
12689
|
+
* 3. dense `perturbChannelFingerprints` — same, at every word boundary,
|
|
12690
|
+
* for a fingerprinted prose span with no punctuation.
|
|
12691
|
+
* 4. `forceNeutralHead` — the LAST resort: the blind, all-role head. Only
|
|
12692
|
+
* when 1–3 failed. This is the one that plants the persona line in
|
|
12693
|
+
* assistant history, so it is reserved for the unmeasured case.
|
|
12436
12694
|
*
|
|
12437
12695
|
* Both return `undefined` when they would change nothing; that is the
|
|
12438
12696
|
* signal not to spend a request on a body that would be refused identically.
|
|
@@ -12443,37 +12701,76 @@ function createWorkBuddyShim(options) {
|
|
|
12443
12701
|
* as an account failure: it was the request that was refused, not the
|
|
12444
12702
|
* credential.
|
|
12445
12703
|
*/
|
|
12446
|
-
let
|
|
12704
|
+
let retriedWithSystemHead = false;
|
|
12447
12705
|
let retriedWithPerturbation = false;
|
|
12448
12706
|
let retriedWithDensePerturbation = false;
|
|
12449
|
-
|
|
12450
|
-
|
|
12707
|
+
let retriedWithBlindHead = false;
|
|
12708
|
+
/**
|
|
12709
|
+
* The channel-gate rescue ladder, as a reusable step.
|
|
12710
|
+
*
|
|
12711
|
+
* ISSUE #302 / #307. This used to be an inline block that ran ONCE, on the
|
|
12712
|
+
* first account's first answer only. But `channel_reject` is not failover-
|
|
12713
|
+
* worthy (`isFailoverWorthy` excludes it), so the failover loop can still
|
|
12714
|
+
* END on one: an account that answers 429/402/5xx is swapped for another,
|
|
12715
|
+
* and THAT account's answer to the same body is a 11128. The ladder had
|
|
12716
|
+
* already run (or been skipped) before the loop, so the final refusal —
|
|
12717
|
+
* the one the user actually reads — never saw a rescue, and `retryNote`
|
|
12718
|
+
* came back EMPTY even though the request was refused for a prompt reason.
|
|
12719
|
+
*
|
|
12720
|
+
* Making it a function lets the SAME ladder run again after failover, once,
|
|
12721
|
+
* on the result the user will actually see. The `retried*` flags are shared
|
|
12722
|
+
* so the second call is a no-op when the first already spent all three
|
|
12723
|
+
* rungs — no extra request is sent for a body the ladder already tried.
|
|
12724
|
+
*/
|
|
12725
|
+
const rescueChannelReject = async (initial) => {
|
|
12726
|
+
if (initial.ok || initial.kind !== "channel_reject" || controller.signal.aborted) return initial;
|
|
12727
|
+
let current = initial;
|
|
12728
|
+
const forced = forceSystemHead(prepared);
|
|
12451
12729
|
if (forced !== void 0) {
|
|
12452
|
-
logger?.warn("dsh-connect-workbuddy: the channel gate refused the body; retrying once with the neutral head
|
|
12453
|
-
|
|
12454
|
-
|
|
12730
|
+
logger?.warn("dsh-connect-workbuddy: the channel gate refused the body; retrying once with the neutral head on the system opening only");
|
|
12731
|
+
current = await client.chatStream(credential, forced, controller.signal, sessionConversationId);
|
|
12732
|
+
retriedWithSystemHead = true;
|
|
12455
12733
|
}
|
|
12456
|
-
if (!
|
|
12734
|
+
if (!current.ok && current.kind === "channel_reject" && !controller.signal.aborted) {
|
|
12457
12735
|
const rescued = perturbChannelFingerprints(forced ?? prepared);
|
|
12458
12736
|
if (rescued !== void 0) {
|
|
12459
12737
|
logger?.warn("dsh-connect-workbuddy: the channel gate refused the body again; retrying once with an invisible perturbation of the scanned text");
|
|
12460
|
-
|
|
12738
|
+
current = await client.chatStream(credential, rescued, controller.signal, sessionConversationId);
|
|
12461
12739
|
retriedWithPerturbation = true;
|
|
12462
|
-
if (
|
|
12740
|
+
if (current.ok) channelNeedsPerturbation = true;
|
|
12463
12741
|
}
|
|
12464
12742
|
}
|
|
12465
|
-
if (!
|
|
12743
|
+
if (!current.ok && current.kind === "channel_reject" && !controller.signal.aborted) {
|
|
12466
12744
|
const dense = perturbChannelFingerprints(forced ?? prepared, true);
|
|
12467
12745
|
if (dense !== void 0) {
|
|
12468
12746
|
logger?.warn("dsh-connect-workbuddy: the channel gate refused the sparse perturbation too; retrying once with a dense word-boundary perturbation");
|
|
12469
|
-
|
|
12747
|
+
current = await client.chatStream(credential, dense, controller.signal, sessionConversationId);
|
|
12470
12748
|
retriedWithDensePerturbation = true;
|
|
12471
|
-
if (
|
|
12749
|
+
if (current.ok && channelPerturbation === "failure") channelNeedsPerturbation = true;
|
|
12472
12750
|
}
|
|
12473
12751
|
}
|
|
12474
|
-
|
|
12752
|
+
if (!current.ok && current.kind === "channel_reject" && !controller.signal.aborted) {
|
|
12753
|
+
const blind = forceNeutralHead(forced ?? prepared);
|
|
12754
|
+
if (blind !== void 0) {
|
|
12755
|
+
logger?.warn("dsh-connect-workbuddy: the system-only head and both perturbations were refused; retrying once with the neutral head forced in front of every opening (including assistant history)");
|
|
12756
|
+
current = await client.chatStream(credential, blind, controller.signal, sessionConversationId);
|
|
12757
|
+
retriedWithBlindHead = true;
|
|
12758
|
+
}
|
|
12759
|
+
}
|
|
12760
|
+
if (!current.ok && current.kind === "channel_reject" && !retriedWithSystemHead && !retriedWithPerturbation && !retriedWithDensePerturbation && !retriedWithBlindHead) logger?.warn("dsh-connect-workbuddy: the channel gate refused the body, but no rescue transform could change it (every scanned opening already neutral); no retry was spent");
|
|
12761
|
+
return current;
|
|
12762
|
+
};
|
|
12763
|
+
result = await rescueChannelReject(result);
|
|
12475
12764
|
const triedAccountIds = [];
|
|
12476
12765
|
/**
|
|
12766
|
+
* How many accounts actually RECEIVED a chat request, including the final
|
|
12767
|
+
* one. `triedAccountIds` alone UNDERCOUNTS by one when the loop ends on a
|
|
12768
|
+
* channel_reject: the loop pushes an id before asking for the NEXT account,
|
|
12769
|
+
* and a channel_reject is not failover-worthy, so the account that produced
|
|
12770
|
+
* the final 11128 was never pushed. #302 / #307.
|
|
12771
|
+
*/
|
|
12772
|
+
let attemptCount = 1;
|
|
12773
|
+
/**
|
|
12477
12774
|
* The account the request STARTED on, and the reason it was abandoned.
|
|
12478
12775
|
*
|
|
12479
12776
|
* `??=` on the first switch only: if three accounts fail in a row the user
|
|
@@ -12541,13 +12838,14 @@ function createWorkBuddyShim(options) {
|
|
|
12541
12838
|
switchedFrom ??= describeAccount(credential);
|
|
12542
12839
|
switchedBecause ??= failoverReasonText(result);
|
|
12543
12840
|
credential = next;
|
|
12544
|
-
result = await client.chatStream(credential,
|
|
12841
|
+
result = await client.chatStream(credential, preferred, controller.signal, sessionConversationId);
|
|
12842
|
+
attemptCount += 1;
|
|
12545
12843
|
}
|
|
12844
|
+
if (!retriedWithSystemHead && !retriedWithPerturbation && !retriedWithDensePerturbation && !retriedWithBlindHead) result = await rescueChannelReject(result);
|
|
12546
12845
|
if (failures.length === 0 || failures[failures.length - 1]?.accountId !== workbuddyAccountId(credential)) recordAttempt(credential, result);
|
|
12547
12846
|
reportFailures();
|
|
12548
12847
|
if (!result.ok) {
|
|
12549
|
-
const
|
|
12550
|
-
const note = attempts > 1 ? `(已尝试 ${attempts} 个账号)` : "";
|
|
12848
|
+
const note = attemptCount > 1 ? `(已尝试 ${attemptCount} 个账号)` : "";
|
|
12551
12849
|
const shortfall = failoverShortfall !== void 0 && failoverAccount !== void 0 && isFailoverWorthy(result.kind) ? await failoverShortfall().catch(() => void 0) : void 0;
|
|
12552
12850
|
const why = shortfall === void 0 ? "" : `:${shortfall}`;
|
|
12553
12851
|
const refusedReport = refusedTierReport(result, requestModelId);
|
|
@@ -12592,17 +12890,18 @@ function createWorkBuddyShim(options) {
|
|
|
12592
12890
|
if (detail?.upstreamCode !== void 0) meta.push(`code ${detail.upstreamCode}`);
|
|
12593
12891
|
if (detail?.requestId !== void 0) meta.push(`requestId ${detail.requestId}`);
|
|
12594
12892
|
const stamp = meta.length === 0 ? "" : `(${meta.join(",")})`;
|
|
12595
|
-
const evidence = channelEvidenceText(raw);
|
|
12893
|
+
const evidence = channelEvidenceText(raw) + fingerprintTraceText(raw, prepared);
|
|
12596
12894
|
const retries = [];
|
|
12597
|
-
if (
|
|
12895
|
+
if (retriedWithSystemHead) retries.push("system 中性头");
|
|
12598
12896
|
if (retriedWithPerturbation) retries.push("一次不可见扰动");
|
|
12599
12897
|
if (retriedWithDensePerturbation) retries.push("一次密集不可见扰动");
|
|
12898
|
+
if (retriedWithBlindHead) retries.push("全消息中性头");
|
|
12600
12899
|
const retryNote = retries.length === 0 ? "" : `,并已用${retries.join("与")}重试过`;
|
|
12601
12900
|
const member = channelGateMemberOf(result.message, requestEvidenceOf(prepared));
|
|
12602
12901
|
const said = detail?.rawMsg ?? detail?.displayMsg;
|
|
12603
12902
|
const echo = said === void 0 ? "" : `上游的 msg 是「${said}」,`;
|
|
12604
12903
|
const memberNote = member === "headers" ? `${echo}但本次请求已经带上了会话 id 三件套(X-Conversation-ID / -Request-ID / -Message-ID),所以这条措辞是上游误报;` : member === "first_message" ? `${echo}但本次请求的首条消息就是 system;` : member === "prompt" ? isConversationIdGateBody(result.message) ? `${echo}但本次请求已经带上了会话 id 三件套(X-Conversation-ID / -Request-ID / -Message-ID),所以这条措辞是上游误报,实际被拒的是请求内容;` : isFirstMessageGateBody(result.message) ? `${echo}但本次请求的首条消息就是 system,所以这条措辞是上游误报,实际被拒的是请求内容;` : "" : `${echo}它属于 11128 这一族但没点名是哪一道门,插件按渠道校验统一处理;`;
|
|
12605
|
-
const message = `workbuddy 上游失败:${failoverReasonText(result)}(http ${result.status})${note}${stamp}。${memberNote}${evidence}该请求被 WorkBuddy 网关的渠道校验拦截,上游把它描述成「不是官方客户端发出的」,但那是误导性文案:网关扫描每一条 system 与 assistant 消息(开头做前缀匹配,正文做精确子串匹配),与账号、积分、额度、网络都无关,换账号或换区域也不会改变结果。插件已对已知的第三方 agent 指纹做归一化` + retryNote + (
|
|
12904
|
+
const message = `workbuddy 上游失败:${failoverReasonText(result)}(http ${result.status})${note}${stamp}。${memberNote}${evidence}该请求被 WorkBuddy 网关的渠道校验拦截,上游把它描述成「不是官方客户端发出的」,但那是误导性文案:网关扫描每一条 system 与 assistant 消息(开头做前缀匹配,正文做精确子串匹配),与账号、积分、额度、网络都无关,换账号或换区域也不会改变结果。插件已对已知的第三方 agent 指纹做归一化` + retryNote + (retriedWithBlindHead ? ";这次重试里每一条被扫描消息都已经加了中性头,仍然被拒,说明卡点不在这些开头本身" : retriedWithSystemHead ? ";这次重试只给 system 开头加了中性头(assistant 历史保持原样,避免模型模仿),仍然被拒" : "") + "。上面标着「不在插件已知名单里」的,只说明该消息的首行不是已知指纹,既不表示这条消息没被处理,也不表示它一定有问题;如果这些消息确实有问题,命中的更可能是中段的某一句。请把这条报错整段反馈到 issue 里——首行之外的线索只能从完整请求里找";
|
|
12606
12905
|
writeOpenAIError(res, KIND_STATUS[result.kind], result.kind, message, hostErrorCode(result.kind));
|
|
12607
12906
|
return;
|
|
12608
12907
|
}
|
|
@@ -13232,6 +13531,8 @@ function outcomeOfFailure(status, body) {
|
|
|
13232
13531
|
const kind = classifyUpstreamError(status, body);
|
|
13233
13532
|
if (kind === "policy_reject") return "policy-rejected";
|
|
13234
13533
|
if (kind === "account_restricted") return "account-restricted";
|
|
13534
|
+
if (kind === "session_dead") return "credential-rejected";
|
|
13535
|
+
if (isGatewayAuthRejection(status, body)) return "failed";
|
|
13235
13536
|
return "credential-rejected";
|
|
13236
13537
|
}
|
|
13237
13538
|
switch (classifyUpstreamError(status, body)) {
|
|
@@ -15195,6 +15496,42 @@ async function writePoolProbes(region, updates) {
|
|
|
15195
15496
|
});
|
|
15196
15497
|
} catch {}
|
|
15197
15498
|
}
|
|
15499
|
+
/**
|
|
15500
|
+
* 只有失败记录写入之后发起的余额查询,才能解除积分耗尽状态与 credential-rejected
|
|
15501
|
+
* (#305:一次**实时** fetchCredits 拿到正余额,证明这把 token 被上游接受,
|
|
15502
|
+
* 直接证伪之前的「token 被拒」结论;而网关 HTML 401 可能只是某条路由被拒)。
|
|
15503
|
+
* 持锁重读可避免较早的查询结果覆盖并发请求刚记录的新失败;其他异常保持原样。
|
|
15504
|
+
* 删除失败记录只表示余额恢复/凭据可用,不会伪造一次成功的模型测试。
|
|
15505
|
+
* 恢复后界面会显示“未测试”:这里删除的是最近失败记录,存储结构没有保留此前
|
|
15506
|
+
* 成功测试的历史,余额到账也不能证明某个模型可用;再次测试才会产生新的结论。
|
|
15507
|
+
*/
|
|
15508
|
+
async function reconcilePoolCredits(region, readings) {
|
|
15509
|
+
const path = workbuddyPoolStorePath(region);
|
|
15510
|
+
try {
|
|
15511
|
+
return await withFileLock(path, async () => {
|
|
15512
|
+
const probes = await readPoolProbes(region);
|
|
15513
|
+
let changed = false;
|
|
15514
|
+
for (const reading of readings) {
|
|
15515
|
+
const probe = probes[reading.accountId];
|
|
15516
|
+
if (probe?.outcome !== "out-of-credit" && probe?.outcome !== "credential-rejected") continue;
|
|
15517
|
+
if (probe.atMs >= reading.startedAtMs) continue;
|
|
15518
|
+
if (!Number.isFinite(reading.total) || reading.total <= 0) continue;
|
|
15519
|
+
delete probes[reading.accountId];
|
|
15520
|
+
changed = true;
|
|
15521
|
+
}
|
|
15522
|
+
if (changed) await writeFileAtomic(path, `${JSON.stringify({
|
|
15523
|
+
version: STORE_FORMAT_VERSION$3,
|
|
15524
|
+
probes
|
|
15525
|
+
}, null, 2)}\n`, {
|
|
15526
|
+
mode: 384,
|
|
15527
|
+
dirMode: 448
|
|
15528
|
+
});
|
|
15529
|
+
return probes;
|
|
15530
|
+
});
|
|
15531
|
+
} catch {
|
|
15532
|
+
return readPoolProbes(region);
|
|
15533
|
+
}
|
|
15534
|
+
}
|
|
15198
15535
|
//#endregion
|
|
15199
15536
|
//#region ../src/auto-checkin-store.ts
|
|
15200
15537
|
/**
|
|
@@ -16428,8 +16765,25 @@ async function measureTps(input) {
|
|
|
16428
16765
|
* regions.<cn|global>.models.{enabledModelIds,contextWindowOverrides,offThinkingIds}
|
|
16429
16766
|
* regions.<cn|global>.{cnBase,pollMs}
|
|
16430
16767
|
*/
|
|
16431
|
-
const STANDALONE_VERSION = "5.31.
|
|
16768
|
+
const STANDALONE_VERSION = "5.31.8";
|
|
16432
16769
|
const BUILTIN_RELEASE_NOTES = [
|
|
16770
|
+
{
|
|
16771
|
+
version: "5.31.8",
|
|
16772
|
+
date: "2026-11-26",
|
|
16773
|
+
items: [
|
|
16774
|
+
"同步上游 v5.31.5~v5.31.8 独立网关相关修复(跳过只与 DSH 宿主前端相关的 v5.31.7 #313/#314)",
|
|
16775
|
+
"企业账号读取模型目录带齐身份头,修复企业账号 cli 名册缺行(#303)",
|
|
16776
|
+
"failover 换号后触发 11128 补跑渠道救援阶梯并修正账号尝试计数(#302/#307);11128 报错附零隐私指纹线索(#311)",
|
|
16777
|
+
"网关 HTML 401 不再误判为凭据吊销,且实时查回正余额可自动自愈 credential-rejected(#305)",
|
|
16778
|
+
"出站剥离已注入的 assistant 中性头,渠道救援第一级仅补 system 中性头避免模型模仿(#297)",
|
|
16779
|
+
"修复 start-hidden.vbs 在未启动时因 VBScript 短路求值误判端口已启动的问题"
|
|
16780
|
+
]
|
|
16781
|
+
},
|
|
16782
|
+
{
|
|
16783
|
+
version: "5.31.5",
|
|
16784
|
+
date: "2026-11-25",
|
|
16785
|
+
items: ["同步上游 v5.31.4(#293/#295 渠道校验改词修复,解决 Claude Code official CLI 自述句与 runtime context 触发的 400/11128 错误)"]
|
|
16786
|
+
},
|
|
16433
16787
|
{
|
|
16434
16788
|
version: "5.31.4",
|
|
16435
16789
|
date: "2026-11-24",
|
|
@@ -19442,6 +19796,7 @@ async function handleAdmin(url, method, res, body, state, settings, client, refr
|
|
|
19442
19796
|
if (gState !== void 0 && gState.day === day) for (const id of gState.doneAccountIds) map[id] = true;
|
|
19443
19797
|
}
|
|
19444
19798
|
accountCache[region] = accountCache[region] || {};
|
|
19799
|
+
const creditReadings = [];
|
|
19445
19800
|
for (const a of accounts) {
|
|
19446
19801
|
const id = a.id ?? "";
|
|
19447
19802
|
const hit = accountCache[region][id];
|
|
@@ -19451,7 +19806,13 @@ async function handleAdmin(url, method, res, body, state, settings, client, refr
|
|
|
19451
19806
|
if (!cred) continue;
|
|
19452
19807
|
const checkinSupported = autoCheckinRegions().includes(region) && a.enterprise !== true;
|
|
19453
19808
|
const alreadyCheckedIn = checkinSupported && (checkinDoneMap[id] === true || await isDoneToday("checkin", region, id));
|
|
19809
|
+
const creditsStartedAtMs = Date.now();
|
|
19454
19810
|
const [credits, checkin] = await Promise.all([client.fetchCredits(cred).catch(() => void 0), !checkinSupported || alreadyCheckedIn ? Promise.resolve(alreadyCheckedIn ? { todayCheckedIn: true } : void 0) : client.fetchCheckinStatus(cred).catch(() => void 0)]);
|
|
19811
|
+
if (credits !== void 0 && Number.isFinite(credits.total)) creditReadings.push({
|
|
19812
|
+
accountId: id,
|
|
19813
|
+
startedAtMs: creditsStartedAtMs,
|
|
19814
|
+
total: Number(credits.total)
|
|
19815
|
+
});
|
|
19455
19816
|
if (!alreadyCheckedIn && checkin?.todayCheckedIn === true) {
|
|
19456
19817
|
await markDoneToday("checkin", region, [id]);
|
|
19457
19818
|
checkinDoneMap[id] = true;
|
|
@@ -19463,6 +19824,13 @@ async function handleAdmin(url, method, res, body, state, settings, client, refr
|
|
|
19463
19824
|
};
|
|
19464
19825
|
} catch {}
|
|
19465
19826
|
}
|
|
19827
|
+
if (creditReadings.length > 0) {
|
|
19828
|
+
const recordedProbes = await readPoolProbes(region).catch(() => ({}));
|
|
19829
|
+
if (creditReadings.some((reading) => {
|
|
19830
|
+
const outcome = recordedProbes[reading.accountId]?.outcome;
|
|
19831
|
+
return outcome === "out-of-credit" || outcome === "credential-rejected";
|
|
19832
|
+
})) await reconcilePoolCredits(region, creditReadings);
|
|
19833
|
+
}
|
|
19466
19834
|
const cacheOf = (id) => accountCache[region]?.[id];
|
|
19467
19835
|
const degradation = st.catalog.degradation();
|
|
19468
19836
|
out.regions[region] = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zzz0350/our-workbuddy-standalone",
|
|
3
|
-
"version": "5.31.
|
|
3
|
+
"version": "5.31.8",
|
|
4
4
|
"description": "Our WorkBuddy 独立本地网关:账号池轮换、自动签到、在线日志与一键更新",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,25 @@
|
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
|
26
26
|
"releaseNotes": [
|
|
27
|
+
{
|
|
28
|
+
"version": "5.31.8",
|
|
29
|
+
"date": "2026-11-26",
|
|
30
|
+
"items": [
|
|
31
|
+
"同步上游 v5.31.5~v5.31.8 独立网关相关修复(跳过只与 DSH 宿主前端相关的 v5.31.7 #313/#314)",
|
|
32
|
+
"企业账号读取模型目录带齐身份头,修复企业账号 cli 名册缺行(#303)",
|
|
33
|
+
"failover 换号后触发 11128 补跑渠道救援阶梯并修正账号尝试计数(#302/#307);11128 报错附零隐私指纹线索(#311)",
|
|
34
|
+
"网关 HTML 401 不再误判为凭据吊销,且实时查回正余额可自动自愈 credential-rejected(#305)",
|
|
35
|
+
"出站剥离已注入的 assistant 中性头,渠道救援第一级仅补 system 中性头避免模型模仿(#297)",
|
|
36
|
+
"修复 start-hidden.vbs 在未启动时因 VBScript 短路求值误判端口已启动的问题"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"version": "5.31.5",
|
|
41
|
+
"date": "2026-11-25",
|
|
42
|
+
"items": [
|
|
43
|
+
"同步上游 v5.31.4(#293/#295 渠道校验改词修复,解决 Claude Code official CLI 自述句与 runtime context 触发的 400/11128 错误)"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
27
46
|
{
|
|
28
47
|
"version": "5.31.4",
|
|
29
48
|
"date": "2026-11-24",
|
package/start-hidden.vbs
CHANGED
|
@@ -9,15 +9,19 @@ Set fso = CreateObject("Scripting.FileSystemObject")
|
|
|
9
9
|
dir = fso.GetParentFolderName(WScript.ScriptFullName)
|
|
10
10
|
|
|
11
11
|
Function IsGatewayUp()
|
|
12
|
-
Dim http
|
|
12
|
+
Dim http, st
|
|
13
13
|
IsGatewayUp = False
|
|
14
14
|
On Error Resume Next
|
|
15
15
|
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
|
|
16
|
+
http.SetProxy 1
|
|
16
17
|
http.SetTimeouts 500, 500, 500, 1000
|
|
17
18
|
http.Open "GET", "http://127.0.0.1:18911/healthz", False
|
|
18
19
|
http.Send
|
|
19
|
-
If Err.Number = 0
|
|
20
|
-
|
|
20
|
+
If Err.Number = 0 Then
|
|
21
|
+
st = http.Status
|
|
22
|
+
If Err.Number = 0 And st = 200 Then
|
|
23
|
+
IsGatewayUp = True
|
|
24
|
+
End If
|
|
21
25
|
End If
|
|
22
26
|
Err.Clear
|
|
23
27
|
On Error GoTo 0
|
|
@@ -29,8 +33,8 @@ If Not IsGatewayUp() Then
|
|
|
29
33
|
WScript.Quit 1
|
|
30
34
|
End If
|
|
31
35
|
sh.CurrentDirectory = dir
|
|
32
|
-
sh.Run """" & dir & "\watchdog.cmd""", 0, False
|
|
33
|
-
For i = 1 To
|
|
36
|
+
sh.Run "cmd.exe /c """ & dir & "\watchdog.cmd""", 0, False
|
|
37
|
+
For i = 1 To 40
|
|
34
38
|
WScript.Sleep 500
|
|
35
39
|
If IsGatewayUp() Then Exit For
|
|
36
40
|
Next
|