dsh-sub2api 0.8.1 → 0.9.1
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 +31 -0
- package/README.md +3 -3
- package/lib/adapter.js +4 -4
- package/lib/client.js +10 -52
- package/lib/commands.js +6 -6
- package/lib/constants.js +1 -1
- package/lib/index.js +63 -2
- package/lib/model-registry.js +112 -0
- package/lib/sub2api/auth.js +1 -1
- package/lib/sub2api/catalog.js +25 -9
- package/lib/sub2api/session.js +1 -1
- package/lib/tools.js +4 -4
- package/package.json +1 -1
- package/lib/model-context.js +0 -63
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
- The plugin calls itself **dsh-sub2api** everywhere a user can see it: the
|
|
6
|
+
settings page tab, both panel cards, the sidebar card, the balance badge's
|
|
7
|
+
accessible name, the provider name in the model picker, the `/sub2api` command
|
|
8
|
+
output, the tool descriptions, and the error messages. "Psapi" is the site's
|
|
9
|
+
name, not the plugin's, and mixing them made the settings page look like it
|
|
10
|
+
belonged to someone else.
|
|
11
|
+
- The pay-centre error matcher still accepts both spellings: it reads text from
|
|
12
|
+
the billing service, which is deployed separately and can lag.
|
|
13
|
+
|
|
14
|
+
## 0.9.0
|
|
15
|
+
|
|
16
|
+
- **The capacity warning is gone.** The panel no longer lists models whose
|
|
17
|
+
window it does not know, and no longer offers a button to go and find out.
|
|
18
|
+
Model facts now come from the open-source registry (LiteLLM's
|
|
19
|
+
`model_prices_and_context_window.json`, 7,194 entries) merged with this
|
|
20
|
+
gateway's own measurements, so a model is either known or it is not offered.
|
|
21
|
+
- **Measurements outrank the open registry, and it matters.** Cross-checking
|
|
22
|
+
showed the registry is wrong for this gateway in both directions and by a
|
|
23
|
+
lot: it claims 922,000 for `gpt-6.2-astra` (really 524,288) and 500,000 for
|
|
24
|
+
`grok-4.7` (really 131,072). Believing either makes the host compact too late
|
|
25
|
+
and the upstream answer with a 400, so any measured value replaces it.
|
|
26
|
+
- **Background sync, invisible to the user.** Every five minutes the plugin
|
|
27
|
+
refreshes the catalogue when it is stale and re-checks availability every
|
|
28
|
+
fifteen, announcing changes so the picker rebuilds itself. Nothing is shown,
|
|
29
|
+
nothing is clicked, and one sweep at a time keeps a slow gateway from stacking
|
|
30
|
+
work.
|
|
31
|
+
- Prefix matching learned that `glm-5` is not `glm-5.2`: a version continuation
|
|
32
|
+
after a digit no longer lets a shorter id lend its window to a longer one.
|
|
33
|
+
|
|
3
34
|
## 0.8.1
|
|
4
35
|
|
|
5
36
|
- `muse-spark` measured at 2,097,152 (it accepts more than the ladder was
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
把自建的 **Psapi**(`sub.pscly.cc`,网关软件是开源的 [sub2api](https://github.com/Wei-Shaw/sub2api))接进 DeepSeek Harness(DSH)。
|
|
4
4
|
|
|
5
|
-
装完之后,在 **设置 →
|
|
5
|
+
装完之后,在 **设置 → dsh-sub2api** 里填一次邮箱和密码就能用:插件自己判断该登录还是注册,注册后自动创建名为 `dsh` 的 API 密钥、写进本机凭据库,并把上游模型同步进模型选择器。余额、用量、订阅、兑换码、充值和技术支持都在同一个面板里。
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
npm: dsh-sub2api https://www.npmjs.com/package/dsh-sub2api
|
|
@@ -40,7 +40,7 @@ dsh plugin --profile web add dsh-sub2api
|
|
|
40
40
|
|
|
41
41
|
也可以直接在 **插件 → 添加插件** 里搜 `dsh-sub2api`。
|
|
42
42
|
|
|
43
|
-
重启后打开 **设置 →
|
|
43
|
+
重启后打开 **设置 → dsh-sub2api**。
|
|
44
44
|
|
|
45
45
|
### 从 GitHub 装
|
|
46
46
|
|
|
@@ -227,7 +227,7 @@ Agent 工具(只读):`sub2api_status`、`sub2api_models`。模型可以回
|
|
|
227
227
|
|
|
228
228
|
### 2. 余额为 0 拿不到模型,到账后自动同步
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
网关对 `/v1/models` 有余额门槛,零余额直接 `403 INSUFFICIENT_BALANCE`:
|
|
231
231
|
|
|
232
232
|
```
|
|
233
233
|
[200] POST /api/v1/keys → 正常返回明文 key
|
package/lib/adapter.js
CHANGED
|
@@ -88,7 +88,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
88
88
|
connections: liveRef(() => [
|
|
89
89
|
{
|
|
90
90
|
id: PROVIDER,
|
|
91
|
-
name: "
|
|
91
|
+
name: "dsh-sub2api",
|
|
92
92
|
baseUrl: `${deps.apiBase()}/v1`,
|
|
93
93
|
apiKeyRef: deps.apiKeyEnv(),
|
|
94
94
|
},
|
|
@@ -96,7 +96,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
96
96
|
llmRoutes: liveRef(() => [
|
|
97
97
|
{
|
|
98
98
|
id: PROVIDER,
|
|
99
|
-
name: "
|
|
99
|
+
name: "dsh-sub2api",
|
|
100
100
|
connection: PROVIDER,
|
|
101
101
|
models: deps.catalog.llmModels(),
|
|
102
102
|
maxCompletionTokens: false,
|
|
@@ -117,7 +117,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
providerInfo(provider) {
|
|
120
|
-
return { id: provider, name: "
|
|
120
|
+
return { id: provider, name: "dsh-sub2api" };
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
async listModels(provider) {
|
|
@@ -160,7 +160,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
160
160
|
// An empty `models` array still yields a route object; without this check
|
|
161
161
|
// the transport would build a request with no model and fail at the wire.
|
|
162
162
|
if (route === undefined || route.models.length === 0) {
|
|
163
|
-
throw new Sub2ApiError("尚未同步到可用模型,请先在
|
|
163
|
+
throw new Sub2ApiError("尚未同步到可用模型,请先在 dsh-sub2api 面板登录或刷新模型", {
|
|
164
164
|
code: "no_models",
|
|
165
165
|
});
|
|
166
166
|
}
|
package/lib/client.js
CHANGED
|
@@ -403,7 +403,7 @@ window.__ModuleLoader__.load({
|
|
|
403
403
|
}
|
|
404
404
|
render() {
|
|
405
405
|
if (this.state.error) {
|
|
406
|
-
return h(Alert, { tone: "error", title: "
|
|
406
|
+
return h(Alert, { tone: "error", title: "dsh-sub2api 面板渲染失败" },
|
|
407
407
|
asText(this.state.error) || "未知错误",
|
|
408
408
|
h("div", { style: { ...T.hint, marginTop: 6 } }, "把这段信息发给我即可定位。"));
|
|
409
409
|
}
|
|
@@ -609,7 +609,7 @@ window.__ModuleLoader__.load({
|
|
|
609
609
|
}),
|
|
610
610
|
h("div", { style: { display: "flex", flexDirection: "column", gap: 1, minWidth: 0 } },
|
|
611
611
|
h("span", { style: { fontSize: 13.5, fontWeight: 600, color: C.text, overflow: "hidden", textOverflow: "ellipsis" } },
|
|
612
|
-
state.loggedIn ? (state.email || "已连接") : "未连接
|
|
612
|
+
state.loggedIn ? (state.email || "已连接") : "未连接 dsh-sub2api"),
|
|
613
613
|
h("span", { style: T.hint },
|
|
614
614
|
state.loggedIn
|
|
615
615
|
? models > 0
|
|
@@ -1121,7 +1121,6 @@ window.__ModuleLoader__.load({
|
|
|
1121
1121
|
const [saving, setSaving] = useState(false);
|
|
1122
1122
|
const [query, setQuery] = useState("");
|
|
1123
1123
|
const [expanded, setExpanded] = useState(false);
|
|
1124
|
-
const [measuring, setMeasuring] = useState(false);
|
|
1125
1124
|
|
|
1126
1125
|
const checked = draft ?? (showingAll ? everything.map((m) => m.id) : allowed);
|
|
1127
1126
|
const isOn = (id) => checked.includes(id);
|
|
@@ -1166,7 +1165,7 @@ window.__ModuleLoader__.load({
|
|
|
1166
1165
|
style: { color: "inherit", borderColor: "currentColor", background: "transparent" },
|
|
1167
1166
|
}, "去充值"),
|
|
1168
1167
|
},
|
|
1169
|
-
"
|
|
1168
|
+
"dsh-sub2api 在余额为 0 时会拒绝 /v1/models;充值到账后自动同步。"));
|
|
1170
1169
|
}
|
|
1171
1170
|
|
|
1172
1171
|
if (everything.length === 0) {
|
|
@@ -1266,49 +1265,8 @@ window.__ModuleLoader__.load({
|
|
|
1266
1265
|
saving ? "保存中…" : "保存选择")),
|
|
1267
1266
|
),
|
|
1268
1267
|
)
|
|
1269
|
-
: h("div",
|
|
1270
|
-
|
|
1271
|
-
`${shown.length} 个模型会出现在对话的选择器里;点「管理」可以增减或改上下文容量。`),
|
|
1272
|
-
// The gateway's /v1/models reports no context window, so a model
|
|
1273
|
-
// outside the measured table silently advertises the default.
|
|
1274
|
-
// Saying how many are in that state is the only way a user can
|
|
1275
|
-
// tell "128k because that is the truth" from "128k because we
|
|
1276
|
-
// never measured it".
|
|
1277
|
-
(() => {
|
|
1278
|
-
const fallback = shown.filter((m) => m.contextSource === "default");
|
|
1279
|
-
if (fallback.length === 0) return null;
|
|
1280
|
-
return h("div", { style: { marginTop: 6 } },
|
|
1281
|
-
h("div", { style: { ...T.hint, color: C.warn } },
|
|
1282
|
-
`${fallback.length} 个模型不知道真实容量,暂按 ${Math.round((state.defaultContextWindow || 128000) / 1000)}k 显示:`,
|
|
1283
|
-
fallback.map((m) => m.id).join("、"),
|
|
1284
|
-
"。"),
|
|
1285
|
-
h("div", { style: { ...T.row, marginTop: 8, alignItems: "flex-start" } },
|
|
1286
|
-
h(Button, {
|
|
1287
|
-
size: "sm",
|
|
1288
|
-
disabled: measuring,
|
|
1289
|
-
onClick: async () => {
|
|
1290
|
-
setMeasuring(true);
|
|
1291
|
-
try {
|
|
1292
|
-
const result = await onMeasureContext(fallback.map((m) => m.id));
|
|
1293
|
-
const ok = result?.measured?.length ?? 0;
|
|
1294
|
-
const bad = result?.failed?.length ?? 0;
|
|
1295
|
-
toastStore.push(
|
|
1296
|
-
ok === 0
|
|
1297
|
-
? `没测出来(${bad} 个失败)`
|
|
1298
|
-
: `测到 ${ok} 个模型${bad > 0 ? `,${bad} 个失败` : ""}`,
|
|
1299
|
-
ok === 0 ? "error" : "ok",
|
|
1300
|
-
);
|
|
1301
|
-
} catch (e) {
|
|
1302
|
-
toastStore.push(e instanceof Error ? e.message : String(e), "error");
|
|
1303
|
-
} finally {
|
|
1304
|
-
setMeasuring(false);
|
|
1305
|
-
}
|
|
1306
|
-
},
|
|
1307
|
-
}, measuring ? "测量中…" : "自动测量容量"),
|
|
1308
|
-
h("span", { style: { ...T.hint, flex: "1 1 200px" } },
|
|
1309
|
-
"向网关发超长请求试探上限,被拒绝的不计费;账号不可用的模型会跳过。"),
|
|
1310
|
-
));
|
|
1311
|
-
})()),
|
|
1268
|
+
: h("div", { style: T.hint },
|
|
1269
|
+
`${shown.length} 个模型会出现在对话的选择器里。`),
|
|
1312
1270
|
);
|
|
1313
1271
|
}
|
|
1314
1272
|
|
|
@@ -1482,7 +1440,7 @@ window.__ModuleLoader__.load({
|
|
|
1482
1440
|
const failure = error || "";
|
|
1483
1441
|
if (failure) {
|
|
1484
1442
|
return h("div", { style: { padding: "4px 0 18px" } },
|
|
1485
|
-
h(Card, { title: "
|
|
1443
|
+
h(Card, { title: "dsh-sub2api" },
|
|
1486
1444
|
h(Alert, { tone: "error", title: "面板无法连接插件后端" }, failure),
|
|
1487
1445
|
h("div", { style: { ...T.hint, marginTop: 12 } },
|
|
1488
1446
|
"常见原因:插件装上了但宿主那一半没有加载(版本不匹配、依赖缺失、或安装后没有重启)。"),
|
|
@@ -1636,7 +1594,7 @@ window.__ModuleLoader__.load({
|
|
|
1636
1594
|
type: "button",
|
|
1637
1595
|
"data-sub2api": "",
|
|
1638
1596
|
title: detail,
|
|
1639
|
-
"aria-label": `
|
|
1597
|
+
"aria-label": `dsh-sub2api ${known ? "余额 " + money(balance) : "余额未知"},点击${low ? "去充值" : "刷新"}`,
|
|
1640
1598
|
onClick,
|
|
1641
1599
|
style: {
|
|
1642
1600
|
display: "inline-flex",
|
|
@@ -1674,7 +1632,7 @@ window.__ModuleLoader__.load({
|
|
|
1674
1632
|
},
|
|
1675
1633
|
});
|
|
1676
1634
|
return h("div", { style: { padding: "4px 0 18px" } },
|
|
1677
|
-
h(Card, { title: "
|
|
1635
|
+
h(Card, { title: "dsh-sub2api" },
|
|
1678
1636
|
bar("40%", 14),
|
|
1679
1637
|
h("div", { style: { height: 10 } }),
|
|
1680
1638
|
bar("70%", 12),
|
|
@@ -1703,7 +1661,7 @@ window.__ModuleLoader__.load({
|
|
|
1703
1661
|
lineHeight: "18px",
|
|
1704
1662
|
},
|
|
1705
1663
|
},
|
|
1706
|
-
h("span", { style: { fontWeight: 600, color: C.text } }, "
|
|
1664
|
+
h("span", { style: { fontWeight: 600, color: C.text } }, "dsh-sub2api"),
|
|
1707
1665
|
h("span", { style: { marginLeft: "auto", color: low ? C.bad : C.muted } },
|
|
1708
1666
|
Number.isFinite(balance) ? (low ? "余额不足" : money(balance)) : "已登录"),
|
|
1709
1667
|
);
|
|
@@ -1717,7 +1675,7 @@ window.__ModuleLoader__.load({
|
|
|
1717
1675
|
try {
|
|
1718
1676
|
ctx.slots.inject("settings.section", () =>
|
|
1719
1677
|
ctx.slots.register(
|
|
1720
|
-
{ name: "settings.section", id: "sub2api", order: 300, label: () => "
|
|
1678
|
+
{ name: "settings.section", id: "sub2api", order: 300, label: () => "dsh-sub2api" },
|
|
1721
1679
|
Section,
|
|
1722
1680
|
),
|
|
1723
1681
|
);
|
package/lib/commands.js
CHANGED
|
@@ -27,7 +27,7 @@ const HELP = [
|
|
|
27
27
|
export function commandDefinition(deps) {
|
|
28
28
|
return {
|
|
29
29
|
name: "sub2api",
|
|
30
|
-
description: "
|
|
30
|
+
description: "dsh-sub2api 中转站:账号、密钥、余额与可用模型",
|
|
31
31
|
input: { hint: "[status|models|balance|recharge]" },
|
|
32
32
|
handler: async (invocation) => {
|
|
33
33
|
const verb = String(invocation?.rawInput ?? "").trim().split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
@@ -42,7 +42,7 @@ export function commandDefinition(deps) {
|
|
|
42
42
|
} catch (error) {
|
|
43
43
|
return {
|
|
44
44
|
kind: "error",
|
|
45
|
-
text: `
|
|
45
|
+
text: `dsh-sub2api:${error instanceof Error ? error.message : String(error)}`,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
},
|
|
@@ -67,8 +67,8 @@ async function statusText(deps) {
|
|
|
67
67
|
|
|
68
68
|
if (session === undefined) {
|
|
69
69
|
return [
|
|
70
|
-
"
|
|
71
|
-
`在 DSH 的 设置 →
|
|
70
|
+
"dsh-sub2api:尚未登录。",
|
|
71
|
+
`在 DSH 的 设置 → dsh-sub2api 里用一个邮箱和密码登录或注册即可(${deps.cfg().apiBase})。`,
|
|
72
72
|
].join("\n");
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -77,7 +77,7 @@ async function statusText(deps) {
|
|
|
77
77
|
const models = deps.catalog.visible();
|
|
78
78
|
|
|
79
79
|
const lines = [
|
|
80
|
-
`
|
|
80
|
+
`dsh-sub2api · ${deps.cfg().apiBase}`,
|
|
81
81
|
`账号 ${profile?.email ?? session.email ?? "已登录"}`,
|
|
82
82
|
`余额 ${money(profile?.balance)}`,
|
|
83
83
|
`密钥 ${apiKey ? maskSecret(apiKey) : "尚未创建"}`,
|
|
@@ -126,7 +126,7 @@ async function modelsText(deps) {
|
|
|
126
126
|
const reason = deps.catalog.lastError?.message;
|
|
127
127
|
return reason
|
|
128
128
|
? `没有可用模型:${reason}`
|
|
129
|
-
: "没有可用模型。登录后在 设置 →
|
|
129
|
+
: "没有可用模型。登录后在 设置 → dsh-sub2api 里点「刷新模型」。";
|
|
130
130
|
}
|
|
131
131
|
const lines = models.map((model) => {
|
|
132
132
|
const bits = [`${Math.round((model.contextWindow ?? 0) / 1000)}k`];
|
package/lib/constants.js
CHANGED
|
@@ -47,7 +47,7 @@ export const TOKEN_REFRESH_LEAD_MS = 60 * 1000;
|
|
|
47
47
|
export const KEY_PAGE_SIZE = 100;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Currency of every amount this plugin shows.
|
|
50
|
+
* Currency of every amount this plugin shows. dsh-sub2api quotes quota in yuan and
|
|
51
51
|
* treats one quota unit as one yuan ("1 额度 = 1 元"), so the panel never uses a
|
|
52
52
|
* foreign-currency figure.
|
|
53
53
|
*/
|
package/lib/index.js
CHANGED
|
@@ -53,7 +53,7 @@ export const VERSION = (() => {
|
|
|
53
53
|
const SECTION_ORDER = 172;
|
|
54
54
|
|
|
55
55
|
const GUIDANCE =
|
|
56
|
-
"本机已安装 dsh-sub2api 插件:它把 sub2api(sub.pscly.cc)中转站接入 DSH。用户在 设置 →
|
|
56
|
+
"本机已安装 dsh-sub2api 插件:它把 sub2api(sub.pscly.cc)中转站接入 DSH。用户在 设置 → dsh-sub2api 用一个邮箱和密码完成登录或注册,插件会自动在该账号下创建名为 dsh 的 API 密钥、写入本机凭据库,并同步上游模型目录,模型随后出现在模型选择器的 dsh-sub2api 分组里。余额、订阅进度与充值入口也在同一面板;充值走 pay.pscly.cc,点「去支付」会在新标签页打开。可用命令 /sub2api 查看状态。用户提到「sub2api / 中转站 / 我的网关 / 余额充值」时即指本插件。";
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Mount the provider, panel routes and tools.
|
|
@@ -153,7 +153,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
153
153
|
const providers = llmCtx.llm.registerConfigurableProviders([
|
|
154
154
|
{
|
|
155
155
|
provider: PROVIDER,
|
|
156
|
-
displayName: "
|
|
156
|
+
displayName: "dsh-sub2api",
|
|
157
157
|
settingsNs: SETTINGS_NS,
|
|
158
158
|
settingsPath: [],
|
|
159
159
|
},
|
|
@@ -209,6 +209,67 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
209
209
|
if (typeof ctx.inject === "function") ctx.inject(["llm"], mountDiscovery);
|
|
210
210
|
else if (optional(ctx, "llm") !== undefined) mountDiscovery(ctx);
|
|
211
211
|
|
|
212
|
+
// 2.4) Keep the catalogue and its availability fresh in the background.
|
|
213
|
+
//
|
|
214
|
+
// The gateway's model list changes when the operator adds or removes an
|
|
215
|
+
// upstream, and models go down and come back. Neither is something a
|
|
216
|
+
// user should have to notice, let alone click: the picker is rebuilt
|
|
217
|
+
// quietly and the announcement event makes it live.
|
|
218
|
+
ctx.effect(() => {
|
|
219
|
+
/** One sweep in flight at a time; a slow gateway must not stack them. */
|
|
220
|
+
let busy = false;
|
|
221
|
+
let stopped = false;
|
|
222
|
+
// Declared before `tick` reads them: `let` bindings sit in a temporal dead
|
|
223
|
+
// zone until their declaration runs, and `tick` closes over both.
|
|
224
|
+
let lastHealthAt = 0;
|
|
225
|
+
let lastBrokenCount = -1;
|
|
226
|
+
|
|
227
|
+
const tick = async () => {
|
|
228
|
+
if (busy || stopped) return;
|
|
229
|
+
const key = await session.apiKey().catch(() => undefined);
|
|
230
|
+
if (key === undefined) return;
|
|
231
|
+
|
|
232
|
+
busy = true;
|
|
233
|
+
try {
|
|
234
|
+
// Refresh only when the catalogue is stale, so an idle session does not
|
|
235
|
+
// re-fetch the list every couple of minutes for nothing.
|
|
236
|
+
if (catalog.stale) {
|
|
237
|
+
const before = catalog.models.map((model) => model.id).join(",");
|
|
238
|
+
await catalog.refresh(key);
|
|
239
|
+
const after = catalog.models.map((model) => model.id).join(",");
|
|
240
|
+
if (before !== after) {
|
|
241
|
+
logger.info(`[sub2api] 模型目录已更新:${catalog.models.length} 个`);
|
|
242
|
+
announceCatalog?.();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// Availability is checked less often: it costs one token per model.
|
|
246
|
+
if (Date.now() - lastHealthAt > 15 * 60_000) {
|
|
247
|
+
lastHealthAt = Date.now();
|
|
248
|
+
const broken = await catalog.sweepHealth(key);
|
|
249
|
+
if (broken !== lastBrokenCount) {
|
|
250
|
+
lastBrokenCount = broken;
|
|
251
|
+
logger.info(`[sub2api] ${broken} 个模型当前路由不到`);
|
|
252
|
+
announceCatalog?.();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
logger.warn?.(`[sub2api] 后台同步失败:${error instanceof Error ? error.message : error}`);
|
|
257
|
+
} finally {
|
|
258
|
+
busy = false;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// First sweep shortly after start so the picker is truthful early, then
|
|
263
|
+
// every five minutes; the work itself is gated by staleness.
|
|
264
|
+
const first = setTimeout(tick, 20_000);
|
|
265
|
+
const timer = setInterval(tick, 5 * 60_000);
|
|
266
|
+
return () => {
|
|
267
|
+
stopped = true;
|
|
268
|
+
clearTimeout(first);
|
|
269
|
+
clearInterval(timer);
|
|
270
|
+
};
|
|
271
|
+
}, "sub2api: auto-sync");
|
|
272
|
+
|
|
212
273
|
// 2.5) Make this the default model for new conversations, once per install.
|
|
213
274
|
//
|
|
214
275
|
// `agentDefaultModel` is the host service that owns that selection and
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model facts: context window and output cap, per model id.
|
|
3
|
+
*
|
|
4
|
+
* Generated by `scripts/build-model-registry.mjs` — do not edit by hand.
|
|
5
|
+
*
|
|
6
|
+
* Sub2API's `/v1/models` returns ids only, with no capacity field at all, so
|
|
7
|
+
* this table is the only thing that lets the picker show a truthful number.
|
|
8
|
+
*
|
|
9
|
+
* Two sources with different standing:
|
|
10
|
+
*
|
|
11
|
+
* - `source: "measured"` — probed against this gateway. Ground truth.
|
|
12
|
+
* - `source: "open"` — from LiteLLM's public registry. A hint, not a fact: for
|
|
13
|
+
* this gateway it over-claimed by up to 397,712 tokens (`gpt-6.2-astra`,
|
|
14
|
+
* really 524,288) and under-claimed elsewhere. An over-claim makes the host
|
|
15
|
+
* compact too late and the upstream answer with a 400, so measurements always
|
|
16
|
+
* replace it when one exists.
|
|
17
|
+
*
|
|
18
|
+
* 24 measured, 3657 from the open registry.
|
|
19
|
+
*
|
|
20
|
+
* @type {Record<string, {contextWindow: number, maxTokens?: number, source: "measured"|"open"}>}
|
|
21
|
+
*/
|
|
22
|
+
export const MODEL_REGISTRY = {
|
|
23
|
+
"claude-haiku-5-5": { contextWindow: 1000000, source: "open" },
|
|
24
|
+
"codex-auto-review": { contextWindow: 950272, source: "measured" },
|
|
25
|
+
"deepseek-flash": { contextWindow: 1048576, source: "measured" },
|
|
26
|
+
"deepseek-pro": { contextWindow: 1048576, source: "measured" },
|
|
27
|
+
"deepseek-v4-pro": { contextWindow: 1048576, source: "measured" },
|
|
28
|
+
"deepseek-v4.1-flash": { contextWindow: 1048576, source: "measured" },
|
|
29
|
+
"DeepSeek-V4.1-flash": { contextWindow: 1000000, source: "open" },
|
|
30
|
+
"deepseek/deepseek-v4-pro": { contextWindow: 1048576, source: "measured" },
|
|
31
|
+
"deepseek/deepseek-v4.1-flash": { contextWindow: 1048576, source: "measured" },
|
|
32
|
+
"gemini-4-carbon": { contextWindow: 1048576, source: "open" },
|
|
33
|
+
"gemini-4-hydrogen": { contextWindow: 1048576, source: "open" },
|
|
34
|
+
"gemini-4-neon": { contextWindow: 1048576, source: "open" },
|
|
35
|
+
"glm-5": { contextWindow: 200000, source: "open" },
|
|
36
|
+
"glm-5.3": { contextWindow: 1048576, source: "measured" },
|
|
37
|
+
"GLM-5.3": { contextWindow: 1000000, source: "open" },
|
|
38
|
+
"gpt-5": { contextWindow: 272000, source: "open" },
|
|
39
|
+
"gpt-5.6": { contextWindow: 922000, source: "open" },
|
|
40
|
+
"gpt-5.6-luna": { contextWindow: 950272, source: "measured" },
|
|
41
|
+
"gpt-5.6-sol": { contextWindow: 950272, source: "measured" },
|
|
42
|
+
"gpt-5.6-terra": { contextWindow: 950272, source: "measured" },
|
|
43
|
+
"gpt-6-astra": { contextWindow: 950272, source: "measured" },
|
|
44
|
+
"gpt-6-luna": { contextWindow: 950272, source: "measured" },
|
|
45
|
+
"gpt-6-sol": { contextWindow: 950272, source: "measured" },
|
|
46
|
+
"gpt-6.1-sol": { contextWindow: 950272, source: "measured" },
|
|
47
|
+
"gpt-6.1-terra": { contextWindow: 950272, source: "measured" },
|
|
48
|
+
"gpt-6.2-astra": { contextWindow: 524288, source: "measured" },
|
|
49
|
+
"gpt-6.2-sol": { contextWindow: 950272, source: "measured" },
|
|
50
|
+
"gpt-reserve": { contextWindow: 950272, source: "measured" },
|
|
51
|
+
"grok-4": { contextWindow: 262000, source: "open" },
|
|
52
|
+
"grok-4.7": { contextWindow: 131072, source: "measured" },
|
|
53
|
+
"hy3": { contextWindow: 256000, source: "open" },
|
|
54
|
+
"hy4": { contextWindow: 960000, source: "open" },
|
|
55
|
+
"hy4-preview": { contextWindow: 960000, source: "open" },
|
|
56
|
+
"kimi-k2.7-code": { contextWindow: 229376, source: "open" },
|
|
57
|
+
"kimi-k3": { contextWindow: 917504, source: "open" },
|
|
58
|
+
"Kimi-K3": { contextWindow: 1000000, source: "open" },
|
|
59
|
+
"kimi-k3.1-pro": { contextWindow: 1048576, source: "open" },
|
|
60
|
+
"longcat-2.0": { contextWindow: 1000000, source: "open" },
|
|
61
|
+
"mimo-v2.6-flash": { contextWindow: 1048576, source: "open" },
|
|
62
|
+
"mimo-v2.6-pro": { contextWindow: 1048576, source: "open" },
|
|
63
|
+
"minimax-m3": { contextWindow: 512000, source: "open" },
|
|
64
|
+
"MiniMax-M3": { contextWindow: 1000000, source: "open" },
|
|
65
|
+
"minimax-m3.1-flash": { contextWindow: 1000000, source: "open" },
|
|
66
|
+
"MiniMax-M3.1-Flash": { contextWindow: 1000000, source: "open" },
|
|
67
|
+
"muse-image": { contextWindow: 2097152, source: "measured" },
|
|
68
|
+
"muse-spark": { contextWindow: 2097152, source: "measured" },
|
|
69
|
+
"muse-video": { contextWindow: 262144, source: "measured" },
|
|
70
|
+
"qwen3.7-plus": { contextWindow: 991808, source: "open" },
|
|
71
|
+
"qwen3.8-flash": { contextWindow: 991808, source: "open" },
|
|
72
|
+
"qwen3.8-max": { contextWindow: 1015808, source: "measured" },
|
|
73
|
+
"Qwen3.8-Max": { contextWindow: 1000000, source: "open" },
|
|
74
|
+
"qwen4-max": { contextWindow: 991808, source: "open" },
|
|
75
|
+
"step-5-preview": { contextWindow: 1000000, source: "open" },
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Facts for `id`: an exact hit, else the longest registry id it extends.
|
|
80
|
+
*
|
|
81
|
+
* The gateway lists both `deepseek-v4-pro` and `deepseek/deepseek-v4-pro`, so a
|
|
82
|
+
* prefix match covers provider-prefixed aliases without duplicating rows.
|
|
83
|
+
* @param {string} id
|
|
84
|
+
* @returns {{contextWindow: number, maxTokens?: number, source: "measured"|"open"} | undefined}
|
|
85
|
+
*/
|
|
86
|
+
export function registryFacts(id) {
|
|
87
|
+
const key = String(id ?? "").trim();
|
|
88
|
+
if (key === "") return undefined;
|
|
89
|
+
const exact = MODEL_REGISTRY[key];
|
|
90
|
+
if (exact !== undefined) return exact;
|
|
91
|
+
|
|
92
|
+
const lower = key.toLowerCase();
|
|
93
|
+
let best;
|
|
94
|
+
for (const [known, facts] of Object.entries(MODEL_REGISTRY)) {
|
|
95
|
+
const name = known.toLowerCase();
|
|
96
|
+
if (!lower.startsWith(name)) continue;
|
|
97
|
+
const next = lower.charAt(name.length);
|
|
98
|
+
// A prefix match must stop at a model boundary, not inside a version.
|
|
99
|
+
// `glm-5` is not `glm-5.2`: a dot (or digit) after a known id that itself
|
|
100
|
+
// ends in a digit is a version continuation, so the shorter id does not
|
|
101
|
+
// describe the longer one. `.` stays a valid separator for namespaces such
|
|
102
|
+
// as `zai-org.GLM`, which do not end in a digit.
|
|
103
|
+
if (next !== "") {
|
|
104
|
+
const endsInDigit = /[0-9]$/.test(name);
|
|
105
|
+
const versionish = next === "." || /[0-9]/.test(next);
|
|
106
|
+
if (versionish && endsInDigit) continue;
|
|
107
|
+
if (!versionish && !"-_@/:".includes(next)) continue;
|
|
108
|
+
}
|
|
109
|
+
if (best === undefined || name.length > best.length) best = { length: name.length, facts };
|
|
110
|
+
}
|
|
111
|
+
return best?.facts;
|
|
112
|
+
}
|
package/lib/sub2api/auth.js
CHANGED
|
@@ -94,7 +94,7 @@ export function isEmailTaken(error) {
|
|
|
94
94
|
/** Re-word a transport failure so the panel can say something actionable. */
|
|
95
95
|
function translateLogin(error) {
|
|
96
96
|
if (error instanceof Sub2ApiError && error.code === "network") {
|
|
97
|
-
return new Sub2ApiError("连不上
|
|
97
|
+
return new Sub2ApiError("连不上 dsh-sub2api,请检查网络或服务地址", { code: "network" });
|
|
98
98
|
}
|
|
99
99
|
return error;
|
|
100
100
|
}
|
package/lib/sub2api/catalog.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "../constants.js";
|
|
21
21
|
import { Sub2ApiError } from "../util.js";
|
|
22
22
|
import { BUILTIN_MODEL } from "../constants.js";
|
|
23
|
-
import {
|
|
23
|
+
import { registryFacts } from "../model-registry.js";
|
|
24
24
|
import { checkAvailability } from "./health.js";
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -213,7 +213,12 @@ export class ModelCatalog {
|
|
|
213
213
|
return { contextWindow: model.contextWindow, contextSource: "upstream" };
|
|
214
214
|
}
|
|
215
215
|
const known = knownContext(model.id);
|
|
216
|
-
if (known !== undefined)
|
|
216
|
+
if (known !== undefined) {
|
|
217
|
+
// `measured` and `open` are different confidence levels and the panel says
|
|
218
|
+
// so; both beat the default.
|
|
219
|
+
const origin = knownContextSource(model.id);
|
|
220
|
+
return { contextWindow: known, contextSource: origin === "open" ? "registry" : "known" };
|
|
221
|
+
}
|
|
217
222
|
|
|
218
223
|
return {
|
|
219
224
|
contextWindow: this.deps.defaultContextWindow?.() ?? DEFAULT_CONTEXT_WINDOW,
|
|
@@ -452,11 +457,11 @@ function normalizeOne(raw, id) {
|
|
|
452
457
|
* @returns {number | undefined}
|
|
453
458
|
*/
|
|
454
459
|
export function knownContext(id) {
|
|
455
|
-
//
|
|
456
|
-
//
|
|
457
|
-
//
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
460
|
+
// One table, two provenances: values measured against this gateway win over
|
|
461
|
+
// the open registry, which for this gateway has been wrong in both directions
|
|
462
|
+
// (it claimed 922,000 for a model that takes 524,288).
|
|
463
|
+
const facts = registryFacts(id);
|
|
464
|
+
if (facts !== undefined) return facts.contextWindow;
|
|
460
465
|
|
|
461
466
|
const lower = String(id).toLowerCase();
|
|
462
467
|
const hit = KNOWN_CONTEXT.find((entry) => lower.includes(entry.match));
|
|
@@ -464,12 +469,23 @@ export function knownContext(id) {
|
|
|
464
469
|
}
|
|
465
470
|
|
|
466
471
|
/**
|
|
467
|
-
*
|
|
472
|
+
* Where a resolved window came from, for the panel's badge.
|
|
473
|
+
* @param {string} id
|
|
474
|
+
* @returns {"measured"|"open"|undefined}
|
|
475
|
+
*/
|
|
476
|
+
export function knownContextSource(id) {
|
|
477
|
+
const facts = registryFacts(id);
|
|
478
|
+
if (facts !== undefined) return facts.source;
|
|
479
|
+
return KNOWN_CONTEXT.some((entry) => String(id).toLowerCase().includes(entry.match)) ? "measured" : undefined;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Max output tokens for `id`, when either source reported one.
|
|
468
484
|
* @param {string} id
|
|
469
485
|
* @returns {number | undefined}
|
|
470
486
|
*/
|
|
471
487
|
export function knownMaxTokens(id) {
|
|
472
|
-
return
|
|
488
|
+
return registryFacts(id)?.maxTokens;
|
|
473
489
|
}
|
|
474
490
|
|
|
475
491
|
/** A model id is the only reliable label; strip a provider prefix for display. */
|
package/lib/sub2api/session.js
CHANGED
|
@@ -84,7 +84,7 @@ export class SessionStore {
|
|
|
84
84
|
async accessToken(signal) {
|
|
85
85
|
const session = await this.read();
|
|
86
86
|
if (session === undefined) {
|
|
87
|
-
throw new Sub2ApiError("尚未登录
|
|
87
|
+
throw new Sub2ApiError("尚未登录 dsh-sub2api", { code: "not_logged_in" });
|
|
88
88
|
}
|
|
89
89
|
if (session.expiresAt > Date.now() + TOKEN_REFRESH_LEAD_MS || !session.refreshToken) {
|
|
90
90
|
return session.accessToken;
|
package/lib/tools.js
CHANGED
|
@@ -27,7 +27,7 @@ function statusTool(deps) {
|
|
|
27
27
|
return defineTool({
|
|
28
28
|
name: "sub2api_status",
|
|
29
29
|
description:
|
|
30
|
-
"查看
|
|
30
|
+
"查看 dsh-sub2api(sub.pscly.cc 中转站)在本机的接入状态:是否已登录、账号邮箱、余额、API 密钥是否已保存(只返回掩码)、订阅进度、已同步的模型数量。不会返回任何明文密钥。",
|
|
31
31
|
parameters: {},
|
|
32
32
|
output: {
|
|
33
33
|
schema: {
|
|
@@ -55,7 +55,7 @@ function statusTool(deps) {
|
|
|
55
55
|
if (stored === undefined) {
|
|
56
56
|
return {
|
|
57
57
|
ok: false,
|
|
58
|
-
message: `尚未登录
|
|
58
|
+
message: `尚未登录 dsh-sub2api。请让用户在 DSH 的 设置 → dsh-sub2api 面板用一个邮箱和密码完成登录或注册(插件会自动创建名为 dsh 的密钥)。站点:${deps.cfg().apiBase}`,
|
|
59
59
|
loggedIn: false,
|
|
60
60
|
hasKey: false,
|
|
61
61
|
modelCount: deps.catalog.visible().length,
|
|
@@ -93,7 +93,7 @@ function modelsTool(deps) {
|
|
|
93
93
|
return defineTool({
|
|
94
94
|
name: "sub2api_models",
|
|
95
95
|
description:
|
|
96
|
-
"列出
|
|
96
|
+
"列出 dsh-sub2api 中转站当前可用的模型 id(来自上游 /v1/models,与模型选择器一致)。需要先登录。返回 id、显示名、上下文窗口与是否支持图片。",
|
|
97
97
|
parameters: {
|
|
98
98
|
limit: {
|
|
99
99
|
type: "number",
|
|
@@ -133,7 +133,7 @@ function modelsTool(deps) {
|
|
|
133
133
|
if (models.length === 0) {
|
|
134
134
|
return {
|
|
135
135
|
ok: false,
|
|
136
|
-
message: "还没有同步到任何模型。请在 设置 →
|
|
136
|
+
message: "还没有同步到任何模型。请在 设置 → dsh-sub2api 面板登录后点「刷新模型」。",
|
|
137
137
|
count: 0,
|
|
138
138
|
models: [],
|
|
139
139
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Psapi (sub.pscly.cc) provider for DeepSeek Harness: zero-friction signup, auto-provisioned API key, upstream model sync, balance and recharge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|
package/lib/model-context.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context windows measured against the gateway, one entry per model id.
|
|
3
|
-
*
|
|
4
|
-
* Generated by `scripts/build-context-table.mjs` from a measurement run — do
|
|
5
|
-
* not edit by hand. `/v1/models` from sub2api returns only ids, so without this
|
|
6
|
-
* table every model would fall back to the default window, which is what made
|
|
7
|
-
* a 200k-context model advertise 128k in the picker.
|
|
8
|
-
*
|
|
9
|
-
* Measured 2026-11-20 against the configured gateway.
|
|
10
|
-
* 24 models.
|
|
11
|
-
*
|
|
12
|
-
* @type {Record<string, {contextWindow: number, maxTokens?: number}>}
|
|
13
|
-
*/
|
|
14
|
-
export const MEASURED_CONTEXT = {
|
|
15
|
-
"codex-auto-review": { contextWindow: 950272 },
|
|
16
|
-
"deepseek-flash": { contextWindow: 1048576 },
|
|
17
|
-
"deepseek-pro": { contextWindow: 1048576 },
|
|
18
|
-
"deepseek-v4-pro": { contextWindow: 1048576 },
|
|
19
|
-
"deepseek-v4.1-flash": { contextWindow: 1048576 },
|
|
20
|
-
"deepseek/deepseek-v4-pro": { contextWindow: 1048576 },
|
|
21
|
-
"deepseek/deepseek-v4.1-flash": { contextWindow: 1048576 },
|
|
22
|
-
"glm-5.3": { contextWindow: 1048576 },
|
|
23
|
-
"gpt-5.6-luna": { contextWindow: 950272 },
|
|
24
|
-
"gpt-5.6-sol": { contextWindow: 950272 },
|
|
25
|
-
"gpt-5.6-terra": { contextWindow: 950272 },
|
|
26
|
-
"gpt-6-astra": { contextWindow: 950272 },
|
|
27
|
-
"gpt-6-luna": { contextWindow: 950272 },
|
|
28
|
-
"gpt-6-sol": { contextWindow: 950272 },
|
|
29
|
-
"gpt-6.1-sol": { contextWindow: 950272 },
|
|
30
|
-
"gpt-6.1-terra": { contextWindow: 950272 },
|
|
31
|
-
"gpt-6.2-astra": { contextWindow: 524288 },
|
|
32
|
-
"gpt-6.2-sol": { contextWindow: 950272 },
|
|
33
|
-
"gpt-reserve": { contextWindow: 950272 },
|
|
34
|
-
"grok-4.7": { contextWindow: 131072 },
|
|
35
|
-
"muse-image": { contextWindow: 2097152 },
|
|
36
|
-
"muse-spark": { contextWindow: 2097152 },
|
|
37
|
-
"muse-video": { contextWindow: 262144 },
|
|
38
|
-
"qwen3.8-max": { contextWindow: 1015808 },
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Known facts for `id`, preferring the longest matching id.
|
|
43
|
-
*
|
|
44
|
-
* The gateway lists both `deepseek-v4-pro` and `deepseek/deepseek-v4-pro`; an
|
|
45
|
-
* exact hit wins, then the longest id that the requested one extends.
|
|
46
|
-
* @param {string} id
|
|
47
|
-
* @returns {{contextWindow: number, maxTokens?: number} | undefined}
|
|
48
|
-
*/
|
|
49
|
-
export function measuredContext(id) {
|
|
50
|
-
const key = String(id ?? "").trim();
|
|
51
|
-
if (key === "") return undefined;
|
|
52
|
-
const exact = MEASURED_CONTEXT[key];
|
|
53
|
-
if (exact !== undefined) return exact;
|
|
54
|
-
|
|
55
|
-
const lower = key.toLowerCase();
|
|
56
|
-
let best;
|
|
57
|
-
for (const [known, facts] of Object.entries(MEASURED_CONTEXT)) {
|
|
58
|
-
const name = known.toLowerCase();
|
|
59
|
-
if (!lower.startsWith(name)) continue;
|
|
60
|
-
if (best === undefined || name.length > best.length) best = { length: name.length, facts };
|
|
61
|
-
}
|
|
62
|
-
return best?.facts;
|
|
63
|
-
}
|