dsh-sub2api 0.2.0 → 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,24 @@
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
+
13
+ ## 0.2.1
14
+
15
+ - Declare reasoning efforts so the picker actually offers a thinking control.
16
+ The host only accepts an effort a model has declared, and the adapter declared
17
+ none, so the selector was empty. Known families (deepseek-v4/flash/reasoner,
18
+ gpt-5, o3/o4) now expose minimal/low/medium/high, the chosen level is merged
19
+ into the request body as `reasoning_effort`, and `reasoningModels` opts other
20
+ ids in without guessing at upstreams that would reject the field.
21
+
3
22
  ## 0.2.0 — feature complete
4
23
 
5
24
  - **每模型上下文修正**:面板里点容量数字即可手填,存在面板状态文件里,优先于上游声明。
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
 
@@ -98,6 +98,22 @@ dsh plugin add dsh-sub2api
98
98
 
99
99
  ---
100
100
 
101
+ ## 思考等级
102
+
103
+ 模型的思考档位由适配器**声明**,宿主只认声明过的 id——没声明就完全没有这个控件。插件对下列家族声明四档 `reasoning_effort`(极低 / 低 / 中 / 高):
104
+
105
+ `deepseek-v4*`、`deepseek-flash`、`deepseek-reasoner`、`deepseek-r1`、`gpt-5*`、`o3*`、`o4*`
106
+
107
+ 其它模型默认不给档位,因为无法确认上游认不认这个字段(认不出会忽略、也可能直接 400)。要让某个模型也出现档位,在配置里加:
108
+
109
+ ```yaml
110
+ llm-sub2api:
111
+ reasoningModels: ["glm-5", "kimi-k3"] # 按 id 片段匹配
112
+ defaultReasoningEffort: medium # 可选,留空则用上游默认
113
+ ```
114
+
115
+ 选中的档位会以 `{"reasoning_effort": "<id>"}` 合并进请求体,和采样参数走同一条路径。面板的模型列表里,支持档位的模型会标注「思考 4 档」。
116
+
101
117
  ## 命令与工具
102
118
 
