dsh-wtq-pool 1.2.1 → 1.2.2

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,5 +1,19 @@
1
1
  # 更新说明
2
2
 
3
+ ## [1.2.2]
4
+
5
+ - 登录:新的登录流程替换旧流程后,不再保存旧流程的结果或清除新流程。
6
+ - 账号池:每次续期后重新确认账号资格,避免使用在等待期间被停用、移除或冷却的账号。
7
+ - 隐私:关闭 WorkBuddy 或其全部区域后,刷新跳过登录凭证扫描;未完成的扫描不再回填账号或继续写入凭证。
8
+ - 成长中心:任务取消后停止后续补签、领奖、活动上报与抽奖,不再继续消费补签卡。
9
+ - WorkBuddy:补齐或折叠系统消息时使用非空内容,兼容 Kimi 3.1 的消息校验,避免空系统消息触发 11151。
10
+ - 账号发现:手动重新检测会在当前扫描结束后重新读取,避免漏掉刚新增的登录。
11
+ - 流式输出:WorkBuddy 在 `[DONE]` 前补齐缺失的结束帧,正确处理分块结束标记与未分隔的尾帧;工具调用补用 `tool_calls` 结束原因。
12
+ - 签到:单账号签到显示领取结果并更新状态;批量签到显示脱敏后的首个失败原因,Qoder 的不可重试拒绝不再安排补领。
13
+ - 安全:本地预览只提供必要的公开资源,拒绝非回环 Host,不再公开仓库内部文件。
14
+ - 面板与文档:调整风险提示与悬停标签对比度,明确两版独立存储和共享凭证的续期限制。
15
+ - 依赖:更新 Zod 与 fast-uri 的兼容补丁,修复开发依赖中的已知安全问题。
16
+
3
17
  ## [1.2.1]
4
18
 
5
19
  - 签到:单账号与批量领取后立即更新账号卡片;已领取的回执按已签到处理,单账号签到遇到当日已领取时直接显示成功;已领取的活动不再遮住其后可领取的轮次;过期登录在批量签到前跳过;Trae 设备签到当天用完后,同批剩余同版本账号标记为跳过;国际版不显示签到入口与说明。
package/README.en.md CHANGED
@@ -33,7 +33,7 @@
33
33
  <a href="https://github.com/chengzhi-c/dsh-wtq-pool/stargazers"><img src="https://img.shields.io/github/stars/chengzhi-c/dsh-wtq-pool?style=flat-square" alt="GitHub stars"></a>
34
34
  </p>
35
35
 
36
- > **! A ban is possible. Use at your own discretion; no liability accepted !**
36
+ > Unofficial clients may trigger account restrictions. Review the risks and the relevant service terms before use.
37
37
 
38
38
  Use local WorkBuddy, Trae and Qoder desktop sign-ins in DeepSeek Harness. WorkBuddy fails over when an account is rate-limited or out of quota. Trae and Qoder select an account per request and move on to the next sign-in on an authentication failure, a rate limit or exhausted quota, while a problem with the request itself, such as an unknown model or a malformed body, is answered as the upstream answered it. Each source has its own switch, with domestic and international accounts grouped separately.
39
39
 
@@ -67,7 +67,7 @@ To run the preview locally, clone the repository, run `node docs/serve.cjs`, and
67
67
 
68
68
  ## Features
69
69
 
70
- - Reuse the local sign-ins: the sign-in files the three desktop apps saved are read as they are. The panel's Add account opens the vendor's own login page and writes the result into the plugin's own directory.
70
+ - Reuse local sign-ins from the three desktop apps. WorkBuddy also supports Add account in the panel, which uses its official login page and saves the sign-in in the plugin's own directory.
71
71
  - Register model groups by region: each region of each vendor becomes its own provider, and several can be on at once; a region with no account is not registered. A domestic model runs only on domestic accounts, and an international model only on international ones.
72
72
  - Account distribution: WorkBuddy supports priority, round-robin, expiring credits first and conversation-sticky accounts, and fails over on a rate limit or exhausted quota. Trae and Qoder support priority, round-robin and expiring credits first, and move on to the next sign-in on an authentication failure, a rate limit or exhausted quota.
73
73
  - Gateway responses are SSE streams of `chat.completion.chunk`; the `stream` field in the request body does not change the format.
@@ -168,13 +168,13 @@ These are the preferred ports. When one is taken, the gateway binds an ephemeral
168
168
 
169
169
  When another process takes a port between the reservation and the listen, that gateway's start fails: its model group is dropped, the connection check reports the reason, and the panel surfaces address drift. Requests reach the new address only after the plugin is reloaded and the host re-reads its declaration.
170
170
 
171
- The PI-Desktop edition uses a separate range starting at 41831, so both plugins can be installed on one machine with each range intact. Each edition keeps its own copy of a sign-in and renews it on its own schedule, and the upstream rotates the refresh token whenever one does. A single account is therefore held by whichever edition renewed it last: the other one's refresh token stops working, its panel marks the account as needing a sign-in, and "Add account" puts it back. The token days differ for the same reason, since each row shows the expiry of that edition's own copy. To keep one account working in both editions, add it in only one of them, or re-add it in the one that was marked.
171
+ The PI-Desktop edition uses a separate port range starting at 41831. Both editions can be installed together, but settings and credentials are stored separately and are not synchronized. If both use the same WorkBuddy sign-in, upstream refresh-token rotation may invalidate the other copy. When an edition asks for a new sign-in, add the account again there rather than overwriting it with old `signins/` files. The editions may show different token expiry times.
172
172
 
173
173
  ## Data and outbound requests
174
174
 
175
- The plugin reads the vendors' local sign-in files. Providers are registered at runtime; the host persists plugin settings in the profile. Tokens are held by the plugin and go only to the relevant vendor endpoints. Gateways listen on `127.0.0.1`; the panel accepts loopback requests only.
175
+ The plugin reads the vendors' local sign-in files. Providers are registered at runtime; the host persists plugin settings in the profile. Tokens are held by the plugin and go only to the relevant vendor endpoints. Gateways listen on `127.0.0.1`, so other local processes can call them and spend account quota. The panel accepts loopback requests only.
176
176
 
177
- The plugin's own data directory, `~/.dsh/dsh-wtq-pool/` (or `$DSH_HOME` when set), holds four files (a `deleted-signins.json.lock` appears for a moment while the delete record is written). `checkin-slots.json` records the check-in slots already collected and the pending Qoder retry time; slots are kept for three days. `doctor.txt` is the most recent connection report, item by item, and lists no account label. `credentials-archive.json` keeps the sign-ins a later account switch overwrote: access and refresh tokens, account identifiers (nickname, uin/uid, enterprise id) and the local sign-in path. Entries are kept by token expiry, dropping each 30 days after it; an entry with no stated expiry is kept until the account is deleted. `deleted-signins.json` records deleted sign-ins as a token digest, the sign-in's issue time and a delete time, so a scan cannot take the same superseded snapshot back over from the desktop app; the entry lapses once that account signs in again. These files carry no additional encryption; access is bounded by the operating system's file ACLs.
177
+ The plugin's own data directory, `~/.dsh/dsh-wtq-pool/` (or `$DSH_HOME/dsh-wtq-pool/` when set), holds four files (a `deleted-signins.json.lock` appears for a moment while the delete record is written). `checkin-slots.json` records the check-in slots already collected and the pending Qoder retry time; slots are kept for three days. `doctor.txt` is the most recent connection report, item by item, and lists no account label. `credentials-archive.json` keeps the sign-ins a later account switch overwrote: access and refresh tokens, account identifiers (nickname, uin/uid, enterprise id) and the local sign-in path. Entries are kept by token expiry, dropping each 30 days after it; an entry with no stated expiry is kept until the account is deleted. `deleted-signins.json` records deleted sign-ins as a token digest, the sign-in's issue time and a delete time, so a scan cannot take the same superseded snapshot back over from the desktop app; the entry lapses once that account signs in again. These files carry no additional encryption; access is bounded by the operating system's file ACLs.
178
178
 
