dsh-workbuddy-bridge 0.5.9 → 0.5.11
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 +2 -0
- package/README_en.md +2 -0
- package/lib/bin.js +1 -1
- package/lib/{heartbeat-36zt0_g0.js → heartbeat-BE0IAXli.js} +85 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +752 -745
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,6 +128,8 @@ WorkBuddy 接口不保证档位信息可靠——有的模型**接受** `reasoni
|
|
|
128
128
|
|
|
129
129
|
## 兼容与限制
|
|
130
130
|
|
|
131
|
+
国内版和国际版的 `hy4std`、`hy4flash`、`hy4flash-free` 默认按 DSH 会话复用提示词缓存标识。排障时,在启动宿主前设置 `WORKBUDDY_HY4_CACHE_AFFINITY=0` 可关闭此行为。
|
|
132
|
+
|
|
131
133
|
无凭据的分组不显示。宿主版本下限、平台支持、模型清单从哪来与已知缺口
|
|
132
134
|
→ [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md)。
|
|
133
135
|
|
package/README_en.md
CHANGED
|
@@ -141,6 +141,8 @@ Mechanism and trade-offs in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
|
141
141
|
|
|
142
142
|
## Compatibility and limits
|
|
143
143
|
|
|
144
|
+
The bridge reuses a prompt cache identifier per DSH session for `hy4std`, `hy4flash`, and `hy4flash-free` in both CN and Global. To disable this behavior, set `WORKBUDDY_HY4_CACHE_AFFINITY=0` before starting the host.
|
|
145
|
+
|
|
144
146
|
A group without credentials does not appear. The host version floor, platform support, where the model
|
|
145
147
|
catalog comes from and known gaps
|
|
146
148
|
→ [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md).
|
package/lib/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as variantFor, D as WorkBuddyUpstreamClient,
|
|
2
|
+
import { C as variantFor, D as WorkBuddyUpstreamClient, S as WORKBUDDY_VARIANTS, a as readHostHeartbeat, c as WORKBUDDY_BRIDGE_VERSION, et as resolveAppVersion, l as FALLBACK_WORKBUDDY_AI_MODELS, m as WorkBuddyCredentialStore, o as workbuddyHostHeartbeatPath, r as isHeartbeatProcessAlive, u as FALLBACK_WORKBUDDY_MODELS, x as CN_VARIANT } from "./heartbeat-BE0IAXli.js";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
//#region src/cli/bin.ts
|
|
@@ -6,7 +6,7 @@ import { withFileLock, writeFileAtomic } from "@deepseek-ai/dsh-atomic-write";
|
|
|
6
6
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
7
7
|
import { createDecipheriv, createHash, randomBytes } from "node:crypto";
|
|
8
8
|
import { execFile, execFileSync } from "node:child_process";
|
|
9
|
-
import { accessSync, constants, realpathSync, statSync } from "node:fs";
|
|
9
|
+
import { accessSync, constants, readdirSync, realpathSync, statSync } from "node:fs";
|
|
10
10
|
//#region src/protocol/app-version.ts
|
|
11
11
|
/**
|
|
12
12
|
* The international desktop app's version, used as the `/v3/config` UA.
|
|
@@ -961,20 +961,45 @@ function billingHeaders(credential) {
|
|
|
961
961
|
* international-only scope decision, which rested on CN accepting it).
|
|
962
962
|
*/
|
|
963
963
|
function prepareChatBody(source) {
|
|
964
|
+
return prepareChatRequest(source).body;
|
|
965
|
+
}
|
|
966
|
+
/** Read the model during normalization so long transcripts need no extra JSON pass. */
|
|
967
|
+
function prepareChatRequest(source) {
|
|
964
968
|
let body;
|
|
965
969
|
try {
|
|
966
970
|
body = JSON.parse(source);
|
|
967
971
|
} catch {
|
|
968
|
-
return source;
|
|
972
|
+
return { body: source };
|
|
969
973
|
}
|
|
970
|
-
if (typeof body !== "object" || body === null || Array.isArray(body)) return source;
|
|
974
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return { body: source };
|
|
971
975
|
const obj = body;
|
|
972
976
|
obj["stream"] = true;
|
|
973
977
|
normalizeDeveloperRole(obj);
|
|
974
978
|
neutralizeChannelSignature(obj);
|
|
975
979
|
normalizeToolChoice(obj);
|
|
976
980
|
dropUnsupportedEffort(obj);
|
|
977
|
-
return
|
|
981
|
+
return {
|
|
982
|
+
body: JSON.stringify(obj),
|
|
983
|
+
...typeof obj["model"] === "string" ? { model: obj["model"] } : {}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
/** Scope cache affinity to the account actually sending the request and the tested models (#47). */
|
|
987
|
+
function cacheConversationId(credential, model, sessionId) {
|
|
988
|
+
if (process.env["WORKBUDDY_HY4_CACHE_AFFINITY"] === "0" || typeof sessionId !== "string" || sessionId.trim() === "" || credential.uid === "") return void 0;
|
|
989
|
+
const region = regionOf(credential.domain);
|
|
990
|
+
if (model !== "hy4flash" && model !== "hy4flash-free" && model !== "hy4std") return void 0;
|
|
991
|
+
const scope = [
|
|
992
|
+
region,
|
|
993
|
+
credential.uid,
|
|
994
|
+
credential.enterpriseId ?? "",
|
|
995
|
+
model,
|
|
996
|
+
sessionId
|
|
997
|
+
];
|
|
998
|
+
const bytes = createHash("sha256").update(JSON.stringify(scope)).digest();
|
|
999
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1000
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1001
|
+
const hex = bytes.subarray(0, 16).toString("hex");
|
|
1002
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
978
1003
|
}
|
|
979
1004
|
/**
|
|
980
1005
|
* Strip the product-identity phrase the CN gateway reads as an unofficial
|
|
@@ -1351,7 +1376,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
1351
1376
|
* Normalization is idempotent, so a caller that already prepared the body
|
|
1352
1377
|
* (the shim does) sees no second change.
|
|
1353
1378
|
*/
|
|
1354
|
-
async chatStream(credential, bodyJson, signal) {
|
|
1379
|
+
async chatStream(credential, bodyJson, signal, conversationId) {
|
|
1355
1380
|
const region = regionOf(credential.domain);
|
|
1356
1381
|
let userAgent;
|
|
1357
1382
|
try {
|
|
@@ -1363,6 +1388,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
1363
1388
|
const url = `${chatBase(credential)}/v2/chat/completions`;
|
|
1364
1389
|
const headers = {
|
|
1365
1390
|
...chatHeaders(credential, userAgent),
|
|
1391
|
+
...conversationId === void 0 ? {} : { "X-Conversation-ID": conversationId },
|
|
1366
1392
|
Authorization: `Bearer ${credential.accessToken}`
|
|
1367
1393
|
};
|
|
1368
1394
|
try {
|
|
@@ -2098,6 +2124,56 @@ const WINDOWS_LOCAL_PROGRAM_SUFFIX = {
|
|
|
2098
2124
|
]
|
|
2099
2125
|
};
|
|
2100
2126
|
/**
|
|
2127
|
+
* The directory a staged Windows install keeps its per-version runtimes in.
|
|
2128
|
+
*
|
|
2129
|
+
* WorkBuddy 5.12 replaced the single-binary layout with a staged one: the
|
|
2130
|
+
* documented path now holds a small activation launcher, and each installed
|
|
2131
|
+
* version's runtime lives under `<root>\versions\<version>\` (verified against
|
|
2132
|
+
* CN 5.12.1, where `<root>\WorkBuddy.exe` is 544 KB and the runtime beside it
|
|
2133
|
+
* is 195 MB). The launcher only prints activation lines and never runs `-e`,
|
|
2134
|
+
* so the key helper must spawn the staged runtime instead.
|
|
2135
|
+
*/
|
|
2136
|
+
const WINDOWS_STAGED_DIRECTORY = "versions";
|
|
2137
|
+
/** The runtime filename inside a staged version directory, keyed by product. */
|
|
2138
|
+
const WINDOWS_STAGED_APP_FILENAME = {
|
|
2139
|
+
cn: "WorkBuddy-app.exe",
|
|
2140
|
+
ai: "WorkBuddyAI-app.exe"
|
|
2141
|
+
};
|
|
2142
|
+
/**
|
|
2143
|
+
* The newest usable runtime of a staged Windows install, or `undefined`.
|
|
2144
|
+
*
|
|
2145
|
+
* Version directory names are compared numerically so `5.12.10` outranks
|
|
2146
|
+
* `5.12.9`; an unparsable name is skipped rather than guessed at. Choosing the
|
|
2147
|
+
* newest matters because an upgrade leaves the previous version directory
|
|
2148
|
+
* behind, and an older runtime may predate the staged layout entirely.
|
|
2149
|
+
*/
|
|
2150
|
+
function stagedWindowsRuntime(root, product) {
|
|
2151
|
+
const stagedRoot = join(root, WINDOWS_STAGED_DIRECTORY);
|
|
2152
|
+
let names;
|
|
2153
|
+
try {
|
|
2154
|
+
names = readdirSync(stagedRoot);
|
|
2155
|
+
} catch {
|
|
2156
|
+
return;
|
|
2157
|
+
}
|
|
2158
|
+
const ranked = names.map((name) => ({
|
|
2159
|
+
name,
|
|
2160
|
+
segments: name.split(".").map((part) => Number.parseInt(part, 10))
|
|
2161
|
+
})).filter(({ segments }) => segments.length > 0 && segments.every((segment) => Number.isFinite(segment))).sort((left, right) => compareVersionSegments(right.segments, left.segments));
|
|
2162
|
+
for (const { name } of ranked) {
|
|
2163
|
+
const candidate = join(stagedRoot, name, WINDOWS_STAGED_APP_FILENAME[product]);
|
|
2164
|
+
if (isExecutable(candidate)) return candidate;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
/** Compare dotted version segments numerically, padding the shorter side with 0. */
|
|
2168
|
+
function compareVersionSegments(left, right) {
|
|
2169
|
+
const length = Math.max(left.length, right.length);
|
|
2170
|
+
for (let index = 0; index < length; index += 1) {
|
|
2171
|
+
const difference = (left[index] ?? 0) - (right[index] ?? 0);
|
|
2172
|
+
if (difference !== 0) return difference;
|
|
2173
|
+
}
|
|
2174
|
+
return 0;
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2101
2177
|
* The Electron binary one discovery strategy expects at its default location, or
|
|
2102
2178
|
* `undefined` where that strategy has no verified layout on this platform.
|
|
2103
2179
|
*
|
|
@@ -2673,7 +2749,7 @@ function workBuddyDiscoveryTools() {
|
|
|
2673
2749
|
return this.explicitPath;
|
|
2674
2750
|
}
|
|
2675
2751
|
if (this.discovery === "none") throw new WorkBuddyElectronPathError("electron-binary-unavailable", `no WorkBuddy Electron binary is configured for this platform; set ${WORKBUDDY_ELECTRON_BIN_ENV} to the app's Electron binary`);
|
|
2676
|
-
if (this.defaultPath !== void 0 && isExecutable(this.defaultPath)) return this.defaultPath;
|
|
2752
|
+
if (this.defaultPath !== void 0 && isExecutable(this.defaultPath)) return (this.discovery === "windows-workbuddy" ? stagedWindowsRuntime(dirname(this.defaultPath), this.product) : void 0) ?? this.defaultPath;
|
|
2677
2753
|
if (this.discoveredPath !== void 0) {
|
|
2678
2754
|
if (isExecutable(this.discoveredPath)) return this.discoveredPath;
|
|
2679
2755
|
this.discoveredPath = void 0;
|
|
@@ -2781,7 +2857,7 @@ function workBuddyDiscoveryTools() {
|
|
|
2781
2857
|
}
|
|
2782
2858
|
const seen = /* @__PURE__ */ new Map();
|
|
2783
2859
|
for (const root of roots) {
|
|
2784
|
-
const electronPath = join(root, WINDOWS_ELECTRON_FILENAME[this.product]);
|
|
2860
|
+
const electronPath = stagedWindowsRuntime(root, this.product) ?? join(root, WINDOWS_ELECTRON_FILENAME[this.product]);
|
|
2785
2861
|
if (!isExecutable(electronPath)) continue;
|
|
2786
2862
|
let identity;
|
|
2787
2863
|
try {
|
|
@@ -4233,7 +4309,7 @@ var WorkBuddyCatalog = class {
|
|
|
4233
4309
|
};
|
|
4234
4310
|
//#endregion
|
|
4235
4311
|
//#region src/version.ts
|
|
4236
|
-
const WORKBUDDY_BRIDGE_VERSION = "0.5.
|
|
4312
|
+
const WORKBUDDY_BRIDGE_VERSION = "0.5.11";
|
|
4237
4313
|
//#endregion
|
|
4238
4314
|
//#region src/web/heartbeat.ts
|
|
4239
4315
|
/**
|
|
@@ -4404,4 +4480,4 @@ function isHeartbeatProcessAlive(heartbeat) {
|
|
|
4404
4480
|
return startAtMs <= heartbeat.registeredAt;
|
|
4405
4481
|
}
|
|
4406
4482
|
//#endregion
|
|
4407
|
-
export {
|
|
4483
|
+
export { readBundleVersion as $, isPlanLimitBody as A, randomSentinel as B, variantFor as C, WorkBuddyUpstreamClient as D, WORKBUDDY_STATUS_PATH as E, prepareChatRequest as F, chatUserAgent as G, upstreamDisplayMessage as H, prepareInternationalChatBody as I, resolveChatIdentity as J, fallbackChatIdentity as K, regionOf as L, normalizeCredits as M, parseModelCatalog as N, cacheConversationId as O, prepareChatBody as P, installedAppVersion as Q, PROBE_EFFORT_CANDIDATES as R, WORKBUDDY_VARIANTS as S, WORKBUDDY_PROBE_PATH as T, CN_APP_VERSION_FILENAME as U, classifyUpstreamError as V, FALLBACK_CN_APP_VERSION as W, WORKBUDDY_APP_VERSION_FILENAME as X, validCliVersion as Y, appUserAgent as Z, desktopAuthCandidatesFor as _, readHostHeartbeat as a, AI_VARIANT as b, WORKBUDDY_BRIDGE_VERSION as c, WorkBuddyCatalog as d, resolveAppVersion as et, WORKBUDDY_AUTH_FILENAME as f, defaultDesktopAuthPath as g, defaultDesktopAuthCandidates as h, processStartTimeMs as i, modelWithCurrentPromotion as j, isChannelGateBody as k, FALLBACK_WORKBUDDY_AI_MODELS as l, WorkBuddyCredentialStore as m, clearHostHeartbeat as n, workbuddyHostHeartbeatPath as o, WORKBUDDY_AUTH_FILE_ENV as p, readCliVersion as q, isHeartbeatProcessAlive as r, writeHostHeartbeat as s, WORKBUDDY_HOST_HEARTBEAT_FILENAME as t, validAppVersion as tt, FALLBACK_WORKBUDDY_MODELS as u, parseWorkBuddyAuth as v, WORKBUDDY_CREDIT_PATH as w, CN_VARIANT as x, workbuddyOwnAuthPath as y, probeModel as z };
|
package/lib/index.d.ts
CHANGED
|
@@ -763,7 +763,7 @@ declare class WorkBuddyUpstreamClient {
|
|
|
763
763
|
* Normalization is idempotent, so a caller that already prepared the body
|
|
764
764
|
* (the shim does) sees no second change.
|
|
765
765
|
*/
|
|
766
|
-
chatStream(credential: WorkBuddyCredential, bodyJson: string, signal?: AbortSignal): Promise<WorkBuddyChatResult>;
|
|
766
|
+
chatStream(credential: WorkBuddyCredential, bodyJson: string, signal?: AbortSignal, conversationId?: string): Promise<WorkBuddyChatResult>;
|
|
767
767
|
/** POST the token-refresh endpoint; the caller merges the outcome. */
|
|
768
768
|
refreshToken(credential: WorkBuddyCredential): Promise<WorkBuddyRefreshOutcome>;
|
|
769
769
|
/**
|