@refeain/dsh-xdpool 3.0.6 → 3.0.8

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 CHANGED
@@ -1,6 +1,33 @@
1
1
  # Changelog
2
2
  本项目的所有重要变更都会记录在此文件。
3
3
  版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
+ ## 3.0.7 — UI 错位修复、一键更新真正生效、代际守卫
5
+
6
+ ### UI 错位:账号卡回到正确的列
7
+
8
+ 3.0.4 起插件池账号卡被挂成了 `.app` 的网格子项。`.app` 是「功能栏 | 渠道列表 | 详情」三列,
9
+ 而 `display:contents` 容器让新增的 `section` 直接参与网格排列,把渠道列表和详情挤到第二行、
10
+ 被 `overflow:hidden` 裁掉 —— 账号池页整页错乱。
11
+
12
+ 现在账号卡由 `ChannelPoolSection` 渲染进**详情列的 `.mbody`**(和提示条同一条通路),
13
+ 并且只在选中 WorkBuddy 国内版 / 国际版时显示;选 CodeArts 等其它渠道、或未选渠道时不显示。
14
+ 结构复用设计稿的 `.sec / .sec-head / .accts / .acct*` 类名,没有新造一套样式。
15
+
16
+ ### 一键更新:之前从来没有真正生效过
17
+
18
+ 更新接口原来只改 profile 的 `package.json`,不碰 `pnpm-lock.yaml`。DSH 下次启动按 lockfile
19
+ 安装(或 frozen-lockfile 校验失败后从快照恢复),spec 被打回旧版本 —— 用户看到的就是
20
+ 「点了一键更新,版本号一直没变」。现在写完后调用 pnpm 同步 **package.json / lockfile /
21
+ node_modules** 三处;同步失败会回滚 manifest,宁可这次没更新,也不留下半更新的 profile。
22
+
23
+ ### pi-ai 代际守卫不再空转
24
+
25
+ 宿主模块路径原来多拼了一层 `node_modules`(`…/node_modules/node_modules/…`),
26
+ 守卫永远返回 `unknown` 且日志里和「对齐」一样静默 —— 真正撞上 0.82 / 1.5 代际错配时
27
+ (切到 xdpool 系模型第一条就报 PI_AI_ERROR)没有任何线索。现在先用 `createRequire` 解析
28
+ 宿主包,失败再退回少一层的相对路径;`unknown` / `aligned` / `mismatch` 都会写 startup.log。
29
+ README 补了「profile 需 `pnpm.overrides` 把 pi-ai 钉到宿主代」的说明。
30
+
4
31
  ## 3.0.6 — 账号卡重做,撤掉没用的关闭按钮
5
32
 
6
33
  3.0.4 把账号卡挂回账号池页时,直接用了 2.x 的 `AccountBlock`:它的根元素是渠道行的类名
package/README.md CHANGED
@@ -9,6 +9,12 @@
9
9
 
10
10
  ## 更新公告
11
11
 
12
+ **3.0.7** — UI 错位修复、一键更新真正生效、代际守卫不再空转。
13
+
14
+ - 修复账号池页整页错乱:账号卡回到详情列里,只在选中 WorkBuddy 国内版/国际版时显示
15
+ - 修复一键更新「更新了但版本号一直没变」:现在会同步 lockfile 和 node_modules,不再被 DSH 启动时装回旧版
16
+ - pi-ai 代际守卫修正宿主路径,mismatch / aligned / unknown 都会写进启动日志,切 xdpool 模型崩溃时不再毫无线索
17
+
12
18
  **3.0.6** — 账号卡重做。
13
19
 
14
20
  - 账号池页的账号卡重画成自包含的卡片:昵称、状态徽章(当前使用 / 已停用 / 冷却中)、令牌到期、积分、以及优先/停用/签到/移出池子一排按钮
@@ -300,6 +306,22 @@ xdpool:
300
306
  - **构建**
301
307
  `tsdown` 产出 `lib/index.js`(宿主入口)+ `lib/index.d.ts`(类型)+ `lib/bin.js`(CLI)+ `lib/client.js`(CJS,用 `window.__ModuleLoader__.load` 包起来的浏览器 bundle)。四个产物都随仓库提交,所以安装时不需要任何构建脚本。
302
308
 
