dsh-sub2api 0.1.6 → 0.1.7
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 +11 -0
- package/README.md +19 -0
- package/lib/client.js +20 -0
- package/lib/config.js +1 -0
- package/lib/constants.js +20 -0
- package/lib/index.js +1 -0
- package/lib/schema.js +2 -1
- package/lib/sub2api/catalog.js +37 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.7
|
|
4
|
+
|
|
5
|
+
- Always report a context window. The host refuses to switch to a model it
|
|
6
|
+
cannot size ("no context capacity for <route>; configure contextWindow on
|
|
7
|
+
that adapter model"), and `/v1/models` usually omits `context_length` because
|
|
8
|
+
it is the upstream's response passed through. The adapter now resolves one
|
|
9
|
+
through config → upstream → measured table → `defaultContextWindow` (128000),
|
|
10
|
+
and the panel labels where the figure came from.
|
|
11
|
+
- `deepseek-flash` / `deepseek-v4.1-flash` are pinned to 1,048,576 from the
|
|
12
|
+
measurement on this gateway.
|
|
13
|
+
|
|
3
14
|
## 0.1.6
|
|
4
15
|
|
|
5
16
|
- Make the chat model picker see a fresh catalog. It rebuilds itself from
|
package/README.md
CHANGED
|
@@ -124,6 +124,25 @@ dsh plugin --profile desktop add dsh-sub2api
|
|
|
124
124
|
- 日志与错误信息不包含 token、密钥或密码。
|
|
125
125
|
- 支付链接里的 `token` 是 sub2api 的访问令牌,只在用户点「去支付」时生成,不写日志、不落盘。
|
|
126
126
|
|
|
127
|
+
## 上下文窗口
|
|
128
|
+
|
|
129
|
+
DSH 在切换模型前要算上下文容量,拿不到就直接拒绝:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Cannot switch to sub2api/...: no context capacity; configure contextWindow on that adapter model
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`/v1/models` 透传的是上游响应,多数上游**不带 `context_length`**,所以插件自己补一个,回退链是:
|
|
136
|
+
|
|
137
|
+
1. 配置里的 `contextWindow`(对所有模型生效)
|
|
138
|
+
2. 上游声明的 `context_length` / `context_window`
|
|
139
|
+
3. 实测表(目前只有 `deepseek-flash` / `deepseek-v4.1-flash` = 1,048,576,来自本站实测)
|
|
140
|
+
4. `defaultContextWindow`,默认 **128000**
|
|
141
|
+
|
|
142
|
+
面板的模型列表里会标出容量来源:`128k · 默认` 表示是兜底值,`1049k · 实测` 表示来自实测表,没有标记表示上游自己声明的。
|
|
143
|
+
|
|
144
|
+
> 兜底值只是让对话能跑起来。如果某个模型实际容量更大,把它写进配置的 `contextWindow`,或者告诉我加进实测表——填大了上游会 400,填小了会提前压缩。
|
|
145
|
+
|
|
127
146
|
## 选择对话里显示哪些模型
|
|
128
147
|
|
|
129
148
|
上游一个中转站往往有几十个模型,全部塞进选择器既难找也容易选错。面板的「模型 → 选择模型」里可以勾选要用的那几个:
|
package/lib/client.js
CHANGED
|
@@ -499,6 +499,25 @@ window.__ModuleLoader__.load({
|
|
|
499
499
|
|
|
500
500
|
// ------------------------------------------------------------ models
|
|
501
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Show the capacity the host will actually use, and say where it came from:
|
|
504
|
+
* a defaulted figure is the difference between "chat works" and "the model
|
|
505
|
+
* cannot be switched to".
|
|
506
|
+
*/
|
|
507
|
+
function contextBadge(model) {
|
|
508
|
+
if (!model || !model.contextWindow) return null;
|
|
509
|
+
const k = Math.round(Number(model.contextWindow) / 1000);
|
|
510
|
+
const source = model.contextSource;
|
|
511
|
+
const label = source === "default" ? "默认" : source === "known" ? "实测" : null;
|
|
512
|
+
return h("span", {
|
|
513
|
+
style: {
|
|
514
|
+
fontSize: 11.5,
|
|
515
|
+
color: source === "default" ? C.warn : C.muted,
|
|
516
|
+
whiteSpace: "nowrap",
|
|
517
|
+
},
|
|
518
|
+
}, k + "k" + (label ? " · " + label : ""));
|
|
519
|
+
}
|
|
520
|
+
|
|
502
521
|
function ModelsCard({ state, busy, onRefreshModels, onReload, onGoRecharge }) {
|
|
503
522
|
const models = state.models || { models: [], all: [], allowed: [], fetchedAt: 0, stale: false, error: null };
|
|
504
523
|
const shown = models.models || [];
|
|
@@ -615,6 +634,7 @@ window.__ModuleLoader__.load({
|
|
|
615
634
|
onChange: () => toggle(model.id),
|
|
616
635
|
}),
|
|
617
636
|
h("code", { style: { ...T.mono, flex: "1 1 auto", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis" } }, model.id),
|
|
637
|
+
contextBadge(shown.find((m) => m.id === model.id) ?? model),
|
|
618
638
|
shown.some((m) => m.id === model.id && m.vision) ? h("span", { style: T.hint }, "图片") : null,
|
|
619
639
|
),
|
|
620
640
|
)),
|
package/lib/config.js
CHANGED
|
@@ -68,6 +68,7 @@ export function resolveConfig(config) {
|
|
|
68
68
|
showSidebarQuota: field(config, "showSidebarQuota", false) === true,
|
|
69
69
|
visibleModels: toStringArray(field(config, "visibleModels", [])),
|
|
70
70
|
contextWindow: toPositiveInt(field(config, "contextWindow", undefined)),
|
|
71
|
+
defaultContextWindow: toPositiveInt(field(config, "defaultContextWindow", undefined)),
|
|
71
72
|
autoProvision: field(config, "autoProvision", true) !== false,
|
|
72
73
|
announceToAgent: field(config, "announceToAgent", true) !== false,
|
|
73
74
|
};
|
package/lib/constants.js
CHANGED
|
@@ -43,6 +43,26 @@ export const TOKEN_REFRESH_LEAD_MS = 60 * 1000;
|
|
|
43
43
|
/** Default page size when listing API keys. */
|
|
44
44
|
export const KEY_PAGE_SIZE = 100;
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Context window used when neither the endpoint nor the configuration says
|
|
48
|
+
* anything. DSH cannot compact a conversation without a capacity figure and
|
|
49
|
+
* refuses to switch to such a model, so "unknown" is not an option the adapter
|
|
50
|
+
* can afford to return.
|
|
51
|
+
*/
|
|
52
|
+
export const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Context windows measured against this gateway, keyed by model id fragment.
|
|
56
|
+
* Only families with direct evidence belong here: a figure larger than the real
|
|
57
|
+
* limit turns every long request into a 400, and a smaller one compacts early.
|
|
58
|
+
*/
|
|
59
|
+
export const KNOWN_CONTEXT = [
|
|
60
|
+
// Measured on sub.pscly.cc: 897,791 tokens accepted, 1,050,041 rejected with
|
|
61
|
+
// "maximum context length is 1048576 tokens".
|
|
62
|
+
{ match: "deepseek-v4.1-flash", contextWindow: 1048576 },
|
|
63
|
+
{ match: "deepseek-flash", contextWindow: 1048576 },
|
|
64
|
+
];
|
|
65
|
+
|
|
46
66
|
/** Model id fragments that mark an image-capable model when the endpoint says nothing. */
|
|
47
67
|
export const VISION_HINTS = [
|
|
48
68
|
"gpt-4o",
|
package/lib/index.js
CHANGED
|
@@ -86,6 +86,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
86
86
|
visibleModels: () => cfg().visibleModels,
|
|
87
87
|
selection: () => selection.current(),
|
|
88
88
|
contextWindow: () => cfg().contextWindow,
|
|
89
|
+
defaultContextWindow: () => cfg().defaultContextWindow,
|
|
89
90
|
apiKey: () => session.apiKey(),
|
|
90
91
|
logger,
|
|
91
92
|
});
|
package/lib/schema.js
CHANGED
|
@@ -30,7 +30,8 @@ export const Config = z.object({
|
|
|
30
30
|
streamIdleTimeoutMs: count("流式请求空闲超时(毫秒)").default(300000),
|
|
31
31
|
modelsCachePath: text("", "模型目录缓存路径;留空使用 $DSH_HOME/sub2api-models.json"),
|
|
32
32
|
visibleModels: z.array(z.string()).description("只在这些模型 id 中显示;留空显示全部").volatile(),
|
|
33
|
-
contextWindow: count("
|
|
33
|
+
contextWindow: count("强制覆盖所有模型的上下文窗口;留空则逐模型解析"),
|
|
34
|
+
defaultContextWindow: count("上游没有声明上下文窗口时使用的兜底值(默认 128000)"),
|
|
34
35
|
showSidebarQuota: z.boolean().default(false).description("在侧边栏显示余额卡片").volatile(),
|
|
35
36
|
autoProvision: z.boolean().default(true).description("登录后自动创建并保存密钥").volatile(),
|
|
36
37
|
announceToAgent: z.boolean().default(true).description("向 agent 注入插件说明").volatile(),
|
package/lib/sub2api/catalog.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
12
12
|
import { dirname } from "node:path";
|
|
13
|
-
import { CATALOG_TTL_MS, VISION_HINTS } from "../constants.js";
|
|
13
|
+
import { CATALOG_TTL_MS, DEFAULT_CONTEXT_WINDOW, KNOWN_CONTEXT, VISION_HINTS } from "../constants.js";
|
|
14
14
|
import { Sub2ApiError } from "../util.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -149,15 +149,35 @@ export class ModelCatalog {
|
|
|
149
149
|
return this.deps.selection?.() ?? [];
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* Models as the picker should see them: allowlist applied and a context
|
|
154
|
+
* window always resolved.
|
|
155
|
+
*
|
|
156
|
+
* A model with no capacity figure is unusable here: the host's compaction
|
|
157
|
+
* refuses to switch to it ("no context capacity for <route>"), so the fall
|
|
158
|
+
* back chain is config → upstream → measured table → conservative default,
|
|
159
|
+
* and `contextSource` records which one answered.
|
|
160
|
+
*/
|
|
153
161
|
visible() {
|
|
154
162
|
const allow = this.allowed();
|
|
155
163
|
const forcedContext = this.deps.contextWindow();
|
|
164
|
+
const fallback = this.deps.defaultContextWindow?.() ?? DEFAULT_CONTEXT_WINDOW;
|
|
165
|
+
|
|
156
166
|
return this.models
|
|
157
167
|
.filter((model) => allow.length === 0 || allow.includes(model.id))
|
|
158
|
-
.map((model) =>
|
|
159
|
-
forcedContext
|
|
160
|
-
|
|
168
|
+
.map((model) => {
|
|
169
|
+
if (forcedContext !== undefined) {
|
|
170
|
+
return { ...model, contextWindow: forcedContext, contextSource: "config" };
|
|
171
|
+
}
|
|
172
|
+
if (model.contextWindow !== undefined) {
|
|
173
|
+
return { ...model, contextSource: "upstream" };
|
|
174
|
+
}
|
|
175
|
+
const known = knownContext(model.id);
|
|
176
|
+
if (known !== undefined) {
|
|
177
|
+
return { ...model, contextWindow: known, contextSource: "known" };
|
|
178
|
+
}
|
|
179
|
+
return { ...model, contextWindow: fallback, contextSource: "default" };
|
|
180
|
+
});
|
|
161
181
|
}
|
|
162
182
|
|
|
163
183
|
/**
|
|
@@ -203,6 +223,7 @@ export class ModelCatalog {
|
|
|
203
223
|
id: model.id,
|
|
204
224
|
name: model.name,
|
|
205
225
|
contextWindow: model.contextWindow ?? null,
|
|
226
|
+
contextSource: model.contextSource ?? null,
|
|
206
227
|
maxTokens: model.maxTokens ?? null,
|
|
207
228
|
vision: model.vision === true,
|
|
208
229
|
ownedBy: model.ownedBy ?? null,
|
|
@@ -292,6 +313,17 @@ function normalizeOne(raw, id) {
|
|
|
292
313
|
return record;
|
|
293
314
|
}
|
|
294
315
|
|
|
316
|
+
/**
|
|
317
|
+
* A measured context window for a known family, when the endpoint omits one.
|
|
318
|
+
* @param {string} id
|
|
319
|
+
* @returns {number | undefined}
|
|
320
|
+
*/
|
|
321
|
+
export function knownContext(id) {
|
|
322
|
+
const lower = String(id).toLowerCase();
|
|
323
|
+
const hit = KNOWN_CONTEXT.find((entry) => lower.includes(entry.match));
|
|
324
|
+
return hit?.contextWindow;
|
|
325
|
+
}
|
|
326
|
+
|
|
295
327
|
/** A model id is the only reliable label; strip a provider prefix for display. */
|
|
296
328
|
function displayName(id) {
|
|
297
329
|
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.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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",
|