179
179
  Every sign-in the plugin writes lives in `signins/` beside it: ones added from the panel, snapshots adopted from the desktop app, and renewed copies. Each file is named after the account's billing identity and read on the same terms as a desktop sign-in. These files are not additionally encrypted either; access is bounded by the operating system's file ACLs. "Delete" in the panel removes that file together with its archive entry, and the snapshot the desktop app left behind stops being adopted; signing the account in again brings it back. "Remove" only disables the account, and "Removed accounts" restores it.
180
180
 
@@ -203,7 +203,7 @@ The host-agnostic core:
203
203
  | Module | Responsibility |
204
204
  | --- | --- |
205
205
  | `loopback.ts` | The loopback security model (Host and Origin checks), response writing, stream relay and message redaction |
206
- | `accounts.ts` | WorkBuddy sign-in parsing, token encryption, the account pool and its cooldowns |
206
+ | `accounts.ts` | WorkBuddy sign-in parsing, the account pool and its cooldowns |
207
207
  | `upstream.ts` | The WorkBuddy upstream client, error classification, rate-limit reset parsing |
208
208
  | `catalog.ts` | The model catalogue and its static fallback list |
209
209
  | `shim.ts` | The WorkBuddy gateway's OpenAI-compatible endpoint |
package/README.md CHANGED
@@ -33,7 +33,7 @@
33
33
  <a href="https://github.com/chengzhi-c/dsh-wtq-pool/stargazers"><img src="https://img.shields.io/github/stars/chengzhi-c/dsh-wtq-pool?style=flat-square" alt="GitHub stars"></a>
34
34
  </p>
35
35
 
36
- > **!可能有封号风险,请斟酌使用,概不负责 !**
36
+ > 使用非官方客户端可能触发厂商的账号风控或限制。请评估相关风险,并遵守对应服务的使用条款。
37
37
 
38
38
  把本机 WorkBuddy、Trae、Qoder 的桌面登录接入 DeepSeek Harness。WorkBuddy 在账号被限流或额度用尽时自动换号;Trae、Qoder 按请求选择账号,认证失败、限流或余额耗尽时改用下一个登录重试,模型不存在、请求体非法这类请求自身的问题则按上游原样返回。三个来源各自开关,国内与国际账号分别成组。
39
39
 
@@ -67,7 +67,7 @@
67
67
 
68
68
  ## 功能
69
69
 
70
- - 复用本机登录:读取三家桌面 App 已保存的登录文件。面板的「添加账号」打开厂商官方登录页,并把登录写入插件自管目录。
70
+ - 复用本机登录:读取三家桌面 App 已保存的登录文件。WorkBuddy 另支持在面板「添加账号」,通过官方登录页授权后将登录保存到插件自管目录。
71
71
  - 按 region 注册模型分组:三家厂商各自的 region 各注册为一个 provider,可同时启用;没有账号的 region 不注册。国内模型只走国内账号,国际版模型只走国际账号。
72
72
  - 账号分发:WorkBuddy 支持先用一个账号、轮流使用、临期积分优先和同一对话固定一个账号,并在限流或额度用尽时自动换号;Trae、Qoder 支持优先使用、轮流使用与临期积分优先,认证失败、限流或余额耗尽时改用下一个登录重试。
73
73
  - 网关以 SSE 返回 `chat.completion.chunk`;请求体里的 `stream` 字段不改变响应格式。
@@ -166,15 +166,15 @@ Qoder 42871 / 42881
166
166
 
167
167
  以上为首选端口。端口被占用时网关绑定系统分配的临时端口,运行时注册的 provider 使用本次实际地址,面板显示回退结果。
168
168
 
169
- PI-Desktop 版使用 41831 开头的另一段端口,两个插件可以同时安装在同一台机器上,两套端口各自正确。两版各自保留一份登录并各自续期,上游在续期时轮换刷新令牌,因此同一账号只会被先续期的那一版持有:另一版手上的刷新令牌随之失效,面板会把它标成「需重新登录」,用「添加账号」补一次即可。签名天数因此也会一边一个样,那是两份登录各自的到期时间。想让同一账号两版都能用,就只在其中一版里添加,或在被标出的那一版重新添加。
169
+ PI-Desktop 版使用 41831 开头的独立端口,两版可以同时安装,设置和凭证分别保存,不会自动同步。若两版使用同一份 WorkBuddy 登录,上游轮换刷新令牌时可能使另一版的登录失效。出现「需重新登录」时,在对应版本重新添加账号,不要复制旧的 `signins/` 文件覆盖;两版显示的令牌到期时间可能不同。
170
170
 
171
171
  端口在预留与监听之间被其他进程占用时,该网关本次启动失败:其模型组被摘掉,连接检查报出失败原因,面板提示重新加载插件。重新加载后宿主重新读取声明,请求才会落到新地址。
172
172
 
173
173
  ## 数据与出网
174
174
 
175
- 读取三家 App 的本机登录文件。provider 通过运行时注册接入,插件设置由宿主持久化至 profile。令牌由插件保管,只发往对应厂商的接口。网关监听 `127.0.0.1`,面板只接受本机回环请求。
175
+ 读取三家 App 的本机登录文件。provider 通过运行时注册接入,插件设置由宿主持久化至 profile。令牌由插件保管,只发往对应厂商的接口。网关监听 `127.0.0.1`,同机其他进程可调用并消耗账号额度;面板只接受本机回环请求。
176
176
 
177
- 插件自管数据目录 `~/.dsh/dsh-wtq-pool/`(设置了 `DSH_HOME` 时改用它)包含四个文件(写删除记录时会短暂多一个 `deleted-signins.json.lock`)。`checkin-slots.json` 记录已领取的签到时段和待重试的 Qoder 时点,时段只保留三天。`doctor.txt` 是最近一次连接检查的报告,逐项记录通过与否,不列账号标签。`credentials-archive.json` 留存被切号覆盖的登录,含访问令牌、刷新令牌、账号标识(昵称、uin/uid、企业 ID)与本机登录文件路径;按令牌到期时间保留,到期后再过 30 天清除,没有到期时间的记录保留到该账号被删除。`deleted-signins.json` 记录已删除的登录,只存令牌摘要、该登录的签发时间与删除时间,用来阻止扫描把桌面端遗留的同一份快照重新接管回来;同一个账号重新登录后(签发时间更新)该记录自动失效。上述文件未额外加密,访问权限由操作系统文件 ACL 决定。
177
+ 插件自管数据目录 `~/.dsh/dsh-wtq-pool/`(设置了 `DSH_HOME` 时为 `$DSH_HOME/dsh-wtq-pool/`)包含四个文件(写删除记录时会短暂多一个 `deleted-signins.json.lock`)。`checkin-slots.json` 记录已领取的签到时段和待重试的 Qoder 时点,时段只保留三天。`doctor.txt` 是最近一次连接检查的报告,逐项记录通过与否,不列账号标签。`credentials-archive.json` 留存被切号覆盖的登录,含访问令牌、刷新令牌、账号标识(昵称、uin/uid、企业 ID)与本机登录文件路径;按令牌到期时间保留,到期后再过 30 天清除,没有到期时间的记录保留到该账号被删除。`deleted-signins.json` 记录已删除的登录,只存令牌摘要、该登录的签发时间与删除时间,用来阻止扫描把桌面端遗留的同一份快照重新接管回来;同一个账号重新登录后(签发时间更新)该记录自动失效。上述文件未额外加密,访问权限由操作系统文件 ACL 决定。
178
178
 
