dsh-sub2api 0.5.0 → 0.6.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ - **Context windows are now measured, not guessed.** The gateway's `/v1/models`
6
+ returns ids only — no capacity field at all — so every model used to fall back
7
+ to the 128k default, which is what made a 950k-context model advertise 128k.
8
+ A probe against the live gateway measured 20 models (an oversized prompt is
9
+ rejected before generation with the limit; models that do not state a number
10
+ are bisected). `scripts/build-context-table.mjs` regenerates the table.
11
+ - Max output tokens are wired through the same table when the gateway reports
12
+ them, so the host stops sending an output cap the upstream rejects.
13
+ - The panel says how many models are still on the default and names them, so
14
+ "128k" can be told apart from "not measured yet"; each can be filled by hand.
15
+
16
+ ## 0.5.1
17
+
18
+ - Package metadata for the plugin market: `repository`, `homepage`, `bugs`,
19
+ `author`, and a 180×180 icon in `assets/`.
20
+
3
21
  ## 0.5.0
4
22
 
5
23
  - **`deepseek-flash` ships with the plugin.** A zero-balance account gets
package/README.md CHANGED
@@ -7,8 +7,15 @@
7
7
  ```
8
8
  npm: dsh-sub2api https://www.npmjs.com/package/dsh-sub2api
9
9
  repo: pscly/dsh-sub2api https://github.com/pscly/dsh-sub2api
10
+ 安装: dsh plugin add dsh-sub2api 需要 DSH ≥ 0.2.2-rc.1,装完重启 DSH
10
11
  ```
11
12
 
