dsh-sub2api 0.2.1 → 0.2.3
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 +18 -0
- package/README.md +2 -1
- package/lib/client.js +7 -6
- package/lib/commands.js +2 -1
- package/lib/config.js +15 -1
- package/lib/constants.js +14 -0
- package/lib/index.js +17 -0
- package/lib/routes.js +10 -3
- package/lib/schema.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
- Show the running build's version in the panel's 诊断 card. A fix that shipped
|
|
6
|
+
minutes ago and an install that never updated look identical in a screenshot;
|
|
7
|
+
now the version says which one it is.
|
|
8
|
+
- The 诊断 card and the diagnostic detail quote balances in ¥ like the rest of
|
|
9
|
+
the panel.
|
|
10
|
+
|
|
11
|
+
## 0.2.2
|
|
12
|
+
|
|
13
|
+
- Quote quota in yuan, which is what the site actually sells. The panel labelled
|
|
14
|
+
it 美元额度 and rendered every amount with `$`, but Sub2API prices one quota
|
|
15
|
+
unit as one yuan ("1 额度 = 1 元") and the recharge page grants 2 元 of quota
|
|
16
|
+
per 元 paid.
|
|
17
|
+
- The ratio is read from configuration (`rechargeMultiplier`, default 2) instead
|
|
18
|
+
of being hardcoded in the card, and `/status` plus the order response carry it
|
|
19
|
+
so the estimate and the host agree.
|
|
20
|
+
|
|
3
21
|
## 0.2.1
|
|
4
22
|
|
|
5
23
|
- Declare reasoning efforts so the picker actually offers a thinking control.
|
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ dsh plugin add dsh-sub2api
|
|
|
83
83
|
|
|
84
84
|
### 余额与充值
|
|
85
85
|
|
|
86
|
-
金额预设 + 自定义,按 `1 元 = 2
|
|
86
|
+
金额预设 + 自定义,按 `1 元 = 2 元额度` 实时显示预计到账(倍率来自配置,不是写死的)。点「去支付」在新标签页打开支付页,付款后自动轮询状态并刷新余额。下方是兑换码入口。
|
|
87
87
|
|
|
88
88
|
### 模型
|
|
89
89
|
|
|
@@ -155,6 +155,7 @@ Agent 工具(只读):`sub2api_status`、`sub2api_models`。模型可以回
|
|
|
155
155
|
| `visibleModels` | 全部 | 运营方统一指定可见模型(优先于面板选择) |
|
|
156
156
|
| `contextWindow` | 逐模型解析 | 强制覆盖**所有**模型的上下文窗口 |
|
|
157
157
|
| `defaultContextWindow` | 128000 | 上游未声明时的兜底值 |
|
|
158
|
+
| `rechargeMultiplier` | 2 | 每 1 元到账多少额度,仅用于面板预估;实际到账由支付站决定 |
|
|
158
159
|
| `showSidebarQuota` | false | 侧边栏余额卡片 |
|
|
159
160
|
| `autoProvision` | true | 登录后自动建 Key |
|
|
160
161
|
| `announceToAgent` | true | 向 agent 注入插件说明 |
|
package/lib/client.js
CHANGED
|
@@ -202,9 +202,10 @@ window.__ModuleLoader__.load({
|
|
|
202
202
|
h("span", { style: { flex: 1, minWidth: 0, color: C.text } }, children));
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/** Every amount is quoted in yuan: the site treats one quota unit as one yuan. */
|
|
205
206
|
function money(value) {
|
|
206
207
|
const n = Number(value);
|
|
207
|
-
return Number.isFinite(n) ? "
|
|
208
|
+
return Number.isFinite(n) ? "¥" + n.toFixed(2) : "—";
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
function asText(value) {
|
|
@@ -466,8 +467,9 @@ window.__ModuleLoader__.load({
|
|
|
466
467
|
const [redeemMsg, setRedeemMsg] = useState("");
|
|
467
468
|
const timer = useRef(null);
|
|
468
469
|
|
|
470
|
+
const multiplier = Number(state.rechargeMultiplier) > 0 ? Number(state.rechargeMultiplier) : 2;
|
|
469
471
|
const value = custom !== "" ? Number(custom) : amount;
|
|
470
|
-
const credit = Number.isFinite(value) ? value *
|
|
472
|
+
const credit = Number.isFinite(value) ? value * multiplier : 0;
|
|
471
473
|
const balance = state.profile ? Number(state.profile.balance) : NaN;
|
|
472
474
|
|
|
473
475
|
useEffect(() => {
|
|
@@ -523,7 +525,7 @@ window.__ModuleLoader__.load({
|
|
|
523
525
|
meta: Number.isFinite(balance) ? "当前 " + money(balance) : null,
|
|
524
526
|
},
|
|
525
527
|
h("div", { style: { ...T.row, marginBottom: 12 } },
|
|
526
|
-
h("span", { style: T.small },
|
|
528
|
+
h("span", { style: T.small }, `1 元 = ${multiplier.toFixed(2)} 元额度`),
|
|
527
529
|
h("span", { style: { ...T.hint, marginLeft: "auto" } },
|
|
528
530
|
Number.isFinite(balance) && balance <= 0 ? "余额为 0 时无法拉取模型" : ""),
|
|
529
531
|
),
|
|
@@ -826,10 +828,9 @@ window.__ModuleLoader__.load({
|
|
|
826
828
|
|
|
827
829
|
return h(Card, {
|
|
828
830
|
title: "诊断",
|
|
831
|
+
meta: state.version ? "v" + state.version : null,
|
|
829
832
|
aside: result
|
|
830
|
-
? h("span", {
|
|
831
|
-
style: { ...T.meta, marginLeft: "auto", color: result.ok ? C.ok : C.warn },
|
|
832
|
-
}, result.summary)
|
|
833
|
+
? h("span", { style: { ...T.meta, color: result.ok ? C.ok : C.warn } }, result.summary)
|
|
833
834
|
: null,
|
|
834
835
|
},
|
|
835
836
|
h("div", { style: T.row },
|
package/lib/commands.js
CHANGED
|
@@ -158,9 +158,10 @@ async function rechargeText(deps) {
|
|
|
158
158
|
].join("\n");
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/** Quota is yuan-denominated: one unit equals one yuan on this gateway. */
|
|
161
162
|
function money(value) {
|
|
162
163
|
const n = Number(value);
|
|
163
|
-
return Number.isFinite(n) ?
|
|
164
|
+
return Number.isFinite(n) ? `¥${n.toFixed(2)}` : "—";
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
function percent(value) {
|
package/lib/config.js
CHANGED
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
API_KEY_REF,
|
|
15
|
+
DEFAULT_RECHARGE_MULTIPLIER,
|
|
16
|
+
KEY_NAME,
|
|
17
|
+
MODELS_CACHE_FILE,
|
|
18
|
+
PANEL_FILE,
|
|
19
|
+
SELECTION_FILE,
|
|
20
|
+
} from "./constants.js";
|
|
14
21
|
import { normalizeBaseUrl } from "./util.js";
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -70,6 +77,7 @@ export function resolveConfig(config) {
|
|
|
70
77
|
visibleModels: toStringArray(field(config, "visibleModels", [])),
|
|
71
78
|
contextWindow: toPositiveInt(field(config, "contextWindow", undefined)),
|
|
72
79
|
defaultContextWindow: toPositiveInt(field(config, "defaultContextWindow", undefined)),
|
|
80
|
+
rechargeMultiplier: toMultiplier(field(config, "rechargeMultiplier", DEFAULT_RECHARGE_MULTIPLIER)),
|
|
73
81
|
reasoningModels: toStringArray(field(config, "reasoningModels", [])),
|
|
74
82
|
defaultReasoningEffort: String(field(config, "defaultReasoningEffort", "")).trim() || undefined,
|
|
75
83
|
autoProvision: field(config, "autoProvision", true) !== false,
|
|
@@ -77,6 +85,12 @@ export function resolveConfig(config) {
|
|
|
77
85
|
};
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
/** Coerce to a positive multiplier, falling back to the documented default. */
|
|
89
|
+
function toMultiplier(value) {
|
|
90
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
91
|
+
return Number.isFinite(n) && n > 0 ? n : DEFAULT_RECHARGE_MULTIPLIER;
|
|
92
|
+
}
|
|
93
|
+
|
|
80
94
|
/** Coerce to a positive integer, or undefined when it is not one. */
|
|
81
95
|
function toPositiveInt(value) {
|
|
82
96
|
const n = typeof value === "number" ? value : Number(value);
|
package/lib/constants.js
CHANGED
|
@@ -46,6 +46,20 @@ export const TOKEN_REFRESH_LEAD_MS = 60 * 1000;
|
|
|
46
46
|
/** Default page size when listing API keys. */
|
|
47
47
|
export const KEY_PAGE_SIZE = 100;
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Currency of every amount this plugin shows. Sub2API quotes quota in yuan and
|
|
51
|
+
* treats one quota unit as one yuan ("1 额度 = 1 元"), so the panel never uses a
|
|
52
|
+
* foreign-currency figure.
|
|
53
|
+
*/
|
|
54
|
+
export const CURRENCY_SYMBOL = "¥";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Quota units granted per yuan recharged. The pay centre applies this itself;
|
|
58
|
+
* the panel only mirrors it for the estimate, and the configuration can follow
|
|
59
|
+
* a different deployment.
|
|
60
|
+
*/
|
|
61
|
+
export const DEFAULT_RECHARGE_MULTIPLIER = 2;
|
|
62
|
+
|
|
49
63
|
/**
|
|
50
64
|
* Context window used when neither the endpoint nor the configuration says
|
|
51
65
|
* anything. DSH cannot compact a conversation without a capacity figure and
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { PROVIDER, PLUGIN_NAME, SETTINGS_NS } from "./constants.js";
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
13
14
|
import { resolveConfig } from "./config.js";
|
|
14
15
|
import { Sub2ApiAdapter } from "./adapter.js";
|
|
15
16
|
import { makeRoutes } from "./routes.js";
|
|
@@ -27,6 +28,21 @@ export const name = PLUGIN_NAME;
|
|
|
27
28
|
/** Services required before anything can mount. */
|
|
28
29
|
export const inject = ["llm"];
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* The running build's version, read from the package next to the module.
|
|
33
|
+
*
|
|
34
|
+
* The panel shows it, because "which version am I looking at" is otherwise
|
|
35
|
+
* unanswerable from a screenshot — and a fix that shipped ten minutes ago is
|
|
36
|
+
* indistinguishable from one that never arrived.
|
|
37
|
+
*/
|
|
38
|
+
export const VERSION = (() => {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
41
|
+
} catch {
|
|
42
|
+
return "unknown";
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
|
|
30
46
|
/** Order of the announcement section within the tool-guidance band. */
|
|
31
47
|
const SECTION_ORDER = 172;
|
|
32
48
|
|
|
@@ -159,6 +175,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
159
175
|
...deps,
|
|
160
176
|
cfg,
|
|
161
177
|
panel,
|
|
178
|
+
version: VERSION,
|
|
162
179
|
announceCatalog,
|
|
163
180
|
hostname: () => "dsh",
|
|
164
181
|
refreshCatalog: async (key) => {
|
package/lib/routes.js
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
* @returns {Array<{kind: "exact", path: string, handler: Function}>}
|
|
38
38
|
*/
|
|
39
39
|
export function makeRoutes(deps) {
|
|
40
|
-
const { api, session, catalog, cfg, logger, panel, announceCatalog } = deps;
|
|
40
|
+
const { api, session, catalog, cfg, logger, panel, announceCatalog, version } = deps;
|
|
41
41
|
|
|
42
42
|
/** Orders created by this process, keyed by the pay centre's order number. */
|
|
43
43
|
const orders = new Map();
|
|
@@ -60,6 +60,9 @@ export function makeRoutes(deps) {
|
|
|
60
60
|
keyMasked: maskSecret(apiKey),
|
|
61
61
|
models: catalog.snapshot(),
|
|
62
62
|
panel: panel.snapshot(),
|
|
63
|
+
rechargeMultiplier: cfg().rechargeMultiplier,
|
|
64
|
+
currency: "CNY",
|
|
65
|
+
version: version ?? "unknown",
|
|
63
66
|
showSidebarQuota: cfg().showSidebarQuota,
|
|
64
67
|
};
|
|
65
68
|
|
|
@@ -287,7 +290,7 @@ export function makeRoutes(deps) {
|
|
|
287
290
|
"profile",
|
|
288
291
|
"账号资料",
|
|
289
292
|
profile !== undefined,
|
|
290
|
-
profile === undefined ? "读取失败" : `余额
|
|
293
|
+
profile === undefined ? "读取失败" : `余额 ¥${Number.isFinite(balance) ? balance.toFixed(2) : "?"}`,
|
|
291
294
|
);
|
|
292
295
|
add(
|
|
293
296
|
"balance",
|
|
@@ -373,7 +376,11 @@ export function makeRoutes(deps) {
|
|
|
373
376
|
if (Date.now() - value.createdAt > 40 * 60 * 1000) orders.delete(key);
|
|
374
377
|
}
|
|
375
378
|
|
|
376
|
-
return {
|
|
379
|
+
return {
|
|
380
|
+
checkoutUrl: order.checkoutUrl,
|
|
381
|
+
orderNo: order.orderNo,
|
|
382
|
+
multiplier: cfg().rechargeMultiplier,
|
|
383
|
+
};
|
|
377
384
|
}),
|
|
378
385
|
|
|
379
386
|
defineRoute("POST", `${ROUTE_PREFIX}/recharge/status`, async (body) => {
|
package/lib/schema.js
CHANGED
|
@@ -32,6 +32,7 @@ export const Config = z.object({
|
|
|
32
32
|
visibleModels: z.array(z.string()).description("只在这些模型 id 中显示;留空显示全部").volatile(),
|
|
33
33
|
contextWindow: count("强制覆盖所有模型的上下文窗口;留空则逐模型解析"),
|
|
34
34
|
defaultContextWindow: count("上游没有声明上下文窗口时使用的兜底值(默认 128000)"),
|
|
35
|
+
rechargeMultiplier: z.natural().min(1).max(100).description("每 1 元到账多少额度,用于面板预估").volatile(),
|
|
35
36
|
reasoningModels: z.array(z.string()).description("额外声明支持思考等级的模型 id 片段").volatile(),
|
|
36
37
|
defaultReasoningEffort: text("", "默认思考等级(minimal/low/medium/high);留空由上游决定"),
|
|
37
38
|
showSidebarQuota: z.boolean().default(false).description("在侧边栏显示余额卡片").volatile(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Sub2API 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",
|