dsh-wtq-pool 1.0.3 → 1.0.4
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 +10 -0
- package/README.en.md +6 -4
- package/README.md +7 -5
- package/lib/index.js +291 -117
- package/package.json +1 -1
- package/renderer/panel.js +68 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# 更新说明
|
|
2
2
|
|
|
3
|
+
## [1.0.4]
|
|
4
|
+
|
|
5
|
+
- Trae、Qoder 的流式回复改为单循环推送:宿主不再反复回调读取,回复不会中途停住;网关先发出响应头,再从桥接流直接泵出,不再读 `Response` 的 body,也不再经过 `Readable.fromWeb`。
|
|
6
|
+
- Qoder 在结束帧后最多等 1 秒:没有后续帧就补上 `[DONE]` 并关闭,用量帧到达则立即收尾,回复写完不再一直显示未完成(上一版的一秒宽限只取消了上游读取,没有关闭转发流)。
|
|
7
|
+
- WorkBuddy 网关同样先发出响应头;其余行为不变。
|
|
8
|
+
- 面板的签到汇总按三家合计显示领取账号数,不再只算 WorkBuddy。
|
|
9
|
+
- 网关拒绝跨站请求(`Sec-Fetch-Site: cross-site`),面板的 `/invoke` 只接受 JSON;本机客户端与面板自身不受影响。
|
|
10
|
+
- 面板的签到日志持续轮询到结束,模型勾选与自动签到时间的未保存草稿不再被轮询覆盖,日志不再强制滚到底部,账号名单读取失败后可以重试。
|
|
11
|
+
- 客户端提前断开时桥接流一并取消,泵送不再向已关闭的响应写入,释放读锁不再抛出。
|
|
12
|
+
|
|
3
13
|
## [1.0.3]
|
|
4
14
|
|
|
5
15
|
- WorkBuddy 国际版补齐会话头族与版本 UA,不再被渠道校验回 400 / 11128;不带会话标记的 401(含网关返回的 HTML 拒绝页)按登录失效分类并换号。
|
package/README.en.md
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
<h1 align="center">WTQ Pool</h1>
|
|
10
10
|
|
|
11
|
+
<p align="center"><sub>For DeepSeek Harness · <a href="https://github.com/chengzhi-c/pi-desktop-wtq-pool">PI-Desktop edition</a></sub></p>
|
|
12
|
+
|
|
11
13
|
<p align="center"><b>Use local WorkBuddy, Trae and Qoder sign-ins in DeepSeek Harness, with automatic failover when an account is rate-limited or out of quota.</b></p>
|
|
12
14
|
|
|
13
15
|
<p align="center">
|
|
@@ -31,7 +33,7 @@
|
|
|
31
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>
|
|
32
34
|
</p>
|
|
33
35
|
|
|
34
|
-
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 (an unknown model, a malformed body) is answered
|
|
36
|
+
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 (an unknown model, a malformed body) is answered as the upstream answered it. Each source has its own switch, with domestic and international accounts grouped separately.
|
|
35
37
|
|
|
36
38
|
## Preview
|
|
37
39
|
|
|
@@ -66,7 +68,7 @@ To run it locally, clone the repo, run `node docs/serve.cjs`, and open the addre
|
|
|
66
68
|
- Account distribution: WorkBuddy supports priority, round-robin, expiring credits first and conversation-sticky accounts, with failover on rate limits or exhausted quota. Trae and Qoder support round-robin and expiring credits first, and move on to the next sign-in on an authentication failure, a rate limit or exhausted quota. A rate limit cools for the wait the upstream stated, taking the response header when that is the only place it appears. Exhausted quota and a dead sign-in do not recover on their own, so that account leaves rotation until the balance is read again or the user signs in anew. When the upstream host cannot be reached at all, the next sign-in is tried.
|
|
67
69
|
- Credit automation: automatic check-in is off by default. The scheduled run and "Run now" perform the same round: vendor check-ins, plus the domestic WorkBuddy streak bonus, task rewards and cat travel. The upstream advances the streak on a conversation, so the round reports one chat activity per domestic account before reading the streak tiers; a tier that comes due is unlocked and collected without the user having to open WorkBuddy and send a message.
|
|
68
70
|
- Composer credits: with `showComposerPoints` on, the composer shows the balance of the account behind the current model; click it to switch accounts. Switching the feature off stops the readout's polling.
|
|
69
|
-
- One panel: account state, pool state, model selection and the connection check all live in the Account pool card on the plugin page. The model catalog loads at startup and refreshes on demand once its cache expires; it does not poll while idle. An account switched off in the panel is never probed, so it does not
|
|
71
|
+
- One panel: account state, pool state, model selection and the connection check all live in the Account pool card on the plugin page. The model catalog loads at startup and refreshes on demand once its cache expires; it does not poll while idle. An account switched off in the panel is never probed, so it does not leave the panel reading "detecting" either.
|
|
70
72
|
- Connection check: every finding carries a verdict. A gateway that is not listening, a catalog that could not be read, a published address that differs from the one bound, or a provider the host did not accept all count as failures and say what to change. A gateway whose start failed is reported with the reason and surfaced as address drift. When the check itself throws, the failure becomes a finding rather than taking the whole channel down.
|
|
71
73
|
|
|
72
74
|
## Install
|
|
@@ -136,7 +138,7 @@ When another process takes a port between the reservation and the listen, that g
|
|
|
136
138
|
|
|
137
139
|
## Data and outbound requests
|
|
138
140
|
|
|
139
|
-
The plugin only reads local vendor sign-in files and does not modify them. Providers are registered at runtime without rewriting host provider configuration; the host still persists plugin settings in the profile. Tokens stay in the plugin process and are sent to the relevant vendor endpoints. Gateways listen on `127.0.0.1`. Panel assets and RPC require an actual loopback peer and ignore forwarded address headers, so remote browsers cannot access the panel directly. The plugin does not directly manage or delete host conversation records. Its own data directory, `~/.dsh/dsh-wtq-pool/` (or `$DSH_HOME` when set), also holds two files: `checkin-slots.json`, the check-in slots already collected, written
|
|
141
|
+
The plugin only reads local vendor sign-in files and does not modify them. Providers are registered at runtime without rewriting host provider configuration; the host still persists plugin settings in the profile. Tokens stay in the plugin process and are sent to the relevant vendor endpoints. Gateways listen on `127.0.0.1`. Panel assets and RPC require an actual loopback peer and ignore forwarded address headers, so remote browsers cannot access the panel directly. The plugin does not directly manage or delete host conversation records. Its own data directory, `~/.dsh/dsh-wtq-pool/` (or `$DSH_HOME` when set), also holds two files: `checkin-slots.json`, the check-in slots already collected, written to a temporary file and renamed into place, then kept for three days, and `doctor.txt`, the most recent connection report.
|
|
140
142
|
|
|
141
143
|
Another process on the same machine can call these loopback endpoints and spend a signed-in account's quota. If replies disappear after a restart, check both the plugin logs and the host's persisted logs.
|
|
142
144
|
|
|
@@ -164,7 +166,7 @@ The host-agnostic core:
|
|
|
164
166
|
|
|
165
167
|
| Module | Responsibility |
|
|
166
168
|
| --- | --- |
|
|
167
|
-
| `loopback.ts` | The loopback security model (Host/Origin checks, response writing, message redaction) |
|
|
169
|
+
| `loopback.ts` | The loopback security model (Host/Origin checks, response writing, relay pumping via pumpToResponse/relayStreamOf, message redaction) |
|
|
168
170
|
| `accounts.ts` | WorkBuddy sign-in parsing, token encryption, the account pool and its cooldowns |
|
|
169
171
|
| `upstream.ts` | The WorkBuddy upstream client, error classification, rate-limit reset parsing |
|
|
170
172
|
| `catalog.ts` | The model catalog and its static fallback list |
|
package/README.md
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
<picture>
|
|
3
3
|
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/chengzhi-c/dsh-wtq-pool/raw/main/docs/logo-dark.png">
|
|
4
4
|
<source media="(prefers-color-scheme: light)" srcset="https://github.com/chengzhi-c/dsh-wtq-pool/raw/main/docs/logo.png">
|
|
5
|
-
<img src="https://github.com/chengzhi-c/dsh-wtq-pool/raw/main/docs/logo.png" width="240" alt="WTQ
|
|
5
|
+
<img src="https://github.com/chengzhi-c/dsh-wtq-pool/raw/main/docs/logo.png" width="240" alt="WTQ Pool">
|
|
6
6
|
</picture>
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
<h1 align="center">WTQ
|
|
9
|
+
<h1 align="center">WTQ Pool</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center"><sub>DeepSeek Harness 版 · <a href="https://github.com/chengzhi-c/pi-desktop-wtq-pool">PI-Desktop 版</a></sub></p>
|
|
10
12
|
|
|
11
13
|
<p align="center"><b>把本机已登录的 WorkBuddy、Trae、Qoder 账号接入 DeepSeek Harness,限流或额度用尽时自动换号。</b></p>
|
|
12
14
|
|
|
@@ -68,8 +70,8 @@
|
|
|
68
70
|
- 账号分发:WorkBuddy 支持先用一个账号、轮流使用、临期积分优先和同一对话固定一个账号,并在限流或额度用尽时自动换号;Trae、Qoder 支持轮流使用与临期积分优先,认证失败、限流或余额耗尽时换下一个登录重试。
|
|
69
71
|
- 积分自动化:自动签到默认关闭。开启后的定时任务与「立即运行」执行同一轮,包含三家签到、WorkBuddy 国内账号的连登奖励、任务奖励和猫猫旅行。连登天数由上游按对话推进,该轮在每个国内账号读取连登档位前先补发一次对话活动上报,因此档位到点即可解锁领取,不需要用户自己进 WorkBuddy 聊一句。
|
|
70
72
|
- 输入框积分:开启 `showComposerPoints` 后,输入框工具栏显示当前模型使用的账号余额,点开可换号。功能关闭后浮层停止轮询。
|
|
71
|
-
-
|
|
72
|
-
- 连接检查:每条发现都带判定。网关没在听、模型目录读不到、发布的地址与实际绑定的不一致、provider
|
|
73
|
+
- 面板:账号状态、池状态、模型勾选、连接检查都在插件页的「账号池」卡片里。模型目录启动时加载,缓存过期后按需刷新,空闲不轮询。停用的账号不参与探测,也不让面板一直显示「检测中」。
|
|
74
|
+
- 连接检查:每条发现都带判定。网关没在听、模型目录读不到、发布的地址与实际绑定的不一致、provider 没被宿主接受,都算失败并给出要改什么。网关启动失败时给出失败原因,面板按地址漂移提示重启。检查自己出错时也作为一条发现写进报告,而不是让整条通道失败。
|
|
73
75
|
|
|
74
76
|
## 安装
|
|
75
77
|
|
|
@@ -165,7 +167,7 @@ pnpm test # Node 自带测试,离线回归
|
|
|
165
167
|
|
|
166
168
|
| 模块 | 职责 |
|
|
167
169
|
| --- | --- |
|
|
168
|
-
| `loopback.ts` |
|
|
170
|
+
| `loopback.ts` | 回环端点的安全模型、响应写入、中继泵送(pumpToResponse / relayStreamOf)与报错脱敏 |
|
|
169
171
|
| `accounts.ts` | WorkBuddy 登录文件解析、令牌加解密、账号池与冷却 |
|
|
170
172
|
| `upstream.ts` | WorkBuddy 上游客户端、错误分类、限流重置解析 |
|
|
171
173
|
| `catalog.ts` | 模型目录与静态兜底列表 |
|
package/lib/index.js
CHANGED
|
@@ -354,6 +354,79 @@ async function readJsonBody(req, limitBytes = REQUEST_BODY_LIMIT) {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
/**
|
|
357
|
+
* The relay stream a `Response` was built from.
|
|
358
|
+
*
|
|
359
|
+
* `Response` wraps the stream it is given in another `ReadableStream`, and in
|
|
360
|
+
* the plugin process that wrapper stops delivering to its reader after the
|
|
361
|
+
* first chunks: the caller holds a 200 whose body never arrives. The bridges
|
|
362
|
+
* hand their stream over under this key as well, and the gateways pump that one
|
|
363
|
+
* directly. Nothing that reads `response.body` is affected.
|
|
364
|
+
*/
|
|
365
|
+
const RELAY_STREAM = Symbol.for("wtq-pool.relay-stream");
|
|
366
|
+
/** Attach the unwrapped relay stream to a response built around it. */
|
|
367
|
+
function withRelayStream(response, stream) {
|
|
368
|
+
Object.defineProperty(response, RELAY_STREAM, {
|
|
369
|
+
value: stream,
|
|
370
|
+
enumerable: false
|
|
371
|
+
});
|
|
372
|
+
return response;
|
|
373
|
+
}
|
|
374
|
+
/** The stream to relay: the attached one when present, else the response body. */
|
|
375
|
+
function relayStreamOf(response) {
|
|
376
|
+
const attached = response[RELAY_STREAM];
|
|
377
|
+
if (attached !== void 0) return attached;
|
|
378
|
+
if (response.body === null) throw new Error("response carries no body");
|
|
379
|
+
return response.body;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Relay one web stream to a Node response, honouring backpressure.
|
|
383
|
+
*
|
|
384
|
+
* Written out rather than `Readable.fromWeb` + `pipe`: that adapter stops
|
|
385
|
+
* delivering a stream this plugin built itself, so the client held a 200 whose
|
|
386
|
+
* body never arrived. Ends the response once the source ends; a read or write
|
|
387
|
+
* failure is the caller's to classify.
|
|
388
|
+
*/
|
|
389
|
+
async function pumpToResponse(source, res) {
|
|
390
|
+
const reader = source.getReader();
|
|
391
|
+
const releaseLock = () => {
|
|
392
|
+
try {
|
|
393
|
+
reader.releaseLock();
|
|
394
|
+
} catch {}
|
|
395
|
+
};
|
|
396
|
+
if (res.destroyed || res.writableEnded) {
|
|
397
|
+
await reader.cancel().catch(() => {});
|
|
398
|
+
releaseLock();
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const cancel = () => {
|
|
402
|
+
reader.cancel().catch(() => {});
|
|
403
|
+
};
|
|
404
|
+
res.once("close", cancel);
|
|
405
|
+
try {
|
|
406
|
+
for (;;) {
|
|
407
|
+
const next = await reader.read();
|
|
408
|
+
if (next.done) break;
|
|
409
|
+
if (res.destroyed || res.writableEnded) break;
|
|
410
|
+
if (!res.write(Buffer.from(next.value))) {
|
|
411
|
+
if (res.destroyed) break;
|
|
412
|
+
await new Promise((resolve) => {
|
|
413
|
+
const wake = () => {
|
|
414
|
+
res.off("drain", wake);
|
|
415
|
+
res.off("close", wake);
|
|
416
|
+
resolve();
|
|
417
|
+
};
|
|
418
|
+
res.once("drain", wake);
|
|
419
|
+
res.once("close", wake);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
} finally {
|
|
424
|
+
res.off("close", cancel);
|
|
425
|
+
releaseLock();
|
|
426
|
+
}
|
|
427
|
+
if (res.writable && !res.destroyed) res.end();
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
357
430
|
* Replay the bytes a peek consumed, then drain the rest of the upstream.
|
|
358
431
|
*
|
|
359
432
|
* The relay hands the client a stream it already read the head of, so the bytes
|
|
@@ -406,6 +479,11 @@ function guardsPass(req, res) {
|
|
|
406
479
|
writeOpenAIError(res, 403, "origin_not_allowed", "Origin must be a loopback origin");
|
|
407
480
|
return false;
|
|
408
481
|
}
|
|
482
|
+
const site = req.headers["sec-fetch-site"];
|
|
483
|
+
if (typeof site === "string" && site !== "" && site !== "same-origin" && site !== "same-site" && site !== "none") {
|
|
484
|
+
writeOpenAIError(res, 403, "origin_not_allowed", "cross-site request to a loopback gateway");
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
409
487
|
if (!bearerAccepted(req)) {
|
|
410
488
|
writeOpenAIError(res, 401, "unauthorized", "missing or invalid Authorization bearer");
|
|
411
489
|
return false;
|
|
@@ -948,6 +1026,7 @@ function registerPanelRoutes(ctx, deps) {
|
|
|
948
1026
|
kind: "exact",
|
|
949
1027
|
path: `${PANEL_BASE}/invoke`,
|
|
950
1028
|
handler: (req, res) => guarded(req, res, "POST", async () => {
|
|
1029
|
+
if (!isJsonContentType(req)) return writeJson(res, 415, { error: "Content-Type must be application/json" });
|
|
951
1030
|
const body = await readJsonBody(req, MAX_BODY_BYTES);
|
|
952
1031
|
const channel = typeof body["channel"] === "string" ? body["channel"] : "";
|
|
953
1032
|
if (channel === "") return writeJson(res, 400, { error: "channel is required" });
|
|
@@ -3916,6 +3995,7 @@ function createWorkBuddyShim(options) {
|
|
|
3916
3995
|
"Connection": "keep-alive",
|
|
3917
3996
|
"X-Accel-Buffering": "no"
|
|
3918
3997
|
});
|
|
3998
|
+
res.flushHeaders();
|
|
3919
3999
|
let sawDone = false;
|
|
3920
4000
|
const decoder = new TextDecoder();
|
|
3921
4001
|
const sse = new SseDecoder();
|
|
@@ -5779,6 +5859,18 @@ function bridgeTraeStream(source, model, options = {}) {
|
|
|
5779
5859
|
const sse = new SseDecoder();
|
|
5780
5860
|
const reader = source.getReader();
|
|
5781
5861
|
let cancelled = false;
|
|
5862
|
+
let wakeRoom;
|
|
5863
|
+
const waitForRoom = () => new Promise((resolve) => {
|
|
5864
|
+
let settled = false;
|
|
5865
|
+
const wake = () => {
|
|
5866
|
+
if (settled) return;
|
|
5867
|
+
settled = true;
|
|
5868
|
+
wakeRoom = void 0;
|
|
5869
|
+
resolve();
|
|
5870
|
+
};
|
|
5871
|
+
wakeRoom = wake;
|
|
5872
|
+
setTimeout(wake, 50);
|
|
5873
|
+
});
|
|
5782
5874
|
let sawToolCalls = false;
|
|
5783
5875
|
let emittedFinishReason = false;
|
|
5784
5876
|
let upstreamDone = false;
|
|
@@ -5856,53 +5948,79 @@ function bridgeTraeStream(source, model, options = {}) {
|
|
|
5856
5948
|
if (released) return;
|
|
5857
5949
|
released = true;
|
|
5858
5950
|
await reader.cancel().catch(() => {});
|
|
5859
|
-
|
|
5951
|
+
try {
|
|
5952
|
+
reader.releaseLock();
|
|
5953
|
+
} catch {}
|
|
5860
5954
|
};
|
|
5861
5955
|
return new ReadableStream({
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
message: redactSecrets(error instanceof Error ? error.message : String(error)),
|
|
5891
|
-
type: "upstream_error"
|
|
5956
|
+
/**
|
|
5957
|
+
* Push from one loop rather than pull one chunk at a time.
|
|
5958
|
+
*
|
|
5959
|
+
* The pull-driven version asked the host to call back for every upstream
|
|
5960
|
+
* chunk, and in the plugin process those callbacks stopped arriving after a
|
|
5961
|
+
* few kilobytes, leaving a turn that had started and then went silent. A
|
|
5962
|
+
* single loop owns the read side; `desiredSize` is the only backpressure, so
|
|
5963
|
+
* at most a chunk or two is held ahead of the client.
|
|
5964
|
+
*/
|
|
5965
|
+
start(controller) {
|
|
5966
|
+
(async () => {
|
|
5967
|
+
try {
|
|
5968
|
+
for (;;) {
|
|
5969
|
+
const next = await reader.read();
|
|
5970
|
+
if (cancelled) return;
|
|
5971
|
+
if (!next.done) {
|
|
5972
|
+
for (const event of sse.push(decoder.decode(next.value, { stream: true }))) consume(event, controller);
|
|
5973
|
+
if (!upstreamDone) {
|
|
5974
|
+
while (!cancelled && (controller.desiredSize ?? 1) <= 0) await waitForRoom();
|
|
5975
|
+
continue;
|
|
5976
|
+
}
|
|
5977
|
+
}
|
|
5978
|
+
const rest = decoder.decode();
|
|
5979
|
+
const events = rest === "" ? sse.finish() : [...sse.push(rest), ...sse.finish()];
|
|
5980
|
+
for (const event of events) consume(event, controller);
|
|
5981
|
+
if (!emittedFinishReason) {
|
|
5982
|
+
emittedFinishReason = true;
|
|
5983
|
+
controller.enqueue(chunk({}, sawToolCalls ? "tool_calls" : "stop"));
|
|
5892
5984
|
}
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
controller.enqueue(chunk({}, sawToolCalls ? "tool_calls" : "stop"));
|
|
5985
|
+
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
|
5986
|
+
controller.close();
|
|
5987
|
+
return;
|
|
5897
5988
|
}
|
|
5898
|
-
|
|
5899
|
-
controller.
|
|
5989
|
+
} catch (error) {
|
|
5990
|
+
if (cancelled) controller.error(error);
|
|
5991
|
+
else {
|
|
5992
|
+
if (!(error instanceof Error && error.name === "AbortError")) try {
|
|
5993
|
+
options.onFailure?.(error);
|
|
5994
|
+
} catch {}
|
|
5995
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify({
|
|
5996
|
+
id,
|
|
5997
|
+
object: "chat.completion.chunk",
|
|
5998
|
+
created,
|
|
5999
|
+
model,
|
|
6000
|
+
choices: [],
|
|
6001
|
+
error: {
|
|
6002
|
+
message: redactSecrets(error instanceof Error ? error.message : String(error)),
|
|
6003
|
+
type: "upstream_error"
|
|
6004
|
+
}
|
|
6005
|
+
})}\n\n`));
|
|
6006
|
+
if (!emittedFinishReason) {
|
|
6007
|
+
emittedFinishReason = true;
|
|
6008
|
+
controller.enqueue(chunk({}, sawToolCalls ? "tool_calls" : "stop"));
|
|
6009
|
+
}
|
|
6010
|
+
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
|
6011
|
+
controller.close();
|
|
6012
|
+
}
|
|
6013
|
+
} finally {
|
|
6014
|
+
await release();
|
|
5900
6015
|
}
|
|
5901
|
-
}
|
|
5902
|
-
|
|
6016
|
+
})();
|
|
6017
|
+
},
|
|
6018
|
+
pull() {
|
|
6019
|
+
wakeRoom?.();
|
|
5903
6020
|
},
|
|
5904
6021
|
cancel(reason) {
|
|
5905
6022
|
cancelled = true;
|
|
6023
|
+
wakeRoom?.();
|
|
5906
6024
|
return reader.cancel(reason);
|
|
5907
6025
|
}
|
|
5908
6026
|
});
|
|
@@ -5979,11 +6097,11 @@ async function openTraeResponse(response, model, options = {}) {
|
|
|
5979
6097
|
...wait === void 0 ? {} : { headers: { "Retry-After": wait } }
|
|
5980
6098
|
});
|
|
5981
6099
|
}
|
|
5982
|
-
const
|
|
5983
|
-
return new Response(
|
|
6100
|
+
const relay = bridgeTraeStream(replaySource(buffered, reader, ended), model, options);
|
|
6101
|
+
return withRelayStream(new Response(relay, {
|
|
5984
6102
|
status: 200,
|
|
5985
6103
|
headers: { "Content-Type": "text/event-stream" }
|
|
5986
|
-
});
|
|
6104
|
+
}), relay);
|
|
5987
6105
|
}
|
|
5988
6106
|
//#endregion
|
|
5989
6107
|
//#region src/trae-gateway.ts
|
|
@@ -6207,18 +6325,21 @@ function createTraeGateway(options) {
|
|
|
6207
6325
|
writeOpenAIError(res, 502, "upstream_error", "Trae SOLO returned no stream");
|
|
6208
6326
|
return;
|
|
6209
6327
|
}
|
|
6328
|
+
if (watcher.signal.aborted) {
|
|
6329
|
+
relayStreamOf(relayed).cancel().catch(() => {});
|
|
6330
|
+
return;
|
|
6331
|
+
}
|
|
6210
6332
|
res.writeHead(200, {
|
|
6211
6333
|
"Content-Type": "text/event-stream",
|
|
6212
6334
|
"Cache-Control": "no-cache",
|
|
6213
6335
|
"Connection": "keep-alive",
|
|
6214
6336
|
"X-Accel-Buffering": "no"
|
|
6215
6337
|
});
|
|
6216
|
-
|
|
6217
|
-
|
|
6338
|
+
res.flushHeaders();
|
|
6339
|
+
pumpToResponse(relayStreamOf(relayed), res).catch((error) => {
|
|
6218
6340
|
if (!(watcher.signal.aborted || error instanceof Error && error.name === "AbortError")) logger?.warn?.(LOG_PREFIX + ": trae relay stream failed mid-flight", error);
|
|
6219
6341
|
if (res.writable) res.end();
|
|
6220
6342
|
});
|
|
6221
|
-
body.pipe(res);
|
|
6222
6343
|
}
|
|
6223
6344
|
async function handle(req, res) {
|
|
6224
6345
|
if (!guardsPass(req, res)) return;
|
|
@@ -8310,6 +8431,18 @@ function bridgeQoderStream(source, model, options = {}) {
|
|
|
8310
8431
|
let usage;
|
|
8311
8432
|
const reader = source.getReader();
|
|
8312
8433
|
let cancelled = false;
|
|
8434
|
+
let wakeRoom;
|
|
8435
|
+
const waitForRoom = () => new Promise((resolve) => {
|
|
8436
|
+
let settled = false;
|
|
8437
|
+
const wake = () => {
|
|
8438
|
+
if (settled) return;
|
|
8439
|
+
settled = true;
|
|
8440
|
+
wakeRoom = void 0;
|
|
8441
|
+
resolve();
|
|
8442
|
+
};
|
|
8443
|
+
wakeRoom = wake;
|
|
8444
|
+
setTimeout(wake, 50);
|
|
8445
|
+
});
|
|
8313
8446
|
const chunk = (delta, finishReason = null) => encoder.encode(`data: ${JSON.stringify({
|
|
8314
8447
|
id,
|
|
8315
8448
|
object: "chat.completion.chunk",
|
|
@@ -8332,6 +8465,7 @@ function bridgeQoderStream(source, model, options = {}) {
|
|
|
8332
8465
|
}));
|
|
8333
8466
|
};
|
|
8334
8467
|
const consume = (payload, controller) => {
|
|
8468
|
+
if (finished) return;
|
|
8335
8469
|
const decoded = decodeQoderFrame(payload);
|
|
8336
8470
|
if (decoded.type === "unknown") return;
|
|
8337
8471
|
if (decoded.type === "failure") {
|
|
@@ -8374,19 +8508,32 @@ function bridgeQoderStream(source, model, options = {}) {
|
|
|
8374
8508
|
};
|
|
8375
8509
|
let released = false;
|
|
8376
8510
|
let tailTimer;
|
|
8511
|
+
let ctrl;
|
|
8512
|
+
let finished = false;
|
|
8377
8513
|
/**
|
|
8378
|
-
*
|
|
8514
|
+
* End the turn from outside `pull`.
|
|
8379
8515
|
*
|
|
8380
|
-
*
|
|
8381
|
-
*
|
|
8382
|
-
*
|
|
8516
|
+
* The vendor keeps its socket open after the finish chunk, so a timer has to
|
|
8517
|
+
* close the relay; waiting for a read that the vendor will never end left the
|
|
8518
|
+
* client on a turn that was already over ("still generating" after the text
|
|
8519
|
+
* stopped). Closing the controller directly is what makes that independent of
|
|
8520
|
+
* whether a read happens to be pending.
|
|
8383
8521
|
*/
|
|
8384
|
-
const
|
|
8522
|
+
const finalize = () => {
|
|
8523
|
+
if (finished) return;
|
|
8524
|
+
finished = true;
|
|
8525
|
+
clearTail();
|
|
8526
|
+
wakeRoom?.();
|
|
8527
|
+
try {
|
|
8528
|
+
ctrl?.enqueue(encoder.encode("data: [DONE]\n\n"));
|
|
8529
|
+
ctrl?.close();
|
|
8530
|
+
} catch {}
|
|
8385
8531
|
reader.cancel().catch(() => {});
|
|
8386
8532
|
};
|
|
8533
|
+
const endTurn = finalize;
|
|
8387
8534
|
const endSoon = () => {
|
|
8388
8535
|
if (tailTimer !== void 0) return;
|
|
8389
|
-
tailTimer = setTimeout(
|
|
8536
|
+
tailTimer = setTimeout(finalize, TAIL_GRACE_MS);
|
|
8390
8537
|
tailTimer.unref?.();
|
|
8391
8538
|
};
|
|
8392
8539
|
const clearTail = () => {
|
|
@@ -8407,53 +8554,81 @@ function bridgeQoderStream(source, model, options = {}) {
|
|
|
8407
8554
|
released = true;
|
|
8408
8555
|
clearTail();
|
|
8409
8556
|
await reader.cancel().catch(() => {});
|
|
8410
|
-
|
|
8557
|
+
try {
|
|
8558
|
+
reader.releaseLock();
|
|
8559
|
+
} catch {}
|
|
8411
8560
|
};
|
|
8412
8561
|
return new ReadableStream({
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8562
|
+
/**
|
|
8563
|
+
* Push from one loop rather than pull one chunk at a time.
|
|
8564
|
+
*
|
|
8565
|
+
* The pull-driven version asked the host to call back for every upstream
|
|
8566
|
+
* chunk, and in the plugin process those callbacks stopped arriving after a
|
|
8567
|
+
* few kilobytes: the turn opened, streamed a little, and then went silent
|
|
8568
|
+
* until the client gave up. One loop owns the read side; `desiredSize` is
|
|
8569
|
+
* the only backpressure.
|
|
8570
|
+
*/
|
|
8571
|
+
start(controller) {
|
|
8572
|
+
ctrl = controller;
|
|
8573
|
+
(async () => {
|
|
8574
|
+
try {
|
|
8575
|
+
for (;;) {
|
|
8576
|
+
if (finished) return;
|
|
8577
|
+
const next = await reader.read();
|
|
8578
|
+
if (cancelled || finished) return;
|
|
8579
|
+
if (!next.done) {
|
|
8580
|
+
for (const payload of frames.push(decoder.decode(next.value, { stream: true }))) consume(payload, controller);
|
|
8581
|
+
if (!frames.ended) {
|
|
8582
|
+
while (!cancelled && !finished && (controller.desiredSize ?? 1) <= 0) await waitForRoom();
|
|
8583
|
+
continue;
|
|
8584
|
+
}
|
|
8585
|
+
}
|
|
8586
|
+
const rest = decoder.decode();
|
|
8587
|
+
for (const payload of rest === "" ? frames.finish() : [...frames.push(rest), ...frames.finish()]) consume(payload, controller);
|
|
8588
|
+
if (!finished) {
|
|
8589
|
+
if (!emittedFinishReason) {
|
|
8590
|
+
emittedFinishReason = true;
|
|
8591
|
+
controller.enqueue(chunk({}, sawToolCalls ? "tool_calls" : "stop"));
|
|
8592
|
+
}
|
|
8593
|
+
finalize();
|
|
8442
8594
|
}
|
|
8443
|
-
|
|
8444
|
-
if (!emittedFinishReason) {
|
|
8445
|
-
emittedFinishReason = true;
|
|
8446
|
-
controller.enqueue(chunk({}, sawToolCalls ? "tool_calls" : "stop"));
|
|
8595
|
+
return;
|
|
8447
8596
|
}
|
|
8448
|
-
|
|
8449
|
-
controller.
|
|
8597
|
+
} catch (error) {
|
|
8598
|
+
if (cancelled) controller.error(error);
|
|
8599
|
+
else if (!finished) {
|
|
8600
|
+
if (!(error instanceof Error && error.name === "AbortError")) try {
|
|
8601
|
+
options.onFailure?.(error);
|
|
8602
|
+
} catch {}
|
|
8603
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify({
|
|
8604
|
+
id,
|
|
8605
|
+
object: "chat.completion.chunk",
|
|
8606
|
+
created,
|
|
8607
|
+
model,
|
|
8608
|
+
choices: [],
|
|
8609
|
+
error: {
|
|
8610
|
+
message: redactSecrets(error instanceof Error ? error.message : String(error)),
|
|
8611
|
+
type: "upstream_error"
|
|
8612
|
+
}
|
|
8613
|
+
})}\n\n`));
|
|
8614
|
+
if (!emittedFinishReason) {
|
|
8615
|
+
emittedFinishReason = true;
|
|
8616
|
+
controller.enqueue(chunk({}, sawToolCalls ? "tool_calls" : "stop"));
|
|
8617
|
+
}
|
|
8618
|
+
finalize();
|
|
8619
|
+
}
|
|
8620
|
+
} finally {
|
|
8621
|
+
await release();
|
|
8450
8622
|
}
|
|
8451
|
-
}
|
|
8452
|
-
|
|
8623
|
+
})();
|
|
8624
|
+
},
|
|
8625
|
+
pull() {
|
|
8626
|
+
wakeRoom?.();
|
|
8453
8627
|
},
|
|
8454
8628
|
cancel(reason) {
|
|
8455
8629
|
cancelled = true;
|
|
8456
8630
|
clearTail();
|
|
8631
|
+
wakeRoom?.();
|
|
8457
8632
|
return reader.cancel(reason);
|
|
8458
8633
|
}
|
|
8459
8634
|
});
|
|
@@ -8476,13 +8651,12 @@ async function openQoderResponse(response, model, options = {}) {
|
|
|
8476
8651
|
code: response.status
|
|
8477
8652
|
} }, { status: response.status });
|
|
8478
8653
|
}
|
|
8479
|
-
|
|
8480
|
-
if (source === null) return Response.json({ error: {
|
|
8654
|
+
if (response.body === null) return Response.json({ error: {
|
|
8481
8655
|
message: `Qoder response ${response.status} carried no body`,
|
|
8482
8656
|
type: "upstream_error",
|
|
8483
8657
|
code: 502
|
|
8484
8658
|
} }, { status: 502 });
|
|
8485
|
-
const reader =
|
|
8659
|
+
const reader = relayStreamOf(response).getReader();
|
|
8486
8660
|
const decoder = new TextDecoder();
|
|
8487
8661
|
const frames = new QoderFrameDecoder();
|
|
8488
8662
|
const buffered = [];
|
|
@@ -8538,11 +8712,11 @@ async function openQoderResponse(response, model, options = {}) {
|
|
|
8538
8712
|
...wait === void 0 ? {} : { headers: { "Retry-After": wait } }
|
|
8539
8713
|
});
|
|
8540
8714
|
}
|
|
8541
|
-
const
|
|
8542
|
-
return new Response(
|
|
8715
|
+
const relay = bridgeQoderStream(replaySource(buffered, reader, ended), model, options);
|
|
8716
|
+
return withRelayStream(new Response(relay, {
|
|
8543
8717
|
status: 200,
|
|
8544
8718
|
headers: { "Content-Type": "text/event-stream" }
|
|
8545
|
-
});
|
|
8719
|
+
}), relay);
|
|
8546
8720
|
}
|
|
8547
8721
|
//#endregion
|
|
8548
8722
|
//#region src/qoder-gateway.ts
|
|
@@ -8767,18 +8941,21 @@ function createQoderGateway(options) {
|
|
|
8767
8941
|
writeOpenAIError(res, 502, "upstream_error", "Qoder returned no stream");
|
|
8768
8942
|
return;
|
|
8769
8943
|
}
|
|
8944
|
+
if (watcher.signal.aborted) {
|
|
8945
|
+
relayStreamOf(relayed).cancel().catch(() => {});
|
|
8946
|
+
return;
|
|
8947
|
+
}
|
|
8770
8948
|
res.writeHead(200, {
|
|
8771
8949
|
"Content-Type": "text/event-stream",
|
|
8772
8950
|
"Cache-Control": "no-cache",
|
|
8773
8951
|
"Connection": "keep-alive",
|
|
8774
8952
|
"X-Accel-Buffering": "no"
|
|
8775
8953
|
});
|
|
8776
|
-
|
|
8777
|
-
|
|
8954
|
+
res.flushHeaders();
|
|
8955
|
+
pumpToResponse(relayStreamOf(relayed), res).catch((error) => {
|
|
8778
8956
|
if (!(watcher.signal.aborted || error instanceof Error && error.name === "AbortError")) logger?.warn?.(LOG_PREFIX + ": qoder relay stream failed mid-flight", error);
|
|
8779
8957
|
if (res.writable) res.end();
|
|
8780
8958
|
});
|
|
8781
|
-
body.pipe(res);
|
|
8782
8959
|
}
|
|
8783
8960
|
async function handle(req, res) {
|
|
8784
8961
|
if (!guardsPass(req, res)) return;
|
|
@@ -9801,17 +9978,10 @@ function sourceRosterFor(key, models, nativeOf) {
|
|
|
9801
9978
|
*
|
|
9802
9979
|
* They are the IDE's own, stable across versions, and are what distinguishes a
|
|
9803
9980
|
* helper slot from a model — a helper sometimes carries a borrowed display name,
|
|
9804
|
-
* so the name alone cannot answer it.
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
"fast_apply",
|
|
9809
|
-
"title_generation",
|
|
9810
|
-
"input_optimization",
|
|
9811
|
-
"laziness_detection"
|
|
9812
|
-
]);
|
|
9813
|
-
/** The same slots, by shape: the placeholders Trae binds at runtime, the helpers it drives, the entries it routes on its own. */
|
|
9814
|
-
const TRAE_INTERNAL_MODEL_ID_RE = /^(custom_model|search_agent)_|_(subagent|agent)(_|$)|-(for-)?auto$/;
|
|
9981
|
+
* so the name alone cannot answer it. The IDE appends a variant suffix to some of
|
|
9982
|
+
* them over time (`fast_apply_new`), so the names are matched by prefix.
|
|
9983
|
+
*/
|
|
9984
|
+
const TRAE_INTERNAL_MODEL_ID_RE = /^(custom_model|search_agent|summary|fast_apply|title_generation|input_optimization|laziness_detection)(_|$)|_(subagent|agent)(_|$)|-(for-)?auto$/;
|
|
9815
9985
|
/**
|
|
9816
9986
|
* Whether one gateway model is something to offer in the picker.
|
|
9817
9987
|
*
|
|
@@ -9833,8 +10003,7 @@ function isSelectableSourceModel(source, view) {
|
|
|
9833
10003
|
const native = typeof view.nativeName === "string" ? view.nativeName.trim() : "";
|
|
9834
10004
|
if ((typeof view.name === "string" ? view.name.trim() : "") === "" || native === "" || !/[\p{L}\p{N}]/u.test(native)) return false;
|
|
9835
10005
|
if (source !== "trae") return true;
|
|
9836
|
-
|
|
9837
|
-
return !TRAE_INTERNAL_MODEL_IDS.has(id) && !TRAE_INTERNAL_MODEL_ID_RE.test(id);
|
|
10006
|
+
return !TRAE_INTERNAL_MODEL_ID_RE.test(view.id);
|
|
9838
10007
|
}
|
|
9839
10008
|
function normalizeSelection(value) {
|
|
9840
10009
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
@@ -12457,7 +12626,7 @@ function checkinSummaryText(result) {
|
|
|
12457
12626
|
const growth = result.growth;
|
|
12458
12627
|
const growthText = growth === void 0 ? "" : ", streak " + (Number(growth.streak) || 0) + " tier(s), tasks " + (Number(growth.tasks) || 0) + " (+" + (Number(growth.credit) || 0) + " credits)";
|
|
12459
12628
|
const row = (value, label) => value === void 0 ? "" : ", " + label + " " + JSON.stringify(value);
|
|
12460
|
-
return "WTQ Pool - checked in " + result.claimed + " account(s)" + row(result.travel, "travel") + growthText + row(result.qoder, "Qoder") + row(result.trae, "Trae");
|
|
12629
|
+
return "WTQ Pool - checked in " + ((Number(result.claimed) || 0) + (Number(result.qoder?.claimed) || 0) + (Number(result.trae?.claimed) || 0)) + " account(s)" + row(result.travel, "travel") + growthText + row(result.qoder, "Qoder") + row(result.trae, "Trae");
|
|
12461
12630
|
}
|
|
12462
12631
|
/**
|
|
12463
12632
|
* Light one account's growth streak, then redeem every tier it opened.
|
|
@@ -13029,19 +13198,24 @@ async function autoCheckinTick(now) {
|
|
|
13029
13198
|
const retry = await qoderCheckinAll();
|
|
13030
13199
|
if (!stillLoaded(retryGeneration)) return autoCheckinLast;
|
|
13031
13200
|
qoderRetryAt = typeof retry.opensAt === "number" && retry.opensAt > Date.now() ? retry.opensAt : 0;
|
|
13201
|
+
const claimedBefore = Number(autoCheckinLast?.qoder?.claimed) || 0;
|
|
13032
13202
|
autoCheckinLast = {
|
|
13033
13203
|
...autoCheckinLast,
|
|
13034
|
-
qoder:
|
|
13204
|
+
qoder: {
|
|
13205
|
+
...retry,
|
|
13206
|
+
claimed: claimedBefore + (Number(retry.claimed) || 0)
|
|
13207
|
+
},
|
|
13035
13208
|
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
13036
13209
|
};
|
|
13037
13210
|
log("info", "deferred Qoder check-in: " + JSON.stringify(retry));
|
|
13038
13211
|
} catch (error) {
|
|
13039
13212
|
if (stillLoaded(retryGeneration)) {
|
|
13040
13213
|
qoderRetryAt = Date.now() + QODER_RETRY_BACKOFF_MS;
|
|
13214
|
+
const claimedBefore = Number(autoCheckinLast?.qoder?.claimed) || 0;
|
|
13041
13215
|
autoCheckinLast = {
|
|
13042
13216
|
...autoCheckinLast,
|
|
13043
13217
|
qoder: {
|
|
13044
|
-
claimed:
|
|
13218
|
+
claimed: claimedBefore,
|
|
13045
13219
|
skipped: 0,
|
|
13046
13220
|
failed: 1,
|
|
13047
13221
|
reason: safeMessage(error)
|
|
@@ -13999,7 +14173,7 @@ function apply(ctx, config = {}) {
|
|
|
13999
14173
|
lastRows = [];
|
|
14000
14174
|
fingerprint = "";
|
|
14001
14175
|
const message = error instanceof Error ? error.message : String(error);
|
|
14002
|
-
ctx.logger.error("dsh-wtq-pool: provider registration failed", error);
|
|
14176
|
+
ctx.logger.error("dsh-wtq-pool: provider registration failed", safeMessage(error));
|
|
14003
14177
|
return {
|
|
14004
14178
|
ok: false,
|
|
14005
14179
|
changed: false,
|
|
@@ -14033,7 +14207,7 @@ function apply(ctx, config = {}) {
|
|
|
14033
14207
|
return rows;
|
|
14034
14208
|
});
|
|
14035
14209
|
} catch (error) {
|
|
14036
|
-
ctx.logger.error("dsh-wtq-pool: model discovery was refused", error);
|
|
14210
|
+
ctx.logger.error("dsh-wtq-pool: model discovery was refused", safeMessage(error));
|
|
14037
14211
|
}
|
|
14038
14212
|
return () => {
|
|
14039
14213
|
disposeDiscovery?.();
|
|
@@ -14066,7 +14240,7 @@ function apply(ctx, config = {}) {
|
|
|
14066
14240
|
if (!stopped) return startRegisteredService();
|
|
14067
14241
|
}).catch((error) => {
|
|
14068
14242
|
if (stopped) return;
|
|
14069
|
-
ctx.logger.error("dsh-wtq-pool: activation failed", error);
|
|
14243
|
+
ctx.logger.error("dsh-wtq-pool: activation failed", safeMessage(error));
|
|
14070
14244
|
});
|
|
14071
14245
|
}
|
|
14072
14246
|
//#endregion
|
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。WorkBuddy 被限流时自动换号。三家各有开关,国内与国际各自成组。",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "chengzhi-c",
|
|
8
8
|
"homepage": "https://github.com/chengzhi-c/dsh-wtq-pool#readme",
|
package/renderer/panel.js
CHANGED
|
@@ -657,6 +657,8 @@ var draftSlot = null;
|
|
|
657
657
|
var busy = null; // id of the control awaiting a response
|
|
658
658
|
var checkinBusy = null;
|
|
659
659
|
var doctorResult = null;
|
|
660
|
+
/** Hours text typed but not yet saved, so a poll cannot overwrite it. */
|
|
661
|
+
var autoHoursDraft = null;
|
|
660
662
|
/** Account ids whose credit package list the user opened. Absent = collapsed. */
|
|
661
663
|
var openCredits = {};
|
|
662
664
|
/** The warning the header banner is currently showing, so it can be cleared. */
|
|
@@ -1418,7 +1420,9 @@ function renderAutoCheckin() {
|
|
|
1418
1420
|
$("autoHoursLabel").textContent = t("auto.hours");
|
|
1419
1421
|
var input = $("autoHours");
|
|
1420
1422
|
input.placeholder = t("auto.hoursHint");
|
|
1421
|
-
if (document.activeElement !== input)
|
|
1423
|
+
if (document.activeElement !== input) {
|
|
1424
|
+
input.value = autoHoursDraft !== null ? autoHoursDraft : (auto.hours || []).join(",");
|
|
1425
|
+
}
|
|
1422
1426
|
var save = $("autoHoursSave");
|
|
1423
1427
|
save.textContent = t("auto.hoursSave");
|
|
1424
1428
|
save.disabled = busy !== null;
|
|
@@ -1481,9 +1485,14 @@ function autoNoteRows(auto) {
|
|
|
1481
1485
|
if (last.error) return [{ text: t("auto.lastFailedAt", { slot: slot, message: last.error }), tone: "fail" }];
|
|
1482
1486
|
var rows = [];
|
|
1483
1487
|
if (last.pending === true) rows.push({ text: t("auto.running"), tone: "" });
|
|
1488
|
+
// The head count is every source's claimed accounts, matching the rows
|
|
1489
|
+
// below; `last.claimed` alone is WorkBuddy's share and read as a total.
|
|
1490
|
+
var claimedTotal = (Number(last.claimed) || 0)
|
|
1491
|
+
+ (last.qoder ? Number(last.qoder.claimed) || 0 : 0)
|
|
1492
|
+
+ (last.trae ? Number(last.trae.claimed) || 0 : 0);
|
|
1484
1493
|
rows.push({
|
|
1485
1494
|
text: t(last.manual === true ? "auto.lastManual" : "auto.lastAuto",
|
|
1486
|
-
{ slot: slot, count:
|
|
1495
|
+
{ slot: slot, count: claimedTotal }),
|
|
1487
1496
|
tone: last.pending === true ? "" : "ok",
|
|
1488
1497
|
});
|
|
1489
1498
|
var push = function (label, counts) {
|
|
@@ -1538,6 +1547,11 @@ function autoNoteRows(auto) {
|
|
|
1538
1547
|
|
|
1539
1548
|
/** Paint the check-in log as rows, so the caller does not build markup inline. */
|
|
1540
1549
|
function paintAutoNote(host, auto) {
|
|
1550
|
+
// A user who scrolled up to read an older line must not be pulled back to the
|
|
1551
|
+
// bottom by every 2 s poll; only a new pass (row count change) or a box that
|
|
1552
|
+
// was already at the bottom follows the tail.
|
|
1553
|
+
var atBottom = host.scrollTop + host.clientHeight >= host.scrollHeight - 4;
|
|
1554
|
+
var rowCount = host.childElementCount;
|
|
1541
1555
|
clear(host);
|
|
1542
1556
|
autoNoteRows(auto).forEach(function (row) {
|
|
1543
1557
|
var line = el("div", "log-line" + (row.tone ? " " + row.tone : ""));
|
|
@@ -1545,10 +1559,7 @@ function paintAutoNote(host, auto) {
|
|
|
1545
1559
|
line.appendChild(el("span", "log-text", row.text));
|
|
1546
1560
|
host.appendChild(line);
|
|
1547
1561
|
});
|
|
1548
|
-
|
|
1549
|
-
// otherwise leave the newest line - the one the user just waited for - below
|
|
1550
|
-
// the fold.
|
|
1551
|
-
host.scrollTop = host.scrollHeight;
|
|
1562
|
+
if (host.childElementCount !== rowCount || atBottom) host.scrollTop = host.scrollHeight;
|
|
1552
1563
|
}
|
|
1553
1564
|
function renderAccounts() {
|
|
1554
1565
|
var host = $("accounts");
|
|
@@ -2093,8 +2104,18 @@ function renderModels() {
|
|
|
2093
2104
|
var key = page.source + "\u0000" + page.key + "\u0000"
|
|
2094
2105
|
+ list.map(function (model) { return model.id; }).sort().join("\u0000");
|
|
2095
2106
|
var slot = page.source + "\u0000" + page.key;
|
|
2096
|
-
if (drafts[slot] === undefined
|
|
2107
|
+
if (drafts[slot] === undefined) {
|
|
2097
2108
|
drafts[slot] = { key: key, draft: draftFor(list, page.selection) };
|
|
2109
|
+
} else if (drafts[slot].key !== key) {
|
|
2110
|
+
// The roster changed under an open draft (a catalog refresh, a fetch): keep
|
|
2111
|
+
// the user's unsaved ticks and overrides for every id that survived, and
|
|
2112
|
+
// start newly listed ids from the saved selection. Replacing the whole
|
|
2113
|
+
// draft silently discarded edits the savebar was still offering to save.
|
|
2114
|
+
var fresh = draftFor(list, page.selection);
|
|
2115
|
+
Object.keys(fresh).forEach(function (id) {
|
|
2116
|
+
if (Object.prototype.hasOwnProperty.call(drafts[slot].draft, id)) fresh[id] = drafts[slot].draft[id];
|
|
2117
|
+
});
|
|
2118
|
+
drafts[slot] = { key: key, draft: fresh };
|
|
2098
2119
|
}
|
|
2099
2120
|
draft = drafts[slot].draft;
|
|
2100
2121
|
draftSlot = slot;
|
|
@@ -2814,6 +2835,12 @@ function render() {
|
|
|
2814
2835
|
lastPressed = null;
|
|
2815
2836
|
}
|
|
2816
2837
|
}
|
|
2838
|
+
// A pending pass whose poll was stopped (or never started) gets its watcher
|
|
2839
|
+
// back here: every state adoption ends in this render, and the log row is the
|
|
2840
|
+
// only thing that reports the pass as running.
|
|
2841
|
+
if (state && state.autoCheckin && state.autoCheckin.last && state.autoCheckin.last.pending === true) {
|
|
2842
|
+
pollCheckinLog(checkinPollAttempts);
|
|
2843
|
+
}
|
|
2817
2844
|
}
|
|
2818
2845
|
|
|
2819
2846
|
// ---------------------------------------------------------------- actions
|
|
@@ -2907,6 +2934,9 @@ function adoptAndMaybePoll(next, attempts) {
|
|
|
2907
2934
|
var checkinPoll = null;
|
|
2908
2935
|
var CHECKIN_POLL_MS = 2000;
|
|
2909
2936
|
var CHECKIN_POLL_LIMIT = 90;
|
|
2937
|
+
var CHECKIN_POLL_SLOW_MS = 10000;
|
|
2938
|
+
var checkinPollAttempts = 0;
|
|
2939
|
+
var checkinPollAt = null;
|
|
2910
2940
|
|
|
2911
2941
|
function stopCheckinPoll() {
|
|
2912
2942
|
if (checkinPoll !== null) {
|
|
@@ -2919,20 +2949,30 @@ function stopCheckinPoll() {
|
|
|
2919
2949
|
function pollCheckinLog(attempts) {
|
|
2920
2950
|
var last = state && state.autoCheckin && state.autoCheckin.last;
|
|
2921
2951
|
if (!last || last.pending !== true) { stopCheckinPoll(); return; }
|
|
2952
|
+
// Progress is counted per pass: a new `at` starts a fresh fast window.
|
|
2953
|
+
var stamp = typeof last.at === "string" ? last.at : "";
|
|
2954
|
+
if (stamp !== checkinPollAt) { checkinPollAt = stamp; attempts = 0; }
|
|
2955
|
+
checkinPollAttempts = attempts;
|
|
2956
|
+
// A pass running beside another action is not a reason to stop watching it,
|
|
2957
|
+
// but the poll must not run while that action re-renders. `runBusy` calls
|
|
2958
|
+
// back here when it finishes, so dropping the timer now is safe.
|
|
2922
2959
|
if (busy !== null && busy !== "checkin") { stopCheckinPoll(); return; }
|
|
2923
|
-
if (attempts >= CHECKIN_POLL_LIMIT) { stopCheckinPoll(); return; }
|
|
2924
2960
|
if (checkinPoll !== null) return;
|
|
2961
|
+
// Past the fast window the pass is either long or wedged; keep a slow watch
|
|
2962
|
+
// instead of giving up, or the row reads "running" for the rest of the day.
|
|
2963
|
+
var delay = attempts >= CHECKIN_POLL_LIMIT ? CHECKIN_POLL_SLOW_MS : CHECKIN_POLL_MS;
|
|
2925
2964
|
checkinPoll = window.setTimeout(function () {
|
|
2926
2965
|
checkinPoll = null;
|
|
2927
2966
|
var revision = stateRevision;
|
|
2928
2967
|
invoke("xd.state").then(function (again) {
|
|
2929
2968
|
if (revision !== stateRevision) { pollCheckinLog(attempts + 1); return; }
|
|
2930
|
-
|
|
2969
|
+
// Another action adopted the state; its own render re-arms the watch.
|
|
2970
|
+
if (busy !== null && busy !== "checkin") { stopCheckinPoll(); return; }
|
|
2931
2971
|
adopt(again);
|
|
2932
2972
|
render();
|
|
2933
2973
|
pollCheckinLog(attempts + 1);
|
|
2934
|
-
}).catch(function () {
|
|
2935
|
-
},
|
|
2974
|
+
}).catch(function () { pollCheckinLog(attempts + 1); });
|
|
2975
|
+
}, delay);
|
|
2936
2976
|
}
|
|
2937
2977
|
|
|
2938
2978
|
function refresh() {
|
|
@@ -3047,6 +3087,11 @@ function setAutoCheckin(enabled, hours) {
|
|
|
3047
3087
|
}
|
|
3048
3088
|
return runBusy("autoCheckin", function () {
|
|
3049
3089
|
return invoke("xd.setAutoCheckin", { enabled: enabled === true, hours: hours });
|
|
3090
|
+
}).then(function (result) {
|
|
3091
|
+
// Saved: the field now follows the host's value again.
|
|
3092
|
+
autoHoursDraft = null;
|
|
3093
|
+
render();
|
|
3094
|
+
return result;
|
|
3050
3095
|
}).catch(function () {});
|
|
3051
3096
|
}
|
|
3052
3097
|
function claimCheckin(accountId) {
|
|
@@ -3149,7 +3194,12 @@ function requestModelRoster() {
|
|
|
3149
3194
|
modelRosterRequested = true;
|
|
3150
3195
|
invoke("xd.fetchModels").then(function (next) {
|
|
3151
3196
|
adoptAndMaybePoll(next, 0);
|
|
3152
|
-
}).catch(function () {
|
|
3197
|
+
}).catch(function (error) {
|
|
3198
|
+
// A failed read must not latch the panel onto the static fallback for the
|
|
3199
|
+
// rest of its life: release the guard so the next visit tries again.
|
|
3200
|
+
modelRosterRequested = false;
|
|
3201
|
+
note(String(error && error.message ? error.message : error), "warn");
|
|
3202
|
+
});
|
|
3153
3203
|
}
|
|
3154
3204
|
function discardDraft() {
|
|
3155
3205
|
// Only the page in view: another page's unsaved edits are not this button's to
|
|
@@ -3272,7 +3322,9 @@ function selectTab(name) {
|
|
|
3272
3322
|
tabs[i].className = isActive ? "subtab active" : "subtab";
|
|
3273
3323
|
tabs[i].setAttribute("aria-selected", isActive ? "true" : "false");
|
|
3274
3324
|
}
|
|
3275
|
-
|
|
3325
|
+
// Entering the tab while another action runs would raise the busy banner and
|
|
3326
|
+
// silently skip the doctor; the next entry retries.
|
|
3327
|
+
if (name === "check" && doctorResult === null && busy === null) runDoctor();
|
|
3276
3328
|
// The model page shows a roster, so entering it is the moment to make sure
|
|
3277
3329
|
// that roster is the vendor's and not this plugin's own fallback.
|
|
3278
3330
|
if (name === "models") requestModelRoster();
|
|
@@ -3316,6 +3368,9 @@ function bind() {
|
|
|
3316
3368
|
}
|
|
3317
3369
|
// Bound once, with the state read at click time: this is a static node, so the
|
|
3318
3370
|
// handler cannot live in the render pass that redraws it.
|
|
3371
|
+
$("autoHours").addEventListener("input", function () {
|
|
3372
|
+
autoHoursDraft = $("autoHours").value;
|
|
3373
|
+
});
|
|
3319
3374
|
$("autoHoursSave").addEventListener("click", function () {
|
|
3320
3375
|
var auto = (state && state.autoCheckin) || { enabled: false };
|
|
3321
3376
|
setAutoCheckin(auto.enabled === true, parseCheckinHours($("autoHours").value));
|