dsh-xdpool 2.6.4 → 2.6.6

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,82 @@
1
1
  # Changelog
2
2
  本项目的所有重要变更都会记录在此文件。
3
3
  版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
+ ## 2.6.6 — 免费线上游已关闭;国际版每日活跃;网关支持非流式
5
+
6
+ > 三处独立改动:一个必须如实说明的坏消息,两个来自社区的修复。
7
+
8
+ ### 免费模型线已被上游关闭(#96)
9
+
10
+ 实测一次裸调用,上游现在回答:
11
+
12
+ ```json
13
+ {"type":"error","error":{"type":"FreeUsageLimitError",
14
+ "message":"Free usage limit reached. Free models work in OpenCode
15
+ (https://opencode.ai); subscribe to OpenCode Go to keep going…"}}
16
+ ```
17
+
18
+ 这既不是指纹失配,也不是「按会话计额」——**上游把免费模型收进了自己的客户端**,第三方的 UA、请求头、路径怎么改都进不去。#96 的「从装上就没成功过」不是我们没修对门禁,而是那道门已经不在了。
19
+
20
+ 原来的提示让人去更新插件,那在门禁还是指纹的年代是对的,现在是一条死路。现在按名字识别 `FreeUsageLimitError`,直接说明这条路已关闭、给出可用的替代(换渠道,或订阅 OpenCode Go)。
21
+
22
+ ### 国际版账号恢复每日活跃上报(PR #138)
23
+
24
+ `scheduler.ts` 原先把 `report` / `streak` 限定为国内版,理由是国际版没有任务中心。这个前提不成立:
25
+
26
+ | 接口 | 国际版实测 |
27
+ |---|---|
28
+ | `POST /v2/report` | `200 {"code":0}` |
29
+ | `GET /activity/growth/streak` | `200`,字段形状与国内版一致 |
30
+ | `GET /activity/growth/tasks` | `200`,返回 5 条任务 |
31
+
32
+ 国际版的机制是:**每个被记录的活跃日,服务端次日凌晨发一个 30 积分的 `Bonus Pack`**,没有领取接口。一个请求就能点亮当天活跃(实测 heatmap 当天 score 从 0 变 2、`streak.days` 从 0 变 1),漏一天就真少 30 积分。
33
+
34
+ 顺带把「签到活动未开启」记为**跳过**而非失败,不再污染失败计数。
35
+
36
+ ### 网关支持 `stream: false`(PR #144)
37
+
38
+ 此前池车道与缓冲车道一律按流式处理,客户端发 `stream: false` 也只拿回 SSE。现在两条车道都按请求体决定,非流式请求返回一个完整 JSON 响应。
39
+
40
+ ## 2.6.5 — 安装不再被判失败,积分面板不再空白
41
+
42
+ > 五张 issue,三个独立根因。前两张是同一件事的两面:2.6.4 的 postinstall 会把**本来能用的安装**判成失败。
43
+
44
+ ### postinstall 不再让安装回滚(#134、#135)
45
+
46
+ 打包版宿主的依赖全在 `app.asar` 里,而 postinstall 跑在裸 Node 进程里——`fs.existsSync` **看不进 asar**,只有 Electron 打过补丁的 `fs` 才行。所以「这里没找到」经常只是「这个进程看不见」,而不是「不存在」。
47
+
48
+ 2.6.3 根本没有 postinstall,在 macOS 上照样能加载:宿主自己在运行时解析这些依赖。2.6.4 的脚本却把探测失败当成安装损坏并 `exit(1)`,于是插件管理器回滚了本来可用的升级。
49
+
50
+ 现在探测不到只输出说明、**正常退出**。只有真正创建链接失败才警告,而那也是警告不是失败。
51
+
52
+ 自检同时改用 **ESM 解析**:`@earendil-works/pi-ai` 是 ESM-only,`exports` 只有 `types` 和 `import`,没有 `require`、也没有 `./package.json` 子路径。`require.resolve` 对它必抛 `ERR_PACKAGE_PATH_NOT_EXPORTED`——包明明装着、能 import,却被判为缺失,这就是 2.6.4 在 Windows 上装不上的原因。
53
+
54
+ 宿主路径探测也补齐了:macOS 的 `/Applications/.../Contents/Resources`、Linux 的 `~/.local/share`,以及**从 `process.execPath` 反推**——报告者的宿主装在 F 盘,所有硬编码的 C 盘猜测都落空。
55
+
56
+ 顺带修好幂等性:`locate()` 现在先看磁盘上的 `node_modules/<name>`,所以已经建好的链接不会被误判为缺失、反复重建。
57
+
58
+ ### 积分面板点开不再空白(#133)
59
+
60
+ `failed || snapshot === undefined` 时整个组件 `return null`,把**触发按钮也一起摘掉**了。新建会话还没有快照,于是圆点先画出来(绿色,来自上一次渲染),随后组件卸载,屏幕上只剩一个空的浮层。
61
+
62
+ 现在圆点永远渲染,数据没到时在面板里说明「正在读取积分…」;读取失败则说失败。状态指示器必须对每一次点击都有回答——「还没加载」是回答,空盒子不是。
63
+
64
+ 未加载时的状态按灰色处理:未知余额不能显示成「你没问题」。
65
+
66
+ ### 空模型选择等于「全部」,不是「一个都不要」(#122)
67
+
68
+ DSH 0.2.2-rc.1 会在选择器首次使用前写入 `enabledModelIds: []`。原代码把空数组当成真实选择,过滤后得到 **0 个模型**,于是卡片上列着 16 个模型,每次请求却报 `has no configured model "<id>"`。
69
+
70
+ 现在空数组与 `undefined` 同等对待。两种状态事后无法区分,所以选了安全的那一侧:空选择等同于没选择,而「全部」一次点击就能改回来,「什么都没有」看起来像装坏了。
71
+
72
+ ### 路由链缺少字段不再让整页崩掉
73
+
74
+ 从磁盘读到的链路可能整个缺 `platforms`,或者某个分组的 `models` 缺失。三个字段原先都是无保护地展开,任何一处缺失都会让路由页崩在 `Cannot read properties of undefined (reading 'length')`——这个报错既不说是哪条链、也不说哪个字段。现在统一归一化。
75
+
76
+ ### 账号池与模型选择器用同一个名字(#119)
77
+
78
+ `buddy` 这条 lane 在插件里叫「WorkBuddy 国内版」,而 vendor 产品常量仍沿用上游旧名「CodeBuddy (腾讯)」,模型选择器的分组名因此和账号池卡片对不上。在呈现层覆盖,不改常量——那个常量还被 429 的报错文案引用着。
79
+
4
80
  ## 2.6.4 — postinstall 真的会跑了
