dsh-workbuddy-bridge 0.5.8 → 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-CaRoYefq.js → heartbeat-DN0dHD6J.js} +136 -42
- package/lib/index.d.ts +38 -3
- package/lib/index.js +752 -745
- package/package.json +51 -48
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 {
|
|
@@ -2070,25 +2096,33 @@ const WORKBUDDY_ELECTRON_BIN_ENV = "WORKBUDDY_ELECTRON_BIN";
|
|
|
2070
2096
|
/** Platform-default Electron binary, confirmed only on macOS (5.6.2). */
|
|
2071
2097
|
const MACOS_ELECTRON_PATH = "/Applications/WorkBuddy.app/Contents/MacOS/Electron";
|
|
2072
2098
|
/**
|
|
2073
|
-
* The
|
|
2099
|
+
* The Electron runtime each Windows installer ships, keyed by product.
|
|
2074
2100
|
*
|
|
2075
|
-
*
|
|
2076
|
-
*
|
|
2077
|
-
*
|
|
2078
|
-
* helper relies on).
|
|
2101
|
+
* Both are the runtime itself — there is no `Electron.exe`, and the launcher is
|
|
2102
|
+
* the runtime (it honours `ELECTRON_RUN_AS_NODE`, which is what the key helper
|
|
2103
|
+
* relies on).
|
|
2079
2104
|
*
|
|
2080
|
-
* The
|
|
2081
|
-
*
|
|
2082
|
-
*
|
|
2105
|
+
* The Global app is `WorkBuddyAI.exe` inside `Programs\\WorkBuddyAI` — no space,
|
|
2106
|
+
* and *not* `Programs\\WorkBuddy`, which is the CN layout. Verified against
|
|
2107
|
+
* WorkBuddy AI 5.11.4; the CN name is the 5.6.2 one.
|
|
2083
2108
|
*/
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2109
|
+
const WINDOWS_ELECTRON_FILENAME = {
|
|
2110
|
+
cn: "WorkBuddy.exe",
|
|
2111
|
+
ai: "WorkBuddyAI.exe"
|
|
2112
|
+
};
|
|
2113
|
+
/** Where each Windows installer puts the app unless the user picks another drive. */
|
|
2114
|
+
const WINDOWS_LOCAL_PROGRAM_SUFFIX = {
|
|
2115
|
+
cn: [
|
|
2116
|
+
"Programs",
|
|
2117
|
+
"WorkBuddy",
|
|
2118
|
+
"WorkBuddy.exe"
|
|
2119
|
+
],
|
|
2120
|
+
ai: [
|
|
2121
|
+
"Programs",
|
|
2122
|
+
"WorkBuddyAI",
|
|
2123
|
+
"WorkBuddyAI.exe"
|
|
2124
|
+
]
|
|
2125
|
+
};
|
|
2092
2126
|
/**
|
|
2093
2127
|
* The Electron binary one discovery strategy expects at its default location, or
|
|
2094
2128
|
* `undefined` where that strategy has no verified layout on this platform.
|
|
@@ -2103,11 +2137,11 @@ const WINDOWS_LOCAL_PROGRAM_SUFFIX = [
|
|
|
2103
2137
|
* {@link WORKBUDDY_ELECTRON_BIN_ENV} explicitly — guessing would spawn the wrong
|
|
2104
2138
|
* app's binary.
|
|
2105
2139
|
*/
|
|
2106
|
-
function defaultWorkBuddyElectronPath(discovery = "none") {
|
|
2140
|
+
function defaultWorkBuddyElectronPath(discovery = "none", product = "cn") {
|
|
2107
2141
|
if (discovery === "macos-workbuddy" && process.platform === "darwin") return MACOS_ELECTRON_PATH;
|
|
2108
2142
|
if (discovery === "windows-workbuddy" && process.platform === "win32") {
|
|
2109
2143
|
const localAppData = process.env["LOCALAPPDATA"]?.trim();
|
|
2110
|
-
if (localAppData !== void 0 && localAppData !== "") return join(localAppData, ...WINDOWS_LOCAL_PROGRAM_SUFFIX);
|
|
2144
|
+
if (localAppData !== void 0 && localAppData !== "") return join(localAppData, ...WINDOWS_LOCAL_PROGRAM_SUFFIX[product]);
|
|
2111
2145
|
}
|
|
2112
2146
|
}
|
|
2113
2147
|
/** Distinct key ids across the wrapped fields, in field order. */
|
|
@@ -2302,6 +2336,21 @@ function cnAppDiscovery() {
|
|
|
2302
2336
|
if (process.platform === "win32") return "windows-workbuddy";
|
|
2303
2337
|
return "none";
|
|
2304
2338
|
}
|
|
2339
|
+
/**
|
|
2340
|
+
* The strategy the Global (WorkBuddy AI) app may use on this platform.
|
|
2341
|
+
*
|
|
2342
|
+
* Windows only, and deliberately narrower than {@link cnAppDiscovery}: the
|
|
2343
|
+
* Uninstall registration names the product, so a Global search can prove it is
|
|
2344
|
+
* looking at the Global install instead of borrowing the CN one. The macOS
|
|
2345
|
+
* lookup is a Spotlight search for the *CN* bundle id, which has no verified
|
|
2346
|
+
* Global counterpart — a Global provider keeps `'none'` there rather than
|
|
2347
|
+
* executing the other product's binary. An explicit `WORKBUDDY_ELECTRON_BIN`
|
|
2348
|
+
* still works on every platform.
|
|
2349
|
+
*/
|
|
2350
|
+
function aiAppDiscovery() {
|
|
2351
|
+
if (process.platform === "win32") return "windows-workbuddy";
|
|
2352
|
+
return "none";
|
|
2353
|
+
}
|
|
2305
2354
|
/** The CN app's bundle id; the only one this round resolves by discovery. */
|
|
2306
2355
|
const WORKBUDDY_CN_BUNDLE_ID = "com.tencent.workbuddy.mac";
|
|
2307
2356
|
/** Absolute tool paths: never resolved through PATH, which a user can change. */
|
|
@@ -2329,6 +2378,25 @@ const WINDOWS_UNINSTALL_HIVES = [
|
|
|
2329
2378
|
/** Three hives' worth of matching entries is far smaller than this. */
|
|
2330
2379
|
const WINDOWS_REGISTRY_MAX_OUTPUT_BYTES = 262144;
|
|
2331
2380
|
/**
|
|
2381
|
+
* Whether a registration's `DisplayName` belongs to the product being searched.
|
|
2382
|
+
*
|
|
2383
|
+
* The two products register as `WorkBuddy <version>` and `WorkBuddy AI <version>`
|
|
2384
|
+
* on the same machine, so the CN prefix match would also accept the Global entry
|
|
2385
|
+
* — and then `join(root, 'WorkBuddy.exe')` would simply miss, turning a
|
|
2386
|
+
* *decidable* "wrong product" into a misleading "not installed". Matching the
|
|
2387
|
+
* product exactly keeps each variant's answer about its own app.
|
|
2388
|
+
*
|
|
2389
|
+
* A name that carries a trailing qualifier is not the app: "WorkBuddy AI Helper"
|
|
2390
|
+
* and "WorkBuddyUninstall" both fail the version/end boundary, so a component of
|
|
2391
|
+
* the product can never be read as the product itself.
|
|
2392
|
+
*/
|
|
2393
|
+
function matchesProduct(displayName, product) {
|
|
2394
|
+
const appName = product === "ai" ? "WorkBuddy AI" : "WorkBuddy";
|
|
2395
|
+
if (!displayName.startsWith(appName)) return false;
|
|
2396
|
+
const rest = displayName.slice(appName.length);
|
|
2397
|
+
return rest === "" || /^\s+\d/u.test(rest);
|
|
2398
|
+
}
|
|
2399
|
+
/**
|
|
2332
2400
|
* Install directories named by one `reg query` dump, in listing order.
|
|
2333
2401
|
*
|
|
2334
2402
|
* `reg query <hive> /s /f WorkBuddy` prints one block per matching key: a
|
|
@@ -2346,13 +2414,13 @@ const WINDOWS_REGISTRY_MAX_OUTPUT_BYTES = 262144;
|
|
|
2346
2414
|
* Exported for tests: the flow's whole decision surface is here, so it can be
|
|
2347
2415
|
* exercised without running `reg.exe`.
|
|
2348
2416
|
*/
|
|
2349
|
-
function windowsInstallsFromRegistry(output) {
|
|
2417
|
+
function windowsInstallsFromRegistry(output, product = "cn") {
|
|
2350
2418
|
const roots = [];
|
|
2351
2419
|
let name;
|
|
2352
2420
|
let icon;
|
|
2353
2421
|
let location;
|
|
2354
2422
|
const flush = () => {
|
|
2355
|
-
if (name !== void 0 &&
|
|
2423
|
+
if (name !== void 0 && matchesProduct(name, product)) {
|
|
2356
2424
|
const root = iconRootOf(icon) ?? locationRootOf(location);
|
|
2357
2425
|
if (root !== void 0 && !roots.includes(root)) roots.push(root);
|
|
2358
2426
|
}
|
|
@@ -2422,7 +2490,7 @@ function locationRootOf(value) {
|
|
|
2422
2490
|
* read as "not installed". A hive that simply holds no WorkBuddy entry is a
|
|
2423
2491
|
* normal empty result: `reg` reports that with exit code 1 and empty stdout.
|
|
2424
2492
|
*/
|
|
2425
|
-
function workBuddyWindowsDiscoveryTools() {
|
|
2493
|
+
function workBuddyWindowsDiscoveryTools(product = "cn") {
|
|
2426
2494
|
return { findInstallRoots: async (signal) => {
|
|
2427
2495
|
const found = [];
|
|
2428
2496
|
for (const hive of WINDOWS_UNINSTALL_HIVES) {
|
|
@@ -2450,7 +2518,7 @@ function workBuddyWindowsDiscoveryTools() {
|
|
|
2450
2518
|
reject(new DiscoveryIncompleteError(`the Windows registry query for ${hive} could not complete (${error.killed === true ? "timed out" : String(error.code)})`));
|
|
2451
2519
|
});
|
|
2452
2520
|
});
|
|
2453
|
-
found.push(...windowsInstallsFromRegistry(output));
|
|
2521
|
+
found.push(...windowsInstallsFromRegistry(output, product));
|
|
2454
2522
|
}
|
|
2455
2523
|
return found;
|
|
2456
2524
|
} };
|
|
@@ -2540,6 +2608,7 @@ function workBuddyDiscoveryTools() {
|
|
|
2540
2608
|
explicitPath;
|
|
2541
2609
|
defaultPath;
|
|
2542
2610
|
discovery;
|
|
2611
|
+
product;
|
|
2543
2612
|
tools;
|
|
2544
2613
|
/** Explicit `tools` means the caller owns the platform question (tests, custom hosts). */
|
|
2545
2614
|
toolsAreInjected;
|
|
@@ -2563,10 +2632,11 @@ function workBuddyDiscoveryTools() {
|
|
|
2563
2632
|
const envPath = fromEnv === void 0 || fromEnv === "" ? void 0 : fromEnv;
|
|
2564
2633
|
this.explicitPath = options.electronPath ?? envPath;
|
|
2565
2634
|
this.discovery = options.discovery ?? "none";
|
|
2566
|
-
this.
|
|
2635
|
+
this.product = options.product ?? "cn";
|
|
2636
|
+
this.defaultPath = options.defaultElectronPath === void 0 ? defaultWorkBuddyElectronPath(this.discovery, this.product) : options.defaultElectronPath ?? void 0;
|
|
2567
2637
|
this.tools = options.tools ?? workBuddyDiscoveryTools();
|
|
2568
2638
|
this.toolsAreInjected = options.tools !== void 0;
|
|
2569
|
-
this.windowsTools = options.windowsTools ?? workBuddyWindowsDiscoveryTools();
|
|
2639
|
+
this.windowsTools = options.windowsTools ?? workBuddyWindowsDiscoveryTools(this.product);
|
|
2570
2640
|
this.windowsToolsAreInjected = options.windowsTools !== void 0;
|
|
2571
2641
|
this.discoveryBudgetMs = options.discoveryBudgetMs ?? 1e4;
|
|
2572
2642
|
this.timeoutMs = options.timeoutMs ?? 1e4;
|
|
@@ -2710,14 +2780,19 @@ function workBuddyDiscoveryTools() {
|
|
|
2710
2780
|
}
|
|
2711
2781
|
}
|
|
2712
2782
|
/**
|
|
2713
|
-
* Resolve
|
|
2783
|
+
* Resolve this provider's product from its Windows registration.
|
|
2714
2784
|
*
|
|
2715
2785
|
* There is no second identity check as on macOS: the registration *is* the
|
|
2716
2786
|
* identity — {@link windowsInstallsFromRegistry} only accepts blocks whose
|
|
2717
|
-
* `DisplayName`
|
|
2787
|
+
* `DisplayName` names this product — and the executable is a fixed name
|
|
2718
2788
|
* inside the registered directory. A registered directory that no longer holds
|
|
2719
2789
|
* an executable is a decidable exclusion, the same way a Spotlight row for a
|
|
2720
2790
|
* deleted app is.
|
|
2791
|
+
*
|
|
2792
|
+
* Both products may be installed side by side and register under the same
|
|
2793
|
+
* `WorkBuddy` stem, so the registry query results are filtered by product
|
|
2794
|
+
* before the executable is looked for: otherwise the Global app's directory
|
|
2795
|
+
* would be probed for a CN executable and read as "not installed".
|
|
2721
2796
|
*/
|
|
2722
2797
|
async discoverWindowsApp() {
|
|
2723
2798
|
if (process.platform !== "win32" && !this.windowsToolsAreInjected) 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`);
|
|
@@ -2732,7 +2807,7 @@ function workBuddyDiscoveryTools() {
|
|
|
2732
2807
|
}
|
|
2733
2808
|
const seen = /* @__PURE__ */ new Map();
|
|
2734
2809
|
for (const root of roots) {
|
|
2735
|
-
const electronPath = join(root, WINDOWS_ELECTRON_FILENAME);
|
|
2810
|
+
const electronPath = join(root, WINDOWS_ELECTRON_FILENAME[this.product]);
|
|
2736
2811
|
if (!isExecutable(electronPath)) continue;
|
|
2737
2812
|
let identity;
|
|
2738
2813
|
try {
|
|
@@ -3118,24 +3193,40 @@ function isENOENT(error) {
|
|
|
3118
3193
|
* (2026-10-03, found by the release checklist). The store knows its variant, so
|
|
3119
3194
|
* the choice belongs here.
|
|
3120
3195
|
*
|
|
3121
|
-
* Why the
|
|
3196
|
+
* Why the two products are treated differently:
|
|
3122
3197
|
*
|
|
3123
|
-
* -
|
|
3124
|
-
*
|
|
3125
|
-
* -
|
|
3126
|
-
*
|
|
3127
|
-
*
|
|
3128
|
-
*
|
|
3198
|
+
* - CN may use every verified strategy: its macOS bundle id and its Windows
|
|
3199
|
+
* Uninstall registration are both known.
|
|
3200
|
+
* - Global (WorkBuddy AI) gets `aiAppDiscovery()`: Windows only, because the
|
|
3201
|
+
* Uninstall registration names the product and can therefore prove it found
|
|
3202
|
+
* the Global install. Its credential *is* the same encrypted-envelope format —
|
|
3203
|
+
* verified against WorkBuddy AI 5.11.4, whose envelopes name the same key id
|
|
3204
|
+
* the CN install resolves to — so it must be openable, but the search must
|
|
3205
|
+
* still be answerable per product. The macOS Spotlight lookup is a CN bundle-id
|
|
3206
|
+
* search with no verified Global counterpart, so it stays `'none'` there: a
|
|
3207
|
+
* Global unlock must not silently execute the *CN* app's Electron.
|
|
3129
3208
|
*
|
|
3130
3209
|
* **No variant** means the CN product's own default file —
|
|
3131
3210
|
* `defaultDesktopAuthCandidates()` is the `workbuddy-desktop.info` path, never the
|
|
3132
3211
|
* AI one — so it gets the same discovery CN does.
|
|
3133
3212
|
*
|
|
3213
|
+
* An explicit `WORKBUDDY_ELECTRON_BIN` still overrides every strategy.
|
|
3214
|
+
*
|
|
3134
3215
|
* A keyId mismatch is still reported as a diagnosis rather than a wrong open, and
|
|
3135
3216
|
* the helper only runs if an encrypted credential is actually read.
|
|
3136
3217
|
*/
|
|
3137
3218
|
function atRestDiscoveryFor(variant) {
|
|
3138
|
-
|
|
3219
|
+
if (variant === void 0 || variant.id === CN_VARIANT.id) return cnAppDiscovery();
|
|
3220
|
+
return aiAppDiscovery();
|
|
3221
|
+
}
|
|
3222
|
+
/**
|
|
3223
|
+
* Which product a variant's key discovery must look for on Windows.
|
|
3224
|
+
*
|
|
3225
|
+
* Everything unknown is read as CN: that is the product whose default auth file
|
|
3226
|
+
* `defaultDesktopAuthCandidates()` already names, so the two answers agree.
|
|
3227
|
+
*/
|
|
3228
|
+
function atRestProductFor(variant) {
|
|
3229
|
+
return variant !== void 0 && variant.id === AI_VARIANT.id ? "ai" : "cn";
|
|
3139
3230
|
}
|
|
3140
3231
|
/**
|
|
3141
3232
|
* Read-only credential store with demand-driven refresh.
|
|
@@ -3159,7 +3250,10 @@ var WorkBuddyCredentialStore = class {
|
|
|
3159
3250
|
this.refresh = options.refresh;
|
|
3160
3251
|
this.refreshMarginMs = options.refreshMarginMs ?? 3e5;
|
|
3161
3252
|
this.ownPath = options.ownPath ?? (options.variant ? join(resolveDshHome(), options.variant.ownFilename) : workbuddyOwnAuthPath());
|
|
3162
|
-
this.keyProvider = options.keyProvider ?? new WorkBuddyAtRestKeyProvider({
|
|
3253
|
+
this.keyProvider = options.keyProvider ?? new WorkBuddyAtRestKeyProvider({
|
|
3254
|
+
discovery: atRestDiscoveryFor(options.variant),
|
|
3255
|
+
product: atRestProductFor(options.variant)
|
|
3256
|
+
});
|
|
3163
3257
|
this.desktopPathOverride = options.desktopPath;
|
|
3164
3258
|
}
|
|
3165
3259
|
/**
|
|
@@ -4165,7 +4259,7 @@ var WorkBuddyCatalog = class {
|
|
|
4165
4259
|
};
|
|
4166
4260
|
//#endregion
|
|
4167
4261
|
//#region src/version.ts
|
|
4168
|
-
const WORKBUDDY_BRIDGE_VERSION = "0.5.
|
|
4262
|
+
const WORKBUDDY_BRIDGE_VERSION = "0.5.10";
|
|
4169
4263
|
//#endregion
|
|
4170
4264
|
//#region src/web/heartbeat.ts
|
|
4171
4265
|
/**
|
|
@@ -4336,4 +4430,4 @@ function isHeartbeatProcessAlive(heartbeat) {
|
|
|
4336
4430
|
return startAtMs <= heartbeat.registeredAt;
|
|
4337
4431
|
}
|
|
4338
4432
|
//#endregion
|
|
4339
|
-
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
|
@@ -75,6 +75,27 @@ type WorkBuddySignedOutReasonCode =
|
|
|
75
75
|
//#region src/credential/at-rest.d.ts
|
|
76
76
|
/** The four states a desktop auth document can be read as. */
|
|
77
77
|
type DesktopAuthFormat = 'absent' | 'plaintext' | 'encrypted' | 'unrecognized';
|
|
78
|
+
/**
|
|
79
|
+
* The Windows install locations probed in order, confirmed on WorkBuddy 5.6.2.
|
|
80
|
+
*
|
|
81
|
+
* The app ships the Electron runtime as `WorkBuddy.exe` beside its `resources/`
|
|
82
|
+
* and `locales/` directories — there is no `Electron.exe`, and the launcher is
|
|
83
|
+
* the runtime itself (it honours `ELECTRON_RUN_AS_NODE`, which is what the key
|
|
84
|
+
* helper relies on).
|
|
85
|
+
*
|
|
86
|
+
* The default location is `%LOCALAPPDATA%\Programs\WorkBuddy`, but the 5.6.2
|
|
87
|
+
* installer here put it at the drive root (`E:\WorkBuddy`), so the registry's
|
|
88
|
+
* `DisplayIcon` is consulted as well — see {@link windowsElectronCandidates}.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* Which WorkBuddy product a Windows discovery pass is looking for.
|
|
92
|
+
*
|
|
93
|
+
* The two products are separate installs with separate directory names and
|
|
94
|
+
* separate executable names, so "the WorkBuddy app" is ambiguous on a machine
|
|
95
|
+
* that has both. Discovery therefore runs *per product*: it never falls back
|
|
96
|
+
* from one to the other, because a CN binary can only answer for CN envelopes.
|
|
97
|
+
*/
|
|
98
|
+
type WorkBuddyElectronProduct = 'cn' | 'ai';
|
|
78
99
|
/** The spawned helper. Separated from the provider so tests can stand it in. */
|
|
79
100
|
type WorkBuddyKeyPayloadSource = () => Promise<string>;
|
|
80
101
|
/**
|
|
@@ -133,6 +154,14 @@ interface WorkBuddyAtRestKeyProviderOptions {
|
|
|
133
154
|
* composition root, never inferred from the environment.
|
|
134
155
|
*/
|
|
135
156
|
discovery?: WorkBuddyElectronDiscovery;
|
|
157
|
+
/**
|
|
158
|
+
* Which product this provider serves, for the Windows layout and registry
|
|
159
|
+
* identity. Defaults to `'cn'` — the product every earlier release served —
|
|
160
|
+
* so an existing caller that says nothing keeps its behaviour. A Global
|
|
161
|
+
* (WorkBuddy AI) provider must pass `'ai'`: the two installs have different
|
|
162
|
+
* directory and executable names, and the CN executable cannot stand in.
|
|
163
|
+
*/
|
|
164
|
+
product?: WorkBuddyElectronProduct;
|
|
136
165
|
/**
|
|
137
166
|
* Platform default binary, consulted only when `discovery` is enabled and no
|
|
138
167
|
* explicit path is configured. Injectable so tests can force the fallback
|
|
@@ -174,6 +203,7 @@ interface WorkBuddyWindowsDiscoveryTools {
|
|
|
174
203
|
private readonly explicitPath;
|
|
175
204
|
private readonly defaultPath;
|
|
176
205
|
private readonly discovery;
|
|
206
|
+
private readonly product;
|
|
177
207
|
private readonly tools;
|
|
178
208
|
/** Explicit `tools` means the caller owns the platform question (tests, custom hosts). */
|
|
179
209
|
private readonly toolsAreInjected;
|
|
@@ -230,14 +260,19 @@ interface WorkBuddyWindowsDiscoveryTools {
|
|
|
230
260
|
*/
|
|
231
261
|
private discoverMacosApp;
|
|
232
262
|
/**
|
|
233
|
-
* Resolve
|
|
263
|
+
* Resolve this provider's product from its Windows registration.
|
|
234
264
|
*
|
|
235
265
|
* There is no second identity check as on macOS: the registration *is* the
|
|
236
266
|
* identity — {@link windowsInstallsFromRegistry} only accepts blocks whose
|
|
237
|
-
* `DisplayName`
|
|
267
|
+
* `DisplayName` names this product — and the executable is a fixed name
|
|
238
268
|
* inside the registered directory. A registered directory that no longer holds
|
|
239
269
|
* an executable is a decidable exclusion, the same way a Spotlight row for a
|
|
240
270
|
* deleted app is.
|
|
271
|
+
*
|
|
272
|
+
* Both products may be installed side by side and register under the same
|
|
273
|
+
* `WorkBuddy` stem, so the registry query results are filtered by product
|
|
274
|
+
* before the executable is looked for: otherwise the Global app's directory
|
|
275
|
+
* would be probed for a CN executable and read as "not installed".
|
|
241
276
|
*/
|
|
242
277
|
private discoverWindowsApp;
|
|
243
278
|
private spawnPayload;
|
|
@@ -728,7 +763,7 @@ declare class WorkBuddyUpstreamClient {
|
|
|
728
763
|
* Normalization is idempotent, so a caller that already prepared the body
|
|
729
764
|
* (the shim does) sees no second change.
|
|
730
765
|
*/
|
|
731
|
-
chatStream(credential: WorkBuddyCredential, bodyJson: string, signal?: AbortSignal): Promise<WorkBuddyChatResult>;
|
|
766
|
+
chatStream(credential: WorkBuddyCredential, bodyJson: string, signal?: AbortSignal, conversationId?: string): Promise<WorkBuddyChatResult>;
|
|
732
767
|
/** POST the token-refresh endpoint; the caller merges the outcome. */
|
|
733
768
|
refreshToken(credential: WorkBuddyCredential): Promise<WorkBuddyRefreshOutcome>;
|
|
734
769
|
/**
|