dsh-sub2api 0.4.3 → 0.5.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 +18 -0
- package/README.md +15 -0
- package/lib/client.js +13 -0
- package/lib/constants.js +15 -0
- package/lib/index.js +43 -1
- package/lib/panel-store.js +21 -2
- package/lib/routes.js +1 -1
- package/lib/sub2api/catalog.js +36 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
- **`deepseek-flash` ships with the plugin.** A zero-balance account gets
|
|
6
|
+
`403 INSUFFICIENT_BALANCE` from `/v1/models`, which used to leave the model
|
|
7
|
+
picker completely empty — an install that looks broken. One entry is always
|
|
8
|
+
offered now, with the measured 1,048,576-token window, and a real catalogue
|
|
9
|
+
replaces it as soon as one arrives.
|
|
10
|
+
- **Installing switches DSH's default model to `sub2api/deepseek-flash`.** Done
|
|
11
|
+
through the host's `agentDefaultModel` service, so it is written into the
|
|
12
|
+
profile and survives restarts. Once only: pick another provider afterwards and
|
|
13
|
+
the plugin leaves that alone.
|
|
14
|
+
- Fixed a regression this introduced while it was being built: the auto-sync
|
|
15
|
+
after a top-up keyed off "the catalogue is empty", which can no longer be true,
|
|
16
|
+
so it never ran once the built-in existed. It now asks the catalogue whether
|
|
17
|
+
the *upstream* is empty.
|
|
18
|
+
- The panel tags the built-in model so its presence is not mistaken for an
|
|
19
|
+
upstream listing.
|
|
20
|
+
|
|
3
21
|
## 0.4.3
|
|
4
22
|
|
|
5
23
|
Interface polish, driven by an audit against the host's real design tokens.
|
package/README.md
CHANGED
|
@@ -65,6 +65,21 @@ dsh plugin add dsh-sub2api
|
|
|
65
65
|
|
|
66
66
|
---
|
|
67
67
|
|
|
68
|
+
## 内置模型与默认模型
|
|
69
|
+
|
|
70
|
+
安装后有两件事自动发生:
|
|
71
|
+
|
|
72
|
+
**1. DSH 的默认模型被改成 `sub2api/deepseek-flash`**
|
|
73
|
+
|
|
74
|
+
写进 profile 配置(`agent-default-model`),重启后依然生效。**只做一次** ——
|
|
75
|
+
你之后手动换成别的 provider,插件不会再抢回来。
|
|
76
|
+
|
|
77
|
+
**2. 永远自带一个 `deepseek-flash`**
|
|
78
|
+
|
|
79
|
+
零余额账号请求 `/v1/models` 会拿到 `403 INSUFFICIENT_BALANCE`,以前结果是模型选择器**完全空白**,装完像坏了一样。现在无论有没有余额、有没有同步成功,列表里至少有一个 `deepseek-flash`(上下文 1,048,576,实测值);上游真的返回后,真实目录会覆盖它。
|
|
80
|
+
|
|
81
|
+
面板里它带一个「内置」标签,避免被误认为是上游列出来的。
|
|
82
|
+
|
|
68
83
|
## 聊天输入框右下角的余额徽章
|
|
69
84
|
|
|
70
85
|
插件在对话输入框的右下角(`conversation.input.right`)常驻一个小徽章:
|
package/lib/client.js
CHANGED
|
@@ -1062,6 +1062,19 @@ window.__ModuleLoader__.load({
|
|
|
1062
1062
|
h("code", {
|
|
1063
1063
|
style: { ...T.mono, flex: "1 1 auto", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis" },
|
|
1064
1064
|
}, model.id),
|
|
1065
|
+
model.builtin === true
|
|
1066
|
+
? h("span", {
|
|
1067
|
+
title: "插件自带,上游没有返回时也能用",
|
|
1068
|
+
style: {
|
|
1069
|
+
fontSize: 11,
|
|
1070
|
+
padding: "0 6px",
|
|
1071
|
+
borderRadius: 999,
|
|
1072
|
+
border: "0.5px solid " + C.line,
|
|
1073
|
+
color: C.muted,
|
|
1074
|
+
whiteSpace: "nowrap",
|
|
1075
|
+
},
|
|
1076
|
+
}, "内置")
|
|
1077
|
+
: null,
|
|
1065
1078
|
editing
|
|
1066
1079
|
? h("span", { style: { display: "flex", gap: 6, alignItems: "center" } },
|
|
1067
1080
|
h("input", {
|
package/lib/constants.js
CHANGED
|
@@ -73,6 +73,21 @@ export const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
|
73
73
|
* Only families with direct evidence belong here: a figure larger than the real
|
|
74
74
|
* limit turns every long request into a 400, and a smaller one compacts early.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* The model a fresh install always offers, upstream or not.
|
|
78
|
+
*
|
|
79
|
+
* Installing the plugin on a zero-balance account returns `403
|
|
80
|
+
* INSUFFICIENT_BALANCE` from `/v1/models`, which used to leave the picker
|
|
81
|
+
* completely empty — an install that looks broken. One entry is declared
|
|
82
|
+
* locally so the plugin is usable the moment it lands, and the real catalogue
|
|
83
|
+
* replaces it as soon as it arrives.
|
|
84
|
+
*/
|
|
85
|
+
export const BUILTIN_MODEL = {
|
|
86
|
+
id: "deepseek-flash",
|
|
87
|
+
name: "deepseek-flash",
|
|
88
|
+
builtin: true,
|
|
89
|
+
};
|
|
90
|
+
|
|
76
91
|
export const KNOWN_CONTEXT = [
|
|
77
92
|
// Measured on sub.pscly.cc: 897,791 tokens accepted, 1,050,041 rejected with
|
|
78
93
|
// "maximum context length is 1048576 tokens".
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @module dsh-sub2api
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { PROVIDER, PLUGIN_NAME, SETTINGS_NS } from "./constants.js";
|
|
12
|
+
import { PROVIDER, PLUGIN_NAME, SETTINGS_NS, BUILTIN_MODEL } from "./constants.js";
|
|
13
13
|
import { readFileSync } from "node:fs";
|
|
14
14
|
import { resolveConfig } from "./config.js";
|
|
15
15
|
import { Sub2ApiAdapter } from "./adapter.js";
|
|
@@ -208,6 +208,48 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
208
208
|
if (typeof ctx.inject === "function") ctx.inject(["llm"], mountDiscovery);
|
|
209
209
|
else if (optional(ctx, "llm") !== undefined) mountDiscovery(ctx);
|
|
210
210
|
|
|
211
|
+
// 2.5) Make this the default model for new conversations, once per install.
|
|
212
|
+
//
|
|
213
|
+
// `agentDefaultModel` is the host service that owns that selection and
|
|
214
|
+
// writes it into the profile, so the choice survives restarts. It runs
|
|
215
|
+
// once: a user who later picks another provider keeps that choice.
|
|
216
|
+
if (typeof ctx.inject === "function") {
|
|
217
|
+
ctx.inject(["agentDefaultModel"], (defaultCtx) => {
|
|
218
|
+
defaultCtx.effect(() => {
|
|
219
|
+
let cancelled = false;
|
|
220
|
+
void (async () => {
|
|
221
|
+
try {
|
|
222
|
+
await panel.load();
|
|
223
|
+
if (cancelled || panel.defaultModelApplied()) return;
|
|
224
|
+
// `ctx.get` is the canonical accessor and works on hosts that do
|
|
225
|
+
// not project injected services onto the context object.
|
|
226
|
+
const service =
|
|
227
|
+
typeof defaultCtx.get === "function"
|
|
228
|
+
? defaultCtx.get("agentDefaultModel")
|
|
229
|
+
: defaultCtx.agentDefaultModel;
|
|
230
|
+
if (service === undefined) return;
|
|
231
|
+
|
|
232
|
+
const current = typeof service.currentSelection === "function" ? service.currentSelection() : undefined;
|
|
233
|
+
if (current?.provider === PROVIDER && current?.model === BUILTIN_MODEL.id) {
|
|
234
|
+
await panel.markDefaultModelApplied();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
await service.saveSelection({ provider: PROVIDER, model: BUILTIN_MODEL.id });
|
|
238
|
+
await panel.markDefaultModelApplied();
|
|
239
|
+
logger.info(`[sub2api] 已把 DSH 默认模型设为 ${PROVIDER}/${BUILTIN_MODEL.id}`);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
logger.warn(
|
|
242
|
+
`[sub2api] 设置默认模型失败(不影响使用):${error instanceof Error ? error.message : error}`,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
})();
|
|
246
|
+
return () => {
|
|
247
|
+
cancelled = true;
|
|
248
|
+
};
|
|
249
|
+
}, "sub2api: default-model");
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
211
253
|
// 3) Browser routes.
|
|
212
254
|
//
|
|
213
255
|
// `webServer` is registered by another plugin, so at this moment it may not
|
package/lib/panel-store.js
CHANGED
|
@@ -23,7 +23,7 @@ export class PanelStore {
|
|
|
23
23
|
this.deps = deps;
|
|
24
24
|
this.logger = deps.logger ?? { warn() {} };
|
|
25
25
|
/** @type {PanelState} */
|
|
26
|
-
this.state = { visible: [], contextOverrides: {} };
|
|
26
|
+
this.state = { visible: [], contextOverrides: {}, defaultModelApplied: false };
|
|
27
27
|
this.loaded = false;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -57,6 +57,24 @@ export class PanelStore {
|
|
|
57
57
|
return this.state;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Whether this install already pointed DSH's default model here.
|
|
62
|
+
*
|
|
63
|
+
* Once only: if the user later picks another provider on purpose, the plugin
|
|
64
|
+
* must not fight them for it on every start.
|
|
65
|
+
* @returns {boolean}
|
|
66
|
+
*/
|
|
67
|
+
defaultModelApplied() {
|
|
68
|
+
return this.state.defaultModelApplied === true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @returns {Promise<void>} */
|
|
72
|
+
async markDefaultModelApplied() {
|
|
73
|
+
if (this.state.defaultModelApplied === true) return;
|
|
74
|
+
this.state.defaultModelApplied = true;
|
|
75
|
+
await this.#persist();
|
|
76
|
+
}
|
|
77
|
+
|
|
60
78
|
/** @returns {string[]} allowlist; empty means "show every model" */
|
|
61
79
|
visible() {
|
|
62
80
|
return this.state.visible;
|
|
@@ -109,6 +127,7 @@ export class PanelStore {
|
|
|
109
127
|
return {
|
|
110
128
|
visible: [...this.state.visible],
|
|
111
129
|
contextOverrides: { ...this.state.contextOverrides },
|
|
130
|
+
defaultModelApplied: this.state.defaultModelApplied === true,
|
|
112
131
|
};
|
|
113
132
|
}
|
|
114
133
|
|
|
@@ -127,7 +146,7 @@ export class PanelStore {
|
|
|
127
146
|
/** @returns {PanelState} */
|
|
128
147
|
function normalizeState(raw) {
|
|
129
148
|
/** @type {PanelState} */
|
|
130
|
-
const state = { visible: [], contextOverrides: {} };
|
|
149
|
+
const state = { visible: [], contextOverrides: {}, defaultModelApplied: raw?.defaultModelApplied === true };
|
|
131
150
|
|
|
132
151
|
const list = Array.isArray(raw?.visible) ? raw.visible : Array.isArray(raw?.ids) ? raw.ids : [];
|
|
133
152
|
state.visible = cleanIds(list);
|
package/lib/routes.js
CHANGED
|
@@ -68,7 +68,7 @@ export function makeRoutes(deps) {
|
|
|
68
68
|
const failedAt = catalog.lastError?.at;
|
|
69
69
|
if (!blockedByBalance && typeof failedAt === "number" && now - failedAt < 120000) return;
|
|
70
70
|
|
|
71
|
-
const empty = catalog.
|
|
71
|
+
const empty = catalog.isEmpty();
|
|
72
72
|
const funded = Number.isFinite(balance) && balance > 0;
|
|
73
73
|
if (empty ? !funded : !catalog.stale) return;
|
|
74
74
|
|
package/lib/sub2api/catalog.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
VISION_HINTS,
|
|
20
20
|
} from "../constants.js";
|
|
21
21
|
import { Sub2ApiError } from "../util.js";
|
|
22
|
+
import { BUILTIN_MODEL } from "../constants.js";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @typedef {object} ModelRecord
|
|
@@ -213,11 +214,38 @@ export class ModelCatalog {
|
|
|
213
214
|
* back chain is config → upstream → measured table → conservative default,
|
|
214
215
|
* and `contextSource` records which one answered.
|
|
215
216
|
*/
|
|
217
|
+
/**
|
|
218
|
+
* Whether the upstream has told us nothing yet.
|
|
219
|
+
*
|
|
220
|
+
* Distinct from `visible().length === 0`, which can no longer happen: the
|
|
221
|
+
* built-in model is always offered. Callers that key off "the catalogue is
|
|
222
|
+
* empty" mean this one — otherwise the built-in silently disables the
|
|
223
|
+
* auto-sync that runs after a top-up.
|
|
224
|
+
* @returns {boolean}
|
|
225
|
+
*/
|
|
226
|
+
isEmpty() {
|
|
227
|
+
return this.models.length === 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Upstream models in display order, with the built-in always present.
|
|
232
|
+
*
|
|
233
|
+
* The built-in sits last so a real catalogue reads first; when upstream also
|
|
234
|
+
* lists the same id, upstream wins — its metadata is fresher than ours.
|
|
235
|
+
* @returns {Array<ModelRecord & {builtin?: boolean}>}
|
|
236
|
+
*/
|
|
237
|
+
catalogue() {
|
|
238
|
+
const has = this.models.some((model) => model.id === BUILTIN_MODEL.id);
|
|
239
|
+
return has ? [...this.models] : [...this.models, { ...BUILTIN_MODEL }];
|
|
240
|
+
}
|
|
241
|
+
|
|
216
242
|
visible() {
|
|
217
243
|
const allow = this.allowed();
|
|
244
|
+
const keep = (model) =>
|
|
245
|
+
model.builtin === true || allow.length === 0 || allow.includes(model.id);
|
|
218
246
|
|
|
219
|
-
return this.
|
|
220
|
-
.filter(
|
|
247
|
+
return this.catalogue()
|
|
248
|
+
.filter(keep)
|
|
221
249
|
.map((model) => ({ ...model, ...this.resolveContext(model) }));
|
|
222
250
|
}
|
|
223
251
|
|
|
@@ -264,7 +292,11 @@ export class ModelCatalog {
|
|
|
264
292
|
error: this.lastError ?? null,
|
|
265
293
|
needsRecharge: this.lastError?.code === "INSUFFICIENT_BALANCE",
|
|
266
294
|
allowed: this.allowed(),
|
|
267
|
-
all: this.
|
|
295
|
+
all: this.catalogue().map((model) => ({
|
|
296
|
+
id: model.id,
|
|
297
|
+
name: model.name,
|
|
298
|
+
builtin: model.builtin === true,
|
|
299
|
+
})),
|
|
268
300
|
models: this.visible().map((model) => ({
|
|
269
301
|
id: model.id,
|
|
270
302
|
name: model.name,
|
|
@@ -274,6 +306,7 @@ export class ModelCatalog {
|
|
|
274
306
|
reasoningEfforts: this.reasoningFor(model.id)?.efforts.map((e) => e.name) ?? null,
|
|
275
307
|
vision: model.vision === true,
|
|
276
308
|
ownedBy: model.ownedBy ?? null,
|
|
309
|
+
builtin: model.builtin === true,
|
|
277
310
|
})),
|
|
278
311
|
};
|
|
279
312
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|