dsh-connect-workbuddy 5.20.32 → 5.21.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 +221 -3
- package/README.md +3 -2
- package/lib/bin.js +1 -1
- package/lib/client.js +480 -39
- package/lib/{host-heartbeat-DekAOmo0.js → host-heartbeat-CxvijdHh.js} +1 -1
- package/lib/index.d.ts +39 -0
- package/lib/index.js +215 -16
- package/package.json +1 -1
|
@@ -10527,7 +10527,7 @@ function describeRosterSeenPayload(raw) {
|
|
|
10527
10527
|
//#endregion
|
|
10528
10528
|
//#region src/version.ts
|
|
10529
10529
|
/** The npm package version this build was produced from. */
|
|
10530
|
-
const WORKBUDDY_CONNECT_VERSION = "5.
|
|
10530
|
+
const WORKBUDDY_CONNECT_VERSION = "5.21.2";
|
|
10531
10531
|
//#endregion
|
|
10532
10532
|
//#region src/host-heartbeat.ts
|
|
10533
10533
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -4189,6 +4189,15 @@ type WorkBuddyWebUsage =
|
|
|
4189
4189
|
* that cannot answer must not be read as consent.
|
|
4190
4190
|
*/
|
|
4191
4191
|
sidebarPanelEnabled?: boolean;
|
|
4192
|
+
/**
|
|
4193
|
+
* How often the card should re-read this document, in milliseconds.
|
|
4194
|
+
*
|
|
4195
|
+
* GLOBAL like `sidebarPanelEnabled`, and carried on the Host's answer for
|
|
4196
|
+
* the same measured reason: on the stale-mirror 0.1.7 deployment an
|
|
4197
|
+
* interval read from the settings mirror could be a value the Host never
|
|
4198
|
+
* stored. Absent reads as {@link WORKBUDDY_DEFAULT_POLL_INTERVAL_MS}.
|
|
4199
|
+
*/
|
|
4200
|
+
pollIntervalMs?: number;
|
|
4192
4201
|
/**
|
|
4193
4202
|
* The model the OPTIONAL CodeBuddy CLI route runs on, or `''` for
|
|
4194
4203
|
* "nothing is pinned, the CLI uses its own default".
|
|
@@ -4342,6 +4351,15 @@ type WorkBuddyWebUsage =
|
|
|
4342
4351
|
* that cannot answer must not be read as consent.
|
|
4343
4352
|
*/
|
|
4344
4353
|
sidebarPanelEnabled?: boolean;
|
|
4354
|
+
/**
|
|
4355
|
+
* How often the card should re-read this document, in milliseconds.
|
|
4356
|
+
*
|
|
4357
|
+
* GLOBAL like `sidebarPanelEnabled`, and carried on the Host's answer for
|
|
4358
|
+
* the same measured reason: on the stale-mirror 0.1.7 deployment an
|
|
4359
|
+
* interval read from the settings mirror could be a value the Host never
|
|
4360
|
+
* stored. Absent reads as {@link WORKBUDDY_DEFAULT_POLL_INTERVAL_MS}.
|
|
4361
|
+
*/
|
|
4362
|
+
pollIntervalMs?: number;
|
|
4345
4363
|
/**
|
|
4346
4364
|
* The model the OPTIONAL CodeBuddy CLI route runs on, or `''` for
|
|
4347
4365
|
* "nothing is pinned, the CLI uses its own default".
|
|
@@ -5086,6 +5104,18 @@ interface WorkBuddyStatusRouteOptions {
|
|
|
5086
5104
|
* stale `true` here would draw a row the Host does not honour.
|
|
5087
5105
|
*/
|
|
5088
5106
|
sidebarPanelEnabled?(): boolean;
|
|
5107
|
+
/**
|
|
5108
|
+
* How often the card should re-read this document, in milliseconds.
|
|
5109
|
+
*
|
|
5110
|
+
* Carried on the Host's answer rather than read from the browser's settings
|
|
5111
|
+
* mirror, for the same measured reason as the two flags above: that mirror is
|
|
5112
|
+
* stale for this namespace on the affected 0.1.7 deployments, and a stale
|
|
5113
|
+
* interval would make the card poll at a cadence the Host never stored.
|
|
5114
|
+
*
|
|
5115
|
+
* Optional, and absent reads as the 5-minute default — which is what an older
|
|
5116
|
+
* Host (and any build before the setting existed) should do.
|
|
5117
|
+
*/
|
|
5118
|
+
pollIntervalMs?(): number;
|
|
5089
5119
|
/**
|
|
5090
5120
|
* The model the OPTIONAL CodeBuddy CLI route runs on, or `''` for "the CLI's
|
|
5091
5121
|
* own default".
|
|
@@ -5929,6 +5959,15 @@ interface Config {
|
|
|
5929
5959
|
* 而不必先回滚一个版本。
|
|
5930
5960
|
*/
|
|
5931
5961
|
wireProfile?: 'conservative' | 'balanced';
|
|
5962
|
+
/**
|
|
5963
|
+
* How often the card refreshes its account table, in milliseconds.
|
|
5964
|
+
*
|
|
5965
|
+
* One of 60000 / 300000 / 600000 / 1800000 / 3600000; absent reads as 5
|
|
5966
|
+
* minutes. This is the setting that decides the plugin's upstream request
|
|
5967
|
+
* volume (one credits read plus one check-in read per pooled account, per
|
|
5968
|
+
* refresh), and the composer account panel follows it.
|
|
5969
|
+
*/
|
|
5970
|
+
pollIntervalMs?: number;
|
|
5932
5971
|
/**
|
|
5933
5972
|
* SDK 功能的**总开关**(默认开)。
|
|
5934
5973
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as imageDefaultFor, A as withoutRouters, At as offRefused, B as defaultDesktopAuthPath, Bt as IMAGE_TAG_TEXT_TO_IMAGE, C as setDeviceMode, Ct as attachBusyLevels, D as applyContextBudgets, Dt as defaultOffModelIds, E as WorkBuddyCatalog, En as writeFileAtomic, Et as REFUSES_OFF_MODEL_IDS, F as WorkBuddyCredentialStore, Ft as WorkBuddyVideoError, G as parseWorkBuddyAuth, Gt as isBareBase64Image, H as isEncryptedCredentialError, Ht as WorkBuddyImageError, I as WorkBuddyEncryptedCredentialError, It as parseSupportedSecondsRange, J as workbuddyOwnAuthPath, Jt as sniffImageMime, K as preferredAccountName, Kt as parseImageDataUrl, L as authFileName, Lt as pickVideoModel, M as WORKBUDDY_AUTH_FILENAME, Mt as withEffectiveOff, N as WORKBUDDY_AUTH_FILE_ENV, Nt as VIDEO_TAG_IMAGE_TO_VIDEO, O as deriveCatalog, Ot as lastRefusalFor, Pt as VIDEO_TAG_TEXT_TO_VIDEO, Q as CREDENTIAL_REJECTED_CODE, Qt as NATIVE_MODALITY_BY_MODEL_ID, R as defaultDesktopAuthCandidates, Rt as resolveVideoParams, S as saveDeviceSdkSettings, Sn as workbuddyAppExecutableCandidates, St as rewriteSessionTitleModel, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, Tn as withFileLock, Tt as selectPromoBadge, U as isVaultAccountId, Ut as imageDataUrl, V as hasEncryptedCredentialFields, Vt as MAX_INPUT_IMAGE_BYTES, W as legacyWorkbuddyOwnAuthPath, Wt as imageMimeForPath, X as APP_VERSION, Xt as queueNoticeText, Yt as parseQueueAnswer, Z as CONTEXT_OVERFLOW_MARKER, Zt as pruneTempDir, _ as createDeviceProfileLookup, _n as isWorkbuddyBundle, _t as parseUpstreamModel, a as readHostHeartbeat, at as declaredTools, b as readDeviceSettings, bn as openEncryptedField, bt as regionOf, c as WORKBUDDY_CONNECT_VERSION, ct as isContextTooLongBody, dn as deriveAtRestKey, dt as isFirstMessageGateBody, en as nativeModalityOf, et as WORKBUDDY_FALLBACK_SYSTEM_PROMPT, fn as deriveAtRestKeyId, ft as knownRegionOf, g as createTuringSdk, gn as isEncryptedFieldWrapper, gt as parseReasoning, h as createDeviceSdkPort, ht as parseCreditMultiplier, i as processStartTimeMs, it as classifyUpstreamError, j as ENCRYPTED_CREDENTIAL_CODE, jt as recordRefusal, k as fallbackModelsFor, kt as offDefaultFor, l as createFileRosterSeenStore, ln as WORKBUDDY_APP_EXECUTABLE_ENV, lt as isConversationIdGateBody, m as piAiRuntimeInfo, mn as findWorkbuddyAppExecutable, mt as openingEvidenceOfBody, n as clearHostHeartbeat, nt as WorkBuddyUpstreamClient, o as workbuddyHostHeartbeatPath, on as isDeviceId, p as resolveCnGateway, pn as fetchAtRestKeyPayload, pt as modelIdOfBody, q as workbuddyAccountId, qt as pickMediaModel, r as isHeartbeatProcessAlive, rt as channelGateMemberOf, s as writeHostHeartbeat, st as forceNeutralHead, t as WORKBUDDY_HOST_HEARTBEAT_FILENAME, tt as WorkBuddyCredentialRejectedError, un as clearAtRestKeyCache, ut as isCredentialRejectedError, v as describeDerivedDevices, vn as macosBundleExecutable, vt as perturbChannelFingerprints, w as FALLBACK_WORKBUDDY_MODELS, wn as resolveDshHome, wt as promoBadgeTone, x as saveDeviceProfile, xn as readAtRestKey, xt as requestEvidenceOf, y as isDeviceMode, yn as macosNestedAppBundles, yt as prepareChatBody, z as defaultDesktopAuthDirs, zt as IMAGE_TAG_IMAGE_TO_IMAGE } from "./host-heartbeat-
|
|
1
|
+
import { $t as imageDefaultFor, A as withoutRouters, At as offRefused, B as defaultDesktopAuthPath, Bt as IMAGE_TAG_TEXT_TO_IMAGE, C as setDeviceMode, Ct as attachBusyLevels, D as applyContextBudgets, Dt as defaultOffModelIds, E as WorkBuddyCatalog, En as writeFileAtomic, Et as REFUSES_OFF_MODEL_IDS, F as WorkBuddyCredentialStore, Ft as WorkBuddyVideoError, G as parseWorkBuddyAuth, Gt as isBareBase64Image, H as isEncryptedCredentialError, Ht as WorkBuddyImageError, I as WorkBuddyEncryptedCredentialError, It as parseSupportedSecondsRange, J as workbuddyOwnAuthPath, Jt as sniffImageMime, K as preferredAccountName, Kt as parseImageDataUrl, L as authFileName, Lt as pickVideoModel, M as WORKBUDDY_AUTH_FILENAME, Mt as withEffectiveOff, N as WORKBUDDY_AUTH_FILE_ENV, Nt as VIDEO_TAG_IMAGE_TO_VIDEO, O as deriveCatalog, Ot as lastRefusalFor, Pt as VIDEO_TAG_TEXT_TO_VIDEO, Q as CREDENTIAL_REJECTED_CODE, Qt as NATIVE_MODALITY_BY_MODEL_ID, R as defaultDesktopAuthCandidates, Rt as resolveVideoParams, S as saveDeviceSdkSettings, Sn as workbuddyAppExecutableCandidates, St as rewriteSessionTitleModel, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, Tn as withFileLock, Tt as selectPromoBadge, U as isVaultAccountId, Ut as imageDataUrl, V as hasEncryptedCredentialFields, Vt as MAX_INPUT_IMAGE_BYTES, W as legacyWorkbuddyOwnAuthPath, Wt as imageMimeForPath, X as APP_VERSION, Xt as queueNoticeText, Yt as parseQueueAnswer, Z as CONTEXT_OVERFLOW_MARKER, Zt as pruneTempDir, _ as createDeviceProfileLookup, _n as isWorkbuddyBundle, _t as parseUpstreamModel, a as readHostHeartbeat, at as declaredTools, b as readDeviceSettings, bn as openEncryptedField, bt as regionOf, c as WORKBUDDY_CONNECT_VERSION, ct as isContextTooLongBody, dn as deriveAtRestKey, dt as isFirstMessageGateBody, en as nativeModalityOf, et as WORKBUDDY_FALLBACK_SYSTEM_PROMPT, fn as deriveAtRestKeyId, ft as knownRegionOf, g as createTuringSdk, gn as isEncryptedFieldWrapper, gt as parseReasoning, h as createDeviceSdkPort, ht as parseCreditMultiplier, i as processStartTimeMs, it as classifyUpstreamError, j as ENCRYPTED_CREDENTIAL_CODE, jt as recordRefusal, k as fallbackModelsFor, kt as offDefaultFor, l as createFileRosterSeenStore, ln as WORKBUDDY_APP_EXECUTABLE_ENV, lt as isConversationIdGateBody, m as piAiRuntimeInfo, mn as findWorkbuddyAppExecutable, mt as openingEvidenceOfBody, n as clearHostHeartbeat, nt as WorkBuddyUpstreamClient, o as workbuddyHostHeartbeatPath, on as isDeviceId, p as resolveCnGateway, pn as fetchAtRestKeyPayload, pt as modelIdOfBody, q as workbuddyAccountId, qt as pickMediaModel, r as isHeartbeatProcessAlive, rt as channelGateMemberOf, s as writeHostHeartbeat, st as forceNeutralHead, t as WORKBUDDY_HOST_HEARTBEAT_FILENAME, tt as WorkBuddyCredentialRejectedError, un as clearAtRestKeyCache, ut as isCredentialRejectedError, v as describeDerivedDevices, vn as macosBundleExecutable, vt as perturbChannelFingerprints, w as FALLBACK_WORKBUDDY_MODELS, wn as resolveDshHome, wt as promoBadgeTone, x as saveDeviceProfile, xn as readAtRestKey, xt as requestEvidenceOf, y as isDeviceMode, yn as macosNestedAppBundles, yt as prepareChatBody, z as defaultDesktopAuthDirs, zt as IMAGE_TAG_IMAGE_TO_IMAGE } from "./host-heartbeat-CxvijdHh.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";
|
|
@@ -399,6 +399,33 @@ const WORKBUDDY_DEVICE_PROFILE_PATH = "/plugins/dsh-connect-workbuddy/device-pro
|
|
|
399
399
|
const WORKBUDDY_DEVICE_SDK_PATH = "/plugins/dsh-connect-workbuddy/device-sdk";
|
|
400
400
|
/** Query parameter selecting it. */
|
|
401
401
|
const WORKBUDDY_DEVICE_SDK_ACTION_PARAM = "action";
|
|
402
|
+
/**
|
|
403
|
+
* The refresh intervals the card offers, in milliseconds.
|
|
404
|
+
*
|
|
405
|
+
* SHARED between the Host (which validates the saved value) and the browser
|
|
406
|
+
* (which renders the dropdown), so the control and its validation cannot drift:
|
|
407
|
+
* a value the dropdown can produce is always a value the Host accepts, and the
|
|
408
|
+
* Host's fallback is always a value the dropdown can show.
|
|
409
|
+
*
|
|
410
|
+
* A CLOSED SET rather than a free number because this interval decides the
|
|
411
|
+
* plugin's upstream request volume — one credits read plus one check-in read per
|
|
412
|
+
* pooled account, per refresh.
|
|
413
|
+
*/
|
|
414
|
+
const WORKBUDDY_POLL_INTERVALS_MS = [
|
|
415
|
+
6e4,
|
|
416
|
+
3e5,
|
|
417
|
+
6e5,
|
|
418
|
+
18e5,
|
|
419
|
+
36e5
|
|
420
|
+
];
|
|
421
|
+
/**
|
|
422
|
+
* The default refresh interval: 5 minutes.
|
|
423
|
+
*
|
|
424
|
+
* Moved off the old hard-coded 60 s. A 4-account pool at 60 s costs ~11,520
|
|
425
|
+
* requests a day for figures that move slowly; 5 minutes is a fifth of that and
|
|
426
|
+
* still five times finer than the 30-minute auto check-in heartbeat.
|
|
427
|
+
*/
|
|
428
|
+
const WORKBUDDY_DEFAULT_POLL_INTERVAL_MS = 3e5;
|
|
402
429
|
/** Read the OAuth action off a request URL; unknown/absent means undefined. */
|
|
403
430
|
function oauthActionOf(url) {
|
|
404
431
|
const at = url.indexOf("?");
|
|
@@ -10640,7 +10667,26 @@ function parseTransferFile(text) {
|
|
|
10640
10667
|
const records = recordsOf(parsed);
|
|
10641
10668
|
if (records === void 0) throw new Error("transfer file must be a JSON array of account records; this file is " + describeShape(parsed) + ". Accepted wrappers: {\"accounts\": [...]}, {\"data\": [...]}, {\"records\": [...]}.");
|
|
10642
10669
|
for (const [index, item] of records.entries()) if (typeof item !== "object" || item === null || Array.isArray(item)) throw new Error("transfer file item " + (index + 1) + " is not an account object");
|
|
10643
|
-
return records;
|
|
10670
|
+
return records.map((item) => stripRedundantRaw(item));
|
|
10671
|
+
}
|
|
10672
|
+
/**
|
|
10673
|
+
* Drop `*_raw` snapshots the importer never reads, keeping `auth_raw`.
|
|
10674
|
+
*
|
|
10675
|
+
* `auth_raw` is exempt because it carries the billing `uin`, which is what makes
|
|
10676
|
+
* a re-imported account converge on the same vault id — dropping it would change
|
|
10677
|
+
* behaviour, not just size.
|
|
10678
|
+
*/
|
|
10679
|
+
function stripRedundantRaw(record) {
|
|
10680
|
+
let changed = false;
|
|
10681
|
+
const kept = {};
|
|
10682
|
+
for (const [key, value] of Object.entries(record)) {
|
|
10683
|
+
if (key !== "auth_raw" && key.endsWith("_raw")) {
|
|
10684
|
+
changed = true;
|
|
10685
|
+
continue;
|
|
10686
|
+
}
|
|
10687
|
+
kept[key] = value;
|
|
10688
|
+
}
|
|
10689
|
+
return changed ? kept : record;
|
|
10644
10690
|
}
|
|
10645
10691
|
/**
|
|
10646
10692
|
* The record array inside whatever the file's top level happens to be.
|
|
@@ -11196,6 +11242,42 @@ function summarizeAutoCheckin(state) {
|
|
|
11196
11242
|
};
|
|
11197
11243
|
}
|
|
11198
11244
|
/**
|
|
11245
|
+
* Today's summary — `undefined` when `state` is not today's.
|
|
11246
|
+
*
|
|
11247
|
+
* The day check is NOT a nicety (issue #232). The state is only rewritten when a
|
|
11248
|
+
* tick runs, and after a finished day the next tick is an idle heartbeat up to
|
|
11249
|
+
* {@link AUTO_CHECKIN_IDLE_MS} away — so for the first half hour of a new local
|
|
11250
|
+
* day the in-memory state still describes YESTERDAY. Summarizing it as today made
|
|
11251
|
+
* the card announce 「今日:N 个全部已签」 at 00:08 while every row underneath
|
|
11252
|
+
* read 未签到, i.e. the one place that is supposed to prove the runner works
|
|
11253
|
+
* claimed the opposite of the truth.
|
|
11254
|
+
*
|
|
11255
|
+
* `undefined` (rather than a zeroed summary) is what the card already renders as
|
|
11256
|
+
* "no status line", and it is the honest answer: nothing has run today yet. The
|
|
11257
|
+
* zeroed variant would invent a denominator for a day no attempt has measured.
|
|
11258
|
+
*/
|
|
11259
|
+
function todaySummary(state, nowMs) {
|
|
11260
|
+
if (state.day !== localDayKey(nowMs)) return void 0;
|
|
11261
|
+
return summarizeAutoCheckin(state);
|
|
11262
|
+
}
|
|
11263
|
+
/**
|
|
11264
|
+
* Whether a cached check-in reading may still be served.
|
|
11265
|
+
*
|
|
11266
|
+
* Two conditions, and the second is the one that took a bug report: a reading is
|
|
11267
|
+
* an answer to "has this account checked in TODAY", so it must not survive local
|
|
11268
|
+
* midnight. The TTL alone would serve a `true` read taken at 23:58 until 00:08,
|
|
11269
|
+
* so the column would assert a check-in that has not happened — the per-account
|
|
11270
|
+
* half of the same lie as {@link todaySummary}.
|
|
11271
|
+
*
|
|
11272
|
+
* The day is derived from `atMs` rather than stored beside it: the read time
|
|
11273
|
+
* already says which day the answer belongs to, and a second field could drift
|
|
11274
|
+
* out of step with it.
|
|
11275
|
+
*/
|
|
11276
|
+
function checkinReadingFresh(atMs, nowMs, ttlMs) {
|
|
11277
|
+
if (nowMs - atMs >= ttlMs) return false;
|
|
11278
|
+
return localDayKey(atMs) === localDayKey(nowMs);
|
|
11279
|
+
}
|
|
11280
|
+
/**
|
|
11199
11281
|
* The accounts an attempt should address, in the pool's own order.
|
|
11200
11282
|
*
|
|
11201
11283
|
* Only members that are not already done. Enterprise members are dropped HERE
|
|
@@ -11350,7 +11432,8 @@ const UPSTREAM_SWITCH_FIELDS = /* @__PURE__ */ new Set([
|
|
|
11350
11432
|
"dropForeignThinking",
|
|
11351
11433
|
"dropAllThinking",
|
|
11352
11434
|
"channelRejectContinue",
|
|
11353
|
-
"sidebarPanel"
|
|
11435
|
+
"sidebarPanel",
|
|
11436
|
+
"pollIntervalMs"
|
|
11354
11437
|
]);
|
|
11355
11438
|
/** A non-null, non-array object: the only shape the slot merge applies to. */
|
|
11356
11439
|
function isPlainRecord(value) {
|
|
@@ -11394,29 +11477,77 @@ function jsonPrivate(res, status, body) {
|
|
|
11394
11477
|
});
|
|
11395
11478
|
res.end(payload);
|
|
11396
11479
|
}
|
|
11397
|
-
/** Request-body cap for the
|
|
11480
|
+
/** Request-body cap for the PROBE route: model ids only, never content. */
|
|
11398
11481
|
const PROBE_BODY_LIMIT = 65536;
|
|
11399
11482
|
/**
|
|
11400
|
-
*
|
|
11483
|
+
* Request-body cap for routes that carry a FILE the user chose.
|
|
11401
11484
|
*
|
|
11402
|
-
*
|
|
11403
|
-
*
|
|
11404
|
-
*
|
|
11485
|
+
* WHY THIS IS NOT `PROBE_BODY_LIMIT` (issue #229, second report). The transfer
|
|
11486
|
+
* route takes the whole text of an account-export file, and those are not small:
|
|
11487
|
+
* a single account from a sibling tool measured 108 KiB, because the file carries
|
|
11488
|
+
* two raw upstream snapshots (`quota_raw` + `usage_raw`, ~59 KiB together) that
|
|
11489
|
+
* this plugin never reads. One account already exceeded the probe's 64 KiB, so a
|
|
11490
|
+
* perfectly valid import failed — with the *worst possible* error message (the
|
|
11491
|
+
* socket was destroyed, so the browser reported `Failed to fetch`).
|
|
11492
|
+
*
|
|
11493
|
+
* The number matches the chat route's limit for the same reason: a cap exists to
|
|
11494
|
+
* stop unbounded buffering, not to express an opinion about how big a user's
|
|
11495
|
+
* export file is allowed to be.
|
|
11405
11496
|
*/
|
|
11406
|
-
|
|
11497
|
+
const TRANSFER_BODY_LIMIT = 67108864;
|
|
11498
|
+
/**
|
|
11499
|
+
* Raised when a request body exceeds its route's cap.
|
|
11500
|
+
*
|
|
11501
|
+
* A CLASS, not a message, so the caller can answer 413 instead of 500: the
|
|
11502
|
+
* protocol says the client sent too much, and a 500 would send the reader
|
|
11503
|
+
* looking for a server-side fault that does not exist. Same reasoning (and the
|
|
11504
|
+
* same shape) as `RequestBodyTooLargeError` in `shim.ts`.
|
|
11505
|
+
*/
|
|
11506
|
+
var JsonBodyTooLargeError = class extends Error {
|
|
11507
|
+
limitBytes;
|
|
11508
|
+
constructor(limitBytes) {
|
|
11509
|
+
super("request body too large (limit " + String(limitBytes) + " bytes)");
|
|
11510
|
+
this.limitBytes = limitBytes;
|
|
11511
|
+
this.name = "JsonBodyTooLargeError";
|
|
11512
|
+
}
|
|
11513
|
+
};
|
|
11514
|
+
/**
|
|
11515
|
+
* Read a JSON object request body, bounded.
|
|
11516
|
+
*
|
|
11517
|
+
* AN OVER-LIMIT BODY IS STOPPED, NOT DESTROYED (issue #229). This used to call
|
|
11518
|
+
* `req.destroy()`, which tears down the SOCKET — so the error response could
|
|
11519
|
+
* never reach the client, and the browser reported a bare `Failed to fetch`.
|
|
11520
|
+
* The user then had no way to learn that the file was merely too large. The
|
|
11521
|
+
* chat route fixed exactly this in #174 ("the 413 can never reach the client
|
|
11522
|
+
* ... it saw a reset connection instead of an answer"); this reader was left
|
|
11523
|
+
* behind, and because the transfer route is the one route that takes a FILE, it
|
|
11524
|
+
* is the place the flaw actually bit. So the stream is paused and its listeners
|
|
11525
|
+
* dropped, the response still goes out, and the caller answers 413.
|
|
11526
|
+
*
|
|
11527
|
+
* @param req - The request to read.
|
|
11528
|
+
* @param limitBytes - The route's cap; defaults to the probe's small limit.
|
|
11529
|
+
*/
|
|
11530
|
+
function readJsonBody(req, limitBytes = PROBE_BODY_LIMIT) {
|
|
11407
11531
|
return new Promise((resolve, reject) => {
|
|
11408
11532
|
const chunks = [];
|
|
11409
11533
|
let size = 0;
|
|
11534
|
+
let settled = false;
|
|
11410
11535
|
req.on("data", (chunk) => {
|
|
11536
|
+
if (settled) return;
|
|
11411
11537
|
size += chunk.length;
|
|
11412
|
-
if (size >
|
|
11413
|
-
|
|
11414
|
-
|
|
11538
|
+
if (size > limitBytes) {
|
|
11539
|
+
settled = true;
|
|
11540
|
+
chunks.length = 0;
|
|
11541
|
+
req.removeAllListeners("data");
|
|
11542
|
+
req.removeAllListeners("end");
|
|
11543
|
+
req.pause();
|
|
11544
|
+
reject(new JsonBodyTooLargeError(limitBytes));
|
|
11415
11545
|
return;
|
|
11416
11546
|
}
|
|
11417
11547
|
chunks.push(chunk);
|
|
11418
11548
|
});
|
|
11419
11549
|
req.on("end", () => {
|
|
11550
|
+
if (settled) return;
|
|
11420
11551
|
try {
|
|
11421
11552
|
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
11422
11553
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
@@ -11659,6 +11790,18 @@ async function workBuddyWebStatus(deps, region, options = {}) {
|
|
|
11659
11790
|
const preferredVideoModels = deps.preferredVideoModels?.(region) ?? {};
|
|
11660
11791
|
const cliBridgeEnabled = deps.cliBridgeEnabled?.() === true;
|
|
11661
11792
|
const sidebarPanelEnabled = deps.sidebarPanelEnabled?.() === true;
|
|
11793
|
+
/**
|
|
11794
|
+
* The card's refresh cadence, resolved once per document.
|
|
11795
|
+
*
|
|
11796
|
+
* Coerced against the offered set here as well as on the Host: this value
|
|
11797
|
+
* drives `setInterval`, and an unrecognized number (an older Host, a
|
|
11798
|
+
* hand-edited profile) must degrade to the default rather than to something
|
|
11799
|
+
* like `0`, which would poll continuously.
|
|
11800
|
+
*/
|
|
11801
|
+
const pollIntervalMs = (() => {
|
|
11802
|
+
const raw = deps.pollIntervalMs?.();
|
|
11803
|
+
return typeof raw === "number" && WORKBUDDY_POLL_INTERVALS_MS.includes(raw) ? raw : WORKBUDDY_DEFAULT_POLL_INTERVAL_MS;
|
|
11804
|
+
})();
|
|
11662
11805
|
const cliBridgeModel = deps.cliBridgeModel?.() ?? "";
|
|
11663
11806
|
const cliBridgeEffort = deps.cliBridgeEffort?.() ?? "";
|
|
11664
11807
|
const cliBridgeRegionOrder = deps.cliBridgeRegionOrder?.() ?? "";
|
|
@@ -11679,6 +11822,7 @@ async function workBuddyWebStatus(deps, region, options = {}) {
|
|
|
11679
11822
|
preferredVideoModels,
|
|
11680
11823
|
cliBridgeEnabled,
|
|
11681
11824
|
sidebarPanelEnabled,
|
|
11825
|
+
pollIntervalMs,
|
|
11682
11826
|
cliBridgeModel,
|
|
11683
11827
|
cliBridgeEffort,
|
|
11684
11828
|
cliBridgeRegionOrder,
|
|
@@ -11704,6 +11848,7 @@ async function workBuddyWebStatus(deps, region, options = {}) {
|
|
|
11704
11848
|
preferredVideoModels,
|
|
11705
11849
|
cliBridgeEnabled,
|
|
11706
11850
|
sidebarPanelEnabled,
|
|
11851
|
+
pollIntervalMs,
|
|
11707
11852
|
cliBridgeModel,
|
|
11708
11853
|
cliBridgeEffort,
|
|
11709
11854
|
cliBridgeRegionOrder,
|
|
@@ -11732,6 +11877,7 @@ async function workBuddyWebStatus(deps, region, options = {}) {
|
|
|
11732
11877
|
preferredVideoModels,
|
|
11733
11878
|
cliBridgeEnabled,
|
|
11734
11879
|
sidebarPanelEnabled,
|
|
11880
|
+
pollIntervalMs,
|
|
11735
11881
|
cliBridgeModel,
|
|
11736
11882
|
cliBridgeEffort,
|
|
11737
11883
|
cliBridgeRegionOrder,
|
|
@@ -12411,13 +12557,14 @@ function registerWorkBuddyStatusRoute(ctx, deps) {
|
|
|
12411
12557
|
if (answer.accounts.length === 0) return json(res, 409, { error: "none of the named accounts was found in this region" });
|
|
12412
12558
|
return jsonPrivate(res, 200, answer);
|
|
12413
12559
|
}
|
|
12414
|
-
const body = await readJsonBody(req);
|
|
12560
|
+
const body = await readJsonBody(req, TRANSFER_BODY_LIMIT);
|
|
12415
12561
|
if (typeof body.text !== "string" || body.text.trim() === "") return json(res, 400, { error: "text must be the transfer file's JSON content" });
|
|
12416
12562
|
if (action === "preview") return json(res, 200, await transfer.previewImport(region, body.text));
|
|
12417
12563
|
const indexes = Array.isArray(body.indexes) ? body.indexes.filter((value) => typeof value === "number" && Number.isInteger(value) && value >= 0) : [];
|
|
12418
12564
|
if (indexes.length === 0) return json(res, 400, { error: "indexes must name at least one file entry to import" });
|
|
12419
12565
|
return json(res, 200, await transfer.importAccounts(region, body.text, indexes));
|
|
12420
12566
|
} catch (error) {
|
|
12567
|
+
if (error instanceof JsonBodyTooLargeError) return json(res, 413, { error: safeMessage(error) });
|
|
12421
12568
|
json(res, 500, { error: safeMessage(error) });
|
|
12422
12569
|
}
|
|
12423
12570
|
}
|
|
@@ -12955,6 +13102,34 @@ const Config = z.object({
|
|
|
12955
13102
|
]).default("failure").description("When to perturb scanned messages with invisible characters: \"off\" only rescues after a channel-gate refusal, \"failure\" (default) learns from a successful rescue and starts later requests perturbed, \"always\" starts every request with the dense rescue for a gateway whose plain attempt is guaranteed to fail.")),
|
|
12956
13103
|
usageIdentity: asVolatile(z.boolean().default(false).description("Send the chat conversation ids in the official client's 32-hex UUIDv7 shape and add a mirroring X-Request-ID. Off by default — it is a display alignment measured by a reporter, not by this plugin, and the chat channel identity (User-Agent) and request body never change.")),
|
|
12957
13104
|
wireProfile: asVolatile(z.union([z.const("conservative"), z.const("balanced")]).default("balanced").description("Outbound identity profile. \"balanced\" (default) makes every request claim the same client (WorkBuddy product/IDE/agent headers, X-CodeBuddy-Request, Accept-Language, X-Root-Request-ID, and a per-account X-Machine-ID/X-Session-ID pair) and gives the billing routes a User-Agent plus Origin/Referer. \"conservative\" restores the 5.16.0 bytes exactly, including X-Product: SaaS.")),
|
|
13105
|
+
/**
|
|
13106
|
+
* How often the card re-reads the usage document.
|
|
13107
|
+
*
|
|
13108
|
+
* GLOBAL, not per-region: the card polls ONE region at a time (whichever tab
|
|
13109
|
+
* is open), so a per-region value would be a setting the user edits per tab
|
|
13110
|
+
* while only one of them is ever in effect. The composer account panel reads
|
|
13111
|
+
* the same number, which is what keeps the two surfaces from disagreeing
|
|
13112
|
+
* about one account — the complaint that fixed the panel at 60s in the first
|
|
13113
|
+
* place.
|
|
13114
|
+
*
|
|
13115
|
+
* A CLOSED SET of five values rather than a free number: this interval decides
|
|
13116
|
+
* the plugin's upstream request volume, and a typo'd `0` or a hand-written
|
|
13117
|
+
* `1000` would turn a display refresh into a poll the upstream could rate
|
|
13118
|
+
* limit. The same five are what the dropdown offers, so the control and its
|
|
13119
|
+
* validation cannot drift apart.
|
|
13120
|
+
*
|
|
13121
|
+
* WHY THE DEFAULT MOVED OFF 60s: one refresh reads a credits document AND a
|
|
13122
|
+
* check-in status per pooled account, so a 4-account pool at 60s is ~11,520
|
|
13123
|
+
* requests a day for figures that move slowly. 5 minutes is a fifth of that
|
|
13124
|
+
* and still far finer than the 30-minute auto check-in heartbeat.
|
|
13125
|
+
*/
|
|
13126
|
+
pollIntervalMs: asVolatile(z.union([
|
|
13127
|
+
z.const(6e4),
|
|
13128
|
+
z.const(3e5),
|
|
13129
|
+
z.const(6e5),
|
|
13130
|
+
z.const(18e5),
|
|
13131
|
+
z.const(36e5)
|
|
13132
|
+
]).default(3e5).description("How often the card refreshes its account table: 60000 (1 min), 300000 (5 min, default), 600000 (10 min), 1800000 (30 min) or 3600000 (60 min), in milliseconds. One refresh costs a credits read plus a check-in read per pooled account, so this is the setting that decides the plugin's upstream request volume. The composer account panel follows this value so the two surfaces cannot disagree about one account.")),
|
|
12958
13133
|
deviceSdkEnabled: asVolatile(z.boolean().default(false).description("Master switch for the real-device SDK. OFF by default, matching the default Virtual tier: turning it on makes the plugin discover the installed desktop SDK, fetch its device token in a background child process and keep it fresh. A capability that reaches into a third party's native modules on your machine should be opted into, and with the Virtual tier (the default) the token it fetches would never be sent anyway. On: discover, fetch, prewarm. Off: none of that — no discovery, no child process, no prewarming — so the Real tier has no token to send; the Virtual tier is unaffected (its ids derive from the local salt).")),
|
|
12959
13134
|
deviceToken: asVolatile(z.object({
|
|
12960
13135
|
file: z.string().default(""),
|
|
@@ -13264,6 +13439,11 @@ function apply(ctx, config) {
|
|
|
13264
13439
|
* Invalidated by this plugin's own check-in batch (the only writer that can
|
|
13265
13440
|
* change the answer during a session), so the user sees their result
|
|
13266
13441
|
* immediately instead of waiting out the TTL.
|
|
13442
|
+
*
|
|
13443
|
+
* A reading is ALSO bounded by the local day, not just by the TTL — see
|
|
13444
|
+
* `checkinReadingFresh`. Both readers go through it, because an entry is an
|
|
13445
|
+
* answer to "has this account checked in TODAY" and a `true` read at 23:58
|
|
13446
|
+
* must not be served at 00:08.
|
|
13267
13447
|
*/
|
|
13268
13448
|
const checkinStateCache = {};
|
|
13269
13449
|
/**
|
|
@@ -14152,6 +14332,11 @@ function apply(ctx, config) {
|
|
|
14152
14332
|
*/
|
|
14153
14333
|
sidebarPanelEnabled: () => unwrapVolatile(current().sidebarPanel) === true,
|
|
14154
14334
|
/**
|
|
14335
|
+
* The card's refresh cadence, read live so a change takes effect on the
|
|
14336
|
+
* next poll rather than on a plugin reload.
|
|
14337
|
+
*/
|
|
14338
|
+
pollIntervalMs: () => pollIntervalOf(current()),
|
|
14339
|
+
/**
|
|
14155
14340
|
* The model / reasoning effort the optional CodeBuddy CLI route runs on.
|
|
14156
14341
|
*
|
|
14157
14342
|
* `cliBridge` is volatile, hence the unwrap; absent keys read as `''` —
|
|
@@ -14357,7 +14542,7 @@ function apply(ctx, config) {
|
|
|
14357
14542
|
const now = Date.now();
|
|
14358
14543
|
const entries = await Promise.all(accounts.map(async (account) => {
|
|
14359
14544
|
const cached = checkinStateCache[region]?.[account.id];
|
|
14360
|
-
if (cached !== void 0 &&
|
|
14545
|
+
if (cached !== void 0 && checkinReadingFresh(cached.atMs, now, CHECKIN_CACHE_MS)) return [account.id, cached.checkedIn];
|
|
14361
14546
|
const credential = await store.credentialFor(account.id).catch(() => void 0);
|
|
14362
14547
|
if (credential === void 0) return void 0;
|
|
14363
14548
|
const status = await client.fetchCheckinStatus(credential).catch(() => void 0);
|
|
@@ -14387,7 +14572,7 @@ function apply(ctx, config) {
|
|
|
14387
14572
|
const state = checkinStateCache[region] ?? {};
|
|
14388
14573
|
const cached = {};
|
|
14389
14574
|
for (const [accountId, entry] of Object.entries(state)) {
|
|
14390
|
-
if (
|
|
14575
|
+
if (!checkinReadingFresh(entry.atMs, now, CHECKIN_CACHE_MS)) continue;
|
|
14391
14576
|
cached[accountId] = entry.checkedIn;
|
|
14392
14577
|
}
|
|
14393
14578
|
return cached;
|
|
@@ -14488,7 +14673,7 @@ function apply(ctx, config) {
|
|
|
14488
14673
|
if (!autoCheckinEnabled(region)) return void 0;
|
|
14489
14674
|
const state = autoCheckinState[region];
|
|
14490
14675
|
if (state === void 0) return void 0;
|
|
14491
|
-
return
|
|
14676
|
+
return todaySummary(state, Date.now());
|
|
14492
14677
|
},
|
|
14493
14678
|
checkin: async (region) => {
|
|
14494
14679
|
const rows = await checkinAllAccounts(await poolTargets(region), poolRunnerDeps(region));
|
|
@@ -14980,6 +15165,20 @@ function apply(ctx, config) {
|
|
|
14980
15165
|
* upgrade moves nothing on screen.
|
|
14981
15166
|
*/
|
|
14982
15167
|
const creditPositionOf = (config, region) => regionStateOf(config, region).creditPosition === "stats" ? "stats" : "composer";
|
|
15168
|
+
/**
|
|
15169
|
+
* The card's refresh interval, coerced against the offered set.
|
|
15170
|
+
*
|
|
15171
|
+
* Coerced HERE rather than trusted from the config, for the same reason
|
|
15172
|
+
* `resolveProbeInputTokens` coerces its own: a hand-edited `cordis.patch.yml`
|
|
15173
|
+
* can carry any number, and `setInterval(…, 0)` would turn a display refresh
|
|
15174
|
+
* into a busy loop against the upstream. An unrecognized value falls back to
|
|
15175
|
+
* the default rather than to the smallest step — the safe direction for a
|
|
15176
|
+
* setting whose whole purpose is bounding request volume.
|
|
15177
|
+
*/
|
|
15178
|
+
const pollIntervalOf = (config) => {
|
|
15179
|
+
const raw = unwrapVolatile(config.pollIntervalMs);
|
|
15180
|
+
return typeof raw === "number" && WORKBUDDY_POLL_INTERVALS_MS.includes(raw) ? raw : WORKBUDDY_DEFAULT_POLL_INTERVAL_MS;
|
|
15181
|
+
};
|
|
14983
15182
|
const poolPreferencesOf = (config, region) => {
|
|
14984
15183
|
const pool = regionStateOf(config, region).pool;
|
|
14985
15184
|
const probeInputTokens = pool?.probeInputTokens;
|
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.21.2",
|
|
6
6
|
"author": "dingminhua",
|
|
7
7
|
"copyright": "Copyright (c) 2026 LaoDing",
|
|
8
8
|
"license": "MIT",
|