dsh-sub2api 0.11.1 → 0.12.0
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 +13 -0
- package/README.md +14 -1
- package/lib/client.js +13 -8
- package/lib/config.js +25 -1
- package/lib/routes.js +19 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
- **Works with any sub2api deployment, not just the one this plugin ships with.**
|
|
6
|
+
It always did technically — every call goes through the gateway's own API and
|
|
7
|
+
`apiBase` was configurable — but the README and the package description read
|
|
8
|
+
like a vendor plugin, which hid that from the people running their own
|
|
9
|
+
sub2api. Both now say so, and the self-hosted path is covered by tests.
|
|
10
|
+
- **An explicit empty `payBase` now means "no pay centre", and stays empty.**
|
|
11
|
+
It used to fall back to the default payment page, which would have pointed a
|
|
12
|
+
self-hosted user at a page that cannot know their account. The panel hides the
|
|
13
|
+
recharge card and the recharge routes answer with a sentence instead of
|
|
14
|
+
building a link from nothing.
|
|
15
|
+
|
|
3
16
|
## 0.11.1
|
|
4
17
|
|
|
5
18
|
- Discoverability. The package description and keywords now lead with the terms
|
package/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# dsh-sub2api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在 DeepSeek Harness 里接入 [sub2api](https://github.com/Wei-Shaw/sub2api) 网关。装完填一次邮箱和密码就能用。
|
|
4
|
+
|
|
5
|
+
**两种用法,同一个插件:**
|
|
6
|
+
|
|
7
|
+
- **用 Psapi 公共网关** —— 默认就是 `sub.svpai.net`,装上直接登录,不用配任何东西。
|
|
8
|
+
- **用你自己部署的 sub2api** —— 在设置里把「中转站地址」改成你的域名即可,其余功能完全一样(登录注册、自动建密钥、模型同步、余额、充值、兑换码)。
|
|
9
|
+
|
|
10
|
+
> sub2api 本身是开源网关,很多人在自建。这个插件不绑定任何一家:登录、密钥、模型目录、余额和充值全部通过网关自己的接口完成,所以只要对方跑的是 sub2api,就能用。
|
|
11
|
+
|
|
12
|
+
自建时如果没部署配套的支付站,把「充值地址」留空即可 —— 余额、模型、密钥这些照常工作,只是不显示充值入口。
|
|
4
13
|
|
|
5
14
|
装完只需在 **设置 → dsh-sub2api** 填入一次邮箱和密码,其余全部自动完成:
|
|
6
15
|
|
|
@@ -291,6 +300,10 @@ Cannot switch to sub2api/...: no context capacity; configure contextWindow on th
|
|
|
291
300
|
|
|
292
301
|
## 上下文窗口从哪来
|
|
293
302
|
|
|
303
|
+
> 实测数据与测量方法整理成了独立页面:[24 个模型的上下文上限实测](docs/context-windows.md)
|
|
304
|
+
>(也可以直接看[网页版](docs/context-windows.html))
|
|
305
|
+
|
|
306
|
+
|
|
294
307
|
网关的 `/v1/models` **只返回模型 id,一个容量字段都没有**(46 个模型全是这样)。所以插件必须自己知道这些数字,
|
|
295
308
|
否则每个模型都只能按默认值显示——这也是「有些模型居然只有 128k」的原因。
|
|
296
309
|
|
package/lib/client.js
CHANGED
|
@@ -1506,14 +1506,19 @@ window.__ModuleLoader__.load({
|
|
|
1506
1506
|
onGoRecharge: () => { setOpen((prev) => ({ ...prev, recharge: true })); },
|
|
1507
1507
|
})),
|
|
1508
1508
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1509
|
+
// A gateway with no pay centre has nothing to recharge here, and an
|
|
1510
|
+
// entry that always fails is worse than no entry. `canRecharge` is the
|
|
1511
|
+
// host's answer to "did anyone configure one".
|
|
1512
|
+
state.canRecharge === false
|
|
1513
|
+
? null
|
|
1514
|
+
: h(Collapsible, {
|
|
1515
|
+
id: "sub2api-recharge",
|
|
1516
|
+
title: "充值",
|
|
1517
|
+
meta: Number.isFinite(balance) ? `余额 ${money(balance)}` : null,
|
|
1518
|
+
open: open.recharge,
|
|
1519
|
+
onToggle: () => toggle("recharge"),
|
|
1520
|
+
},
|
|
1521
|
+
h(RechargeDetail, { state, pending, onRecharge, onPoll, onRefresh, onRedeem })),
|
|
1517
1522
|
|
|
1518
1523
|
h(Collapsible, {
|
|
1519
1524
|
title: "API 密钥",
|
package/lib/config.js
CHANGED
|
@@ -89,13 +89,37 @@ function followMovedHost(url) {
|
|
|
89
89
|
return parsed.toString().replace(/\/+$/, "");
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Where the recharge page lives, with "explicitly none" respected.
|
|
94
|
+
*
|
|
95
|
+
* Absent means "use the gateway this plugin ships for"; empty means "there is
|
|
96
|
+
* no pay centre here". Those are different answers and the panel shows a
|
|
97
|
+
* different thing for each.
|
|
98
|
+
* @param {any} config raw or volatile configuration
|
|
99
|
+
* @returns {string}
|
|
100
|
+
*/
|
|
101
|
+
function resolvePayBase(config) {
|
|
102
|
+
// Read the raw value, not through `field`: that helper treats "" as "absent",
|
|
103
|
+
// which is exactly the distinction being made here.
|
|
104
|
+
let raw = config?.["payBase"];
|
|
105
|
+
if (raw !== null && typeof raw === "object" && typeof raw.get === "function") raw = raw.get();
|
|
106
|
+
if (raw === undefined || raw === null) return "https://pay.svpai.net";
|
|
107
|
+
const text = String(raw).trim();
|
|
108
|
+
if (text === "") return "";
|
|
109
|
+
return followMovedHost(normalizeBaseUrl(text));
|
|
110
|
+
}
|
|
111
|
+
|
|
92
112
|
export function resolveConfig(config) {
|
|
93
113
|
const dshHome = process.env.DSH_HOME ?? join(homedir(), ".dsh");
|
|
94
114
|
const configuredKeyName = String(field(config, "keyName", "")).trim();
|
|
95
115
|
|
|
96
116
|
return {
|
|
97
117
|
apiBase: followMovedHost(normalizeBaseUrl(field(config, "apiBase", "https://sub.svpai.net"))),
|
|
98
|
-
payBase
|
|
118
|
+
// An explicitly empty payBase means "this gateway has no pay centre", and
|
|
119
|
+
// must stay empty. Falling back to the default here would point a
|
|
120
|
+
// self-hosted user at a payment page that cannot possibly know their
|
|
121
|
+
// account, which is worse than showing no recharge button at all.
|
|
122
|
+
payBase: resolvePayBase(config),
|
|
99
123
|
apiKeyEnv: String(field(config, "apiKeyEnv", API_KEY_REF)),
|
|
100
124
|
groupId: toPositiveInt(field(config, "groupId", undefined)),
|
|
101
125
|
keyName: configuredKeyName === "" ? KEY_NAME : configuredKeyName,
|
package/lib/routes.js
CHANGED
|
@@ -100,6 +100,7 @@ export function makeRoutes(deps) {
|
|
|
100
100
|
const view = {
|
|
101
101
|
apiBase: cfg().apiBase,
|
|
102
102
|
payBase: cfg().payBase,
|
|
103
|
+
canRecharge: typeof cfg().payBase === "string" && cfg().payBase !== "",
|
|
103
104
|
keyName: cfg().keyName,
|
|
104
105
|
loggedIn: stored !== undefined,
|
|
105
106
|
email: stored?.email ?? stored?.user?.email ?? null,
|
|
@@ -131,6 +132,22 @@ export function makeRoutes(deps) {
|
|
|
131
132
|
return view;
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/**
|
|
136
|
+
* A gateway without a pay centre cannot recharge. Saying so is the honest
|
|
137
|
+
* answer; building a URL from an empty base produces a broken link to whatever
|
|
138
|
+
* host happens to parse it.
|
|
139
|
+
* @returns {string} the pay centre base
|
|
140
|
+
*/
|
|
141
|
+
function requirePayBase() {
|
|
142
|
+
const base = cfg().payBase;
|
|
143
|
+
if (typeof base !== "string" || base === "") {
|
|
144
|
+
throw new Sub2ApiError("这个网关没有配置充值站点,无法在线充值;请联系站点管理员", {
|
|
145
|
+
code: "no_pay_center",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return base;
|
|
149
|
+
}
|
|
150
|
+
|
|
134
151
|
return [
|
|
135
152
|
defineRoute("GET", `${ROUTE_PREFIX}/status`, async () => status()),
|
|
136
153
|
|
|
@@ -451,6 +468,7 @@ export function makeRoutes(deps) {
|
|
|
451
468
|
|
|
452
469
|
/** Recharge level 1: a signed-in URL the browser opens in a new tab. */
|
|
453
470
|
defineRoute("POST", `${ROUTE_PREFIX}/recharge/link`, async (body) => {
|
|
471
|
+
requirePayBase();
|
|
454
472
|
const stored = await session.read();
|
|
455
473
|
const token = await session.accessToken();
|
|
456
474
|
const userId = stored?.user?.id;
|
|
@@ -470,6 +488,7 @@ export function makeRoutes(deps) {
|
|
|
470
488
|
|
|
471
489
|
/** Recharge level 2: choose the amount here and land straight on checkout. */
|
|
472
490
|
defineRoute("POST", `${ROUTE_PREFIX}/recharge`, async (body) => {
|
|
491
|
+
requirePayBase();
|
|
473
492
|
const stored = await session.read();
|
|
474
493
|
const token = await session.accessToken();
|
|
475
494
|
const userId = stored?.user?.id;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Sub2API
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "Sub2API provider for DeepSeek Harness (DSH): email sign-in, automatic API key and model provisioning, one panel for balance and recharge. Works with the hosted gateway or your own sub2api deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
7
7
|
"main": "./lib/index.js",
|