5
81
 
6
82
  2.6.3 的修复方向是对的,但 的改动在合并时丢了:`postinstall` 没挂上,`scripts/` 也没进 `files`。结果是 npm 上的 2.6.3 依然缺 peer 依赖,靠的是此前手动建的 junction。
package/lib/bin.js CHANGED
@@ -1346,8 +1346,18 @@ var WorkBuddyUpstreamClient = class {
1346
1346
  if (models.length === 0) throw new Error("workbuddy model catalog resolved to an empty list");
1347
1347
  return models;
1348
1348
  }
1349
- /** Read-only credits query, aggregated by package. Does not consume credits. */
1350
- async fetchCredits(credential) {
1349
+ /**
1350
+ * Read-only credits query, aggregated by package. Does not consume credits.
1351
+ *
1352
+ * `signal` is the caller's cancellation, merged with the built-in timeout
1353
+ * rather than replacing it: the pool's background warm must give up when the
1354
+ * host shuts down, and a caller that has already gone away must not leave a
1355
+ * 30 s request running. `AbortSignal.any` is already the repo's way of
1356
+ * combining these (see the pricing probe in the shim), and the timeout stays
1357
+ * in force so a signal-less caller keeps the old behaviour exactly.
1358
+ */
1359
+ async fetchCredits(credential, signal) {
1360
+ const timeout = AbortSignal.timeout(JSON_TIMEOUT_MS);
1351
1361
  const now = /* @__PURE__ */ new Date();
1352
1362
  const fmt = (date) => {
1353
1363
  const p = (n) => n.toString().padStart(2, "0");
@@ -1364,7 +1374,7 @@ var WorkBuddyUpstreamClient = class {
1364
1374
  PackageEndTimeRangeBegin: fmt(now),
1365
1375
  PackageEndTimeRangeEnd: fmt(new Date(now.getTime() + 3185136e6))
1366
1376
  }),
1367
- signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
1377
+ signal: signal === void 0 ? timeout : AbortSignal.any([timeout, signal])
1368
1378
  });
1369
1379
  const envelope = await readEnvelope(response);
1370
1380
  if (!response.ok || envelope.code !== 0) throw envelopeError(response.status, envelope);
