mslxdff 0.1.4 → 0.1.5
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/bin/mslxdff.js +64 -0
- package/package.json +2 -2
package/bin/mslxdff.js
CHANGED
|
@@ -55,6 +55,60 @@ if (args.includes("-status") || args.includes("--status") || args.includes("-s")
|
|
|
55
55
|
process.exit(0);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// -model list | -models : show the free models this proxy serves (cache-first)
|
|
59
|
+
// -model refresh : force a fresh fetch from the upstream and update the cache
|
|
60
|
+
if (args.includes("-model") || args.includes("-models")) {
|
|
61
|
+
const idx = args.findIndex((x) => x === "-model" || x === "-models");
|
|
62
|
+
const sub = args[idx + 1];
|
|
63
|
+
if (sub === "refresh") {
|
|
64
|
+
const models = createModelsService({
|
|
65
|
+
baseUrl: process.env.UPSTREAM_BASE_URL || "https://opencode.ai",
|
|
66
|
+
headers: createUpstreamClient({}).headers,
|
|
67
|
+
refreshMs: 0,
|
|
68
|
+
cacheFile: join(logDir(), "models.json"),
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
const list = await models.get();
|
|
72
|
+
const ids = (list.data || []).map((m) => m.id).filter(Boolean);
|
|
73
|
+
console.log(`refreshed: ${ids.length} free model(s)`);
|
|
74
|
+
for (const id of ids) console.log(` ${id}`);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.error(`could not refresh models: ${String(err?.message || err)}`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|
|
81
|
+
if (sub !== undefined && sub !== "list") {
|
|
82
|
+
console.error("usage: mslxdff -model list | mslxdff -model refresh");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
const cacheFile = join(logDir(), "models.json");
|
|
86
|
+
try {
|
|
87
|
+
const cached = readModelsCache(cacheFile);
|
|
88
|
+
if (cached) {
|
|
89
|
+
const ids = (cached.data || []).map((m) => m.id).filter(Boolean);
|
|
90
|
+
const at = cached.cachedAt ? ` (cached ${new Date(cached.cachedAt).toISOString().slice(0, 16).replace("T", " ")})` : "";
|
|
91
|
+
console.log(`${ids.length} free model(s)${at}:`);
|
|
92
|
+
for (const id of ids) console.log(` ${id}`);
|
|
93
|
+
} else {
|
|
94
|
+
const models = createModelsService({
|
|
95
|
+
baseUrl: process.env.UPSTREAM_BASE_URL || "https://opencode.ai",
|
|
96
|
+
headers: createUpstreamClient({}).headers,
|
|
97
|
+
refreshMs: 0,
|
|
98
|
+
cacheFile,
|
|
99
|
+
});
|
|
100
|
+
const list = await models.get();
|
|
101
|
+
const ids = (list.data || []).map((m) => m.id).filter(Boolean);
|
|
102
|
+
console.log(`${ids.length} free model(s):`);
|
|
103
|
+
for (const id of ids) console.log(` ${id}`);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error(`could not fetch models: ${String(err?.message || err)}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
|
|
58
112
|
// -creategroup <name> | -group create <name> | -group sync | -group leave <name> | -group list |
|
|
59
113
|
// -addtogroup <leader-host> <name> | -resetban [ip]
|
|
60
114
|
const createGroupArg = argValue("-creategroup", "--creategroup") || groupIs("create", args);
|
|
@@ -178,6 +232,14 @@ function markJoined(entry) {
|
|
|
178
232
|
|
|
179
233
|
const errMsg = (err) => String(err?.message || err);
|
|
180
234
|
|
|
235
|
+
function readModelsCache(cacheFile) {
|
|
236
|
+
try {
|
|
237
|
+
return JSON.parse(readFileSync(cacheFile, "utf8"));
|
|
238
|
+
} catch {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
181
243
|
// Sync every joined group into the local peer list. Leaders read their local
|
|
182
244
|
// groups state; members re-register with the leader (idempotent) to get the
|
|
183
245
|
// freshest member list. Returns per-group results.
|
|
@@ -398,6 +460,8 @@ Usage:
|
|
|
398
460
|
mslxdff start as a background daemon and exit (status + help if one is already running)
|
|
399
461
|
mslxdff -d start as a background daemon
|
|
400
462
|
mslxdff -status show current status (daemon, models, recent calls, last error)
|
|
463
|
+
mslxdff -model list list the free models this proxy serves (cached)
|
|
464
|
+
mslxdff -model refresh force-refresh the model cache from the upstream
|
|
401
465
|
mslxdff -stop stop the running daemon
|
|
402
466
|
mslxdff -port N persist the listen port (restarts the daemon on it if running)
|
|
403
467
|
mslxdff -update update mslxdff to the latest published version
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mslxdff",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "测试项目,请勿使用。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node bin/mslxdff.js",
|
|
11
|
-
"test": "node --test test
|
|
11
|
+
"test": "node --test test/*.test.js"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20"
|