dsh-sub2api 0.1.6 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
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/smoke.mjs && node test/edges.mjs && node test/client-load.mjs",
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
- }