@@ -3546,6 +3556,13 @@ const EXHAUST_COOLDOWN_MS = 18e5;
3546
3556
  */
3547
3557
  const CREDENTIAL_DEAD_COOLDOWN_MS = 18e5;
3548
3558
  /**
3559
+ * Shortest gap between two attempts at the same account's deadline reading.
3560
+ *
3561
+ * Only failed attempts are actually throttled by this: a successful read stamps
3562
+ * the reading itself, so {@link EXPIRY_READING_TTL_MS} takes over from there.
3563
+ */
3564
+ const EXPIRY_WARM_RETRY_MS = 6e4;
3565
+ /**
3549
3566
  * Does this refresh failure prove the credential itself is dead?
3550
3567
  *
3551
3568
  * The upstream answers a revoked refresh token with `invalid_grant: Offline user
@@ -3574,6 +3591,7 @@ var WorkBuddyAccountPool = class {
3574
3591
  credentialDeadCooldownMs;
3575
3592
  client;
3576
3593
  refreshMarginMs;
3594
+ expiryReadingTtlMs;
3577
3595
  accounts = [];
3578
3596
  /**
3579
3597
  * Files the last scan could not read, with the reason.
@@ -3669,11 +3687,42 @@ var WorkBuddyAccountPool = class {
3669
3687
  * their own cycle and are therefore never urgent — which is why this is
3670
3688
  * written from the same `fetchCredits` reading that fills `creditBalances`.
3671
3689
  *
3672
- * An absent entry means "never probed, or nothing is about to expire". Both
3673
- * are the same thing to `expiry` mode: not urgent, so it sorts last.
3690
+ * A positive value is a deadline. The two other states are kept in
3691
+ * {@link creditExpiryNone} and {@link creditExpiryReadAt} rather than as a
3692
+ * missing key, because a missing key cannot tell "we never looked" from "we
3693
+ * looked and nothing has a deadline" — and only the first is worth reading
3694
+ * again. An account whose packs are all monthly reads as `none` forever, which
3695
+ * is exactly right: asking again cannot change the answer (S1).
3674
3696
  */
3675
3697
  creditExpiry = /* @__PURE__ */ new Map();
