dsh-sub2api 0.2.1 → 0.2.2

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.2
4
+
5
+ - Quote quota in yuan, which is what the site actually sells. The panel labelled
6
+ it 美元额度 and rendered every amount with `$`, but Sub2API prices one quota
7
+ unit as one yuan ("1 额度 = 1 元") and the recharge page grants 2 元 of quota
8
+ per 元 paid.
9
+ - The ratio is read from configuration (`rechargeMultiplier`, default 2) instead
10
+ of being hardcoded in the card, and `/status` plus the order response carry it
11
+ so the estimate and the host agree.
12
+
3
13
  ## 0.2.1
4
14
 
5
15
  - 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) ? "$" + n.toFixed(2) : "—";
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 * 2 : 0;
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 }, "1 元 = 2.00 美元额度"),
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
  ),
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) ? `$${n.toFixed(2)}` : "—";
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 { API_KEY_REF, KEY_NAME, MODELS_CACHE_FILE, PANEL_FILE, SELECTION_FILE } from "./constants.js";
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 nothing here is a
52
+ * dollar 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/routes.js CHANGED
@@ -60,6 +60,8 @@ 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",
63
65
  showSidebarQuota: cfg().showSidebarQuota,
64
66
  };
65
67
 
@@ -373,7 +375,11 @@ export function makeRoutes(deps) {
373
375
  if (Date.now() - value.createdAt > 40 * 60 * 1000) orders.delete(key);
374
376
  }
375
377
 
376
- return { checkoutUrl: order.checkoutUrl, orderNo: order.orderNo };
378
+ return {
379
+ checkoutUrl: order.checkoutUrl,
380
+ orderNo: order.orderNo,
381
+ multiplier: cfg().rechargeMultiplier,
382
+ };
377
383
  }),
378
384
 
379
385
  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.1",
3
+ "version": "0.2.2",
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",