mslxdff 0.1.155 → 0.1.158
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 +4 -4
- package/docs/ARCHITECTURE.md +426 -0
- package/docs/FEATURE_TREE.md +164 -0
- package/docs/MOBILE.md +82 -0
- package/docs/adr/0001-reasoning-content-injection.md +14 -0
- package/docs/adr/0002-models-free-filter.md +12 -0
- package/docs/adr/0003-zero-state-no-auth.md +10 -0
- package/docs/adr/0004-bearer-token.md +18 -0
- package/docs/adr/0005-peer-mesh.md +53 -0
- package/docs/adr/0006-broadband-member.md +103 -0
- package/docs/adr/0007-multi-provider-prefix.md +25 -0
- package/docs/adr/0008-share-keys-to-peers.md +52 -0
- package/docs/adr/0009-chat-repl.md +37 -0
- package/docs/adr/0010-allowlist.md +36 -0
- package/docs/adr/0011-broadband-stream.md +30 -0
- package/docs/adr/0012-responses-endpoint-codex-sync.md +48 -0
- package/docs/adr/0013-node16-compat.md +41 -0
- package/docs/adr/0014-deepseek-provider.md +52 -0
- package/docs/adr/0015-upstream-probe-routing.md +50 -0
- package/docs/adr/0016-model-capabilities.md +27 -0
- package/docs/adr/0017-ai-sdk-upstream-engine.md +59 -0
- package/docs/adr/0018-zen-client-identity.md +52 -0
- package/docs/adr/0019-share-keys-always-lend.md +59 -0
- package/docs/adr/0020-zen-free-lane-agent-shape.md +52 -0
- package/docs/adr/0021-usage-report-jsonl.md +47 -0
- package/docs/adr/0022-models-capability-merge.md +61 -0
- package/docs/adr/0023-key-provider-default-direct.md +58 -0
- package/docs/adr/0024-node18-baseline.md +63 -0
- package/docs/adr/0025-workbuddy-authdir-follows-state.md +71 -0
- package/docs/adr/0026-cline-provider-id-unify.md +67 -0
- package/docs/adr/0027-codearts-provider.md +48 -0
- package/docs/adr/0028-traework-provider.md +34 -0
- package/docs/adr/0029-qoder-native-provider.md +60 -0
- package/docs/adr/0030-models-list-scoped-by-picks.md +53 -0
- package/docs/adr/0031-qoder-true-streaming.md +50 -0
- package/docs/adr/0032-generic-responses-channel.md +72 -0
- package/docs/adr/0033-cline-allowlist-auto-sync.md +75 -0
- package/docs/adr/0034-request-level-human-readable-observability.md +60 -0
- package/docs/adr/0035-sdk-channel-headers-timeout.md +49 -0
- package/docs/adr/0036-qoder-per-request-sticky-account.md +82 -0
- package/docs/adr/0037-qwenwork-independent-provider.md +82 -0
- package/docs/adr/0038-zcode-provider.md +140 -0
- package/docs/agents/domain.md +51 -0
- package/docs/agents/issue-tracker.md +30 -0
- package/docs/agents/triage-labels.md +15 -0
- package/docs/cli_help.md +1391 -0
- package/docs/cli_help_mini.md +133 -0
- package/docs/plans/bench-via-latency-2026-09-01.md +215 -0
- package/docs/plugins.md +187 -0
- package/package.json +1 -1
- 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 +123 -123
- package/src/chat-pipeline/policy.js +76 -76
- package/src/chat-pipeline/serial-trial.js +210 -210
- package/src/cli/commands/group.js +249 -249
- package/src/cli/commands/model/list-providers.js +4 -3
- package/src/cli/commands/model/list-render.js +7 -9
- package/src/cli/commands/model/list-sort.js +52 -0
- package/src/cli/commands/model/list-tty.js +76 -0
- package/src/cli/commands/model/list.js +5 -62
- 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 +124 -116
- package/src/cli/commands/provider/models.js +139 -128
- package/src/cli/commands/provider/qwenwork-login.js +119 -0
- package/src/cli/commands/provider/zcode-login.js +77 -0
- package/src/cli/commands/provider/zcode-quota.js +55 -0
- package/src/cli/commands/sync.js +232 -232
- package/src/cli/provider-row.js +2 -2
- package/src/cli/status.js +279 -279
- package/src/daemon.js +96 -96
- 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/model-trace.js +1 -0
- package/src/models.js +225 -225
- package/src/providers/classify.js +1 -1
- 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/keyring.js +60 -56
- package/src/providers/qoder/chat.js +183 -100
- package/src/providers/qoder/index.js +230 -184
- package/src/providers/qoder/sse.js +103 -46
- package/src/providers/qoder/sticky.js +1 -0
- package/src/providers/qoder/stream.js +32 -9
- package/src/providers/qwenwork/account-store.js +133 -0
- package/src/providers/qwenwork/constants.js +67 -0
- package/src/providers/qwenwork/cosy.js +120 -0
- package/src/providers/qwenwork/crypto.js +218 -0
- package/src/providers/qwenwork/http.js +20 -0
- package/src/providers/qwenwork/index.js +327 -0
- package/src/providers/qwenwork/payload.js +142 -0
- package/src/providers/qwenwork/rsa.js +54 -0
- package/src/providers/qwenwork/sse.js +268 -0
- package/src/providers/qwenwork/stream.js +130 -0
- package/src/providers/qwenwork/upstream.js +120 -0
- package/src/providers/qwenwork.js +1 -0
- package/src/providers/registry.js +66 -56
- package/src/providers/share-keys.js +2 -2
- package/src/providers/workbuddy/chat.js +248 -248
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/providers/zcode/account-store.js +129 -0
- package/src/providers/zcode/auth.js +28 -0
- package/src/providers/zcode/chat.js +171 -0
- package/src/providers/zcode/const.js +54 -0
- package/src/providers/zcode/headers.js +55 -0
- package/src/providers/zcode/index.js +124 -0
- package/src/providers/zcode/models.js +65 -0
- package/src/providers/zcode/oauth.js +120 -0
- package/src/providers/zcode/quota.js +176 -0
- package/src/providers/zcode/sse.js +179 -0
- package/src/reasoning.js +32 -32
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +250 -246
- package/src/routes/chat/via-route-handler.js +144 -144
- package/src/routes/hedge.js +255 -255
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +273 -273
- package/src/routes/stream.js +438 -399
- package/src/runtime/bootstrap.js +45 -45
- package/src/runtime/provider-gate.js +33 -30
- package/src/runtime/providers-setup.js +165 -165
- package/src/server.js +64 -64
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- 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-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.js +289 -289
package/src/daemon.js
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { appendFileSync, existsSync, mkdirSync, openSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
3
|
-
import { join, dirname } from "node:path";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
|
|
7
|
-
export function daemonDir() {
|
|
8
|
-
return process.env.MSLXDFF_DAEMON_DIR || join(os.homedir(), ".config", "mslxdff");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function pidFile() {
|
|
12
|
-
return join(daemonDir(), "daemon.pid");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function logFile() {
|
|
16
|
-
return join(daemonDir(), "daemon.log");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 当前代码所在的 CLI 入口(bin/mslxdff.js 绝对路径):startDaemon 与
|
|
20
|
-
// auto-update 的 -restart 委托共用(后者从 daemon 进程 spawn 时必须指向同一份代码)。
|
|
21
|
-
export function daemonEntry() {
|
|
22
|
-
const here = fileURLToPath(import.meta.url);
|
|
23
|
-
return here.endsWith("bin/mslxdff.js")
|
|
24
|
-
? here
|
|
25
|
-
: join(dirname(here), "..", "bin", "mslxdff.js");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function startDaemon(args = []) {
|
|
29
|
-
const entry = daemonEntry();
|
|
30
|
-
const dir = daemonDir();
|
|
31
|
-
mkdirSync(dir, { recursive: true });
|
|
32
|
-
const logFd = openSync(logFile(), "a", 0o600);
|
|
33
|
-
const env = { ...process.env, MSLXDFF_DAEMON: "1" };
|
|
34
|
-
// a -debug foreground session wouldn't pass MSLXDFF_DEBUG to the
|
|
35
|
-
// background daemon it restores (that flag means "print events to stdout")
|
|
36
|
-
delete env.MSLXDFF_DEBUG;
|
|
37
|
-
const child = spawn(process.execPath, [entry, ...args, "--daemon"], {
|
|
38
|
-
detached: true,
|
|
39
|
-
stdio: ["ignore", logFd, logFd],
|
|
40
|
-
env,
|
|
41
|
-
});
|
|
42
|
-
child.unref();
|
|
43
|
-
return child.pid;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function writePid(pid, version) {
|
|
47
|
-
const dir = daemonDir();
|
|
48
|
-
mkdirSync(dir, { recursive: true });
|
|
49
|
-
writeFileSync(pidFile(), version ? `${pid}\n${version}` : String(pid), { mode: 0o600 });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function readPid() {
|
|
53
|
-
if (!existsSync(pidFile())) return null;
|
|
54
|
-
const raw = readFileSync(pidFile(), "utf8").trim();
|
|
55
|
-
const n = Number(raw.split("\n")[0]);
|
|
56
|
-
return Number.isInteger(n) && n > 0 ? n : null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function readPidVersion() {
|
|
60
|
-
if (!existsSync(pidFile())) return null;
|
|
61
|
-
const raw = readFileSync(pidFile(), "utf8");
|
|
62
|
-
const lines = raw.split("\n");
|
|
63
|
-
return lines.length > 1 && lines[1].trim() ? lines[1].trim() : null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Best-effort liveness check (signal 0); ESRCH means the process is gone.
|
|
67
|
-
export function isPidAlive(pid) {
|
|
68
|
-
try {
|
|
69
|
-
process.kill(pid, 0);
|
|
70
|
-
return true;
|
|
71
|
-
} catch (err) {
|
|
72
|
-
return err.code !== "ESRCH";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function stopDaemon() {
|
|
77
|
-
const pid = readPid();
|
|
78
|
-
if (!pid) return { stopped: false, reason: "no pid file" };
|
|
79
|
-
// 杀者留痕(写 daemon.log):Windows 的 SIGTERM 是 TerminateProcess 强杀,被杀的 daemon
|
|
80
|
-
// 在 JS 层收不到任何事件(无法自记),故由"杀者"记录调用方 pid——
|
|
81
|
-
// 没有这行 = 非我方所杀(外部 taskkill/任务管理器/崩溃),配合最后一条 heartbeat 定位死亡时刻。
|
|
82
|
-
try {
|
|
83
|
-
appendFileSync(logFile(), `[lifecycle] stopDaemon called by pid=${process.pid} — killing daemon pid=${pid}\n`);
|
|
84
|
-
} catch {}
|
|
85
|
-
try {
|
|
86
|
-
process.kill(pid, "SIGTERM");
|
|
87
|
-
} catch (err) {
|
|
88
|
-
if (err.code !== "ESRCH") throw err;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
unlinkSync(pidFile());
|
|
92
|
-
} catch {
|
|
93
|
-
// already gone
|
|
94
|
-
}
|
|
95
|
-
return { stopped: true, pid };
|
|
96
|
-
}
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, openSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { join, dirname } from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
export function daemonDir() {
|
|
8
|
+
return process.env.MSLXDFF_DAEMON_DIR || join(os.homedir(), ".config", "mslxdff");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function pidFile() {
|
|
12
|
+
return join(daemonDir(), "daemon.pid");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function logFile() {
|
|
16
|
+
return join(daemonDir(), "daemon.log");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 当前代码所在的 CLI 入口(bin/mslxdff.js 绝对路径):startDaemon 与
|
|
20
|
+
// auto-update 的 -restart 委托共用(后者从 daemon 进程 spawn 时必须指向同一份代码)。
|
|
21
|
+
export function daemonEntry() {
|
|
22
|
+
const here = fileURLToPath(import.meta.url);
|
|
23
|
+
return here.endsWith("bin/mslxdff.js")
|
|
24
|
+
? here
|
|
25
|
+
: join(dirname(here), "..", "bin", "mslxdff.js");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function startDaemon(args = []) {
|
|
29
|
+
const entry = daemonEntry();
|
|
30
|
+
const dir = daemonDir();
|
|
31
|
+
mkdirSync(dir, { recursive: true });
|
|
32
|
+
const logFd = openSync(logFile(), "a", 0o600);
|
|
33
|
+
const env = { ...process.env, MSLXDFF_DAEMON: "1" };
|
|
34
|
+
// a -debug foreground session wouldn't pass MSLXDFF_DEBUG to the
|
|
35
|
+
// background daemon it restores (that flag means "print events to stdout")
|
|
36
|
+
delete env.MSLXDFF_DEBUG;
|
|
37
|
+
const child = spawn(process.execPath, [entry, ...args, "--daemon"], {
|
|
38
|
+
detached: true,
|
|
39
|
+
stdio: ["ignore", logFd, logFd],
|
|
40
|
+
env,
|
|
41
|
+
});
|
|
42
|
+
child.unref();
|
|
43
|
+
return child.pid;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function writePid(pid, version) {
|
|
47
|
+
const dir = daemonDir();
|
|
48
|
+
mkdirSync(dir, { recursive: true });
|
|
49
|
+
writeFileSync(pidFile(), version ? `${pid}\n${version}` : String(pid), { mode: 0o600 });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function readPid() {
|
|
53
|
+
if (!existsSync(pidFile())) return null;
|
|
54
|
+
const raw = readFileSync(pidFile(), "utf8").trim();
|
|
55
|
+
const n = Number(raw.split("\n")[0]);
|
|
56
|
+
return Number.isInteger(n) && n > 0 ? n : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function readPidVersion() {
|
|
60
|
+
if (!existsSync(pidFile())) return null;
|
|
61
|
+
const raw = readFileSync(pidFile(), "utf8");
|
|
62
|
+
const lines = raw.split("\n");
|
|
63
|
+
return lines.length > 1 && lines[1].trim() ? lines[1].trim() : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Best-effort liveness check (signal 0); ESRCH means the process is gone.
|
|
67
|
+
export function isPidAlive(pid) {
|
|
68
|
+
try {
|
|
69
|
+
process.kill(pid, 0);
|
|
70
|
+
return true;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return err.code !== "ESRCH";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function stopDaemon() {
|
|
77
|
+
const pid = readPid();
|
|
78
|
+
if (!pid) return { stopped: false, reason: "no pid file" };
|
|
79
|
+
// 杀者留痕(写 daemon.log):Windows 的 SIGTERM 是 TerminateProcess 强杀,被杀的 daemon
|
|
80
|
+
// 在 JS 层收不到任何事件(无法自记),故由"杀者"记录调用方 pid——
|
|
81
|
+
// 没有这行 = 非我方所杀(外部 taskkill/任务管理器/崩溃),配合最后一条 heartbeat 定位死亡时刻。
|
|
82
|
+
try {
|
|
83
|
+
appendFileSync(logFile(), `[lifecycle] stopDaemon called by pid=${process.pid} — killing daemon pid=${pid}\n`);
|
|
84
|
+
} catch {}
|
|
85
|
+
try {
|
|
86
|
+
process.kill(pid, "SIGTERM");
|
|
87
|
+
} catch (err) {
|
|
88
|
+
if (err.code !== "ESRCH") throw err;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
unlinkSync(pidFile());
|
|
92
|
+
} catch {
|
|
93
|
+
// already gone
|
|
94
|
+
}
|
|
95
|
+
return { stopped: true, pid };
|
|
96
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
// -setto opencode 条目能力注入(ADR-0016 联动):把 models.dev 能力写进 opencode.json
|
|
2
|
-
// 的 per-model 条目(opencode Model 形状,实测 debug config 原样保留并生效),
|
|
3
|
-
// 并产出一行人话摘要供 CLI 展示。查不到能力(未收录 provider/模型)时原样返回不硬造。
|
|
4
|
-
import { globalCapabilities } from "./index.js";
|
|
5
|
-
|
|
6
|
-
// "bai/glm-5.3-flash" → { provider: "bai", raw: "glm-5.3-flash" };裸 id 归 opencode
|
|
7
|
-
function splitProvider(modelId) {
|
|
8
|
-
const s = String(modelId || "").trim();
|
|
9
|
-
const i = s.indexOf("/");
|
|
10
|
-
if (i > 0) return { provider: s.slice(0, i).toLowerCase(), raw: s.slice(i + 1) };
|
|
11
|
-
return { provider: "opencode", raw: s };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// caps → opencode Model 形状增量(只含能力字段,name 等原有键不动)
|
|
15
|
-
// variants:config 条目显式档位(provider.ts config 路径 mergeDeep(config.variants) 优先于启发式,
|
|
16
|
-
// 绕过 transform.ts 黑名单——glm/kimi/deepseek-v3/minimax/qwen/big-pickle 启发式恒 return {})。
|
|
17
|
-
// 参数形状 reasoningEffort 对齐 @ai-sdk/openai-compatible(muse-spark 启发式同款)。
|
|
18
|
-
// toggle/budget_tokens 型不注入(OpenAI 兼容协议无标准开关参数,留启发式判断)。
|
|
19
|
-
function capsToEntryFields(caps) {
|
|
20
|
-
if (!caps) return null;
|
|
21
|
-
const fields = {
|
|
22
|
-
reasoning: Boolean(caps.reasoning),
|
|
23
|
-
tool_call: Boolean(caps.toolCall),
|
|
24
|
-
attachment: Boolean(caps.attachment),
|
|
25
|
-
temperature: Boolean(caps.temperature),
|
|
26
|
-
modalities: { input: caps.inputModalities || ["text"], output: caps.outputModalities || ["text"] },
|
|
27
|
-
limit: { context: Number(caps.context) || 0, output: Number(caps.maxOutput) || 0 },
|
|
28
|
-
};
|
|
29
|
-
if (caps.effortType === "effort" && Array.isArray(caps.effortValues) && caps.effortValues.length) {
|
|
30
|
-
fields.variants = Object.fromEntries(caps.effortValues.map((v) => [String(v), { reasoningEffort: String(v) }]));
|
|
31
|
-
}
|
|
32
|
-
if (caps.releaseDate) fields.release_date = caps.releaseDate;
|
|
33
|
-
if (caps.costIn != null || caps.costOut != null) {
|
|
34
|
-
fields.cost = { input: Number(caps.costIn) || 0, output: Number(caps.costOut) || 0 };
|
|
35
|
-
}
|
|
36
|
-
return fields;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// entry: 现有条目(含 name 等);modelId: 内部 canonical id;capsSvc: 可注入(默认全局单例)
|
|
40
|
-
// wbSource: workbuddy 动态源接缝(测试注入;生产 = workbuddyAllModels 上游原生字段)
|
|
41
|
-
// 返回 { entry: 增强后条目, caps: caps|null };服务异常静默降级(同步命令不能因目录拉取失败而挂)
|
|
42
|
-
export async function enrichOpencodeEntry(entry, modelId, capsSvc, wbSource) {
|
|
43
|
-
const base = entry && typeof entry === "object" && !Array.isArray(entry) ? entry : {};
|
|
44
|
-
const svc = capsSvc === undefined ? globalCapabilities() : capsSvc;
|
|
45
|
-
if (!svc) return { entry: base, caps: null };
|
|
46
|
-
const { provider, raw } = splitProvider(modelId);
|
|
47
|
-
let caps = null;
|
|
48
|
-
try {
|
|
49
|
-
await svc.ready();
|
|
50
|
-
caps = svc.get(provider, raw) || null;
|
|
51
|
-
// 降级匹配:mslxdff 自建目录的 -free/-search-free/-expert-free 后缀在 models.dev 无后缀
|
|
52
|
-
if (!caps && /-free$/.test(raw)) caps = svc.get(provider, raw.replace(/-free$/, "")) || null;
|
|
53
|
-
// workbuddy 不在 models.dev 目录 → 上游原生字段兜底(maxInputTokens/supportsImages/... first-party 最准)
|
|
54
|
-
if (!caps && provider === "workbuddy") {
|
|
55
|
-
const { workbuddyCapsFromModels, workbuddyAllModels } = await import("./index.js");
|
|
56
|
-
const map = await workbuddyCapsFromModels(wbSource || workbuddyAllModels)();
|
|
57
|
-
caps = map[raw] || null;
|
|
58
|
-
}
|
|
59
|
-
} catch {
|
|
60
|
-
caps = null; // 目录不可用:降级为无能力条目(staleness 兜底在服务内已做)
|
|
61
|
-
}
|
|
62
|
-
const fields = capsToEntryFields(caps);
|
|
63
|
-
if (!fields) return { entry: base, caps: null };
|
|
64
|
-
return { entry: { ...base, ...fields }, caps };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// caps → 一行人话摘要(无有效信息返回 "",调用方按空跳过不噪音)
|
|
68
|
-
export function capsSummary(caps) {
|
|
69
|
-
if (!caps) return "";
|
|
70
|
-
const parts = [];
|
|
71
|
-
if (caps.effortType === "effort" && Array.isArray(caps.effortValues) && caps.effortValues.length) {
|
|
72
|
-
parts.push(`推理档 ${caps.effortValues.join("/")}`);
|
|
73
|
-
} else if (caps.effortType === "toggle") {
|
|
74
|
-
parts.push("推理 开关型");
|
|
75
|
-
} else if (caps.effortType === "budget_tokens") {
|
|
76
|
-
parts.push("推理 budget_tokens");
|
|
77
|
-
} else if (caps.reasoning) {
|
|
78
|
-
parts.push(caps.defaultEffort ? `推理(默认 ${caps.defaultEffort})` : "推理模型");
|
|
79
|
-
}
|
|
80
|
-
if (caps.imageInput) parts.push("📷读图");
|
|
81
|
-
if (caps.context) parts.push(`上下文 ${caps.context >= 1000 ? `${Math.round(caps.context / 1000)}k` : caps.context}`);
|
|
82
|
-
if (caps.costIn != null || caps.costOut != null) {
|
|
83
|
-
parts.push(`$${caps.costIn ?? 0}/${caps.costOut ?? 0} 每M`);
|
|
84
|
-
}
|
|
85
|
-
return parts.join(" · ");
|
|
86
|
-
}
|
|
1
|
+
// -setto opencode 条目能力注入(ADR-0016 联动):把 models.dev 能力写进 opencode.json
|
|
2
|
+
// 的 per-model 条目(opencode Model 形状,实测 debug config 原样保留并生效),
|
|
3
|
+
// 并产出一行人话摘要供 CLI 展示。查不到能力(未收录 provider/模型)时原样返回不硬造。
|
|
4
|
+
import { globalCapabilities } from "./index.js";
|
|
5
|
+
|
|
6
|
+
// "bai/glm-5.3-flash" → { provider: "bai", raw: "glm-5.3-flash" };裸 id 归 opencode
|
|
7
|
+
function splitProvider(modelId) {
|
|
8
|
+
const s = String(modelId || "").trim();
|
|
9
|
+
const i = s.indexOf("/");
|
|
10
|
+
if (i > 0) return { provider: s.slice(0, i).toLowerCase(), raw: s.slice(i + 1) };
|
|
11
|
+
return { provider: "opencode", raw: s };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// caps → opencode Model 形状增量(只含能力字段,name 等原有键不动)
|
|
15
|
+
// variants:config 条目显式档位(provider.ts config 路径 mergeDeep(config.variants) 优先于启发式,
|
|
16
|
+
// 绕过 transform.ts 黑名单——glm/kimi/deepseek-v3/minimax/qwen/big-pickle 启发式恒 return {})。
|
|
17
|
+
// 参数形状 reasoningEffort 对齐 @ai-sdk/openai-compatible(muse-spark 启发式同款)。
|
|
18
|
+
// toggle/budget_tokens 型不注入(OpenAI 兼容协议无标准开关参数,留启发式判断)。
|
|
19
|
+
function capsToEntryFields(caps) {
|
|
20
|
+
if (!caps) return null;
|
|
21
|
+
const fields = {
|
|
22
|
+
reasoning: Boolean(caps.reasoning),
|
|
23
|
+
tool_call: Boolean(caps.toolCall),
|
|
24
|
+
attachment: Boolean(caps.attachment),
|
|
25
|
+
temperature: Boolean(caps.temperature),
|
|
26
|
+
modalities: { input: caps.inputModalities || ["text"], output: caps.outputModalities || ["text"] },
|
|
27
|
+
limit: { context: Number(caps.context) || 0, output: Number(caps.maxOutput) || 0 },
|
|
28
|
+
};
|
|
29
|
+
if (caps.effortType === "effort" && Array.isArray(caps.effortValues) && caps.effortValues.length) {
|
|
30
|
+
fields.variants = Object.fromEntries(caps.effortValues.map((v) => [String(v), { reasoningEffort: String(v) }]));
|
|
31
|
+
}
|
|
32
|
+
if (caps.releaseDate) fields.release_date = caps.releaseDate;
|
|
33
|
+
if (caps.costIn != null || caps.costOut != null) {
|
|
34
|
+
fields.cost = { input: Number(caps.costIn) || 0, output: Number(caps.costOut) || 0 };
|
|
35
|
+
}
|
|
36
|
+
return fields;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// entry: 现有条目(含 name 等);modelId: 内部 canonical id;capsSvc: 可注入(默认全局单例)
|
|
40
|
+
// wbSource: workbuddy 动态源接缝(测试注入;生产 = workbuddyAllModels 上游原生字段)
|
|
41
|
+
// 返回 { entry: 增强后条目, caps: caps|null };服务异常静默降级(同步命令不能因目录拉取失败而挂)
|
|
42
|
+
export async function enrichOpencodeEntry(entry, modelId, capsSvc, wbSource) {
|
|
43
|
+
const base = entry && typeof entry === "object" && !Array.isArray(entry) ? entry : {};
|
|
44
|
+
const svc = capsSvc === undefined ? globalCapabilities() : capsSvc;
|
|
45
|
+
if (!svc) return { entry: base, caps: null };
|
|
46
|
+
const { provider, raw } = splitProvider(modelId);
|
|
47
|
+
let caps = null;
|
|
48
|
+
try {
|
|
49
|
+
await svc.ready();
|
|
50
|
+
caps = svc.get(provider, raw) || null;
|
|
51
|
+
// 降级匹配:mslxdff 自建目录的 -free/-search-free/-expert-free 后缀在 models.dev 无后缀
|
|
52
|
+
if (!caps && /-free$/.test(raw)) caps = svc.get(provider, raw.replace(/-free$/, "")) || null;
|
|
53
|
+
// workbuddy 不在 models.dev 目录 → 上游原生字段兜底(maxInputTokens/supportsImages/... first-party 最准)
|
|
54
|
+
if (!caps && provider === "workbuddy") {
|
|
55
|
+
const { workbuddyCapsFromModels, workbuddyAllModels } = await import("./index.js");
|
|
56
|
+
const map = await workbuddyCapsFromModels(wbSource || workbuddyAllModels)();
|
|
57
|
+
caps = map[raw] || null;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
caps = null; // 目录不可用:降级为无能力条目(staleness 兜底在服务内已做)
|
|
61
|
+
}
|
|
62
|
+
const fields = capsToEntryFields(caps);
|
|
63
|
+
if (!fields) return { entry: base, caps: null };
|
|
64
|
+
return { entry: { ...base, ...fields }, caps };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// caps → 一行人话摘要(无有效信息返回 "",调用方按空跳过不噪音)
|
|
68
|
+
export function capsSummary(caps) {
|
|
69
|
+
if (!caps) return "";
|
|
70
|
+
const parts = [];
|
|
71
|
+
if (caps.effortType === "effort" && Array.isArray(caps.effortValues) && caps.effortValues.length) {
|
|
72
|
+
parts.push(`推理档 ${caps.effortValues.join("/")}`);
|
|
73
|
+
} else if (caps.effortType === "toggle") {
|
|
74
|
+
parts.push("推理 开关型");
|
|
75
|
+
} else if (caps.effortType === "budget_tokens") {
|
|
76
|
+
parts.push("推理 budget_tokens");
|
|
77
|
+
} else if (caps.reasoning) {
|
|
78
|
+
parts.push(caps.defaultEffort ? `推理(默认 ${caps.defaultEffort})` : "推理模型");
|
|
79
|
+
}
|
|
80
|
+
if (caps.imageInput) parts.push("📷读图");
|
|
81
|
+
if (caps.context) parts.push(`上下文 ${caps.context >= 1000 ? `${Math.round(caps.context / 1000)}k` : caps.context}`);
|
|
82
|
+
if (caps.costIn != null || caps.costOut != null) {
|
|
83
|
+
parts.push(`$${caps.costIn ?? 0}/${caps.costOut ?? 0} 每M`);
|
|
84
|
+
}
|
|
85
|
+
return parts.join(" · ");
|
|
86
|
+
}
|