mslxdff 0.1.170 → 0.1.171
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 +3 -3
- package/docs/cli_help_mini.md +143 -0
- package/package.json +1 -1
- package/src/anthropic/count-tokens.js +39 -0
- package/src/anthropic/translate.js +20 -41
- package/src/auto.js +254 -254
- package/src/bench/cline-bench.js +42 -42
- package/src/bench/probe.js +70 -70
- package/src/bench/report.js +162 -162
- package/src/bench/runner.js +77 -77
- package/src/bench/via-probe.js +124 -124
- package/src/bench/via-routes.js +87 -87
- package/src/bench/workbuddy-bench.js +54 -54
- package/src/chat/engine.js +160 -160
- package/src/chat/gateway.js +163 -163
- package/src/chat/orchestrator.js +234 -234
- package/src/chat/prompt.js +70 -70
- package/src/chat/repl.js +88 -88
- package/src/chat/terminal.js +135 -135
- package/src/chat/tools.js +306 -306
- package/src/chat-pipeline/index.js +131 -131
- package/src/chat-pipeline/policy.js +76 -76
- package/src/cli/commands/group.js +249 -249
- package/src/cli/commands/model/picks.js +50 -50
- package/src/cli/commands/provider/bench-via.js +247 -247
- package/src/cli/commands/provider/bench.js +141 -141
- package/src/cli/commands/provider/index.js +133 -133
- package/src/cli/commands/provider/models.js +145 -145
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/sync.js +310 -310
- package/src/cli/status.js +279 -279
- package/src/daemon.js +112 -112
- package/src/model-capabilities/enrich.js +86 -86
- package/src/model-capabilities/index.js +183 -183
- package/src/model-capabilities/parse.js +70 -70
- package/src/models.js +225 -225
- package/src/providers/AGENTS.md +49 -0
- package/src/providers/cline/auth.js +228 -228
- package/src/providers/cline/chat.js +307 -307
- package/src/providers/cline.js +2 -2
- package/src/providers/codearts/concurrency.js +34 -0
- package/src/providers/codearts/index.js +11 -3
- package/src/providers/globalqwenwork/cosy.js +123 -123
- package/src/providers/globalqwenwork/crypto.js +218 -218
- package/src/providers/globalqwenwork/http.js +20 -20
- package/src/providers/globalqwenwork/payload.js +4 -2
- package/src/providers/globalqwenwork/rsa.js +54 -54
- package/src/providers/globalqwenwork/sse.js +268 -268
- package/src/providers/globalqwenwork/stream.js +130 -130
- package/src/providers/globalqwenwork/upstream.js +122 -122
- package/src/providers/keyring.js +60 -60
- package/src/providers/qoder/chat.js +203 -200
- package/src/providers/qoder/index.js +249 -249
- package/src/providers/qoder/sse.js +145 -145
- package/src/providers/qwenwork/account-store.js +133 -133
- package/src/providers/qwenwork/constants.js +67 -67
- package/src/providers/qwenwork/cosy.js +120 -120
- package/src/providers/qwenwork/crypto.js +218 -218
- package/src/providers/qwenwork/http.js +20 -20
- package/src/providers/qwenwork/index.js +327 -327
- package/src/providers/qwenwork/payload.js +144 -142
- package/src/providers/qwenwork/rsa.js +54 -54
- package/src/providers/qwenwork/sse.js +268 -268
- package/src/providers/qwenwork/stream.js +130 -130
- package/src/providers/qwenwork/upstream.js +120 -120
- package/src/providers/qwenwork.js +1 -1
- package/src/providers/raccoon/chat.js +10 -5
- package/src/providers/raccoon/const.js +4 -4
- package/src/providers/registry.js +79 -79
- package/src/providers/workbuddy/chat.js +248 -248
- package/src/providers/workbuddy/payload.js +16 -7
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/providers/zcode/chat.js +7 -0
- package/src/reasoning.js +32 -32
- package/src/responses/translate.js +4 -0
- package/src/routes/AGENTS.md +37 -0
- package/src/routes/chat/exhausted-handler.js +5 -0
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +294 -291
- package/src/routes/chat/via-route-handler.js +146 -146
- package/src/routes/hedge.js +255 -255
- package/src/routes/messages-route.js +1 -1
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +273 -273
- package/src/routes/stream-scan.js +47 -21
- package/src/routes/stream.js +385 -385
- package/src/runtime/bootstrap.js +50 -50
- package/src/runtime/provider-gate.js +36 -36
- package/src/runtime/providers-setup.js +165 -165
- package/src/server.js +69 -69
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- package/src/talk-full.js +1 -0
- package/src/talk-log.js +3 -2
- package/src/thinking-effort.js +67 -0
- package/src/transport/index.js +244 -244
- package/src/transport/pool.js +56 -56
- package/src/transport/retry.js +24 -24
- package/src/transport/sse.js +93 -93
- package/src/upstream-engine/sdk/convert.js +6 -0
- package/src/upstream-probe/display.js +52 -52
- package/src/upstream-probe/probe.js +49 -49
- package/src/upstream-probe/rotate.js +110 -110
- package/src/upstream-probe/start.js +45 -45
- package/src/upstream-responses.js +5 -0
- package/src/upstream.js +289 -289
package/src/server.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { createServer as httpCreateServer } from "node:http";
|
|
2
|
-
import { DEFAULT_PORT, getPort } from "./state.js";
|
|
3
|
-
import { flushAgentLoop } from "./talk-full.js"; // 关停收尾:talk/full 捕获是异步队列落盘,退出前排空(空队列时近似 O(1),且自身不抛)
|
|
4
|
-
|
|
5
|
-
export function startServer({ router, signals = true, host, onBeforeClose }, port = resolvePort()) {
|
|
6
|
-
const listenHost = host ?? resolveHost();
|
|
7
|
-
const server = httpCreateServer((req, res) => {
|
|
8
|
-
router(req, res).catch((err) => {
|
|
9
|
-
res.statusCode = 500;
|
|
10
|
-
res.setHeader("Content-Type", "application/json");
|
|
11
|
-
res.end(JSON.stringify({ error: String(err?.message || err) }));
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const ready = () =>
|
|
16
|
-
new Promise((resolve, reject) => {
|
|
17
|
-
server.on("error", reject);
|
|
18
|
-
if (listenHost) server.listen(port, listenHost, resolve);
|
|
19
|
-
else server.listen(port, resolve);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const close = async () => {
|
|
23
|
-
// 关停序列里唯一的新增步:先排空 agent 回路捕获(talk/full)的异步写队列,再走既有顺序
|
|
24
|
-
// (server:stop hook → server.close/closeAllConnections)。既有关停顺序语义一字未动;
|
|
25
|
-
// 队列空时 flush 即刻返回,且 flushAgentLoop 自身不抛(外层 try 只为兜住 import 侧意外)。
|
|
26
|
-
try { await flushAgentLoop(); } catch {}
|
|
27
|
-
// 插件 hook:server:stop — 关闭前触发(fire-and-forget,不阻塞关停)
|
|
28
|
-
try { await onBeforeClose?.(); } catch {}
|
|
29
|
-
await new Promise((resolve) => {
|
|
30
|
-
server.close(resolve);
|
|
31
|
-
// SSE debug streams keep connections open — force-close so shutdown
|
|
32
|
-
// never waits on them.
|
|
33
|
-
server.closeAllConnections?.();
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (signals) {
|
|
38
|
-
// 关停留痕(Linux 有效:可捕获 SIGTERM/SIGINT 并记录)。Windows 注意:process.kill 的
|
|
39
|
-
// SIGTERM 实为 TerminateProcess 强杀,被杀的 JS 进程收不到该事件,此处不会触发——
|
|
40
|
-
// Windows 的"谁杀了我"靠 src/daemon.js stopDaemon() 的杀者留痕 + 最后一条 heartbeat。
|
|
41
|
-
const onSignal = (sig) => {
|
|
42
|
-
try { console.log(`[lifecycle] ${sig} received — shutting down (pid ${process.pid}, uptime ${Math.round(process.uptime())}s)`); } catch {}
|
|
43
|
-
close();
|
|
44
|
-
};
|
|
45
|
-
process.on("SIGINT", () => onSignal("SIGINT"));
|
|
46
|
-
process.on("SIGTERM", () => onSignal("SIGTERM"));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return { server, ready, close };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function resolveHost() {
|
|
53
|
-
const envHost = process.env.MSLXDFF_HOST || process.env.MSLXDFF_BIND_HOST;
|
|
54
|
-
if (typeof envHost === "string" && envHost.trim()) return envHost.trim();
|
|
55
|
-
return "0.0.0.0";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function resolvePort() {
|
|
59
|
-
// 8989 is the hard default. Port only changes via an explicit, mslxdff-owned
|
|
60
|
-
// override: the persisted `-port N` setting, or the MSLXDFF_PORT env var.
|
|
61
|
-
// Bare `PORT` is deliberately NOT read — an ssh session / wrapper script
|
|
62
|
-
// commonly injects it and would silently override the default.
|
|
63
|
-
const persisted = getPort();
|
|
64
|
-
if (persisted) return persisted;
|
|
65
|
-
const env = Number(process.env.MSLXDFF_PORT);
|
|
66
|
-
// 0 = OS-assigned ephemeral port (valid; used by tests/containers)
|
|
67
|
-
if (Number.isInteger(env) && env >= 0) return env;
|
|
68
|
-
return DEFAULT_PORT;
|
|
69
|
-
}
|
|
1
|
+
import { createServer as httpCreateServer } from "node:http";
|
|
2
|
+
import { DEFAULT_PORT, getPort } from "./state.js";
|
|
3
|
+
import { flushAgentLoop } from "./talk-full.js"; // 关停收尾:talk/full 捕获是异步队列落盘,退出前排空(空队列时近似 O(1),且自身不抛)
|
|
4
|
+
|
|
5
|
+
export function startServer({ router, signals = true, host, onBeforeClose }, port = resolvePort()) {
|
|
6
|
+
const listenHost = host ?? resolveHost();
|
|
7
|
+
const server = httpCreateServer((req, res) => {
|
|
8
|
+
router(req, res).catch((err) => {
|
|
9
|
+
res.statusCode = 500;
|
|
10
|
+
res.setHeader("Content-Type", "application/json");
|
|
11
|
+
res.end(JSON.stringify({ error: String(err?.message || err) }));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const ready = () =>
|
|
16
|
+
new Promise((resolve, reject) => {
|
|
17
|
+
server.on("error", reject);
|
|
18
|
+
if (listenHost) server.listen(port, listenHost, resolve);
|
|
19
|
+
else server.listen(port, resolve);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const close = async () => {
|
|
23
|
+
// 关停序列里唯一的新增步:先排空 agent 回路捕获(talk/full)的异步写队列,再走既有顺序
|
|
24
|
+
// (server:stop hook → server.close/closeAllConnections)。既有关停顺序语义一字未动;
|
|
25
|
+
// 队列空时 flush 即刻返回,且 flushAgentLoop 自身不抛(外层 try 只为兜住 import 侧意外)。
|
|
26
|
+
try { await flushAgentLoop(); } catch {}
|
|
27
|
+
// 插件 hook:server:stop — 关闭前触发(fire-and-forget,不阻塞关停)
|
|
28
|
+
try { await onBeforeClose?.(); } catch {}
|
|
29
|
+
await new Promise((resolve) => {
|
|
30
|
+
server.close(resolve);
|
|
31
|
+
// SSE debug streams keep connections open — force-close so shutdown
|
|
32
|
+
// never waits on them.
|
|
33
|
+
server.closeAllConnections?.();
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (signals) {
|
|
38
|
+
// 关停留痕(Linux 有效:可捕获 SIGTERM/SIGINT 并记录)。Windows 注意:process.kill 的
|
|
39
|
+
// SIGTERM 实为 TerminateProcess 强杀,被杀的 JS 进程收不到该事件,此处不会触发——
|
|
40
|
+
// Windows 的"谁杀了我"靠 src/daemon.js stopDaemon() 的杀者留痕 + 最后一条 heartbeat。
|
|
41
|
+
const onSignal = (sig) => {
|
|
42
|
+
try { console.log(`[lifecycle] ${sig} received — shutting down (pid ${process.pid}, uptime ${Math.round(process.uptime())}s)`); } catch {}
|
|
43
|
+
close();
|
|
44
|
+
};
|
|
45
|
+
process.on("SIGINT", () => onSignal("SIGINT"));
|
|
46
|
+
process.on("SIGTERM", () => onSignal("SIGTERM"));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { server, ready, close };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function resolveHost() {
|
|
53
|
+
const envHost = process.env.MSLXDFF_HOST || process.env.MSLXDFF_BIND_HOST;
|
|
54
|
+
if (typeof envHost === "string" && envHost.trim()) return envHost.trim();
|
|
55
|
+
return "0.0.0.0";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function resolvePort() {
|
|
59
|
+
// 8989 is the hard default. Port only changes via an explicit, mslxdff-owned
|
|
60
|
+
// override: the persisted `-port N` setting, or the MSLXDFF_PORT env var.
|
|
61
|
+
// Bare `PORT` is deliberately NOT read — an ssh session / wrapper script
|
|
62
|
+
// commonly injects it and would silently override the default.
|
|
63
|
+
const persisted = getPort();
|
|
64
|
+
if (persisted) return persisted;
|
|
65
|
+
const env = Number(process.env.MSLXDFF_PORT);
|
|
66
|
+
// 0 = OS-assigned ephemeral port (valid; used by tests/containers)
|
|
67
|
+
if (Number.isInteger(env) && env >= 0) return env;
|
|
68
|
+
return DEFAULT_PORT;
|
|
69
|
+
}
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
-
import {
|
|
3
|
-
normalizeAllowedModel,
|
|
4
|
-
normalizeBaseUrl,
|
|
5
|
-
normalizeAuths,
|
|
6
|
-
normalizeEndpointPath,
|
|
7
|
-
loadProviderConfigs,
|
|
8
|
-
loadProviderConfig,
|
|
9
|
-
loadProviderBaseUrl,
|
|
10
|
-
loadProviderKeys,
|
|
11
|
-
} from "./provider.js";
|
|
12
|
-
|
|
13
|
-
export function loadProviderAllowedModels(id, { file = defaultStateFile() } = {}) {
|
|
14
|
-
const cfg = loadProviderConfig(id, { file });
|
|
15
|
-
if (cfg && Array.isArray(cfg.allowedModels)) return [...cfg.allowedModels];
|
|
16
|
-
const raw = readState(file).providerConfigs?.[id];
|
|
17
|
-
if (raw && Array.isArray(raw.allowedModels)) return [...new Set(raw.allowedModels.map((m) => normalizeAllowedModel(m, id)).filter(Boolean))];
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function saveProviderAllowedModels(id, list, { file = defaultStateFile() } = {}) {
|
|
22
|
-
const clean = [...new Set((Array.isArray(list) ? list : []).map((m) => normalizeAllowedModel(m, id)).filter(Boolean))];
|
|
23
|
-
const configs = { ...loadProviderConfigs({ file }) };
|
|
24
|
-
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
25
|
-
const baseUrl = normalizeBaseUrl(cur.baseUrl || loadProviderBaseUrl(id, { file }) || "");
|
|
26
|
-
const keys = Array.isArray(cur.keys) ? cur.keys : loadProviderKeys(id, { file });
|
|
27
|
-
const auths = normalizeAuths(cur.auths);
|
|
28
|
-
const modelsPath = typeof cur.modelsPath === "string" ? normalizeEndpointPath(cur.modelsPath) : "";
|
|
29
|
-
const chatPath = typeof cur.chatPath === "string" ? normalizeEndpointPath(cur.chatPath) : "";
|
|
30
|
-
// allowAnyModels 是独立语义开关:只有它也设过时,即使其余字段全空也不能整键删(否则 clear 会把「允许任意」连带抹掉,供应商从放行降级成全拦 403)
|
|
31
|
-
if (!baseUrl && !keys.length && !auths.length && !clean.length && !modelsPath && !chatPath && typeof cur.allowAnyModels !== "boolean") {
|
|
32
|
-
delete configs[id];
|
|
33
|
-
} else {
|
|
34
|
-
configs[id] = { baseUrl, keys };
|
|
35
|
-
// 重建 cfg 是 `{ baseUrl, keys }` 起手,不显式带 allowAnyModels 就会静默丢用户的「允许任意」设置
|
|
36
|
-
// (实测 2026-09-24:saveProviderAllowedModels 把 allowAnyModels:true 抹成默认 false)。
|
|
37
|
-
// cline 白名单 auto-sync 会周期性写这里,丢了就是持续丢,必须保留。
|
|
38
|
-
if (typeof cur.allowAnyModels === "boolean") configs[id].allowAnyModels = cur.allowAnyModels;
|
|
39
|
-
if (auths.length) configs[id].auths = auths;
|
|
40
|
-
if (clean.length) configs[id].allowedModels = clean;
|
|
41
|
-
if (modelsPath) configs[id].modelsPath = modelsPath;
|
|
42
|
-
if (chatPath) configs[id].chatPath = chatPath;
|
|
43
|
-
}
|
|
44
|
-
writeStateImmediate(file, { providerConfigs: configs });
|
|
45
|
-
return clean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function addProviderAllowedModel(id, model, opts = {}) {
|
|
49
|
-
const cur = loadProviderAllowedModels(id, opts);
|
|
50
|
-
const norm = normalizeAllowedModel(model, id);
|
|
51
|
-
if (!norm || cur.includes(norm)) return cur;
|
|
52
|
-
return saveProviderAllowedModels(id, [...cur, norm], opts);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function removeProviderAllowedModel(id, model, opts = {}) {
|
|
56
|
-
return removeProviderAllowedModels(id, [model], opts);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function removeProviderAllowedModels(id, targets = [], opts = {}) {
|
|
60
|
-
const set = new Set((Array.isArray(targets) ? targets : [targets]).map((m) => normalizeAllowedModel(m, id)).filter(Boolean));
|
|
61
|
-
const cur = loadProviderAllowedModels(id, opts);
|
|
62
|
-
const next = cur.filter((m) => !set.has(m));
|
|
63
|
-
return saveProviderAllowedModels(id, next, opts);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function normalizeAllowAny(v, id) {
|
|
67
|
-
if (typeof v === "boolean") return v;
|
|
68
|
-
if (String(id || "").toLowerCase() === "opencode") return true;
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
export function loadProviderAllowAnyModels(id, { file = defaultStateFile() } = {}) {
|
|
72
|
-
const cfg = readState(file).providerConfigs?.[id];
|
|
73
|
-
if (cfg && typeof cfg.allowAnyModels === "boolean") return cfg.allowAnyModels;
|
|
74
|
-
return normalizeAllowAny(undefined, id);
|
|
75
|
-
}
|
|
76
|
-
export function saveProviderAllowAnyModels(id, allowAny, { file = defaultStateFile() } = {}) {
|
|
77
|
-
const state = readState(file);
|
|
78
|
-
const cfgs = { ...(state.providerConfigs || {}) };
|
|
79
|
-
const cur = cfgs[id] || {};
|
|
80
|
-
cfgs[id] = { ...cur, allowAnyModels: normalizeAllowAny(allowAny, id) };
|
|
81
|
-
writeStateImmediate(file, { providerConfigs: cfgs });
|
|
82
|
-
return cfgs[id].allowAnyModels;
|
|
83
|
-
}
|
|
84
|
-
export function isModelAllowed(id, rawModel, { file = defaultStateFile() } = {}) {
|
|
85
|
-
const raw = String(rawModel || "").trim();
|
|
86
|
-
if (!raw) return true;
|
|
87
|
-
const allowed = loadProviderAllowedModels(id, { file });
|
|
88
|
-
const allowAny = loadProviderAllowAnyModels(id, { file });
|
|
89
|
-
if (!allowed.length) return allowAny;
|
|
90
|
-
const norm = normalizeAllowedModel(raw, id);
|
|
91
|
-
return allowed.includes(norm);
|
|
92
|
-
}
|
|
1
|
+
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
+
import {
|
|
3
|
+
normalizeAllowedModel,
|
|
4
|
+
normalizeBaseUrl,
|
|
5
|
+
normalizeAuths,
|
|
6
|
+
normalizeEndpointPath,
|
|
7
|
+
loadProviderConfigs,
|
|
8
|
+
loadProviderConfig,
|
|
9
|
+
loadProviderBaseUrl,
|
|
10
|
+
loadProviderKeys,
|
|
11
|
+
} from "./provider.js";
|
|
12
|
+
|
|
13
|
+
export function loadProviderAllowedModels(id, { file = defaultStateFile() } = {}) {
|
|
14
|
+
const cfg = loadProviderConfig(id, { file });
|
|
15
|
+
if (cfg && Array.isArray(cfg.allowedModels)) return [...cfg.allowedModels];
|
|
16
|
+
const raw = readState(file).providerConfigs?.[id];
|
|
17
|
+
if (raw && Array.isArray(raw.allowedModels)) return [...new Set(raw.allowedModels.map((m) => normalizeAllowedModel(m, id)).filter(Boolean))];
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function saveProviderAllowedModels(id, list, { file = defaultStateFile() } = {}) {
|
|
22
|
+
const clean = [...new Set((Array.isArray(list) ? list : []).map((m) => normalizeAllowedModel(m, id)).filter(Boolean))];
|
|
23
|
+
const configs = { ...loadProviderConfigs({ file }) };
|
|
24
|
+
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
25
|
+
const baseUrl = normalizeBaseUrl(cur.baseUrl || loadProviderBaseUrl(id, { file }) || "");
|
|
26
|
+
const keys = Array.isArray(cur.keys) ? cur.keys : loadProviderKeys(id, { file });
|
|
27
|
+
const auths = normalizeAuths(cur.auths);
|
|
28
|
+
const modelsPath = typeof cur.modelsPath === "string" ? normalizeEndpointPath(cur.modelsPath) : "";
|
|
29
|
+
const chatPath = typeof cur.chatPath === "string" ? normalizeEndpointPath(cur.chatPath) : "";
|
|
30
|
+
// allowAnyModels 是独立语义开关:只有它也设过时,即使其余字段全空也不能整键删(否则 clear 会把「允许任意」连带抹掉,供应商从放行降级成全拦 403)
|
|
31
|
+
if (!baseUrl && !keys.length && !auths.length && !clean.length && !modelsPath && !chatPath && typeof cur.allowAnyModels !== "boolean") {
|
|
32
|
+
delete configs[id];
|
|
33
|
+
} else {
|
|
34
|
+
configs[id] = { baseUrl, keys };
|
|
35
|
+
// 重建 cfg 是 `{ baseUrl, keys }` 起手,不显式带 allowAnyModels 就会静默丢用户的「允许任意」设置
|
|
36
|
+
// (实测 2026-09-24:saveProviderAllowedModels 把 allowAnyModels:true 抹成默认 false)。
|
|
37
|
+
// cline 白名单 auto-sync 会周期性写这里,丢了就是持续丢,必须保留。
|
|
38
|
+
if (typeof cur.allowAnyModels === "boolean") configs[id].allowAnyModels = cur.allowAnyModels;
|
|
39
|
+
if (auths.length) configs[id].auths = auths;
|
|
40
|
+
if (clean.length) configs[id].allowedModels = clean;
|
|
41
|
+
if (modelsPath) configs[id].modelsPath = modelsPath;
|
|
42
|
+
if (chatPath) configs[id].chatPath = chatPath;
|
|
43
|
+
}
|
|
44
|
+
writeStateImmediate(file, { providerConfigs: configs });
|
|
45
|
+
return clean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function addProviderAllowedModel(id, model, opts = {}) {
|
|
49
|
+
const cur = loadProviderAllowedModels(id, opts);
|
|
50
|
+
const norm = normalizeAllowedModel(model, id);
|
|
51
|
+
if (!norm || cur.includes(norm)) return cur;
|
|
52
|
+
return saveProviderAllowedModels(id, [...cur, norm], opts);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function removeProviderAllowedModel(id, model, opts = {}) {
|
|
56
|
+
return removeProviderAllowedModels(id, [model], opts);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function removeProviderAllowedModels(id, targets = [], opts = {}) {
|
|
60
|
+
const set = new Set((Array.isArray(targets) ? targets : [targets]).map((m) => normalizeAllowedModel(m, id)).filter(Boolean));
|
|
61
|
+
const cur = loadProviderAllowedModels(id, opts);
|
|
62
|
+
const next = cur.filter((m) => !set.has(m));
|
|
63
|
+
return saveProviderAllowedModels(id, next, opts);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function normalizeAllowAny(v, id) {
|
|
67
|
+
if (typeof v === "boolean") return v;
|
|
68
|
+
if (String(id || "").toLowerCase() === "opencode") return true;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
export function loadProviderAllowAnyModels(id, { file = defaultStateFile() } = {}) {
|
|
72
|
+
const cfg = readState(file).providerConfigs?.[id];
|
|
73
|
+
if (cfg && typeof cfg.allowAnyModels === "boolean") return cfg.allowAnyModels;
|
|
74
|
+
return normalizeAllowAny(undefined, id);
|
|
75
|
+
}
|
|
76
|
+
export function saveProviderAllowAnyModels(id, allowAny, { file = defaultStateFile() } = {}) {
|
|
77
|
+
const state = readState(file);
|
|
78
|
+
const cfgs = { ...(state.providerConfigs || {}) };
|
|
79
|
+
const cur = cfgs[id] || {};
|
|
80
|
+
cfgs[id] = { ...cur, allowAnyModels: normalizeAllowAny(allowAny, id) };
|
|
81
|
+
writeStateImmediate(file, { providerConfigs: cfgs });
|
|
82
|
+
return cfgs[id].allowAnyModels;
|
|
83
|
+
}
|
|
84
|
+
export function isModelAllowed(id, rawModel, { file = defaultStateFile() } = {}) {
|
|
85
|
+
const raw = String(rawModel || "").trim();
|
|
86
|
+
if (!raw) return true;
|
|
87
|
+
const allowed = loadProviderAllowedModels(id, { file });
|
|
88
|
+
const allowAny = loadProviderAllowAnyModels(id, { file });
|
|
89
|
+
if (!allowed.length) return allowAny;
|
|
90
|
+
const norm = normalizeAllowedModel(raw, id);
|
|
91
|
+
return allowed.includes(norm);
|
|
92
|
+
}
|