dsh-workbuddy-bridge 0.5.9 → 0.5.10
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-DN0dHD6J.js} +32 -6
- 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-DN0dHD6J.js";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
//#region src/cli/bin.ts
|
|
@@ -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 {
|
|
@@ -4233,7 +4259,7 @@ var WorkBuddyCatalog = class {
|
|
|
4233
4259
|
};
|
|
4234
4260
|
//#endregion
|
|
4235
4261
|
//#region src/version.ts
|
|
4236
|
-
const WORKBUDDY_BRIDGE_VERSION = "0.5.
|
|
4262
|
+
const WORKBUDDY_BRIDGE_VERSION = "0.5.10";
|
|
4237
4263
|
//#endregion
|
|
4238
4264
|
//#region src/web/heartbeat.ts
|
|
4239
4265
|
/**
|
|
@@ -4404,4 +4430,4 @@ function isHeartbeatProcessAlive(heartbeat) {
|
|
|
4404
4430
|
return startAtMs <= heartbeat.registeredAt;
|
|
4405
4431
|
}
|
|
4406
4432
|
//#endregion
|
|
4407
|
-
export {
|
|
4433
|
+
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
|
/**
|