13
+ ![设置页面板](https://raw.githubusercontent.com/pscly/dsh-sub2api/main/assets/screenshots/panel.png)
14
+
15
+ 装好之后你不需要碰任何接口地址或密钥:**邮箱 + 密码**就够了。插件自己判断该登录还是注册,
16
+ 在账号下建一个名为 `dsh` 的密钥存档,把模型同步进选择器,并把余额、用量、订阅、兑换码、
17
+ 充值集中在一个面板里。
18
+
12
19
  ---
13
20
 
14
21
  ## 它解决什么
@@ -84,6 +91,8 @@ dsh plugin add dsh-sub2api
84
91
 
85
92
  插件在对话输入框的右下角(`conversation.input.right`)常驻一个小徽章:
86
93
 
94
+ ![余额徽章](https://raw.githubusercontent.com/pscly/dsh-sub2api/main/assets/screenshots/badge.png)
95
+
87
96
  ```
88
97
  ● ¥12.34 正常
89
98
  ● ¥3.00 偏低(< 5 元,琥珀色)
@@ -269,6 +278,38 @@ Cannot switch to sub2api/...: no context capacity; configure contextWindow on th
269
278
 
270
279
  ---
271
280
 
281
+ ## 上下文窗口从哪来
282
+
283
+ 网关的 `/v1/models` **只返回模型 id,一个容量字段都没有**(46 个模型全是这样)。所以插件必须自己知道这些数字,
284
+ 否则每个模型都只能按默认值显示——这也是「有些模型居然只有 128k」的原因。
285
+
286
+ 容量按这个顺序解析:
287
+
288
+ | 优先级 | 来源 | 面板标注 |
289
+ |---|---|---|
290
+ | 1 | 配置里强制指定 | — |
291
+ | 2 | 面板里手动填 | 手填 |
292
+ | 3 | 上游在 `/v1/models` 里声明 | — |
293
+ | 4 | **实测表** `lib/model-context.js` | 实测 |
294
+ | 5 | 默认值(默认 128000) | 默认 |
295
+
296
+ 实测表是**测出来的,不是抄的**:发一个超过模型容量的 prompt,服务端会在生成前拒绝并报出上限;
297
+ 不报数字的模型(比如 gpt 系列只说 "Your input exceeds the context window")就用二分法在「能过」和「过不了」之间逼近。
298
+ 脚本在 `scripts/build-context-table.mjs`,被拒的请求不计费。
299
+
300
+ 已知实测值(2026-11-20):
301
+
302
+ | 模型 | 上下文 |
303
+ |---|---|
304
+ | `deepseek-flash` / `deepseek-pro` / `deepseek-v4-pro` / `deepseek-v4.1-flash`(含 `deepseek/` 前缀别名) | 1,048,576 |
305
+ | `gpt-5.6-*` / `gpt-6-*` / `gpt-6.1-*` / `gpt-reserve` / `codex-auto-review` | 950,272 |
306
+ | `gpt-6.2-astra` | 524,288 |
307
+ | `qwen3.8-max` | 1,015,808 |
308
+ | `muse-image` | 2,097,152 |
309
+ | `muse-video` | 262,144 |
310
+
311
+ 面板里标「默认」的模型就是**没测到**的(上游当时不可用),会有一行提示列出来,点右侧数字可以手填。
312
+
272
313
  ## 自动重试
273
314
 
274
315
  回答还没吐出第一个字之前,插件会自动重试这几类失败:
Binary file
Binary file
Binary file
package/lib/adapter.js CHANGED
@@ -16,6 +16,7 @@
16
16
  import { LlmAdapter, attributionHeaders } from "@deepseek-ai/dsh-llm";
17
17
  import { PROVIDER } from "./constants.js";
18
18
  import { Sub2ApiError } from "./util.js";
19
+ import { knownMaxTokens } from "./sub2api/catalog.js";
19
20
 
20
21
  /** @type {Promise<any> | undefined} */
21
22
  let transportModule;
@@ -134,7 +135,11 @@ export class Sub2ApiAdapter extends LlmAdapter {
134
135
  /** @type {Record<string, unknown>} */
135
136
  const resolved = { provider, id: model, name: known?.name ?? model };
136
137
  if (known?.contextWindow !== undefined) resolved.context = { contextWindow: known.contextWindow };
137
- if (known?.maxTokens !== undefined) resolved.defaultMaxTokens = known.maxTokens;
138
+ // `/v1/models` never reports an output cap, so the measured table is the
139
+ // only source for it; without one the host would send our own default and
140
+ // the upstream would reject oversized `max_tokens` outright.
141
+ const maxTokens = known?.maxTokens ?? knownMaxTokens?.(model);
142
+ if (maxTokens !== undefined) resolved.defaultMaxTokens = maxTokens;
138
143
  if (known?.vision === true) resolved.inputModalities = ["text", "image"];
139
144
 
140
145
  // Declaring the levels is the only way the picker offers a thinking control:
package/lib/client.js CHANGED
@@ -1238,8 +1238,22 @@ window.__ModuleLoader__.load({
1238
1238
  saving ? "保存中…" : "保存选择")),
1239
1239
  ),
1240
1240
  )
1241
- : h("div", { style: T.hint },
1242
- `${shown.length} 个模型会出现在对话的选择器里;点「管理」可以增减或改上下文容量。`),
1241
+ : h("div", null,
1242
+ h("div", { style: T.hint },
1243
+ `${shown.length} 个模型会出现在对话的选择器里;点「管理」可以增减或改上下文容量。`),
1244
+ // The gateway's /v1/models reports no context window, so a model
1245
+ // outside the measured table silently advertises the default.
1246
+ // Saying how many are in that state is the only way a user can
1247
+ // tell "128k because that is the truth" from "128k because we
1248
+ // never measured it".
1249
+ (() => {
1250
+ const fallback = shown.filter((m) => m.contextSource === "default");
1251
+ if (fallback.length === 0) return null;
1252
+ return h("div", { style: { ...T.hint, marginTop: 6, color: C.warn } },
1253
+ `${fallback.length} 个模型不知道真实容量,暂按 ${Math.round((state.defaultContextWindow || 128000) / 1000)}k 显示:`,
1254
+ fallback.map((m) => m.id).join("、"),
1255
+ "。点右侧数字可以手动填。");
1256
+ })()),
1243
1257
  );
1244
1258
  }
1245
1259
 
@@ -0,0 +1,59 @@
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
+ * 20 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
+ "gpt-5.6-luna": { contextWindow: 950272 },
23
+ "gpt-5.6-sol": { contextWindow: 950272 },
24
+ "gpt-5.6-terra": { contextWindow: 950272 },
25
+ "gpt-6-astra": { contextWindow: 950272 },
26
+ "gpt-6-luna": { contextWindow: 950272 },
27
+ "gpt-6-sol": { contextWindow: 950272 },
28
+ "gpt-6.1-sol": { contextWindow: 950272 },
29
+ "gpt-6.1-terra": { contextWindow: 950272 },
30
+ "gpt-6.2-astra": { contextWindow: 524288 },
31
+ "gpt-reserve": { contextWindow: 950272 },
32
+ "muse-image": { contextWindow: 2097152 },
33
+ "muse-video": { contextWindow: 262144 },
34
+ "qwen3.8-max": { contextWindow: 1015808 },
35
+ };
36
+
37
+ /**
38
+ * Known facts for `id`, preferring the longest matching id.
39
+ *
40
+ * The gateway lists both `deepseek-v4-pro` and `deepseek/deepseek-v4-pro`; an
41
+ * exact hit wins, then the longest id that the requested one extends.
42
+ * @param {string} id
43
+ * @returns {{contextWindow: number, maxTokens?: number} | undefined}
44
+ */
45
+ export function measuredContext(id) {
46
+ const key = String(id ?? "").trim();
47
+ if (key === "") return undefined;
48
+ const exact = MEASURED_CONTEXT[key];
49
+ if (exact !== undefined) return exact;
50
+
51
+ const lower = key.toLowerCase();
52
+ let best;
53
+ for (const [known, facts] of Object.entries(MEASURED_CONTEXT)) {
54
+ const name = known.toLowerCase();
55
+ if (!lower.startsWith(name)) continue;
56
+ if (best === undefined || name.length > best.length) best = { length: name.length, facts };
57
+ }
58
+ return best?.facts;
59
+ }
package/lib/routes.js CHANGED
@@ -111,6 +111,8 @@ export function makeRoutes(deps) {
111
111
  currency: "CNY",
112
112
  version: version ?? "unknown",
113
113
  showSidebarQuota: cfg().showSidebarQuota,
114
+ // The panel names the default window when a model has no measured one.
115
+ defaultContextWindow: cfg().defaultContextWindow,
114
116
  };
115
117
 
116
118
  if (stored !== undefined) {
@@ -20,6 +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 { measuredContext } from "../model-context.js";
23
24
 
24
25
  /**
25
26
  * @typedef {object} ModelRecord
@@ -399,11 +400,26 @@ function normalizeOne(raw, id) {
399
400
  * @returns {number | undefined}
400
401
  */
401
402
  export function knownContext(id) {
403
+ // Measured against the gateway first: that table is generated from real
404
+ // limits. KNOWN_CONTEXT stays as the hand-written fallback for ids the
405
+ // measurement run could not reach.
406
+ const measured = measuredContext(id);
407
+ if (measured !== undefined) return measured.contextWindow;
408
+
402
409
  const lower = String(id).toLowerCase();
403
410
  const hit = KNOWN_CONTEXT.find((entry) => lower.includes(entry.match));
404
411
  return hit?.contextWindow;
405
412
  }
406
413
 
414
+ /**
415
+ * Max output tokens measured for `id`, when the gateway reported one.
416
+ * @param {string} id
417
+ * @returns {number | undefined}
418
+ */
419
+ export function knownMaxTokens(id) {
420
+ return measuredContext(id)?.maxTokens;
421
+ }
422
+
407
423
  /** A model id is the only reliable label; strip a provider prefix for display. */
408
424
  function displayName(id) {
409
425
  const tail = id.includes("/") ? id.slice(id.lastIndexOf("/") + 1) : id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
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",
@@ -14,6 +14,7 @@
14
14
  "CHANGELOG.md",
15
15
  "LICENSE",
16
16
  "README.md",
17
+ "assets",
17
18
  "cordis.patch.yml",
18
19
  "lib"
19
20
  ],
@@ -76,5 +77,17 @@
76
77
  "publishConfig": {
77
78
  "access": "public",
78
79
  "provenance": false
80
+ },
81
+ "repository": {
82
+ "type": "git",
83
+ "url": "git+https://github.com/pscly/dsh-sub2api.git"
84
+ },
85
+ "homepage": "https://github.com/pscly/dsh-sub2api#readme",
86
+ "bugs": {
87
+ "url": "https://github.com/pscly/dsh-sub2api/issues"
88
+ },
89
+ "author": {
90
+ "name": "pscly",
91
+ "url": "https://github.com/pscly"
79
92
  }
80
93
  }