309
+ ## π-ai 代际对齐(重要)
310
+
311
+ 本插件在宿主里用 pi-ai 组装 provider,宿主适配器用**它自己**那份 pi-ai 消费事件流。
312
+ 两份大版本不一致时(典型:插件侧 0.82.x、宿主侧 1.5.x),第一次请求就会崩在适配器接缝,
313
+ 宿主把它归成不可重试的 `PI_AI_ERROR` —— 现象是「切到 xdpool 系模型,第一条就没内容」。
314
+
315
+ 如何确认:重启 DSH 后看 `~/.dsh/.xdpool/startup.log`,会写 `pi-ai generation: aligned at …`
316
+ 或 `mismatch`。一旦看到 mismatch,在 profile 的 `package.json` 里钉到宿主代:
317
+
318
+ ```json
319
+ { "pnpm": { "overrides": { "@earendil-works/pi-ai": "<宿主版本>" } } }
320
+ ```
321
+
322
+ 然后重装依赖并重启。日志里写 `unknown` 表示两侧只读到一份(比如宿主把它打进了 bundle),
323
+ 插件会继续工作,但代际无法自动核对。
324
+
303
325
  ## 已知限制
304
326
 
305
327
  - **WorkBuddy 主账号的登录仍走桌面 App**:XD Pool 可以为插件自己的二十多家登录渠道发起登录,但 WorkBuddy 本体的 token 由桌面 App 的腾讯 SSO 铸造并和设备绑定,池不会替你登录 WorkBuddy。加号 = 在桌面 App 里登录 / 切换,XD Pool 自动吸收。
package/lib/bin.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import { createDecipheriv, createHash, randomUUID } from "node:crypto";
2
3
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
3
4
  import { chmod, copyFile, mkdir, readFile, readdir, rename, rm, unlink, writeFile, writeFile as writeFile$1 } from "node:fs/promises";
@@ -190,6 +191,23 @@ const SESSION_DEAD_MARKERS = [
190
191
  */
191
192
  const ALREADY_CHECKIN_MARKERS = ["已签到", "already"];
192
193
  /**
194
+ * 签到相关的业务码。
195
+ *
196
+ * 上游用 `code` 区分三种「不是成功也不是故障」的结果,而我们此前一律当失败抛出:
197
+ * 今天已经领过(1001/10001)会在每次自动领取时记一条失败;活动未开放(1002/1003/
198
+ * 40901/41000)也会,而且永远重试不到结果。它们必须分开对待:
199
+ *
200
+ * 已领 → 幂等成功(今天的分就在账上,不是错)
201
+ * 未开放 → inactive(等下一次,不报错、不重试)
202
+ */
203
+ const CHECKIN_ALREADY_CODES = /* @__PURE__ */ new Set([1001, 10001]);
204
+ const CHECKIN_INACTIVE_CODES = /* @__PURE__ */ new Set([
205
+ 1002,
206
+ 1003,
207
+ 40901,
208
+ 41e3
209
+ ]);
210
+ /**
193
211
  * Markers for "there is no compensation offer to collect".
194
212
  *
195
213
  * The offer is seasonal — an outage announcement opens one, and it closes on a
@@ -575,7 +593,17 @@ function billingHeaders(credential) {
575
593
  const headers = {
576
594
  "Authorization": `Bearer ${credential.accessToken}`,
577
595
  "Accept": "application/json",
578
- "Content-Type": "application/json"
596
+ "Content-Type": "application/json",
597
+ /**
598
+ * 产品身份头 —— 缺了它们,计费/签到端点会把请求当成「不是客户端发的」。
599
+ *
600
+ * 这三个头一直在客户端那边发(网页/IDE 的每个 billing 请求都带),我们只发了
601
+ * Authorization + X-Domain + X-User-Id。上游收紧校验之后,签到就只剩一个笼统的
602
+ * 失败,看不出原因。UA 用本插件已经在别处使用的桌面版本号,不再另造一个。
603
+ */
604
+ "X-Product": "SaaS",
605
+ "X-Product-Code": "workbuddy",
606
+ "User-Agent": DESKTOP_UA
579
607
  };
580
608
  if (credential.uid !== "" && credential.uid !== void 0) headers["X-User-Id"] = credential.uid;
581
609
  if (credential.enterpriseId !== void 0 && credential.enterpriseId !== "") {
@@ -1466,6 +1494,17 @@ var WorkBuddyUpstreamClient = class {
1466
1494
  signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
1467
1495
  });
1468
1496
  const envelope = await readEnvelope(response);
1497
+ if (response.ok && CHECKIN_INACTIVE_CODES.has(envelope.code)) return {
1498
+ active: false,
1499
+ todayCheckedIn: false,
1500
+ streakDays: 0,
1501
+ dailyCredit: 0,
1502
+ todayCredit: 0,
1503
+ isStreakDay: false,
1504
+ nextStreakDay: 0,
1505
+ streakBonusDays: 0,
1506
+ streakBonusCredit: 0
1507
+ };
1469
1508
  if (!response.ok || envelope.code !== 0) throw envelopeError(response.status, envelope);
1470
1509
  const data = typeof envelope.data === "object" && envelope.data !== null ? envelope.data : {};
