@refeain/dsh-xdpool 3.0.7 → 3.0.9
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 +27 -0
- package/README.en.md +46 -22
- package/README.md +70 -22
- package/lib/bin.js +149 -4
- package/lib/client.js +37 -6
- package/lib/index.d.ts +38 -0
- package/lib/index.js +640 -367
- package/package.json +1 -1
- package/vendor/channel-pack/pack.js +14 -20
package/lib/index.js
CHANGED
|
@@ -2839,12 +2839,7 @@ function createDoubaoLlm(options) {
|
|
|
2839
2839
|
* The reasoning level.
|
|
2840
2840
|
*
|
|
2841
2841
|
* The picker sends an opaque branded string; Doubao's levels are named. An unknown
|
|
2842
|
-
* value falls back to
|
|
2843
|
-
* family accepts.
|
|
2844
|
-
*
|
|
2845
|
-
* 兜底值必须是 `DOUBAO_REASONING_LEVELS` 里真实存在的 id —— 否则上面的 some()
|
|
2846
|
-
* 永远匹配不到它,请求会带着一个上游不认的档位发出去。这里以前写 `medium`:
|
|
2847
|
-
* 那是 `LEVEL_NAMES` 的旧拼法(catalog 与 adapter 都叫 `mid`),不在档位表里。
|
|
2842
|
+
* value falls back to the middle level, which every model in the family accepts.
|
|
2848
2843
|
*/
|
|
2849
2844
|
const requested = streamOptions["reasoningEffort"];
|
|
2850
2845
|
const levelName = DOUBAO_REASONING_LEVELS.some((entry) => entry.id === requested) ? String(requested) : DEFAULT_REASONING_LEVEL_ID;
|
|
@@ -13501,6 +13496,23 @@ const SESSION_DEAD_MARKERS = [
|
|
|
13501
13496
|
*/
|
|
13502
13497
|
const ALREADY_CHECKIN_MARKERS = ["已签到", "already"];
|
|
13503
13498
|
/**
|
|
13499
|
+
* 签到相关的业务码。
|
|
13500
|
+
*
|
|
13501
|
+
* 上游用 `code` 区分三种「不是成功也不是故障」的结果,而我们此前一律当失败抛出:
|
|
13502
|
+
* 今天已经领过(1001/10001)会在每次自动领取时记一条失败;活动未开放(1002/1003/
|
|
13503
|
+
* 40901/41000)也会,而且永远重试不到结果。它们必须分开对待:
|
|
13504
|
+
*
|
|
13505
|
+
* 已领 → 幂等成功(今天的分就在账上,不是错)
|
|
13506
|
+
* 未开放 → inactive(等下一次,不报错、不重试)
|
|
13507
|
+
*/
|
|
13508
|
+
const CHECKIN_ALREADY_CODES = /* @__PURE__ */ new Set([1001, 10001]);
|
|
13509
|
+
const CHECKIN_INACTIVE_CODES = /* @__PURE__ */ new Set([
|
|
13510
|
+
1002,
|
|
13511
|
+
1003,
|
|
13512
|
+
40901,
|
|
13513
|
+
41e3
|
|
13514
|
+
]);
|
|
13515
|
+
/**
|
|
13504
13516
|
* Markers for "there is no compensation offer to collect".
|
|
13505
13517
|
*
|
|
13506
13518
|
* The offer is seasonal — an outage announcement opens one, and it closes on a
|
|
@@ -13886,7 +13898,17 @@ function billingHeaders(credential) {
|
|
|
13886
13898
|
const headers = {
|
|
13887
13899
|
"Authorization": `Bearer ${credential.accessToken}`,
|
|
13888
13900
|
"Accept": "application/json",
|
|
13889
|
-
"Content-Type": "application/json"
|
|
13901
|
+
"Content-Type": "application/json",
|
|
13902
|
+
/**
|
|
13903
|
+
* 产品身份头 —— 缺了它们,计费/签到端点会把请求当成「不是客户端发的」。
|
|
13904
|
+
*
|
|
13905
|
+
* 这三个头一直在客户端那边发(网页/IDE 的每个 billing 请求都带),我们只发了
|
|
13906
|
+
* Authorization + X-Domain + X-User-Id。上游收紧校验之后,签到就只剩一个笼统的
|
|
13907
|
+
* 失败,看不出原因。UA 用本插件已经在别处使用的桌面版本号,不再另造一个。
|
|
13908
|
+
*/
|
|
13909
|
+
"X-Product": "SaaS",
|
|
13910
|
+
"X-Product-Code": "workbuddy",
|
|
13911
|
+
"User-Agent": DESKTOP_UA
|
|
13890
13912
|
};
|
|
13891
13913
|
if (credential.uid !== "" && credential.uid !== void 0) headers["X-User-Id"] = credential.uid;
|
|
13892
13914
|
if (credential.enterpriseId !== void 0 && credential.enterpriseId !== "") {
|
|
@@ -14886,6 +14908,17 @@ var WorkBuddyUpstreamClient = class {
|
|
|
14886
14908
|
signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
|
|
14887
14909
|
});
|
|
14888
14910
|
const envelope = await readEnvelope(response);
|
|
14911
|
+
if (response.ok && CHECKIN_INACTIVE_CODES.has(envelope.code)) return {
|
|
14912
|
+
active: false,
|
|
14913
|
+
todayCheckedIn: false,
|
|
14914
|
+
streakDays: 0,
|
|
14915
|
+
dailyCredit: 0,
|
|
14916
|
+
todayCredit: 0,
|
|
14917
|
+
isStreakDay: false,
|
|
14918
|
+
nextStreakDay: 0,
|
|
14919
|
+
streakBonusDays: 0,
|
|
14920
|
+
streakBonusCredit: 0
|
|
14921
|
+
};
|
|
14889
14922
|
if (!response.ok || envelope.code !== 0) throw envelopeError(response.status, envelope);
|
|
14890
14923
|
const data = typeof envelope.data === "object" && envelope.data !== null ? envelope.data : {};
|
|
14891
14924
|
const num = (key) => typeof data[key] === "number" ? data[key] : 0;
|
|
@@ -14911,8 +14944,22 @@ var WorkBuddyUpstreamClient = class {
|
|
|
14911
14944
|
signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
|
|
14912
14945
|
});
|
|
14913
14946
|
const envelope = await readEnvelope(response);
|
|
14947
|
+
const neutral = (data_) => ({
|
|
14948
|
+
credit: 0,
|
|
14949
|
+
streakDays: typeof data_["streak_days"] === "number" ? data_["streak_days"] : 0,
|
|
14950
|
+
isStreakDay: false
|
|
14951
|
+
});
|
|
14952
|
+
const payload = typeof envelope.data === "object" && envelope.data !== null ? envelope.data : {};
|
|
14953
|
+
/**
|
|
14954
|
+
* 已领过(1001/10001)就是成功:今天的分在账上,重复领取不该被记成失败 ——
|
|
14955
|
+
* 自动化每小时跑一次,记成失败会刷出一整片红字。
|
|
14956
|
+
*
|
|
14957
|
+
* 未开放(1002/1003/40901/41000)同样是「今天没有可领的」,不是故障;
|
|
14958
|
+
* 抛错会让调度器一直重试一个永远不会成功的结果。
|
|
14959
|
+
*/
|
|
14960
|
+
if (response.ok && (CHECKIN_ALREADY_CODES.has(envelope.code) || CHECKIN_INACTIVE_CODES.has(envelope.code))) return neutral(payload);
|
|
14914
14961
|
if (!response.ok || envelope.code !== 0) throw envelopeError(response.status, envelope);
|
|
14915
|
-
const data =
|
|
14962
|
+
const data = payload;
|
|
14916
14963
|
const numberField = (key) => typeof data[key] === "number" ? data[key] : 0;
|
|
14917
14964
|
return {
|
|
14918
14965
|
credit: numberField("credit"),
|
|
@@ -18134,6 +18181,22 @@ var WorkBuddyAccountPool = class {
|
|
|
18134
18181
|
* Returns true when the token is known good afterwards (refreshed, or still
|
|
18135
18182
|
* valid), false when the credential was proven dead.
|
|
18136
18183
|
*/
|
|
18184
|
+
/**
|
|
18185
|
+
* 取一个账号「可以用来发一次请求」的凭据:过期就先刷新。
|
|
18186
|
+
*
|
|
18187
|
+
* 签到 / 积分这些端点走的是「按 id 直接找账号」的路径,和选号路径不同 ——
|
|
18188
|
+
* 以前它们直接拿池里的 `account.credential`,凭据过期时上游回 401,界面只能
|
|
18189
|
+
* 说「领取失败」,而同一时刻对话却正常(对话走 `getAvailableAccount`,那里会
|
|
18190
|
+
* 先 `ensureFresh`)。用户反馈的「积分领取全部失败」就是这一处。
|
|
18191
|
+
*
|
|
18192
|
+
* 返回 undefined 表示「刷新失败」:调用方应当直接告诉用户重新登录,
|
|
18193
|
+
* 而不是拿旧 token 再去撞一次 401。
|
|
18194
|
+
*/
|
|
18195
|
+
async freshCredential(id) {
|
|
18196
|
+
const account = this.accounts.find((item) => item.id === id);
|
|
18197
|
+
if (account === void 0) return void 0;
|
|
18198
|
+
return await this.ensureFresh(account) ? account.credential : void 0;
|
|
18199
|
+
}
|
|
18137
18200
|
async ensureFresh(account, force = false) {
|
|
18138
18201
|
if (this.client === void 0) return true;
|
|
18139
18202
|
const credential = account.credential;
|
|
@@ -29317,7 +29380,7 @@ function parseBody(body) {
|
|
|
29317
29380
|
*
|
|
29318
29381
|
* @module dsh-xdpool/version
|
|
29319
29382
|
*/
|
|
29320
|
-
const POOL_VERSION = "3.0.
|
|
29383
|
+
const POOL_VERSION = "3.0.9";
|
|
29321
29384
|
//#endregion
|
|
29322
29385
|
//#region src/update-check.ts
|
|
29323
29386
|
/**
|
|
@@ -29496,6 +29559,96 @@ function extractNotes(readme) {
|
|
|
29496
29559
|
return {};
|
|
29497
29560
|
}
|
|
29498
29561
|
//#endregion
|
|
29562
|
+
//#region src/diagnostics.ts
|
|
29563
|
+
/**
|
|
29564
|
+
* A startup trace this plugin owns.
|
|
29565
|
+
*
|
|
29566
|
+
* The host's own logs have moved between at least three directories across the
|
|
29567
|
+
* 0.1.x / 0.2.x / DSH NEXT lines, and on a machine with no outbound network
|
|
29568
|
+
* they are not always where anyone thinks to look. When a provider fails to
|
|
29569
|
+
* register, "the model picker does not list xdpool" is the only symptom the
|
|
29570
|
+
* user can report, and answering it needs the exact throw — so the plugin
|
|
29571
|
+
* writes one small append-only file next to the settings it already owns.
|
|
29572
|
+
*
|
|
29573
|
+
* Everything here is best-effort: a diagnostic that can crash the thing it is
|
|
29574
|
+
* diagnosing is worse than no diagnostic, so every path swallows its own
|
|
29575
|
+
* failure and returns a value the caller can log instead.
|
|
29576
|
+
*
|
|
29577
|
+
* @module dsh-xdpool/diagnostics
|
|
29578
|
+
*/
|
|
29579
|
+
/**
|
|
29580
|
+
* Cap the trace so a plugin that restarts in a loop cannot fill the disk.
|
|
29581
|
+
* Half a megabyte is roughly a month of restarts, which is far more than the
|
|
29582
|
+
* single boot this file is meant to explain.
|
|
29583
|
+
*/
|
|
29584
|
+
const MAX_BYTES = 524288;
|
|
29585
|
+
/** The file lives beside the settings store, so one directory explains both. */
|
|
29586
|
+
function startupLogPath() {
|
|
29587
|
+
const home = process.env.DSH_HOME !== void 0 && process.env.DSH_HOME !== "" ? process.env.DSH_HOME : homedir();
|
|
29588
|
+
return join(home, ".xdpool", "startup.log");
|
|
29589
|
+
}
|
|
29590
|
+
/**
|
|
29591
|
+
* Render any thrown value as one line of text.
|
|
29592
|
+
*
|
|
29593
|
+
* `String(error)` on a real `Error` collapses the stack to "Error: message",
|
|
29594
|
+
* which is exactly the part worth keeping; the object form (`{}` for a
|
|
29595
|
+
* structured clone, `[object Object]` for anything else) is what produced the
|
|
29596
|
+
* unreadable `{}` markers in this project's earlier logs.
|
|
29597
|
+
*/
|
|
29598
|
+
function describeError(error) {
|
|
29599
|
+
if (error instanceof Error) {
|
|
29600
|
+
const code = "code" in error && typeof error.code === "string" ? ` (${String(error.code)})` : "";
|
|
29601
|
+
return `${error.name}: ${error.message}${code}`;
|
|
29602
|
+
}
|
|
29603
|
+
if (typeof error === "string") return error;
|
|
29604
|
+
try {
|
|
29605
|
+
return JSON.stringify(error) ?? String(error);
|
|
29606
|
+
} catch {
|
|
29607
|
+
return String(error);
|
|
29608
|
+
}
|
|
29609
|
+
}
|
|
29610
|
+
/**
|
|
29611
|
+
* Append one timestamped line. Returns the text that was written, so a caller
|
|
29612
|
+
* that cannot write the file can still put the same words in the host log.
|
|
29613
|
+
*/
|
|
29614
|
+
function recordStartupNote(line) {
|
|
29615
|
+
const text = `${(/* @__PURE__ */ new Date()).toISOString()} ${line}`;
|
|
29616
|
+
try {
|
|
29617
|
+
const path = startupLogPath();
|
|
29618
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
29619
|
+
try {
|
|
29620
|
+
if (statSync(path).size > MAX_BYTES) truncateSync(path, 0);
|
|
29621
|
+
} catch {}
|
|
29622
|
+
appendFileSync(path, `${text}\n`, "utf8");
|
|
29623
|
+
} catch {}
|
|
29624
|
+
return text;
|
|
29625
|
+
}
|
|
29626
|
+
//#endregion
|
|
29627
|
+
//#region src/redact.ts
|
|
29628
|
+
/**
|
|
29629
|
+
* Strip credential-shaped substrings out of text that is about to be shown to a
|
|
29630
|
+
* person, or written to a log line we do not control.
|
|
29631
|
+
*
|
|
29632
|
+
* The rules are deliberately narrow: they match the two shapes this plugin
|
|
29633
|
+
* actually carries around — a JWT, and a token passed as a query parameter —
|
|
29634
|
+
* rather than trying to guess at "secrets" in general. A redactor that also
|
|
29635
|
+
* eats ordinary prose is worse than none: the reader stops believing the
|
|
29636
|
+
* message, and the next failure gets pasted into an issue by hand.
|
|
29637
|
+
*
|
|
29638
|
+
* Shared on purpose. The status route and the automation scheduler both surface
|
|
29639
|
+
* upstream failures, and two copies of this logic drifting apart would mean the
|
|
29640
|
+
* same account failure reads one way on the card and another in the log.
|
|
29641
|
+
*
|
|
29642
|
+
* @module dsh-xdpool/redact
|
|
29643
|
+
*/
|
|
29644
|
+
/** `eyJ…` header.payload.signature — what an access or refresh token looks like. */
|
|
29645
|
+
const JWT = /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu;
|
|
29646
|
+
/** `?code=…` / `token=…` in a URL or a request echo. The key is kept, the value is not. */
|
|
29647
|
+
const QUERY_SECRET = /(\b(?:code|token|refresh_token|access_token)=)[^&\s]+/giu;
|
|
29648
|
+
function redactSecrets(text) {
|
|
29649
|
+
return text.replace(JWT, "[redacted token]").replace(QUERY_SECRET, "$1[redacted]");
|
|
29650
|
+
}
|
|
29651
|
+
//#endregion
|
|
29499
29652
|
//#region src/task-events.ts
|
|
29500
29653
|
/**
|
|
29501
29654
|
* The app the buddy chain enters.
|
|
@@ -30650,6 +30803,15 @@ var WorkBuddyScheduler = class {
|
|
|
30650
30803
|
* distinguishable from "0 tasks, everything already collected".
|
|
30651
30804
|
*/
|
|
30652
30805
|
const items = [];
|
|
30806
|
+
/**
|
|
30807
|
+
* One line per account that threw, already redacted.
|
|
30808
|
+
*
|
|
30809
|
+
* Kept beside `detail` rather than read back out of it because `summarise`
|
|
30810
|
+
* needs the reasons WITHOUT the account labels it already prefixes — and
|
|
30811
|
+
* because `detail` also carries success lines ("签到 +5"), which a
|
|
30812
|
+
* positional convention over a mixed list would eventually get wrong.
|
|
30813
|
+
*/
|
|
30814
|
+
const failureNotes = [];
|
|
30653
30815
|
let progressNote;
|
|
30654
30816
|
try {
|
|
30655
30817
|
const revived = await this.pool.reviveBenched((credential) => this.client.fetchCredits(credential));
|
|
@@ -30733,6 +30895,9 @@ var WorkBuddyScheduler = class {
|
|
|
30733
30895
|
} catch (error) {
|
|
30734
30896
|
failed++;
|
|
30735
30897
|
this.logger.warn?.(`automation ${accountWord} ${account.label} failed:`, error);
|
|
30898
|
+
const reason = redactSecrets(describeError(error)).slice(0, 200);
|
|
30899
|
+
detail.push(`${account.label} ${accountWord} failed: ${reason}`);
|
|
30900
|
+
failureNotes.push(`${account.label}: ${reason}`);
|
|
30736
30901
|
}
|
|
30737
30902
|
if (index < accounts.length - 1 && this.delayMs > 0 && !this.stopped) await sleep$1(this.delayMs);
|
|
30738
30903
|
}
|
|
@@ -30747,6 +30912,8 @@ var WorkBuddyScheduler = class {
|
|
|
30747
30912
|
state.energy = energy;
|
|
30748
30913
|
state.claimed = claimed;
|
|
30749
30914
|
state.message = this.summarise(kind, ok, failed, claimed, credit, energy);
|
|
30915
|
+
if (failureNotes.length === 0) delete state.failures;
|
|
30916
|
+
else state.failures = failureNotes;
|
|
30750
30917
|
state.detail = detail;
|
|
30751
30918
|
state.items = items;
|
|
30752
30919
|
if (progressNote === void 0) delete state.progress;
|
|
@@ -31755,6 +31922,66 @@ function profileDir() {
|
|
|
31755
31922
|
if (existsSync(join(candidate, "package.json"))) return candidate;
|
|
31756
31923
|
}
|
|
31757
31924
|
}
|
|
31925
|
+
let syncImplementation = syncWithPnpm;
|
|
31926
|
+
/**
|
|
31927
|
+
* 写完 package.json 后用 pnpm 同步 lockfile 与 node_modules。
|
|
31928
|
+
*
|
|
31929
|
+
* 这是「更新了却一直没生效」的真正原因:以前只改 profile 的 package.json,没碰
|
|
31930
|
+
* pnpm-lock.yaml。DSH 下次启动按 lockfile 装回旧版本 —— 用户看到的就是
|
|
31931
|
+
* 「一键更新从没成功过」。现在交给 pnpm 把 package.json / lockfile / node_modules
|
|
31932
|
+
* 三处一次对齐。失败时调用方会回滚 manifest:半更新的 profile 会让宿主 repair。
|
|
31933
|
+
*/
|
|
31934
|
+
async function syncWithPnpm(profile) {
|
|
31935
|
+
return await new Promise((resolve) => {
|
|
31936
|
+
const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
31937
|
+
let child;
|
|
31938
|
+
try {
|
|
31939
|
+
child = spawn(command, [
|
|
31940
|
+
"install",
|
|
31941
|
+
"--config.auto-install-peers=false",
|
|
31942
|
+
"--ignore-scripts"
|
|
31943
|
+
], {
|
|
31944
|
+
cwd: profile,
|
|
31945
|
+
env: process.env,
|
|
31946
|
+
stdio: [
|
|
31947
|
+
"ignore",
|
|
31948
|
+
"pipe",
|
|
31949
|
+
"pipe"
|
|
31950
|
+
],
|
|
31951
|
+
shell: process.platform === "win32"
|
|
31952
|
+
});
|
|
31953
|
+
} catch (error) {
|
|
31954
|
+
resolve({
|
|
31955
|
+
ok: false,
|
|
31956
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
31957
|
+
});
|
|
31958
|
+
return;
|
|
31959
|
+
}
|
|
31960
|
+
let output = "";
|
|
31961
|
+
child.stdout?.on("data", (chunk) => {
|
|
31962
|
+
output += chunk.toString();
|
|
31963
|
+
});
|
|
31964
|
+
child.stderr?.on("data", (chunk) => {
|
|
31965
|
+
output += chunk.toString();
|
|
31966
|
+
});
|
|
31967
|
+
child.on("error", (error) => {
|
|
31968
|
+
resolve({
|
|
31969
|
+
ok: false,
|
|
31970
|
+
detail: error.message
|
|
31971
|
+
});
|
|
31972
|
+
});
|
|
31973
|
+
child.on("close", (code) => {
|
|
31974
|
+
if (code === 0) resolve({
|
|
31975
|
+
ok: true,
|
|
31976
|
+
detail: "pnpm install ok"
|
|
31977
|
+
});
|
|
31978
|
+
else resolve({
|
|
31979
|
+
ok: false,
|
|
31980
|
+
detail: output.slice(-400) || `pnpm exit ${String(code)}`
|
|
31981
|
+
});
|
|
31982
|
+
});
|
|
31983
|
+
});
|
|
31984
|
+
}
|
|
31758
31985
|
/** 把下载 / 读写文件时的错误翻成一句中文(前端直接展示)。 */
|
|
31759
31986
|
function chineseFailure(prefix, error) {
|
|
31760
31987
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -31881,6 +32108,7 @@ async function installVersion(version) {
|
|
|
31881
32108
|
*/
|
|
31882
32109
|
const newSpec = version;
|
|
31883
32110
|
const pkgPath = join(profile, "package.json");
|
|
32111
|
+
const originalManifest = readFileSync(pkgPath, "utf8");
|
|
31884
32112
|
const read = readProfilePackage(pkgPath);
|
|
31885
32113
|
if ("error" in read) {
|
|
31886
32114
|
steps.push({
|
|
@@ -31942,6 +32170,30 @@ async function installVersion(version) {
|
|
|
31942
32170
|
id: "write",
|
|
31943
32171
|
ok: true
|
|
31944
32172
|
});
|
|
32173
|
+
/**
|
|
32174
|
+
* 关键:让 pnpm 同步 lockfile 与 node_modules。
|
|
32175
|
+
* 以前只到上一行就返回成功,DSH 下次启动按旧 lockfile 装回旧版,版本号从不变化。
|
|
32176
|
+
* 同步失败就回滚,宁可这次没更新,也不留下会触发宿主 repair 的半更新 profile。
|
|
32177
|
+
*/
|
|
32178
|
+
const synced = await syncImplementation(profile);
|
|
32179
|
+
if (!synced.ok) {
|
|
32180
|
+
writeFileSync(`${pkgPath}.tmp`, originalManifest, "utf8");
|
|
32181
|
+
renameSync(`${pkgPath}.tmp`, pkgPath);
|
|
32182
|
+
steps.push({
|
|
32183
|
+
id: "write",
|
|
32184
|
+
ok: false,
|
|
32185
|
+
detail: `pnpm 同步失败,已回滚:${synced.detail}`
|
|
32186
|
+
});
|
|
32187
|
+
return failed(`安装依赖失败,已回滚,插件和数据都没有改动:${synced.detail}`, {
|
|
32188
|
+
path: target,
|
|
32189
|
+
backupPath
|
|
32190
|
+
});
|
|
32191
|
+
}
|
|
32192
|
+
steps.push({
|
|
32193
|
+
id: "sync",
|
|
32194
|
+
ok: true,
|
|
32195
|
+
detail: synced.detail
|
|
32196
|
+
});
|
|
31945
32197
|
return {
|
|
31946
32198
|
ok: true,
|
|
31947
32199
|
version,
|
|
@@ -31992,7 +32244,6 @@ async function updateToLatest() {
|
|
|
31992
32244
|
}
|
|
31993
32245
|
//#endregion
|
|
31994
32246
|
//#region src/web-status.ts
|
|
31995
|
-
/** Redact token-like content before it crosses to the browser. */
|
|
31996
32247
|
/**
|
|
31997
32248
|
* A zeroed-out automation job record.
|
|
31998
32249
|
*
|
|
@@ -32008,8 +32259,9 @@ function emptyAutomationJob() {
|
|
|
32008
32259
|
claimed: 0
|
|
32009
32260
|
};
|
|
32010
32261
|
}
|
|
32262
|
+
/** Redact token-like content before it crosses to the browser. */
|
|
32011
32263
|
function safeMessage(error) {
|
|
32012
|
-
return (error instanceof Error ? error.message : String(error)).
|
|
32264
|
+
return redactSecrets(error instanceof Error ? error.message : String(error)).slice(0, 500);
|
|
32013
32265
|
}
|
|
32014
32266
|
function json(res, status, body) {
|
|
32015
32267
|
const payload = JSON.stringify(body);
|
|
@@ -32412,7 +32664,17 @@ function toWebAccount(account, disabled, preferred, reserve, reserved) {
|
|
|
32412
32664
|
const now = Date.now();
|
|
32413
32665
|
const cooling = account.cooldownUntilMs > now;
|
|
32414
32666
|
const deadUntil = account.credentialDeadUntilMs ?? 0;
|
|
32415
|
-
|
|
32667
|
+
/**
|
|
32668
|
+
* 凭据本身已经过期、且 refresh 也过期 —— 这种情况不必等用户点一次失败才知道。
|
|
32669
|
+
*
|
|
32670
|
+
* 实测:一个 access 过期 9 天、refresh 过期 7 天的账号,点领取只会得到上游 401,
|
|
32671
|
+
* 而卡片上什么标记都没有,用户唯一的线索是「领取失败」。现在这种账号直接标成
|
|
32672
|
+
* 「登录失效」,卡片上就能看到,点它也会得到一句能照做的中文提示。
|
|
32673
|
+
*/
|
|
32674
|
+
const credential = account.credential;
|
|
32675
|
+
const refreshExpired = credential.refreshExpiresAtMs === void 0 || credential.refreshExpiresAtMs <= now;
|
|
32676
|
+
const expiredBeyondRepair = credential.expiresAtMs > 0 && credential.expiresAtMs <= now && refreshExpired;
|
|
32677
|
+
const credentialDead = deadUntil > now || expiredBeyondRepair;
|
|
32416
32678
|
const modelCooldowns = Object.entries(account.modelCooldowns).filter(([, until]) => until > now).sort((a, b) => a[1] - b[1]).map(([modelId, until]) => ({
|
|
32417
32679
|
modelId,
|
|
32418
32680
|
until: new Date(until).toISOString()
|
|
@@ -32695,7 +32957,15 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
32695
32957
|
if (accountId === "") return json(res, 400, { error: "accountId is required" });
|
|
32696
32958
|
const account = deps.pool.list().find((item) => item.id === accountId);
|
|
32697
32959
|
if (account === void 0) return json(res, 404, { error: "unknown account" });
|
|
32698
|
-
|
|
32960
|
+
/**
|
|
32961
|
+
* 先拿一份「能用」的凭据再发请求。
|
|
32962
|
+
*
|
|
32963
|
+
* 以前这里直接用 `account.credential`:凭据过期时上游回 401,用户看到
|
|
32964
|
+
* 的只有「领取失败」,而同一时刻对话正常(对话路径会先 ensureFresh)。
|
|
32965
|
+
*/
|
|
32966
|
+
const credential = deps.pool.freshCredential === void 0 ? account.credential : await deps.pool.freshCredential(accountId);
|
|
32967
|
+
if (credential === void 0) return json(res, 409, { error: "this account's sign-in has expired and could not be renewed; sign in again in the WorkBuddy desktop app, then retry" });
|
|
32968
|
+
const before = await deps.client.fetchCheckinStatus(credential);
|
|
32699
32969
|
if (!before.active) return json(res, 409, { error: "check-in activity is not active" });
|
|
32700
32970
|
if (before.todayCheckedIn) return json(res, 200, {
|
|
32701
32971
|
ok: true,
|
|
@@ -32708,10 +32978,19 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
32708
32978
|
});
|
|
32709
32979
|
json(res, 200, {
|
|
32710
32980
|
ok: true,
|
|
32711
|
-
claim: await deps.client.claimDailyCheckin(
|
|
32981
|
+
claim: await deps.client.claimDailyCheckin(credential)
|
|
32712
32982
|
});
|
|
32713
32983
|
} catch (error) {
|
|
32714
|
-
|
|
32984
|
+
const message = safeMessage(error);
|
|
32985
|
+
/**
|
|
32986
|
+
* 401 说清楚该做什么。
|
|
32987
|
+
*
|
|
32988
|
+
* 「领取失败」没有信息量:它可能是活动没有、可能今天已经领过、也可能是
|
|
32989
|
+
* 登录态彻底过期(refresh token 也过了)。实测这一类占失败的大多数,
|
|
32990
|
+
* 而用户能做的动作只有一个 —— 回 WorkBuddy 桌面端重新登录这个账号。
|
|
32991
|
+
*/
|
|
32992
|
+
if (/401|rejected this credential/i.test(message)) return json(res, 409, { error: "这个账号的登录已失效(上游返回 401),refresh token 也过期了。请在 WorkBuddy 桌面端重新登录这个账号,然后在卡片上重新检测账号后再领取。" });
|
|
32993
|
+
json(res, 500, { error: message });
|
|
32715
32994
|
}
|
|
32716
32995
|
}
|
|
32717
32996
|
});
|
|
@@ -33231,71 +33510,6 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
33231
33510
|
}, "dsh-xdpool: Web status route");
|
|
33232
33511
|
}
|
|
33233
33512
|
//#endregion
|
|
33234
|
-
//#region src/diagnostics.ts
|
|
33235
|
-
/**
|
|
33236
|
-
* A startup trace this plugin owns.
|
|
33237
|
-
*
|
|
33238
|
-
* The host's own logs have moved between at least three directories across the
|
|
33239
|
-
* 0.1.x / 0.2.x / DSH NEXT lines, and on a machine with no outbound network
|
|
33240
|
-
* they are not always where anyone thinks to look. When a provider fails to
|
|
33241
|
-
* register, "the model picker does not list xdpool" is the only symptom the
|
|
33242
|
-
* user can report, and answering it needs the exact throw — so the plugin
|
|
33243
|
-
* writes one small append-only file next to the settings it already owns.
|
|
33244
|
-
*
|
|
33245
|
-
* Everything here is best-effort: a diagnostic that can crash the thing it is
|
|
33246
|
-
* diagnosing is worse than no diagnostic, so every path swallows its own
|
|
33247
|
-
* failure and returns a value the caller can log instead.
|
|
33248
|
-
*
|
|
33249
|
-
* @module dsh-xdpool/diagnostics
|
|
33250
|
-
*/
|
|
33251
|
-
/**
|
|
33252
|
-
* Cap the trace so a plugin that restarts in a loop cannot fill the disk.
|
|
33253
|
-
* Half a megabyte is roughly a month of restarts, which is far more than the
|
|
33254
|
-
* single boot this file is meant to explain.
|
|
33255
|
-
*/
|
|
33256
|
-
const MAX_BYTES = 524288;
|
|
33257
|
-
/** The file lives beside the settings store, so one directory explains both. */
|
|
33258
|
-
function startupLogPath() {
|
|
33259
|
-
const home = process.env.DSH_HOME !== void 0 && process.env.DSH_HOME !== "" ? process.env.DSH_HOME : homedir();
|
|
33260
|
-
return join(home, ".xdpool", "startup.log");
|
|
33261
|
-
}
|
|
33262
|
-
/**
|
|
33263
|
-
* Render any thrown value as one line of text.
|
|
33264
|
-
*
|
|
33265
|
-
* `String(error)` on a real `Error` collapses the stack to "Error: message",
|
|
33266
|
-
* which is exactly the part worth keeping; the object form (`{}` for a
|
|
33267
|
-
* structured clone, `[object Object]` for anything else) is what produced the
|
|
33268
|
-
* unreadable `{}` markers in this project's earlier logs.
|
|
33269
|
-
*/
|
|
33270
|
-
function describeError(error) {
|
|
33271
|
-
if (error instanceof Error) {
|
|
33272
|
-
const code = "code" in error && typeof error.code === "string" ? ` (${String(error.code)})` : "";
|
|
33273
|
-
return `${error.name}: ${error.message}${code}`;
|
|
33274
|
-
}
|
|
33275
|
-
if (typeof error === "string") return error;
|
|
33276
|
-
try {
|
|
33277
|
-
return JSON.stringify(error) ?? String(error);
|
|
33278
|
-
} catch {
|
|
33279
|
-
return String(error);
|
|
33280
|
-
}
|
|
33281
|
-
}
|
|
33282
|
-
/**
|
|
33283
|
-
* Append one timestamped line. Returns the text that was written, so a caller
|
|
33284
|
-
* that cannot write the file can still put the same words in the host log.
|
|
33285
|
-
*/
|
|
33286
|
-
function recordStartupNote(line) {
|
|
33287
|
-
const text = `${(/* @__PURE__ */ new Date()).toISOString()} ${line}`;
|
|
33288
|
-
try {
|
|
33289
|
-
const path = startupLogPath();
|
|
33290
|
-
mkdirSync(join(path, ".."), { recursive: true });
|
|
33291
|
-
try {
|
|
33292
|
-
if (statSync(path).size > MAX_BYTES) truncateSync(path, 0);
|
|
33293
|
-
} catch {}
|
|
33294
|
-
appendFileSync(path, `${text}\n`, "utf8");
|
|
33295
|
-
} catch {}
|
|
33296
|
-
return text;
|
|
33297
|
-
}
|
|
33298
|
-
//#endregion
|
|
33299
33513
|
//#region src/model-switch-bridge.ts
|
|
33300
33514
|
/**
|
|
33301
33515
|
* The lane id the host's picker uses for each region.
|
|
@@ -37735,10 +37949,25 @@ const PLUGIN_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
|
37735
37949
|
* other side; comparing one tree with itself would always agree.
|
|
37736
37950
|
*/
|
|
37737
37951
|
const HOST_MODULE_ROOT = (() => {
|
|
37952
|
+
/**
|
|
37953
|
+
* issue #208:原来用 `../../node_modules/@deepseek-ai/dsh-llm-pi-ai/`:
|
|
37954
|
+
* `import.meta.url` 是 `<profile>/node_modules/dsh-xdpool/lib/index.js`,`../../`
|
|
37955
|
+
* 已经落到 `<profile>/node_modules/`,再拼 `node_modules/...` 就成了
|
|
37956
|
+
* `<profile>/node_modules/node_modules/...` —— 多一层,永远解析不到,守卫因此
|
|
37957
|
+
* 长期返回 unknown、日志里一个字都不写,而真正的 0.82 / 1.5 代际错配照样崩。
|
|
37958
|
+
*
|
|
37959
|
+
* 现在优先用 createRequire 从插件自身解析宿主包(pnpm / hoisted / 全局安装都
|
|
37960
|
+
* 能覆盖),再退回少一层的相对路径。createRequire 在 ESM bundle 里也可用。
|
|
37961
|
+
*/
|
|
37738
37962
|
try {
|
|
37739
|
-
|
|
37963
|
+
const require_ = createRequire(import.meta.url);
|
|
37964
|
+
return dirname(require_.resolve("@deepseek-ai/dsh-llm-pi-ai/package.json"));
|
|
37740
37965
|
} catch {
|
|
37741
|
-
|
|
37966
|
+
try {
|
|
37967
|
+
return fileURLToPath(new URL("../node_modules/@deepseek-ai/dsh-llm-pi-ai/", import.meta.url));
|
|
37968
|
+
} catch {
|
|
37969
|
+
return "";
|
|
37970
|
+
}
|
|
37742
37971
|
}
|
|
37743
37972
|
})();
|
|
37744
37973
|
/** Stable Cordis plugin name. */
|
|
@@ -37995,9 +38224,19 @@ function createCore(logger) {
|
|
|
37995
38224
|
*/
|
|
37996
38225
|
function warnOnPiAiGenerationMismatch(ctx) {
|
|
37997
38226
|
try {
|
|
37998
|
-
const
|
|
38227
|
+
const check = checkPiAiGeneration(PLUGIN_ROOT, HOST_MODULE_ROOT);
|
|
38228
|
+
const message = piAiMismatchMessage(check);
|
|
37999
38229
|
if (message !== void 0) ctx.logger.warn(message);
|
|
38000
|
-
|
|
38230
|
+
/**
|
|
38231
|
+
* issue #208:`unknown` 曾经和「对齐」在日志上完全一样,用户撞上代际错配时
|
|
38232
|
+
* 没有任何线索。现在至少留一行,说明是「读不到某一侧」还是「两侧对齐」。
|
|
38233
|
+
* 这一行不是警告 —— 单侧可见(比如宿主把 pi-ai 打进 bundle)是合法安装。
|
|
38234
|
+
*/
|
|
38235
|
+
if (check.kind === "unknown") recordStartupNote("pi-ai generation: unknown (one or both resolutions unavailable)");
|
|
38236
|
+
else if (check.kind === "aligned") recordStartupNote(`pi-ai generation: aligned at ${check.generation}`);
|
|
38237
|
+
} catch (error) {
|
|
38238
|
+
recordStartupNote(`pi-ai generation check skipped: ${describeError(error)}`);
|
|
38239
|
+
}
|
|
38001
38240
|
}
|
|
38002
38241
|
/**
|
|
38003
38242
|
* Late-bound switch for the 免密 lane, set once the catalog exists.
|
|
@@ -38623,30 +38862,52 @@ function apply(ctx, config = {}) {
|
|
|
38623
38862
|
adopted: () => {},
|
|
38624
38863
|
trustedHosts
|
|
38625
38864
|
});
|
|
38626
|
-
|
|
38627
|
-
|
|
38628
|
-
|
|
38629
|
-
|
|
38630
|
-
|
|
38631
|
-
|
|
38632
|
-
|
|
38633
|
-
|
|
38634
|
-
|
|
38635
|
-
|
|
38636
|
-
|
|
38637
|
-
|
|
38638
|
-
|
|
38639
|
-
|
|
38640
|
-
|
|
38641
|
-
|
|
38642
|
-
|
|
38643
|
-
|
|
38644
|
-
|
|
38645
|
-
|
|
38646
|
-
|
|
38647
|
-
|
|
38648
|
-
|
|
38649
|
-
|
|
38865
|
+
/**
|
|
38866
|
+
* 探针:确认 webServer 这条注入真的进来了。
|
|
38867
|
+
*
|
|
38868
|
+
* 插件有两层注册 —— `ctx.inject(['webServer'])` 里的 HTTP 路由,和
|
|
38869
|
+
* `ctx.inject(['llm'])` 里的 provider。前者若整段没执行(服务没注入、或回调里
|
|
38870
|
+
* 某条注册抛错),界面就只剩 `HTTP 404`,而 provider 层照常工作、日志里也有
|
|
38871
|
+
* `providers registered`。所以这一条 note 是判断「路由层到底有没有起来」的分界线。
|
|
38872
|
+
*/
|
|
38873
|
+
recordStartupNote("routes: webCtx callback entered");
|
|
38874
|
+
/**
|
|
38875
|
+
* 每一层路由各自兜住自己的失败。
|
|
38876
|
+
*
|
|
38877
|
+
* 以前这里是三段落顺序执行的裸调用:任何一段抛错(重复路由、依赖没就位),
|
|
38878
|
+
* 后面的注册就再也不执行 —— 界面上表现为「模型能用、点任何按钮都是 HTTP 404」,
|
|
38879
|
+
* 而且日志里只剩一条 `providers registered`,看不出断在哪。
|
|
38880
|
+
* 现在每段独立 try/catch,失败写进 startup.log,其余照常注册。
|
|
38881
|
+
*/
|
|
38882
|
+
try {
|
|
38883
|
+
registerDoubaoRoutes(webCtx, {
|
|
38884
|
+
session: () => doubaoSession,
|
|
38885
|
+
trustedHosts,
|
|
38886
|
+
save: (session) => {
|
|
38887
|
+
adoptDoubaoSession(session);
|
|
38888
|
+
writeStoredSession(session);
|
|
38889
|
+
},
|
|
38890
|
+
clear: () => {
|
|
38891
|
+
adoptDoubaoSession(void 0);
|
|
38892
|
+
removeStoredSession();
|
|
38893
|
+
},
|
|
38894
|
+
automation: () => doubaoAutomation,
|
|
38895
|
+
/**
|
|
38896
|
+
* Persist the card's disable-list — issue #196.
|
|
38897
|
+
*
|
|
38898
|
+
* `setSetting` re-reads and throws when the document did not change, so a
|
|
38899
|
+
* refused write reaches the card as a 500 instead of looking saved.
|
|
38900
|
+
*/
|
|
38901
|
+
saveDoubaoSelection: async (ids, hideAll) => {
|
|
38902
|
+
const payload = [...ids];
|
|
38903
|
+
await setSetting("doubaoDisabledModels", payload, payload);
|
|
38904
|
+
await setSetting("doubaoHideAllModels", hideAll === true, hideAll === true);
|
|
38905
|
+
}
|
|
38906
|
+
});
|
|
38907
|
+
recordStartupNote("routes: doubao ok");
|
|
38908
|
+
} catch (error) {
|
|
38909
|
+
recordStartupNote(`routes: doubao FAILED: ${describeError(error)}`);
|
|
38910
|
+
}
|
|
38650
38911
|
/**
|
|
38651
38912
|
* The 「账号使用方式」 route — the one 3.0.0 forgot to register.
|
|
38652
38913
|
*
|
|
@@ -38656,266 +38917,278 @@ function apply(ctx, config = {}) {
|
|
|
38656
38917
|
* Registering it here is the whole fix — the read, the atomic write and the
|
|
38657
38918
|
* publish to the pack were already written and tested.
|
|
38658
38919
|
*/
|
|
38659
|
-
|
|
38660
|
-
|
|
38661
|
-
|
|
38662
|
-
|
|
38663
|
-
|
|
38664
|
-
|
|
38665
|
-
|
|
38666
|
-
|
|
38667
|
-
|
|
38668
|
-
|
|
38669
|
-
|
|
38670
|
-
|
|
38671
|
-
|
|
38672
|
-
|
|
38673
|
-
|
|
38674
|
-
|
|
38675
|
-
|
|
38676
|
-
|
|
38677
|
-
|
|
38678
|
-
|
|
38679
|
-
|
|
38680
|
-
|
|
38681
|
-
|
|
38682
|
-
|
|
38683
|
-
|
|
38684
|
-
|
|
38685
|
-
|
|
38686
|
-
|
|
38687
|
-
|
|
38688
|
-
|
|
38689
|
-
|
|
38690
|
-
|
|
38691
|
-
|
|
38692
|
-
|
|
38693
|
-
|
|
38694
|
-
|
|
38695
|
-
|
|
38696
|
-
|
|
38697
|
-
|
|
38698
|
-
|
|
38699
|
-
|
|
38700
|
-
|
|
38701
|
-
|
|
38702
|
-
|
|
38703
|
-
|
|
38704
|
-
|
|
38705
|
-
|
|
38706
|
-
|
|
38707
|
-
|
|
38708
|
-
|
|
38709
|
-
|
|
38710
|
-
|
|
38711
|
-
|
|
38712
|
-
|
|
38713
|
-
|
|
38714
|
-
|
|
38715
|
-
|
|
38716
|
-
|
|
38717
|
-
|
|
38718
|
-
}
|
|
38719
|
-
|
|
38720
|
-
|
|
38721
|
-
|
|
38722
|
-
|
|
38723
|
-
|
|
38724
|
-
|
|
38725
|
-
|
|
38726
|
-
|
|
38727
|
-
|
|
38728
|
-
|
|
38729
|
-
|
|
38730
|
-
|
|
38731
|
-
|
|
38732
|
-
|
|
38733
|
-
|
|
38734
|
-
|
|
38735
|
-
|
|
38736
|
-
|
|
38737
|
-
|
|
38738
|
-
|
|
38739
|
-
|
|
38740
|
-
|
|
38741
|
-
|
|
38742
|
-
|
|
38743
|
-
|
|
38744
|
-
|
|
38745
|
-
|
|
38746
|
-
|
|
38747
|
-
|
|
38748
|
-
|
|
38749
|
-
|
|
38750
|
-
|
|
38751
|
-
|
|
38752
|
-
status: probe.status,
|
|
38753
|
-
message: probe.message,
|
|
38754
|
-
...probe.modelCount === void 0 ? {} : { modelCount: probe.modelCount },
|
|
38755
|
-
...probe.modelIds === void 0 ? {} : { modelIds: probe.modelIds }
|
|
38756
|
-
};
|
|
38757
|
-
},
|
|
38758
|
-
/**
|
|
38759
|
-
* One real streaming call, for the card's per-model "test connection" button.
|
|
38760
|
-
*
|
|
38761
|
-
* Routed through `ctx.llm.stream` rather than through any of this plugin's
|
|
38762
|
-
* own lanes, and that is the whole point: `ctx.llm` is the host's adapter
|
|
38763
|
-
* registry, so it resolves the provider/model pair to whichever credential
|
|
38764
|
-
* and endpoint actually serve it — including lanes this plugin knows nothing
|
|
38765
|
-
* about. Asking our own shims instead would make the button report on the
|
|
38766
|
-
* plumbing rather than on the model the user clicked.
|
|
38767
|
-
*
|
|
38768
|
-
* Never throws (see {@link probeModelConnectivity}): the measurement is the
|
|
38769
|
-
* answer, and a rejection here would show as a bare route failure that reads
|
|
38770
|
-
* like a wrong key.
|
|
38771
|
-
*/
|
|
38772
|
-
probeModel: async (provider, model, signal) => {
|
|
38773
|
-
return probeModelConnectivity(ctx.llm, provider, model, { signal });
|
|
38774
|
-
},
|
|
38775
|
-
/**
|
|
38776
|
-
* What each login channel contributes, read from the host's own catalogue.
|
|
38777
|
-
*
|
|
38778
|
-
* Not from the pack, on purpose. The pack's `model.list` keeps the id, the
|
|
38779
|
-
* name and two flags and drops the rest, and the rest is exactly what the
|
|
38780
|
-
* login page is asked to show. The host's `listModels` is also the same
|
|
38781
|
-
* catalogue the model picker builds from, so a row's window here is the
|
|
38782
|
-
* window the picker will enforce.
|
|
38783
|
-
*
|
|
38784
|
-
* `listModels` is a LISTING, though: the host's own answer carries only the
|
|
38785
|
-
* id, the name, a description and the input modalities, and the host drops
|
|
38786
|
-
* the context window out of it on the way out (its listing mapper keeps
|
|
38787
|
-
* four fields). The window lives one call deeper, on
|
|
38788
|
-
* `resolveModelInfo(provider, model)` — which is where the model picker and
|
|
38789
|
-
* the compaction planner read it from — so a second pass over each row is
|
|
38790
|
-
* the only way to show a context size that matches what will actually be
|
|
38791
|
-
* enforced.
|
|
38792
|
-
*
|
|
38793
|
-
* That second pass is bounded and per-row isolated: adapters resolve a model
|
|
38794
|
-
* from their own cache in the common case, a row that cannot be resolved
|
|
38795
|
-
* simply prints no window, and a channel's answer is never held up by one
|
|
38796
|
-
* model it could not describe.
|
|
38797
|
-
*
|
|
38798
|
-
* A provider with no adapter registered under it is left out of the record
|
|
38799
|
-
* instead of being reported empty: "not signed in" and "signed in with
|
|
38800
|
-
* nothing to offer" would otherwise be drawn identically, and the user has
|
|
38801
|
-
* no way to tell which one they are looking at.
|
|
38802
|
-
*/
|
|
38803
|
-
channelModels: async (providers, hints) => {
|
|
38804
|
-
const models = {};
|
|
38805
|
-
const resolveConcurrency = 6;
|
|
38806
|
-
for (const provider of providers) try {
|
|
38807
|
-
const hinted = hints?.[provider];
|
|
38808
|
-
const rows = hinted !== void 0 && hinted.length > 0 ? hinted.map((id) => ({
|
|
38809
|
-
id,
|
|
38810
|
-
name: id
|
|
38811
|
-
})) : await ctx.llm.listModels(provider);
|
|
38812
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
38813
|
-
let next = 0;
|
|
38814
|
-
const workers = Array.from({ length: Math.min(resolveConcurrency, rows.length) }, async () => {
|
|
38815
|
-
while (next < rows.length) {
|
|
38816
|
-
const row = rows[next++];
|
|
38817
|
-
if (row === void 0) continue;
|
|
38818
|
-
let extra = {};
|
|
38819
|
-
try {
|
|
38820
|
-
const info = await ctx.llm.resolveModelInfo(provider, row.id);
|
|
38821
|
-
extra = {
|
|
38822
|
-
...info.context?.contextWindow === void 0 ? {} : { contextWindow: info.context.contextWindow },
|
|
38823
|
-
...info.defaultMaxTokens === void 0 ? {} : { maxTokens: info.defaultMaxTokens },
|
|
38824
|
-
...info.inputModalities === void 0 ? {} : { inputModalities: info.inputModalities }
|
|
38825
|
-
};
|
|
38826
|
-
} catch (cause) {}
|
|
38827
|
-
resolved.set(row.id, {
|
|
38828
|
-
id: row.id,
|
|
38829
|
-
name: row.name,
|
|
38830
|
-
...row.description === void 0 ? {} : { description: row.description },
|
|
38831
|
-
...row.inputModalities === void 0 ? {} : { inputModalities: row.inputModalities },
|
|
38832
|
-
...extra
|
|
38833
|
-
});
|
|
38834
|
-
}
|
|
38920
|
+
try {
|
|
38921
|
+
registerChannelUsageRoute(webCtx, {
|
|
38922
|
+
pool: () => current().distribution ?? "priority",
|
|
38923
|
+
trustedHosts
|
|
38924
|
+
});
|
|
38925
|
+
recordStartupNote("routes: channel-usage ok");
|
|
38926
|
+
} catch (error) {
|
|
38927
|
+
recordStartupNote(`routes: channel-usage FAILED: ${describeError(error)}`);
|
|
38928
|
+
}
|
|
38929
|
+
recordStartupNote("routes: doubao + channel-usage registered; registering the rest");
|
|
38930
|
+
recordStartupNote("routes: status + checkin + models routes registering");
|
|
38931
|
+
try {
|
|
38932
|
+
registerPoolStatusRoute(webCtx, {
|
|
38933
|
+
pool: core.pool,
|
|
38934
|
+
trustedHosts,
|
|
38935
|
+
/**
|
|
38936
|
+
* The usage order each channel actually uses.
|
|
38937
|
+
*
|
|
38938
|
+
* A channel with an override reports it; one without reports the pool-wide value, because
|
|
38939
|
+
* that IS what it uses — the card shows the effective decision, not just the stored one.
|
|
38940
|
+
*/
|
|
38941
|
+
/**
|
|
38942
|
+
* The usage order each channel actually uses.
|
|
38943
|
+
*
|
|
38944
|
+
* The per-channel overrides live in the plugin's own state file rather than in the host's
|
|
38945
|
+
* settings document: the host's write path for a plugin's section accepts only its own
|
|
38946
|
+
* `{auto}` toggle, so a settings write from here would need a service this build may not
|
|
38947
|
+
* publish. A file the plugin already owns is the same mechanism `accounts.json` uses, and
|
|
38948
|
+
* the effective value is computed the same way either way.
|
|
38949
|
+
*/
|
|
38950
|
+
channelUsage: () => ({
|
|
38951
|
+
pool: config.distribution ?? "priority",
|
|
38952
|
+
channels: readChannelUsage()
|
|
38953
|
+
}),
|
|
38954
|
+
setChannelUsage: async (channel, strategy) => {
|
|
38955
|
+
writeChannelUsage(channel, isUsageStrategy(strategy) ? strategy : void 0);
|
|
38956
|
+
},
|
|
38957
|
+
catalogs: core.catalogs,
|
|
38958
|
+
client: core.client,
|
|
38959
|
+
usage: () => usageRecorder.summary(),
|
|
38960
|
+
shim: () => shimInfo("cn"),
|
|
38961
|
+
scheduler: () => core.scheduler.status(),
|
|
38962
|
+
runAutomation: (_job, _force) => core.scheduler.startRunAll(),
|
|
38963
|
+
saveSelection: async (region, selection) => {
|
|
38964
|
+
const payload = {
|
|
38965
|
+
...selection.enabledModelIds === void 0 ? {} : { enabledModelIds: [...selection.enabledModelIds] },
|
|
38966
|
+
...selection.imageModelIds === void 0 ? {} : { imageModelIds: [...selection.imageModelIds] },
|
|
38967
|
+
...selection.contextBudgets === void 0 ? {} : { contextBudgets: { ...selection.contextBudgets } }
|
|
38968
|
+
};
|
|
38969
|
+
await setSetting(modelSelectionKeyFor(region), payload, payload);
|
|
38970
|
+
},
|
|
38971
|
+
setAccountDisabled: async (accountId, disabled) => {
|
|
38972
|
+
const currentIds = current().disabledAccountIds ?? [];
|
|
38973
|
+
const next = disabled ? currentIds.includes(accountId) ? currentIds : [...currentIds, accountId] : currentIds.filter((id) => id !== accountId);
|
|
38974
|
+
await setSetting("disabledAccountIds", next, next);
|
|
38975
|
+
},
|
|
38976
|
+
setCreditReserve: async (accountId, reserve) => {
|
|
38977
|
+
const next = creditReservesWith(current().creditReserves, accountId, reserve);
|
|
38978
|
+
await setSetting("creditReserves", next, next);
|
|
38979
|
+
},
|
|
38980
|
+
setAccountIgnored: async (accountId, ignored) => {
|
|
38981
|
+
if (ignored) {
|
|
38982
|
+
const known = core.pool.list().find((account) => account.id === accountId);
|
|
38983
|
+
await ignoreAccount({
|
|
38984
|
+
id: accountId,
|
|
38985
|
+
...known === void 0 ? {} : { label: known.label }
|
|
38986
|
+
}, ignoredPath);
|
|
38987
|
+
} else await unignoreAccount(accountId, ignoredPath);
|
|
38988
|
+
refreshIgnored();
|
|
38989
|
+
if (!ignored) await core.pool.scan();
|
|
38990
|
+
},
|
|
38991
|
+
ignoredAccounts: () => ignoredAccounts,
|
|
38992
|
+
setPreferredAccount: async (accountId) => {
|
|
38993
|
+
await writePreferredId(accountId ?? void 0, preferredPath);
|
|
38994
|
+
applyPreferred(accountId ?? void 0);
|
|
38995
|
+
},
|
|
38996
|
+
refreshCatalog: async () => {
|
|
38997
|
+
const result = await seedCatalog();
|
|
38998
|
+
invalidateCatalog();
|
|
38999
|
+
return result;
|
|
39000
|
+
},
|
|
39001
|
+
aggregateDocument: () => aggregateStatusOf(readAggregateSettingsSync(), aggregateCatalog.providerRows().map(toWebAggregateModel)),
|
|
39002
|
+
saveAggregate: async (patch) => {
|
|
39003
|
+
if (patch.kind === "lane") await setAggregateEnabled(patch.enabled);
|
|
39004
|
+
else if (patch.kind === "clear") await clearProviderSetting(patch.providerId);
|
|
39005
|
+
else await updateProviderSetting(patch.providerId, {
|
|
39006
|
+
...patch.enabled === void 0 ? {} : { enabled: patch.enabled },
|
|
39007
|
+
...patch.apiKey === void 0 ? {} : { apiKey: patch.apiKey },
|
|
39008
|
+
...patch.apiKeys === void 0 ? {} : { apiKeys: patch.apiKeys },
|
|
39009
|
+
...patch.appendApiKey === void 0 ? {} : { appendApiKey: patch.appendApiKey },
|
|
39010
|
+
...patch.distribution === void 0 ? {} : { distribution: patch.distribution },
|
|
39011
|
+
...patch.baseUrl === void 0 ? {} : { baseUrl: patch.baseUrl },
|
|
39012
|
+
...patch.models === void 0 ? {} : { models: patch.models }
|
|
38835
39013
|
});
|
|
38836
|
-
await
|
|
38837
|
-
|
|
38838
|
-
}
|
|
38839
|
-
|
|
38840
|
-
|
|
38841
|
-
|
|
38842
|
-
|
|
38843
|
-
|
|
38844
|
-
|
|
38845
|
-
|
|
38846
|
-
|
|
38847
|
-
|
|
38848
|
-
}
|
|
38849
|
-
|
|
38850
|
-
|
|
38851
|
-
|
|
38852
|
-
|
|
38853
|
-
|
|
38854
|
-
|
|
38855
|
-
|
|
38856
|
-
|
|
38857
|
-
|
|
38858
|
-
|
|
38859
|
-
|
|
38860
|
-
|
|
38861
|
-
|
|
38862
|
-
|
|
38863
|
-
|
|
38864
|
-
|
|
38865
|
-
|
|
38866
|
-
|
|
38867
|
-
|
|
38868
|
-
|
|
38869
|
-
|
|
38870
|
-
|
|
38871
|
-
|
|
38872
|
-
|
|
38873
|
-
|
|
38874
|
-
|
|
38875
|
-
|
|
38876
|
-
|
|
38877
|
-
|
|
38878
|
-
|
|
38879
|
-
|
|
38880
|
-
|
|
38881
|
-
|
|
38882
|
-
|
|
38883
|
-
|
|
38884
|
-
|
|
38885
|
-
|
|
38886
|
-
|
|
38887
|
-
|
|
38888
|
-
|
|
38889
|
-
|
|
38890
|
-
|
|
38891
|
-
|
|
38892
|
-
|
|
38893
|
-
|
|
38894
|
-
|
|
38895
|
-
|
|
38896
|
-
|
|
38897
|
-
|
|
38898
|
-
|
|
38899
|
-
|
|
38900
|
-
|
|
38901
|
-
|
|
38902
|
-
|
|
38903
|
-
|
|
38904
|
-
|
|
38905
|
-
|
|
38906
|
-
|
|
38907
|
-
|
|
38908
|
-
|
|
38909
|
-
|
|
38910
|
-
|
|
38911
|
-
|
|
38912
|
-
|
|
38913
|
-
|
|
38914
|
-
|
|
38915
|
-
|
|
38916
|
-
|
|
38917
|
-
|
|
38918
|
-
|
|
39014
|
+
await aggregateCatalog.refresh();
|
|
39015
|
+
return aggregateStatusOf(readAggregateSettingsSync(), aggregateCatalog.providerRows().map(toWebAggregateModel));
|
|
39016
|
+
},
|
|
39017
|
+
probeAggregate: async (providerId) => {
|
|
39018
|
+
const probe = await probeAggregateProvider(readAggregateSettingsSync(), providerId);
|
|
39019
|
+
return {
|
|
39020
|
+
ok: probe.ok,
|
|
39021
|
+
status: probe.status,
|
|
39022
|
+
message: probe.message,
|
|
39023
|
+
...probe.modelCount === void 0 ? {} : { modelCount: probe.modelCount },
|
|
39024
|
+
...probe.modelIds === void 0 ? {} : { modelIds: probe.modelIds }
|
|
39025
|
+
};
|
|
39026
|
+
},
|
|
39027
|
+
/**
|
|
39028
|
+
* One real streaming call, for the card's per-model "test connection" button.
|
|
39029
|
+
*
|
|
39030
|
+
* Routed through `ctx.llm.stream` rather than through any of this plugin's
|
|
39031
|
+
* own lanes, and that is the whole point: `ctx.llm` is the host's adapter
|
|
39032
|
+
* registry, so it resolves the provider/model pair to whichever credential
|
|
39033
|
+
* and endpoint actually serve it — including lanes this plugin knows nothing
|
|
39034
|
+
* about. Asking our own shims instead would make the button report on the
|
|
39035
|
+
* plumbing rather than on the model the user clicked.
|
|
39036
|
+
*
|
|
39037
|
+
* Never throws (see {@link probeModelConnectivity}): the measurement is the
|
|
39038
|
+
* answer, and a rejection here would show as a bare route failure that reads
|
|
39039
|
+
* like a wrong key.
|
|
39040
|
+
*/
|
|
39041
|
+
probeModel: async (provider, model, signal) => {
|
|
39042
|
+
return probeModelConnectivity(ctx.llm, provider, model, { signal });
|
|
39043
|
+
},
|
|
39044
|
+
/**
|
|
39045
|
+
* What each login channel contributes, read from the host's own catalogue.
|
|
39046
|
+
*
|
|
39047
|
+
* Not from the pack, on purpose. The pack's `model.list` keeps the id, the
|
|
39048
|
+
* name and two flags and drops the rest, and the rest is exactly what the
|
|
39049
|
+
* login page is asked to show. The host's `listModels` is also the same
|
|
39050
|
+
* catalogue the model picker builds from, so a row's window here is the
|
|
39051
|
+
* window the picker will enforce.
|
|
39052
|
+
*
|
|
39053
|
+
* `listModels` is a LISTING, though: the host's own answer carries only the
|
|
39054
|
+
* id, the name, a description and the input modalities, and the host drops
|
|
39055
|
+
* the context window out of it on the way out (its listing mapper keeps
|
|
39056
|
+
* four fields). The window lives one call deeper, on
|
|
39057
|
+
* `resolveModelInfo(provider, model)` — which is where the model picker and
|
|
39058
|
+
* the compaction planner read it from — so a second pass over each row is
|
|
39059
|
+
* the only way to show a context size that matches what will actually be
|
|
39060
|
+
* enforced.
|
|
39061
|
+
*
|
|
39062
|
+
* That second pass is bounded and per-row isolated: adapters resolve a model
|
|
39063
|
+
* from their own cache in the common case, a row that cannot be resolved
|
|
39064
|
+
* simply prints no window, and a channel's answer is never held up by one
|
|
39065
|
+
* model it could not describe.
|
|
39066
|
+
*
|
|
39067
|
+
* A provider with no adapter registered under it is left out of the record
|
|
39068
|
+
* instead of being reported empty: "not signed in" and "signed in with
|
|
39069
|
+
* nothing to offer" would otherwise be drawn identically, and the user has
|
|
39070
|
+
* no way to tell which one they are looking at.
|
|
39071
|
+
*/
|
|
39072
|
+
channelModels: async (providers, hints) => {
|
|
39073
|
+
const models = {};
|
|
39074
|
+
const resolveConcurrency = 6;
|
|
39075
|
+
for (const provider of providers) try {
|
|
39076
|
+
const hinted = hints?.[provider];
|
|
39077
|
+
const rows = hinted !== void 0 && hinted.length > 0 ? hinted.map((id) => ({
|
|
39078
|
+
id,
|
|
39079
|
+
name: id
|
|
39080
|
+
})) : await ctx.llm.listModels(provider);
|
|
39081
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
39082
|
+
let next = 0;
|
|
39083
|
+
const workers = Array.from({ length: Math.min(resolveConcurrency, rows.length) }, async () => {
|
|
39084
|
+
while (next < rows.length) {
|
|
39085
|
+
const row = rows[next++];
|
|
39086
|
+
if (row === void 0) continue;
|
|
39087
|
+
let extra = {};
|
|
39088
|
+
try {
|
|
39089
|
+
const info = await ctx.llm.resolveModelInfo(provider, row.id);
|
|
39090
|
+
extra = {
|
|
39091
|
+
...info.context?.contextWindow === void 0 ? {} : { contextWindow: info.context.contextWindow },
|
|
39092
|
+
...info.defaultMaxTokens === void 0 ? {} : { maxTokens: info.defaultMaxTokens },
|
|
39093
|
+
...info.inputModalities === void 0 ? {} : { inputModalities: info.inputModalities }
|
|
39094
|
+
};
|
|
39095
|
+
} catch (cause) {}
|
|
39096
|
+
resolved.set(row.id, {
|
|
39097
|
+
id: row.id,
|
|
39098
|
+
name: row.name,
|
|
39099
|
+
...row.description === void 0 ? {} : { description: row.description },
|
|
39100
|
+
...row.inputModalities === void 0 ? {} : { inputModalities: row.inputModalities },
|
|
39101
|
+
...extra
|
|
39102
|
+
});
|
|
39103
|
+
}
|
|
39104
|
+
});
|
|
39105
|
+
await Promise.all(workers);
|
|
39106
|
+
models[provider] = rows.map((row) => resolved.get(row.id)).filter((row) => row !== void 0);
|
|
39107
|
+
} catch {}
|
|
39108
|
+
return models;
|
|
39109
|
+
},
|
|
39110
|
+
discoverAggregate: async (providerId) => {
|
|
39111
|
+
const probe = await probeAggregateProvider(readAggregateSettingsSync(), providerId);
|
|
39112
|
+
if (!probe.ok || probe.modelIds === void 0) return {
|
|
39113
|
+
ok: probe.ok,
|
|
39114
|
+
status: probe.status,
|
|
39115
|
+
message: probe.message,
|
|
39116
|
+
...probe.modelCount === void 0 ? {} : { modelCount: probe.modelCount }
|
|
39117
|
+
};
|
|
39118
|
+
await updateProviderSetting(providerId, { discovered: probe.modelIds });
|
|
39119
|
+
await aggregateCatalog.refresh();
|
|
39120
|
+
return {
|
|
39121
|
+
ok: true,
|
|
39122
|
+
status: probe.status,
|
|
39123
|
+
message: probe.message,
|
|
39124
|
+
...probe.modelCount === void 0 ? {} : { modelCount: probe.modelCount },
|
|
39125
|
+
modelIds: probe.modelIds,
|
|
39126
|
+
committed: probe.modelIds.length
|
|
39127
|
+
};
|
|
39128
|
+
},
|
|
39129
|
+
channelsDocument: () => {
|
|
39130
|
+
const state = channels.state();
|
|
39131
|
+
return {
|
|
39132
|
+
state: state.state,
|
|
39133
|
+
...state.state === "unavailable" ? { reason: state.reason } : {},
|
|
39134
|
+
channels: REGISTERED_CHANNELS.map((channel) => ({
|
|
39135
|
+
id: channel.id,
|
|
39136
|
+
name: channel.name,
|
|
39137
|
+
org: channel.org,
|
|
39138
|
+
...channel.domain === void 0 ? {} : { domain: channel.domain },
|
|
39139
|
+
accent: channel.accent,
|
|
39140
|
+
note: channel.note,
|
|
39141
|
+
loginKind: channel.login,
|
|
39142
|
+
ownedByPool: POOL_OWNED_CHANNELS.has(channel.id),
|
|
39143
|
+
...channel.smsHint === true ? { smsHint: true } : {},
|
|
39144
|
+
...channel.credits === void 0 ? {} : { credits: channel.credits }
|
|
39145
|
+
}))
|
|
39146
|
+
};
|
|
39147
|
+
},
|
|
39148
|
+
combosDocument: async () => combosStatusOf(readAggregateSettingsSync(), aggregateCatalog, core.catalogs.cn.current(), await hostRoster()),
|
|
39149
|
+
saveCombos: async (raw) => {
|
|
39150
|
+
await saveCombos(raw);
|
|
39151
|
+
await aggregateCatalog.refresh();
|
|
39152
|
+
return combosStatusOf(readAggregateSettingsSync(), aggregateCatalog, core.catalogs.cn.current(), await hostRoster());
|
|
39153
|
+
},
|
|
39154
|
+
/** Estimated credit spend per channel, for the composer strip. */
|
|
39155
|
+
creditsSpend: async (days) => await creditSpend(days),
|
|
39156
|
+
/**
|
|
39157
|
+
* Relay state plus the gateway's model picker.
|
|
39158
|
+
*
|
|
39159
|
+
* The candidates come from the shim's own roster rather than a parallel
|
|
39160
|
+
* assembly here, so the card cannot offer a model the gateway would then
|
|
39161
|
+
* refuse — the exact drift the picker exists to prevent.
|
|
39162
|
+
*/
|
|
39163
|
+
relayDocument,
|
|
39164
|
+
/**
|
|
39165
|
+
* Apply one patch from the card and answer with the fresh document.
|
|
39166
|
+
*
|
|
39167
|
+
* The write path mints a key when the card asks for a rotation and the user
|
|
39168
|
+
* has never had one: an enabled relay with no key would have to either refuse
|
|
39169
|
+
* everyone (so the switch silently does nothing) or accept everyone. Minting
|
|
39170
|
+
* one keeps "enabled" honest, and the card shows it so it can be pasted into
|
|
39171
|
+
* the other device.
|
|
39172
|
+
*/
|
|
39173
|
+
saveRelay: async (patch) => {
|
|
39174
|
+
const before = readAggregateSettingsSync().relay ?? {};
|
|
39175
|
+
const key = patch.key === "" ? newRelayKey() : patch.key;
|
|
39176
|
+
await updateRelaySetting({
|
|
39177
|
+
...patch.enabled === void 0 ? {} : { enabled: patch.enabled },
|
|
39178
|
+
...patch.host === void 0 ? {} : { host: patch.host },
|
|
39179
|
+
...patch.port === void 0 ? {} : { port: patch.port },
|
|
39180
|
+
key: key ?? before.key ?? newRelayKey(),
|
|
39181
|
+
...patch.models === void 0 ? {} : { models: patch.models },
|
|
39182
|
+
...patch.modelsMode === void 0 ? {} : { modelsMode: patch.modelsMode }
|
|
39183
|
+
});
|
|
39184
|
+
await relay.sync();
|
|
39185
|
+
return relayDocument();
|
|
39186
|
+
}
|
|
39187
|
+
});
|
|
39188
|
+
recordStartupNote("routes: status family ok");
|
|
39189
|
+
} catch (error) {
|
|
39190
|
+
recordStartupNote(`routes: status family FAILED: ${describeError(error)}`);
|
|
39191
|
+
}
|
|
38919
39192
|
});
|
|
38920
39193
|
api = {
|
|
38921
39194
|
...core,
|