dsh-connect-workbuddy 5.19.1 → 5.20.2
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 +170 -0
- package/README.en.md +14 -3
- package/README.md +21 -3
- package/lib/bin.js +26 -4
- package/lib/client.js +528 -67
- package/lib/{host-heartbeat-hEksLFOK.js → host-heartbeat-CQ3ot5-F.js} +182 -22
- package/lib/index.d.ts +39 -0
- package/lib/index.js +57 -2
- package/package.json +1 -1
|
@@ -3978,11 +3978,27 @@ function globalBase(domain) {
|
|
|
3978
3978
|
if (lowered === "codebuddy.ai" || lowered.endsWith(".codebuddy.ai")) return "https://www.codebuddy.ai";
|
|
3979
3979
|
return GLOBAL_BASE;
|
|
3980
3980
|
}
|
|
3981
|
-
|
|
3982
|
-
|
|
3981
|
+
/**
|
|
3982
|
+
* The CN gateway base for this process, resolved ONCE at construction.
|
|
3983
|
+
*
|
|
3984
|
+
* Empty means "no override", and then the constant is used — the pre-#220
|
|
3985
|
+
* behaviour, byte for byte. A non-empty value has already passed
|
|
3986
|
+
* `resolveCnGateway`'s allowlist, so this is a validated host and not whatever
|
|
3987
|
+
* happened to be in the settings file.
|
|
3988
|
+
*
|
|
3989
|
+
* Deliberately injected rather than read from config at each call site: the CN
|
|
3990
|
+
* base feeds a Bearer token, so "which host" must be decided in exactly one
|
|
3991
|
+
* place that can be pointed at and audited, not re-derived by ten request
|
|
3992
|
+
* builders. The class also swaps it when the setting changes (the mount
|
|
3993
|
+
* reconstructs the client on a volatile update).
|
|
3994
|
+
*/
|
|
3995
|
+
function chatBase(credential, cnBase) {
|
|
3996
|
+
if (regionOf(credential.domain) === "global") return globalBase(credential.domain);
|
|
3997
|
+
return cnBase === void 0 || cnBase === "" ? CN_CHAT_BASE : cnBase;
|
|
3983
3998
|
}
|
|
3984
|
-
function billingBase(credential) {
|
|
3985
|
-
|
|
3999
|
+
function billingBase(credential, cnBase) {
|
|
4000
|
+
if (regionOf(credential.domain) === "global") return globalBase(credential.domain);
|
|
4001
|
+
return cnBase === void 0 || cnBase === "" ? CN_BILLING_BASE : cnBase;
|
|
3986
4002
|
}
|
|
3987
4003
|
function originReferer(credential) {
|
|
3988
4004
|
return regionOf(credential.domain) === "global" ? globalBase(credential.domain) : CN_BILLING_BASE;
|
|
@@ -5878,8 +5894,17 @@ var WorkBuddyUpstreamClient = class {
|
|
|
5878
5894
|
deviceProfiles;
|
|
5879
5895
|
/** 真实值档的 token 源(本机安装的桌面端 SDK);未接线时为 undefined。 */
|
|
5880
5896
|
realDevice;
|
|
5897
|
+
/**
|
|
5898
|
+
* CN 网关 base(issue #220)。空 = 用内置常量,即 #220 之前的行为逐字节不变。
|
|
5899
|
+
*
|
|
5900
|
+
* 只影响 CN 区域:国际版仍然跟随凭据自己的域(`workbuddy.ai` /
|
|
5901
|
+
* `codebuddy.ai`),因为国际 token 跨品牌互不通用,那里没有"换一个同构主机"
|
|
5902
|
+
* 这回事。返回值必须已由 `resolveCnGateway` 的允许清单校验过,这个类不重新校验。
|
|
5903
|
+
*/
|
|
5904
|
+
cnBaseOf;
|
|
5881
5905
|
constructor(onFallback, identity = {}, options = {}) {
|
|
5882
5906
|
this.onFallback = onFallback;
|
|
5907
|
+
this.cnBaseOf = options.cnBase === void 0 ? () => "" : options.cnBase;
|
|
5883
5908
|
this.baseIdentity = resolveWireIdentity(identity);
|
|
5884
5909
|
this.deviceProfiles = options.deviceProfiles;
|
|
5885
5910
|
this.realDevice = options.realDevice;
|
|
@@ -5955,7 +5980,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
5955
5980
|
kind: "server",
|
|
5956
5981
|
message: "cancelled before send"
|
|
5957
5982
|
};
|
|
5958
|
-
response = await fetch(`${chatBase(credential)}/v2/chat/completions`, {
|
|
5983
|
+
response = await fetch(`${chatBase(credential, this.cnBaseOf())}/v2/chat/completions`, {
|
|
5959
5984
|
method: "POST",
|
|
5960
5985
|
headers,
|
|
5961
5986
|
body: bodyJson,
|
|
@@ -6033,7 +6058,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6033
6058
|
ceiling.abort(/* @__PURE__ */ new Error(`no response within ${PROBE_TIMEOUT_MS}ms`));
|
|
6034
6059
|
}, PROBE_TIMEOUT_MS);
|
|
6035
6060
|
try {
|
|
6036
|
-
response = await fetch(`${chatBase(credential)}/v2/chat/completions`, {
|
|
6061
|
+
response = await fetch(`${chatBase(credential, this.cnBaseOf())}/v2/chat/completions`, {
|
|
6037
6062
|
method: "POST",
|
|
6038
6063
|
headers,
|
|
6039
6064
|
body: bodyJson,
|
|
@@ -6066,7 +6091,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6066
6091
|
}
|
|
6067
6092
|
/** POST the token-refresh endpoint; the caller merges the outcome. */
|
|
6068
6093
|
async refreshToken(credential) {
|
|
6069
|
-
const response = await fetch(`${chatBase(credential)}/v2/plugin/auth/token/refresh`, {
|
|
6094
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}/v2/plugin/auth/token/refresh`, {
|
|
6070
6095
|
method: "POST",
|
|
6071
6096
|
headers: refreshHeaders(credential),
|
|
6072
6097
|
signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
|
|
@@ -6132,7 +6157,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6132
6157
|
return withPromos(selectCliModels(data["models"], data["agents"], keepModelIds), data);
|
|
6133
6158
|
}
|
|
6134
6159
|
const readCatalog = async (path) => {
|
|
6135
|
-
const response = await fetch(`${chatBase(credential)}${path}`, {
|
|
6160
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${path}`, {
|
|
6136
6161
|
headers: {
|
|
6137
6162
|
"Authorization": `Bearer ${credential.accessToken}`,
|
|
6138
6163
|
"Accept": "application/json",
|
|
@@ -6168,7 +6193,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6168
6193
|
async fetchModelBusy(credential, modelIds, signal) {
|
|
6169
6194
|
const levels = /* @__PURE__ */ new Map();
|
|
6170
6195
|
for (const batch of batchModelIds(modelIds)) {
|
|
6171
|
-
const response = await fetch(`${chatBase(credential)}${MODEL_BUSY_PATH}`, {
|
|
6196
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${MODEL_BUSY_PATH}`, {
|
|
6172
6197
|
method: "POST",
|
|
6173
6198
|
headers: {
|
|
6174
6199
|
...legacyCommonHeaders(credential),
|
|
@@ -6210,7 +6235,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6210
6235
|
*/
|
|
6211
6236
|
async fetchMediaModels(credential, signal) {
|
|
6212
6237
|
const readMedia = async (path) => {
|
|
6213
|
-
const response = await fetch(`${chatBase(credential)}${path}`, {
|
|
6238
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${path}`, {
|
|
6214
6239
|
headers: {
|
|
6215
6240
|
"Authorization": `Bearer ${credential.accessToken}`,
|
|
6216
6241
|
"Accept": "application/json",
|
|
@@ -6245,7 +6270,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6245
6270
|
* HTTP 200 但信封 `code !== 0` 由 {@link parseImageResponse} 处理。
|
|
6246
6271
|
*/
|
|
6247
6272
|
async generateImage(credential, request, signal) {
|
|
6248
|
-
const response = await fetch(`${chatBase(credential)}${IMAGE_GENERATIONS_PATH}`, {
|
|
6273
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${IMAGE_GENERATIONS_PATH}`, {
|
|
6249
6274
|
method: "POST",
|
|
6250
6275
|
headers: imageHeaders(credential, await this.wireIdentity(credential)),
|
|
6251
6276
|
body: JSON.stringify(buildImageBody(request)),
|
|
@@ -6274,7 +6299,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6274
6299
|
*/
|
|
6275
6300
|
async editImage(credential, request, signal) {
|
|
6276
6301
|
if (request.image.length === 0) throw new WorkBuddyImageError("workbuddy image: 改图请求缺少输入图(image 数组为空)。", "INVALID_ARGS");
|
|
6277
|
-
const response = await fetch(`${chatBase(credential)}${IMAGE_EDITS_PATH}`, {
|
|
6302
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${IMAGE_EDITS_PATH}`, {
|
|
6278
6303
|
method: "POST",
|
|
6279
6304
|
headers: imageHeaders(credential, await this.wireIdentity(credential)),
|
|
6280
6305
|
body: JSON.stringify(buildEditBody(request)),
|
|
@@ -6315,7 +6340,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6315
6340
|
aspectRatio: request.aspectRatio,
|
|
6316
6341
|
enableAudio: request.enableAudio
|
|
6317
6342
|
}, isImageToVideo);
|
|
6318
|
-
const response = await fetch(`${chatBase(credential)}${VIDEO_GENERATIONS_PATH}`, {
|
|
6343
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${VIDEO_GENERATIONS_PATH}`, {
|
|
6319
6344
|
method: "POST",
|
|
6320
6345
|
headers: imageHeaders(credential, await this.wireIdentity(credential)),
|
|
6321
6346
|
body: JSON.stringify(body),
|
|
@@ -6351,7 +6376,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6351
6376
|
if (Date.now() - startedAt > VIDEO_POLL_TIMEOUT_MS) throw new WorkBuddyVideoError(`workbuddy video: 轮询超过 ${VIDEO_POLL_TIMEOUT_MS / 1e3} 秒仍未完成(task ${taskId})。`, "POLL_TIMEOUT");
|
|
6352
6377
|
let payload;
|
|
6353
6378
|
try {
|
|
6354
|
-
const response = await fetch(`${chatBase(credential)}${VIDEO_TASKS_PATH}`, {
|
|
6379
|
+
const response = await fetch(`${chatBase(credential, this.cnBaseOf())}${VIDEO_TASKS_PATH}`, {
|
|
6355
6380
|
method: "POST",
|
|
6356
6381
|
headers: imageHeaders(credential, await this.wireIdentity(credential)),
|
|
6357
6382
|
body: JSON.stringify({ task_id: taskId }),
|
|
@@ -6409,7 +6434,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6409
6434
|
}
|
|
6410
6435
|
/** Query today's check-in status without changing account state. */
|
|
6411
6436
|
async fetchCheckinStatus(credential) {
|
|
6412
|
-
const response = await fetch(`${billingBase(credential)}/v2/billing/meter/checkin-activity-status`, {
|
|
6437
|
+
const response = await fetch(`${billingBase(credential, this.cnBaseOf())}/v2/billing/meter/checkin-activity-status`, {
|
|
6413
6438
|
method: "POST",
|
|
6414
6439
|
headers: billingHeaders(credential, await this.wireIdentity(credential)),
|
|
6415
6440
|
body: "{}",
|
|
@@ -6462,7 +6487,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6462
6487
|
}
|
|
6463
6488
|
/** One benefit status endpoint. Throws on anything that is not a clean `code: 0`. */
|
|
6464
6489
|
async readBenefitStatus(kind, credential, path) {
|
|
6465
|
-
const response = await fetch(`${billingBase(credential)}${path}`, {
|
|
6490
|
+
const response = await fetch(`${billingBase(credential, this.cnBaseOf())}${path}`, {
|
|
6466
6491
|
method: "POST",
|
|
6467
6492
|
headers: billingHeaders(credential, await this.wireIdentity(credential)),
|
|
6468
6493
|
body: "{}",
|
|
@@ -6507,7 +6532,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6507
6532
|
* that silently did nothing still cannot leave the card saying 待领取.
|
|
6508
6533
|
*/
|
|
6509
6534
|
async claimBenefit(credential, kind) {
|
|
6510
|
-
const response = await fetch(`${billingBase(credential)}${BENEFIT_CLAIM_PATHS[kind]}`, {
|
|
6535
|
+
const response = await fetch(`${billingBase(credential, this.cnBaseOf())}${BENEFIT_CLAIM_PATHS[kind]}`, {
|
|
6511
6536
|
method: "POST",
|
|
6512
6537
|
headers: billingHeaders(credential, await this.wireIdentity(credential)),
|
|
6513
6538
|
body: "{}",
|
|
@@ -6518,7 +6543,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6518
6543
|
}
|
|
6519
6544
|
/** Claim today's check-in reward. The browser route guards this mutation. */
|
|
6520
6545
|
async claimDailyCheckin(credential) {
|
|
6521
|
-
const response = await fetch(`${billingBase(credential)}/v2/billing/meter/daily-checkin`, {
|
|
6546
|
+
const response = await fetch(`${billingBase(credential, this.cnBaseOf())}/v2/billing/meter/daily-checkin`, {
|
|
6522
6547
|
method: "POST",
|
|
6523
6548
|
headers: billingHeaders(credential, await this.wireIdentity(credential)),
|
|
6524
6549
|
body: "{}",
|
|
@@ -6555,7 +6580,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6555
6580
|
* reporting zero).
|
|
6556
6581
|
*/
|
|
6557
6582
|
async fetchEnterpriseCredits(credential) {
|
|
6558
|
-
const response = await fetch(`${billingBase(credential)}/billing/meter/get-enterprise-user-usage`, {
|
|
6583
|
+
const response = await fetch(`${billingBase(credential, this.cnBaseOf())}/billing/meter/get-enterprise-user-usage`, {
|
|
6559
6584
|
method: "POST",
|
|
6560
6585
|
headers: billingHeaders(credential, await this.wireIdentity(credential)),
|
|
6561
6586
|
body: JSON.stringify({}),
|
|
@@ -6604,7 +6629,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6604
6629
|
date.getMinutes().toString().padStart(2, "0"),
|
|
6605
6630
|
date.getSeconds().toString().padStart(2, "0")
|
|
6606
6631
|
].join(":");
|
|
6607
|
-
const response = await fetch(`${billingBase(credential)}/v2/billing/meter/get-user-resource`, {
|
|
6632
|
+
const response = await fetch(`${billingBase(credential, this.cnBaseOf())}/v2/billing/meter/get-user-resource`, {
|
|
6608
6633
|
method: "POST",
|
|
6609
6634
|
headers: billingHeaders(credential, await this.wireIdentity(credential)),
|
|
6610
6635
|
body: JSON.stringify({
|
|
@@ -9846,6 +9871,141 @@ function generationOf(version) {
|
|
|
9846
9871
|
if (match === null) return "legacy";
|
|
9847
9872
|
return Number(match[1]) >= 87 ? "modern" : "legacy";
|
|
9848
9873
|
}
|
|
9874
|
+
//#endregion
|
|
9875
|
+
//#region src/cn-gateway.ts
|
|
9876
|
+
/**
|
|
9877
|
+
* The CN region's gateway host, and the ONE place an override is validated.
|
|
9878
|
+
*
|
|
9879
|
+
* ## Why this exists (issue #220)
|
|
9880
|
+
*
|
|
9881
|
+
* The CN chat gateway was the single hard-coded constant
|
|
9882
|
+
* `https://copilot.tencent.com`. In a corporate network that filters on the TLS
|
|
9883
|
+
* ClientHello's SNI, that name is reset before the handshake completes — while
|
|
9884
|
+
* the SAME network lets the WorkBuddy desktop app work, because the app reads a
|
|
9885
|
+
* failover list from its own config and uses `wb.tencentbuddy.com` as well.
|
|
9886
|
+
*
|
|
9887
|
+
* The reporter measured (2026-11-06): `copilot.tencent.com` answers
|
|
9888
|
+
* `ECONNRESET` in <100ms while `wb.tencentbuddy.com` answers a normal
|
|
9889
|
+
* `401 Authorization Required`. This module is what lets such a user point the
|
|
9890
|
+
* plugin at a host their network actually permits.
|
|
9891
|
+
*
|
|
9892
|
+
* ## Why an allowlist, and not "any URL you like"
|
|
9893
|
+
*
|
|
9894
|
+
* The value feeds `Authorization: Bearer <token>` on every CN request, plus the
|
|
9895
|
+
* refresh-token exchange. A free-form base is therefore a **credential
|
|
9896
|
+
* exfiltration primitive**: whoever can edit the settings (a synced profile, a
|
|
9897
|
+
* shared dotfile, a pasted "fix" from a forum post) could redirect a live
|
|
9898
|
+
* WorkBuddy token to a host they run. That is a strictly worse failure than the
|
|
9899
|
+
* timeout it fixes, and it is invisible — the requests would keep succeeding.
|
|
9900
|
+
*
|
|
9901
|
+
* So the override names a HOST from a closed set, never a URL from the open
|
|
9902
|
+
* internet. The set is the CN product's own brand registrable domains, measured
|
|
9903
|
+
* 2026-11-06 to answer the chat, billing, catalog and busy routes identically
|
|
9904
|
+
* (see `docs/CN_GATEWAY_FALLBACK.md`):
|
|
9905
|
+
*
|
|
9906
|
+
* copilot.tencent.com the shipping default
|
|
9907
|
+
* wb.tencentbuddy.com what the desktop app's failover.json lists
|
|
9908
|
+
* www.workbuddy.cn the brand host
|
|
9909
|
+
* www.codebuddy.cn the sibling brand host, also the billing base
|
|
9910
|
+
*
|
|
9911
|
+
* Each is admitted by REGISTRABLE domain, so any subdomain of those brands
|
|
9912
|
+
* qualifies and a lookalike (`wb.tencentbuddy.com.evil.example`) cannot —
|
|
9913
|
+
* the same rule `knownRegionOf` already applies to credential domains.
|
|
9914
|
+
*
|
|
9915
|
+
* ## What an override does NOT change
|
|
9916
|
+
*
|
|
9917
|
+
* `Origin` / `Referer` stay on the billing base (see `originReferer`): they
|
|
9918
|
+
* describe which web app the request comes from, not which socket it reaches.
|
|
9919
|
+
* Rewriting them from the override would make the identity claim disagree with
|
|
9920
|
+
* itself for no benefit — the gateway reads them as "this is the CN web app".
|
|
9921
|
+
*
|
|
9922
|
+
* @module dsh-connect-workbuddy/cn-gateway
|
|
9923
|
+
*/
|
|
9924
|
+
/** The CN chat gateway the plugin has always used. */
|
|
9925
|
+
const CN_GATEWAY_DEFAULT = "https://copilot.tencent.com";
|
|
9926
|
+
/**
|
|
9927
|
+
* Environment override for `doctor`, mirroring the settings field.
|
|
9928
|
+
*
|
|
9929
|
+
* WHY THIS EXISTS. `dsh plugin exec … doctor` runs in its own process, which
|
|
9930
|
+
* never loads the plugin's settings — the same reason `WORKBUDDY_DEVICE_TOKEN_FILE`
|
|
9931
|
+
* already exists as the CLI's way to see what the plugin sees. Without it, a
|
|
9932
|
+
* user who fixed their network via the card's field would run `doctor` and get a
|
|
9933
|
+
* report measured against the gateway their network RESETS: a diagnostics tool
|
|
9934
|
+
* that lies about which host it probed is worse than no tool.
|
|
9935
|
+
*
|
|
9936
|
+
* The plugin reads the settings field; `doctor` reads this. Both go through
|
|
9937
|
+
* `resolveCnGateway`, so the allowlist cannot diverge between them.
|
|
9938
|
+
*/
|
|
9939
|
+
const WORKBUDDY_CN_BASE_ENV = "WORKBUDDY_CN_BASE";
|
|
9940
|
+
/**
|
|
9941
|
+
* Hosts an override may name, as registrable domains.
|
|
9942
|
+
*
|
|
9943
|
+
* A closed set is the security boundary described in this module's header. Adding
|
|
9944
|
+
* a host here is a deliberate act that must come with a measurement showing it
|
|
9945
|
+
* answers the CN routes, not with a guess about the brand.
|
|
9946
|
+
*/
|
|
9947
|
+
const ALLOWED_CN_DOMAINS = [
|
|
9948
|
+
"copilot.tencent.com",
|
|
9949
|
+
"tencentbuddy.com",
|
|
9950
|
+
"workbuddy.cn",
|
|
9951
|
+
"codebuddy.cn"
|
|
9952
|
+
];
|
|
9953
|
+
/**
|
|
9954
|
+
* Whether `hostname` belongs to one of the CN brands above.
|
|
9955
|
+
*
|
|
9956
|
+
* Matched on the registrable domain (`host === domain` or `host.endsWith('.' +
|
|
9957
|
+
* domain)`), so `wb.tencentbuddy.com` and `copilot.internal.tencentbuddy.com`
|
|
9958
|
+
* both qualify while `tencentbuddy.com.evil.example` does not.
|
|
9959
|
+
*/
|
|
9960
|
+
function isKnownCnHost(hostname) {
|
|
9961
|
+
const lowered = hostname.trim().toLowerCase();
|
|
9962
|
+
if (lowered === "") return false;
|
|
9963
|
+
return ALLOWED_CN_DOMAINS.some((domain) => lowered === domain || lowered.endsWith(`.${domain}`));
|
|
9964
|
+
}
|
|
9965
|
+
/**
|
|
9966
|
+
* Resolve the CN gateway base from an optional user-supplied value.
|
|
9967
|
+
*
|
|
9968
|
+
* An ABSENT or blank value is the normal case and yields the default with
|
|
9969
|
+
* `overridden: false`. A non-blank value must pass every check or the caller
|
|
9970
|
+
* gets `ok: false` and is expected to say so rather than silently falling back:
|
|
9971
|
+
* a user who typed a host and got the default anyway has no way to tell the
|
|
9972
|
+
* setting was ignored, and would keep debugging a network they already fixed.
|
|
9973
|
+
*/
|
|
9974
|
+
function resolveCnGateway(value) {
|
|
9975
|
+
const raw = typeof value === "string" ? value.trim() : "";
|
|
9976
|
+
if (raw === "") return {
|
|
9977
|
+
ok: true,
|
|
9978
|
+
base: CN_GATEWAY_DEFAULT,
|
|
9979
|
+
host: "copilot.tencent.com",
|
|
9980
|
+
overridden: false
|
|
9981
|
+
};
|
|
9982
|
+
let parsed;
|
|
9983
|
+
try {
|
|
9984
|
+
parsed = new URL(raw);
|
|
9985
|
+
} catch {
|
|
9986
|
+
return {
|
|
9987
|
+
ok: false,
|
|
9988
|
+
reason: "malformed",
|
|
9989
|
+
value: raw
|
|
9990
|
+
};
|
|
9991
|
+
}
|
|
9992
|
+
if (parsed.protocol !== "https:") return {
|
|
9993
|
+
ok: false,
|
|
9994
|
+
reason: "insecure",
|
|
9995
|
+
value: raw
|
|
9996
|
+
};
|
|
9997
|
+
if (!isKnownCnHost(parsed.hostname)) return {
|
|
9998
|
+
ok: false,
|
|
9999
|
+
reason: "unknown-host",
|
|
10000
|
+
value: raw
|
|
10001
|
+
};
|
|
10002
|
+
return {
|
|
10003
|
+
ok: true,
|
|
10004
|
+
base: `https://${parsed.hostname.toLowerCase()}`,
|
|
10005
|
+
host: parsed.hostname.toLowerCase(),
|
|
10006
|
+
overridden: true
|
|
10007
|
+
};
|
|
10008
|
+
}
|
|
9849
10009
|
/** The versions this build can read (add a new one on upgrade, keep old ones). */
|
|
9850
10010
|
const KNOWN_ROSTER_SEEN_VERSIONS = Object.freeze([1]);
|
|
9851
10011
|
/**
|
|
@@ -10060,7 +10220,7 @@ function describeRosterSeenPayload(raw) {
|
|
|
10060
10220
|
//#endregion
|
|
10061
10221
|
//#region src/version.ts
|
|
10062
10222
|
/** The npm package version this build was produced from. */
|
|
10063
|
-
const WORKBUDDY_CONNECT_VERSION = "5.
|
|
10223
|
+
const WORKBUDDY_CONNECT_VERSION = "5.20.2";
|
|
10064
10224
|
//#endregion
|
|
10065
10225
|
//#region src/host-heartbeat.ts
|
|
10066
10226
|
/**
|
|
@@ -10271,4 +10431,4 @@ async function clearHostHeartbeat() {
|
|
|
10271
10431
|
await rm(workbuddyHostHeartbeatPath(), { force: true });
|
|
10272
10432
|
}
|
|
10273
10433
|
//#endregion
|
|
10274
|
-
export {
|
|
10434
|
+
export { DEFAULT_WIRE_PROFILE as $, WORKBUDDY_DEVICE_TOKEN_FILE_ENV as $t, withoutRouters as A, withEffectiveOff as At, defaultDesktopAuthPath as B, WorkBuddyImageError as Bt, setDeviceMode as C, withFileLock as Cn, attachBusyLevels as Ct, applyContextBudgets as D, offDefaultFor as Dt, WorkBuddyCatalog as E, lastRefusalFor as Et, WorkBuddyCredentialStore as F, pickVideoModel as Ft, parseWorkBuddyAuth as G, pickMediaModel as Gt, isEncryptedCredentialError as H, imageMimeForPath as Ht, WorkBuddyEncryptedCredentialError as I, resolveVideoParams as It, workbuddyOwnAuthPath as J, queueNoticeText as Jt, preferredAccountName as K, sniffImageMime as Kt, authFileName as L, IMAGE_TAG_IMAGE_TO_IMAGE as Lt, WORKBUDDY_AUTH_FILENAME as M, VIDEO_TAG_TEXT_TO_VIDEO as Mt, WORKBUDDY_AUTH_FILE_ENV as N, WorkBuddyVideoError as Nt, deriveCatalog as O, offRefused as Ot, WORKBUDDY_VAULT_DIRNAME as P, parseSupportedSecondsRange as Pt, CREDENTIAL_REJECTED_CODE as Q, nativeModalityOf as Qt, defaultDesktopAuthCandidates as R, IMAGE_TAG_TEXT_TO_IMAGE as Rt, saveDeviceSdkSettings as S, resolveDshHome as Sn, rewriteSessionTitleModel as St, FALLBACK_WORKBUDDY_MODELS_GLOBAL as T, defaultOffModelIds as Tt, isVaultAccountId as U, isBareBase64Image as Ut, hasEncryptedCredentialFields as V, imageDataUrl as Vt, legacyWorkbuddyOwnAuthPath as W, parseImageDataUrl as Wt, APP_VERSION as X, NATIVE_MODALITY_BY_MODEL_ID as Xt, workbuddyVaultDir as Y, pruneTempDir as Yt, CONTEXT_OVERFLOW_MARKER as Z, imageDefaultFor as Zt, createDeviceProfileLookup as _, macosNestedAppBundles as _n, parseUpstreamModel as _t, readHostHeartbeat as a, inspectCredentialDirectory as an, declaredTools as at, readDeviceSettings as b, workbuddyAppExecutableCandidates as bn, regionOf as bt, WORKBUDDY_CONNECT_VERSION as c, clearAtRestKeyCache as cn, isContextTooLongBody as ct, rosterSeenPath as d, fetchAtRestKeyPayload as dn, isFirstMessageGateBody as dt, readDeviceTokenFile as en, WORKBUDDY_FALLBACK_SYSTEM_PROMPT as et, WORKBUDDY_CN_BASE_ENV as f, findWorkbuddyAppExecutable as fn, knownRegionOf as ft, createTuringSdk as g, macosBundleExecutable as gn, parseReasoning as gt, createDeviceSdkPort as h, isWorkbuddyBundle as hn, parseCreditMultiplier as ht, processStartTimeMs as i, isDeviceId as in, classifyUpstreamError as it, ENCRYPTED_CREDENTIAL_CODE as j, VIDEO_TAG_IMAGE_TO_VIDEO as jt, fallbackModelsFor as k, recordRefusal as kt, createFileRosterSeenStore as l, deriveAtRestKey as ln, isConversationIdGateBody as lt, piAiRuntimeInfo as m, isEncryptedFieldWrapper as mn, openingEvidenceOfBody as mt, clearHostHeartbeat as n, readDeviceSalt as nn, WorkBuddyUpstreamClient as nt, workbuddyHostHeartbeatPath as o, protectCredentialDirectory as on, describeRequestHeaderNames as ot, resolveCnGateway as p, findWorkbuddyAppExecutableWithSource as pn, modelIdOfBody as pt, workbuddyAccountId as q, parseQueueAnswer as qt, isHeartbeatProcessAlive as r, deriveDeviceId as rn, channelGateMemberOf as rt, writeHostHeartbeat as s, WORKBUDDY_APP_EXECUTABLE_ENV as sn, forceNeutralHead as st, WORKBUDDY_HOST_HEARTBEAT_FILENAME as t, ensureDeviceSalt as tn, WorkBuddyCredentialRejectedError as tt, describeRosterSeenPayload as u, deriveAtRestKeyId as un, isCredentialRejectedError as ut, describeDerivedDevices as v, openEncryptedField as vn, perturbChannelFingerprints as vt, FALLBACK_WORKBUDDY_MODELS as w, writeFileAtomic as wn, REFUSES_OFF_MODEL_IDS as wt, saveDeviceProfile as x, hostPeersInfo as xn, requestEvidenceOf as xt, isDeviceMode as y, readAtRestKey as yn, prepareChatBody as yt, defaultDesktopAuthDirs as z, MAX_INPUT_IMAGE_BYTES as zt };
|
package/lib/index.d.ts
CHANGED
|
@@ -1852,6 +1852,14 @@ declare class WorkBuddyUpstreamClient {
|
|
|
1852
1852
|
private readonly deviceProfiles;
|
|
1853
1853
|
/** 真实值档的 token 源(本机安装的桌面端 SDK);未接线时为 undefined。 */
|
|
1854
1854
|
private readonly realDevice;
|
|
1855
|
+
/**
|
|
1856
|
+
* CN 网关 base(issue #220)。空 = 用内置常量,即 #220 之前的行为逐字节不变。
|
|
1857
|
+
*
|
|
1858
|
+
* 只影响 CN 区域:国际版仍然跟随凭据自己的域(`workbuddy.ai` /
|
|
1859
|
+
* `codebuddy.ai`),因为国际 token 跨品牌互不通用,那里没有"换一个同构主机"
|
|
1860
|
+
* 这回事。返回值必须已由 `resolveCnGateway` 的允许清单校验过,这个类不重新校验。
|
|
1861
|
+
*/
|
|
1862
|
+
private readonly cnBaseOf;
|
|
1855
1863
|
constructor(onFallback?: ((message: string) => void) | undefined, identity?: WorkBuddyWireIdentity, options?: {
|
|
1856
1864
|
/** `deviceToken.file`:裸值或 A 的 `{token,ts}` 信封都可。 */
|
|
1857
1865
|
deviceTokenFile?: string;
|
|
@@ -1861,6 +1869,15 @@ declare class WorkBuddyUpstreamClient {
|
|
|
1861
1869
|
deviceProfiles?: WorkBuddyDeviceProfileLookup;
|
|
1862
1870
|
/** 真实值档的 token 源(`src/turing-sdk.ts`)。 */
|
|
1863
1871
|
realDevice?: TuringTokenSource;
|
|
1872
|
+
/**
|
|
1873
|
+
* CN 网关 base 覆盖(issue #220)的**读取器**,不是值。
|
|
1874
|
+
*
|
|
1875
|
+
* 为什么是函数:`regions` 是 volatile 字段,用户改完不必重启插件。若这里收
|
|
1876
|
+
* 一个字符串,改设置在进程生命周期内不会生效——用户会认为「填了没反应」,
|
|
1877
|
+
* 而这恰好是本设置唯一的用途。每次请求现问一次,与 `regionEnabled` 读活值
|
|
1878
|
+
* 同一条规则。返回空串表示用内置网关。
|
|
1879
|
+
*/
|
|
1880
|
+
cnBase?: () => string;
|
|
1864
1881
|
});
|
|
1865
1882
|
/**
|
|
1866
1883
|
* 本次请求的完整身份:底座(盐)+ 当前有效的真 token + 这个账号的覆盖值。
|
|
@@ -5666,6 +5683,28 @@ interface WorkBuddyRegionState {
|
|
|
5666
5683
|
* decides, and which refuses to name a tier the model does not declare.
|
|
5667
5684
|
*/
|
|
5668
5685
|
defaultThinkingEfforts?: Record<string, string>;
|
|
5686
|
+
/**
|
|
5687
|
+
* An alternative CN gateway host (issue #220).
|
|
5688
|
+
*
|
|
5689
|
+
* Only the CN region reads it; the international gateways follow the
|
|
5690
|
+
* credential's own brand domain and have no equivalent setting.
|
|
5691
|
+
*
|
|
5692
|
+
* EXISTS FOR ONE CASE: a corporate network that filters on the TLS
|
|
5693
|
+
* ClientHello's SNI. `copilot.tencent.com` is then reset before any HTTP is
|
|
5694
|
+
* sent (`ECONNRESET`, <100ms) while the WorkBuddy desktop app keeps working,
|
|
5695
|
+
* because the app reads a failover list from its own config and also uses
|
|
5696
|
+
* `wb.tencentbuddy.com`. Without this field the plugin is simply unusable on
|
|
5697
|
+
* such a network, and looks broken rather than filtered.
|
|
5698
|
+
*
|
|
5699
|
+
* The value is a HOST, validated against a closed allowlist by
|
|
5700
|
+
* `resolveCnGateway` (`src/cn-gateway.ts`) — never a free-form URL. That
|
|
5701
|
+
* allowlist is the security boundary, not a convenience: this base carries
|
|
5702
|
+
* `Authorization: Bearer <token>` on every CN request, so accepting an
|
|
5703
|
+
* arbitrary host would turn a settings file into a token-exfiltration
|
|
5704
|
+
* primitive. Empty/absent means the built-in gateway, i.e. the behaviour
|
|
5705
|
+
* before #220.
|
|
5706
|
+
*/
|
|
5707
|
+
cnBase?: string;
|
|
5669
5708
|
/** This region's account-pool preferences (opt-in; see {@link WorkBuddyPoolPreferences}). */
|
|
5670
5709
|
pool?: WorkBuddyPoolPreferences;
|
|
5671
5710
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as withoutRouters, At as withEffectiveOff, B as defaultDesktopAuthPath, Bt as WorkBuddyImageError, C as setDeviceMode, Cn as withFileLock, Ct as attachBusyLevels, D as applyContextBudgets, Dt as offDefaultFor, E as WorkBuddyCatalog, Et as lastRefusalFor, F as WorkBuddyCredentialStore, Ft as pickVideoModel, G as parseWorkBuddyAuth, Gt as pickMediaModel, H as isEncryptedCredentialError, Ht as imageMimeForPath, I as WorkBuddyEncryptedCredentialError, It as resolveVideoParams, J as workbuddyOwnAuthPath, Jt as queueNoticeText, K as preferredAccountName, Kt as sniffImageMime, L as authFileName, Lt as IMAGE_TAG_IMAGE_TO_IMAGE, M as WORKBUDDY_AUTH_FILENAME, Mt as VIDEO_TAG_TEXT_TO_VIDEO, N as WORKBUDDY_AUTH_FILE_ENV, Nt as WorkBuddyVideoError, O as deriveCatalog, Ot as offRefused, Pt as parseSupportedSecondsRange, Q as CREDENTIAL_REJECTED_CODE, Qt as nativeModalityOf, R as defaultDesktopAuthCandidates, Rt as IMAGE_TAG_TEXT_TO_IMAGE, S as saveDeviceSdkSettings, Sn as resolveDshHome, St as rewriteSessionTitleModel, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, Tt as defaultOffModelIds, U as isVaultAccountId, Ut as isBareBase64Image, V as hasEncryptedCredentialFields, Vt as imageDataUrl, W as legacyWorkbuddyOwnAuthPath, Wt as parseImageDataUrl, X as APP_VERSION, Xt as NATIVE_MODALITY_BY_MODEL_ID, Yt as pruneTempDir, Z as CONTEXT_OVERFLOW_MARKER, Zt as imageDefaultFor, _ as createDeviceProfileLookup, _n as macosNestedAppBundles, _t as parseUpstreamModel, a as readHostHeartbeat, at as declaredTools, b as readDeviceSettings, bn as workbuddyAppExecutableCandidates, bt as regionOf, c as WORKBUDDY_CONNECT_VERSION, cn as clearAtRestKeyCache, ct as isContextTooLongBody, dn as fetchAtRestKeyPayload, dt as isFirstMessageGateBody, et as WORKBUDDY_FALLBACK_SYSTEM_PROMPT, fn as findWorkbuddyAppExecutable, ft as knownRegionOf, g as createTuringSdk, gn as macosBundleExecutable, gt as parseReasoning, h as createDeviceSdkPort, hn as isWorkbuddyBundle, ht as parseCreditMultiplier, i as processStartTimeMs, in as isDeviceId, it as classifyUpstreamError, j as ENCRYPTED_CREDENTIAL_CODE, jt as VIDEO_TAG_IMAGE_TO_VIDEO, k as fallbackModelsFor, kt as recordRefusal, l as createFileRosterSeenStore, ln as deriveAtRestKey, lt as isConversationIdGateBody, m as piAiRuntimeInfo, mn as isEncryptedFieldWrapper, mt as openingEvidenceOfBody, n as clearHostHeartbeat, nt as WorkBuddyUpstreamClient, o as workbuddyHostHeartbeatPath, p as resolveCnGateway, pt as modelIdOfBody, q as workbuddyAccountId, qt as parseQueueAnswer, r as isHeartbeatProcessAlive, rt as channelGateMemberOf, s as writeHostHeartbeat, sn as WORKBUDDY_APP_EXECUTABLE_ENV, st as forceNeutralHead, t as WORKBUDDY_HOST_HEARTBEAT_FILENAME, tt as WorkBuddyCredentialRejectedError, un as deriveAtRestKeyId, ut as isCredentialRejectedError, v as describeDerivedDevices, vn as openEncryptedField, vt as perturbChannelFingerprints, w as FALLBACK_WORKBUDDY_MODELS, wn as writeFileAtomic, wt as REFUSES_OFF_MODEL_IDS, x as saveDeviceProfile, xt as requestEvidenceOf, y as isDeviceMode, yn as readAtRestKey, yt as prepareChatBody, z as defaultDesktopAuthDirs, zt as MAX_INPUT_IMAGE_BYTES } from "./host-heartbeat-CQ3ot5-F.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";
|
|
@@ -12543,6 +12543,18 @@ const regionStateConfig = z.object({
|
|
|
12543
12543
|
enabledModelIds: z.array(z.string()).default([]),
|
|
12544
12544
|
imageModelIds: z.array(z.string()).default([]),
|
|
12545
12545
|
/**
|
|
12546
|
+
* Alternative CN gateway host (issue #220); see the interface field of the
|
|
12547
|
+
* same name. Empty = the built-in gateway.
|
|
12548
|
+
*
|
|
12549
|
+
* A plain string rather than a `union` of the allowed hosts on purpose: the
|
|
12550
|
+
* allowlist lives in `src/cn-gateway.ts` and is enforced there with an
|
|
12551
|
+
* explicit reason the card can word ("not a known CN host" vs "not https").
|
|
12552
|
+
* Encoding it in the schema too would produce a validation error the settings
|
|
12553
|
+
* layer reports as a generic schema failure, and the user would be told their
|
|
12554
|
+
* value is invalid without being told which rule it broke.
|
|
12555
|
+
*/
|
|
12556
|
+
cnBase: z.string().default("").description("Alternative CN gateway host for networks that filter copilot.tencent.com by TLS SNI (issue #220). Must be an https URL on one of the CN brands: copilot.tencent.com, wb.tencentbuddy.com, www.workbuddy.cn, www.codebuddy.cn (any subdomain of those registrable domains). Empty keeps the built-in gateway. Chat, billing, catalog and check-in all follow it; Origin/Referer keep naming the CN web app. CONNECTION-LAYER failures only — set it after a filter, not to change your account or region."),
|
|
12557
|
+
/**
|
|
12546
12558
|
* Whether the model may call the image-generation tool (opt-IN, default off).
|
|
12547
12559
|
*
|
|
12548
12560
|
* Per-REGION like the credit switches, and it now means the same thing on both
|
|
@@ -12953,6 +12965,28 @@ function apply(ctx, config) {
|
|
|
12953
12965
|
ctx.effect(() => () => {
|
|
12954
12966
|
turing.stopAutoRefresh();
|
|
12955
12967
|
});
|
|
12968
|
+
/**
|
|
12969
|
+
* Announce a CN gateway override, ONCE per distinct value / failure.
|
|
12970
|
+
*
|
|
12971
|
+
* The reader runs on every CN request, so logging unconditionally would turn
|
|
12972
|
+
* one misconfiguration into a warn per request. Keyed on the VALUE rather than
|
|
12973
|
+
* a plain boolean, so fixing the setting and breaking it again both get said —
|
|
12974
|
+
* a user who is iterating on hosts needs to see each attempt acknowledged.
|
|
12975
|
+
*/
|
|
12976
|
+
let announcedCnBase;
|
|
12977
|
+
let announcedCnBaseFailure;
|
|
12978
|
+
const warnCnBaseOnce = (base) => {
|
|
12979
|
+
if (announcedCnBase === base) return;
|
|
12980
|
+
announcedCnBase = base;
|
|
12981
|
+
ctx.logger.warn(`dsh-connect-workbuddy: CN gateway overridden to ${base} (issue #220). Chat, billing, catalog and check-in follow it; Origin/Referer still name the CN web app.`);
|
|
12982
|
+
};
|
|
12983
|
+
const warnCnBaseInvalidOnce = (reason, value) => {
|
|
12984
|
+
const key = `${reason}:${value}`;
|
|
12985
|
+
if (announcedCnBaseFailure === key) return;
|
|
12986
|
+
announcedCnBaseFailure = key;
|
|
12987
|
+
const why = reason === "malformed" ? "it is not an absolute URL" : reason === "insecure" ? "only https is accepted (a plaintext base would put the bearer token on the wire in clear)" : "its host is not one of the CN brands (copilot.tencent.com, wb.tencentbuddy.com, workbuddy.cn, codebuddy.cn)";
|
|
12988
|
+
ctx.logger.warn(`dsh-connect-workbuddy: ignoring regions.cn.cnBase "${value}" — ${why}. Using the built-in CN gateway.`);
|
|
12989
|
+
};
|
|
12956
12990
|
const client = new WorkBuddyUpstreamClient((message) => {
|
|
12957
12991
|
ctx.logger.warn(`dsh-connect-workbuddy: ${message}`);
|
|
12958
12992
|
}, {
|
|
@@ -12965,7 +12999,28 @@ function apply(ctx, config) {
|
|
|
12965
12999
|
deviceTokenFile: configured !== "" ? configured : (process.env["WORKBUDDY_DEVICE_TOKEN_FILE"] ?? "").trim(),
|
|
12966
13000
|
...typeof token?.ttlMs === "number" ? { deviceTokenTtlMs: token.ttlMs } : {},
|
|
12967
13001
|
deviceProfiles,
|
|
12968
|
-
realDevice: turing.tokens
|
|
13002
|
+
realDevice: turing.tokens,
|
|
13003
|
+
/**
|
|
13004
|
+
* CN 网关覆盖(issue #220):**每次请求现读**,不是一个采样值。
|
|
13005
|
+
*
|
|
13006
|
+
* `regions` 是 volatile 字段,用户保存后不重启插件;这里若在构造期采样
|
|
13007
|
+
* 一次,改设置就只有重启才生效,而「填了没反应」正是本设置唯一的用途。
|
|
13008
|
+
*
|
|
13009
|
+
* 只对 CN 生效,且只有 `resolveCnGateway` 通过时才返回覆盖值:
|
|
13010
|
+
* 校验失败一律退回内置网关并记一条 warn。**退回而不是抛**,因为这条
|
|
13011
|
+
* 路径在每一请求上;但绝不静默——用户填了个不被接受的 host 却一直用着
|
|
13012
|
+
* 默认网关,会让他继续怀疑是网络,而不是自己填错。
|
|
13013
|
+
*/
|
|
13014
|
+
cnBase: () => {
|
|
13015
|
+
const raw = regionStateOf(current(), "cn").cnBase;
|
|
13016
|
+
const resolved = resolveCnGateway(raw);
|
|
13017
|
+
if (resolved.ok) {
|
|
13018
|
+
if (resolved.overridden) warnCnBaseOnce(resolved.base);
|
|
13019
|
+
return resolved.overridden ? resolved.base : "";
|
|
13020
|
+
}
|
|
13021
|
+
warnCnBaseInvalidOnce(resolved.reason, resolved.value);
|
|
13022
|
+
return "";
|
|
13023
|
+
}
|
|
12969
13024
|
};
|
|
12970
13025
|
})());
|
|
12971
13026
|
/**
|
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.
|
|
5
|
+
"version": "5.20.2",
|
|
6
6
|
"author": "dingminhua",
|
|
7
7
|
"copyright": "Copyright (c) 2026 LaoDing",
|
|
8
8
|
"license": "MIT",
|