dsh-sub2api 0.2.7 → 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 +14 -0
- package/README.md +15 -0
- package/lib/client.js +28 -3
- package/lib/index.js +62 -25
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
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
|
+
|
|
3
17
|
## 0.2.7
|
|
4
18
|
|
|
5
19
|
- Retry 5xx and 429, not just dropped connections. The openresty in front of the
|
package/README.md
CHANGED
|
@@ -262,6 +262,21 @@ llm-sub2api:
|
|
|
262
262
|
|
|
263
263
|
> 报错里的 URL 显示成 `/v1` 是传输层只上报 base 的结果;插件会把它改写成真正失败的那条路径 `/chat/completions`,并带上重试次数。
|
|
264
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
|
+
|
|
265
280
|
### `the endpoint answered 502 Bad Gateway: <html>...openresty</html>`
|
|
266
281
|
|
|
267
282
|
这是**网关前面的 openresty 返回的**,不是模型的问题:sub2api 的 Go 后端当时不可用(重启中),或者上游账号被判定不可用正在切换。
|
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/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.
|
|
@@ -125,32 +131,56 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
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/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",
|