179
179
  插件写入的登录都在同目录的 `signins/`:面板添加的、接管桌面端快照的、续期后的副本。文件名带账号的计费身份,与桌面登录同等参与分发。这些文件同样未额外加密,访问权限由操作系统文件 ACL 决定。在面板中「删除」该账号会连同 `credentials-archive.json` 里的留档一起清除,桌面端遗留的同一份快照随之失效;重新登录该账号即解除。「移除」只是停用,可在「已移除的账号」中恢复。
180
180
 
@@ -203,7 +203,7 @@ pnpm test # Node 自带测试,离线回归
203
203
  | 模块 | 职责 |
204
204
  | --- | --- |
205
205
  | `loopback.ts` | 回环端点的安全模型(Host 与 Origin 校验)、响应写入、流式中继与报错脱敏 |
206
- | `accounts.ts` | WorkBuddy 登录文件解析、令牌加解密、账号池与冷却 |
206
+ | `accounts.ts` | WorkBuddy 登录文件解析、账号池与冷却 |
207
207
  | `upstream.ts` | WorkBuddy 上游客户端、错误分类、限流重置解析 |
208
208
  | `catalog.ts` | 模型目录与静态兜底列表 |
209
209
  | `shim.ts` | WorkBuddy 网关的 OpenAI 兼容端点 |
package/lib/index.js CHANGED
@@ -1920,17 +1920,8 @@ function parseUpstreamModel(value) {
1920
1920
  ...supportsImages === void 0 ? {} : { supportsImages }
1921
1921
  };
1922
1922
  }