103
119
  ```
@@ -139,6 +155,7 @@ Agent 工具(只读):`sub2api_status`、`sub2api_models`。模型可以回
139
155
  | `visibleModels` | 全部 | 运营方统一指定可见模型(优先于面板选择) |
140
156
  | `contextWindow` | 逐模型解析 | 强制覆盖**所有**模型的上下文窗口 |
141
157
  | `defaultContextWindow` | 128000 | 上游未声明时的兜底值 |
158
+ | `rechargeMultiplier` | 2 | 每 1 元到账多少额度,仅用于面板预估;实际到账由支付站决定 |
142
159
  | `showSidebarQuota` | false | 侧边栏余额卡片 |
143
160
  | `autoProvision` | true | 登录后自动建 Key |
144
161
  | `announceToAgent` | true | 向 agent 注入插件说明 |
package/lib/adapter.js CHANGED
@@ -136,6 +136,16 @@ export class Sub2ApiAdapter extends LlmAdapter {
136
136
  if (known?.contextWindow !== undefined) resolved.context = { contextWindow: known.contextWindow };
137
137
  if (known?.maxTokens !== undefined) resolved.defaultMaxTokens = known.maxTokens;
138
138
  if (known?.vision === true) resolved.inputModalities = ["text", "image"];
139
+
140
+ // Declaring the levels is the only way the picker offers a thinking control:
141
+ // the host rejects any effort a model has not declared.
142
+ const reasoning = this.deps.catalog.reasoningFor(model);
143
+ if (reasoning !== undefined) {
144
+ resolved.reasoning = {
145
+ efforts: reasoning.efforts.map((effort) => ({ id: effort.id, name: effort.name })),
146
+ ...(reasoning.defaultEffort === undefined ? {} : { defaultEffort: reasoning.defaultEffort }),
147
+ };
148
+ }
139
149
  return resolved;
140
150
  }
141
151
 
@@ -151,12 +161,21 @@ export class Sub2ApiAdapter extends LlmAdapter {
151
161
  }
152
162
 
153
163
  const model = route.models.find((entry) => entry.id === options.model);
164
+
165
+ // The transport forwards `sampling.body` verbatim, so the chosen level's
166
+ // fields have to land there; the host only validates the id.
167
+ const sampling = mergeSampling(route.sampling, model?.sampling, options);
168
+ const effort = selectedEffort(model, options.reasoningEffort);
169
+ if (effort !== undefined) {
170
+ sampling.body = { ...(sampling.body ?? {}), ...effort.body };
171
+ }
172
+
154
173
  /** @type {any} */
155
174
  const call = {
156
175
  options,
157
176
  route,
158
177
  model,
159
- sampling: mergeSampling(route.sampling, model?.sampling, options),
178
+ sampling,
160
179
  headers: safeAttributionHeaders(),
161
180
  };
162
181
 
@@ -186,6 +205,19 @@ export function mergeSampling(routeSampling, modelSampling, options) {
186
205
  return merged;
187
206
  }
188
207
 
208
+ /**
209
+ * The level a request selected, matched by id against the model's declared
210
+ * levels. An unknown id yields undefined rather than guessing.
211
+ * @param {any} model
212
+ * @param {unknown} id
213
+ */
214
+ export function selectedEffort(model, id) {
215
+ if (id === undefined || id === null) return undefined;
216
+ const levels = model?.reasoningLevels;
217
+ if (!Array.isArray(levels)) return undefined;
218
+ return levels.find((level) => String(level.id) === String(id));
219
+ }
220
+
189
221
  /** Read an optional host service without letting an absent one abort the call. */
190
222
  function optionalService(ctx, name) {
191
223
  try {
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
  ),
@@ -659,6 +661,10 @@ window.__ModuleLoader__.load({
659
661
  color: current.contextSource === "default" ? C.warn : C.muted, fontSize: 11.5,
660
662
  },
661
663
  }, contextBadge(current) ?? "设置"),
664
+ Array.isArray(current.reasoningEfforts)
665
+ ? h("span", { style: { ...T.hint, whiteSpace: "nowrap" } },
666
+ "思考 " + current.reasoningEfforts.length + " 档")
667
+ : null,
662
668
  shown.some((m) => m.id === model.id && m.vision) ? h("span", { style: T.hint }, "图片") : null,
663
669
  );
664
670
  }
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,11 +77,20 @@ 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)),
81
+ reasoningModels: toStringArray(field(config, "reasoningModels", [])),
82
+ defaultReasoningEffort: String(field(config, "defaultReasoningEffort", "")).trim() || undefined,
73
83
  autoProvision: field(config, "autoProvision", true) !== false,
74
84
  announceToAgent: field(config, "announceToAgent", true) !== false,
75
85
  };
76
86
  }
77
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
+
78
94
  /** Coerce to a positive integer, or undefined when it is not one. */
79
95
  function toPositiveInt(value) {
80
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
@@ -66,6 +80,34 @@ export const KNOWN_CONTEXT = [
66
80
  { match: "deepseek-flash", contextWindow: 1048576 },
67
81
  ];
68
82
 
83
+ /**
84
+ * The four selectable reasoning efforts of an OpenAI-compatible endpoint, from
85
+ * least to greatest. `body` is merged into the request when one is selected.
86
+ */
87
+ export const STANDARD_EFFORTS = [
88
+ { id: "minimal", name: "极低", body: { reasoning_effort: "minimal" } },
89
+ { id: "low", name: "低", body: { reasoning_effort: "low" } },
90
+ { id: "medium", name: "中", body: { reasoning_effort: "medium" } },
91
+ { id: "high", name: "高", body: { reasoning_effort: "high" } },
92
+ ];
93
+
94
+ /**
95
+ * Model id fragments whose upstream accepts `reasoning_effort`.
96
+ *
97
+ * Only families with a documented or observed mapping belong here: an endpoint
98
+ * that does not know the field either ignores it (the selector then lies) or
99
+ * rejects the request. Anything else can be opted in through `reasoningModels`.
100
+ */
101
+ export const REASONING_HINTS = [
102
+ "deepseek-v4",
103
+ "deepseek-flash",
104
+ "deepseek-reasoner",
105
+ "deepseek-r1",
106
+ "gpt-5",
107
+ "o3",
108
+ "o4",
109
+ ];
110
+
69
111
  /** Model id fragments that mark an image-capable model when the endpoint says nothing. */
70
112
  export const VISION_HINTS = [
71
113
  "gpt-4o",
package/lib/index.js CHANGED
@@ -90,6 +90,8 @@ export function apply(ctx, rawConfig = {}) {
90
90
  contextOverride: (id) => panel.contextOverride(id),
91
91
  contextWindow: () => cfg().contextWindow,
92
92
  defaultContextWindow: () => cfg().defaultContextWindow,
93
+ reasoningModels: () => cfg().reasoningModels,
94
+ defaultReasoningEffort: () => cfg().defaultReasoningEffort,
93
95
  apiKey: () => session.apiKey(),
94
96
  logger,
95
97
  });
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,9 @@ 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(),
36
+ reasoningModels: z.array(z.string()).description("额外声明支持思考等级的模型 id 片段").volatile(),
37
+ defaultReasoningEffort: text("", "默认思考等级(minimal/low/medium/high);留空由上游决定"),
35
38
  showSidebarQuota: z.boolean().default(false).description("在侧边栏显示余额卡片").volatile(),
36
39
  autoProvision: z.boolean().default(true).description("登录后自动创建并保存密钥").volatile(),
37
40
  announceToAgent: z.boolean().default(true).description("向 agent 注入插件说明").volatile(),
@@ -10,7 +10,14 @@
10
10
 
11
11
  import { mkdir, readFile, writeFile } from "node:fs/promises";
12
12
  import { dirname } from "node:path";
13
- import { CATALOG_TTL_MS, DEFAULT_CONTEXT_WINDOW, KNOWN_CONTEXT, VISION_HINTS } from "../constants.js";
13
+ import {
14
+ CATALOG_TTL_MS,
15
+ DEFAULT_CONTEXT_WINDOW,
16
+ KNOWN_CONTEXT,
17
+ REASONING_HINTS,
18
+ STANDARD_EFFORTS,
19
+ VISION_HINTS,
20
+ } from "../constants.js";
14
21
  import { Sub2ApiError } from "../util.js";
15
22
 
16
23
  /**
@@ -149,6 +156,30 @@ export class ModelCatalog {
149
156
  return this.deps.selection?.() ?? [];
150
157
  }
151
158
 
159
+ /**
160
+ * Reasoning levels this model accepts, when the upstream is known to
161
+ * understand `reasoning_effort`. Declaring none is what makes the selector
162
+ * offer no thinking control at all.
163
+ * @param {string} id
164
+ * @returns {{efforts: Array<{id: string, name: string, body: Record<string, unknown>}>, defaultEffort?: string} | undefined}
165
+ */
166
+ reasoningFor(id) {
167
+ const lower = String(id).toLowerCase();
168
+ const forced = (this.deps.reasoningModels?.() ?? []).some(
169
+ (entry) => entry === id || lower.includes(String(entry).toLowerCase()),
170
+ );
171
+ const known = REASONING_HINTS.some((hint) => lower.includes(hint));
172
+ if (!forced && !known) return undefined;
173
+
174
+ const efforts = STANDARD_EFFORTS.map((effort) => ({
175
+ id: effort.id,
176
+ name: effort.name,
177
+ body: { ...effort.body },
178
+ }));
179
+ const preferred = this.deps.defaultReasoningEffort?.();
180
+ return preferred === undefined ? { efforts } : { efforts, defaultEffort: preferred };
181
+ }
182
+
152
183
  /**
153
184
  * Where a model's capacity came from, in precedence order.
154
185
  * @param {ModelRecord} model
@@ -201,6 +232,11 @@ export class ModelCatalog {
201
232
  if (model.contextWindow !== undefined) entry.contextWindow = model.contextWindow;
202
233
  if (model.maxTokens !== undefined) entry.maxTokens = model.maxTokens;
203
234
  if (model.vision === true) entry.vision = true;
235
+ const reasoning = this.reasoningFor(model.id);
236
+ if (reasoning !== undefined) {
237
+ entry.reasoningLevels = reasoning.efforts;
238
+ if (reasoning.defaultEffort !== undefined) entry.defaultReasoning = reasoning.defaultEffort;
239
+ }
204
240
  return entry;
205
241
  });
206
242
  }
@@ -235,6 +271,7 @@ export class ModelCatalog {
235
271
  contextWindow: model.contextWindow ?? null,
236
272
  contextSource: model.contextSource ?? null,
237
273
  maxTokens: model.maxTokens ?? null,
274
+ reasoningEfforts: this.reasoningFor(model.id)?.efforts.map((e) => e.name) ?? null,
238
275
  vision: model.vision === true,
239
276
  ownedBy: model.ownedBy ?? null,
240
277
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.2.0",
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",