dsh-sub2api 0.2.8 → 0.2.10
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 +19 -0
- package/README.md +25 -0
- package/lib/adapter.js +11 -7
- package/lib/index.js +28 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.10
|
|
4
|
+
|
|
5
|
+
- Recognize sub2api's own "Upstream service temporarily unavailable" 502 and say
|
|
6
|
+
what it means: the gateway has no usable upstream account for that model right
|
|
7
|
+
now, so this is not a plugin fault and retrying cannot conjure capacity. The
|
|
8
|
+
message names the condition and suggests waiting or switching models.
|
|
9
|
+
- README documents the gateway log line that breaks the pool down
|
|
10
|
+
(`excluded` / `model_not_supported` / `runtime_blocked`).
|
|
11
|
+
|
|
12
|
+
## 0.2.9
|
|
13
|
+
|
|
14
|
+
- Mount the panel routes by **waiting for `webServer`**, not by sampling it once
|
|
15
|
+
during `apply`. The service is registered by a plugin that loads after this
|
|
16
|
+
one, so `ctx.get("webServer")` was undefined at that moment and every
|
|
17
|
+
`/api/sub2api/*` route was silently skipped — the settings page then showed
|
|
18
|
+
only "HTTP 404:响应不是 JSON". Found by installing the plugin into a real
|
|
19
|
+
DSH profile and watching it 404.
|
|
20
|
+
- Same treatment for `llm` and `webServer` on hosts without `ctx.inject`.
|
|
21
|
+
|
|
3
22
|
## 0.2.8
|
|
4
23
|
|
|
5
24
|
- The panel no longer depends on the provider registration succeeding. A
|
package/README.md
CHANGED
|
@@ -277,6 +277,31 @@ llm-sub2api:
|
|
|
277
277
|
|
|
278
278
|
从 0.2.8 起,宿主会在启动日志里写一行 `[sub2api] 面板路由已注册:N 条(vX.Y.Z)`——**有这行就说明后端活着**,没有就是没挂载,日志里会同时给出原因(缺 `webServer`、provider 注册被拒等)。
|
|
279
279
|
|
|
280
|
+
### `the endpoint answered 502 Bad Gateway: Upstream service temporarily unavailable`
|
|
281
|
+
|
|
282
|
+
这句是 **sub2api 自己**返回的(不是 openresty 的错误页),含义是「我的上游失败了」。最常见的原因是**该模型此刻没有可用账号**,网关日志会写得很清楚:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
ssh pskh 'docker logs --since 1h sub2api | grep account_select_failed | tail -5'
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
"error":"no available OpenAI accounts supporting model: deepseek-v4.1-flash
|
|
290
|
+
(pool=4, filtered: excluded=1 model_not_supported=2 runtime_blocked=1)"
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
括号里就是原因分解:池子里 4 个账号,1 个被排除、2 个不支持这个模型、1 个被运行时拉黑。
|
|
294
|
+
|
|
295
|
+
**这是网关侧的容量问题,插件重试也变不出账号。** 处理方式:
|
|
296
|
+
|
|
297
|
+
| 计数 | 含义 | 怎么办 |
|
|
298
|
+
|---|---|---|
|
|
299
|
+
| `model_not_supported` | 账号的模型清单里没有这个模型 | 在后台给账号补上模型映射 |
|
|
300
|
+
| `runtime_blocked` | 连续失败被临时拉黑 | 等冷却,或查该账号的上游报错 |
|
|
301
|
+
| `excluded` | 被分组/规则排除 | 检查分组绑定 |
|
|
302
|
+
|
|
303
|
+
插件会把这句话翻译成中文并说明「不是插件本身的问题」,但真正的修复在网关。
|
|
304
|
+
|
|
280
305
|
### `the endpoint answered 502 Bad Gateway: <html>...openresty</html>`
|
|
281
306
|
|
|
282
307
|
这是**网关前面的 openresty 返回的**,不是模型的问题:sub2api 的 Go 后端当时不可用(重启中),或者上游账号被判定不可用正在切换。
|
package/lib/adapter.js
CHANGED
|
@@ -316,17 +316,21 @@ export function describeStreamFailure(error, emitted, attempts) {
|
|
|
316
316
|
const said = plainText(error?.message ?? error);
|
|
317
317
|
|
|
318
318
|
if (status !== undefined && status >= 500) {
|
|
319
|
-
|
|
320
|
-
|
|
319
|
+
// sub2api answers this exact sentence for "my upstream failed", which in
|
|
320
|
+
// practice means the account pool has nothing usable for this model — a
|
|
321
|
+
// gateway-side condition the user can only act on by waiting or switching.
|
|
322
|
+
const upstreamDown = /Upstream service temporarily unavailable/i.test(said);
|
|
323
|
+
const what = upstreamDown
|
|
324
|
+
? "中转站的上游暂时不可用(502);这通常是该模型此刻没有可用账号,或上游账号返回了 5xx,不是插件本身的问题"
|
|
325
|
+
: status === 502
|
|
321
326
|
? "中转站的网关返回 502,后端当时不可用(重启或上游账号异常)"
|
|
322
327
|
: status === 504
|
|
323
328
|
? "中转站的网关返回 504,上游超时"
|
|
324
329
|
: `中转站的网关返回 ${status}`;
|
|
325
|
-
return new Sub2ApiError(
|
|
326
|
-
|
|
327
|
-
status,
|
|
328
|
-
|
|
329
|
-
});
|
|
330
|
+
return new Sub2ApiError(
|
|
331
|
+
`${what}${retryNote}${midStream}。可稍后重试或换一个模型;原始信息:${said}`,
|
|
332
|
+
{ code: failureClass(error) || "SERVER", status, cause: error },
|
|
333
|
+
);
|
|
330
334
|
}
|
|
331
335
|
|
|
332
336
|
if (isTransportFailure(error)) {
|
package/lib/index.js
CHANGED
|
@@ -118,16 +118,19 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
118
118
|
logger,
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
const adapter =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
const adapter =
|
|
122
|
+
Sub2ApiAdapter === undefined
|
|
123
|
+
? undefined
|
|
124
|
+
: new Sub2ApiAdapter({
|
|
125
|
+
ctx,
|
|
126
|
+
catalog,
|
|
127
|
+
apiBase: () => cfg().apiBase,
|
|
128
|
+
apiKeyEnv: () => cfg().apiKeyEnv,
|
|
129
|
+
timeoutMs: () => cfg().requestTimeoutMs,
|
|
130
|
+
idleTimeoutMs: () => cfg().streamIdleTimeoutMs,
|
|
131
|
+
transportRetries: () => cfg().retries,
|
|
132
|
+
logger,
|
|
133
|
+
});
|
|
131
134
|
|
|
132
135
|
const deps = { api, session, catalog, adapter, cfg, logger };
|
|
133
136
|
|
|
@@ -140,6 +143,10 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
140
143
|
/** @type {{replace?: (providers: string[]) => void} | undefined} */
|
|
141
144
|
let adapterHandle;
|
|
142
145
|
const mountProvider = (llmCtx) => {
|
|
146
|
+
if (adapter === undefined) {
|
|
147
|
+
logger.warn("[sub2api] adapter 未加载,provider 路由未注册(面板仍可用)");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
143
150
|
llmCtx.effect(() => {
|
|
144
151
|
try {
|
|
145
152
|
const providers = llmCtx.llm.registerConfigurableProviders([
|
|
@@ -202,10 +209,14 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
202
209
|
else if (optional(ctx, "llm") !== undefined) mountDiscovery(ctx);
|
|
203
210
|
|
|
204
211
|
// 3) Browser routes.
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
//
|
|
213
|
+
// `webServer` is registered by another plugin, so at this moment it may not
|
|
214
|
+
// exist yet: reading it once here is why a correctly installed plugin could
|
|
215
|
+
// answer 404. `ctx.inject` waits for the service before mounting.
|
|
216
|
+
const mountRoutes = (webCtx) => webCtx.effect(() => {
|
|
217
|
+
const webServer = webCtx.webServer;
|
|
207
218
|
if (webServer === undefined || typeof webServer.register !== "function") {
|
|
208
|
-
logger.warn("[sub2api]
|
|
219
|
+
logger.warn("[sub2api] 宿主的 webServer 不可用,面板路由未注册(设置页会显示 404)");
|
|
209
220
|
return () => {};
|
|
210
221
|
}
|
|
211
222
|
const routes = makeRoutes({
|
|
@@ -226,6 +237,10 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
226
237
|
return () => disposers.forEach((dispose) => dispose?.());
|
|
227
238
|
}, "sub2api: routes");
|
|
228
239
|
|
|
240
|
+
if (typeof ctx.inject === "function") ctx.inject(["webServer"], mountRoutes);
|
|
241
|
+
else if (optional(ctx, "webServer") !== undefined) mountRoutes(ctx);
|
|
242
|
+
else logger.warn("[sub2api] 宿主没有 webServer 服务,面板路由未注册(设置页会显示 404)");
|
|
243
|
+
|
|
229
244
|
// 4) Slash command for the terminal surface, where the panel does not exist.
|
|
230
245
|
ctx.effect(() => {
|
|
231
246
|
const dispose = applyCommands(ctx, { api, session, catalog, cfg });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
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",
|