dsh-sub2api 0.1.7 → 0.2.1
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 +22 -0
- package/README.md +143 -100
- package/lib/adapter.js +33 -1
- package/lib/client.js +324 -90
- package/lib/commands.js +185 -0
- package/lib/config.js +4 -1
- package/lib/constants.js +31 -0
- package/lib/index.js +20 -9
- package/lib/panel-store.js +151 -0
- package/lib/routes.js +94 -2
- package/lib/schema.js +2 -0
- package/lib/sub2api/catalog.js +63 -16
- package/package.json +5 -3
- package/lib/selection.js +0 -66
package/lib/sub2api/catalog.js
CHANGED
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
12
12
|
import { dirname } from "node:path";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
CATALOG_TTL_MS,
|
|
15
|
+
DEFAULT_CONTEXT_WINDOW,
|
|
16
|
+
KNOWN_CONTEXT,
|
|
17
|
+
REASONING_HINTS,
|
|
18
|
+
STANDARD_EFFORTS,
|
|
19
|
+
VISION_HINTS,
|
|
20
|
+
} from "../constants.js";
|
|
14
21
|
import { Sub2ApiError } from "../util.js";
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -149,6 +156,54 @@ export class ModelCatalog {
|
|
|
149
156
|
return this.deps.selection?.() ?? [];
|
|
150
157
|
}
|
|
151
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Reasoning levels this model accepts, when the upstream is known to
|
|
161
|
+
* understand `reasoning_effort`. Declaring none is what makes the selector
|
|
162
|
+
* offer no thinking control at all.
|
|
163
|
+
* @param {string} id
|
|
164
|
+
* @returns {{efforts: Array<{id: string, name: string, body: Record<string, unknown>}>, defaultEffort?: string} | undefined}
|
|
165
|
+
*/
|
|
166
|
+
reasoningFor(id) {
|
|
167
|
+
const lower = String(id).toLowerCase();
|
|
168
|
+
const forced = (this.deps.reasoningModels?.() ?? []).some(
|
|
169
|
+
(entry) => entry === id || lower.includes(String(entry).toLowerCase()),
|
|
170
|
+
);
|
|
171
|
+
const known = REASONING_HINTS.some((hint) => lower.includes(hint));
|
|
172
|
+
if (!forced && !known) return undefined;
|
|
173
|
+
|
|
174
|
+
const efforts = STANDARD_EFFORTS.map((effort) => ({
|
|
175
|
+
id: effort.id,
|
|
176
|
+
name: effort.name,
|
|
177
|
+
body: { ...effort.body },
|
|
178
|
+
}));
|
|
179
|
+
const preferred = this.deps.defaultReasoningEffort?.();
|
|
180
|
+
return preferred === undefined ? { efforts } : { efforts, defaultEffort: preferred };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Where a model's capacity came from, in precedence order.
|
|
185
|
+
* @param {ModelRecord} model
|
|
186
|
+
* @returns {{contextWindow: number, contextSource: "config"|"panel"|"upstream"|"known"|"default"}}
|
|
187
|
+
*/
|
|
188
|
+
resolveContext(model) {
|
|
189
|
+
const forced = this.deps.contextWindow();
|
|
190
|
+
if (forced !== undefined) return { contextWindow: forced, contextSource: "config" };
|
|
191
|
+
|
|
192
|
+
const override = this.deps.contextOverride?.(model.id);
|
|
193
|
+
if (override !== undefined) return { contextWindow: override, contextSource: "panel" };
|
|
194
|
+
|
|
195
|
+
if (model.contextWindow !== undefined) {
|
|
196
|
+
return { contextWindow: model.contextWindow, contextSource: "upstream" };
|
|
197
|
+
}
|
|
198
|
+
const known = knownContext(model.id);
|
|
199
|
+
if (known !== undefined) return { contextWindow: known, contextSource: "known" };
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
contextWindow: this.deps.defaultContextWindow?.() ?? DEFAULT_CONTEXT_WINDOW,
|
|
203
|
+
contextSource: "default",
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
152
207
|
/**
|
|
153
208
|
* Models as the picker should see them: allowlist applied and a context
|
|
154
209
|
* window always resolved.
|
|
@@ -160,24 +215,10 @@ export class ModelCatalog {
|
|
|
160
215
|
*/
|
|
161
216
|
visible() {
|
|
162
217
|
const allow = this.allowed();
|
|
163
|
-
const forcedContext = this.deps.contextWindow();
|
|
164
|
-
const fallback = this.deps.defaultContextWindow?.() ?? DEFAULT_CONTEXT_WINDOW;
|
|
165
218
|
|
|
166
219
|
return this.models
|
|
167
220
|
.filter((model) => allow.length === 0 || allow.includes(model.id))
|
|
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
|
-
});
|
|
221
|
+
.map((model) => ({ ...model, ...this.resolveContext(model) }));
|
|
181
222
|
}
|
|
182
223
|
|
|
183
224
|
/**
|
|
@@ -191,6 +232,11 @@ export class ModelCatalog {
|
|
|
191
232
|
if (model.contextWindow !== undefined) entry.contextWindow = model.contextWindow;
|
|
192
233
|
if (model.maxTokens !== undefined) entry.maxTokens = model.maxTokens;
|
|
193
234
|
if (model.vision === true) entry.vision = true;
|
|
235
|
+
const reasoning = this.reasoningFor(model.id);
|
|
236
|
+
if (reasoning !== undefined) {
|
|
237
|
+
entry.reasoningLevels = reasoning.efforts;
|
|
238
|
+
if (reasoning.defaultEffort !== undefined) entry.defaultReasoning = reasoning.defaultEffort;
|
|
239
|
+
}
|
|
194
240
|
return entry;
|
|
195
241
|
});
|
|
196
242
|
}
|
|
@@ -225,6 +271,7 @@ export class ModelCatalog {
|
|
|
225
271
|
contextWindow: model.contextWindow ?? null,
|
|
226
272
|
contextSource: model.contextSource ?? null,
|
|
227
273
|
maxTokens: model.maxTokens ?? null,
|
|
274
|
+
reasoningEfforts: this.reasoningFor(model.id)?.efforts.map((e) => e.name) ?? null,
|
|
228
275
|
vision: model.vision === true,
|
|
229
276
|
ownedBy: model.ownedBy ?? null,
|
|
230
277
|
})),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"CHANGELOG.md",
|
|
15
|
+
"LICENSE",
|
|
15
16
|
"README.md",
|
|
16
17
|
"cordis.patch.yml",
|
|
17
18
|
"lib"
|
|
@@ -66,10 +67,11 @@
|
|
|
66
67
|
"gateway"
|
|
67
68
|
],
|
|
68
69
|
"scripts": {
|
|
69
|
-
"test": "node test/
|
|
70
|
+
"test": "node test/all.mjs",
|
|
70
71
|
"test:smoke": "node test/smoke.mjs",
|
|
71
72
|
"test:edges": "node test/edges.mjs",
|
|
72
|
-
"test:client": "node test/client-load.mjs"
|
|
73
|
+
"test:client": "node test/client-load.mjs",
|
|
74
|
+
"link:host": "node scripts/link-host.mjs"
|
|
73
75
|
},
|
|
74
76
|
"publishConfig": {
|
|
75
77
|
"access": "public",
|
package/lib/selection.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which models the user wants in the picker.
|
|
3
|
-
*
|
|
4
|
-
* Configuration can pin a list, but typing model ids into a YAML file is not a
|
|
5
|
-
* reasonable way to choose from forty of them, so the panel writes this small
|
|
6
|
-
* sidecar instead. It is deliberately separate from the settings document: the
|
|
7
|
-
* settings service projects a schema, and a growing list of upstream ids is not
|
|
8
|
-
* a schema.
|
|
9
|
-
* @module dsh-sub2api/selection
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
13
|
-
import { dirname } from "node:path";
|
|
14
|
-
|
|
15
|
-
export class SelectionStore {
|
|
16
|
-
/**
|
|
17
|
-
* @param {object} deps
|
|
18
|
-
* @param {() => string} deps.path file to keep the selection in
|
|
19
|
-
* @param {{warn: Function}} [deps.logger]
|
|
20
|
-
*/
|
|
21
|
-
constructor(deps) {
|
|
22
|
-
this.deps = deps;
|
|
23
|
-
this.logger = deps.logger ?? { warn() {} };
|
|
24
|
-
/** @type {string[] | undefined} */
|
|
25
|
-
this.ids = undefined;
|
|
26
|
-
this.loaded = false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async load() {
|
|
30
|
-
if (this.loaded) return this.current();
|
|
31
|
-
this.loaded = true;
|
|
32
|
-
try {
|
|
33
|
-
const text = await readFile(this.deps.path(), "utf8");
|
|
34
|
-
const parsed = JSON.parse(text);
|
|
35
|
-
if (Array.isArray(parsed?.ids)) {
|
|
36
|
-
this.ids = parsed.ids.filter((id) => typeof id === "string" && id.trim() !== "");
|
|
37
|
-
}
|
|
38
|
-
} catch {
|
|
39
|
-
// No file yet: an empty selection means "show everything".
|
|
40
|
-
}
|
|
41
|
-
return this.current();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** The stored ids, synchronously. Empty means no restriction. */
|
|
45
|
-
current() {
|
|
46
|
-
return Array.isArray(this.ids) ? this.ids : [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {string[]} ids model ids to keep; an empty list restores "show all"
|
|
51
|
-
* @returns {Promise<string[]>}
|
|
52
|
-
*/
|
|
53
|
-
async save(ids) {
|
|
54
|
-
const clean = [...new Set((Array.isArray(ids) ? ids : []).map((id) => String(id).trim()))]
|
|
55
|
-
.filter((id) => id !== "");
|
|
56
|
-
this.ids = clean;
|
|
57
|
-
this.loaded = true;
|
|
58
|
-
try {
|
|
59
|
-
await mkdir(dirname(this.deps.path()), { recursive: true });
|
|
60
|
-
await writeFile(this.deps.path(), JSON.stringify({ ids: clean }, null, 0), { mode: 0o600 });
|
|
61
|
-
} catch (error) {
|
|
62
|
-
this.logger.warn?.(`[sub2api] 模型选择保存失败:${error instanceof Error ? error.message : error}`);
|
|
63
|
-
}
|
|
64
|
-
return clean;
|
|
65
|
-
}
|
|
66
|
-
}
|