3676
3698
  /**
3699
+ * Accounts whose last reading found NO one-off deadline (all monthly packs, or
3700
+ * none at all). Written instead of deleting the key, so the account stops
3701
+ * being a candidate for re-reading.
3702
+ */
3703
+ creditExpiryNone = /* @__PURE__ */ new Set();
3704
+ /** When each account's deadline reading was taken, epoch ms. */
3705
+ creditExpiryReadAt = /* @__PURE__ */ new Map();
3706
+ /**
3707
+ * Accounts whose deadline reading is being fetched right now.
3708
+ *
3709
+ * Same de-duplication idea as {@link refreshInflight}, for the same reason: a
3710
+ * scan-triggered warm and a request-triggered top-up must not both spend a
3711
+ * billing round trip on the same account. A Set rather than a Map of promises
3712
+ * because no caller ever awaits the warm — the point is only that a second
3713
+ * pass skips it.
3714
+ */
3715
+ expiryWarmInflight = /* @__PURE__ */ new Set();
3716
+ /**
3717
+ * Last time the pool tried to warm an account's deadline reading, epoch ms.
3718
+ *
3719
+ * The TTL is the success gate, not a retry gate: a failed read writes nothing,
3720
+ * so without this a permanently failing billing endpoint would be hit on every
3721
+ * scan and every served request. One attempt per account per minute is cheap
3722
+ * and still recovers quickly from a transient failure.
3723
+ */
3724
+ expiryWarmAttemptAt = /* @__PURE__ */ new Map();
3725
+ /**
3677
3726
  * Last time each account served a request, epoch ms. Drives the idle term
3678
3727
  * of the priority-mode weighting below: an account that just served loses to
3679
3728
  * one that has been idle, so a small pool stops hammering a single account.
@@ -3718,6 +3767,7 @@ var WorkBuddyAccountPool = class {
3718
3767
  this.credentialDeadCooldownMs = options.credentialDeadCooldownMs ?? CREDENTIAL_DEAD_COOLDOWN_MS;
3719
3768
  this.client = options.client;
3720
3769
  this.refreshMarginMs = options.refreshMarginMs ?? 3e5;
3770
+ this.expiryReadingTtlMs = options.expiryReadingTtlMs ?? 36e5;
3721
3771
  this.distribution = options.distribution ?? "priority";
3722
3772
  this.persistent = options.persistent ?? false;
3723
3773
  this.storePath = accountStorePath();
@@ -3932,6 +3982,7 @@ var WorkBuddyAccountPool = class {
3932
3982
  ordered.sort((a, b) => compareFreshness(a.credential, b.credential));
3933
3983
  this.accounts = ordered;
3934
3984
  this.lastScanAtMs = Date.now();
3985
+ this.warmExpiryReadings();
3935
3986
  if (this.persistent) try {
3936
3987
  const leaving = this.lastPersistedIds === void 0 ? [] : [...this.lastPersistedIds].filter((id) => !this.accounts.some((account) => account.id === id));
3937
3988
  if (leaving.length > 0) this.logger?.warn?.(`dsh-xdpool: ${String(leaving.length)} account(s) are no longer in the pool after a rescan and were removed from the store: ${leaving.join(", ")}. Their credentials are gone unless they are signed in again.`);
@@ -3942,6 +3993,76 @@ var WorkBuddyAccountPool = class {
3942
3993
  }
3943
3994
  return this.accounts;
3944
3995
  }
3996
+ /**
3997
+ * Warm the deadline readings that `expiry` mode sorts on.
3998
+ *
3999
+ * Fire-and-forget on purpose, from `scan()`: the pool's first request arrives
4000
+ * before any reading exists, and the honest answer to that is the documented
4001
+ * fallback plus a log line, not a stalled request. Everything about the call
4002
+ * is chosen to be unable to make things worse:
4003
+ *
4004
+ * - `this.client` may not exist (a host that wired only token refresh), in
4005
+ * which case there is nothing to read with and the pass is a no-op — the
4006
+ * same guard `ensureFresh` uses;
4007
+ * - a dead sign-in is skipped, and a successful read NEVER calls
4008
+ * `clearCredentialDead`. That is the difference between this and
4009
+ * `reviveBenched`: the billing endpoint answers 200 for a banned account
4010
+ * (observed on 11140), so treating a read as proof of health is what got a
4011
+ * banned account revived six times in a day (S2). Only a token refresh or a
4012
+ * fresh sign-in may clear that mark;
4013
+ * - accounts whose reading is fresh enough are skipped, and so are accounts
4014
+ * already being read (S10's de-duplication, mirroring `refreshInflight`);
4015
+ * - a failed read writes nothing and only warns, so the next pass tries
4016
+ * again without the failure being mistaken for a reading.
4017
+ */
4018
+ warmExpiryReadings() {
4019
+ if (this.client?.fetchCredits === void 0) return;
4020
+ for (const account of this.accounts) this.warmExpiryReadingFor(account.id);
4021
+ }
4022
+ /** One account's warm read; see {@link warmExpiryReadings} for the rules. */
4023
+ async warmOneExpiryReading(account, client) {
4024
+ this.expiryWarmInflight.add(account.id);
4025
+ this.expiryWarmAttemptAt.set(account.id, Date.now());
4026
+ try {
4027
+ const credits = await client.fetchCredits(account.credential);
4028
+ this.noteExpiryOnly(account.id, credits.nearestExpiryMs);
4029
+ } catch (error) {
4030
+ this.logger?.warn?.(`dsh-xdpool: could not read credit deadlines for ${account.label} (read failed); expiry mode keeps falling back for it until a read succeeds`, error);
4031
+ } finally {
4032
+ this.expiryWarmInflight.delete(account.id);
4033
+ }
4034
+ }
4035
+ /**
4036
+ * Top up one account's deadline reading, from wherever the pool notices it is
4037
+ * missing or stale.
4038
+ *
4039
+ * The request path is the second caller (after `scan()`), because a reading
4040
+ * ages out while the pool is busy too: the shim calls this for the account that
4041
+ * just served a request, which is the one whose spend is most likely to have
4042
+ * moved its deadline. No timer is created — the existing balance refresh is
4043
+ * already the natural heartbeat, and this rides on it.
4044
+ *
4045
+ * Every gate lives here rather than in the callers, so both paths obey exactly
4046
+ * the same rules: no client, no account, a rejected sign-in, an already-running
4047
+ * read, a finished "nothing expires" answer, a fresh reading, or an attempt
4048
+ * made within the last minute all mean "do nothing".
4049
+ */
4050
+ warmExpiryReadingFor(accountId) {
4051
+ if (this.distribution !== "expiry") return;
4052
+ const client = this.client;
4053
+ if (client?.fetchCredits === void 0) return;
4054
+ const account = this.accounts.find((item) => item.id === accountId);
4055
+ if (account === void 0) return;
4056
+ const now = Date.now();
4057
+ if ((account.credentialDeadUntilMs ?? 0) > now) return;
4058
+ if (this.expiryWarmInflight.has(accountId)) return;
4059
+ const reading = this.expiryReadingOf(accountId, now);
4060
+ if (reading.state === "none") return;
4061
+ if (reading.state === "at" && !reading.stale) return;
4062
+ const lastAttempt = this.expiryWarmAttemptAt.get(accountId) ?? 0;
4063
+ if (lastAttempt > (reading.readAtMs ?? 0) && now - lastAttempt < EXPIRY_WARM_RETRY_MS) return;
4064
+ this.warmOneExpiryReading(account, client);
4065
+ }
3945
4066
  /** All accounts, cooldown state included. */
