dsh-sub2api 0.2.6 → 0.2.8
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 +27 -0
- package/README.md +46 -0
- package/lib/adapter.js +89 -15
- package/lib/client.js +28 -3
- package/lib/config.js +5 -1
- package/lib/index.js +63 -26
- package/lib/schema.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.8
|
|
4
|
+
|
|
5
|
+
- The panel no longer depends on the provider registration succeeding. A
|
|
6
|
+
rejected route (a second install, an older host) used to abort `apply`, so the
|
|
7
|
+
browser half rendered while every `/api/sub2api/*` route was missing — the
|
|
8
|
+
settings page showed only "HTTP 404:响应不是 JSON". Registration now runs in a
|
|
9
|
+
nested injection with its own try/catch, and `inject` is empty so the panel
|
|
10
|
+
mounts even when the LLM seam is absent.
|
|
11
|
+
- Say what a 404 means: the panel now explains that the host half did not load,
|
|
12
|
+
lists the usual causes, and offers a retry.
|
|
13
|
+
- Log what mounted: `[sub2api] 面板路由已注册:N 条(vX.Y.Z)`, or the reason it
|
|
14
|
+
did not (missing `webServer`, rejected provider).
|
|
15
|
+
- Fall back to `ctx.get` when a host predates `ctx.inject`.
|
|
16
|
+
|
|
17
|
+
## 0.2.7
|
|
18
|
+
|
|
19
|
+
- Retry 5xx and 429, not just dropped connections. The openresty in front of the
|
|
20
|
+
gateway answers 502 while the Go backend restarts; the same request a second
|
|
21
|
+
later succeeds.
|
|
22
|
+
- Read the real failure class. The transport's error carries it in `failure`
|
|
23
|
+
(`SERVER`, `TRANSPORT`, …) while `code` is the seam-level bucket
|
|
24
|
+
(`unavailable`), so routing on `code` treated every provider fault as one kind
|
|
25
|
+
— the 502 path was never taken.
|
|
26
|
+
- Report HTTP failures as sentences instead of raw HTML, and name the status.
|
|
27
|
+
- `retries` replaces `transportRetries` (the old key still works), default 2,
|
|
28
|
+
with quadratic backoff. Retries stop at the first streamed chunk.
|
|
29
|
+
|
|
3
30
|
## 0.2.6
|
|
4
31
|
|
|
5
32
|
- Retry a dropped connection once before the first chunk. The transport reports
|
package/README.md
CHANGED
|
@@ -227,6 +227,27 @@ Cannot switch to sub2api/...: no context capacity; configure contextWindow on th
|
|
|
227
227
|
|
|
228
228
|
---
|
|
229
229
|
|
|
230
|
+
## 自动重试
|
|
231
|
+
|
|
232
|
+
回答还没吐出第一个字之前,插件会自动重试这几类失败:
|
|
233
|
+
|
|
234
|
+
| 类型 | 典型表现 | 默认重试 |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| 连接中断 | `fetch failed`、`could not be reached`、socket reset | ✅ |
|
|
237
|
+
| 网关 5xx | openresty 返回 `502 Bad Gateway`(后端重启/上游账号异常) | ✅ |
|
|
238
|
+
| 限流 | HTTP 429 | ✅ |
|
|
239
|
+
| 空响应 | 200 但没有任何内容 | ✅ |
|
|
240
|
+
| 业务错误 | 401/403、余额不足、超长上下文 | ❌ 立即返回 |
|
|
241
|
+
|
|
242
|
+
已经吐出内容之后**绝不重试**——否则会把半截回答拼成两遍。
|
|
243
|
+
|
|
244
|
+
```yaml
|
|
245
|
+
llm-sub2api:
|
|
246
|
+
retries: 2 # 0 关闭,最大 5
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
> 取舍:极少数情况下,网关其实已经受理并计费,只是响应在返回途中丢了,这时重试会多算一次。窗口很小,但如果你更在意账目精确,把 `retries` 设为 0。
|
|
250
|
+
|
|
230
251
|
## 常见报错
|
|
231
252
|
|
|
232
253
|
### `https://sub.pscly.cc/v1 could not be reached or the connection dropped: fetch failed`
|
|
@@ -241,6 +262,31 @@ Cannot switch to sub2api/...: no context capacity; configure contextWindow on th
|
|
|
241
262
|
|
|
242
263
|
> 报错里的 URL 显示成 `/v1` 是传输层只上报 base 的结果;插件会把它改写成真正失败的那条路径 `/chat/completions`,并带上重试次数。
|
|
243
264
|
|
|
265
|
+
### 设置页只有一行「HTTP 404:响应不是 JSON」
|
|
266
|
+
|
|
267
|
+
这是**插件后端没有挂载**:浏览器那一半加载了(所以设置页能渲染),但 `/api/sub2api/*` 一条都不存在,DSH 的 Web 服务器对未知路径返回了 HTML。
|
|
268
|
+
|
|
269
|
+
从 0.2.8 起,面板会直接说清楚,并给出排查步骤。根因通常是:
|
|
270
|
+
|
|
271
|
+
| 原因 | 怎么确认 |
|
|
272
|
+
|---|---|
|
|
273
|
+
| 装上了但没重启 | 重启 DSH 后再打开 |
|
|
274
|
+
| 插件被禁用 | 插件页确认已启用 |
|
|
275
|
+
| 宿主那一半加载失败 | 看 `~/.dsh/logs/startup-*.log` 里 `sub2api` 的报错 |
|
|
276
|
+
| 同一 profile 装了两份 | `dsh plugin list` 里出现两条 |
|
|
277
|
+
|
|
278
|
+
从 0.2.8 起,宿主会在启动日志里写一行 `[sub2api] 面板路由已注册:N 条(vX.Y.Z)`——**有这行就说明后端活着**,没有就是没挂载,日志里会同时给出原因(缺 `webServer`、provider 注册被拒等)。
|
|
279
|
+
|
|
280
|
+
### `the endpoint answered 502 Bad Gateway: <html>...openresty</html>`
|
|
281
|
+
|
|
282
|
+
这是**网关前面的 openresty 返回的**,不是模型的问题:sub2api 的 Go 后端当时不可用(重启中),或者上游账号被判定不可用正在切换。
|
|
283
|
+
|
|
284
|
+
插件会自动重试(见上),连续失败才会抛给你。持续出现时看后端状态:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
ssh pshk 'docker ps | grep sub2api; docker logs --tail 50 sub2api'
|
|
288
|
+
```
|
|
289
|
+
|
|
244
290
|
### `Cannot switch to sub2api/...: no context capacity`
|
|
245
291
|
|
|
246
292
|
见上文[上下文窗口](#上下文窗口),在面板里给这个模型手填容量即可。
|
package/lib/adapter.js
CHANGED
|
@@ -199,13 +199,13 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
199
199
|
!emitted &&
|
|
200
200
|
attempt < attempts &&
|
|
201
201
|
options.signal?.aborted !== true &&
|
|
202
|
-
|
|
202
|
+
isRetryableFailure(error);
|
|
203
203
|
if (!canRetry) throw describeStreamFailure(error, emitted, attempt);
|
|
204
204
|
attempt += 1;
|
|
205
205
|
this.deps.logger?.warn?.(
|
|
206
|
-
`[sub2api]
|
|
206
|
+
`[sub2api] 第 ${attempt} 次重试:${plainText(error?.message ?? error).slice(0, 100)}`,
|
|
207
207
|
);
|
|
208
|
-
await delay(
|
|
208
|
+
await delay(500 * attempt * attempt);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
@@ -233,16 +233,75 @@ export function mergeSampling(routeSampling, modelSampling, options) {
|
|
|
233
233
|
return merged;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/**
|
|
237
|
+
* The provider-level failure class.
|
|
238
|
+
*
|
|
239
|
+
* The transport's error carries the real class in `failure`; its `code` is the
|
|
240
|
+
* seam-level bucket (`unavailable`) and using that for routing silently treats
|
|
241
|
+
* every provider fault as one kind.
|
|
242
|
+
*/
|
|
243
|
+
export function failureClass(error) {
|
|
244
|
+
const failure = String(error?.failure ?? "");
|
|
245
|
+
if (failure !== "") return failure;
|
|
246
|
+
return String(error?.code ?? "");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** HTTP status the transport recorded for this failure, when it has one. */
|
|
250
|
+
export function failureStatus(error) {
|
|
251
|
+
const status = Number(error?.facts?.status ?? error?.status);
|
|
252
|
+
return Number.isFinite(status) ? status : undefined;
|
|
253
|
+
}
|
|
254
|
+
|
|
236
255
|
/** Whether a failure came from the transport rather than the endpoint's answer. */
|
|
237
256
|
export function isTransportFailure(error) {
|
|
238
|
-
|
|
239
|
-
if (code === "TRANSPORT" || code === "TIMEOUT") return true;
|
|
257
|
+
if (failureClass(error) === "TRANSPORT" || failureClass(error) === "TIMEOUT") return true;
|
|
240
258
|
const message = String(error?.message ?? "");
|
|
241
259
|
return /fetch failed|could not be reached|connection dropped|socket hang up|ECONNRESET|ETIMEDOUT|EPIPE/i.test(
|
|
242
260
|
message,
|
|
243
261
|
);
|
|
244
262
|
}
|
|
245
263
|
|
|
264
|
+
/** Error codes a second attempt can plausibly turn into an answer. */
|
|
265
|
+
const RETRYABLE_CODES = new Set([
|
|
266
|
+
"TRANSPORT",
|
|
267
|
+
"TIMEOUT",
|
|
268
|
+
"SERVER",
|
|
269
|
+
"RATE_LIMIT",
|
|
270
|
+
"THROTTLED",
|
|
271
|
+
"EMPTY_RESPONSE",
|
|
272
|
+
]);
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Whether asking again could work.
|
|
276
|
+
*
|
|
277
|
+
* A 502 from the openresty in front of the gateway is the common one here: the
|
|
278
|
+
* Go backend was restarting or the upstream account was unusable, and the same
|
|
279
|
+
* request a second later usually succeeds. Retrying is only allowed before the
|
|
280
|
+
* first chunk, so a partially streamed answer is never repeated.
|
|
281
|
+
*/
|
|
282
|
+
export function isRetryableFailure(error) {
|
|
283
|
+
if (error === undefined || error === null) return false;
|
|
284
|
+
if (isTransportFailure(error)) return true;
|
|
285
|
+
|
|
286
|
+
if (RETRYABLE_CODES.has(failureClass(error))) return true;
|
|
287
|
+
|
|
288
|
+
const status = failureStatus(error);
|
|
289
|
+
if (status !== undefined && (status >= 500 || status === 429)) return true;
|
|
290
|
+
|
|
291
|
+
const message = String(error?.message ?? "");
|
|
292
|
+
return /answered 5\d\d|Bad Gateway|Service Unavailable|Gateway Timeout/i.test(message);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Strip the tags a gateway puts around an HTML error page. */
|
|
296
|
+
export function plainText(value) {
|
|
297
|
+
return String(value ?? "")
|
|
298
|
+
.replace(/<script[\s\S]*?<\/script>/gi, " ")
|
|
299
|
+
.replace(/<style[\s\S]*?<\/style>/gi, " ")
|
|
300
|
+
.replace(/<[^>]+>/g, " ")
|
|
301
|
+
.replace(/\s+/g, " ")
|
|
302
|
+
.trim();
|
|
303
|
+
}
|
|
304
|
+
|
|
246
305
|
/**
|
|
247
306
|
* Name the endpoint that actually failed.
|
|
248
307
|
*
|
|
@@ -251,18 +310,33 @@ export function isTransportFailure(error) {
|
|
|
251
310
|
* /v1/chat/completions. That sends people looking at the wrong thing.
|
|
252
311
|
*/
|
|
253
312
|
export function describeStreamFailure(error, emitted, attempts) {
|
|
254
|
-
const message = String(error?.message ?? error);
|
|
255
|
-
const isTransport = isTransportFailure(error);
|
|
256
|
-
if (!isTransport) return error;
|
|
257
|
-
|
|
258
313
|
const retryNote = attempts > 0 ? `,已重试 ${attempts} 次` : "";
|
|
259
314
|
const midStream = emitted ? ",回复中途断开" : "";
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
315
|
+
const status = failureStatus(error);
|
|
316
|
+
const said = plainText(error?.message ?? error);
|
|
317
|
+
|
|
318
|
+
if (status !== undefined && status >= 500) {
|
|
319
|
+
const what =
|
|
320
|
+
status === 502
|
|
321
|
+
? "中转站的网关返回 502,后端当时不可用(重启或上游账号异常)"
|
|
322
|
+
: status === 504
|
|
323
|
+
? "中转站的网关返回 504,上游超时"
|
|
324
|
+
: `中转站的网关返回 ${status}`;
|
|
325
|
+
return new Sub2ApiError(`${what}${retryNote}${midStream}。原始信息:${said}`, {
|
|
326
|
+
code: failureClass(error) || "SERVER",
|
|
327
|
+
status,
|
|
328
|
+
cause: error,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (isTransportFailure(error)) {
|
|
333
|
+
return new Sub2ApiError(
|
|
334
|
+
`与中转站的连接中断(/chat/completions${retryNote}${midStream});如果这条会话很长,可能是等待首字超时,可在插件配置里调大 streamIdleTimeoutMs。原始信息:${said}`,
|
|
335
|
+
{ code: failureClass(error) || "TRANSPORT", cause: error },
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return error;
|
|
266
340
|
}
|
|
267
341
|
|
|
268
342
|
/** Sleep between retries. */
|
package/lib/client.js
CHANGED
|
@@ -34,7 +34,19 @@ window.__ModuleLoader__.load({
|
|
|
34
34
|
try {
|
|
35
35
|
payload = await response.json();
|
|
36
36
|
} catch {
|
|
37
|
-
|
|
37
|
+
// A 404 here means the host half of the plugin never mounted: the
|
|
38
|
+
// browser bundle loads independently, so the panel renders while every
|
|
39
|
+
// route is missing. Say that instead of "响应不是 JSON".
|
|
40
|
+
if (response.status === 404) {
|
|
41
|
+
throw new ApiError(
|
|
42
|
+
"插件后端没有加载:/api/sub2api 返回 404。请确认插件已启用,然后重启 DSH。",
|
|
43
|
+
"host_missing",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
throw new ApiError(
|
|
47
|
+
"HTTP " + response.status + ":响应不是 JSON(可能是网关或代理返回了错误页)",
|
|
48
|
+
"not_json",
|
|
49
|
+
);
|
|
38
50
|
}
|
|
39
51
|
if (!payload || payload.ok !== true) {
|
|
40
52
|
throw new ApiError(
|
|
@@ -968,8 +980,21 @@ window.__ModuleLoader__.load({
|
|
|
968
980
|
const onRefresh = useCallback(() => refresh(), [refresh]);
|
|
969
981
|
|
|
970
982
|
if (state === null) {
|
|
971
|
-
|
|
972
|
-
|
|
983
|
+
if (error) {
|
|
984
|
+
return h("div", { style: { padding: "4px 0 18px" } },
|
|
985
|
+
h(Card, { title: "Sub2API" },
|
|
986
|
+
h(Alert, { tone: "error", title: "面板无法连接插件后端" }, error),
|
|
987
|
+
h("div", { style: { ...T.hint, marginTop: 12 } },
|
|
988
|
+
"常见原因:插件装上了但宿主那一半没有加载(版本不匹配、依赖缺失、或安装后没有重启)。"),
|
|
989
|
+
h("div", { style: { ...T.hint, marginTop: 6 } },
|
|
990
|
+
"排查:在 DSH 终端执行 ", h("code", { style: T.mono }, "dsh plugin list"),
|
|
991
|
+
" 确认已安装;重启 DSH 后再打开这里。"),
|
|
992
|
+
h("div", { style: { marginTop: 12 } },
|
|
993
|
+
h(Button, { onClick: () => refresh() }, "重试")),
|
|
994
|
+
),
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
return h("div", { style: { padding: 18, color: C.muted, fontSize: 13 } }, "加载中…");
|
|
973
998
|
}
|
|
974
999
|
|
|
975
1000
|
const unread = announcements.filter((item) => !item.is_read);
|
package/lib/config.js
CHANGED
|
@@ -78,7 +78,11 @@ export function resolveConfig(config) {
|
|
|
78
78
|
contextWindow: toPositiveInt(field(config, "contextWindow", undefined)),
|
|
79
79
|
defaultContextWindow: toPositiveInt(field(config, "defaultContextWindow", undefined)),
|
|
80
80
|
rechargeMultiplier: toMultiplier(field(config, "rechargeMultiplier", DEFAULT_RECHARGE_MULTIPLIER)),
|
|
81
|
-
|
|
81
|
+
retries: toCount(
|
|
82
|
+
field(config, "retries", field(config, "transportRetries", 2)),
|
|
83
|
+
2,
|
|
84
|
+
5,
|
|
85
|
+
),
|
|
82
86
|
reasoningModels: toStringArray(field(config, "reasoningModels", [])),
|
|
83
87
|
defaultReasoningEffort: String(field(config, "defaultReasoningEffort", "")).trim() || undefined,
|
|
84
88
|
autoProvision: field(config, "autoProvision", true) !== false,
|
package/lib/index.js
CHANGED
|
@@ -25,8 +25,14 @@ export { Config } from "./schema.js";
|
|
|
25
25
|
/** Stable Cordis plugin name. */
|
|
26
26
|
export const name = PLUGIN_NAME;
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Nothing is a hard requirement.
|
|
30
|
+
*
|
|
31
|
+
* The panel is the part a user needs when something is wrong, so it must mount
|
|
32
|
+
* even when the LLM seam is missing or a provider registration is rejected.
|
|
33
|
+
* The provider route is installed later, once `llm` is actually available.
|
|
34
|
+
*/
|
|
35
|
+
export const inject = [];
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
38
|
* The running build's version, read from the package next to the module.
|
|
@@ -119,38 +125,62 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
119
125
|
apiKeyEnv: () => cfg().apiKeyEnv,
|
|
120
126
|
timeoutMs: () => cfg().requestTimeoutMs,
|
|
121
127
|
idleTimeoutMs: () => cfg().streamIdleTimeoutMs,
|
|
122
|
-
transportRetries: () => cfg().
|
|
128
|
+
transportRetries: () => cfg().retries,
|
|
123
129
|
logger,
|
|
124
130
|
});
|
|
125
131
|
|
|
126
132
|
const deps = { api, session, catalog, adapter, cfg, logger };
|
|
127
133
|
|
|
128
|
-
// 1) Provider directory + adapter
|
|
129
|
-
//
|
|
134
|
+
// 1) Provider directory + adapter, installed once the LLM seam exists.
|
|
135
|
+
//
|
|
136
|
+
// This is deliberately a nested injection rather than a top-level
|
|
137
|
+
// `inject`: a rejected registration (a duplicate route from a second
|
|
138
|
+
// install, an older host without the directory API) must not take the
|
|
139
|
+
// panel down with it. Without the panel the user cannot even see why.
|
|
130
140
|
/** @type {{replace?: (providers: string[]) => void} | undefined} */
|
|
131
141
|
let adapterHandle;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
const mountProvider = (llmCtx) => {
|
|
143
|
+
llmCtx.effect(() => {
|
|
144
|
+
try {
|
|
145
|
+
const providers = llmCtx.llm.registerConfigurableProviders([
|
|
146
|
+
{
|
|
147
|
+
provider: PROVIDER,
|
|
148
|
+
displayName: "Sub2API",
|
|
149
|
+
settingsNs: SETTINGS_NS,
|
|
150
|
+
settingsPath: [],
|
|
151
|
+
},
|
|
152
|
+
]);
|
|
153
|
+
const adapters = llmCtx.llm.registerAdapter([PROVIDER], adapter);
|
|
154
|
+
adapterHandle = adapters;
|
|
155
|
+
return () => {
|
|
156
|
+
adapterHandle = undefined;
|
|
157
|
+
adapters?.();
|
|
158
|
+
providers?.();
|
|
159
|
+
};
|
|
160
|
+
} catch (error) {
|
|
161
|
+
logger.warn(
|
|
162
|
+
`[sub2api] provider 注册失败,面板仍可用:${error instanceof Error ? error.message : error}`,
|
|
163
|
+
);
|
|
164
|
+
return () => {};
|
|
165
|
+
}
|
|
166
|
+
}, "sub2api: provider");
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// `ctx.inject` is the modern way to wait for a service; older hosts only have
|
|
170
|
+
// `ctx.get`, and a missing method here would abort apply and take the panel
|
|
171
|
+
// down with it.
|
|
172
|
+
if (typeof ctx.inject === "function") {
|
|
173
|
+
ctx.inject(["llm"], mountProvider);
|
|
174
|
+
} else if (optional(ctx, "llm") !== undefined) {
|
|
175
|
+
mountProvider(ctx);
|
|
176
|
+
} else {
|
|
177
|
+
logger.warn("[sub2api] 宿主没有 llm 服务,provider 未注册(面板仍可用)");
|
|
178
|
+
}
|
|
149
179
|
|
|
150
180
|
// 2) Model discovery for the Models page's probe button.
|
|
151
|
-
|
|
152
|
-
if (typeof
|
|
153
|
-
const dispose =
|
|
181
|
+
const mountDiscovery = (llmCtx) => llmCtx.effect(() => {
|
|
182
|
+
if (typeof llmCtx.llm.registerModelDiscovery !== "function") return () => {};
|
|
183
|
+
const dispose = llmCtx.llm.registerModelDiscovery(SETTINGS_NS, async (request, signal) => {
|
|
154
184
|
// A draft probe carries its own one-shot key and endpoint; a configured
|
|
155
185
|
// route falls back to the stored credential and this plugin's apiBase.
|
|
156
186
|
const key = request?.apiKey ?? (await session.apiKey());
|
|
@@ -168,10 +198,16 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
168
198
|
return () => dispose?.();
|
|
169
199
|
}, "sub2api: discovery");
|
|
170
200
|
|
|
201
|
+
if (typeof ctx.inject === "function") ctx.inject(["llm"], mountDiscovery);
|
|
202
|
+
else if (optional(ctx, "llm") !== undefined) mountDiscovery(ctx);
|
|
203
|
+
|
|
171
204
|
// 3) Browser routes.
|
|
172
205
|
ctx.effect(() => {
|
|
173
206
|
const webServer = optional(ctx, "webServer");
|
|
174
|
-
if (webServer === undefined || typeof webServer.register !== "function")
|
|
207
|
+
if (webServer === undefined || typeof webServer.register !== "function") {
|
|
208
|
+
logger.warn("[sub2api] 宿主没有 webServer 服务,面板路由未注册(设置页会显示 404)");
|
|
209
|
+
return () => {};
|
|
210
|
+
}
|
|
175
211
|
const routes = makeRoutes({
|
|
176
212
|
...deps,
|
|
177
213
|
cfg,
|
|
@@ -186,6 +222,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
186
222
|
},
|
|
187
223
|
});
|
|
188
224
|
const disposers = routes.map((route) => webServer.register(route));
|
|
225
|
+
logger.info(`[sub2api] 面板路由已注册:${routes.length} 条(v${VERSION})`);
|
|
189
226
|
return () => disposers.forEach((dispose) => dispose?.());
|
|
190
227
|
}, "sub2api: routes");
|
|
191
228
|
|
package/lib/schema.js
CHANGED
|
@@ -33,7 +33,7 @@ export const Config = z.object({
|
|
|
33
33
|
contextWindow: count("强制覆盖所有模型的上下文窗口;留空则逐模型解析"),
|
|
34
34
|
defaultContextWindow: count("上游没有声明上下文窗口时使用的兜底值(默认 128000)"),
|
|
35
35
|
rechargeMultiplier: z.natural().min(1).max(100).description("每 1 元到账多少额度,用于面板预估").volatile(),
|
|
36
|
-
|
|
36
|
+
retries: count("首字之前的重试次数,覆盖断连与 5xx/限流(0-5,默认 2)"),
|
|
37
37
|
reasoningModels: z.array(z.string()).description("额外声明支持思考等级的模型 id 片段").volatile(),
|
|
38
38
|
defaultReasoningEffort: text("", "默认思考等级(minimal/low/medium/high);留空由上游决定"),
|
|
39
39
|
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.8",
|
|
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",
|