dsh-codearts 1.4.3 → 1.4.5

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
@@ -3,6 +3,52 @@
3
3
  本文件记录本插件的重要改动。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
4
4
  版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
5
5
 
6
+ ## [1.4.5] - 2026-11-18
7
+
8
+ ### 修复
9
+
10
+ - **企业版自定义模型的输出上限不再被压到 8000**(#11):企业内部专业版的模型由
11
+ 管理侧注册为自定义模型,上游把输出上限放在 `model_parameters.output_context_window`、
12
+ 而 `max_tokens` 留 0。插件以前只读 `max_tokens`,这类模型的 `maxTokens` 全部落到
13
+ 8000 兜底,长回答在 8K token 处被截断。现在 `max_tokens` 为 0 时退回读
14
+ `output_context_window`,随后仍按该模型的实测上限钳制(声明 100000 会被钳到
15
+ 65536);内置模型与福利模型的取值不变。
16
+ - **续期不再把两个账号同时刷死**:插件的保活循环和守护进程 keeper 会各自拿同一份
17
+ `refresh_token` 去换新令牌,而 CodeArts 的 refresh_token 是一次性的 —— 谁后到
18
+ 谁收到 `HTTP 400 STS5.1806 invalid refresh token: 'the refresh token has been used'`,
19
+ 两个令牌一起作废,所有账号掉到需要重新登录。现在跨进程用 `.codearts-refresh.lock`
20
+ (PID + 心跳,60ms 轮询抢锁、20s 重申、90s 判僵尸)串行化刷新,拿不到锁的一方
21
+ 直接跳过本轮,等对端写完再读盘。
22
+ - **「refresh token 已用过」不再当场判死**:这条错误以前被当成永久失败,直接把账号
23
+ 标成 `stale` 停在登录页。现在按瞬态处理:先重读磁盘看对端是否已换上新令牌,没换
24
+ 就连续 3 轮(插件侧 3 次独立刷新)才真正判死,期间保持可重试。
25
+ - **PID 探活不再误杀进程**:Windows 上 `process.kill(pid, 0)` 会真的把目标进程
26
+ 干掉(Node 不看信号值,直接 TerminateProcess)。锁文件的僵尸判定与 keeper 的
27
+ `keeperStats()` 探活都踩了这一条 —— 后者每探一次就可能杀掉守护进程,keeper 一死
28
+ 插件就整段时间不再自己续期。现在 Windows 分支改用 `tasklist /FI "PID eq N"` 判定,
29
+ 探活失败按「活着」处理,宁可等心跳超时也不误删。
30
+ - **机器睡眠后 keeper 立即补一轮**:Windows 睡眠会让 20 分钟一次的 `setTimeout`
31
+ 停摆(11-18 凌晨实测有 4 轮 tick 全空,而进程一直活着),期间没有续期。现在加了
32
+ 30 秒看门狗,发现距上次 tick 超过 25 分钟就重排定时器并立刻补跑一轮。
33
+ - **旧版本误标的 `stale` 账号自动复活**:1.3.0 及以前任何一次续期失败(含网络抖动)
34
+ 都会永久落 `stale`;现在重新登录前会先用一次续期复验,成功就直接恢复,不必手动重登。
35
+
36
+ ## [1.4.4] - 2026-11-17
37
+
38
+ ### 调整
39
+
40
+ - 设置卡片「显示」页按「界面显示 / 后台行为」两组重排:入口类开关(设置左侧、
41
+ 侧边栏)并入显示组;行为类开关按「动账号余额 → 动请求 → 起进程」排序
42
+ (每日签到 → 排队等待 → 常驻保活),不再与顶部「不影响任何请求」的说明矛盾。
43
+ - 账号页行内操作分级:启用/重新登录常驻行内,置顶/删除收进行尾「⋯」菜单;
44
+ 「清除全部凭据」左侧补影响说明并右对齐,不再孤立地挂在页面最底部。
45
+ - 账号卡改为自适应分栏(auto-fit,最小 320px):面板够宽时一行两个,窄了回落
46
+ 一行一个;「启用」只留开关图形(悬浮提示和无障碍名仍在),省下的宽度让
47
+ 「重新登录」留在行内。
48
+ - 模型页行尾收拢:倍率与识图合并成一段文字(少两个胶囊),语义 Tag 与测试按钮
49
+ 成簇靠右,窄宽度下整簇换行,不再把模型名挤扁;上下文规格按钮紧跟模型名
50
+ (原先被右对齐,与名字之间留出一大段空白)。
51
+
6
52
  ## [1.4.3] - 2026-11-17
7
53
 
8
54
  ### 修复
@@ -1,8 +1,9 @@
1
1
  import { createHash, createPrivateKey, createSign, generateKeyPairSync, randomBytes } from "node:crypto";
2
- import { chmod, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
2
+ import { chmod, mkdir, open, readFile, rename, unlink, utimes, writeFile } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import http from "node:http";
6
+ import { execFileSync } from "node:child_process";
6
7
  //#region src/dpop.ts
7
8
  /**
8
9
  * DPoP(RFC 9449)证明 JWT:ES256 + P-256,供 oauth2/tokens 请求头使用。
@@ -343,6 +344,161 @@ async function startLogin(cfg = defaultLoginConfig()) {
343
344
  close: () => codeCh.server.close()
344
345
  };
345
346
  }
347
+ /** Windows 上探活要起一次 tasklist:超时按毫秒给足,卡住就按「活着」处理。 */
348
+ const PID_PROBE_TIMEOUT_MS = 5e3;
349
+ /** 抢锁的轮询间隔(带上少量抖动,避免两个进程同拍重试)。 */
350
+ const POLL_MS = 60;
351
+ /** 持锁期间的重申间隔:一次续期里超过这个时长没重申,别人就可以认定我们死了。 */
352
+ const RENEW_MS = 2e4;
353
+ /** 锁文件路径:与账号文档同目录,保证同一份凭证只有一个锁。 */
354
+ function refreshLockPath(home) {
355
+ return join(home, ".codearts-refresh.lock");
356
+ }
357
+ const sleep$1 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
358
+ /**
359
+ * 判断某个 pid 是否还活着。
360
+ *
361
+ * **绝不能用 `process.kill(pid, 0)`**:这个技巧只在 POSIX 上成立。Windows 上 Node 的
362
+ * 实现不看信号值,直接用 `TerminateProcess` —— `kill(pid, 0)` 会把那个进程**直接杀掉**
363
+ * (实测:同步执行的两段代码互相探活,持锁那一段被当场干掉,锁一直留到 90 秒超时)。
364
+ * 续期锁要探的正是插件自己或守护进程,杀掉它们就是杀掉登录态本身。
365
+ *
366
+ * 这里改用 Windows 自带的 tasklist 查表;POSIX 上继续用 `kill(pid, 0)`。
367
+ */
368
+ function pidAlive(pid) {
369
+ if (!Number.isInteger(pid) || pid <= 0) return false;
370
+ if (process.platform !== "win32") try {
371
+ process.kill(pid, 0);
372
+ return true;
373
+ } catch (error) {
374
+ return error?.code === "EPERM";
375
+ }
376
+ if (pid === process.pid) return true;
377
+ try {
378
+ const out = execFileSync("tasklist", [
379
+ "/FI",
380
+ `PID eq ${pid}`,
381
+ "/NH"
382
+ ], {
383
+ encoding: "utf8",
384
+ stdio: [
385
+ "ignore",
386
+ "pipe",
387
+ "ignore"
388
+ ],
389
+ timeout: PID_PROBE_TIMEOUT_MS,
390
+ windowsHide: true
391
+ });
392
+ return /\b\d+/.test(out) && out.includes(String(pid));
393
+ } catch {
394
+ return true;
395
+ }
396
+ }
397
+ /** 读锁文件;读不到/内容坏掉都返回 undefined(坏锁当成「可以清掉」)。 */
398
+ async function readLock(path) {
399
+ try {
400
+ const parsed = JSON.parse(await readFile(path, "utf8"));
401
+ if (typeof parsed.pid === "number" && typeof parsed.at === "number") return {
402
+ pid: parsed.pid,
403
+ at: parsed.at
404
+ };
405
+ } catch {}
406
+ }
407
+ /**
408
+ * 这个锁还能不能算数。
409
+ *
410
+ * pid 复用是 Windows 上的真实风险:被 kill 的进程留下的 pid 很快会分给新进程,
411
+ * 只看 `pidAlive` 会把死锁当成活锁,永远抢不到。所以「pid 还活着」也要配上
412
+ * `at` 在合理范围内才算活着。
413
+ */
414
+ function isStale(lock, now) {
415
+ if (now - lock.at > 9e4) return true;
416
+ return !pidAlive(lock.pid);
417
+ }
418
+ /**
419
+ * 清掉一个陈旧锁。
420
+ *
421
+ * 删之前重读一次内容、和刚才判定时逐字段比对:中间可能有人刚抢到新锁,
422
+ * 那就不许删(删了会让两个进程同时持锁,比不加锁更糟)。
423
+ */
424
+ async function breakStale(path, seen) {
425
+ const now = await readLock(path);
426
+ if (now !== void 0 && seen !== void 0 && (now.pid !== seen.pid || now.at !== seen.at)) return;
427
+ try {
428
+ await unlink(path);
429
+ } catch {}
430
+ }
431
+ /**
432
+ * 抢锁。拿到了返回释放函数,等不到返回 undefined。
433
+ *
434
+ * 调用方**必须**在 `finally` 里释放(或依赖它自己超时 —— 不释放只是让别人多等
435
+ * 一个 `REFRESH_LOCK_STALE_MS`,不会把锁永久卡死)。
436
+ */
437
+ async function acquireRefreshLock(path, options = {}) {
438
+ const now = options.now ?? Date.now;
439
+ const deadline = now() + (options.waitMs ?? 2e4);
440
+ for (;;) {
441
+ const payload = {
442
+ pid: process.pid,
443
+ at: now()
444
+ };
445
+ let handle;
446
+ try {
447
+ handle = await open(path, "wx", 384);
448
+ await handle.writeFile(JSON.stringify(payload));
449
+ await handle.close();
450
+ handle = void 0;
451
+ return releaser(path, payload);
452
+ } catch (error) {
453
+ await handle?.close().catch(() => {});
454
+ if (error?.code !== "EEXIST") return;
455
+ }
456
+ const held = await readLock(path);
457
+ if (held === void 0 || isStale(held, now())) {
458
+ await breakStale(path, held);
459
+ continue;
460
+ }
461
+ if (now() >= deadline) return void 0;
462
+ await sleep$1(POLL_MS + Math.floor(Math.random() * POLL_MS));
463
+ }
464
+ }
465
+ function releaser(path, payload) {
466
+ let released = false;
467
+ const renew = setInterval(() => {
468
+ if (released) return;
469
+ payload.at = Date.now();
470
+ writeFile(path, JSON.stringify(payload), { mode: 384 }).then(() => utimes(path, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date())).catch(() => {});
471
+ }, RENEW_MS);
472
+ renew.unref?.();
473
+ return async () => {
474
+ if (released) return;
475
+ released = true;
476
+ clearInterval(renew);
477
+ const now_ = await readLock(path);
478
+ if (now_ !== void 0 && now_.pid !== payload.pid) return;
479
+ try {
480
+ await unlink(path);
481
+ } catch {}
482
+ };
483
+ }
484
+ /**
485
+ * 拿着锁做一件事。
486
+ *
487
+ * 拿不到锁返回 `undefined` —— 调用方据此知道「这一轮没轮到我们,什么都不用做」,
488
+ * 而不是把「没刷成」当成「刷新失败」(后者会误判 stale)。
489
+ */
490
+ async function withRefreshLock(path, fn, options = {}) {
491
+ const release = await acquireRefreshLock(path, options);
492
+ if (release === void 0) {
493
+ options.onBusy?.();
494
+ return;
495
+ }
496
+ try {
497
+ return await fn();
498
+ } finally {
499
+ await release();
500
+ }
501
+ }
346
502
  //#endregion
347
503
  //#region src/auth.ts
348
504
  /**
@@ -428,7 +584,7 @@ async function clearCredential(path) {
428
584
  async function claimIfPossible(cred) {
429
585
  if (!cred.accessKeyId || !cred.secretAccessKey) return;
430
586
  try {
431
- const { claimBenefit } = await import("./upstream-BV4XWB4l.mjs").then((n) => n.P);
587
+ const { claimBenefit } = await import("./upstream-B_KAbdPy.mjs").then((n) => n.P);
432
588
  await claimBenefit({
433
589
  token: cred.token,
434
590
  accessKeyId: cred.accessKeyId,
@@ -467,6 +623,15 @@ const REFRESH_RETRY_BASE_MS = 250;
467
623
  * 一次性 refresh_token 反复烧掉,把「暂时失败」放大成「真的失效」。
468
624
  */
469
625
  const REFRESH_TRANSIENT_BLOCK_MS = 6e4;
626
+ /**
627
+ * `STS5.1806`(refresh_token 已被用掉)连续撞上几次才判死。
628
+ *
629
+ * 这个码本身**不能**证明凭证坏了:另一个写入方(守护进程)恰好先用掉了同一个令牌,
630
+ * 撞上的这一方手里拿的就是旧值。绝大多数情况下下一轮重读磁盘就能拿到新令牌。
631
+ * 连续 3 次、每次之间隔一个瞬时冷却还都是这个结果,才算真的没救了 ——
632
+ * 早先一次就判死,2026-11-18 00:06 两个号同时被误杀(见 `refresh-lock.ts` 的说明)。
633
+ */
634
+ const REFRESH_USED_MAX_STREAK = 3;
470
635
  /** 失败是不是「凭证真的没了」;只有这一类才允许写 `stale`。 */
471
636
  function isPermanentRefreshFailure(error) {
472
637
  return error instanceof OAuthTokenError && error.permanent;
@@ -722,14 +887,19 @@ var AccountSlot = class {
722
887
  _gen = 0;
723
888
  persist;
724
889
  log;
890
+ /** 跨进程续期锁的路径(由 store 注入;单凭证时代用默认目录)。 */
891
+ lockPath;
725
892
  /** 瞬时失败后的冷却:这之前不再拿 refresh_token 去撞上游。 */
726
893
  _refreshBlockedUntil = 0;
727
894
  /** 最近一次续期失败的类型,供 store 判断要不要「重读磁盘再试一次」。 */
728
895
  _lastFailure;
729
- constructor(cred, persist, log) {
896
+ /** `STS5.1806` 连续撞了几次(成功一次就清零);见 `REFRESH_USED_MAX_STREAK`。 */
897
+ _usedStreak = 0;
898
+ constructor(cred, persist, log, lockPath) {
730
899
  this._cred = cred;
731
900
  this.persist = persist;
732
901
  this.log = log;
902
+ this.lockPath = lockPath ?? refreshLockPath(dirname(codeartsAccountsPath()));
733
903
  }
734
904
  get credential() {
735
905
  return this._cred;
@@ -738,6 +908,17 @@ var AccountSlot = class {
738
908
  get lastFailure() {
739
909
  return this._lastFailure;
740
910
  }
911
+ /**
912
+ * 这一份凭证是不是真的完了。
913
+ *
914
+ * `_lastFailure === 'used'` 只代表「这一趟撞上了已用过的令牌」,还要看连续撞了几次:
915
+ * 一两次是并发轮换的正常现象,重读磁盘就能恢复。
916
+ */
917
+ get exhausted() {
918
+ if (this._cred.stale === true) return true;
919
+ if (this._lastFailure === "permanent") return true;
920
+ return this._lastFailure === "used" && this._usedStreak >= REFRESH_USED_MAX_STREAK;
921
+ }
741
922
  /** 把这份凭证标成 stale 并落库(store 在「令牌被别人用掉且磁盘也没有更新」时调)。 */
742
923
  async markStale() {
743
924
  if (this._cred.stale === true) return;
@@ -791,20 +972,57 @@ var AccountSlot = class {
791
972
  */
792
973
  async verifyStale() {
793
974
  const cred = this._cred;
794
- if (cred.stale !== true) return true;
975
+ if (this._cred.stale === true) {
976
+ if (!cred.refreshToken || !cred.dpopPrivateKey || !cred.clientId) return false;
977
+ if (Date.now() < this._refreshBlockedUntil) return false;
978
+ const outcome = await this.refresh(cred, {
979
+ refreshToken: cred.refreshToken,
980
+ dpopPrivateKey: cred.dpopPrivateKey,
981
+ clientId: cred.clientId
982
+ });
983
+ if (outcome.ok) this._cred = outcome.cred;
984
+ return outcome.ok;
985
+ }
795
986
  if (!cred.refreshToken || !cred.dpopPrivateKey || !cred.clientId) return false;
796
987
  if (Date.now() < this._refreshBlockedUntil) return false;
797
- return (await this.runRefresh(cred)).ok;
988
+ const outcome = await this.refresh(cred, {
989
+ refreshToken: cred.refreshToken,
990
+ dpopPrivateKey: cred.dpopPrivateKey,
991
+ clientId: cred.clientId
992
+ });
993
+ if (outcome.ok) this._cred = outcome.cred;
994
+ return outcome.ok;
798
995
  }
799
- /** 单飞执行一次续期。 */
996
+ /**
997
+ * 单飞执行一次续期,**并在跨进程文件锁里做**。
998
+ *
999
+ * 单飞只挡得住同一进程内的并发;守护进程(`keeper-main.ts`)是另一个进程,
1000
+ * 它和我们各持一份同一个账号的 refresh_token,同时刷必然有一方撞上 `STS5.1806`。
1001
+ * 锁保证「同一时刻只有一个进程拿 refresh_token 去撞上游」。拿不到锁(对方正在刷)
1002
+ * 就当这一轮没轮到我们:不写 stale,只冷却一会儿等下一轮重读磁盘拿它写回的新令牌。
1003
+ */
800
1004
  async runRefresh(cred) {
801
- return this._inflight ??= this.refresh(cred, {
1005
+ return this._inflight ??= this.refreshLocked(cred).finally(() => {
1006
+ this._inflight = void 0;
1007
+ });
1008
+ }
1009
+ async refreshLocked(cred) {
1010
+ const outcome = await withRefreshLock(this.lockPath, () => this.refresh(cred, {
802
1011
  refreshToken: cred.refreshToken ?? "",
803
1012
  dpopPrivateKey: cred.dpopPrivateKey,
804
1013
  clientId: cred.clientId ?? ""
805
- }).finally(() => {
806
- this._inflight = void 0;
807
- });
1014
+ }), { onBusy: () => {
1015
+ this._refreshBlockedUntil = Date.now() + REFRESH_TRANSIENT_BLOCK_MS;
1016
+ this.log?.(`[dsh-codearts] refresh ${cred.label ?? "account"} skipped: another process holds the refresh lock, will reload from disk`);
1017
+ } });
1018
+ if (outcome !== void 0) return outcome;
1019
+ this._refreshBlockedUntil = Date.now() + REFRESH_TRANSIENT_BLOCK_MS;
1020
+ return {
1021
+ ok: false,
1022
+ cred: this._cred,
1023
+ permanent: false,
1024
+ reason: "refresh lock busy"
1025
+ };
808
1026
  }
809
1027
  async refresh(cred, mat) {
810
1028
  const gen = this._gen;
@@ -825,6 +1043,7 @@ var AccountSlot = class {
825
1043
  }), cred.label);
826
1044
  this._refreshBlockedUntil = 0;
827
1045
  this._lastFailure = void 0;
1046
+ this._usedStreak = 0;
828
1047
  if (!stillCurrent()) return {
829
1048
  ok: true,
830
1049
  cred: next
@@ -838,15 +1057,34 @@ var AccountSlot = class {
838
1057
  };
839
1058
  } catch (error) {
840
1059
  lastError = error;
841
- if (isPermanentRefreshFailure(error)) break;
1060
+ if (isPermanentRefreshFailure(error) || isRefreshTokenUsed(error)) break;
842
1061
  this.log?.(`[dsh-codearts] refresh ${cred.label ?? "account"} attempt ${attempt}/${REFRESH_MAX_ATTEMPTS} failed (transient): ${describeRefreshFailure(error)}`);
843
1062
  if (attempt < REFRESH_MAX_ATTEMPTS) await sleep(REFRESH_RETRY_BASE_MS * 2 ** (attempt - 1));
844
1063
  }
845
1064
  const used = isRefreshTokenUsed(lastError);
846
1065
  const permanent = !used && isPermanentRefreshFailure(lastError);
847
1066
  const reason = describeRefreshFailure(lastError);
848
- if (used) this._lastFailure = "used";
849
- else if (permanent) {
1067
+ if (used) {
1068
+ this._usedStreak += 1;
1069
+ this._lastFailure = "used";
1070
+ this._refreshBlockedUntil = Date.now() + REFRESH_TRANSIENT_BLOCK_MS;
1071
+ this.log?.(`[dsh-codearts] refresh ${cred.label ?? "account"} hit a used refresh token (${this._usedStreak}/${REFRESH_USED_MAX_STREAK}), reloading from disk`);
1072
+ if (!stillCurrent()) return {
1073
+ ok: false,
1074
+ cred: this._cred,
1075
+ permanent: false,
1076
+ reason
1077
+ };
1078
+ this._cred = cred;
1079
+ return {
1080
+ ok: false,
1081
+ cred,
1082
+ permanent: false,
1083
+ reason
1084
+ };
1085
+ }
1086
+ this._usedStreak = 0;
1087
+ if (permanent) {
850
1088
  this._lastFailure = "permanent";
851
1089
  cred.stale = true;
852
1090
  } else {
@@ -911,6 +1149,16 @@ var CodeArtsAccountStore = class {
911
1149
  this.legacyPath = legacyPath ?? join(dirname(path), ".codearts-auth.json");
912
1150
  this.log = options.log;
913
1151
  }
1152
+ /**
1153
+ * 所有槽位共用的跨进程续期锁(与守护进程同一个文件)。
1154
+ *
1155
+ * 注意是**整个文档一把锁**,不是每个账号一把:`AccountSlot` 是先刷后整份写回的,
1156
+ * 两个账号同时在刷会让后写的那次把前一个刚轮换出来的 refresh_token 覆盖掉。
1157
+ * 一把锁的代价只是多账号时串行几秒,换来的是不可能互相踩。
1158
+ */
1159
+ slotLockPath() {
1160
+ return refreshLockPath(dirname(this.path));
1161
+ }
914
1162
  async loaded() {
915
1163
  this._loading ??= this.load();
916
1164
  return this._loading;
@@ -938,7 +1186,8 @@ var CodeArtsAccountStore = class {
938
1186
  adopt(doc) {
939
1187
  this._doc = doc;
940
1188
  this._slots.clear();
941
- for (const [id, cred] of Object.entries(doc.accounts)) this._slots.set(id, new AccountSlot(cred, this.persisterFor(id), this.log));
1189
+ const lockPath = this.slotLockPath();
1190
+ for (const [id, cred] of Object.entries(doc.accounts)) this._slots.set(id, new AccountSlot(cred, this.persisterFor(id), this.log, lockPath));
942
1191
  }
943
1192
  persisterFor(id) {
944
1193
  return async (cred) => {
@@ -985,7 +1234,7 @@ var CodeArtsAccountStore = class {
985
1234
  this._slots.get(id)?.invalidate();
986
1235
  doc.accounts[id] = cred;
987
1236
  if (!doc.order.includes(id)) doc.order.push(id);
988
- this._slots.set(id, new AccountSlot(cred, this.persisterFor(id), this.log));
1237
+ this._slots.set(id, new AccountSlot(cred, this.persisterFor(id), this.log, this.slotLockPath()));
989
1238
  await this.persistDoc();
990
1239
  await claimIfPossible(cred);
991
1240
  return id;
@@ -1030,7 +1279,7 @@ var CodeArtsAccountStore = class {
1030
1279
  ...identity.domainId === "" ? {} : { domainId: identity.domainId }
1031
1280
  };
1032
1281
  this._slots.get(id)?.invalidate();
1033
- this._slots.set(id, new AccountSlot(doc.accounts[id], this.persisterFor(id), this.log));
1282
+ this._slots.set(id, new AccountSlot(doc.accounts[id], this.persisterFor(id), this.log, this.slotLockPath()));
1034
1283
  await this.persistDoc();
1035
1284
  return "noop";
1036
1285
  }
@@ -1048,7 +1297,7 @@ var CodeArtsAccountStore = class {
1048
1297
  this._slots.get(id)?.invalidate();
1049
1298
  this._slots.delete(id);
1050
1299
  this._slots.get(targetKey)?.invalidate();
1051
- this._slots.set(targetKey, new AccountSlot(doc.accounts[targetKey], this.persisterFor(targetKey), this.log));
1300
+ this._slots.set(targetKey, new AccountSlot(doc.accounts[targetKey], this.persisterFor(targetKey), this.log, this.slotLockPath()));
1052
1301
  await this.persistDoc();
1053
1302
  return target === void 0 ? "moved" : "merged";
1054
1303
  }
@@ -1085,7 +1334,7 @@ var CodeArtsAccountStore = class {
1085
1334
  paused
1086
1335
  };
1087
1336
  this._slots.get(id)?.invalidate();
1088
- this._slots.set(id, new AccountSlot(doc.accounts[id], this.persisterFor(id), this.log));
1337
+ this._slots.set(id, new AccountSlot(doc.accounts[id], this.persisterFor(id), this.log, this.slotLockPath()));
1089
1338
  await this.persistDoc();
1090
1339
  return true;
1091
1340
  }
@@ -1100,7 +1349,7 @@ var CodeArtsAccountStore = class {
1100
1349
  pinned
1101
1350
  };
1102
1351
  this._slots.get(id)?.invalidate();
1103
- this._slots.set(id, new AccountSlot(doc.accounts[id], this.persisterFor(id), this.log));
1352
+ this._slots.set(id, new AccountSlot(doc.accounts[id], this.persisterFor(id), this.log, this.slotLockPath()));
1104
1353
  await this.persistDoc();
1105
1354
  return true;
1106
1355
  }
@@ -1144,11 +1393,8 @@ var CodeArtsAccountStore = class {
1144
1393
  if (await this.reloadIfPeerAdvanced(id)) {
1145
1394
  const retry = this._slots.get(id);
1146
1395
  if (retry !== void 0) cred = await retry.ensureFresh();
1147
- if (retry?.lastFailure === "used") {
1148
- await this.markStale(id);
1149
- cred = this._slots.get(id)?.credential ?? cred;
1150
- }
1151
- } else {
1396
+ }
1397
+ if (this._slots.get(id)?.exhausted === true) {
1152
1398
  await this.markStale(id);
1153
1399
  cred = this._slots.get(id)?.credential ?? cred;
1154
1400
  }
@@ -1177,7 +1423,7 @@ var CodeArtsAccountStore = class {
1177
1423
  slot = this._slots.get(id);
1178
1424
  next = slot === void 0 ? void 0 : await slot.forceRefresh();
1179
1425
  }
1180
- if (next === void 0) await this.markStale(id);
1426
+ if (next === void 0 && this._slots.get(id)?.exhausted === true) await this.markStale(id);
1181
1427
  }
1182
1428
  return next;
1183
1429
  }
@@ -1284,4 +1530,4 @@ var CodeArtsAccountStore = class {
1284
1530
  }
1285
1531
  };
1286
1532
  //#endregion
1287
- export { codeartsAuthPath as a, credentialFromOAuth as c, OAuthTokenError as d, defaultLoginConfig as f, codeartsAccountsPath as i, readAccountDocument as l, startLogin as m, CodeArtsCredentialStore as n, codeartsDebugLogPath as o, refreshToken as p, MANUAL_ACCOUNT_ID as r, codeartsRefreshLogPath as s, CodeArtsAccountStore as t, writeJsonAtomic as u };
1533
+ export { codeartsAuthPath as a, credentialFromOAuth as c, refreshLockPath as d, withRefreshLock as f, startLogin as g, refreshToken as h, codeartsAccountsPath as i, readAccountDocument as l, defaultLoginConfig as m, CodeArtsCredentialStore as n, codeartsDebugLogPath as o, OAuthTokenError as p, MANUAL_ACCOUNT_ID as r, codeartsRefreshLogPath as s, CodeArtsAccountStore as t, writeJsonAtomic as u };
package/lib/bin.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { i as codeartsAccountsPath, t as CodeArtsAccountStore } from "./auth-Cd2SvQIy.mjs";
3
- import { H as isBenefitModel, l as fetchCallerIdentity } from "./upstream-BV4XWB4l.mjs";
4
- import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-DqzkoxeU.mjs";
2
+ import { i as codeartsAccountsPath, t as CodeArtsAccountStore } from "./auth-B5PDMG7r.mjs";
3
+ import { H as isBenefitModel, l as fetchCallerIdentity } from "./upstream-B_KAbdPy.mjs";
4
+ import { i as discoverModels, n as CodeArtsUsageTracker, r as codeartsUsagePath, t as CODEARTS_VERSION } from "./version-DZ47veC-.mjs";
5
5
  import { existsSync, statSync } from "node:fs";
6
6
  //#region src/bin.ts
7
7
  /**
@@ -24,6 +24,10 @@ interface CodeArtsSettingsKey {
24
24
  storedMetaNoLabel: string;
25
25
  refresh: string;
26
26
  clearToken: string;
27
+ /** 「清除全部凭据」左侧的影响说明。 */
28
+ clearTokenHint: string;
29
+ /** 账号行尾「⋯」菜单的按钮名(无障碍标签)。 */
30
+ accountMore: string;
27
31
  tokenLabel: string;
28
32
  tokenPlaceholder: string;
29
33
  labelLabel: string;
@@ -198,6 +202,8 @@ interface CodeArtsSettingsKey {
198
202
  displayCreditsToggle: string;
199
203
  displayQueueToggle: string;
200
204
  displayModelDetailToggle: string;
205
+ displayGroupUi: string;
206
+ displayGroupBehavior: string;
201
207
  displayAutoClaimTitle: string;
202
208
  displayAutoClaimHint: string;
203
209
  displayAutoClaimToggle: string;