3946
4067
  list(region) {
3947
4068
  if (region === void 0) return this.accounts;
@@ -4289,18 +4410,37 @@ var WorkBuddyAccountPool = class {
4289
4410
  * A pool where nobody has a known expiry therefore behaves exactly like
4290
4411
  * priority, which is the honest degradation: without a reading there is
4291
4412
  * nothing to sort by.
4413
+ *
4414
+ * What this method must NOT do is pretend. With only SOME readings in hand it
4415
+ * still has to fall back to `pool[0]`, because picking the earliest of the
4416
+ * accounts that happen to have answered would silently drop the account that
4417
+ * really dies first — the failure mode S0 in `EXPIRY-ADVERSARIAL-20261111.md`
4418
+ * called "worse than not fixing it", since the pick looks plausible and is
4419
+ * wrong. So the incomplete case is announced instead: the caller keeps the old
4420
+ * semantics and the log says which accounts were not read.
4292
4421
  */
4293
4422
  pickByExpiry(pool) {
4423
+ const now = Date.now();
4424
+ const unread = [];
4425
+ const stale = [];
4294
4426
  let best;
4295
4427
  let bestAt = Number.POSITIVE_INFINITY;
4296
4428
  for (const account of pool) {
4297
- const at = this.creditExpiry.get(account.id);
4298
- if (at === void 0) continue;
4429
+ const reading = this.expiryReadingOf(account.id, now);
4430
+ if (reading.stale) stale.push(account);
4431
+ if (reading.state === "unread" || reading.stale) {
4432
+ unread.push(account);
4433
+ continue;
4434
+ }
4435
+ if (reading.state === "none") continue;
4436
+ const at = reading.at ?? Number.POSITIVE_INFINITY;
4299
4437
  if (at < bestAt) {
4300
4438
  best = account;
4301
4439
  bestAt = at;
4302
4440
  }
4303
4441
  }
4442
+ if (stale.length > 0) this.logger?.info?.(`dsh-xdpool: expiry mode found ${stale.length} deadline reading(s) older than ${Math.round(this.expiryReadingTtlMs / 6e4)} minute(s) (${stale.map((account) => account.label).join(", ")}); they are being topped up in the background`);
4443
+ if (unread.length > 0) this.logger?.warn?.(`dsh-xdpool: expiry mode has no deadline reading for ${unread.length} of ${pool.length} account(s) (${unread.map((account) => account.label).join(", ")}); falling back to pool order for this pick, which may not be the soonest to expire. Readings are filled in the background after a scan and by the request path.`);
4304
4444
  return best ?? pool[0];
4305
4445
  }
4306
4446
  /**
@@ -4478,21 +4618,91 @@ var WorkBuddyAccountPool = class {
4478
4618
  * merged: a pack that has been spent or has died disappears from the next
4479
4619
  * reading, and keeping the stale deadline would pin the pool to an account
4480
4620
  * whose credits are already gone — the opposite of what `expiry` mode wants.
4621
+ *
4622
+ * "Nothing expires" is a real answer, not the absence of one: it is stored as
4623
+ * {@link creditExpiryNone} so the account is not read again on every pass.
4481
4624
  */
4482
4625
  noteCredits(accountId, balance, nearestExpiryMs) {
4483
4626
  if (!Number.isFinite(balance)) return;
4484
4627
  if (!this.accounts.some((account) => account.id === accountId)) return;
4485
4628
  this.creditBalances.set(accountId, balance);
4629
+ this.noteExpiryReading(accountId, nearestExpiryMs);
4630
+ }
4631
+ /**
4632
+ * Record ONLY the deadline, never the balance.
4633
+ *
4634
+ * The scan-triggered warm exists to fill `expiry` mode's sort key. Writing the
4635
+ * balance as a side effect would change what the reserve floor decides — an
4636
+ * account could be pulled out of rotation by a background read the user never
4637
+ * asked for, which is a behaviour change outside this fix's scope (S7 in
4638
+ * `EXPIRY-ADVERSARIAL-20261111.md`; the reserve's own cold-start hole is V4,
4639
+ * fixed separately).
4640
+ */
4641
+ noteExpiryOnly(accountId, nearestExpiryMs) {
4642
+ if (!this.accounts.some((account) => account.id === accountId)) return;
4643
+ this.noteExpiryReading(accountId, nearestExpiryMs);
4644
+ }
4645
+ /**
4646
+ * The three-state writer both entry points funnel through.
4647
+ *
4648
+ * One place, so the invariant "a finished reading always leaves a state" can be
4649
+ * read off a single function: either a deadline is stored, or the account joins
4650
+ * `creditExpiryNone`. Nothing here deletes the read stamp — that is what makes
4651
+ * "read, found nothing" distinguishable from "never read".
4652
+ */
4653
+ noteExpiryReading(accountId, nearestExpiryMs) {
4654
+ this.creditExpiryReadAt.set(accountId, Date.now());
4486
4655
  if (nearestExpiryMs === void 0 || !Number.isFinite(nearestExpiryMs)) {
4487
4656
  this.creditExpiry.delete(accountId);
4657
+ this.creditExpiryNone.add(accountId);
4488
4658
  return;
4489
4659
  }
4660
+ this.creditExpiryNone.delete(accountId);
4490
4661
  this.creditExpiry.set(accountId, nearestExpiryMs);
4491
4662
  }
4492
4663
  /** Nearest one-off pack expiry for one account, or undefined when none known. */
4493
4664
  creditExpiryOf(accountId) {
4494
4665
  return this.creditExpiry.get(accountId);
4495
4666
  }
4667
+ /**
4668
+ * The full three-state reading for one account, including staleness.
4669
+ *
4670
+ * `stale` is evaluated against {@link EXPIRY_READING_TTL_MS} here rather than
4671
+ * baked into the stored value, so the TTL stays a constant of the policy and
4672
+ * not of the data.
4673
+ *
4674
+ * Only a real deadline can go stale. "We never asked" is not a reading, and
4675
+ * "nothing here has a deadline" does not become less true with age: a monthly
4676
+ * pack does not grow an expiry date by waiting. Keeping `none` permanently
4677
+ * valid is what makes the S1 loop impossible — an account that answered once
4678
+ * is never read again by the expiry machinery, so there is no predicate that
4679
+ * can stay true forever and re-read it on every pass. If such an account does
4680
+ * gain a one-off pack later, the card refresh (which writes through
4681
+ * `noteCredits` on every poll) is what notices.
4682
+ */
4683
+ expiryReadingOf(accountId, now = Date.now()) {
4684
+ const at = this.creditExpiry.get(accountId);
4685
+ const readAtMs = this.creditExpiryReadAt.get(accountId);
4686
+ if (readAtMs === void 0) return {
4687
+ state: "unread",
4688
+ stale: false
4689
+ };
4690
+ if (at !== void 0) return {
4691
+ state: "at",
4692
+ at,
4693
+ readAtMs,
4694
+ stale: now - readAtMs > this.expiryReadingTtlMs
4695
+ };
4696
+ if (this.creditExpiryNone.has(accountId)) return {
4697
+ state: "none",
4698
+ readAtMs,
4699
+ stale: false
4700
+ };
4701
+ return {
4702
+ state: "unread",
4703
+ stale: false
4704
+ };
4705
+ }
4496
4706
  /** Last known balance for one account, or undefined when never read. */
4497
4707
  creditsOf(accountId) {
4498
4708
  return this.creditBalances.get(accountId);
@@ -5011,7 +5221,21 @@ var WorkBuddyCatalog = class {
5011
5221
  */
5012
5222
  visible() {
5013
5223
  const enabled = this.selection.enabledModelIds;
5014
- const allow = enabled === void 0 ? void 0 : new Set(enabled);
5224
+ /**
5225
+ * An EMPTY list means "nothing has been chosen yet", not "serve nothing".
5226
+ *
5227
+ * `undefined` was already treated as "all enabled", but `[]` fell through to an empty
5228
+ * allow-set and filtered out every model. A host that writes the legacy key with a
5229
+ * default `[]` — DSH 0.2.2-rc.1 does exactly that before the picker has ever been
5230
+ * used — therefore made this catalog publish ZERO models, and the picker and every
5231
+ * "test" call reported `has no configured model "<id>"` for models that were plainly
5232
+ * listed on the card (issue #122).
5233
+ *
5234
+ * The two states cannot be distinguished by intent afterwards, so the safe reading is
5235
+ * chosen: an empty selection is indistinguishable from no selection, and "everything"
5236
+ * is recoverable in one click whereas "nothing" looks like a broken install.
5237
+ */
5238
+ const allow = enabled === void 0 || enabled.length === 0 ? void 0 : new Set(enabled);
5015
5239
  const images = this.selection.imageModelIds;
5016
5240
  const imageSet = images === void 0 ? void 0 : new Set(images);
5017
5241
  const budgets = this.selection.contextBudgets;
package/lib/client.js CHANGED
@@ -10340,12 +10340,22 @@ window.__ModuleLoader__.load({
10340
10340
  * can serve right now. Dropping them would make a save silently delete members
10341
10341
  * the user never asked to remove — the "保存了没法用" class of data loss.
10342
10342
  */
10343
- const platforms = combo.platforms.map((group) => ({
10344
- owner: group.owner,
10345
- models: [...group.models]
10343
+ /**
10344
+ * A chain read from disk may be missing `platforms` entirely — an older shape, a
10345
+ * hand-edited file, or a partial write — and either level can be absent:
10346
+ * `platforms` itself, or one group's `models` array inside it.
10347
+ *
10348
+ * Both used to be spread unguarded, so a chain in either state crashed the whole
10349
+ * routing page with `Cannot read properties of undefined (reading 'length')` — a
10350
+ * message that names neither the chain nor the field, leaving nothing to act on.
10351
+ * Normalising here means every reader below can treat the shape as total.
10352
+ */
10353
+ const platforms = (Array.isArray(combo.platforms) ? combo.platforms : []).filter((group) => group !== null && typeof group === "object").map((group) => ({
10354
+ owner: typeof group.owner === "string" ? group.owner : "workbuddy",
10355
+ models: Array.isArray(group.models) ? [...group.models].filter((model) => typeof model === "string") : []
10346
10356
  }));
10347
- const known = new Set(combo.models);
10348
- for (const modelId of combo.missing) {
10357
+ const known = new Set(Array.isArray(combo.models) ? combo.models : []);
10358
+ for (const modelId of Array.isArray(combo.missing) ? combo.missing : []) {
10349
10359
  if (known.has(modelId)) continue;
10350
10360
  const slash = modelId.indexOf("/");
10351
10361
  const owner = slash === -1 ? "workbuddy" : modelId.slice(0, slash);
@@ -10362,7 +10372,7 @@ window.__ModuleLoader__.load({
10362
10372
  id: combo.id,
10363
10373
  name: combo.name,
10364
10374
  platforms,
10365
- flat: [...combo.models, ...combo.missing.filter((id) => !combo.models.includes(id))],
10375
+ flat: [...Array.isArray(combo.models) ? combo.models : [], ...(Array.isArray(combo.missing) ? combo.missing : []).filter((id) => !(Array.isArray(combo.models) ? combo.models : []).includes(id))],
10366
10376
  strategy: combo.strategy,
10367
10377
  stickyLimit: combo.stickyLimit,
10368
10378
  enabled: combo.enabled
@@ -13460,7 +13470,7 @@ window.__ModuleLoader__.load({
13460
13470
  *
13461
13471
  * @module dsh-xdpool/version
13462
13472
  */
13463
- const POOL_VERSION = "2.6.4";
13473
+ const POOL_VERSION = "2.6.6";
13464
13474
  //#endregion
13465
13475
  //#region src/client/PoolCard.tsx
13466
13476
  /**
@@ -16413,7 +16423,23 @@ window.__ModuleLoader__.load({
16413
16423
  document.removeEventListener("keydown", onKey);
16414
16424
  };
16415
16425
  }, [open]);
16416
- if (failed || snapshot === void 0) return null;
16426
+ /**
16427
+ * The dot itself is never withheld.
16428
+ *
16429
+ * `failed || snapshot === undefined` used to `return null` for the WHOLE component, which
16430
+ * removed the trigger as well as the panel. The reported symptom was "clicking the green
16431
+ * credit icon opens a blank page": a newly created session has no snapshot yet, so the dot
16432
+ * briefly existed (green, from an earlier paint) and then the component unmounted, leaving
16433
+ * an empty popover shell on screen.
16434
+ *
16435
+ * Rendering the dot unconditionally and explaining the absence INSIDE the panel is the
16436
+ * only version where a click always produces an answer — which is the entire job of a
16437
+ * status indicator.
16438
+ *
16439
+ * `snapshot === undefined` before the first successful load reads as grey: an unknown
16440
+ * balance must not be presented as "you are fine".
16441
+ */
16442
+ const ready = snapshot !== void 0 && !failed;
16417
16443
  /**
16418
16444
  * Green when the serving channel still has credits, grey when it does not.
16419
16445
  *
@@ -16421,7 +16447,7 @@ window.__ModuleLoader__.load({
16421
16447
  * reserved floor, so a non-zero total is genuinely spendable. A channel that could not
16422
16448
  * be read is grey — the dot must not claim "you are fine" on missing data.
16423
16449
  */
16424
- const alive = snapshot.channel !== void 0 && snapshot.channel.total > 0;
16450
+ const alive = ready && snapshot.channel !== void 0 && snapshot.channel.total > 0;
16425
16451
  const label = alive ? t?.("dot.alive") ?? "还有积分" : t?.("dot.empty") ?? "没有积分了";
16426
16452
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
16427
16453
  className: "dsm-xdpool-dotwrap",
@@ -16435,7 +16461,7 @@ window.__ModuleLoader__.load({
16435
16461
  "data-state": alive ? "alive" : "empty",
16436
16462
  "aria-label": label,
16437
16463
  "aria-expanded": open,
16438
- title: `${label} · ${snapshot.channel === void 0 ? "—" : grouped(snapshot.channel.total)}`,
16464
+ title: `${label} · ${snapshot?.channel === void 0 ? "—" : grouped(snapshot.channel.total)}`,
16439
16465
  onClick: () => {
16440
16466
  setOpen((current) => !current);
16441
16467
  },
@@ -16453,7 +16479,10 @@ window.__ModuleLoader__.load({
16453
16479
  top: `${String(pos.top)}px`,
16454
16480
  left: `${String(pos.left)}px`
16455
16481
  },
16456
- children: [
16482
+ children: [!ready ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
16483
+ className: "dsm-xdpool-dotpanel-empty",
16484
+ children: failed ? t?.("dot.loadFailed") ?? "积分数据读取失败" : t?.("dot.loading") ?? "正在读取积分…"
16485
+ }) : null, !ready ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
16457
16486
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
16458
16487
  className: "dsm-xdpool-dotpanel-head",
16459
16488
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -16508,7 +16537,7 @@ window.__ModuleLoader__.load({
16508
16537
  }, channel.id);
16509
16538
  })
16510
16539
  }) : null
16511
- ]
16540
+ ] })]
16512
16541
  })
16513
16542
  ]
16514
16543
  });
@@ -17055,6 +17084,8 @@ window.__ModuleLoader__.load({
17055
17084
  "dot.spentToday": "Used today",
17056
17085
  "dot.model": "Model",
17057
17086
  "dot.channelUnknown": "No channel connected",
17087
+ "dot.loading": "Reading credits…",
17088
+ "dot.loadFailed": "Could not read the credit data",
17058
17089
  "dot.remaining": "Remaining",
17059
17090
  "dot.barLabel": "Share of the period budget used",
17060
17091
  "gw.keyHint": "This key survives a DSH restart. Rotating it drops every device that still holds the old one. This is not the per-process secret of the pool itself — a client that learned that one would stop working the next time DSH restarts.",
@@ -17649,6 +17680,8 @@ window.__ModuleLoader__.load({
17649
17680
  "dot.spentToday": "今日已用",
17650
17681
  "dot.model": "模型",
17651
17682
  "dot.channelUnknown": "未连接渠道",
17683
+ "dot.loading": "正在读取积分…",
17684
+ "dot.loadFailed": "积分数据读取失败",
17652
17685
  "dot.remaining": "剩余积分",
17653
17686
  "dot.barLabel": "本期已用占比",
17654
17687
  "gw.keyHint": "这把密钥在 DSH 重启后仍然有效。轮换会让所有还在用旧密钥的设备立刻断线。这里给的也不是账号池自己每进程生成的秘密 —— 客户端要是拿到它,DSH 下次一重启就全废了。",