1923
- /**
1924
- * Put an empty system prompt in front of the conversation when the host opened
1925
- * with a user turn.
1926
- *
1927
- * The international gateway refuses a request whose first message is not a
1928
- * system prompt (code 11128, "first message is not system prompt"), and a host
1929
- * that starts with the user's turn sends none. The content is empty on purpose:
1930
- * it satisfies the check without adding an instruction the model would follow,
1931
- * so the model still sees exactly what the host sent. The CN gateway asks for
1932
- * neither, so this is the one part of the shape that is region-specific.
1933
- */
1923
+ const NEUTRAL_SYSTEM_PROMPT = "You are a helpful assistant.";
1924
+ /** Global requires a leading system turn; Kimi rejects an empty placeholder. */
1934
1925
  function withLeadingSystemPrompt(prepared) {
1935
1926
  let body;
1936
1927
  try {
@@ -1946,7 +1937,7 @@ function withLeadingSystemPrompt(prepared) {
1946
1937
  if (typeof first === "object" && first !== null && first["role"] === "system") return prepared;
1947
1938
  obj["messages"] = [{
1948
1939
  role: "system",
1949
- content: ""
1940
+ content: NEUTRAL_SYSTEM_PROMPT
1950
1941
  }, ...messages];
1951
1942
  return JSON.stringify(obj);
1952
1943
  }
@@ -2001,7 +1992,7 @@ function contentText(content) {
2001
1992
  * quoted the client name would fail the next request; that copy is renamed. A
2002
1993
  * neutral system message stays first so a gateway that insists on one still sees
2003
1994
  * it. Returns undefined when there is nothing to move or rename, which is also
2004
- * what keeps an empty system message from looping.
1995
+ * what keeps the neutral placeholder from folding into the user turn again.
2005
1996
  */
2006
1997
  function foldSystemIntoUser(prepared) {
2007
1998
  let body;
@@ -2017,12 +2008,14 @@ function foldSystemIntoUser(prepared) {
2017
2008
  const prompts = [];
2018
2009
  const rest = [];
2019
2010
  let renamed = false;
2011
+ let hadSystem = false;
2020
2012
  for (const value of messages) {
2021
2013
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
2022
2014
  const message = value;
2023
2015
  if (message["role"] === "system" || message["role"] === "developer") {
2016
+ hadSystem = true;
2024
2017
  const text = contentText(message["content"]);
2025
- if (text.trim() !== "") prompts.push(text);
2018
+ if (text.trim() !== "" && text !== NEUTRAL_SYSTEM_PROMPT) prompts.push(text);
2026
2019
  continue;
2027
2020
  }
2028
2021
  if (message["role"] === "assistant" && "content" in message) {
@@ -2041,7 +2034,10 @@ function foldSystemIntoUser(prepared) {
2041
2034
  }
2042
2035
  if (prompts.length === 0 && !renamed) return void 0;
2043
2036
  if (prompts.length === 0) {
2044
- obj["messages"] = rest;
2037
+ obj["messages"] = hadSystem ? [{
2038
+ role: "system",
2039
+ content: NEUTRAL_SYSTEM_PROMPT
2040
+ }, ...rest] : rest;
2045
2041
  return JSON.stringify(obj);
2046
2042
  }
2047
2043
  const instructions = prompts.join("\n\n");
@@ -2063,7 +2059,7 @@ function foldSystemIntoUser(prepared) {
2063
2059
  }
2064
2060
  obj["messages"] = [{
2065
2061
  role: "system",
2066
- content: ""
2062
+ content: NEUTRAL_SYSTEM_PROMPT
2067
2063
  }, ...rest];
2068
2064
  return JSON.stringify(obj);
2069
2065
  }
@@ -3846,11 +3842,12 @@ function ownSignInOf(credential) {
3846
3842
  * account rewrites its own file instead of leaving a second copy behind, and
3847
3843
  * two accounts never collide on a name.
3848
3844
  */
3849
- async function writeOwnSignIn(directory, signIn) {
3845
+ async function writeOwnSignIn(directory, signIn, signal) {
3850
3846
  const stable = signIn.uin === "" ? signIn.uid : signIn.uin;
3851
3847
  const suffix = stable === "" ? randomUUID() : stable.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 32);
3852
3848
  const file = join(directory, `${OWN_SIGN_IN_PREFIX}${suffix === "" ? randomUUID() : suffix}.info`);
3853
3849
  await mkdir(directory, { recursive: true });
3850
+ signal?.throwIfAborted();
3854
3851
  await writeFile(file, JSON.stringify({
3855
3852
  auth: {
3856
3853
  accessToken: signIn.accessToken,
@@ -3993,8 +3990,9 @@ async function readArchivedCredentials(file) {
3993
3990
  * leave a truncated file behind if it is interrupted: temp file, then rename.
3994
3991
  * Only the archived credential is stored, not the raw sign-in document.
3995
3992
  */
3996
- async function writeArchivedCredentials(file, entries) {
3993
+ async function writeArchivedCredentials(file, entries, signal) {
3997
3994
  await mkdir(dirname(file), { recursive: true });
3995
+ signal?.throwIfAborted();
3998
3996
  const body = JSON.stringify({
3999
3997
  version: 1,
4000
3998
  entries: [...entries].map(([id, credential]) => ({
@@ -4018,6 +4016,7 @@ async function writeArchivedCredentials(file, entries) {
4018
4016
  encoding: "utf8",
4019
4017
  mode: 384
4020
4018
  });
4019
+ signal?.throwIfAborted();
4021
4020
  await rename(temporary, file);
4022
4021
  } catch (error) {
4023
4022
  await unlink(temporary).catch(() => {});
@@ -4097,6 +4096,7 @@ var WorkBuddyAccountPool = class {
4097
4096
  deletedSignInsStamp;
4098
4097
  /** The directories the in-flight scan is reading, so a repoint supersedes it. */
4099
4098
  scanDirs = [];
4099
+ scanAbort = new AbortController();
4100
4100
  /**
4101
4101
  * Accounts whose "expired with no refresh token" warning has been logged.
4102
4102
  *
@@ -4168,7 +4168,7 @@ var WorkBuddyAccountPool = class {
4168
4168
  let emptied = false;
4169
4169
  if (options.authDirs !== void 0 && options.authDirs.length > 0) {
4170
4170
  if (!sameDirs(this.authDirs, options.authDirs)) {
4171
- this.accounts = [];
4171
+ this.clear();
4172
4172
  emptied = true;
4173
4173
  }
4174
4174
  this.authDirs = options.authDirs;
@@ -4317,9 +4317,10 @@ var WorkBuddyAccountPool = class {
4317
4317
  * client's directory until the client overwrites it, so a tombstone that
4318
4318
  * expired would bring that copy straight back, refresh token included.
4319
4319
  */
4320
- async loadDeletedSignIns() {
4320
+ async loadDeletedSignIns(signal) {
4321
4321
  const file = this.deletedSignInsFile();
4322
4322
  const stamp = file === void 0 ? "" : await signInFileStamp(file);
4323
+ if (signal?.aborted) return this.deletedSignIns ?? /* @__PURE__ */ new Map();
4323
4324
  if (this.deletedSignIns !== void 0 && this.deletedSignInsStamp === stamp) return this.deletedSignIns;
4324
4325
  if (file === void 0) {
4325
4326
  this.deletedSignInsStamp = "";
@@ -4328,10 +4329,12 @@ var WorkBuddyAccountPool = class {
4328
4329
  }
4329
4330
  try {
4330
4331
  const tombstones = await readDeletedSignInsFile(file);
4332
+ if (signal?.aborted) return this.deletedSignIns ?? /* @__PURE__ */ new Map();
4331
4333
  this.deletedSignInsStamp = stamp;
4332
4334
  this.deletedSignIns = tombstones;
4333
4335
  return tombstones;
4334
4336
  } catch (error) {
4337
+ if (signal?.aborted) return this.deletedSignIns ?? /* @__PURE__ */ new Map();
4335
4338
  if (error.code === "ENOENT") {
4336
4339
  this.deletedSignInsStamp = stamp;
4337
4340
  this.deletedSignIns = /* @__PURE__ */ new Map();
@@ -4353,13 +4356,15 @@ var WorkBuddyAccountPool = class {
4353
4356
  * Answers false when the file could not be written, so a delete can refuse to
4354
4357
  * report success on a state it could not record.
4355
4358
  */
4356
- async writeDeletedSignIns(removed = []) {
4359
+ async writeDeletedSignIns(removed = [], signal) {
4357
4360
  const tombstones = this.deletedSignIns;
4358
4361
  const file = this.deletedSignInsFile();
4359
4362
  if (tombstones === void 0 || file === void 0) return true;
4360
4363
  let written = false;
4361
4364
  await withFileLock(`${file}.lock`, async () => {
4365
+ if (signal?.aborted) return;
4362
4366
  const onDisk = await readDeletedSignInsFile(file).catch(() => /* @__PURE__ */ new Map());
4367
+ if (signal?.aborted) return;
4363
4368
  for (const [id, entry] of onDisk) {
4364
4369
  if (removed.includes(id)) continue;
4365
4370
  const ours = tombstones.get(id);
@@ -4368,16 +4373,19 @@ var WorkBuddyAccountPool = class {
4368
4373
  const temporary = `${file}.${randomUUID()}.tmp`;
4369
4374
  try {
4370
4375
  await mkdir(dirname(file), { recursive: true });
4376
+ signal?.throwIfAborted();
4371
4377
  await writeFile(temporary, JSON.stringify({
4372
4378
  version: 1,
4373
4379
  entries: Object.fromEntries(tombstones)
4374
4380
  }, null, 2), { mode: 384 });
4381
+ signal?.throwIfAborted();
4375
4382
  await rename(temporary, file);
4376
- this.deletedSignInsStamp = await signInFileStamp(file);
4383
+ const stamp = await signInFileStamp(file);
4384
+ if (!signal?.aborted && this.deletedSignIns === tombstones) this.deletedSignInsStamp = stamp;
4377
4385
  written = true;
4378
4386
  } catch (error) {
4379
4387
  await unlink(temporary).catch(() => {});
4380
- this.logger?.warn?.(`${LOG_PREFIX}: could not record the deleted sign-ins: ${String(error)}`);
4388
+ if (!signal?.aborted) this.logger?.warn?.(`${LOG_PREFIX}: could not record the deleted sign-ins: ${String(error)}`);
4381
4389
  }
4382
4390
  });
4383
4391
  return written;
@@ -4427,7 +4435,7 @@ var WorkBuddyAccountPool = class {
4427
4435
  * refreshing on its own schedule is how both end up with a spent refresh
4428
4436
  * token. An account the client is signed into is skipped for the same reason.
4429
4437
  */
4430
- async adoptOrphanedSignIns(found, tornDown) {
4438
+ async adoptOrphanedSignIns(found, tornDown, signal) {
4431
4439
  const directory = ownSignInDir(this.dataPath?.() ?? "");
4432
4440
  if (directory === "") return [];
4433
4441
  const liveIds = /* @__PURE__ */ new Set();
@@ -4439,6 +4447,7 @@ var WorkBuddyAccountPool = class {
4439
4447
  }
4440
4448
  const adopted = [];
4441
4449
  for (const credential of found) {
4450
+ if (signal.aborted) break;
4442
4451
  if (isLiveAuthFile(credential.sourcePath)) continue;
4443
4452
  if (ownSignInPath(credential.sourcePath, directory)) continue;
4444
4453
  const id = workbuddyAccountId(credential);
@@ -4449,8 +4458,9 @@ var WorkBuddyAccountPool = class {
4449
4458
  file = await writeOwnSignIn(directory, {
4450
4459
  ...ownSignInOf(credential),
4451
4460
  lastRefreshAtMs: credential.lastRefreshAtMs ?? 0
4452
- });
4461
+ }, signal);
4453
4462
  } catch (error) {
4463
+ if (signal.aborted) break;
4454
4464
  this.logger?.warn?.(`${LOG_PREFIX}: could not take over ${accountLogTag(accountLabel(credential))}: ${String(error)}`);
4455
4465
  continue;
4456
4466
  }
@@ -4510,14 +4520,25 @@ var WorkBuddyAccountPool = class {
4510
4520
  }
4511
4521
  /** Drop every account, e.g. when the source is switched off. A later `scan()` rebuilds from disk. */
4512
4522
  clear() {
4523
+ this.scanAbort.abort();
4524
+ this.scanAbort = new AbortController();
4525
+ this.scanInflight = void 0;
4526
+ this.scanDirs = [];
4513
4527
  this.accounts = [];
4514
4528
  this.appHeldIds = /* @__PURE__ */ new Set();
4515
4529
  }
4516
- /** Rescan the auth directories and merge newly discovered accounts. */
4530
+ /** Read after any scan already running, so a manual request gets a fresh snapshot. */
4531
+ async rescan() {
4532
+ const signal = this.scanAbort.signal;
4533
+ await this.scanInflight?.catch(() => {});
4534
+ if (signal.aborted) return this.accounts;
4535
+ return this.scan();
4536
+ }
4537
+ /** Scan the auth directories and merge newly discovered accounts. */
4517
4538
  async scan() {
4518
4539
  const dirs = this.scanDirsFor(this.authDirs);
4519
4540
  if (this.scanInflight !== void 0 && sameDirs(this.scanDirs, dirs)) return this.scanInflight;
4520
- const inflight = this.scanOnce(dirs).finally(() => {
4541
+ const inflight = this.scanOnce(dirs, this.scanAbort.signal).finally(() => {
4521
4542
  if (this.scanInflight === inflight) {
4522
4543
  this.scanInflight = void 0;
4523
4544
  this.scanDirs = [];
@@ -4548,12 +4569,14 @@ var WorkBuddyAccountPool = class {
4548
4569
  *
4549
4570
  * Best effort by design: a failed write costs the archive, never the scan.
4550
4571
  */
4551
- async archiveCredentials(credentials) {
4572
+ async archiveCredentials(credentials, signal) {
4552
4573
  const file = this.archiveFile();
4553
4574
  if (file === void 0 || credentials.length === 0) return;
4554
4575
  const ownDir = ownSignInDir(this.dataPath?.() ?? "");
4555
4576
  const run = this.archiveQueue.then(async () => {
4577
+ if (signal?.aborted) return;
4556
4578
  const stored = await readArchivedCredentials(file);
4579
+ if (signal?.aborted) return;
4557
4580
  let changed = false;
4558
4581
  for (const credential of credentials) {
4559
4582
  const id = workbuddyAccountId(credential);
@@ -4562,13 +4585,13 @@ var WorkBuddyAccountPool = class {
4562
4585
  stored.set(id, credential);
4563
4586
  changed = true;
4564
4587
  }
4565
- if (changed) await writeArchivedCredentials(file, stored);
4588
+ if (changed) await writeArchivedCredentials(file, stored, signal);
4566
4589
  });
4567
4590
  this.archiveQueue = run.catch(() => {});
4568
4591
  try {
4569
4592
  await run;
4570
4593
  } catch (error) {
4571
- this.logger?.warn?.(`${LOG_PREFIX}: could not update the credential archive: ${String(error)}`);
4594
+ if (!signal?.aborted) this.logger?.warn?.(`${LOG_PREFIX}: could not update the credential archive: ${String(error)}`);
4572
4595
  }
4573
4596
  }
4574
4597
  /** Credentials the archive kept for a directory this walk can read. */
@@ -4590,21 +4613,25 @@ var WorkBuddyAccountPool = class {
4590
4613
  const directory = this.dataPath?.();
4591
4614
  return directory === void 0 || directory === "" ? void 0 : join(directory, ARCHIVE_FILENAME);
4592
4615
  }
4593
- async scanOnce(dirs) {
4616
+ async scanOnce(dirs, signal = this.scanAbort.signal) {
4594
4617
  const found = [];
4595
4618
  const readableDirs = /* @__PURE__ */ new Set();
4596
4619
  const sealedDirs = /* @__PURE__ */ new Set();
4597
4620
  for (const dir of dirs) {
4621
+ if (signal.aborted) return this.accounts;
4598
4622
  const files = await authFilesIn(dir);
4623
+ if (signal.aborted) return this.accounts;
4599
4624
  if (files === void 0) continue;
4600
4625
  readableDirs.add(resolve(dir));
4601
4626
  for (const file of files) {
4602
4627
  const read = await readCredential(file);
4628
+ if (signal.aborted) return this.accounts;
4603
4629
  if (read.kind === "credential") found.push(read.credential);
4604
4630
  else if (read.kind === "sealed") sealedDirs.add(resolve(dir));
4605
4631
  }
4606
4632
  }
4607
- const tombstones = await this.loadDeletedSignIns();
4633
+ const tombstones = await this.loadDeletedSignIns(signal);
4634
+ if (signal.aborted) return this.accounts;
4608
4635
  const tornDown = /* @__PURE__ */ new Set();
4609
4636
  const releasedIds = [];
4610
4637
  const held = [];
@@ -4626,9 +4653,12 @@ var WorkBuddyAccountPool = class {
4626
4653
  found.length = 0;
4627
4654
  found.push(...held);
4628
4655
  for (const id of tombstones.keys()) tornDown.add(id);
4629
- if (releasedIds.length > 0) await this.writeDeletedSignIns(releasedIds);
4630
- await this.archiveCredentials(found);
4631
- found.push(...await this.adoptOrphanedSignIns(found, tornDown));
4656
+ if (releasedIds.length > 0) await this.writeDeletedSignIns(releasedIds, signal);
4657
+ if (signal.aborted) return this.accounts;
4658
+ await this.archiveCredentials(found, signal);
4659
+ if (signal.aborted) return this.accounts;
4660
+ found.push(...await this.adoptOrphanedSignIns(found, tornDown, signal));
4661
+ if (signal.aborted) return this.accounts;
4632
4662
  const signInTokens = /* @__PURE__ */ new Map();
4633
4663
  for (const credential of found) {
4634
4664
  const id = workbuddyAccountId(credential);
@@ -4638,7 +4668,9 @@ var WorkBuddyAccountPool = class {
4638
4668
  }
4639
4669
  const liveIds = new Set(found.map((credential) => workbuddyAccountId(credential)));
4640
4670
  const appHeld = new Set(found.filter((credential) => isLiveAuthFile(credential.sourcePath)).map((credential) => workbuddyAccountId(credential)));
4641
- for (const credential of await this.archivedCredentials(readableDirs)) {
4671
+ const archived = await this.archivedCredentials(readableDirs);
4672
+ if (signal.aborted) return this.accounts;
4673
+ for (const credential of archived) {
4642
4674
  const id = workbuddyAccountId(credential);
4643
4675
  if (tornDown.has(id)) continue;
4644
4676
  if (found.some((entry) => workbuddyAccountId(entry) === id && entry.accessToken === credential.accessToken)) continue;
@@ -4811,27 +4843,32 @@ var WorkBuddyAccountPool = class {
4811
4843
  * fresh desktop login is the usual way out of an exhausted pool.
4812
4844
  */
4813
4845
  async acquire(modelId, region, conversationKey, excludeIds) {
4846
+ const signal = this.scanAbort.signal;
4814
4847
  const eligibleNow = () => {
4815
4848
  const list = this.available(Date.now(), modelId, region);
4816
4849
  return excludeIds === void 0 ? list : list.filter((item) => !excludeIds.has(item.id));
4817
4850
  };
4818
4851
  if (this.accounts.length === 0) await this.scan();
4852
+ if (signal.aborted) return void 0;
4819
4853
  let pool = eligibleNow();
4820
4854
  if (pool.length === 0) {
4821
4855
  await this.scan();
4856
+ if (signal.aborted) return void 0;
4822
4857
  pool = eligibleNow();
4823
4858
  }
4824
4859
  if (pool.length === 0) return void 0;
4825
4860
  const preferredId = this.preferredIds.get(region);
4826
- const account = pool.find((item) => item.id === preferredId) ?? this.pick(pool, conversationKey);
4827
- if (account === void 0) return void 0;
4828
- await this.ensureFresh(account);
4829
- const eligible = eligibleNow();
4830
- if (eligible.includes(account)) return account;
4831
- const next = eligible.find((item) => item.id === preferredId) ?? this.pick(eligible, conversationKey);
4832
- if (next === void 0) return void 0;
4833
- await this.ensureFresh(next);
4834
- return next;
4861
+ const remaining = new Set(pool.map((account) => account.id));
4862
+ while (remaining.size > 0) {
4863
+ const account = pool.find((item) => item.id === preferredId) ?? this.pick(pool, conversationKey);
4864
+ if (account === void 0) return void 0;
4865
+ remaining.delete(account.id);
4866
+ await this.ensureFresh(account);
4867
+ if (signal.aborted) return void 0;
4868
+ const eligible = eligibleNow();
4869
+ if (eligible.includes(account)) return account;
4870
+ pool = eligible.filter((item) => remaining.has(item.id));
4871
+ }
4835
4872
  }
4836
4873
  pick(pool, conversationKey) {
4837
4874
  if (this.distribution === "expiry") return this.pickByExpiry(pool);
@@ -5310,12 +5347,17 @@ const MAX_LINE_CHARS$1 = 67108864;
5310
5347
  */
5311
5348
  const MAX_DATA_CHARS = 4194304;
5312
5349
  var SseDecoder = class {
5350
+ onFrame;
5313
5351
  buffer = "";
5314
5352
  event;
5315
5353
  id;
5316
5354
  retry;
5317
5355
  data = [];
5318
5356
  dataChars = 0;
5357
+ rawFrame = "";
5358
+ constructor(onFrame) {
5359
+ this.onFrame = onFrame;
5360
+ }
5319
5361
  push(chunk) {
5320
5362
  this.buffer += chunk;
5321
5363
  const events = [];
@@ -5324,9 +5366,14 @@ var SseDecoder = class {
5324
5366
  if (match === null || match.index === void 0) break;
5325
5367
  if (match[0] === "\r" && match.index + 1 === this.buffer.length) break;
5326
5368
  const line = this.buffer.slice(0, match.index);
5369
+ if (this.onFrame !== void 0) this.appendRaw(this.buffer.slice(0, match.index + match[0].length));
5327
5370
  this.buffer = this.buffer.slice(match.index + match[0].length);
5328
5371
  const emitted = this.consumeLine(line);
5329
5372
  if (emitted !== void 0) events.push(emitted);
5373
+ if (line === "" && this.onFrame !== void 0) {
5374
+ this.onFrame(this.rawFrame, emitted);
5375
+ this.rawFrame = "";
5376
+ }
5330
5377
  }
5331
5378
  if (this.buffer.length > MAX_LINE_CHARS$1) {
5332
5379
  this.buffer = "";
@@ -5343,6 +5390,7 @@ var SseDecoder = class {
5343
5390
  finish() {
5344
5391
  const events = [];
5345
5392
  if (this.buffer !== "") {
5393
+ if (this.onFrame !== void 0) this.appendRaw(this.buffer);
5346
5394
  const tail = this.buffer.endsWith("\r") ? this.buffer.slice(0, -1) : this.buffer;
5347
5395
  const emitted = this.consumeLine(tail);
5348
5396
  this.buffer = "";
@@ -5350,8 +5398,19 @@ var SseDecoder = class {
5350
5398
  }
5351
5399
  const final = this.dispatch();
5352
5400
  if (final !== void 0) events.push(final);
5401
+ if (this.rawFrame !== "" && this.onFrame !== void 0) {
5402
+ this.onFrame(this.rawFrame, events[0]);
5403
+ this.rawFrame = "";
5404
+ }
5353
5405
  return events;
5354
5406
  }
5407
+ appendRaw(value) {
5408
+ if (this.rawFrame.length + value.length > MAX_DATA_CHARS) {
5409
+ this.rawFrame = "";
5410
+ throw new Error("sse event exceeded 4194304 characters of framing without a separator");
5411
+ }
5412
+ this.rawFrame += value;
5413
+ }
5355
5414
  consumeLine(line) {
5356
5415
  if (line === "") return this.dispatch();
5357
5416
  if (line.startsWith(":")) return void 0;
@@ -5464,13 +5523,19 @@ function decodeTraeEvent(event) {
5464
5523
  * Loopback guards, the request body bound and the server shell live in
5465
5524
  * `./loopback` — one copy, shared with the Trae and Qoder gateways.
5466
5525
  */
5467
- /** Whether one SSE data frame carries a non-null `finish_reason`. */
5468
- function carriesFinishReason(data) {
5526
+ function completionState(data) {
5469
5527
  try {
5470
5528
  const parsed = JSON.parse(data);
5471
- return Array.isArray(parsed.choices) && parsed.choices.some((choice) => typeof choice?.finish_reason === "string" && choice.finish_reason !== "");
5529
+ const choices = Array.isArray(parsed.choices) ? parsed.choices : [];
5530
+ return {
5531
+ finished: choices.some((choice) => typeof choice?.finish_reason === "string" && choice.finish_reason !== ""),
5532
+ toolCalls: choices.some((choice) => Array.isArray(choice?.delta?.tool_calls) && choice.delta.tool_calls.length > 0)
5533
+ };
5472
5534
  } catch {
5473
- return false;
5535
+ return {
5536
+ finished: false,
5537
+ toolCalls: false
5538
+ };
5474
5539
  }
5475
5540
  }
5476
5541
  /** HTTP status each upstream failure class surfaces as. */
@@ -5885,10 +5950,20 @@ function createWorkBuddyShim(options) {
5885
5950
  const reader = relayStreamOf(result.response).getReader();
5886
5951
  let sawDone = false;
5887
5952
  let sawFinish = false;
5953
+ let sawToolCalls = false;
5888
5954
  let envelopeFailure;
5889
5955
  let headFailure;
5890
5956
  const decoder = new TextDecoder();
5891
- const sse = new SseDecoder();
5957
+ const frames = [];
5958
+ const sse = new SseDecoder((raw, event) => frames.push({
5959
+ raw,
5960
+ event
5961
+ }));
5962
+ const finishChunk = () => Buffer.from(`data: ${JSON.stringify({ choices: [{
5963
+ index: 0,
5964
+ delta: {},
5965
+ finish_reason: openAIFinishReason(void 0, sawToolCalls)
5966
+ }] })}\n\n`);
5892
5967
  const startStream = () => {
5893
5968
  res.writeHead(200, {
5894
5969
  "Content-Type": "text/event-stream",
@@ -5929,13 +6004,32 @@ function createWorkBuddyShim(options) {
5929
6004
  function closeWithoutDone() {
5930
6005
  if (sawDone || !res.writable) return;
5931
6006
  logger?.warn?.("wtq-pool: upstream stream ended without [DONE]");
5932
- if (!sawFinish) res.write(`data: ${JSON.stringify({ choices: [{
5933
- index: 0,
5934
- delta: {},
5935
- finish_reason: "stop"
5936
- }] })}\n\n`);
6007
+ if (!sawFinish) res.write(finishChunk());
5937
6008
  res.end("data: [DONE]\n\n");
5938
6009
  }
6010
+ const relayFrames = async (finishTail = false) => {
6011
+ for (const { raw, event } of frames.splice(0)) {
6012
+ const chunk = Buffer.from(finishTail ? raw + "\n\n" : raw);
6013
+ if (event?.data === "[DONE]") {
6014
+ if (!sawFinish) {
6015
+ await writeChunk(res, finishChunk());
6016
+ sawFinish = true;
6017
+ }
6018
+ await writeChunk(res, chunk);
6019
+ sawDone = true;
6020
+ res.end();
6021
+ await reader.cancel().catch(() => {});
6022
+ return true;
6023
+ }
6024
+ if (event !== void 0) {
6025
+ const state = completionState(event.data);
6026
+ sawFinish ||= state.finished;
6027
+ sawToolCalls ||= state.toolCalls;
6028
+ }
6029
+ await writeChunk(res, chunk);
6030
+ }
6031
+ return false;
6032
+ };
5939
6033
  await (async () => {
5940
6034
  let head = [];
5941
6035
  let ended = false;
@@ -6008,33 +6102,15 @@ function createWorkBuddyShim(options) {
6008
6102
  } : await reader.read();
6009
6103
  if (done || value === void 0) break;
6010
6104
  if (!res.writable) return;
6011
- await writeChunk(res, value);
6012
- try {
6013
- const decoded = decoder.decode(value, { stream: true });
6014
- const events = sse.push(decoded);
6015
- if (!sawFinish && events.some((event) => carriesFinishReason(event.data))) sawFinish = true;
6016
- if (events.some((event) => event.data === "[DONE]")) {
6017
- if (!sawFinish && res.writable) {
6018
- res.write(`data: ${JSON.stringify({ choices: [{
6019
- index: 0,
6020
- delta: {},
6021
- finish_reason: "stop"
6022
- }] })}\n\n`);
6023
- sawFinish = true;
6024
- }
6025
- sawDone = true;
6026
- if (res.writable) res.end();
6027
- await reader.cancel().catch(() => {});
6028
- return;
6029
- }
6030
- } catch {}
6105
+ sse.push(decoder.decode(value, { stream: true }));
6106
+ if (await relayFrames()) return;
6031
6107
  }
6032
- if (!sawDone) try {
6108
+ if (!sawDone) {
6033
6109
  const rest = decoder.decode();
6034
- const events = rest === "" ? sse.finish() : [...sse.push(rest), ...sse.finish()];
6035
- if (events.some((event) => event.data === "[DONE]")) sawDone = true;
6036
- if (events.some((event) => carriesFinishReason(event.data))) sawFinish = true;
6037
- } catch {}
6110
+ if (rest !== "") sse.push(rest);
6111
+ sse.finish();
6112
+ if (await relayFrames(true)) return;
6113
+ }
6038
6114
  closeWithoutDone();
6039
6115
  } catch (error) {
6040
6116
  failInBand(error);
@@ -13831,7 +13907,7 @@ async function refreshAll(reason, force) {
13831
13907
  await adoptHostSettings();
13832
13908
  if (!stillLoaded(generation)) return stalePass();
13833
13909
  applySettingsToCore();
13834
- if (poolNeedsScan) {
13910
+ if (poolNeedsScan && activeRegions().length > 0) {
13835
13911
  poolNeedsScan = false;
13836
13912
  await settle(core.pool.scan());
13837
13913
  if (!stillLoaded(generation)) return stalePass();
@@ -15066,7 +15142,7 @@ async function onPanelInvoke(channel, payload) {
15066
15142
  resetDiscoveryCaches();
15067
15143
  growthRead = null;
15068
15144
  growthReadEpoch += 1;
15069
- if (activeRegions().length > 0) await settle(core.pool.scan());
15145
+ if (activeRegions().length > 0) await settle(core.pool.rescan());
15070
15146
  await settle(startRuntimes());
15071
15147
  await settle(refreshSourceAccounts());
15072
15148
  await settle(reconcileTraeGateways());
@@ -15518,6 +15594,7 @@ async function onPanelInvoke(channel, payload) {
15518
15594
  throw panelError("the login link has expired; start again", "LOGIN_EXPIRED");
15519
15595
  }
15520
15596
  const answer = await pollDeviceLogin(realm, pending.state);
15597
+ if (deviceLogins.get(realm) !== pending) throw panelError("this login is no longer waiting; start again", "NO_LOGIN");
15521
15598
  if (answer.status !== "ok") return { status: "pending" };
15522
15599
  deviceLogins.delete(realm);
15523
15600
  const directory = ownSignInDir(dataPath);
@@ -15750,7 +15827,7 @@ async function runCheckinPass(options) {
15750
15827
  if (want("qoder")) {
15751
15828
  const now = Date.now();
15752
15829
  const opening = typeof qoder?.opensAt === "number" && qoder.opensAt > now ? qoder.opensAt : 0;
15753
- const backoff = Number(qoder?.failed) > 0 && (typeof qoder?.reason === "string" || qoder?.retry === true) ? now + QODER_RETRY_BACKOFF_MS : 0;
15830
+ const backoff = Number(qoder?.failed) > 0 && qoder?.retry !== false && (typeof qoder?.reason === "string" || qoder?.retry === true) ? now + QODER_RETRY_BACKOFF_MS : 0;
15754
15831
  qoderRetryAt = opening === 0 ? backoff : backoff === 0 ? opening : Math.min(opening, backoff);
15755
15832
  }
15756
15833
  Object.assign(started, {
@@ -15845,9 +15922,20 @@ async function redeemAccountStreak(account) {
15845
15922
  lottery: 0,
15846
15923
  failed: 0
15847
15924
  };
15925
+ const result = {
15926
+ claimed: 0,
15927
+ credit: 0,
15928
+ energy: 0,
15929
+ detail
15930
+ };
15931
+ const signal = currentCheckinSignal();
15932
+ if (signal.aborted) return result;
15848
15933
  const conversationId = "wb2api-streak-" + Date.now();
15849
15934
  try {
15850
- if (await core.client.makeupCards(account.credential) > 0 && await core.client.missedYesterday(account.credential)) {
15935
+ const cards = await core.client.makeupCards(account.credential);
15936
+ if (signal.aborted) return result;
15937
+ if (cards > 0 && await core.client.missedYesterday(account.credential)) {
15938
+ if (signal.aborted) return result;
15851
15939
  const yesterday = zonedDay(-1);
15852
15940
  await core.client.useMakeupCard(account.credential, yesterday);
15853
15941
  detail.makeup += 1;
@@ -15857,13 +15945,17 @@ async function redeemAccountStreak(account) {
15857
15945
  detail.failed += 1;
15858
15946
  log("warn", "streak " + accountLogTag(account.label) + ": make-up: " + safeMessage(error));
15859
15947
  }
15860
- for (const [label, collect] of [["gift", () => core.client.claimGift(account.credential)], ["compensation", () => core.client.claimCompensation(account.credential)]]) try {
15861
- const paid = await collect();
15862
- if (paid > 0) {
15863
- detail[label] += paid;
15864
- log("info", "streak " + accountLogTag(account.label) + ": " + label + " +" + paid + "c");
15865
- }
15866
- } catch {}
15948
+ for (const [label, collect] of [["gift", () => core.client.claimGift(account.credential)], ["compensation", () => core.client.claimCompensation(account.credential)]]) {
15949
+ if (signal.aborted) return result;
15950
+ try {
15951
+ const paid = await collect();
15952
+ if (paid > 0) {
15953
+ detail[label] += paid;
15954
+ log("info", "streak " + accountLogTag(account.label) + ": " + label + " +" + paid + "c");
15955
+ }
15956
+ } catch {}
15957
+ }
15958
+ if (signal.aborted) return result;
15867
15959
  try {
15868
15960
  await core.client.reportChatActivity(account.credential, conversationId);
15869
15961
  detail.activity += 1;
@@ -15872,17 +15964,16 @@ async function redeemAccountStreak(account) {
15872
15964
  log("warn", "streak " + accountLogTag(account.label) + ": activity report failed: " + safeMessage(error));
15873
15965
  }
15874
15966
  await checkinDelay(STREAK_REPORT_READ_GAP_MS);
15967
+ if (signal.aborted) return result;
15875
15968
  const status = await core.client.growthStreakFull(account.credential);
15876
- let claimed = 0;
15877
- let credit = 0;
15878
- let energy = 0;
15879
15969
  for (const tier of status.tiers) {
15880
15970
  if (tier.status !== "unlocked") continue;
15971
+ if (signal.aborted) return result;
15881
15972
  try {
15882
15973
  await core.client.redeemStreakTier(account.credential, tier.tier);
15883
- claimed += 1;
15884
- credit += tier.credit;
15885
- energy += tier.energy;
15974
+ result.claimed += 1;
15975
+ result.credit += tier.credit;
15976
+ result.energy += tier.energy;
15886
15977
  detail.streak += 1;
15887
15978
  log("info", "streak " + accountLogTag(account.label) + ": redeemed " + tier.tier + " (+" + tier.credit + "c +" + tier.energy + "e)");
15888
15979
  } catch (error) {
@@ -15890,9 +15981,11 @@ async function redeemAccountStreak(account) {
15890
15981
  log("warn", "streak " + accountLogTag(account.label) + ": redeem " + tier.tier + " failed: " + safeMessage(error));
15891
15982
  }
15892
15983
  }
15984
+ if (signal.aborted) return result;
15893
15985
  try {
15894
15986
  const chances = await core.client.lotteryChances(account.credential);
15895
15987
  for (let draw = 0; draw < chances; draw += 1) {
15988
+ if (signal.aborted) return result;
15896
15989
  const prize = await core.client.drawLottery(account.credential);
15897
15990
  detail.lottery += 1;
15898
15991
  log("info", "streak " + accountLogTag(account.label) + ": draw " + (draw + 1) + "/" + chances + " " + JSON.stringify(prize).slice(0, 160));
@@ -15901,12 +15994,7 @@ async function redeemAccountStreak(account) {
15901
15994
  detail.failed += 1;
15902
15995
  log("warn", "streak " + accountLogTag(account.label) + ": lottery: " + safeMessage(error));
15903
15996
  }
15904
- return {
15905
- claimed,
15906
- credit,
15907
- energy,
15908
- detail
15909
- };
15997
+ return result;
15910
15998
  }
15911
15999
  /**
15912
16000
  * Collect the streak bonus of every account.
@@ -16241,7 +16329,8 @@ async function qoderCheckinAll() {
16241
16329
  return {
16242
16330
  ...counts,
16243
16331
  failed: 1,
16244
- reason
16332
+ reason,
16333
+ retry: true
16245
16334
  };
16246
16335
  }
16247
16336
  if (found.failures.length > 0) {
@@ -16256,6 +16345,7 @@ async function qoderCheckinAll() {
16256
16345
  seen += 1;
16257
16346
  const result = await qoderClaimFor(credential);
16258
16347
  counts[result.outcome] += 1;
16348
+ if (result.outcome === "failed" && counts.reason === void 0 && result.reason) counts.reason = safeMessage(result.reason);
16259
16349
  markSourceCheckinRow("qoder", qoderRowLabel(credential), credential.region, result);
16260
16350
  if (result.retry === true) counts.retry = true;
16261
16351
  if (result.opensAt !== void 0 && (counts.opensAt === void 0 || result.opensAt < counts.opensAt)) counts.opensAt = result.opensAt;
@@ -16294,10 +16384,11 @@ async function qoderClaimFor(credential) {
16294
16384
  }
16295
16385
  const result = qoderNormalizeClaimResult(await client.claimCampaign(id));
16296
16386
  if (result.reason !== void 0) {
16297
- log("warn", "[qoder:" + credential.region + "] check-in refused for " + accountLogTag(qoderRowLabel(credential)) + ": " + result.reason);
16387
+ const reason = safeMessage(result.reason);
16388
+ log("warn", "[qoder:" + credential.region + "] check-in refused for " + accountLogTag(qoderRowLabel(credential)) + ": " + reason);
16298
16389
  return {
16299
16390
  outcome: "failed",
16300
- reason: result.reason,
16391
+ reason,
16301
16392
  retry: false
16302
16393
  };
16303
16394
  }
@@ -16362,6 +16453,7 @@ async function traeCheckinAll() {
16362
16453
  if (index > 0) await checkinDelay(Math.max(1e3, TRAE_ACCOUNT_DELAY_MS + Math.round((Math.random() * 2 - 1) * TRAE_ACCOUNT_JITTER_MS)));
16363
16454
  const result = await traeClaimFor(credential, desktopCandidates);
16364
16455
  counts[result.outcome] += 1;
16456
+ if (result.outcome === "failed" && counts.reason === void 0 && result.reason) counts.reason = safeMessage(result.reason);
16365
16457
  markSourceCheckinRow("trae", traeRowLabel(credential), "cn", result);
16366
16458
  if (result.deviceCheckedIn === true) spentEditions.add(credential.edition);
16367
16459
  }
@@ -16528,7 +16620,7 @@ async function autoCheckinTick(now) {
16528
16620
  if (!stillLoaded(retryGeneration)) return autoCheckinLast;
16529
16621
  const now = Date.now();
16530
16622
  const opening = typeof retry.opensAt === "number" && retry.opensAt > now ? retry.opensAt : 0;
16531
- const backoff = Number(retry.failed) > 0 && (typeof retry.reason === "string" || retry.retry === true) ? now + QODER_RETRY_BACKOFF_MS : 0;
16623
+ const backoff = Number(retry.failed) > 0 && retry.retry !== false && (typeof retry.reason === "string" || retry.retry === true) ? now + QODER_RETRY_BACKOFF_MS : 0;
16532
16624
  qoderRetryAt = opening === 0 ? backoff : backoff === 0 ? opening : Math.min(opening, backoff);
16533
16625
  const claimedBefore = Number(autoCheckinLast?.qoder?.claimed) || 0;
16534
16626
  autoCheckinLast = {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-wtq-pool",
3
3
  "displayName": "WTQ Pool",
4
4
  "description": "把本机 WorkBuddy、Trae、Qoder 的桌面登录接入 DeepSeek Harness。限流或额度用尽时自动换号,三家各自开关,国内与国际账号分别成组。",
5
- "version": "1.2.1",
5
+ "version": "1.2.2",
6
6
  "license": "MIT",
7
7
  "author": "chengzhi-c",
8
8
  "homepage": "https://github.com/chengzhi-c/dsh-wtq-pool#readme",
@@ -859,6 +859,7 @@ button.park:hover:not(:disabled) { filter: brightness(1.08); background: var(--x
859
859
  color: var(--xd-muted);
860
860
  font-variant-numeric: tabular-nums;
861
861
  }
862
+ .credits-head:is(:hover, :active) .count-chip { color: var(--xd-fg); }
862
863
 
863
864
  /* ---------------------------------------------------- model columns */
864
865
 
package/renderer/panel.js CHANGED
@@ -29,7 +29,7 @@ var EN = {
29
29
  "tab.models": "Models",
30
30
  "tab.check": "Connection check",
31
31
  "tab.growth": "Growth centre",
32
- "risk.note": "! A ban is possible. Use at your own discretion; no liability accepted !",
32
+ "risk.note": "Unofficial clients may trigger account restrictions. Follow each vendor's terms of service.",
33
33
  "host.missing": "The host has not registered {count} model group(s) from this plugin yet: reload the plugin.",
34
34
  "btn.rescan": "Detect accounts again",
35
35
  "btn.reset": "Clear all cooldowns",
@@ -316,7 +316,7 @@ var ZH = {
316
316
  "tab.models": "模型",
317
317
  "tab.check": "连接检查",
318
318
  "tab.growth": "成长中心",
319
- "risk.note": "!可能有封号风险,请斟酌使用,概不负责 !",
319
+ "risk.note": "非官方客户端可能触发账号风控,请遵守厂商服务条款。",
320
320
  "host.missing": "宿主还没有注册本插件的 {count} 个模型组:重新加载插件。",
321
321
  "btn.rescan": "重新检测账号",
322
322
  "btn.reset": "清除所有冷却",