dsh-xdpool 2.7.3 → 2.7.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 +39 -0
- package/lib/client.js +209 -6
- package/lib/index.d.ts +12 -0
- package/lib/index.js +299 -66
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
本项目的所有重要变更都会记录在此文件。
|
|
3
3
|
版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
|
+
## 2.7.4 — 远程可用、只列已绑定渠道、检查更新
|
|
5
|
+
|
|
6
|
+
### 远程访问时所有按钮 403(#164)
|
|
7
|
+
|
|
8
|
+
通过 `tailscale serve`、局域网主机名或任何反向代理打开 Web UI 时,卡片**数据显示正常、所有
|
|
9
|
+
按钮报「请求失败」**。根因不是网络:插件的 `loopbackOrigin` 只认 loopback `Origin`,而浏览器
|
|
10
|
+
在非本机地址下必然发送公开主机名 —— 于是写请求全部 `403 origin-not-trusted`,而只读请求没事,
|
|
11
|
+
因为页面自己发的 GET 不带 `Origin`。
|
|
12
|
+
|
|
13
|
+
宿主其实早就放行了这些地址(`connection.trustedHosts`,宿主自己的 `/api` 桥用它),只有插件
|
|
14
|
+
还在说不。
|
|
15
|
+
|
|
16
|
+
现在按四条规则放行:
|
|
17
|
+
|
|
18
|
+
1. 没有 `Origin` —— 同源请求,页面自己发的那种
|
|
19
|
+
2. loopback `Origin` —— 默认部署
|
|
20
|
+
3. `Origin` 命中 `trustedHosts` 里的条目 —— 显式配置的服务面
|
|
21
|
+
4. `Origin` 的主机名等于请求自己的 `Host` —— 浏览器意义上的同源
|
|
22
|
+
|
|
23
|
+
第 4 条让反向代理无需配置即可工作;跨站页面伪造不了这一条,因为浏览器分别从页面和 URL 填这
|
|
24
|
+
两个头,只有页面真的由该地址提供时它们才会一致。
|
|
25
|
+
|
|
26
|
+
### 只列已绑定的渠道(#166)
|
|
27
|
+
|
|
28
|
+
首页原本把所有渠道都列出来,于是绑了一个豆包的账号池要滚过十几个「– 账号 – 模型 – 积分」的
|
|
29
|
+
空卡片才能看到它。
|
|
30
|
+
|
|
31
|
+
现在默认只列有账号的渠道,并给一个「显示全部渠道」的开关(要再加一个的时候用)。
|
|
32
|
+
**一个都没绑时仍然全部显示** —— 否则新装的用户看到的是空白页,没有任何入口添加第一个账号。
|
|
33
|
+
|
|
34
|
+
### 检查更新(#166)
|
|
35
|
+
|
|
36
|
+
升级原本要人肉去 GitHub 看,或者让 agent 定期跑任务。现在备份页顶部有「检查更新」:
|
|
37
|
+
读 npm registry 的 `dist-tags.latest`,与当前版本比较,答「有新版本 / 已是最新 / 没法检查」。
|
|
38
|
+
|
|
39
|
+
- 结果缓存 10 分钟;点按钮强制刷新
|
|
40
|
+
- **失败单独报**:告诉用户「已是最新」而实际是网络不通,是这里唯一不能给的答案
|
|
41
|
+
- 页面改名「更新与备份」 —— 两者都是偶尔做一次的维护,不是日常跑池子的一部分
|
|
42
|
+
|
|
4
43
|
## 2.7.3 — 豆包进模型选择器,开关能记住了
|
|
5
44
|
|
|
6
45
|
> 两个问题:豆包的模型在选择器里完全看不到;勾选和全开全关关掉面板就失效。
|
package/lib/client.js
CHANGED
|
@@ -112,6 +112,8 @@ window.__ModuleLoader__.load({
|
|
|
112
112
|
const POOL_ACCOUNT_IGNORE_PATH = "/plugins/dsh-xdpool/accounts/ignored";
|
|
113
113
|
/** Run one automation job immediately, so the card can verify it on demand. */
|
|
114
114
|
const POOL_AUTOMATION_RUN_PATH = "/plugins/dsh-xdpool/automation/run";
|
|
115
|
+
/** Is there a newer build of this plugin? */
|
|
116
|
+
const POOL_UPDATE_CHECK_PATH = "/plugins/dsh-xdpool/update";
|
|
115
117
|
/** Set or clear one account's reserved-credit floor. */
|
|
116
118
|
const POOL_CREDIT_RESERVE_PATH = "/plugins/dsh-xdpool/accounts/credit-reserve";
|
|
117
119
|
/**
|
|
@@ -746,6 +748,7 @@ window.__ModuleLoader__.load({
|
|
|
746
748
|
model always visible, and keeping the old names on the new shapes would
|
|
747
749
|
leave two rule sets fighting over one element. */
|
|
748
750
|
.dsm-xdpool-cpool{display:flex;flex-direction:column;gap:10px}
|
|
751
|
+
.dsm-xdpool-cpool-bar{display:flex;justify-content:flex-end;margin:0 0 8px}
|
|
749
752
|
.dsm-xdpool-cpool-grid{display:flex;flex-direction:column;gap:12px;min-width:0}
|
|
750
753
|
.dsm-xdpool-cpool-card{--dsm-xdpool-cpool-accent:var(--dsw-alias-brand-primary,#5686fe);position:relative;display:flex;flex-direction:column;gap:8px;padding:12px 13px 12px 15px;overflow:hidden;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:13px;background:color-mix(in srgb, var(--dsw-alias-bg-layer-3,#2a2c33) 80%, transparent);box-shadow:inset 0 1px 0 rgb(255 255 255 / 6%), 0 1px 2px rgb(0 0 0 / 6%);transition:transform .22s cubic-bezier(.32,.72,0,1),box-shadow .24s ease,border-color .2s ease}
|
|
751
754
|
.dsm-xdpool-cpool-card:hover{transform:translateY(-3px);border-color:color-mix(in srgb, var(--dsm-xdpool-cpool-accent,#5686fe) 55%, var(--dsw-alias-border-l2,#36373b));box-shadow:inset 0 1px 0 rgb(255 255 255 / 8%),0 18px 40px rgb(0 0 0 / 15%)}
|
|
@@ -1937,6 +1940,16 @@ window.__ModuleLoader__.load({
|
|
|
1937
1940
|
.dsm-xdpool-bak-clear:hover{background:color-mix(in srgb, var(--dsw-alias-label-primary,#e8eaf0) 12%, transparent);color:var(--dsw-alias-label-primary,#e8eaf0)}
|
|
1938
1941
|
.dsm-xdpool-bak-note{margin:0;font-size:11px;line-height:16px;color:var(--dsw-alias-state-success-primary,#22a06b)}
|
|
1939
1942
|
.dsm-xdpool-bak-error{margin:0;font-size:11px;line-height:16px;color:var(--dsw-alias-state-error-primary,#e5534b)}
|
|
1943
|
+
.dsm-xdpool-update{display:flex;flex-direction:column;gap:8px;margin:0 0 14px;padding:12px 14px;border-radius:12px;border:1px solid color-mix(in srgb, var(--dsw-alias-border-l2,#ffffff1f) 82%, transparent);background:color-mix(in srgb, var(--dsw-alias-bg-layer-2,#1c1e22) 60%, transparent)}
|
|
1944
|
+
.dsm-xdpool-update-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
|
|
1945
|
+
.dsm-xdpool-update-title{font-size:13px;font-weight:650;color:var(--dsw-alias-label-primary,#e8eaf0)}
|
|
1946
|
+
.dsm-xdpool-update-versions{font-size:11.5px;color:var(--dsw-alias-label-tertiary,#8a90a0);font-variant-numeric:tabular-nums}
|
|
1947
|
+
.dsm-xdpool-update-versions b{color:var(--dsw-alias-label-secondary,#c6c9d0);font-weight:600}
|
|
1948
|
+
.dsm-xdpool-update-sep{margin:0 5px;opacity:.6}
|
|
1949
|
+
.dsm-xdpool-update-head .dsm-xdpool-btn{margin-left:auto}
|
|
1950
|
+
.dsm-xdpool-update-current{margin:0;font-size:11.5px;line-height:17px;color:var(--dsw-alias-state-success-primary,#22a06b)}
|
|
1951
|
+
.dsm-xdpool-update-newer{margin:0;font-size:11.5px;line-height:17px;color:var(--dsw-alias-state-warning-primary,#d99a2b)}
|
|
1952
|
+
.dsm-xdpool-update-error{margin:0;font-size:11.5px;line-height:17px;color:var(--dsw-alias-state-error-primary,#e5534b)}
|
|
1940
1953
|
`;
|
|
1941
1954
|
//#endregion
|
|
1942
1955
|
//#region src/client/avatar.ts
|
|
@@ -12436,7 +12449,7 @@ window.__ModuleLoader__.load({
|
|
|
12436
12449
|
* @module dsh-xdpool/client/DoubaoAutomationPane
|
|
12437
12450
|
*/
|
|
12438
12451
|
/** A short "3 小时前" style line for the last pass. */
|
|
12439
|
-
function agoText(iso) {
|
|
12452
|
+
function agoText$1(iso) {
|
|
12440
12453
|
if (iso === void 0) return void 0;
|
|
12441
12454
|
const at = Date.parse(iso);
|
|
12442
12455
|
if (Number.isNaN(at)) return void 0;
|
|
@@ -12485,7 +12498,7 @@ window.__ModuleLoader__.load({
|
|
|
12485
12498
|
}
|
|
12486
12499
|
}, []);
|
|
12487
12500
|
const enabled = state.enabled === true;
|
|
12488
|
-
const lastRun = agoText(state.lastRunAt);
|
|
12501
|
+
const lastRun = agoText$1(state.lastRunAt);
|
|
12489
12502
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
12490
12503
|
className: "dsm-xdpool-cpool-auto",
|
|
12491
12504
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
@@ -12999,6 +13012,15 @@ window.__ModuleLoader__.load({
|
|
|
12999
13012
|
const [busy, setBusy] = (0, react.useState)(/* @__PURE__ */ new Set());
|
|
13000
13013
|
/** Channels whose model catalogue is being re-read. */
|
|
13001
13014
|
const [catalogBusy, setCatalogBusy] = (0, react.useState)(/* @__PURE__ */ new Set());
|
|
13015
|
+
/**
|
|
13016
|
+
* Whether channels without an account are listed.
|
|
13017
|
+
*
|
|
13018
|
+
* They are hidden by default: a card for a channel nobody signed into says "– accounts, –
|
|
13019
|
+
* models, – credit" and takes a full row to say it, so an account pool with one signed-in
|
|
13020
|
+
* channel scrolled past a dozen empty ones to reach it (#166). The switch brings them back for
|
|
13021
|
+
* the one case where they are wanted — adding another.
|
|
13022
|
+
*/
|
|
13023
|
+
const [showAll, setShowAll] = (0, react.useState)(false);
|
|
13002
13024
|
/** provider → what the reader typed into that card's model search box. */
|
|
13003
13025
|
const [queries, setQueries] = (0, react.useState)(/* @__PURE__ */ new Map());
|
|
13004
13026
|
const entriesRef = (0, react.useRef)(entries);
|
|
@@ -13586,9 +13608,32 @@ window.__ModuleLoader__.load({
|
|
|
13586
13608
|
className: "dsm-xdpool-note",
|
|
13587
13609
|
children: notice
|
|
13588
13610
|
}),
|
|
13611
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
13612
|
+
className: "dsm-xdpool-cpool-bar",
|
|
13613
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
13614
|
+
type: "button",
|
|
13615
|
+
className: "dsm-xdpool-btn",
|
|
13616
|
+
"aria-pressed": showAll,
|
|
13617
|
+
onClick: () => {
|
|
13618
|
+
setShowAll(!showAll);
|
|
13619
|
+
},
|
|
13620
|
+
children: showAll ? t?.("channelpool.onlyBound") ?? "只显示已绑定" : t?.("channelpool.showAll") ?? `显示全部渠道(${String(entries.length)})`
|
|
13621
|
+
})
|
|
13622
|
+
}),
|
|
13589
13623
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
13590
13624
|
className: "dsm-xdpool-cpool-grid",
|
|
13591
|
-
children: [
|
|
13625
|
+
children: [(() => {
|
|
13626
|
+
const bound = entries.filter((entry) => entry.accounts.length > 0);
|
|
13627
|
+
/**
|
|
13628
|
+
* Nothing bound yet means EVERYTHING is shown.
|
|
13629
|
+
*
|
|
13630
|
+
* Hiding empty cards is only useful once there is something to hide them behind. On a
|
|
13631
|
+
* fresh install every card is empty, so the same rule would produce a blank page with
|
|
13632
|
+
* no way to add the first account.
|
|
13633
|
+
*/
|
|
13634
|
+
if (showAll || bound.length === 0) return entries;
|
|
13635
|
+
return bound;
|
|
13636
|
+
})().map((entry) => {
|
|
13592
13637
|
const { channel, accounts, models, facts, balances, statuses, status } = entry;
|
|
13593
13638
|
const icon = channelIcon(channel.id);
|
|
13594
13639
|
const tileMark = icon === void 0 ? { initials: channelInitials(channel.name) } : { icon };
|
|
@@ -14051,6 +14096,141 @@ window.__ModuleLoader__.load({
|
|
|
14051
14096
|
});
|
|
14052
14097
|
}
|
|
14053
14098
|
//#endregion
|
|
14099
|
+
//#region src/client/UpdatePanel.tsx
|
|
14100
|
+
/**
|
|
14101
|
+
* The update check, above the backup controls.
|
|
14102
|
+
*
|
|
14103
|
+
* WHY IT SITS HERE
|
|
14104
|
+
*
|
|
14105
|
+
* "Is there a newer version" and "put this machine back how it was" are the same kind of task —
|
|
14106
|
+
* maintenance the user does occasionally, not part of running the pool. They belong on one page,
|
|
14107
|
+
* which is why the tab is now 「更新与备份」 rather than just 备份.
|
|
14108
|
+
*
|
|
14109
|
+
* WHAT IT SAYS
|
|
14110
|
+
*
|
|
14111
|
+
* Three outcomes, three sentences: newer, current, or could not check. The third is why `error`
|
|
14112
|
+
* is kept apart from "no update": telling a user they are current when the registry was
|
|
14113
|
+
* unreachable is the one wrong answer this panel could give.
|
|
14114
|
+
*
|
|
14115
|
+
* @module dsh-xdpool/client/UpdatePanel
|
|
14116
|
+
*/
|
|
14117
|
+
/** A short "3 分钟前" line for the last check. */
|
|
14118
|
+
function agoText(iso) {
|
|
14119
|
+
if (iso === void 0) return void 0;
|
|
14120
|
+
const at = Date.parse(iso);
|
|
14121
|
+
if (Number.isNaN(at)) return void 0;
|
|
14122
|
+
const minutes = Math.floor((Date.now() - at) / 6e4);
|
|
14123
|
+
if (minutes < 1) return "刚刚";
|
|
14124
|
+
if (minutes < 60) return `${String(minutes)} 分钟前`;
|
|
14125
|
+
const hours = Math.floor(minutes / 60);
|
|
14126
|
+
if (hours < 24) return `${String(hours)} 小时前`;
|
|
14127
|
+
return `${String(Math.floor(hours / 24))} 天前`;
|
|
14128
|
+
}
|
|
14129
|
+
/** The published date, as a plain day. */
|
|
14130
|
+
function dayText(iso) {
|
|
14131
|
+
if (iso === void 0) return void 0;
|
|
14132
|
+
const at = Date.parse(iso);
|
|
14133
|
+
if (Number.isNaN(at)) return void 0;
|
|
14134
|
+
return new Date(at).toISOString().slice(0, 10);
|
|
14135
|
+
}
|
|
14136
|
+
function UpdatePanel({ t }) {
|
|
14137
|
+
const [status, setStatus] = (0, react.useState)(void 0);
|
|
14138
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
14139
|
+
const mounted = (0, react.useRef)(true);
|
|
14140
|
+
(0, react.useEffect)(() => {
|
|
14141
|
+
mounted.current = true;
|
|
14142
|
+
return () => {
|
|
14143
|
+
mounted.current = false;
|
|
14144
|
+
};
|
|
14145
|
+
}, []);
|
|
14146
|
+
const check = (0, react.useCallback)(async (force) => {
|
|
14147
|
+
setBusy(true);
|
|
14148
|
+
try {
|
|
14149
|
+
const body = await (await fetch(POOL_UPDATE_CHECK_PATH, {
|
|
14150
|
+
method: force ? "POST" : "GET",
|
|
14151
|
+
credentials: "same-origin"
|
|
14152
|
+
})).json().catch(() => void 0);
|
|
14153
|
+
if (!mounted.current || body === void 0) return;
|
|
14154
|
+
setStatus(body);
|
|
14155
|
+
} catch {
|
|
14156
|
+
if (!mounted.current) return;
|
|
14157
|
+
setStatus({
|
|
14158
|
+
error: "无法连接插件(请确认页面已连上宿主)",
|
|
14159
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
14160
|
+
});
|
|
14161
|
+
} finally {
|
|
14162
|
+
if (mounted.current) setBusy(false);
|
|
14163
|
+
}
|
|
14164
|
+
}, []);
|
|
14165
|
+
(0, react.useEffect)(() => {
|
|
14166
|
+
check(false);
|
|
14167
|
+
}, [check]);
|
|
14168
|
+
const newer = status?.newer === true;
|
|
14169
|
+
const checked = agoText(status?.checkedAt);
|
|
14170
|
+
const published = dayText(status?.publishedAt);
|
|
14171
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
14172
|
+
className: "dsm-xdpool-update",
|
|
14173
|
+
children: [
|
|
14174
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
14175
|
+
className: "dsm-xdpool-update-head",
|
|
14176
|
+
children: [
|
|
14177
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
14178
|
+
className: "dsm-xdpool-update-title",
|
|
14179
|
+
children: t?.("update.title") ?? "检查更新"
|
|
14180
|
+
}),
|
|
14181
|
+
status?.current === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
14182
|
+
className: "dsm-xdpool-update-versions",
|
|
14183
|
+
children: [
|
|
14184
|
+
t?.("update.current") ?? "当前",
|
|
14185
|
+
" ",
|
|
14186
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: status.current }),
|
|
14187
|
+
status.latest === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
14188
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
14189
|
+
className: "dsm-xdpool-update-sep",
|
|
14190
|
+
"aria-hidden": "true",
|
|
14191
|
+
children: "·"
|
|
14192
|
+
}),
|
|
14193
|
+
t?.("update.latest") ?? "最新",
|
|
14194
|
+
" ",
|
|
14195
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: status.latest })
|
|
14196
|
+
] })
|
|
14197
|
+
]
|
|
14198
|
+
}),
|
|
14199
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
14200
|
+
type: "button",
|
|
14201
|
+
className: "dsm-xdpool-btn",
|
|
14202
|
+
disabled: busy,
|
|
14203
|
+
onClick: () => {
|
|
14204
|
+
check(true);
|
|
14205
|
+
},
|
|
14206
|
+
children: busy ? t?.("update.checking") ?? "检查中…" : t?.("update.check") ?? "检查更新"
|
|
14207
|
+
})
|
|
14208
|
+
]
|
|
14209
|
+
}),
|
|
14210
|
+
status?.error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
14211
|
+
className: "dsm-xdpool-update-error",
|
|
14212
|
+
children: [
|
|
14213
|
+
t?.("update.failed") ?? "没能检查更新",
|
|
14214
|
+
":",
|
|
14215
|
+
status.error
|
|
14216
|
+
]
|
|
14217
|
+
}),
|
|
14218
|
+
status?.error !== void 0 || status === void 0 ? null : newer ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
14219
|
+
className: "dsm-xdpool-update-newer",
|
|
14220
|
+
children: [
|
|
14221
|
+
t?.("update.available", { version: status.latest ?? "" }) ?? `有新版本 ${status.latest ?? ""}`,
|
|
14222
|
+
published === void 0 ? "" : `(发布于 ${published})`,
|
|
14223
|
+
". ",
|
|
14224
|
+
t?.("update.howTo") ?? "在 DSH 的插件设置里把它更新到该版本即可;数据与账号不受影响。"
|
|
14225
|
+
]
|
|
14226
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
14227
|
+
className: "dsm-xdpool-update-current",
|
|
14228
|
+
children: [t?.("update.upToDate") ?? "已是最新版本", checked === void 0 ? "" : `(${checked}检查)`]
|
|
14229
|
+
})
|
|
14230
|
+
]
|
|
14231
|
+
});
|
|
14232
|
+
}
|
|
14233
|
+
//#endregion
|
|
14054
14234
|
//#region src/client/backup-crypto.ts
|
|
14055
14235
|
/**
|
|
14056
14236
|
* Password-encrypted backup envelope for the credential export.
|
|
@@ -14369,6 +14549,7 @@ window.__ModuleLoader__.load({
|
|
|
14369
14549
|
className: "dsm-xdpool-bak",
|
|
14370
14550
|
children: [
|
|
14371
14551
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: BACKUP_CSS }),
|
|
14552
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(UpdatePanel, { t }),
|
|
14372
14553
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
14373
14554
|
className: "dsm-xdpool-bak-head",
|
|
14374
14555
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -14477,7 +14658,7 @@ window.__ModuleLoader__.load({
|
|
|
14477
14658
|
*
|
|
14478
14659
|
* @module dsh-xdpool/version
|
|
14479
14660
|
*/
|
|
14480
|
-
const POOL_VERSION = "2.7.
|
|
14661
|
+
const POOL_VERSION = "2.7.4";
|
|
14481
14662
|
//#endregion
|
|
14482
14663
|
//#region src/client/PoolCard.tsx
|
|
14483
14664
|
/**
|
|
@@ -17591,6 +17772,17 @@ window.__ModuleLoader__.load({
|
|
|
17591
17772
|
* @module dsh-xdpool/client/locales
|
|
17592
17773
|
*/
|
|
17593
17774
|
const en = {
|
|
17775
|
+
"update.title": "Check for updates",
|
|
17776
|
+
"update.current": "current",
|
|
17777
|
+
"update.latest": "latest",
|
|
17778
|
+
"update.check": "Check",
|
|
17779
|
+
"update.checking": "Checking…",
|
|
17780
|
+
"update.upToDate": "Up to date",
|
|
17781
|
+
"update.available": "Version {version} is available",
|
|
17782
|
+
"update.howTo": "Update it from the plugin settings; your data and accounts are unaffected.",
|
|
17783
|
+
"update.failed": "Could not check",
|
|
17784
|
+
"channelpool.showAll": "Show all channels",
|
|
17785
|
+
"channelpool.onlyBound": "Show bound only",
|
|
17594
17786
|
"channelpool.reloadModels": "Reload models",
|
|
17595
17787
|
"channelpool.reloadModelsBusy": "Reading…",
|
|
17596
17788
|
"channelpool.reloadModelsHint": "Read the model list (and multipliers) from the vendor again",
|
|
@@ -17982,7 +18174,7 @@ window.__ModuleLoader__.load({
|
|
|
17982
18174
|
"shell.subRouting": "Chains that try models in order, so one busy or rate-limited model falls through to the next.",
|
|
17983
18175
|
"shell.tabGateway": "Gateway",
|
|
17984
18176
|
"shell.tabDoubao": "Doubao",
|
|
17985
|
-
"shell.tabBackup": "
|
|
18177
|
+
"shell.tabBackup": "Updates & backup",
|
|
17986
18178
|
"shell.subGateway": "Open the pool to the other devices on your network.",
|
|
17987
18179
|
"gw.title": "Gateway",
|
|
17988
18180
|
"gw.sub": "An OpenAI-compatible endpoint other devices on your network can point at. Off until you turn it on, and bound to this computer only until you say otherwise.",
|
|
@@ -18207,6 +18399,17 @@ window.__ModuleLoader__.load({
|
|
|
18207
18399
|
"channelpool.note": "Note"
|
|
18208
18400
|
};
|
|
18209
18401
|
const zh = {
|
|
18402
|
+
"update.title": "检查更新",
|
|
18403
|
+
"update.current": "当前",
|
|
18404
|
+
"update.latest": "最新",
|
|
18405
|
+
"update.check": "检查更新",
|
|
18406
|
+
"update.checking": "检查中…",
|
|
18407
|
+
"update.upToDate": "已是最新版本",
|
|
18408
|
+
"update.available": "有新版本 {version}",
|
|
18409
|
+
"update.howTo": "在插件设置里更新到该版本即可;数据和账号不受影响。",
|
|
18410
|
+
"update.failed": "没能检查更新",
|
|
18411
|
+
"channelpool.showAll": "显示全部渠道",
|
|
18412
|
+
"channelpool.onlyBound": "只显示已绑定",
|
|
18210
18413
|
"channelpool.reloadModels": "重新加载模型",
|
|
18211
18414
|
"channelpool.reloadModelsBusy": "正在读取…",
|
|
18212
18415
|
"channelpool.reloadModelsHint": "从上游重新读取这个渠道的模型列表(含倍率)",
|
|
@@ -18598,7 +18801,7 @@ window.__ModuleLoader__.load({
|
|
|
18598
18801
|
"shell.subRouting": "把几个模型串成一条链,按顺序试;一个忙了或被限流,就自动落到下一个。",
|
|
18599
18802
|
"shell.tabGateway": "网关",
|
|
18600
18803
|
"shell.tabDoubao": "豆包",
|
|
18601
|
-
"shell.tabBackup": "
|
|
18804
|
+
"shell.tabBackup": "更新与备份",
|
|
18602
18805
|
"shell.subGateway": "把账号池开放给同网络里的其它设备。",
|
|
18603
18806
|
"gw.title": "网关",
|
|
18604
18807
|
"gw.sub": "开一个 OpenAI 兼容的入口,同网络的其它设备可以指过来。默认关闭,默认只绑定本机 —— 你不改,它就一直只在你这台电脑上。",
|
package/lib/index.d.ts
CHANGED
|
@@ -4340,10 +4340,22 @@ export declare function readPreferredIdSync(path?: string): string | undefined;
|
|
|
4340
4340
|
*/
|
|
4341
4341
|
export declare function writePreferredId(accountId: string | undefined, path?: string): Promise<void>;
|
|
4342
4342
|
//#endregion
|
|
4343
|
+
//#region src/origin-trust.d.ts
|
|
4344
|
+
/** The authorities a deployment says it serves, as the host reports them. */
|
|
4345
|
+
type TrustedHosts = readonly string[];
|
|
4346
|
+
//#endregion
|
|
4343
4347
|
//#region src/web-status.d.ts
|
|
4344
4348
|
/** Constructor dependencies — a narrow slice of the pool runtime. */
|
|
4345
4349
|
interface PoolStatusRouteOptions {
|
|
4346
4350
|
pool: WorkBuddyAccountPool;
|
|
4351
|
+
/**
|
|
4352
|
+
* The authorities this deployment serves, read per request.
|
|
4353
|
+
*
|
|
4354
|
+
* Passed through from `connection.trustedHosts` so the plugin's gate agrees with the host's
|
|
4355
|
+
* own `/api` bridge. They disagreed once, and the symptom was a card that displayed its data
|
|
4356
|
+
* and refused every button — see `origin-trust.ts`.
|
|
4357
|
+
*/
|
|
4358
|
+
trustedHosts?: () => TrustedHosts;
|
|
4347
4359
|
/** One catalog per region; the card reads the one for its active tab. */
|
|
4348
4360
|
catalogs: Readonly<Record<PoolRegion, WorkBuddyCatalog>>;
|
|
4349
4361
|
client: WorkBuddyUpstreamClient;
|
package/lib/index.js
CHANGED
|
@@ -998,7 +998,7 @@ const BRIEF_LIST_ENDPOINT = "https://www.doubao.com/alice/slot/action_bar_v3/bri
|
|
|
998
998
|
/** The bot whose roster is being asked for — the default Doubao assistant. */
|
|
999
999
|
const BOT_ID = "7338286299411103781";
|
|
1000
1000
|
/** How long a live listing is reused. */
|
|
1001
|
-
const TTL_MS = 6e5;
|
|
1001
|
+
const TTL_MS$1 = 6e5;
|
|
1002
1002
|
/** The query the endpoint expects. */
|
|
1003
1003
|
const CLIENT_PARAMS$2 = {
|
|
1004
1004
|
aid: "497858",
|
|
@@ -1018,7 +1018,7 @@ const CLIENT_PARAMS$2 = {
|
|
|
1018
1018
|
samantha_web: "1",
|
|
1019
1019
|
"use-olympus-account": "1"
|
|
1020
1020
|
};
|
|
1021
|
-
let cached$
|
|
1021
|
+
let cached$2;
|
|
1022
1022
|
/**
|
|
1023
1023
|
* Read the roster from the account.
|
|
1024
1024
|
*
|
|
@@ -1026,7 +1026,7 @@ let cached$1;
|
|
|
1026
1026
|
*/
|
|
1027
1027
|
async function fetchLiveModels(session, options = {}) {
|
|
1028
1028
|
const now = options.now ?? Date.now();
|
|
1029
|
-
if (options.force !== true && cached$
|
|
1029
|
+
if (options.force !== true && cached$2 !== void 0 && now - cached$2.at < TTL_MS$1) return cached$2.models;
|
|
1030
1030
|
if (session === void 0 || !sessionUsable(session)) return DOUBAO_MODELS;
|
|
1031
1031
|
const params = new URLSearchParams({
|
|
1032
1032
|
...CLIENT_PARAMS$2,
|
|
@@ -1086,7 +1086,7 @@ async function fetchLiveModels(session, options = {}) {
|
|
|
1086
1086
|
byId.set(model.id, model);
|
|
1087
1087
|
}
|
|
1088
1088
|
const models = [...byId.values()];
|
|
1089
|
-
cached$
|
|
1089
|
+
cached$2 = {
|
|
1090
1090
|
at: now,
|
|
1091
1091
|
models
|
|
1092
1092
|
};
|
|
@@ -2466,6 +2466,77 @@ function createDoubaoLlm(options) {
|
|
|
2466
2466
|
};
|
|
2467
2467
|
}
|
|
2468
2468
|
//#endregion
|
|
2469
|
+
//#region src/origin-trust.ts
|
|
2470
|
+
/** Whether a hostname is the local machine. */
|
|
2471
|
+
function isLoopback(hostname) {
|
|
2472
|
+
const bare = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
|
|
2473
|
+
return bare === "localhost" || bare === "127.0.0.1" || bare === "::1" || bare.startsWith("127.");
|
|
2474
|
+
}
|
|
2475
|
+
/**
|
|
2476
|
+
* A `trustedHosts` entry and an origin, compared the way the host compares them.
|
|
2477
|
+
*
|
|
2478
|
+
* An entry WITH a port matches exactly; a port-less entry matches the hostname on any port. The
|
|
2479
|
+
* host's own `isTrustedAuthority` works this way, and agreeing with it matters more than picking
|
|
2480
|
+
* a rule of our own — two components disagreeing about trust is how this defect happened.
|
|
2481
|
+
*/
|
|
2482
|
+
function matchesTrusted(origin, trusted) {
|
|
2483
|
+
for (const entry of trusted) {
|
|
2484
|
+
if (typeof entry !== "string" || entry.trim() === "") continue;
|
|
2485
|
+
const wanted = entry.trim().toLowerCase();
|
|
2486
|
+
if (/:\d+$/u.test(wanted)) {
|
|
2487
|
+
if (origin.host.toLowerCase() === wanted) return true;
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
if (origin.hostname.toLowerCase() === wanted) return true;
|
|
2491
|
+
}
|
|
2492
|
+
return false;
|
|
2493
|
+
}
|
|
2494
|
+
/** The `Host` header's hostname, or undefined when it is absent or unparseable. */
|
|
2495
|
+
function hostHeaderName(req) {
|
|
2496
|
+
const host = req.headers.host;
|
|
2497
|
+
if (typeof host !== "string" || host === "") return void 0;
|
|
2498
|
+
try {
|
|
2499
|
+
return new URL(`http://${host}`).hostname.toLowerCase();
|
|
2500
|
+
} catch {
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Decide whether `req` may act.
|
|
2506
|
+
*
|
|
2507
|
+
* `trusted` is read fresh on each call so a configuration change reaches the next request
|
|
2508
|
+
* without a plugin restart — the host's own bridge does the same.
|
|
2509
|
+
*/
|
|
2510
|
+
function originTrusted(req, trusted = []) {
|
|
2511
|
+
const origin = req.headers.origin;
|
|
2512
|
+
/**
|
|
2513
|
+
* No `Origin` at all.
|
|
2514
|
+
*
|
|
2515
|
+
* A same-origin `fetch()` in Chromium omits it for GET/HEAD, and the card's own reads are
|
|
2516
|
+
* exactly that. Refusing this would break the page on the machine it was installed on.
|
|
2517
|
+
*/
|
|
2518
|
+
if (typeof origin !== "string" || origin === "") return true;
|
|
2519
|
+
let url;
|
|
2520
|
+
try {
|
|
2521
|
+
url = new URL(origin);
|
|
2522
|
+
} catch {
|
|
2523
|
+
return false;
|
|
2524
|
+
}
|
|
2525
|
+
if (isLoopback(url.hostname)) return true;
|
|
2526
|
+
if (matchesTrusted(url, trusted)) return true;
|
|
2527
|
+
/**
|
|
2528
|
+
* Same-origin, judged by the browser's own two headers.
|
|
2529
|
+
*
|
|
2530
|
+
* This is the case a reverse proxy produces: the page is served from
|
|
2531
|
+
* `https://node.tailXXXX.ts.net`, so that is what `Origin` says, and the request arrives at a
|
|
2532
|
+
* plugin route on that same authority — so `Host` says the same thing. A malicious page on
|
|
2533
|
+
* another site cannot make these agree.
|
|
2534
|
+
*/
|
|
2535
|
+
const host = hostHeaderName(req);
|
|
2536
|
+
if (host !== void 0 && url.hostname.toLowerCase() === host) return true;
|
|
2537
|
+
return false;
|
|
2538
|
+
}
|
|
2539
|
+
//#endregion
|
|
2469
2540
|
//#region src/status-paths.ts
|
|
2470
2541
|
/**
|
|
2471
2542
|
* Node-free constants and types shared by the Host and browser halves of the
|
|
@@ -2510,6 +2581,8 @@ const POOL_ACCOUNT_DISABLE_PATH = "/plugins/dsh-xdpool/accounts/disabled";
|
|
|
2510
2581
|
const POOL_ACCOUNT_IGNORE_PATH = "/plugins/dsh-xdpool/accounts/ignored";
|
|
2511
2582
|
/** Run one automation job immediately, so the card can verify it on demand. */
|
|
2512
2583
|
const POOL_AUTOMATION_RUN_PATH = "/plugins/dsh-xdpool/automation/run";
|
|
2584
|
+
/** Is there a newer build of this plugin? */
|
|
2585
|
+
const POOL_UPDATE_CHECK_PATH = "/plugins/dsh-xdpool/update";
|
|
2513
2586
|
/** Set or clear one account's reserved-credit floor. */
|
|
2514
2587
|
const POOL_CREDIT_RESERVE_PATH = "/plugins/dsh-xdpool/accounts/credit-reserve";
|
|
2515
2588
|
/**
|
|
@@ -3115,7 +3188,7 @@ function evaluateQuotaExhausted(data) {
|
|
|
3115
3188
|
}
|
|
3116
3189
|
async function fetchQuota(options = {}) {
|
|
3117
3190
|
const now = Date.now();
|
|
3118
|
-
if (!options.force && cached && now - cached.fetchedAt < 3e5) return cached;
|
|
3191
|
+
if (!options.force && cached$1 && now - cached$1.fetchedAt < 3e5) return cached$1;
|
|
3119
3192
|
if (!options.force && cachedFailure !== void 0 && now - cachedFailureAt < QUOTA_FAILURE_TTL_MS) return cachedFailure;
|
|
3120
3193
|
/**
|
|
3121
3194
|
* No session is a quotable answer, not a throw.
|
|
@@ -3162,7 +3235,7 @@ async function fetchQuota(options = {}) {
|
|
|
3162
3235
|
const plan = payload.data?.current_subscription?.display?.short_name;
|
|
3163
3236
|
if (plan) quota.plan = plan;
|
|
3164
3237
|
if (payload.data?.member_info?.hasActiveSubscription !== void 0) quota.planActive = payload.data.member_info.hasActiveSubscription;
|
|
3165
|
-
cached = quota;
|
|
3238
|
+
cached$1 = quota;
|
|
3166
3239
|
cachedFailure = void 0;
|
|
3167
3240
|
return quota;
|
|
3168
3241
|
} catch (error) {
|
|
@@ -3174,7 +3247,7 @@ async function fetchQuota(options = {}) {
|
|
|
3174
3247
|
});
|
|
3175
3248
|
}
|
|
3176
3249
|
}
|
|
3177
|
-
let cached;
|
|
3250
|
+
let cached$1;
|
|
3178
3251
|
/** The last FAILED reading, reused for {@link QUOTA_FAILURE_TTL_MS}. */
|
|
3179
3252
|
let cachedFailure;
|
|
3180
3253
|
let cachedFailureAt = 0;
|
|
@@ -3198,25 +3271,6 @@ function json$1(res, status, body) {
|
|
|
3198
3271
|
res.end(JSON.stringify(body));
|
|
3199
3272
|
}
|
|
3200
3273
|
/**
|
|
3201
|
-
* Whether the request came from the host's own page.
|
|
3202
|
-
*
|
|
3203
|
-
* An ABSENT `Origin` is allowed and is the common case: only cross-origin requests carry the
|
|
3204
|
-
* header, so a same-origin request from the card sends none. Requiring it refused every call
|
|
3205
|
-
* the UI made — the paste arrived, was rejected `403` before any parsing ran, and the card
|
|
3206
|
-
* reported it as a bad cookie. A page in the user's browser driving this endpoint is
|
|
3207
|
-
* cross-origin by construction and always sends `Origin`, so the hostname check covers it.
|
|
3208
|
-
*/
|
|
3209
|
-
function loopbackOrigin$1(req) {
|
|
3210
|
-
const origin = req.headers.origin;
|
|
3211
|
-
if (typeof origin !== "string" || origin === "") return true;
|
|
3212
|
-
try {
|
|
3213
|
-
const url = new URL(origin);
|
|
3214
|
-
return url.hostname === "127.0.0.1" || url.hostname === "localhost" || url.hostname === "::1";
|
|
3215
|
-
} catch {
|
|
3216
|
-
return false;
|
|
3217
|
-
}
|
|
3218
|
-
}
|
|
3219
|
-
/**
|
|
3220
3274
|
* Mount the Doubao routes.
|
|
3221
3275
|
*
|
|
3222
3276
|
* The sign-in route answers `signedIn: false` rather than an error when the user closes the
|
|
@@ -3228,7 +3282,7 @@ function registerDoubaoRoutes(ctx, deps) {
|
|
|
3228
3282
|
kind: "exact",
|
|
3229
3283
|
path: POOL_DOUBAO_SESSION_PATH,
|
|
3230
3284
|
handler: async (req, res) => {
|
|
3231
|
-
if (!
|
|
3285
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json$1(res, 403, { error: "origin-not-trusted" });
|
|
3232
3286
|
try {
|
|
3233
3287
|
if (req.method === "DELETE") {
|
|
3234
3288
|
deps.clear();
|
|
@@ -3305,7 +3359,7 @@ function registerDoubaoRoutes(ctx, deps) {
|
|
|
3305
3359
|
path: POOL_DOUBAO_QUOTA_PATH,
|
|
3306
3360
|
handler: async (req, res) => {
|
|
3307
3361
|
if (req.method !== "GET") return json$1(res, 405, { error: "method not allowed" });
|
|
3308
|
-
if (!
|
|
3362
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json$1(res, 403, { error: "origin-not-trusted" });
|
|
3309
3363
|
const session = deps.session();
|
|
3310
3364
|
if (session === void 0 || !sessionUsable(session)) return json$1(res, 200, {
|
|
3311
3365
|
ok: false,
|
|
@@ -3337,7 +3391,7 @@ function registerDoubaoRoutes(ctx, deps) {
|
|
|
3337
3391
|
path: POOL_DOUBAO_MODELS_PATH,
|
|
3338
3392
|
handler: async (req, res) => {
|
|
3339
3393
|
if (req.method !== "GET") return json$1(res, 405, { error: "method not allowed" });
|
|
3340
|
-
if (!
|
|
3394
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json$1(res, 403, { error: "origin-not-trusted" });
|
|
3341
3395
|
/**
|
|
3342
3396
|
* The same list the picker gets.
|
|
3343
3397
|
*
|
|
@@ -3364,7 +3418,7 @@ function registerDoubaoRoutes(ctx, deps) {
|
|
|
3364
3418
|
path: POOL_DOUBAO_CAMPAIGN_PATH,
|
|
3365
3419
|
handler: async (req, res) => {
|
|
3366
3420
|
if (req.method !== "GET") return json$1(res, 405, { error: "method not allowed" });
|
|
3367
|
-
if (!
|
|
3421
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json$1(res, 403, { error: "origin-not-trusted" });
|
|
3368
3422
|
const session = deps.session();
|
|
3369
3423
|
const campaign = await fetchCampaign(session);
|
|
3370
3424
|
return json$1(res, 200, {
|
|
@@ -3379,7 +3433,7 @@ function registerDoubaoRoutes(ctx, deps) {
|
|
|
3379
3433
|
path: POOL_DOUBAO_CLAIM_PATH,
|
|
3380
3434
|
handler: async (req, res) => {
|
|
3381
3435
|
if (req.method !== "POST") return json$1(res, 405, { error: "method not allowed" });
|
|
3382
|
-
if (!
|
|
3436
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json$1(res, 403, { error: "origin-not-trusted" });
|
|
3383
3437
|
const result = await claimTasks(deps.session());
|
|
3384
3438
|
return json$1(res, 200, {
|
|
3385
3439
|
ok: result.failed === 0,
|
|
@@ -3391,7 +3445,7 @@ function registerDoubaoRoutes(ctx, deps) {
|
|
|
3391
3445
|
kind: "exact",
|
|
3392
3446
|
path: POOL_DOUBAO_AUTOMATION_PATH,
|
|
3393
3447
|
handler: async (req, res) => {
|
|
3394
|
-
if (!
|
|
3448
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json$1(res, 403, { error: "origin-not-trusted" });
|
|
3395
3449
|
const automation = deps.automation();
|
|
3396
3450
|
try {
|
|
3397
3451
|
if (req.method === "POST") {
|
|
@@ -19664,6 +19718,149 @@ function parseBody(body) {
|
|
|
19664
19718
|
throw new Error("the request body was not a JSON object");
|
|
19665
19719
|
}
|
|
19666
19720
|
//#endregion
|
|
19721
|
+
//#region src/version.ts
|
|
19722
|
+
/**
|
|
19723
|
+
* The plugin's own version, hand-maintained for the browser bundle.
|
|
19724
|
+
*
|
|
19725
|
+
* The card ships as `lib/client.js`, served to the host dialog as a browser
|
|
19726
|
+
* script: `package.json` is neither reachable nor guaranteed to be the file
|
|
19727
|
+
* the running build came from. A manifest lying next to the code is worse than
|
|
19728
|
+
* a number a test keeps honest.
|
|
19729
|
+
*
|
|
19730
|
+
* `tests/version-sync.test.ts` fails when this drifts from `package.json`, so
|
|
19731
|
+
* the release checklist cannot ship a card that calls itself the wrong version.
|
|
19732
|
+
*
|
|
19733
|
+
* @module dsh-xdpool/version
|
|
19734
|
+
*/
|
|
19735
|
+
const POOL_VERSION = "2.7.4";
|
|
19736
|
+
//#endregion
|
|
19737
|
+
//#region src/update-check.ts
|
|
19738
|
+
/**
|
|
19739
|
+
* Whether a newer build of this plugin exists.
|
|
19740
|
+
*
|
|
19741
|
+
* WHY IT LIVES IN THE PLUGIN
|
|
19742
|
+
*
|
|
19743
|
+
* Updating meant watching the repository by hand or asking an agent to check — neither is
|
|
19744
|
+
* something a user should have to do to stay current. A version read from the registry on demand
|
|
19745
|
+
* answers the only question worth asking ("is there something newer than what I run?") without a
|
|
19746
|
+
* background task that phones home on its own schedule.
|
|
19747
|
+
*
|
|
19748
|
+
* WHAT IT ASKS
|
|
19749
|
+
*
|
|
19750
|
+
* The npm registry's abbreviated document for this package: `dist-tags.latest` and the publish
|
|
19751
|
+
* time of that version. Nothing else is read, nothing is sent beyond the package name, and the
|
|
19752
|
+
* answer is cached for a few minutes so opening the panel repeatedly is one request.
|
|
19753
|
+
*
|
|
19754
|
+
* A FAILURE IS AN ORDINARY ANSWER
|
|
19755
|
+
*
|
|
19756
|
+
* A machine behind a proxy, offline, or with no registry access still has a working plugin. The
|
|
19757
|
+
* result carries `error` and the card says "could not check" rather than hiding the control or
|
|
19758
|
+
* claiming there is nothing new — telling a user they are current when the check did not run is
|
|
19759
|
+
* the one wrong answer here.
|
|
19760
|
+
*
|
|
19761
|
+
* @module dsh-xdpool/update-check
|
|
19762
|
+
*/
|
|
19763
|
+
/** The package name this plugin publishes under. */
|
|
19764
|
+
const PACKAGE = "dsh-xdpool";
|
|
19765
|
+
/** The registries tried, in order. npm first: it is the canonical one. */
|
|
19766
|
+
const REGISTRIES = [`https://registry.npmjs.org/${PACKAGE}/latest`, `https://registry.npmjs.org/${PACKAGE}`];
|
|
19767
|
+
/** How long an answer is reused. */
|
|
19768
|
+
const TTL_MS = 6e5;
|
|
19769
|
+
let cached;
|
|
19770
|
+
/**
|
|
19771
|
+
* Compare two dotted versions.
|
|
19772
|
+
*
|
|
19773
|
+
* Numeric segments compare as numbers and everything else as text, which is the ordering npm
|
|
19774
|
+
* itself uses for the plain `x.y.z` releases this package publishes. A prerelease tag is older
|
|
19775
|
+
* than its release (`2.7.3-rc.1 < 2.7.3`), which is what the `-` check below states.
|
|
19776
|
+
*/
|
|
19777
|
+
function compareVersions(left, right) {
|
|
19778
|
+
const parse = (value) => {
|
|
19779
|
+
const [core, ...rest] = value.trim().replace(/^v/u, "").split("-");
|
|
19780
|
+
return {
|
|
19781
|
+
parts: (core ?? "").split(".").map((segment) => {
|
|
19782
|
+
const number = Number.parseInt(segment, 10);
|
|
19783
|
+
return Number.isFinite(number) ? number : 0;
|
|
19784
|
+
}),
|
|
19785
|
+
pre: rest.join("-")
|
|
19786
|
+
};
|
|
19787
|
+
};
|
|
19788
|
+
const a = parse(left);
|
|
19789
|
+
const b = parse(right);
|
|
19790
|
+
const length = Math.max(a.parts.length, b.parts.length);
|
|
19791
|
+
for (let i = 0; i < length; i += 1) {
|
|
19792
|
+
const left1 = a.parts[i] ?? 0;
|
|
19793
|
+
const right1 = b.parts[i] ?? 0;
|
|
19794
|
+
if (left1 !== right1) return left1 < right1 ? -1 : 1;
|
|
19795
|
+
}
|
|
19796
|
+
if (a.pre === "" && b.pre !== "") return 1;
|
|
19797
|
+
if (a.pre !== "" && b.pre === "") return -1;
|
|
19798
|
+
return a.pre === b.pre ? 0 : a.pre < b.pre ? -1 : 1;
|
|
19799
|
+
}
|
|
19800
|
+
/** Read `dist-tags.latest` and its publish time from a registry document. */
|
|
19801
|
+
function parseRegistry(body) {
|
|
19802
|
+
if (body === null || typeof body !== "object") return {};
|
|
19803
|
+
const record = body;
|
|
19804
|
+
const direct = record["version"];
|
|
19805
|
+
if (typeof direct === "string" && direct !== "") return { latest: direct };
|
|
19806
|
+
const tags = record["dist-tags"];
|
|
19807
|
+
if (tags !== null && typeof tags === "object") {
|
|
19808
|
+
const latest = tags["latest"];
|
|
19809
|
+
if (typeof latest === "string" && latest !== "") {
|
|
19810
|
+
const times = record["time"];
|
|
19811
|
+
const when = times !== null && typeof times === "object" ? times[latest] : void 0;
|
|
19812
|
+
return {
|
|
19813
|
+
latest,
|
|
19814
|
+
...typeof when === "string" ? { publishedAt: when } : {}
|
|
19815
|
+
};
|
|
19816
|
+
}
|
|
19817
|
+
}
|
|
19818
|
+
return {};
|
|
19819
|
+
}
|
|
19820
|
+
/**
|
|
19821
|
+
* Ask the registry, or answer from the cache.
|
|
19822
|
+
*
|
|
19823
|
+
* `force` skips the cache — that is what the card's button does, and a button that silently
|
|
19824
|
+
* returns a ten-minute-old answer is indistinguishable from one that did nothing.
|
|
19825
|
+
*/
|
|
19826
|
+
async function checkForUpdate(options = {}) {
|
|
19827
|
+
const now = options.now ?? Date.now();
|
|
19828
|
+
if (options.force !== true && cached !== void 0 && now - cached.at < TTL_MS) return cached.status;
|
|
19829
|
+
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
19830
|
+
for (const url of REGISTRIES) try {
|
|
19831
|
+
const response = await fetch(url, {
|
|
19832
|
+
headers: { accept: "application/vnd.npm.install-v1+json, application/json" },
|
|
19833
|
+
signal: AbortSignal.timeout(8e3)
|
|
19834
|
+
});
|
|
19835
|
+
if (!response.ok) continue;
|
|
19836
|
+
const parsed = parseRegistry(await response.json());
|
|
19837
|
+
if (parsed.latest === void 0) continue;
|
|
19838
|
+
const status = {
|
|
19839
|
+
current: POOL_VERSION,
|
|
19840
|
+
latest: parsed.latest,
|
|
19841
|
+
newer: compareVersions(parsed.latest, POOL_VERSION) > 0,
|
|
19842
|
+
...parsed.publishedAt === void 0 ? {} : { publishedAt: parsed.publishedAt },
|
|
19843
|
+
checkedAt
|
|
19844
|
+
};
|
|
19845
|
+
cached = {
|
|
19846
|
+
at: now,
|
|
19847
|
+
status
|
|
19848
|
+
};
|
|
19849
|
+
return status;
|
|
19850
|
+
} catch {}
|
|
19851
|
+
const status = {
|
|
19852
|
+
current: POOL_VERSION,
|
|
19853
|
+
newer: false,
|
|
19854
|
+
error: "无法访问 npm registry(离线或代理未放行)",
|
|
19855
|
+
checkedAt
|
|
19856
|
+
};
|
|
19857
|
+
cached = {
|
|
19858
|
+
at: now - TTL_MS + 6e4,
|
|
19859
|
+
status
|
|
19860
|
+
};
|
|
19861
|
+
return status;
|
|
19862
|
+
}
|
|
19863
|
+
//#endregion
|
|
19667
19864
|
//#region src/task-events.ts
|
|
19668
19865
|
/**
|
|
19669
19866
|
* The app the buddy chain enters.
|
|
@@ -21487,17 +21684,6 @@ function json(res, status, body) {
|
|
|
21487
21684
|
});
|
|
21488
21685
|
res.end(payload);
|
|
21489
21686
|
}
|
|
21490
|
-
/** Loopback browser origins only; other devices are refused. */
|
|
21491
|
-
function loopbackOrigin(req) {
|
|
21492
|
-
const origin = req.headers.origin;
|
|
21493
|
-
if (origin === void 0) return true;
|
|
21494
|
-
try {
|
|
21495
|
-
const { hostname } = new URL(origin);
|
|
21496
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
21497
|
-
} catch {
|
|
21498
|
-
return false;
|
|
21499
|
-
}
|
|
21500
|
-
}
|
|
21501
21687
|
/** Smallest possible POST body reader, capped so a hung or oversized body
|
|
21502
21688
|
* cannot pin memory on the Host. Returns `{}` for an empty body. */
|
|
21503
21689
|
function readJsonBody(req) {
|
|
@@ -22044,7 +22230,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22044
22230
|
path: POOL_STATUS_PATH,
|
|
22045
22231
|
handler: async (req, res) => {
|
|
22046
22232
|
if (req.method !== "GET") return json(res, 405, { error: "method not allowed" });
|
|
22047
|
-
if (!
|
|
22233
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22048
22234
|
try {
|
|
22049
22235
|
json(res, 200, await poolWebStatus(deps, new URL(req.url ?? "/", "http://localhost").searchParams.get("region") === "global" ? "global" : "cn"));
|
|
22050
22236
|
} catch (error) {
|
|
@@ -22064,7 +22250,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22064
22250
|
path: POOL_USAGE_PATH,
|
|
22065
22251
|
handler: async (req, res) => {
|
|
22066
22252
|
if (req.method !== "GET") return json(res, 405, { error: "method not allowed" });
|
|
22067
|
-
if (!
|
|
22253
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22068
22254
|
if (deps.usage === void 0) return json(res, 503, { error: "usage accounting is not available in this build" });
|
|
22069
22255
|
try {
|
|
22070
22256
|
json(res, 200, deps.usage());
|
|
@@ -22090,7 +22276,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22090
22276
|
path: POOL_CATALOG_REFRESH_PATH,
|
|
22091
22277
|
handler: async (req, res) => {
|
|
22092
22278
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22093
|
-
if (!
|
|
22279
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22094
22280
|
if (deps.refreshCatalog === void 0) return json(res, 503, { error: "catalog refresh is not available in this build" });
|
|
22095
22281
|
try {
|
|
22096
22282
|
json(res, 200, {
|
|
@@ -22107,7 +22293,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22107
22293
|
path: POOL_RESCAN_PATH,
|
|
22108
22294
|
handler: async (req, res) => {
|
|
22109
22295
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22110
|
-
if (!
|
|
22296
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22111
22297
|
try {
|
|
22112
22298
|
json(res, 200, { accounts: (await deps.pool.scan()).length });
|
|
22113
22299
|
} catch (error) {
|
|
@@ -22120,7 +22306,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22120
22306
|
path: POOL_RESET_COOLDOWN_PATH,
|
|
22121
22307
|
handler: async (req, res) => {
|
|
22122
22308
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22123
|
-
if (!
|
|
22309
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22124
22310
|
deps.pool.resetCooldowns();
|
|
22125
22311
|
json(res, 200, { ok: true });
|
|
22126
22312
|
}
|
|
@@ -22130,7 +22316,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22130
22316
|
path: POOL_CHECKIN_PATH,
|
|
22131
22317
|
handler: async (req, res) => {
|
|
22132
22318
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22133
|
-
if (!
|
|
22319
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22134
22320
|
try {
|
|
22135
22321
|
const body = await readJsonBody(req);
|
|
22136
22322
|
const accountId = typeof body["accountId"] === "string" ? body["accountId"] : "";
|
|
@@ -22162,7 +22348,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22162
22348
|
path: POOL_MODELS_SAVE_PATH,
|
|
22163
22349
|
handler: async (req, res) => {
|
|
22164
22350
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22165
|
-
if (!
|
|
22351
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22166
22352
|
if (deps.saveSelection === void 0) return json(res, 503, { error: "settings service unavailable; model selection cannot be saved" });
|
|
22167
22353
|
try {
|
|
22168
22354
|
const body = await readJsonBody(req);
|
|
@@ -22185,7 +22371,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22185
22371
|
path: POOL_ACCOUNT_DISABLE_PATH,
|
|
22186
22372
|
handler: async (req, res) => {
|
|
22187
22373
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22188
|
-
if (!
|
|
22374
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22189
22375
|
if (deps.setAccountDisabled === void 0) return json(res, 503, { error: "settings service unavailable; the account switch cannot be saved" });
|
|
22190
22376
|
try {
|
|
22191
22377
|
const body = await readJsonBody(req);
|
|
@@ -22220,7 +22406,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22220
22406
|
path: POOL_ACCOUNT_IGNORE_PATH,
|
|
22221
22407
|
handler: async (req, res) => {
|
|
22222
22408
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22223
|
-
if (!
|
|
22409
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22224
22410
|
if (deps.setAccountIgnored === void 0) return json(res, 503, { error: "settings service unavailable; the ignore list cannot be saved" });
|
|
22225
22411
|
try {
|
|
22226
22412
|
const body = await readJsonBody(req);
|
|
@@ -22243,7 +22429,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22243
22429
|
path: POOL_ACCOUNT_PREFER_PATH,
|
|
22244
22430
|
handler: async (req, res) => {
|
|
22245
22431
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22246
|
-
if (!
|
|
22432
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22247
22433
|
if (deps.setPreferredAccount === void 0) return json(res, 503, { error: "the preferred account cannot be saved in this build" });
|
|
22248
22434
|
try {
|
|
22249
22435
|
const body = await readJsonBody(req);
|
|
@@ -22272,7 +22458,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22272
22458
|
path: POOL_AUTOMATION_RUN_PATH,
|
|
22273
22459
|
handler: async (req, res) => {
|
|
22274
22460
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22275
|
-
if (!
|
|
22461
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22276
22462
|
if (deps.runAutomation === void 0) return json(res, 503, { error: "automation is not available in this build" });
|
|
22277
22463
|
try {
|
|
22278
22464
|
const run = parseAutomationRun(await readJsonBody(req));
|
|
@@ -22300,7 +22486,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22300
22486
|
path: POOL_CREDIT_RESERVE_PATH,
|
|
22301
22487
|
handler: async (req, res) => {
|
|
22302
22488
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22303
|
-
if (!
|
|
22489
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22304
22490
|
if (deps.setCreditReserve === void 0) return json(res, 503, { error: "settings service unavailable; the reserve cannot be saved" });
|
|
22305
22491
|
try {
|
|
22306
22492
|
const body = await readJsonBody(req);
|
|
@@ -22335,7 +22521,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22335
22521
|
path: POOL_AGGREGATE_PATH,
|
|
22336
22522
|
handler: async (req, res) => {
|
|
22337
22523
|
if (req.method !== "GET") return json(res, 405, { error: "method not allowed" });
|
|
22338
|
-
if (!
|
|
22524
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22339
22525
|
if (deps.aggregateDocument === void 0) return json(res, 503, { error: "the aggregate lane is not available in this build" });
|
|
22340
22526
|
try {
|
|
22341
22527
|
json(res, 200, await deps.aggregateDocument());
|
|
@@ -22361,7 +22547,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22361
22547
|
path: POOL_AGGREGATE_SAVE_PATH,
|
|
22362
22548
|
handler: async (req, res) => {
|
|
22363
22549
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22364
|
-
if (!
|
|
22550
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22365
22551
|
if (deps.saveAggregate === void 0) return json(res, 503, { error: "the aggregate lane is not available in this build" });
|
|
22366
22552
|
try {
|
|
22367
22553
|
const patch = parseAggregatePatch(await readJsonBody(req));
|
|
@@ -22393,7 +22579,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22393
22579
|
path: POOL_AGGREGATE_TEST_PATH,
|
|
22394
22580
|
handler: async (req, res) => {
|
|
22395
22581
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22396
|
-
if (!
|
|
22582
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22397
22583
|
if (deps.probeAggregate === void 0) return json(res, 503, { error: "the aggregate lane is not available in this build" });
|
|
22398
22584
|
try {
|
|
22399
22585
|
const providerId = parseProviderId(await readJsonBody(req));
|
|
@@ -22422,7 +22608,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22422
22608
|
path: POOL_MODEL_PROBE_PATH,
|
|
22423
22609
|
handler: async (req, res) => {
|
|
22424
22610
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22425
|
-
if (!
|
|
22611
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22426
22612
|
if (deps.probeModel === void 0) return json(res, 503, { error: "the connectivity probe is not available in this build" });
|
|
22427
22613
|
const controller = new AbortController();
|
|
22428
22614
|
req.on("aborted", () => {
|
|
@@ -22470,7 +22656,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22470
22656
|
path: POOL_CHANNEL_MODELS_PATH,
|
|
22471
22657
|
handler: async (req, res) => {
|
|
22472
22658
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22473
|
-
if (!
|
|
22659
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22474
22660
|
if (deps.channelModels === void 0) return json(res, 503, { error: "the login channels are not available in this build" });
|
|
22475
22661
|
try {
|
|
22476
22662
|
const body = await readJsonBody(req);
|
|
@@ -22487,7 +22673,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22487
22673
|
path: POOL_AGGREGATE_DISCOVER_PATH,
|
|
22488
22674
|
handler: async (req, res) => {
|
|
22489
22675
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22490
|
-
if (!
|
|
22676
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22491
22677
|
if (deps.discoverAggregate === void 0) return json(res, 503, { error: "the aggregate lane is not available in this build" });
|
|
22492
22678
|
try {
|
|
22493
22679
|
const providerId = parseProviderId(await readJsonBody(req));
|
|
@@ -22503,7 +22689,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22503
22689
|
path: POOL_CHANNELS_PATH,
|
|
22504
22690
|
handler: (req, res) => {
|
|
22505
22691
|
if (req.method !== "GET") return json(res, 405, { error: "method not allowed" });
|
|
22506
|
-
if (!
|
|
22692
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22507
22693
|
if (deps.channelsDocument === void 0) return json(res, 503, { error: "the login channels are not available in this build" });
|
|
22508
22694
|
try {
|
|
22509
22695
|
json(res, 200, deps.channelsDocument());
|
|
@@ -22525,7 +22711,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22525
22711
|
path: POOL_COMBOS_PATH,
|
|
22526
22712
|
handler: async (req, res) => {
|
|
22527
22713
|
if (req.method !== "GET") return json(res, 405, { error: "method not allowed" });
|
|
22528
|
-
if (!
|
|
22714
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22529
22715
|
if (deps.combosDocument === void 0) return json(res, 503, { error: "the routing chains are not available in this build" });
|
|
22530
22716
|
try {
|
|
22531
22717
|
json(res, 200, await deps.combosDocument());
|
|
@@ -22546,7 +22732,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22546
22732
|
path: POOL_CREDITS_SPEND_PATH,
|
|
22547
22733
|
handler: async (req, res) => {
|
|
22548
22734
|
if (req.method !== "GET") return json(res, 405, { error: "method not allowed" });
|
|
22549
|
-
if (!
|
|
22735
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22550
22736
|
if (deps.creditsSpend === void 0) return json(res, 503, { error: "credit accounting is not available in this build" });
|
|
22551
22737
|
try {
|
|
22552
22738
|
const raw = new URL(req.url ?? "/", "http://127.0.0.1").searchParams.get("days");
|
|
@@ -22569,7 +22755,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22569
22755
|
path: POOL_COMBOS_SAVE_PATH,
|
|
22570
22756
|
handler: async (req, res) => {
|
|
22571
22757
|
if (req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22572
|
-
if (!
|
|
22758
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22573
22759
|
if (deps.saveCombos === void 0) return json(res, 503, { error: "the routing chains are not available in this build" });
|
|
22574
22760
|
try {
|
|
22575
22761
|
const body = await readJsonBody(req);
|
|
@@ -22595,7 +22781,7 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22595
22781
|
path: POOL_RELAY_PATH,
|
|
22596
22782
|
handler: async (req, res) => {
|
|
22597
22783
|
if (req.method !== "GET" && req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22598
|
-
if (!
|
|
22784
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22599
22785
|
if (deps.relayDocument === void 0 || deps.saveRelay === void 0) return json(res, 503, { error: "the LAN relay is not available in this build" });
|
|
22600
22786
|
try {
|
|
22601
22787
|
if (req.method === "GET") {
|
|
@@ -22609,7 +22795,32 @@ function registerPoolStatusRoute(ctx, deps) {
|
|
|
22609
22795
|
}
|
|
22610
22796
|
}
|
|
22611
22797
|
});
|
|
22798
|
+
/**
|
|
22799
|
+
* Is there a newer build?
|
|
22800
|
+
*
|
|
22801
|
+
* `POST` forces a fresh read — that is the panel's button, and a button that silently
|
|
22802
|
+
* returns a cached answer is indistinguishable from one that did nothing.
|
|
22803
|
+
*/
|
|
22804
|
+
const disposeUpdate = ctx.webServer.register({
|
|
22805
|
+
kind: "exact",
|
|
22806
|
+
path: POOL_UPDATE_CHECK_PATH,
|
|
22807
|
+
handler: async (req, res) => {
|
|
22808
|
+
if (req.method !== "GET" && req.method !== "POST") return json(res, 405, { error: "method not allowed" });
|
|
22809
|
+
if (!originTrusted(req, deps.trustedHosts?.() ?? [])) return json(res, 403, { error: "origin-not-trusted" });
|
|
22810
|
+
try {
|
|
22811
|
+
return json(res, 200, await checkForUpdate({ force: req.method === "POST" }));
|
|
22812
|
+
} catch (error) {
|
|
22813
|
+
return json(res, 200, {
|
|
22814
|
+
current: "unknown",
|
|
22815
|
+
newer: false,
|
|
22816
|
+
error: safeMessage(error),
|
|
22817
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
22818
|
+
});
|
|
22819
|
+
}
|
|
22820
|
+
}
|
|
22821
|
+
});
|
|
22612
22822
|
return () => {
|
|
22823
|
+
disposeUpdate();
|
|
22613
22824
|
disposeRelay();
|
|
22614
22825
|
disposeCombosSave();
|
|
22615
22826
|
disposeCombos();
|
|
@@ -27566,6 +27777,26 @@ function apply(ctx, config = {}) {
|
|
|
27566
27777
|
rateOf
|
|
27567
27778
|
});
|
|
27568
27779
|
};
|
|
27780
|
+
/**
|
|
27781
|
+
* The authorities this deployment serves, read per request.
|
|
27782
|
+
*
|
|
27783
|
+
* `connection.trustedHosts` is what the host's own `/api` bridge trusts — Tailscale serve, a
|
|
27784
|
+
* LAN hostname, a reverse proxy. The plugin's routes used to accept loopback only, so behind
|
|
27785
|
+
* any of those the card displayed its data and refused every button (#164). Reading it fresh
|
|
27786
|
+
* means a configuration change reaches the next request without a restart.
|
|
27787
|
+
*
|
|
27788
|
+
* A missing service is not an error: it simply means nothing beyond loopback is trusted, which
|
|
27789
|
+
* is the desktop default.
|
|
27790
|
+
*/
|
|
27791
|
+
const trustedHosts = () => {
|
|
27792
|
+
try {
|
|
27793
|
+
const list = ctx.connection?.config?.trustedHosts;
|
|
27794
|
+
if (!Array.isArray(list)) return [];
|
|
27795
|
+
return list.filter((entry) => typeof entry === "string");
|
|
27796
|
+
} catch {
|
|
27797
|
+
return [];
|
|
27798
|
+
}
|
|
27799
|
+
};
|
|
27569
27800
|
ctx.inject(["webServer"], (webCtx) => {
|
|
27570
27801
|
/**
|
|
27571
27802
|
* Doubao's three routes.
|
|
@@ -27576,6 +27807,7 @@ function apply(ctx, config = {}) {
|
|
|
27576
27807
|
*/
|
|
27577
27808
|
registerDoubaoRoutes(webCtx, {
|
|
27578
27809
|
session: () => doubaoSession,
|
|
27810
|
+
trustedHosts,
|
|
27579
27811
|
save: (session) => {
|
|
27580
27812
|
adoptDoubaoSession(session);
|
|
27581
27813
|
writeStoredSession(session);
|
|
@@ -27588,6 +27820,7 @@ function apply(ctx, config = {}) {
|
|
|
27588
27820
|
});
|
|
27589
27821
|
return registerPoolStatusRoute(webCtx, {
|
|
27590
27822
|
pool: core.pool,
|
|
27823
|
+
trustedHosts,
|
|
27591
27824
|
catalogs: core.catalogs,
|
|
27592
27825
|
client: core.client,
|
|
27593
27826
|
usage: () => usageRecorder.summary(),
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-xdpool",
|
|
3
3
|
"displayName": "DSH XD Pool",
|
|
4
4
|
"description": "One DSH model pool for every free quota you have: merge all locally signed-in WorkBuddy accounts with auto-failover, sign in to 13 vendors by QR/web, aggregate 76 vendors' free tiers, plus a usage dashboard, model routing, a local OpenAI-compatible gateway and a points-automation suite.",
|
|
5
|
-
"version": "2.7.
|
|
5
|
+
"version": "2.7.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "XDTrees",
|
|
8
8
|
"homepage": "https://github.com/XDTrees/dsh-xdpool#readme",
|