1471
1510
  const num = (key) => typeof data[key] === "number" ? data[key] : 0;
@@ -1491,8 +1530,22 @@ var WorkBuddyUpstreamClient = class {
1491
1530
  signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
1492
1531
  });
1493
1532
  const envelope = await readEnvelope(response);
1533
+ const neutral = (data_) => ({
1534
+ credit: 0,
1535
+ streakDays: typeof data_["streak_days"] === "number" ? data_["streak_days"] : 0,
1536
+ isStreakDay: false
1537
+ });
1538
+ const payload = typeof envelope.data === "object" && envelope.data !== null ? envelope.data : {};
1539
+ /**
1540
+ * 已领过(1001/10001)就是成功:今天的分在账上,重复领取不该被记成失败 ——
1541
+ * 自动化每小时跑一次,记成失败会刷出一整片红字。
1542
+ *
1543
+ * 未开放(1002/1003/40901/41000)同样是「今天没有可领的」,不是故障;
1544
+ * 抛错会让调度器一直重试一个永远不会成功的结果。
1545
+ */
1546
+ if (response.ok && (CHECKIN_ALREADY_CODES.has(envelope.code) || CHECKIN_INACTIVE_CODES.has(envelope.code))) return neutral(payload);
1494
1547
  if (!response.ok || envelope.code !== 0) throw envelopeError(response.status, envelope);
1495
- const data = typeof envelope.data === "object" && envelope.data !== null ? envelope.data : {};
1548
+ const data = payload;
1496
1549
  const numberField = (key) => typeof data[key] === "number" ? data[key] : 0;
