dsh-connect-workbuddy 5.24.9 → 5.24.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/CHANGELOG.md +38 -0
- package/docs/ROUTE-B-SESSION-ID.md +75 -0
- package/lib/bin.js +1 -1
- package/lib/{host-heartbeat-CgkojTgC.js → host-heartbeat-Dfhm6kYT.js} +32 -4
- package/lib/index.d.ts +54 -2
- package/lib/index.js +40 -15
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.24.10 (2026-11-17)
|
|
4
|
+
|
|
5
|
+
> 版本号是 **patch**:新增一个**默认关闭**的实验开关(路线 B),默认行为、出站字节、
|
|
6
|
+
> 既有开关与池子排序一律未动;无破坏性改动。来自 PR #266。
|
|
7
|
+
> 是否把它作为默认能力,留待命中率实测与 GA 验收决定——本版只是把对照实验的能力发出去。
|
|
8
|
+
|
|
9
|
+
### 新增:路线 B —— 从宿主会话 ID 派生上游会话亲和键(opt-in,默认 false)
|
|
10
|
+
|
|
11
|
+
路线 A(`stableConversationId`)把 `X-Conversation-ID` 固定为请求前缀派生的亲和键,
|
|
12
|
+
压缩 / 首问变化 / 换模型都会换键。路线 B(`sessionConversationId`)改为以**宿主会话 ID**
|
|
13
|
+
为来源:pi-ai 把它作为 session-affinity 头 stamp 到 loopback 请求,shim 读该头并用
|
|
14
|
+
**带域隔离的确定性摘要**(scheme `dsh-session-conversation-id/v1`)映射成 v4 形状 ID,
|
|
15
|
+
沿全部 `chatStream` 路径(含渠道拒绝救援阶梯与账号 failover)作为 `X-Conversation-ID`
|
|
16
|
+
发出。真实 sessionId 从不出进程、不入日志。
|
|
17
|
+
|
|
18
|
+
- 两个开关独立、默认 `false`;同时打开时路线 B 优先。
|
|
19
|
+
- shim 与 adapter 用 live getter 读开关,切换后下一次请求即生效,无需重载(路线 A 是挂载时采样)。
|
|
20
|
+
- 关闭时模型描述不带 affinity compat 键、shim 不读头、出站字节完全不变。
|
|
21
|
+
- 共享 secret 只做 Bearer 校验,不独立证明头的宿主来源;详见 `docs/ROUTE-B-SESSION-ID.md`(已随包发布)。
|
|
22
|
+
|
|
23
|
+
**限定**:这是实验性能力,不附带任何命中率实测结论,不声称改善缓存,不区分上游内部机制
|
|
24
|
+
(缓存键分区 / 路由亲和 / 其它),默认关闭。
|
|
25
|
+
|
|
26
|
+
验证:`typecheck` / `build` / `check:pii` / 全量 `test` 全绿(3696 passed);维护者独立
|
|
27
|
+
变异验证与 pi-ai 版本下界(0.85.0)前提核实见 PR #266 审查记录。
|
|
28
|
+
|
|
29
|
+
### 修复:发布流程里查 overrides 的命令恒返回空,等于没有检查
|
|
30
|
+
|
|
31
|
+
`RELEASING.md` §2.6 那条「不得跳过」的 overrides 核对命令用了 `awk '{print $3}'`,
|
|
32
|
+
而那些行只有两个字段——`$3` 恒为空,检查永远静默通过,恰好漏掉它本该抓的
|
|
33
|
+
「混入别的版本串」。已改为按实际字段形态提取,并复核当前 overrides 整块指向
|
|
34
|
+
同一条宿主线(25 条、唯一版本 0.2.2-rc.3)。
|
|
35
|
+
|
|
36
|
+
### 测试:#263 的到期断言在任何时区都成立
|
|
37
|
+
|
|
38
|
+
临期展示的到期时刻断言此前依赖跑测试机器的本地时区;已改为时区无关的断言,
|
|
39
|
+
并把 `TZ` 钉进测试环境,避免 CI 与本机时区不同导致的假红/假绿。
|
|
40
|
+
|
|
3
41
|
## 5.24.9 (2026-11-16)
|
|
4
42
|
|
|
5
43
|
> 版本号是 **patch**:新增一处只读展示,默认行为、开关、路由形状与池子排序一律未动;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# 路线 B:从宿主会话 ID 派生上游会话亲和键(实验性,默认关闭)
|
|
2
|
+
|
|
3
|
+
> 本文是**设计与语义**说明,不是收益结论。本 PR 不附带任何命中率实测数字,
|
|
4
|
+
> 不声称改善缓存,也不区分上游内部机制(缓存键分区 / 路由亲和 / 其它)。
|
|
5
|
+
|
|
6
|
+
## 1. 它解决什么,不解决什么
|
|
7
|
+
|
|
8
|
+
路线 A(`stableConversationId`,见 [`STABLE-KEY-SEMANTICS.md`](STABLE-KEY-SEMANTICS.md))
|
|
9
|
+
把 `X-Conversation-ID` 固定为**请求前缀**派生的亲和键。它的已知限制是:压缩、
|
|
10
|
+
首问变化、换模型、对话分叉都会改变前缀,从而换键——它并不是宿主真正的会话标识。
|
|
11
|
+
|
|
12
|
+
路线 B 用**宿主会话 ID**代替请求前缀作为亲和键的来源,因此上面的变化不再换键。
|
|
13
|
+
它要证明的只是一个可检验的命题:**当上游把同一个 `X-Conversation-ID` 视作同一
|
|
14
|
+
会话时,稳定它是否与更高命中相关。** 本文与实现都不对"上游究竟如何分区缓存"
|
|
15
|
+
作任何断言(`MECHANISM_PROVEN = false`)。
|
|
16
|
+
|
|
17
|
+
路线 B 与路线 A **相互独立**,默认都关闭。两者同时打开时,路线 B 优先。
|
|
18
|
+
|
|
19
|
+
## 2. 会话 ID 如何到达上游(且真值不外发)
|
|
20
|
+
|
|
21
|
+
宿主在每次生成的 `GenerateOptions` 上带一个 `sessionId`。链路:
|
|
22
|
+
|
|
23
|
+
1. `dsh-llm-pi-ai` 把 `options.sessionId` 转成字符串传给 pi-ai 的 `streamSimple`。
|
|
24
|
+
2. pi-ai 的 `buildBaseOptions` 把 `sessionId` 转发给 `stream`。
|
|
25
|
+
3. 本插件在模型描述的 `compat` 上声明
|
|
26
|
+
`sendSessionAffinityHeaders: true, sessionAffinityFormat: 'openai'`,
|
|
27
|
+
pi-ai 的 `createClient` 因此在该请求上 stamp 三个 loopback 头:
|
|
28
|
+
`session_id`、`x-client-request-id`、`x-session-affinity`(值都是 sessionId)。
|
|
29
|
+
4. loopback shim 已强制Bearer + 本机回环校验;它在 `chatCompletions` 入口读
|
|
30
|
+
`x-session-affinity`,**只在开关打开时**读,并做限长(≤256)与空值校验。
|
|
31
|
+
5. shim 把该值经 `conversationIdFromSessionId()` 做**带域隔离的确定性 SHA-256**
|
|
32
|
+
(scheme `dsh-session-conversation-id/v1`,与路线 A 的 scheme 不同,避免两路
|
|
33
|
+
共享亲和桶),映射成 v4 形状的 ID,作为**每请求一次**的局部变量。
|
|
34
|
+
6. 该局部 ID 沿全部 `chatStream` 调用链传递——主路、渠道校验拒绝后的
|
|
35
|
+
救援阶梯、账号 failover——所以同一逻辑请求的每次重试都用同一个 ID。
|
|
36
|
+
7. `chatStream` 收到该 ID 后,用它覆盖 `X-Conversation-ID`;**真实 sessionId
|
|
37
|
+
从不离开进程**,不做日志,只以摘要形式出现在出站头里。
|
|
38
|
+
|
|
39
|
+
关闭开关时:模型描述不带那两个 compat 键(pi-ai 的 detected 默认仍是
|
|
40
|
+
`sendSessionAffinityHeaders: false`),shim 不读头,`chatStream` 收到
|
|
41
|
+
`undefined`——三次参数调用形态与默认字节**完全不变**。
|
|
42
|
+
|
|
43
|
+
## 3. 开关与生效时机
|
|
44
|
+
|
|
45
|
+
配置项 `sessionConversationId: boolean`,默认 `false`。
|
|
46
|
+
|
|
47
|
+
- shim 与 adapter 都用 **live getter**(每次请求读当前 volatile 配置),
|
|
48
|
+
因此卡片切换后下一次请求就生效,**不需要重载插件**——这是与路线 A(挂载时
|
|
49
|
+
采样一次)的有意区别。
|
|
50
|
+
- 与 `stableConversationId` 独立;两者都开时路线 B 优先。
|
|
51
|
+
|
|
52
|
+
## 4. 已知限制与信任边界
|
|
53
|
+
|
|
54
|
+
- **共享 secret 不是来源证明。** shim 的 Bearer 只证明调用方持有进程内密钥,
|
|
55
|
+
不独立证明头确实来自宿主。若要严格防伪造,需宿主对头做签名/绑定。
|
|
56
|
+
- **头一旦被中间人改写,摘要随之改变。** 所以只接受 loopback + Bearer 的请求,
|
|
57
|
+
并对值做长度/空值约束;不把它当作鉴权凭证。
|
|
58
|
+
- **会话 ID 是敏感值。** 只在进程内以明文存在,出站只发域隔离摘要;任何日志、
|
|
59
|
+
错误信息、测试固件都不得出现真值。
|
|
60
|
+
- **并发不串。** 摘要是每请求的局部变量,无共享可变状态,不依赖
|
|
61
|
+
`AsyncLocalStorage`(它无法跨 loopback)。
|
|
62
|
+
- **不同会话不会复用同一键。** 摘要对 sessionId 是确定性的;相同 sessionId
|
|
63
|
+
跨进程也得到相同键(这是有意的稳定),域隔离只防止与路线 A 的键碰撞。
|
|
64
|
+
- **本 PR 不改变默认值、不发版、不请求合并后默认打开。** 是否把它作为默认
|
|
65
|
+
能力属于维护者与 GA 验收的决定。
|
|
66
|
+
|
|
67
|
+
## 5. 术语
|
|
68
|
+
|
|
69
|
+
| 概念 | 路线 A | 路线 B |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `X-Conversation-ID` 来源 | 请求前缀派生哈希 | 宿主 sessionId 派生哈希(域隔离) |
|
|
72
|
+
| 换键条件 | 压缩 / 首问 / 换模型 / 分叉 | 换会话 |
|
|
73
|
+
| 稳定性 | 挂载时采样配置 | 每请求 live getter |
|
|
74
|
+
| 真值外发 | 无(只有前缀摘要) | 无(只有 sessionId 摘要) |
|
|
75
|
+
| 默认 | 关 | 关 |
|
package/lib/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { F as WorkBuddyCredentialStore, J as workbuddyOwnAuthPath,
|
|
2
|
+
import { F as WorkBuddyCredentialStore, J as workbuddyOwnAuthPath, N as WORKBUDDY_AUTH_FILE_ENV, Nn as hostPeersInfo, P as WORKBUDDY_VAULT_DIRNAME, Pn as resolveDshHome, R as defaultDesktopAuthCandidates, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, Tn as findWorkbuddyAppExecutableWithSource, W as legacyWorkbuddyOwnAuthPath, X as APP_VERSION, Y as workbuddyVaultDir, _n as inspectCredentialDirectory, a as readHostHeartbeat, b as readDeviceSettings, c as WORKBUDDY_CONNECT_VERSION, d as rosterSeenPath, dn as WORKBUDDY_DEVICE_TOKEN_FILE_ENV, et as DEFAULT_WIRE_PROFILE, f as WORKBUDDY_CN_BASE_ENV, fn as readDeviceTokenFile, g as createTuringSdk, hn as deriveDeviceId, lt as describeRequestHeaderNames, m as piAiRuntimeInfo, mn as readDeviceSalt, o as workbuddyHostHeartbeatPath, p as resolveCnGateway, pn as ensureDeviceSalt, r as isHeartbeatProcessAlive, rt as WorkBuddyUpstreamClient, u as describeRosterSeenPayload, vn as protectCredentialDirectory, w as FALLBACK_WORKBUDDY_MODELS, yn as WORKBUDDY_APP_EXECUTABLE_ENV, z as defaultDesktopAuthDirs } from "./host-heartbeat-Dfhm6kYT.js";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { realpathSync } from "node:fs";
|
|
@@ -4625,6 +4625,34 @@ function deriveStableConversationId(bodyJson) {
|
|
|
4625
4625
|
return formatAsUuidV4(createHash("sha256").update(tuple).digest("hex"));
|
|
4626
4626
|
}
|
|
4627
4627
|
/**
|
|
4628
|
+
* Route B: version tag for mapping a HOST session id onto a v4-shaped
|
|
4629
|
+
* conversation id. Deliberately different from {@link STABLE_KEY_SCHEME} so a
|
|
4630
|
+
* session-derived id can never equal a prefix-derived (route A) id — the two
|
|
4631
|
+
* routes must not silently share an upstream affinity bucket.
|
|
4632
|
+
*/
|
|
4633
|
+
const SESSION_CONVERSATION_KEY_SCHEME = "dsh-session-conversation-id/v1";
|
|
4634
|
+
/**
|
|
4635
|
+
* Map a host session id to a v4-SHAPED `X-Conversation-ID` (route B).
|
|
4636
|
+
*
|
|
4637
|
+
* The REAL session id never leaves this process: only this digest is put on the
|
|
4638
|
+
* wire. The digest is domain-separated from route A and from any other hash use,
|
|
4639
|
+
* so the same text cannot collide with a prefix-derived affinity key. The input
|
|
4640
|
+
* is trimmed and length-capped (a defensive bound on a loopback-only header):
|
|
4641
|
+
* an empty or over-long value yields `undefined`, which makes the caller fall
|
|
4642
|
+
* back to the ordinary per-request id rather than send anything derived from
|
|
4643
|
+
* malformed input.
|
|
4644
|
+
*
|
|
4645
|
+
* This is a stable, deterministic LOCAL mapping, NOT the host session id itself
|
|
4646
|
+
* and NOT a claim that the upstream keys any cache by session. It makes no
|
|
4647
|
+
* assertion about upstream internal mechanism (cache-key partitioning vs routing
|
|
4648
|
+
* affinity are indistinguishable from here). See `docs/ROUTE-B-SESSION-ID.md`.
|
|
4649
|
+
*/
|
|
4650
|
+
function conversationIdFromSessionId(sessionId) {
|
|
4651
|
+
const trimmed = sessionId.trim();
|
|
4652
|
+
if (trimmed === "" || trimmed.length > 256) return void 0;
|
|
4653
|
+
return formatAsUuidV4(createHash("sha256").update(SESSION_CONVERSATION_KEY_SCHEME).update("\0").update(trimmed).digest("hex"));
|
|
4654
|
+
}
|
|
4655
|
+
/**
|
|
4628
4656
|
* 没有显式配置时用的档位。
|
|
4629
4657
|
*
|
|
4630
4658
|
* `balanced`:P0.5 已证实有效,默认就应该吃到收益;`conservative` 留给
|
|
@@ -6937,12 +6965,12 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6937
6965
|
};
|
|
6938
6966
|
}
|
|
6939
6967
|
/** POST the chat endpoint; a successful answer is the raw SSE response. */
|
|
6940
|
-
async chatStream(credential, bodyJson, signal) {
|
|
6968
|
+
async chatStream(credential, bodyJson, signal, sessionConversationId) {
|
|
6941
6969
|
let response;
|
|
6942
6970
|
try {
|
|
6943
6971
|
const identity = await this.wireIdentity(credential);
|
|
6944
6972
|
const headers = {
|
|
6945
|
-
...chatHeaders(credential, identity, identity.stableConversationId === true ? deriveStableConversationId(bodyJson) : void 0),
|
|
6973
|
+
...chatHeaders(credential, identity, sessionConversationId !== void 0 && sessionConversationId !== "" ? sessionConversationId : identity.stableConversationId === true ? deriveStableConversationId(bodyJson) : void 0),
|
|
6946
6974
|
"Authorization": `Bearer ${credential.accessToken}`
|
|
6947
6975
|
};
|
|
6948
6976
|
if (signal?.aborted === true) return {
|
|
@@ -11239,7 +11267,7 @@ function describeRosterSeenPayload(raw) {
|
|
|
11239
11267
|
//#endregion
|
|
11240
11268
|
//#region src/version.ts
|
|
11241
11269
|
/** The npm package version this build was produced from. */
|
|
11242
|
-
const WORKBUDDY_CONNECT_VERSION = "5.24.
|
|
11270
|
+
const WORKBUDDY_CONNECT_VERSION = "5.24.10";
|
|
11243
11271
|
//#endregion
|
|
11244
11272
|
//#region src/host-heartbeat.ts
|
|
11245
11273
|
/**
|
|
@@ -11473,4 +11501,4 @@ async function clearHostHeartbeat(owner) {
|
|
|
11473
11501
|
if (current === owner.contents) await rm(owner.path, { force: true });
|
|
11474
11502
|
}
|
|
11475
11503
|
//#endregion
|
|
11476
|
-
export { CREDENTIAL_REJECTED_CODE as $,
|
|
11504
|
+
export { CREDENTIAL_REJECTED_CODE as $, imageSizeLimitsOf as $t, withoutRouters as A, openEncryptedField as An, promoBadgeTone as At, defaultDesktopAuthPath as B, VIDEO_TAG_TEXT_TO_VIDEO as Bt, setDeviceMode as C, fetchAtRestKeyPayload as Cn, perturbChannelFingerprints as Ct, applyContextBudgets as D, isWorkbuddyBundle as Dn, rewriteSessionTitleModel as Dt, WorkBuddyCatalog as E, isEncryptedFieldWrapper as En, requestEvidenceOf as Et, WorkBuddyCredentialStore as F, withFileLock as Fn, offDefaultFor as Ft, parseWorkBuddyAuth as G, IMAGE_SIZE_LIMITS_WIDE as Gt, isEncryptedCredentialError as H, parseSupportedSecondsRange as Ht, WorkBuddyEncryptedCredentialError as I, writeFileAtomic as In, offRefused as It, workbuddyOwnAuthPath as J, MAX_INPUT_IMAGE_BYTES as Jt, preferredAccountName as K, IMAGE_TAG_IMAGE_TO_IMAGE as Kt, authFileName as L, recordRefusal as Lt, WORKBUDDY_AUTH_FILENAME as M, workbuddyAppExecutableCandidates as Mn, REFUSES_OFF_MODEL_IDS as Mt, WORKBUDDY_AUTH_FILE_ENV as N, hostPeersInfo as Nn, defaultOffModelIds as Nt, deriveCatalog as O, macosBundleExecutable as On, toolSchemaRejectAdvice as Ot, WORKBUDDY_VAULT_DIRNAME as P, resolveDshHome as Pn, lastRefusalFor as Pt, CONTEXT_OVERFLOW_MARKER as Q, imageModelChoices as Qt, defaultDesktopAuthCandidates as R, withEffectiveOff as Rt, saveDeviceSdkSettings as S, deriveAtRestKeyId as Sn, parseUpstreamModel as St, FALLBACK_WORKBUDDY_MODELS_GLOBAL as T, findWorkbuddyAppExecutableWithSource as Tn, regionOf as Tt, isVaultAccountId as U, pickVideoModel as Ut, hasEncryptedCredentialFields as V, WorkBuddyVideoError as Vt, legacyWorkbuddyOwnAuthPath as W, resolveVideoParams as Wt, APP_VERSION as X, imageDataUrl as Xt, workbuddyVaultDir as Y, WorkBuddyImageError as Yt, BODY_OVERSIZE_MARKER as Z, imageMimeForPath as Zt, createDeviceProfileLookup as _, inspectCredentialDirectory as _n, knownRegionOf as _t, readHostHeartbeat as a, parseQueueAnswer as an, classifyUpstreamError as at, readDeviceSettings as b, clearAtRestKeyCache as bn, parseCreditMultiplier as bt, WORKBUDDY_CONNECT_VERSION as c, NATIVE_MODALITY_BY_MODEL_ID as cn, deriveStableConversationId as ct, rosterSeenPath as d, WORKBUDDY_DEVICE_TOKEN_FILE_ENV as dn, isBodyOversizeRefusal as dt, isBareBase64Image as en, DEFAULT_WIRE_PROFILE as et, WORKBUDDY_CN_BASE_ENV as f, readDeviceTokenFile as fn, isContextTooLongBody as ft, createTuringSdk as g, isDeviceId as gn, isToolSchemaRejectBody as gt, createDeviceSdkPort as h, deriveDeviceId as hn, isFirstMessageGateBody as ht, processStartTimeMs as i, sniffImageMime as in, channelGateMemberOf as it, ENCRYPTED_CREDENTIAL_CODE as j, readAtRestKey as jn, selectPromoBadge as jt, fallbackModelsFor as k, macosNestedAppBundles as kn, attachBusyLevels as kt, createFileRosterSeenStore as l, imageDefaultFor as ln, describeRequestHeaderNames as lt, piAiRuntimeInfo as m, readDeviceSalt as mn, isCredentialRejectedError as mt, clearHostHeartbeat as n, parseImageDataUrl as nn, WorkBuddyCredentialRejectedError as nt, workbuddyHostHeartbeatPath as o, queueNoticeText as on, conversationIdFromSessionId as ot, resolveCnGateway as p, ensureDeviceSalt as pn, isConversationIdGateBody as pt, workbuddyAccountId as q, IMAGE_TAG_TEXT_TO_IMAGE as qt, isHeartbeatProcessAlive as r, pickMediaModel as rn, WorkBuddyUpstreamClient as rt, writeHostHeartbeat as s, pruneTempDir as sn, declaredTools as st, WORKBUDDY_HOST_HEARTBEAT_FILENAME as t, isWatermarkFreeImageModel as tn, WORKBUDDY_FALLBACK_SYSTEM_PROMPT as tt, describeRosterSeenPayload as u, nativeModalityOf as un, forceNeutralHead as ut, describeDerivedDevices as v, protectCredentialDirectory as vn, modelIdOfBody as vt, FALLBACK_WORKBUDDY_MODELS as w, findWorkbuddyAppExecutable as wn, prepareChatBody as wt, saveDeviceProfile as x, deriveAtRestKey as xn, parseReasoning as xt, isDeviceMode as y, WORKBUDDY_APP_EXECUTABLE_ENV as yn, openingEvidenceOfBody as yt, defaultDesktopAuthDirs as z, VIDEO_TAG_IMAGE_TO_VIDEO as zt };
|
package/lib/index.d.ts
CHANGED
|
@@ -1646,6 +1646,23 @@ declare function knownRegionOf(domain: string): WorkBuddyRegion | undefined;
|
|
|
1646
1646
|
* id. No secret, account or machine value is read here.
|
|
1647
1647
|
*/
|
|
1648
1648
|
declare function deriveStableConversationId(bodyJson: string): string | undefined;
|
|
1649
|
+
/**
|
|
1650
|
+
* Map a host session id to a v4-SHAPED `X-Conversation-ID` (route B).
|
|
1651
|
+
*
|
|
1652
|
+
* The REAL session id never leaves this process: only this digest is put on the
|
|
1653
|
+
* wire. The digest is domain-separated from route A and from any other hash use,
|
|
1654
|
+
* so the same text cannot collide with a prefix-derived affinity key. The input
|
|
1655
|
+
* is trimmed and length-capped (a defensive bound on a loopback-only header):
|
|
1656
|
+
* an empty or over-long value yields `undefined`, which makes the caller fall
|
|
1657
|
+
* back to the ordinary per-request id rather than send anything derived from
|
|
1658
|
+
* malformed input.
|
|
1659
|
+
*
|
|
1660
|
+
* This is a stable, deterministic LOCAL mapping, NOT the host session id itself
|
|
1661
|
+
* and NOT a claim that the upstream keys any cache by session. It makes no
|
|
1662
|
+
* assertion about upstream internal mechanism (cache-key partitioning vs routing
|
|
1663
|
+
* affinity are indistinguishable from here). See `docs/ROUTE-B-SESSION-ID.md`.
|
|
1664
|
+
*/
|
|
1665
|
+
declare function conversationIdFromSessionId(sessionId: string): string | undefined;
|
|
1649
1666
|
/**
|
|
1650
1667
|
* 出站身份档位(`docs/DEVICE-IDENTITY-AUDIT.md` 的 P1)。
|
|
1651
1668
|
*
|
|
@@ -1931,7 +1948,14 @@ declare class WorkBuddyUpstreamClient {
|
|
|
1931
1948
|
*/
|
|
1932
1949
|
private wireIdentity;
|
|
1933
1950
|
/** POST the chat endpoint; a successful answer is the raw SSE response. */
|
|
1934
|
-
chatStream(credential: WorkBuddyCredential, bodyJson: string, signal?: AbortSignal
|
|
1951
|
+
chatStream(credential: WorkBuddyCredential, bodyJson: string, signal?: AbortSignal,
|
|
1952
|
+
/**
|
|
1953
|
+
* Route B (opt-in): the loopback-only session id the shim read from the
|
|
1954
|
+
* adapter-stamped affinity header, ALREADY mapped to a v4-shaped digest by
|
|
1955
|
+
* the caller. When present it takes precedence over the route-A prefix key.
|
|
1956
|
+
* Purely additive: existing three-argument callers are byte-identical.
|
|
1957
|
+
*/
|
|
1958
|
+
sessionConversationId?: string): Promise<WorkBuddyChatResult>;
|
|
1935
1959
|
/**
|
|
1936
1960
|
* Send one minimal chat request for `bodyJson` and report the RAW answer.
|
|
1937
1961
|
*
|
|
@@ -2564,6 +2588,13 @@ interface WorkBuddyShimOptions {
|
|
|
2564
2588
|
* Default false: it changes bytes the upstream counts, so it is opt-in.
|
|
2565
2589
|
*/
|
|
2566
2590
|
keepPromptLast?: boolean;
|
|
2591
|
+
/**
|
|
2592
|
+
* Route B (opt-in): the shim reads the pi-ai session-affinity header on the
|
|
2593
|
+
* loopback request and maps it to a domain-separated `X-Conversation-ID`
|
|
2594
|
+
* upstream. The real session id is never forwarded. OFF by default.
|
|
2595
|
+
* See `docs/ROUTE-B-SESSION-ID.md`.
|
|
2596
|
+
*/
|
|
2597
|
+
sessionConversationId?: () => boolean;
|
|
2567
2598
|
/**
|
|
2568
2599
|
* Extra literal prefixes (issue #133) treated like the harness's injected
|
|
2569
2600
|
* markers under `keepPromptLast`, for context blocks a companion plugin
|
|
@@ -2842,6 +2873,18 @@ interface WorkBuddyAdapterOptions {
|
|
|
2842
2873
|
* normally.
|
|
2843
2874
|
*/
|
|
2844
2875
|
dropForeignThinking?: () => boolean;
|
|
2876
|
+
/**
|
|
2877
|
+
* Route B (opt-in): ask pi-ai to stamp the host's session id onto each request
|
|
2878
|
+
* as session-affinity HEADERS, so the loopback shim can read it and give the
|
|
2879
|
+
* upstream a stable, session-scoped conversation id (a domain-separated
|
|
2880
|
+
* digest; the real session id never leaves the process).
|
|
2881
|
+
*
|
|
2882
|
+
* OFF by default: this changes headers the provider sends AND is only correct
|
|
2883
|
+
* if the shim is loopback-only + bearer-gated (it is — see `src/shim.ts`). Read
|
|
2884
|
+
* LIVE so the card toggle takes effect on the next request without a reload.
|
|
2885
|
+
* See `docs/ROUTE-B-SESSION-ID.md`; no upstream mechanism is asserted.
|
|
2886
|
+
*/
|
|
2887
|
+
sessionConversationId?: () => boolean;
|
|
2845
2888
|
/**
|
|
2846
2889
|
* Strip EVERY historical thinking block before the request goes out (issue #213).
|
|
2847
2890
|
*
|
|
@@ -6162,6 +6205,15 @@ interface Config {
|
|
|
6162
6205
|
* 开启后只固定 X-Conversation-ID,其余三件套仍每请求现生成。
|
|
6163
6206
|
*/
|
|
6164
6207
|
stableConversationId?: boolean;
|
|
6208
|
+
/**
|
|
6209
|
+
* Route B (opt-in): derive the upstream `X-Conversation-ID` from the HOST
|
|
6210
|
+
* session id instead of the request prefix. The session id travels from the
|
|
6211
|
+
* host through pi-ai to the loopback shim as session-affinity HEADERS, and the
|
|
6212
|
+
* shim/upstream turn it into a domain-separated digest — the real session id
|
|
6213
|
+
* never leaves the process. OFF by default; independent of route A. See
|
|
6214
|
+
* `docs/ROUTE-B-SESSION-ID.md`. No upstream mechanism is asserted.
|
|
6215
|
+
*/
|
|
6216
|
+
sessionConversationId?: boolean;
|
|
6165
6217
|
/**
|
|
6166
6218
|
* Move the harness's injected context above the real prompt (issue #132).
|
|
6167
6219
|
*
|
|
@@ -6414,4 +6466,4 @@ declare function legacyAttributionRegion(value: Config, accountsFor: (region: Wo
|
|
|
6414
6466
|
*/
|
|
6415
6467
|
declare function apply(ctx: Context, config: Config): void;
|
|
6416
6468
|
//#endregion
|
|
6417
|
-
export { CREDENTIAL_REJECTED_CODE, Config, DEFAULT_PROBE_INPUT_TOKENS, ENCRYPTED_CREDENTIAL_CODE, FALLBACK_WORKBUDDY_MODELS, FALLBACK_WORKBUDDY_MODELS_GLOBAL, NATIVE_MODALITY_BY_MODEL_ID, PROBE_INPUT_TOKEN_CHOICES, PROBE_MAX_TOKENS, PROBE_SYSTEM_PROMPT, REFUSES_OFF_MODEL_IDS, type UpstreamErrorKind, WORKBUDDY_ACCOUNTS_REFRESH_PATH, WORKBUDDY_APP_EXECUTABLE_ENV, WORKBUDDY_AUTH_FILENAME, WORKBUDDY_AUTH_FILE_ENV, WORKBUDDY_CHECKIN_PATH, WORKBUDDY_CONNECT_VERSION, WORKBUDDY_GLOBAL_PROVIDER, WORKBUDDY_HOST_HEARTBEAT_FILENAME, WORKBUDDY_MODELS_REFRESH_PATH, WORKBUDDY_PROBE_PATH, WORKBUDDY_PROVIDER, WORKBUDDY_PROVIDERS, WORKBUDDY_PROVIDER_DISPLAY_NAMES, WORKBUDDY_REGIONS, WORKBUDDY_REGION_PARAM, WORKBUDDY_SETTINGS_NS, WORKBUDDY_STREAM_IDLE_TIMEOUT_MS, WORKBUDDY_TPS_PATH, WORKBUDDY_USAGE_PATH, type WorkBuddyAccountChoice, type WorkBuddyAdapter, type WorkBuddyAuthStatus, type WorkBuddyCandidateFailure, WorkBuddyCatalog, type WorkBuddyChatResult, type WorkBuddyCredential, type WorkBuddyCredentialRecovery, WorkBuddyCredentialRejectedError, WorkBuddyCredentialStore, type WorkBuddyCreditPackage, type WorkBuddyCredits, WorkBuddyEncryptedCredentialError, type WorkBuddyEncryptedField, type WorkBuddyHostHeartbeat, type WorkBuddyHostHeartbeatOwner, type WorkBuddyModelInfo, type WorkBuddyNativeModality, WorkBuddyPoolPreferences, type WorkBuddyProbeClient, type WorkBuddyProbeOutcome, type WorkBuddyProbeResult, type WorkBuddyProbeStore, type WorkBuddyReasoning, type WorkBuddyRecoveryCandidate, type WorkBuddyRefreshOutcome, WorkBuddyRegionState, type WorkBuddyShim, type WorkBuddyStatusRouteOptions, type WorkBuddyStoreOptions, WorkBuddyUpstreamClient, type WorkBuddyUpstreamModel, type WorkBuddyUsabilityProbeOptions, apply, asVolatile, authFileName, classifyUpstreamError, clearAtRestKeyCache, clearHostHeartbeat, cooldownOf, createAccountUsabilityProbe, createWorkBuddyAdapter, createWorkBuddyShim, creditOfStream, defaultDesktopAuthCandidates, defaultDesktopAuthDirs, defaultDesktopAuthPath, defaultOffModelIds, deriveAtRestKey, deriveAtRestKeyId, deriveCatalog, deriveStableConversationId, fallbackModelsFor, fetchAtRestKeyPayload, findWorkbuddyAppExecutable, hasEncryptedCredentialFields, imageDefaultFor, imageToolRegionOf, inject, isCredentialRejectedError, isEncryptedCredentialError, isEncryptedFieldWrapper, isHeartbeatProcessAlive, isWorkbuddyBundle, knownRegionOf, legacyAttributionRegion, legacyWorkbuddyOwnAuthPath, macosBundleExecutable, macosNestedAppBundles, modelIdOfBody, name, nativeModalityOf, nextRegionEnabled, nextRegionSlots, offDefaultFor, openEncryptedField, outcomeOfFailure, parseCreditMultiplier, parseReasoning, parseRetryAfter, parseUpstreamModel, parseWorkBuddyAuth, prepareChatBody, probeModel, probeRequestBody, probeSucceeded, processStartTimeMs, readAtRestKey, readHostHeartbeat, realTierAvailabilityFor, regionCleared, regionEnabled, regionEnabledOf, regionOf, regionOfProvider, regionOfStatusUrl, regionStateOf, regionsFieldIsCorrupt, regionsMapOf, registerWorkBuddyStatusRoute, resolveCredentialRecovery, selectAccountFor, settingsNamespaceOf, toPersistedWorkBuddyModel, unwrapVolatileDeep, videoToolRegionOf, withEffectiveOff, withWorkBuddyRegion, workBuddyDisplayName, workBuddyModelInput, workBuddyThinkingLevelMap, workBuddyWebStatus, workbuddyAccountId, workbuddyAppExecutableCandidates, workbuddyHostHeartbeatPath, workbuddyOwnAuthPath, writeHostHeartbeat };
|
|
6469
|
+
export { CREDENTIAL_REJECTED_CODE, Config, DEFAULT_PROBE_INPUT_TOKENS, ENCRYPTED_CREDENTIAL_CODE, FALLBACK_WORKBUDDY_MODELS, FALLBACK_WORKBUDDY_MODELS_GLOBAL, NATIVE_MODALITY_BY_MODEL_ID, PROBE_INPUT_TOKEN_CHOICES, PROBE_MAX_TOKENS, PROBE_SYSTEM_PROMPT, REFUSES_OFF_MODEL_IDS, type UpstreamErrorKind, WORKBUDDY_ACCOUNTS_REFRESH_PATH, WORKBUDDY_APP_EXECUTABLE_ENV, WORKBUDDY_AUTH_FILENAME, WORKBUDDY_AUTH_FILE_ENV, WORKBUDDY_CHECKIN_PATH, WORKBUDDY_CONNECT_VERSION, WORKBUDDY_GLOBAL_PROVIDER, WORKBUDDY_HOST_HEARTBEAT_FILENAME, WORKBUDDY_MODELS_REFRESH_PATH, WORKBUDDY_PROBE_PATH, WORKBUDDY_PROVIDER, WORKBUDDY_PROVIDERS, WORKBUDDY_PROVIDER_DISPLAY_NAMES, WORKBUDDY_REGIONS, WORKBUDDY_REGION_PARAM, WORKBUDDY_SETTINGS_NS, WORKBUDDY_STREAM_IDLE_TIMEOUT_MS, WORKBUDDY_TPS_PATH, WORKBUDDY_USAGE_PATH, type WorkBuddyAccountChoice, type WorkBuddyAdapter, type WorkBuddyAuthStatus, type WorkBuddyCandidateFailure, WorkBuddyCatalog, type WorkBuddyChatResult, type WorkBuddyCredential, type WorkBuddyCredentialRecovery, WorkBuddyCredentialRejectedError, WorkBuddyCredentialStore, type WorkBuddyCreditPackage, type WorkBuddyCredits, WorkBuddyEncryptedCredentialError, type WorkBuddyEncryptedField, type WorkBuddyHostHeartbeat, type WorkBuddyHostHeartbeatOwner, type WorkBuddyModelInfo, type WorkBuddyNativeModality, WorkBuddyPoolPreferences, type WorkBuddyProbeClient, type WorkBuddyProbeOutcome, type WorkBuddyProbeResult, type WorkBuddyProbeStore, type WorkBuddyReasoning, type WorkBuddyRecoveryCandidate, type WorkBuddyRefreshOutcome, WorkBuddyRegionState, type WorkBuddyShim, type WorkBuddyStatusRouteOptions, type WorkBuddyStoreOptions, WorkBuddyUpstreamClient, type WorkBuddyUpstreamModel, type WorkBuddyUsabilityProbeOptions, apply, asVolatile, authFileName, classifyUpstreamError, clearAtRestKeyCache, clearHostHeartbeat, conversationIdFromSessionId, cooldownOf, createAccountUsabilityProbe, createWorkBuddyAdapter, createWorkBuddyShim, creditOfStream, defaultDesktopAuthCandidates, defaultDesktopAuthDirs, defaultDesktopAuthPath, defaultOffModelIds, deriveAtRestKey, deriveAtRestKeyId, deriveCatalog, deriveStableConversationId, fallbackModelsFor, fetchAtRestKeyPayload, findWorkbuddyAppExecutable, hasEncryptedCredentialFields, imageDefaultFor, imageToolRegionOf, inject, isCredentialRejectedError, isEncryptedCredentialError, isEncryptedFieldWrapper, isHeartbeatProcessAlive, isWorkbuddyBundle, knownRegionOf, legacyAttributionRegion, legacyWorkbuddyOwnAuthPath, macosBundleExecutable, macosNestedAppBundles, modelIdOfBody, name, nativeModalityOf, nextRegionEnabled, nextRegionSlots, offDefaultFor, openEncryptedField, outcomeOfFailure, parseCreditMultiplier, parseReasoning, parseRetryAfter, parseUpstreamModel, parseWorkBuddyAuth, prepareChatBody, probeModel, probeRequestBody, probeSucceeded, processStartTimeMs, readAtRestKey, readHostHeartbeat, realTierAvailabilityFor, regionCleared, regionEnabled, regionEnabledOf, regionOf, regionOfProvider, regionOfStatusUrl, regionStateOf, regionsFieldIsCorrupt, regionsMapOf, registerWorkBuddyStatusRoute, resolveCredentialRecovery, selectAccountFor, settingsNamespaceOf, toPersistedWorkBuddyModel, unwrapVolatileDeep, videoToolRegionOf, withEffectiveOff, withWorkBuddyRegion, workBuddyDisplayName, workBuddyModelInput, workBuddyThinkingLevelMap, workBuddyWebStatus, workbuddyAccountId, workbuddyAppExecutableCandidates, workbuddyHostHeartbeatPath, workbuddyOwnAuthPath, writeHostHeartbeat };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as CREDENTIAL_REJECTED_CODE, $t as
|
|
1
|
+
import { $ as CREDENTIAL_REJECTED_CODE, $t as imageSizeLimitsOf, A as withoutRouters, An as openEncryptedField, At as promoBadgeTone, B as defaultDesktopAuthPath, Bt as VIDEO_TAG_TEXT_TO_VIDEO, C as setDeviceMode, Cn as fetchAtRestKeyPayload, Ct as perturbChannelFingerprints, D as applyContextBudgets, Dn as isWorkbuddyBundle, Dt as rewriteSessionTitleModel, E as WorkBuddyCatalog, En as isEncryptedFieldWrapper, Et as requestEvidenceOf, F as WorkBuddyCredentialStore, Fn as withFileLock, Ft as offDefaultFor, G as parseWorkBuddyAuth, Gt as IMAGE_SIZE_LIMITS_WIDE, H as isEncryptedCredentialError, Ht as parseSupportedSecondsRange, I as WorkBuddyEncryptedCredentialError, In as writeFileAtomic, It as offRefused, J as workbuddyOwnAuthPath, Jt as MAX_INPUT_IMAGE_BYTES, K as preferredAccountName, Kt as IMAGE_TAG_IMAGE_TO_IMAGE, L as authFileName, Lt as recordRefusal, M as WORKBUDDY_AUTH_FILENAME, Mn as workbuddyAppExecutableCandidates, Mt as REFUSES_OFF_MODEL_IDS, N as WORKBUDDY_AUTH_FILE_ENV, Nt as defaultOffModelIds, O as deriveCatalog, On as macosBundleExecutable, Ot as toolSchemaRejectAdvice, Pn as resolveDshHome, Pt as lastRefusalFor, Q as CONTEXT_OVERFLOW_MARKER, Qt as imageModelChoices, R as defaultDesktopAuthCandidates, Rt as withEffectiveOff, S as saveDeviceSdkSettings, Sn as deriveAtRestKeyId, St as parseUpstreamModel, T as FALLBACK_WORKBUDDY_MODELS_GLOBAL, Tt as regionOf, U as isVaultAccountId, Ut as pickVideoModel, V as hasEncryptedCredentialFields, Vt as WorkBuddyVideoError, W as legacyWorkbuddyOwnAuthPath, Wt as resolveVideoParams, X as APP_VERSION, Xt as imageDataUrl, Yt as WorkBuddyImageError, Z as BODY_OVERSIZE_MARKER, Zt as imageMimeForPath, _ as createDeviceProfileLookup, _t as knownRegionOf, a as readHostHeartbeat, an as parseQueueAnswer, at as classifyUpstreamError, b as readDeviceSettings, bn as clearAtRestKeyCache, bt as parseCreditMultiplier, c as WORKBUDDY_CONNECT_VERSION, cn as NATIVE_MODALITY_BY_MODEL_ID, ct as deriveStableConversationId, dt as isBodyOversizeRefusal, en as isBareBase64Image, ft as isContextTooLongBody, g as createTuringSdk, gn as isDeviceId, gt as isToolSchemaRejectBody, h as createDeviceSdkPort, ht as isFirstMessageGateBody, i as processStartTimeMs, in as sniffImageMime, it as channelGateMemberOf, j as ENCRYPTED_CREDENTIAL_CODE, jn as readAtRestKey, jt as selectPromoBadge, k as fallbackModelsFor, kn as macosNestedAppBundles, kt as attachBusyLevels, l as createFileRosterSeenStore, ln as imageDefaultFor, m as piAiRuntimeInfo, mt as isCredentialRejectedError, n as clearHostHeartbeat, nn as parseImageDataUrl, nt as WorkBuddyCredentialRejectedError, o as workbuddyHostHeartbeatPath, on as queueNoticeText, ot as conversationIdFromSessionId, p as resolveCnGateway, pt as isConversationIdGateBody, q as workbuddyAccountId, qt as IMAGE_TAG_TEXT_TO_IMAGE, r as isHeartbeatProcessAlive, rn as pickMediaModel, rt as WorkBuddyUpstreamClient, s as writeHostHeartbeat, sn as pruneTempDir, st as declaredTools, t as WORKBUDDY_HOST_HEARTBEAT_FILENAME, tn as isWatermarkFreeImageModel, tt as WORKBUDDY_FALLBACK_SYSTEM_PROMPT, un as nativeModalityOf, ut as forceNeutralHead, v as describeDerivedDevices, vt as modelIdOfBody, w as FALLBACK_WORKBUDDY_MODELS, wn as findWorkbuddyAppExecutable, wt as prepareChatBody, x as saveDeviceProfile, xn as deriveAtRestKey, xt as parseReasoning, y as isDeviceMode, yn as WORKBUDDY_APP_EXECUTABLE_ENV, yt as openingEvidenceOfBody, z as defaultDesktopAuthDirs, zt as VIDEO_TAG_IMAGE_TO_VIDEO } from "./host-heartbeat-Dfhm6kYT.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";
|
|
@@ -1517,12 +1517,18 @@ function workBuddyThinkingLevelMap(info) {
|
|
|
1517
1517
|
* stamped field is what pi-ai resolves the provider BY (issue #75) — so every
|
|
1518
1518
|
* key in {@link modelIdentityKeysOf} must be a key this route registers.
|
|
1519
1519
|
*/
|
|
1520
|
-
function toPiModel(info, baseUrl, identity = WORKBUDDY_MODEL_IDENTITY, midConvoSystemMessages = false) {
|
|
1520
|
+
function toPiModel(info, baseUrl, identity = WORKBUDDY_MODEL_IDENTITY, midConvoSystemMessages = false, sessionAffinity = false) {
|
|
1521
1521
|
const thinkingLevelMap = workBuddyThinkingLevelMap(info);
|
|
1522
|
-
const compat =
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1522
|
+
const compat = {
|
|
1523
|
+
...midConvoSystemMessages ? {
|
|
1524
|
+
supportsReasoningEffort: thinkingLevelMap !== void 0,
|
|
1525
|
+
supportsMidConvoSystemMessages: true
|
|
1526
|
+
} : { supportsReasoningEffort: thinkingLevelMap !== void 0 },
|
|
1527
|
+
...sessionAffinity ? {
|
|
1528
|
+
sendSessionAffinityHeaders: true,
|
|
1529
|
+
sessionAffinityFormat: "openai"
|
|
1530
|
+
} : {}
|
|
1531
|
+
};
|
|
1526
1532
|
return {
|
|
1527
1533
|
id: info.id,
|
|
1528
1534
|
name: workBuddyDisplayName(info),
|
|
@@ -2402,7 +2408,8 @@ function createWorkBuddyAdapter(options) {
|
|
|
2402
2408
|
const buildModels = () => {
|
|
2403
2409
|
const baseUrl = `${shim.baseUrl()}/v1`;
|
|
2404
2410
|
const midConvoSystemMessages = regionOfProvider(providerId) === "cn";
|
|
2405
|
-
|
|
2411
|
+
const sessionAffinity = options.sessionConversationId?.() === true;
|
|
2412
|
+
return catalog.current().map((info) => toPiModel(info, baseUrl, modelIdentity, midConvoSystemMessages, sessionAffinity));
|
|
2406
2413
|
};
|
|
2407
2414
|
const provider = {
|
|
2408
2415
|
...createProvider({
|
|
@@ -5967,6 +5974,20 @@ function createWorkBuddyShim(options) {
|
|
|
5967
5974
|
const keepPromptLastEnabled = options.keepPromptLast === true;
|
|
5968
5975
|
const extraInjectedPrefixes = Array.isArray(options.extraInjectedPrefixes) ? options.extraInjectedPrefixes.filter((entry) => typeof entry === "string" && entry !== "") : [];
|
|
5969
5976
|
const sessionTitleOptions = options.sessionTitle ?? {};
|
|
5977
|
+
/**
|
|
5978
|
+
* Route B (opt-in), read LIVE so the card toggle works without a reload.
|
|
5979
|
+
* pi-ai stamps the host session id on the loopback request as
|
|
5980
|
+
* `x-session-affinity`; we read ONLY that trusted, loopback+bearer-gated
|
|
5981
|
+
* header and map it to a domain-separated digest. The id is never logged,
|
|
5982
|
+
* never forwarded verbatim, and an absent/oversized value is ignored.
|
|
5983
|
+
*/
|
|
5984
|
+
const sessionConversationIdEnabled = options.sessionConversationId;
|
|
5985
|
+
const readSessionConversationId = (req) => {
|
|
5986
|
+
if (sessionConversationIdEnabled?.() !== true) return void 0;
|
|
5987
|
+
const raw = req.headers["x-session-affinity"];
|
|
5988
|
+
const value = typeof raw === "string" ? raw : Array.isArray(raw) ? raw[0] : void 0;
|
|
5989
|
+
return value === void 0 ? void 0 : conversationIdFromSessionId(value);
|
|
5990
|
+
};
|
|
5970
5991
|
const SHARED_SECRET = randomBytes(32).toString("base64url");
|
|
5971
5992
|
/**
|
|
5972
5993
|
* Whether this process's prompts have been PROVEN to need the invisible
|
|
@@ -6124,6 +6145,7 @@ function createWorkBuddyShim(options) {
|
|
|
6124
6145
|
writeOpenAIError(res, 401, "not_signed_in", String(error));
|
|
6125
6146
|
return;
|
|
6126
6147
|
}
|
|
6148
|
+
const sessionConversationId = readSessionConversationId(req);
|
|
6127
6149
|
const raw = (await readBody(req)).toString("utf8");
|
|
6128
6150
|
const prepared = rewriteSessionTitleModel(prepareChatBody(raw, {
|
|
6129
6151
|
keepPromptLast: keepPromptLastEnabled,
|
|
@@ -6136,11 +6158,11 @@ function createWorkBuddyShim(options) {
|
|
|
6136
6158
|
logger?.warn("dsh-connect-workbuddy: body report failed", error);
|
|
6137
6159
|
}
|
|
6138
6160
|
const preferred = channelPerturbation === "always" || channelNeedsPerturbation ? perturbChannelFingerprints(prepared, channelPerturbation === "always") ?? prepared : prepared;
|
|
6139
|
-
let result = await client.chatStream(credential, preferred, controller.signal);
|
|
6161
|
+
let result = await client.chatStream(credential, preferred, controller.signal, sessionConversationId);
|
|
6140
6162
|
if (channelNeedsPerturbation && !result.ok && result.kind === "channel_reject") {
|
|
6141
6163
|
channelNeedsPerturbation = false;
|
|
6142
6164
|
logger?.warn("dsh-connect-workbuddy: a perturbed body was refused too; clearing the learned preference and retrying from the plain form");
|
|
6143
|
-
result = await client.chatStream(credential, prepared, controller.signal);
|
|
6165
|
+
result = await client.chatStream(credential, prepared, controller.signal, sessionConversationId);
|
|
6144
6166
|
}
|
|
6145
6167
|
/**
|
|
6146
6168
|
* The retry ladder that does not depend on knowing the fingerprint
|
|
@@ -6181,14 +6203,14 @@ function createWorkBuddyShim(options) {
|
|
|
6181
6203
|
const forced = forceNeutralHead(prepared);
|
|
6182
6204
|
if (forced !== void 0) {
|
|
6183
6205
|
logger?.warn("dsh-connect-workbuddy: the channel gate refused the body; retrying once with the neutral head forced in front of every opening");
|
|
6184
|
-
result = await client.chatStream(credential, forced, controller.signal);
|
|
6206
|
+
result = await client.chatStream(credential, forced, controller.signal, sessionConversationId);
|
|
6185
6207
|
retriedWithForcedHead = true;
|
|
6186
6208
|
}
|
|
6187
6209
|
if (!result.ok && result.kind === "channel_reject" && !controller.signal.aborted) {
|
|
6188
6210
|
const rescued = perturbChannelFingerprints(forced ?? prepared);
|
|
6189
6211
|
if (rescued !== void 0) {
|
|
6190
6212
|
logger?.warn("dsh-connect-workbuddy: the channel gate refused the body again; retrying once with an invisible perturbation of the scanned text");
|
|
6191
|
-
result = await client.chatStream(credential, rescued, controller.signal);
|
|
6213
|
+
result = await client.chatStream(credential, rescued, controller.signal, sessionConversationId);
|
|
6192
6214
|
retriedWithPerturbation = true;
|
|
6193
6215
|
if (result.ok) channelNeedsPerturbation = true;
|
|
6194
6216
|
}
|
|
@@ -6197,7 +6219,7 @@ function createWorkBuddyShim(options) {
|
|
|
6197
6219
|
const dense = perturbChannelFingerprints(forced ?? prepared, true);
|
|
6198
6220
|
if (dense !== void 0) {
|
|
6199
6221
|
logger?.warn("dsh-connect-workbuddy: the channel gate refused the sparse perturbation too; retrying once with a dense word-boundary perturbation");
|
|
6200
|
-
result = await client.chatStream(credential, dense, controller.signal);
|
|
6222
|
+
result = await client.chatStream(credential, dense, controller.signal, sessionConversationId);
|
|
6201
6223
|
retriedWithDensePerturbation = true;
|
|
6202
6224
|
if (result.ok && channelPerturbation === "failure") channelNeedsPerturbation = true;
|
|
6203
6225
|
}
|
|
@@ -6272,7 +6294,7 @@ function createWorkBuddyShim(options) {
|
|
|
6272
6294
|
switchedFrom ??= describeAccount(credential);
|
|
6273
6295
|
switchedBecause ??= failoverReasonText(result);
|
|
6274
6296
|
credential = next;
|
|
6275
|
-
result = await client.chatStream(credential, prepared, controller.signal);
|
|
6297
|
+
result = await client.chatStream(credential, prepared, controller.signal, sessionConversationId);
|
|
6276
6298
|
}
|
|
6277
6299
|
if (failures.length === 0 || failures[failures.length - 1]?.accountId !== workbuddyAccountId(credential)) recordAttempt(credential, result);
|
|
6278
6300
|
reportFailures();
|
|
@@ -6374,7 +6396,7 @@ function createWorkBuddyShim(options) {
|
|
|
6374
6396
|
const retryTried = [...triedAccountIds, workbuddyAccountId(credential)];
|
|
6375
6397
|
let retryCredential = credential;
|
|
6376
6398
|
for (;;) {
|
|
6377
|
-
const attempt = await client.chatStream(retryCredential, prepared, controller.signal);
|
|
6399
|
+
const attempt = await client.chatStream(retryCredential, prepared, controller.signal, sessionConversationId);
|
|
6378
6400
|
if (attempt.ok) {
|
|
6379
6401
|
writer.discard();
|
|
6380
6402
|
const retried = new RecoveryStream(res, gate, logger);
|
|
@@ -13483,6 +13505,7 @@ const Config = z.object({
|
|
|
13483
13505
|
]).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.")),
|
|
13484
13506
|
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.")),
|
|
13485
13507
|
stableConversationId: asVolatile(z.boolean().default(false).description("A/B 开关(路线 A,默认关):开启时把 X-Conversation-ID 固定为从请求体不变前缀派生的亲和键(其余三件套仍每请求现生成)。该值不是宿主会话标识,不宣称会话隔离,也不证明上游按会话分区;相同前缀的独立会话会共享键。关闭时不进入派生分支。用于离线单变量命中率对照,详见 docs/STABLE-KEY-SEMANTICS.md。改动后需重载插件(配置在挂载时采样一次)。")),
|
|
13508
|
+
sessionConversationId: asVolatile(z.boolean().default(false).description("Route B (默认关): derive the upstream X-Conversation-ID from the HOST session id instead of the request prefix. The session id reaches the loopback shim as pi-ai session-affinity headers and is replaced by a domain-separated digest before anything is sent upstream — the real session id never leaves the process. Independent of route A; takes effect on the next request without a reload. See docs/ROUTE-B-SESSION-ID.md. No upstream cache-key or routing mechanism is asserted.")),
|
|
13486
13509
|
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.")),
|
|
13487
13510
|
/**
|
|
13488
13511
|
* How often the card re-reads the usage document.
|
|
@@ -13907,6 +13930,7 @@ function apply(ctx, config) {
|
|
|
13907
13930
|
logger: ctx.logger,
|
|
13908
13931
|
channelPerturbation: unwrapVolatile(config.channelPerturbation) ?? "failure",
|
|
13909
13932
|
keepPromptLast: unwrapVolatile(config.keepPromptLast) === true,
|
|
13933
|
+
sessionConversationId: () => unwrapVolatile(current().sessionConversationId) === true,
|
|
13910
13934
|
extraInjectedPrefixes: unwrapVolatile(config.extraInjectedPrefixes) ?? [],
|
|
13911
13935
|
sessionTitle: unwrapVolatile(config.sessionTitle) ?? {},
|
|
13912
13936
|
/**
|
|
@@ -15938,6 +15962,7 @@ function apply(ctx, config) {
|
|
|
15938
15962
|
defaultThinkingEfforts: () => regionStateOf(current(), region).defaultThinkingEfforts ?? {},
|
|
15939
15963
|
dropForeignThinking: () => unwrapVolatile(current().dropForeignThinking) === true,
|
|
15940
15964
|
dropAllThinking: () => unwrapVolatile(current().dropAllThinking) === true,
|
|
15965
|
+
sessionConversationId: () => unwrapVolatile(current().sessionConversationId) === true,
|
|
15941
15966
|
onForeignThinking: (blocks) => {
|
|
15942
15967
|
latestForeignThinking = {
|
|
15943
15968
|
blocks,
|
|
@@ -16040,4 +16065,4 @@ function apply(ctx, config) {
|
|
|
16040
16065
|
});
|
|
16041
16066
|
}
|
|
16042
16067
|
//#endregion
|
|
16043
|
-
export { CREDENTIAL_REJECTED_CODE, Config, DEFAULT_PROBE_INPUT_TOKENS, ENCRYPTED_CREDENTIAL_CODE, FALLBACK_WORKBUDDY_MODELS, FALLBACK_WORKBUDDY_MODELS_GLOBAL, NATIVE_MODALITY_BY_MODEL_ID, PROBE_INPUT_TOKEN_CHOICES, PROBE_MAX_TOKENS, PROBE_SYSTEM_PROMPT, REFUSES_OFF_MODEL_IDS, WORKBUDDY_ACCOUNTS_REFRESH_PATH, WORKBUDDY_APP_EXECUTABLE_ENV, WORKBUDDY_AUTH_FILENAME, WORKBUDDY_AUTH_FILE_ENV, WORKBUDDY_CHECKIN_PATH, WORKBUDDY_CONNECT_VERSION, WORKBUDDY_GLOBAL_PROVIDER, WORKBUDDY_HOST_HEARTBEAT_FILENAME, WORKBUDDY_MODELS_REFRESH_PATH, WORKBUDDY_PROBE_PATH, WORKBUDDY_PROVIDER, WORKBUDDY_PROVIDERS, WORKBUDDY_PROVIDER_DISPLAY_NAMES, WORKBUDDY_REGIONS, WORKBUDDY_REGION_PARAM, WORKBUDDY_SETTINGS_NS, WORKBUDDY_STREAM_IDLE_TIMEOUT_MS, WORKBUDDY_TPS_PATH, WORKBUDDY_USAGE_PATH, WorkBuddyCatalog, WorkBuddyCredentialRejectedError, WorkBuddyCredentialStore, WorkBuddyEncryptedCredentialError, WorkBuddyUpstreamClient, apply, asVolatile, authFileName, classifyUpstreamError, clearAtRestKeyCache, clearHostHeartbeat, cooldownOf, createAccountUsabilityProbe, createWorkBuddyAdapter, createWorkBuddyShim, creditOfStream, defaultDesktopAuthCandidates, defaultDesktopAuthDirs, defaultDesktopAuthPath, defaultOffModelIds, deriveAtRestKey, deriveAtRestKeyId, deriveCatalog, deriveStableConversationId, fallbackModelsFor, fetchAtRestKeyPayload, findWorkbuddyAppExecutable, hasEncryptedCredentialFields, imageDefaultFor, imageToolRegionOf, inject, isCredentialRejectedError, isEncryptedCredentialError, isEncryptedFieldWrapper, isHeartbeatProcessAlive, isWorkbuddyBundle, knownRegionOf, legacyAttributionRegion, legacyWorkbuddyOwnAuthPath, macosBundleExecutable, macosNestedAppBundles, modelIdOfBody, name, nativeModalityOf, nextRegionEnabled, nextRegionSlots, offDefaultFor, openEncryptedField, outcomeOfFailure, parseCreditMultiplier, parseReasoning, parseRetryAfter, parseUpstreamModel, parseWorkBuddyAuth, prepareChatBody, probeModel, probeRequestBody, probeSucceeded, processStartTimeMs, readAtRestKey, readHostHeartbeat, realTierAvailabilityFor, regionCleared, regionEnabled, regionEnabledOf, regionOf, regionOfProvider, regionOfStatusUrl, regionStateOf, regionsFieldIsCorrupt, regionsMapOf, registerWorkBuddyStatusRoute, resolveCredentialRecovery, selectAccountFor, settingsNamespaceOf, toPersistedWorkBuddyModel, unwrapVolatileDeep, videoToolRegionOf, withEffectiveOff, withWorkBuddyRegion, workBuddyDisplayName, workBuddyModelInput, workBuddyThinkingLevelMap, workBuddyWebStatus, workbuddyAccountId, workbuddyAppExecutableCandidates, workbuddyHostHeartbeatPath, workbuddyOwnAuthPath, writeHostHeartbeat };
|
|
16068
|
+
export { CREDENTIAL_REJECTED_CODE, Config, DEFAULT_PROBE_INPUT_TOKENS, ENCRYPTED_CREDENTIAL_CODE, FALLBACK_WORKBUDDY_MODELS, FALLBACK_WORKBUDDY_MODELS_GLOBAL, NATIVE_MODALITY_BY_MODEL_ID, PROBE_INPUT_TOKEN_CHOICES, PROBE_MAX_TOKENS, PROBE_SYSTEM_PROMPT, REFUSES_OFF_MODEL_IDS, WORKBUDDY_ACCOUNTS_REFRESH_PATH, WORKBUDDY_APP_EXECUTABLE_ENV, WORKBUDDY_AUTH_FILENAME, WORKBUDDY_AUTH_FILE_ENV, WORKBUDDY_CHECKIN_PATH, WORKBUDDY_CONNECT_VERSION, WORKBUDDY_GLOBAL_PROVIDER, WORKBUDDY_HOST_HEARTBEAT_FILENAME, WORKBUDDY_MODELS_REFRESH_PATH, WORKBUDDY_PROBE_PATH, WORKBUDDY_PROVIDER, WORKBUDDY_PROVIDERS, WORKBUDDY_PROVIDER_DISPLAY_NAMES, WORKBUDDY_REGIONS, WORKBUDDY_REGION_PARAM, WORKBUDDY_SETTINGS_NS, WORKBUDDY_STREAM_IDLE_TIMEOUT_MS, WORKBUDDY_TPS_PATH, WORKBUDDY_USAGE_PATH, WorkBuddyCatalog, WorkBuddyCredentialRejectedError, WorkBuddyCredentialStore, WorkBuddyEncryptedCredentialError, WorkBuddyUpstreamClient, apply, asVolatile, authFileName, classifyUpstreamError, clearAtRestKeyCache, clearHostHeartbeat, conversationIdFromSessionId, cooldownOf, createAccountUsabilityProbe, createWorkBuddyAdapter, createWorkBuddyShim, creditOfStream, defaultDesktopAuthCandidates, defaultDesktopAuthDirs, defaultDesktopAuthPath, defaultOffModelIds, deriveAtRestKey, deriveAtRestKeyId, deriveCatalog, deriveStableConversationId, fallbackModelsFor, fetchAtRestKeyPayload, findWorkbuddyAppExecutable, hasEncryptedCredentialFields, imageDefaultFor, imageToolRegionOf, inject, isCredentialRejectedError, isEncryptedCredentialError, isEncryptedFieldWrapper, isHeartbeatProcessAlive, isWorkbuddyBundle, knownRegionOf, legacyAttributionRegion, legacyWorkbuddyOwnAuthPath, macosBundleExecutable, macosNestedAppBundles, modelIdOfBody, name, nativeModalityOf, nextRegionEnabled, nextRegionSlots, offDefaultFor, openEncryptedField, outcomeOfFailure, parseCreditMultiplier, parseReasoning, parseRetryAfter, parseUpstreamModel, parseWorkBuddyAuth, prepareChatBody, probeModel, probeRequestBody, probeSucceeded, processStartTimeMs, readAtRestKey, readHostHeartbeat, realTierAvailabilityFor, regionCleared, regionEnabled, regionEnabledOf, regionOf, regionOfProvider, regionOfStatusUrl, regionStateOf, regionsFieldIsCorrupt, regionsMapOf, registerWorkBuddyStatusRoute, resolveCredentialRecovery, selectAccountFor, settingsNamespaceOf, toPersistedWorkBuddyModel, unwrapVolatileDeep, videoToolRegionOf, withEffectiveOff, withWorkBuddyRegion, workBuddyDisplayName, workBuddyModelInput, workBuddyThinkingLevelMap, workBuddyWebStatus, workbuddyAccountId, workbuddyAppExecutableCandidates, workbuddyHostHeartbeatPath, workbuddyOwnAuthPath, writeHostHeartbeat };
|
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.24.
|
|
5
|
+
"version": "5.24.10",
|
|
6
6
|
"author": "dingminhua",
|
|
7
7
|
"copyright": "Copyright (c) 2026 LaoDing",
|
|
8
8
|
"license": "MIT",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"docs/assets",
|
|
46
46
|
"docs/PRIVACY.md",
|
|
47
47
|
"docs/STABLE-KEY-SEMANTICS.md",
|
|
48
|
+
"docs/ROUTE-B-SESSION-ID.md",
|
|
48
49
|
"screenshots.json",
|
|
49
50
|
"cordis.patch.yml",
|
|
50
51
|
"README.md",
|