1497
1550
  return {
1498
1551
  credit: numberField("credit"),
@@ -4931,6 +4984,22 @@ var WorkBuddyAccountPool = class {
4931
4984
  * Returns true when the token is known good afterwards (refreshed, or still
4932
4985
  * valid), false when the credential was proven dead.
4933
4986
  */
4987
+ /**
4988
+ * 取一个账号「可以用来发一次请求」的凭据:过期就先刷新。
4989
+ *
4990
+ * 签到 / 积分这些端点走的是「按 id 直接找账号」的路径,和选号路径不同 ——
4991
+ * 以前它们直接拿池里的 `account.credential`,凭据过期时上游回 401,界面只能
4992
+ * 说「领取失败」,而同一时刻对话却正常(对话走 `getAvailableAccount`,那里会
4993
+ * 先 `ensureFresh`)。用户反馈的「积分领取全部失败」就是这一处。
4994
+ *
4995
+ * 返回 undefined 表示「刷新失败」:调用方应当直接告诉用户重新登录,
4996
+ * 而不是拿旧 token 再去撞一次 401。
4997
+ */
4998
+ async freshCredential(id) {
4999
+ const account = this.accounts.find((item) => item.id === id);
5000
+ if (account === void 0) return void 0;
5001
+ return await this.ensureFresh(account) ? account.credential : void 0;
5002
+ }
4934
5003
  async ensureFresh(account, force = false) {
4935
5004
  if (this.client === void 0) return true;
4936
5005
  const credential = account.credential;
@@ -12643,10 +12712,25 @@ async function writePreferredId(accountId, path = preferredIdPath()) {
12643
12712
  }
12644
12713
  fileURLToPath(new URL("..", import.meta.url));
12645
12714
  (() => {
12715
+ /**
12716
+ * issue #208:原来用 `../../node_modules/@deepseek-ai/dsh-llm-pi-ai/`:
12717
+ * `import.meta.url` 是 `<profile>/node_modules/dsh-xdpool/lib/index.js`,`../../`
12718
+ * 已经落到 `<profile>/node_modules/`,再拼 `node_modules/...` 就成了
12719
+ * `<profile>/node_modules/node_modules/...` —— 多一层,永远解析不到,守卫因此
12720
+ * 长期返回 unknown、日志里一个字都不写,而真正的 0.82 / 1.5 代际错配照样崩。
12721
+ *
12722
+ * 现在优先用 createRequire 从插件自身解析宿主包(pnpm / hoisted / 全局安装都
12723
+ * 能覆盖),再退回少一层的相对路径。createRequire 在 ESM bundle 里也可用。
12724
+ */
12646
12725
  try {
12647
- return fileURLToPath(new URL("../../node_modules/@deepseek-ai/dsh-llm-pi-ai/", import.meta.url));
12726
+ const require_ = createRequire(import.meta.url);
12727
+ return dirname(require_.resolve("@deepseek-ai/dsh-llm-pi-ai/package.json"));
12648
12728
  } catch {
12649
- return "";
12729
+ try {
12730
+ return fileURLToPath(new URL("../node_modules/@deepseek-ai/dsh-llm-pi-ai/", import.meta.url));
12731
+ } catch {
12732
+ return "";
12733
+ }
12650
12734
  }
12651
12735
  })();
12652
12736
  /**
package/lib/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  window.__ModuleLoader__.load({
2
- id: "dsh-xdpool",
2
+ id: "@refeain/dsh-xdpool",
3
3
  factory: (require) => {
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
@@ -269,7 +269,7 @@ window.__ModuleLoader__.load({
269
269
  const POOL_NAV_ICON_MASK_URL = `data:image/svg+xml;utf8,${encodeURIComponent(POOL_NAV_ICON_SVG)}`;
270
270
  //#endregion
271
271
  //#region src/version.ts
272
- const POOL_VERSION = "3.0.6";
272
+ const POOL_VERSION = "3.0.8";
273
273
  function compareVersions(left, right) {
274
274
  const parse = (value) => {
275
275
  const [core, ...rest] = value.trim().replace(/^v/u, "").split("-");
@@ -15286,7 +15286,9 @@ window.__ModuleLoader__.load({
15286
15286
  })]
15287
15287
  });
15288
15288
  }
15289
- Object.freeze({
15289
+ //#endregion
15290
+ //#region src/client/region-card.tsx
15291
+ const REGION_CHANNEL_BY_REGION = Object.freeze({
15290
15292
  cn: "buddy",
15291
15293
  global: "workbuddy"
15292
15294
  });
@@ -16510,6 +16512,7 @@ window.__ModuleLoader__.load({
16510
16512
  };
16511
16513
  t?.("row.title");
16512
16514
  t?.("row.desc");
16515
+ const showPoolAccounts = selectedChannel === REGION_CHANNEL_BY_REGION.cn || selectedChannel === REGION_CHANNEL_BY_REGION.global;
16513
16516
  return (0, react_jsx_runtime.jsx)(PoolShell, {
16514
16517
  t,
16515
16518
  version: POOL_VERSION,
@@ -16550,7 +16553,7 @@ window.__ModuleLoader__.load({
16550
16553
  style: { display: "contents" },
16551
16554
  children: (0, react_jsx_runtime.jsx)(ChannelPoolSection, {
16552
16555
  t,
16553
- regionCards: ["cn", "global"].map((region) => {
16556
+ regionCards: showPoolAccounts ? ["cn", "global"].map((region) => {
16554
16557
  const here = statusOf(region);
16555
16558
  const rows = here?.accounts ?? [];
16556
16559
  if (rows.length === 0) return null;
@@ -16563,7 +16566,7 @@ window.__ModuleLoader__.load({
16563
16566
  children: [region === "cn" ? t?.("row.tabCn") ?? "CN" : t?.("row.tabGlobal") ?? "Global", ` · ${String(rows.length)}`]
16564
16567
  })
16565
16568
  }), (0, react_jsx_runtime.jsx)("div", {
16566
- className: "xdp-accts",
16569
+ className: "accts",
16567
16570
  children: rows.map((account) => (0, react_jsx_runtime.jsx)(AccountCard, {
16568
16571
  account,
16569
16572
  t,
@@ -16585,7 +16588,7 @@ window.__ModuleLoader__.load({
16585
16588
  }, account.id))
16586
16589
  })]
16587
16590
  }, region);
16588
- }),
16591
+ }) : void 0,
16589
16592
  active: selectedChannel,
16590
16593
  onAddAccount: () => {
16591
16594
  setPage("channels");
package/lib/index.d.ts CHANGED
@@ -1716,6 +1716,18 @@ export declare class WorkBuddyAccountPool {
1716
1716
  * Returns true when the token is known good afterwards (refreshed, or still
1717
1717
  * valid), false when the credential was proven dead.
1718
1718
  */
1719
+ /**
1720
+ * 取一个账号「可以用来发一次请求」的凭据:过期就先刷新。
1721
+ *
1722
+ * 签到 / 积分这些端点走的是「按 id 直接找账号」的路径,和选号路径不同 ——
1723
+ * 以前它们直接拿池里的 `account.credential`,凭据过期时上游回 401,界面只能
1724
+ * 说「领取失败」,而同一时刻对话却正常(对话走 `getAvailableAccount`,那里会
1725
+ * 先 `ensureFresh`)。用户反馈的「积分领取全部失败」就是这一处。
1726
+ *
1727
+ * 返回 undefined 表示「刷新失败」:调用方应当直接告诉用户重新登录,
1728
+ * 而不是拿旧 token 再去撞一次 401。
1729
+ */
1730
+ freshCredential(id: string): Promise<WorkBuddyCredential | undefined>;
1719
1731
  private ensureFresh;
1720
1732
  /**
1721
1733
  * Cool a whole account after the upstream reports its credits are spent.