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
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import { probeModels } from "../../../bench/probe.js";
|
|
2
|
-
import { runOne } from "../../../bench/runner.js";
|
|
3
|
-
import { formatReport } from "../../../bench/report.js";
|
|
4
|
-
import { defaultModelsPath, defaultChatPath } from "../../../state/provider-config.js";
|
|
5
|
-
import { isRefreshToken } from "../../../providers/cline/headers.js";
|
|
6
|
-
import { refreshTokenForBase } from "../../../providers/cline/auth.js";
|
|
7
|
-
import { clineBenchOne } from "../../../bench/cline-bench.js";
|
|
8
|
-
import { workbuddyBenchOne } from "../../../bench/workbuddy-bench.js";
|
|
9
|
-
import { buildHeadersForProvider, filterBenchModels, handleVia } from "./bench-via.js";
|
|
10
|
-
import { compatFetch } from "../../../compat.js";
|
|
11
|
-
|
|
12
|
-
function parseBenchArgs(rest) {
|
|
13
|
-
const opts = { json: false, prompt: "hi", maxTokens: 32, timeoutMs: 30000, via: false, includeOpencode: false, samples: 1, apply: false };
|
|
14
|
-
for (let i = 0; i < rest.length; i++) {
|
|
15
|
-
const a = rest[i];
|
|
16
|
-
if (a === "--json" || a === "-json") opts.json = true;
|
|
17
|
-
else if (a === "--via" || a === "--bench-via") opts.via = true;
|
|
18
|
-
else if (a === "--apply" || a === "--write" || a === "--save") opts.apply = true;
|
|
19
|
-
else if (a === "--include-opencode") opts.includeOpencode = true;
|
|
20
|
-
else if (a === "--samples" && rest[i + 1]) opts.samples = Number(rest[++i]) || 1;
|
|
21
|
-
else if (a.startsWith("--samples=")) opts.samples = Number(a.split("=")[1]) || 1;
|
|
22
|
-
else if (a === "--prompt" && rest[i + 1]) opts.prompt = rest[++i];
|
|
23
|
-
else if (a.startsWith("--prompt=")) opts.prompt = a.slice(9);
|
|
24
|
-
else if (a === "--max-tokens" && rest[i + 1]) opts.maxTokens = Number(rest[++i]) || 32;
|
|
25
|
-
else if (a.startsWith("--max-tokens=")) opts.maxTokens = Number(a.split("=")[1]) || 32;
|
|
26
|
-
else if (a === "--timeout" && rest[i + 1]) opts.timeoutMs = Number(rest[++i]) || 30000;
|
|
27
|
-
else if (a.startsWith("--timeout=")) opts.timeoutMs = Number(a.split("=")[1]) || 30000;
|
|
28
|
-
}
|
|
29
|
-
return opts;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function handleProviderBench(id, sub, rest, args, deps = {}) {
|
|
33
|
-
const _restArr = rest || [];
|
|
34
|
-
const _hasVia = _restArr.includes("--via") || _restArr.includes("--bench-via");
|
|
35
|
-
const _isBenchViaAll = (String(id) === "bench" || String(id) === "all") && _hasVia;
|
|
36
|
-
const isBench = sub === "bench" || sub === "benchmark" || sub === "eval" || sub === "test" || _isBenchViaAll;
|
|
37
|
-
if (!isBench) return false;
|
|
38
|
-
const opts = parseBenchArgs(_restArr);
|
|
39
|
-
if (opts.via) {
|
|
40
|
-
const stateMod = await import("../../../state.js");
|
|
41
|
-
const loadConfigs = deps.loadProviderConfigs || stateMod.loadProviderConfigs;
|
|
42
|
-
const loadKeys = deps.loadProviderKeys || stateMod.loadProviderKeys;
|
|
43
|
-
const loadAllowed = deps.loadProviderAllowedModels || stateMod.loadProviderAllowedModels;
|
|
44
|
-
const loadBaseUrl = deps.loadProviderBaseUrl || stateMod.loadProviderBaseUrl;
|
|
45
|
-
const viaPid = _isBenchViaAll ? "bench" : String(id || "").trim();
|
|
46
|
-
if (!viaPid) { console.error("usage: mslxdff -provider <id> bench --via [--json] [--include-opencode]"); process.exit(1); }
|
|
47
|
-
await handleVia({ providerId: viaPid, opts, fetchImpl: deps.fetchImpl || compatFetch, loadConfigs, loadKeys, loadAllowed, loadBaseUrl, loadAllowAny: deps.loadProviderAllowAnyModels || stateMod.loadProviderAllowAnyModels, loadModelPicks: deps.loadModelPicks, getOnlinePeersFn: deps.getOnlinePeers });
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
const fetchImpl = deps.fetchImpl || compatFetch;
|
|
51
|
-
const loadConfigs = deps.loadProviderConfigs || (await import("../../../state.js")).loadProviderConfigs;
|
|
52
|
-
const loadKeys = deps.loadProviderKeys || (await import("../../../state.js")).loadProviderKeys;
|
|
53
|
-
const loadAllowed = deps.loadProviderAllowedModels || (await import("../../../state.js")).loadProviderAllowedModels;
|
|
54
|
-
const loadAllowAny = deps.loadProviderAllowAnyModels || (await import("../../../state.js")).loadProviderAllowAnyModels;
|
|
55
|
-
const loadBaseUrl = deps.loadProviderBaseUrl || (await import("../../../state.js")).loadProviderBaseUrl;
|
|
56
|
-
const providerId = String(id || "").trim();
|
|
57
|
-
if (!providerId) { console.error("usage: mslxdff -provider <id> bench [--json] [--prompt hi] [--max-tokens 32]"); process.exit(1); }
|
|
58
|
-
const configs = loadConfigs();
|
|
59
|
-
const cfg = configs[providerId] || {};
|
|
60
|
-
const keys = loadKeys(providerId) || [];
|
|
61
|
-
const allowed = loadAllowed(providerId) || [];
|
|
62
|
-
const allowAny = loadAllowAny(providerId);
|
|
63
|
-
let picks = [];
|
|
64
|
-
try {
|
|
65
|
-
const m = await import("../../../state.js");
|
|
66
|
-
picks = typeof deps.loadModelPicks === "function" ? (deps.loadModelPicks() || []) : (typeof m.loadModelPicks === "function" ? m.loadModelPicks() || [] : []);
|
|
67
|
-
} catch { picks = []; }
|
|
68
|
-
const picked = filterBenchModels({ providerId, allowed, picks, allowAny });
|
|
69
|
-
const baseUrl = (loadBaseUrl(providerId) || cfg.baseUrl || "").trim();
|
|
70
|
-
let auths = [];
|
|
71
|
-
try { const m = await import("../../../state.js"); auths = m.loadProviderAuths ? m.loadProviderAuths(providerId) : []; } catch {}
|
|
72
|
-
if (!baseUrl) { console.error(`provider ${providerId}: missing baseUrl — 先设置: mslxdff -provider ${providerId} set-url https://api.example.com/v1`); process.exit(1); }
|
|
73
|
-
if (!keys.length) { console.error(`provider ${providerId}: 未配置 Key — 先设置: mslxdff -provider ${providerId} <key>`); process.exit(1); }
|
|
74
|
-
if (!allowed.length) {
|
|
75
|
-
const modelsPath = cfg.modelsPath || defaultModelsPath(providerId);
|
|
76
|
-
console.log(`provider ${providerId}: 未设置 allowlist(allowAny=${allowAny ? "ON" : "OFF"}),不发起测速,仅探活模型列表...`);
|
|
77
|
-
console.log(`尝试:GET ${baseUrl}${modelsPath} → GET ${baseUrl}/v1/models → GET ${baseUrl}/models`);
|
|
78
|
-
const headers = buildHeadersForProvider(providerId, keys[0], auths[0]);
|
|
79
|
-
const probed = await probeModels({ baseUrl, modelsPath, headers, fetchImpl, timeoutMs: 8000 });
|
|
80
|
-
if (!probed.ok) { console.error(`探活失败:${probed.error}`); console.error(`已尝试:${probed.tried.join(", ")}`); console.error(`请手动设置 allowlist:mslxdff -provider ${providerId} allowlist set <model>`); if (opts.json) console.log(JSON.stringify({ ok: false, error: probed.error, tried: probed.tried }, null, 2)); process.exit(1); }
|
|
81
|
-
const list = probed.data || [];
|
|
82
|
-
if (!list.length) { console.log("探活成功但返回空列表,请确认上游是否暴露 /v1/models"); if (opts.json) console.log(JSON.stringify({ ok: true, data: [] }, null, 2)); process.exit(0); }
|
|
83
|
-
console.log(`\n发现 ${list.length} 个模型:`);
|
|
84
|
-
for (const m of list.slice(0, 30)) console.log(` - ${m.id || m.model || m.name || JSON.stringify(m).slice(0, 80)}`);
|
|
85
|
-
if (list.length > 30) console.log(` ... 还有 ${list.length - 30} 个未展示`);
|
|
86
|
-
console.log(`\n下一步:勾选后再测(只测勾选,避免扣费)`);
|
|
87
|
-
console.log(` mslxdff -provider ${providerId} allowlist set ${list.slice(0, 2).map((m) => m.id).join(" ")}`);
|
|
88
|
-
console.log(` mslxdff -provider ${providerId} bench${opts.json ? " --json" : ""}`);
|
|
89
|
-
if (opts.json) console.log(JSON.stringify({ ok: true, data: list, hint: `pick then bench` }, null, 2));
|
|
90
|
-
process.exit(0);
|
|
91
|
-
}
|
|
92
|
-
if (picks.length && !picked.models.length) {
|
|
93
|
-
console.log(`provider ${providerId}: allowlist ${allowed.length} 个模型都不在全局 picks 中,不测速(只测勾选)。`);
|
|
94
|
-
if (picked.pickedBlocked.length) console.log(`已勾选但未进 allowlist:${picked.pickedBlocked.join(" ")} → mslxdff -provider ${providerId} allowlist set <model>`);
|
|
95
|
-
else console.log(`先勾选:mslxdff -model pick ${providerId}/<model>`);
|
|
96
|
-
process.exit(0);
|
|
97
|
-
}
|
|
98
|
-
const log = (s) => (opts.json ? console.error(s) : console.log(s));
|
|
99
|
-
log(`bench ${providerId}: 共 ${picked.models.length} 个已勾选模型,逐个测速(串行,${opts.timeoutMs}ms 超时)...`);
|
|
100
|
-
if (picked.skippedUnpicked) log(`跳过 ${picked.skippedUnpicked} 个未勾选模型`);
|
|
101
|
-
if (!opts.json) console.log(`prompt="${opts.prompt}" maxTokens=${opts.maxTokens}\n`);
|
|
102
|
-
const chatPath = cfg.chatPath || defaultChatPath(providerId);
|
|
103
|
-
const rtKeys = keys.filter((k) => isRefreshToken(k, providerId));
|
|
104
|
-
const normBase = String(baseUrl).replace(/\/+$/, "");
|
|
105
|
-
const clineChatBase = normBase.endsWith("/api/v1") ? normBase.slice(0, -7) : normBase;
|
|
106
|
-
const results = [];
|
|
107
|
-
const benchModels = picked.models;
|
|
108
|
-
for (let i = 0; i < benchModels.length; i++) {
|
|
109
|
-
const raw = benchModels[i];
|
|
110
|
-
const model = String(raw || "").trim();
|
|
111
|
-
if (!opts.json) process.stdout.write(` [${i + 1}/${benchModels.length}] ${model} ... `);
|
|
112
|
-
const kIdx = i % (keys.length || 1);
|
|
113
|
-
const aIdx = Math.min(kIdx, Math.max(auths.length - 1, 0));
|
|
114
|
-
const key = keys[kIdx];
|
|
115
|
-
const auth = auths[aIdx] || auths[0] || null;
|
|
116
|
-
if (String(providerId).toLowerCase() === "workbuddy") {
|
|
117
|
-
const r = await workbuddyBenchOne({ baseUrl, chatPath, model, apiKey: key, auth, prompt: opts.prompt, maxTokens: opts.maxTokens, timeoutMs: opts.timeoutMs, fetchImpl });
|
|
118
|
-
results.push(r);
|
|
119
|
-
if (!opts.json) { if (r.ok) console.log(`OK TTFB ${r.ttfbMs}ms 总 ${r.totalMs}ms ${r.tps != null ? `${r.tps} t/s` : r.charsPerSec != null ? `${r.charsPerSec} 字/秒` : "—"}`); else console.log(`FAIL ${r.label} ${r.error ? `(${r.error.slice(0, 60)})` : ""}`); }
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (rtKeys.length) {
|
|
123
|
-
const rt = rtKeys[kIdx % rtKeys.length];
|
|
124
|
-
const at = await refreshTokenForBase({ refreshToken: rt, baseUrl: normBase, fetchImpl });
|
|
125
|
-
if (!at) { const r = { id: model, ok: false, error: "refreshToken 换 accessToken 失败", label: "鉴权失败", ttfbMs: null, totalMs: 0, tps: null, charsPerSec: null, tokens: null }; results.push(r); if (!opts.json) console.log(`FAIL ${r.label} (${r.error})`); continue; }
|
|
126
|
-
const r = await clineBenchOne({ baseUrl: clineChatBase, model, accessToken: at, prompt: opts.prompt, maxTokens: opts.maxTokens, timeoutMs: opts.timeoutMs, fetchImpl });
|
|
127
|
-
results.push(r);
|
|
128
|
-
if (!opts.json) { if (r.ok) console.log(`OK TTFB ${r.ttfbMs}ms 总 ${r.totalMs}ms ${r.tps != null ? `${r.tps} t/s` : r.charsPerSec != null ? `${r.charsPerSec} 字/秒` : "—"}`); else console.log(`FAIL ${r.label} ${r.error ? `(${r.error.slice(0, 60)})` : ""}`); }
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const headers = buildHeadersForProvider(providerId, key, auth);
|
|
132
|
-
const r = await runOne({ baseUrl, chatPath, model, providerId, apiKey: key, headers, prompt: opts.prompt, maxTokens: opts.maxTokens, timeoutMs: opts.timeoutMs, fetchImpl });
|
|
133
|
-
results.push(r);
|
|
134
|
-
if (!opts.json) { if (r.ok) console.log(`OK TTFB ${r.ttfbMs}ms 总 ${r.totalMs}ms ${r.tps != null ? `${r.tps} t/s` : r.charsPerSec != null ? `${r.charsPerSec} 字/秒` : "—"}`); else console.log(`FAIL ${r.label} ${r.error ? `(${r.error.slice(0, 60)})` : ""}`); }
|
|
135
|
-
}
|
|
136
|
-
const report = formatReport(results, { json: opts.json });
|
|
137
|
-
console.log("\n" + report.text);
|
|
138
|
-
const failed = results.filter((r) => !r.ok).length;
|
|
139
|
-
if (failed && !opts.json) console.log(`\n提示:失败 ${failed} 个多为 402余额不足/429限流/超时,可清冷却或换 Key 后重试`);
|
|
140
|
-
process.exit(failed ? 2 : 0);
|
|
141
|
-
}
|
|
1
|
+
import { probeModels } from "../../../bench/probe.js";
|
|
2
|
+
import { runOne } from "../../../bench/runner.js";
|
|
3
|
+
import { formatReport } from "../../../bench/report.js";
|
|
4
|
+
import { defaultModelsPath, defaultChatPath } from "../../../state/provider-config.js";
|
|
5
|
+
import { isRefreshToken } from "../../../providers/cline/headers.js";
|
|
6
|
+
import { refreshTokenForBase } from "../../../providers/cline/auth.js";
|
|
7
|
+
import { clineBenchOne } from "../../../bench/cline-bench.js";
|
|
8
|
+
import { workbuddyBenchOne } from "../../../bench/workbuddy-bench.js";
|
|
9
|
+
import { buildHeadersForProvider, filterBenchModels, handleVia } from "./bench-via.js";
|
|
10
|
+
import { compatFetch } from "../../../compat.js";
|
|
11
|
+
|
|
12
|
+
function parseBenchArgs(rest) {
|
|
13
|
+
const opts = { json: false, prompt: "hi", maxTokens: 32, timeoutMs: 30000, via: false, includeOpencode: false, samples: 1, apply: false };
|
|
14
|
+
for (let i = 0; i < rest.length; i++) {
|
|
15
|
+
const a = rest[i];
|
|
16
|
+
if (a === "--json" || a === "-json") opts.json = true;
|
|
17
|
+
else if (a === "--via" || a === "--bench-via") opts.via = true;
|
|
18
|
+
else if (a === "--apply" || a === "--write" || a === "--save") opts.apply = true;
|
|
19
|
+
else if (a === "--include-opencode") opts.includeOpencode = true;
|
|
20
|
+
else if (a === "--samples" && rest[i + 1]) opts.samples = Number(rest[++i]) || 1;
|
|
21
|
+
else if (a.startsWith("--samples=")) opts.samples = Number(a.split("=")[1]) || 1;
|
|
22
|
+
else if (a === "--prompt" && rest[i + 1]) opts.prompt = rest[++i];
|
|
23
|
+
else if (a.startsWith("--prompt=")) opts.prompt = a.slice(9);
|
|
24
|
+
else if (a === "--max-tokens" && rest[i + 1]) opts.maxTokens = Number(rest[++i]) || 32;
|
|
25
|
+
else if (a.startsWith("--max-tokens=")) opts.maxTokens = Number(a.split("=")[1]) || 32;
|
|
26
|
+
else if (a === "--timeout" && rest[i + 1]) opts.timeoutMs = Number(rest[++i]) || 30000;
|
|
27
|
+
else if (a.startsWith("--timeout=")) opts.timeoutMs = Number(a.split("=")[1]) || 30000;
|
|
28
|
+
}
|
|
29
|
+
return opts;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function handleProviderBench(id, sub, rest, args, deps = {}) {
|
|
33
|
+
const _restArr = rest || [];
|
|
34
|
+
const _hasVia = _restArr.includes("--via") || _restArr.includes("--bench-via");
|
|
35
|
+
const _isBenchViaAll = (String(id) === "bench" || String(id) === "all") && _hasVia;
|
|
36
|
+
const isBench = sub === "bench" || sub === "benchmark" || sub === "eval" || sub === "test" || _isBenchViaAll;
|
|
37
|
+
if (!isBench) return false;
|
|
38
|
+
const opts = parseBenchArgs(_restArr);
|
|
39
|
+
if (opts.via) {
|
|
40
|
+
const stateMod = await import("../../../state.js");
|
|
41
|
+
const loadConfigs = deps.loadProviderConfigs || stateMod.loadProviderConfigs;
|
|
42
|
+
const loadKeys = deps.loadProviderKeys || stateMod.loadProviderKeys;
|
|
43
|
+
const loadAllowed = deps.loadProviderAllowedModels || stateMod.loadProviderAllowedModels;
|
|
44
|
+
const loadBaseUrl = deps.loadProviderBaseUrl || stateMod.loadProviderBaseUrl;
|
|
45
|
+
const viaPid = _isBenchViaAll ? "bench" : String(id || "").trim();
|
|
46
|
+
if (!viaPid) { console.error("usage: mslxdff -provider <id> bench --via [--json] [--include-opencode]"); process.exit(1); }
|
|
47
|
+
await handleVia({ providerId: viaPid, opts, fetchImpl: deps.fetchImpl || compatFetch, loadConfigs, loadKeys, loadAllowed, loadBaseUrl, loadAllowAny: deps.loadProviderAllowAnyModels || stateMod.loadProviderAllowAnyModels, loadModelPicks: deps.loadModelPicks, getOnlinePeersFn: deps.getOnlinePeers });
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const fetchImpl = deps.fetchImpl || compatFetch;
|
|
51
|
+
const loadConfigs = deps.loadProviderConfigs || (await import("../../../state.js")).loadProviderConfigs;
|
|
52
|
+
const loadKeys = deps.loadProviderKeys || (await import("../../../state.js")).loadProviderKeys;
|
|
53
|
+
const loadAllowed = deps.loadProviderAllowedModels || (await import("../../../state.js")).loadProviderAllowedModels;
|
|
54
|
+
const loadAllowAny = deps.loadProviderAllowAnyModels || (await import("../../../state.js")).loadProviderAllowAnyModels;
|
|
55
|
+
const loadBaseUrl = deps.loadProviderBaseUrl || (await import("../../../state.js")).loadProviderBaseUrl;
|
|
56
|
+
const providerId = String(id || "").trim();
|
|
57
|
+
if (!providerId) { console.error("usage: mslxdff -provider <id> bench [--json] [--prompt hi] [--max-tokens 32]"); process.exit(1); }
|
|
58
|
+
const configs = loadConfigs();
|
|
59
|
+
const cfg = configs[providerId] || {};
|
|
60
|
+
const keys = loadKeys(providerId) || [];
|
|
61
|
+
const allowed = loadAllowed(providerId) || [];
|
|
62
|
+
const allowAny = loadAllowAny(providerId);
|
|
63
|
+
let picks = [];
|
|
64
|
+
try {
|
|
65
|
+
const m = await import("../../../state.js");
|
|
66
|
+
picks = typeof deps.loadModelPicks === "function" ? (deps.loadModelPicks() || []) : (typeof m.loadModelPicks === "function" ? m.loadModelPicks() || [] : []);
|
|
67
|
+
} catch { picks = []; }
|
|
68
|
+
const picked = filterBenchModels({ providerId, allowed, picks, allowAny });
|
|
69
|
+
const baseUrl = (loadBaseUrl(providerId) || cfg.baseUrl || "").trim();
|
|
70
|
+
let auths = [];
|
|
71
|
+
try { const m = await import("../../../state.js"); auths = m.loadProviderAuths ? m.loadProviderAuths(providerId) : []; } catch {}
|
|
72
|
+
if (!baseUrl) { console.error(`provider ${providerId}: missing baseUrl — 先设置: mslxdff -provider ${providerId} set-url https://api.example.com/v1`); process.exit(1); }
|
|
73
|
+
if (!keys.length) { console.error(`provider ${providerId}: 未配置 Key — 先设置: mslxdff -provider ${providerId} <key>`); process.exit(1); }
|
|
74
|
+
if (!allowed.length) {
|
|
75
|
+
const modelsPath = cfg.modelsPath || defaultModelsPath(providerId);
|
|
76
|
+
console.log(`provider ${providerId}: 未设置 allowlist(allowAny=${allowAny ? "ON" : "OFF"}),不发起测速,仅探活模型列表...`);
|
|
77
|
+
console.log(`尝试:GET ${baseUrl}${modelsPath} → GET ${baseUrl}/v1/models → GET ${baseUrl}/models`);
|
|
78
|
+
const headers = buildHeadersForProvider(providerId, keys[0], auths[0]);
|
|
79
|
+
const probed = await probeModels({ baseUrl, modelsPath, headers, fetchImpl, timeoutMs: 8000 });
|
|
80
|
+
if (!probed.ok) { console.error(`探活失败:${probed.error}`); console.error(`已尝试:${probed.tried.join(", ")}`); console.error(`请手动设置 allowlist:mslxdff -provider ${providerId} allowlist set <model>`); if (opts.json) console.log(JSON.stringify({ ok: false, error: probed.error, tried: probed.tried }, null, 2)); process.exit(1); }
|
|
81
|
+
const list = probed.data || [];
|
|
82
|
+
if (!list.length) { console.log("探活成功但返回空列表,请确认上游是否暴露 /v1/models"); if (opts.json) console.log(JSON.stringify({ ok: true, data: [] }, null, 2)); process.exit(0); }
|
|
83
|
+
console.log(`\n发现 ${list.length} 个模型:`);
|
|
84
|
+
for (const m of list.slice(0, 30)) console.log(` - ${m.id || m.model || m.name || JSON.stringify(m).slice(0, 80)}`);
|
|
85
|
+
if (list.length > 30) console.log(` ... 还有 ${list.length - 30} 个未展示`);
|
|
86
|
+
console.log(`\n下一步:勾选后再测(只测勾选,避免扣费)`);
|
|
87
|
+
console.log(` mslxdff -provider ${providerId} allowlist set ${list.slice(0, 2).map((m) => m.id).join(" ")}`);
|
|
88
|
+
console.log(` mslxdff -provider ${providerId} bench${opts.json ? " --json" : ""}`);
|
|
89
|
+
if (opts.json) console.log(JSON.stringify({ ok: true, data: list, hint: `pick then bench` }, null, 2));
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
if (picks.length && !picked.models.length) {
|
|
93
|
+
console.log(`provider ${providerId}: allowlist ${allowed.length} 个模型都不在全局 picks 中,不测速(只测勾选)。`);
|
|
94
|
+
if (picked.pickedBlocked.length) console.log(`已勾选但未进 allowlist:${picked.pickedBlocked.join(" ")} → mslxdff -provider ${providerId} allowlist set <model>`);
|
|
95
|
+
else console.log(`先勾选:mslxdff -model pick ${providerId}/<model>`);
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
const log = (s) => (opts.json ? console.error(s) : console.log(s));
|
|
99
|
+
log(`bench ${providerId}: 共 ${picked.models.length} 个已勾选模型,逐个测速(串行,${opts.timeoutMs}ms 超时)...`);
|
|
100
|
+
if (picked.skippedUnpicked) log(`跳过 ${picked.skippedUnpicked} 个未勾选模型`);
|
|
101
|
+
if (!opts.json) console.log(`prompt="${opts.prompt}" maxTokens=${opts.maxTokens}\n`);
|
|
102
|
+
const chatPath = cfg.chatPath || defaultChatPath(providerId);
|
|
103
|
+
const rtKeys = keys.filter((k) => isRefreshToken(k, providerId));
|
|
104
|
+
const normBase = String(baseUrl).replace(/\/+$/, "");
|
|
105
|
+
const clineChatBase = normBase.endsWith("/api/v1") ? normBase.slice(0, -7) : normBase;
|
|
106
|
+
const results = [];
|
|
107
|
+
const benchModels = picked.models;
|
|
108
|
+
for (let i = 0; i < benchModels.length; i++) {
|
|
109
|
+
const raw = benchModels[i];
|
|
110
|
+
const model = String(raw || "").trim();
|
|
111
|
+
if (!opts.json) process.stdout.write(` [${i + 1}/${benchModels.length}] ${model} ... `);
|
|
112
|
+
const kIdx = i % (keys.length || 1);
|
|
113
|
+
const aIdx = Math.min(kIdx, Math.max(auths.length - 1, 0));
|
|
114
|
+
const key = keys[kIdx];
|
|
115
|
+
const auth = auths[aIdx] || auths[0] || null;
|
|
116
|
+
if (String(providerId).toLowerCase() === "workbuddy") {
|
|
117
|
+
const r = await workbuddyBenchOne({ baseUrl, chatPath, model, apiKey: key, auth, prompt: opts.prompt, maxTokens: opts.maxTokens, timeoutMs: opts.timeoutMs, fetchImpl });
|
|
118
|
+
results.push(r);
|
|
119
|
+
if (!opts.json) { if (r.ok) console.log(`OK TTFB ${r.ttfbMs}ms 总 ${r.totalMs}ms ${r.tps != null ? `${r.tps} t/s` : r.charsPerSec != null ? `${r.charsPerSec} 字/秒` : "—"}`); else console.log(`FAIL ${r.label} ${r.error ? `(${r.error.slice(0, 60)})` : ""}`); }
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (rtKeys.length) {
|
|
123
|
+
const rt = rtKeys[kIdx % rtKeys.length];
|
|
124
|
+
const at = await refreshTokenForBase({ refreshToken: rt, baseUrl: normBase, fetchImpl });
|
|
125
|
+
if (!at) { const r = { id: model, ok: false, error: "refreshToken 换 accessToken 失败", label: "鉴权失败", ttfbMs: null, totalMs: 0, tps: null, charsPerSec: null, tokens: null }; results.push(r); if (!opts.json) console.log(`FAIL ${r.label} (${r.error})`); continue; }
|
|
126
|
+
const r = await clineBenchOne({ baseUrl: clineChatBase, model, accessToken: at, prompt: opts.prompt, maxTokens: opts.maxTokens, timeoutMs: opts.timeoutMs, fetchImpl });
|
|
127
|
+
results.push(r);
|
|
128
|
+
if (!opts.json) { if (r.ok) console.log(`OK TTFB ${r.ttfbMs}ms 总 ${r.totalMs}ms ${r.tps != null ? `${r.tps} t/s` : r.charsPerSec != null ? `${r.charsPerSec} 字/秒` : "—"}`); else console.log(`FAIL ${r.label} ${r.error ? `(${r.error.slice(0, 60)})` : ""}`); }
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const headers = buildHeadersForProvider(providerId, key, auth);
|
|
132
|
+
const r = await runOne({ baseUrl, chatPath, model, providerId, apiKey: key, headers, prompt: opts.prompt, maxTokens: opts.maxTokens, timeoutMs: opts.timeoutMs, fetchImpl });
|
|
133
|
+
results.push(r);
|
|
134
|
+
if (!opts.json) { if (r.ok) console.log(`OK TTFB ${r.ttfbMs}ms 总 ${r.totalMs}ms ${r.tps != null ? `${r.tps} t/s` : r.charsPerSec != null ? `${r.charsPerSec} 字/秒` : "—"}`); else console.log(`FAIL ${r.label} ${r.error ? `(${r.error.slice(0, 60)})` : ""}`); }
|
|
135
|
+
}
|
|
136
|
+
const report = formatReport(results, { json: opts.json });
|
|
137
|
+
console.log("\n" + report.text);
|
|
138
|
+
const failed = results.filter((r) => !r.ok).length;
|
|
139
|
+
if (failed && !opts.json) console.log(`\n提示:失败 ${failed} 个多为 402余额不足/429限流/超时,可清冷却或换 Key 后重试`);
|
|
140
|
+
process.exit(failed ? 2 : 0);
|
|
141
|
+
}
|
|
@@ -1,116 +1,124 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { normalizeProviderId } from "../../../providers/model-id.js";
|
|
3
|
-
import { defaultStateFile } from "../../../state.js";
|
|
4
|
-
|
|
5
|
-
export async function handleProviders(args) {
|
|
6
|
-
if (!(args.includes("-providers") || args.includes("--providers"))) return false;
|
|
7
|
-
const idx = args.findIndex((x) => x === "-providers" || x === "--providers");
|
|
8
|
-
const sub = args[idx + 1];
|
|
9
|
-
if (!sub || sub === "list" || sub === "status") {
|
|
10
|
-
const { buildProviderRows, formatProviderSection } = await import("../../provider-row.js");
|
|
11
|
-
const rows = buildProviderRows({});
|
|
12
|
-
const enabled = rows.filter((r) => r.enabled).length;
|
|
13
|
-
console.log(`providers ${rows.length} 个 · ${enabled} 已启用 — mslxdff -provider <id> list 查看详情`);
|
|
14
|
-
console.log(formatProviderSection(rows));
|
|
15
|
-
console.log(`\n提示: mslxdff -provider <id> list 单看一个 · allowlist set <model...> 限制模型 · allowAny on|off 空名单放行/阻断`);
|
|
16
|
-
process.exit(0);
|
|
17
|
-
}
|
|
18
|
-
console.error("usage: mslxdff -providers list");
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function handleProvider(args) {
|
|
23
|
-
if (!(args.includes("-provider") || args.includes("--provider"))) return false;
|
|
24
|
-
const idx = args.findIndex((x) => x === "-provider" || x === "--provider");
|
|
25
|
-
const id = args[idx + 1];
|
|
26
|
-
const sub = args[idx + 2];
|
|
27
|
-
const rest = args.slice(idx + 2);
|
|
28
|
-
if (!id) {
|
|
29
|
-
console.error("usage: mslxdff -provider <id> [key...|add|remove|list|models|clear|set-url|allowlist|allowAny]");
|
|
30
|
-
console.error(" e.g. mslxdff -provider openrouter sk-1 sk-2 sk-3 set multiple keys (replaces all)");
|
|
31
|
-
console.error(" mslxdff -provider openrouter add sk-4 append one key");
|
|
32
|
-
console.error(" mslxdff -provider openrouter remove sk-1 remove a key by value");
|
|
33
|
-
console.error(" mslxdff -provider openrouter list list all keys (masked)");
|
|
34
|
-
console.error(" mslxdff -provider openrouter models [--json] list provider models (allowlist filtered)");
|
|
35
|
-
console.error(" mslxdff -provider openrouter set-url https://api.example.com/v1");
|
|
36
|
-
console.error(" mslxdff -provider openrouter set-models-path /v1/models");
|
|
37
|
-
console.error(" mslxdff -provider openrouter set-chat-path /v1/chat/completions");
|
|
38
|
-
console.error(" mslxdff -provider openrouter allowlist set gpt-4 gpt-3.5 manage allowed models (empty=block unless allowAny ON)");
|
|
39
|
-
console.error(" mslxdff -provider openrouter allowAny on|off empty allowlist = allow all or block all (default OFF, secure)");
|
|
40
|
-
console.error(" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx add generic OpenAI-compatible provider");
|
|
41
|
-
console.error(" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx gpt-4 add with allowlist");
|
|
42
|
-
console.error(" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx --models-path /v1/models --chat-path /v1/chat/completions");
|
|
43
|
-
console.error(" mslxdff -provider openrouter interactive hidden input (append)");
|
|
44
|
-
console.error(" mslxdff -provider codearts login 华为云 CodeArts PKCE 授权(浏览器登录 → 凭证 blob 落盘,ADR-0027)");
|
|
45
|
-
console.error(" mslxdff -provider qoder login [--region cn|global] Qoder 设备授权(国际站默认,国内站 --region cn)");
|
|
46
|
-
console.error(" mslxdff -provider qoder checkin [--json] [--region cn|global] [--any] [--dry] 每日签到领积分(cn=daily-check-in,global=campaigns)");
|
|
47
|
-
console.error(" mslxdff -provider
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
console.log(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const {
|
|
72
|
-
if (await
|
|
73
|
-
const {
|
|
74
|
-
if (await
|
|
75
|
-
const {
|
|
76
|
-
if (await
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (await
|
|
80
|
-
|
|
81
|
-
if (await
|
|
82
|
-
const {
|
|
83
|
-
if (await
|
|
84
|
-
const {
|
|
85
|
-
if (await
|
|
86
|
-
const {
|
|
87
|
-
if (await
|
|
88
|
-
const {
|
|
89
|
-
if (await
|
|
90
|
-
const {
|
|
91
|
-
if (await
|
|
92
|
-
const {
|
|
93
|
-
if (await
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
console.log(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { normalizeProviderId } from "../../../providers/model-id.js";
|
|
3
|
+
import { defaultStateFile } from "../../../state.js";
|
|
4
|
+
|
|
5
|
+
export async function handleProviders(args) {
|
|
6
|
+
if (!(args.includes("-providers") || args.includes("--providers"))) return false;
|
|
7
|
+
const idx = args.findIndex((x) => x === "-providers" || x === "--providers");
|
|
8
|
+
const sub = args[idx + 1];
|
|
9
|
+
if (!sub || sub === "list" || sub === "status") {
|
|
10
|
+
const { buildProviderRows, formatProviderSection } = await import("../../provider-row.js");
|
|
11
|
+
const rows = buildProviderRows({});
|
|
12
|
+
const enabled = rows.filter((r) => r.enabled).length;
|
|
13
|
+
console.log(`providers ${rows.length} 个 · ${enabled} 已启用 — mslxdff -provider <id> list 查看详情`);
|
|
14
|
+
console.log(formatProviderSection(rows));
|
|
15
|
+
console.log(`\n提示: mslxdff -provider <id> list 单看一个 · allowlist set <model...> 限制模型 · allowAny on|off 空名单放行/阻断`);
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
console.error("usage: mslxdff -providers list");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function handleProvider(args) {
|
|
23
|
+
if (!(args.includes("-provider") || args.includes("--provider"))) return false;
|
|
24
|
+
const idx = args.findIndex((x) => x === "-provider" || x === "--provider");
|
|
25
|
+
const id = args[idx + 1];
|
|
26
|
+
const sub = args[idx + 2];
|
|
27
|
+
const rest = args.slice(idx + 2);
|
|
28
|
+
if (!id) {
|
|
29
|
+
console.error("usage: mslxdff -provider <id> [key...|add|remove|list|models|clear|set-url|allowlist|allowAny]");
|
|
30
|
+
console.error(" e.g. mslxdff -provider openrouter sk-1 sk-2 sk-3 set multiple keys (replaces all)");
|
|
31
|
+
console.error(" mslxdff -provider openrouter add sk-4 append one key");
|
|
32
|
+
console.error(" mslxdff -provider openrouter remove sk-1 remove a key by value");
|
|
33
|
+
console.error(" mslxdff -provider openrouter list list all keys (masked)");
|
|
34
|
+
console.error(" mslxdff -provider openrouter models [--json] list provider models (allowlist filtered)");
|
|
35
|
+
console.error(" mslxdff -provider openrouter set-url https://api.example.com/v1");
|
|
36
|
+
console.error(" mslxdff -provider openrouter set-models-path /v1/models");
|
|
37
|
+
console.error(" mslxdff -provider openrouter set-chat-path /v1/chat/completions");
|
|
38
|
+
console.error(" mslxdff -provider openrouter allowlist set gpt-4 gpt-3.5 manage allowed models (empty=block unless allowAny ON)");
|
|
39
|
+
console.error(" mslxdff -provider openrouter allowAny on|off empty allowlist = allow all or block all (default OFF, secure)");
|
|
40
|
+
console.error(" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx add generic OpenAI-compatible provider");
|
|
41
|
+
console.error(" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx gpt-4 add with allowlist");
|
|
42
|
+
console.error(" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx --models-path /v1/models --chat-path /v1/chat/completions");
|
|
43
|
+
console.error(" mslxdff -provider openrouter interactive hidden input (append)");
|
|
44
|
+
console.error(" mslxdff -provider codearts login 华为云 CodeArts PKCE 授权(浏览器登录 → 凭证 blob 落盘,ADR-0027)");
|
|
45
|
+
console.error(" mslxdff -provider qoder login [--region cn|global] Qoder 设备授权(国际站默认,国内站 --region cn)");
|
|
46
|
+
console.error(" mslxdff -provider qoder checkin [--json] [--region cn|global] [--any] [--dry] 每日签到领积分(cn=daily-check-in,global=campaigns)");
|
|
47
|
+
console.error(" mslxdff -provider zcode login [--bigmodel] ZCode 授权(智谱免费额度,Start/Coding Plan)");
|
|
48
|
+
console.error(" mslxdff -provider zcode quota [--json] 查看套餐/余量(未登录给重登指引)");
|
|
49
|
+
console.error(" mslxdff -provider openrouter clear remove all keys");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
if (id === "list" || id === "status") {
|
|
53
|
+
const { buildProviderRows, formatProviderSection } = await import("../../provider-row.js");
|
|
54
|
+
const rows = buildProviderRows({});
|
|
55
|
+
const enabled = rows.filter((r) => r.enabled).length;
|
|
56
|
+
console.log(`providers ${rows.length} 个 · ${enabled} 已启用 — mslxdff -provider <id> list 单看一个`);
|
|
57
|
+
console.log(formatProviderSection(rows));
|
|
58
|
+
process.exit(0);
|
|
59
|
+
}
|
|
60
|
+
if (id === "add") {
|
|
61
|
+
const { handleProviderAdd } = await import("./add.js");
|
|
62
|
+
await handleProviderAdd(id, sub, rest);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if ((id === "opencode" || id === "oc") && sub !== "allowlist" && sub !== "allow" && sub !== "allowed" && sub !== "whitelist" && sub !== "list" && sub !== "status" && sub !== "allowAny" && sub !== "allow-any" && sub !== "allow_any" && sub !== "allowany") {
|
|
66
|
+
console.log("opencode is the default (bare) provider — it needs no API key and can never be shared with peers");
|
|
67
|
+
console.log("(its IP-based rate limit is spread by peer forwarding itself)");
|
|
68
|
+
console.log(` allowlist: mslxdff -provider opencode allowlist [list|set|add|remove|clear] — restrict models (empty=allow all)`);
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
const { handleClineLogin } = await import("./cline-login.js");
|
|
72
|
+
if (await handleClineLogin(id, sub)) return true;
|
|
73
|
+
const { handleWorkbuddyLogin } = await import("./workbuddy-login.js");
|
|
74
|
+
if (await handleWorkbuddyLogin(id, sub, rest)) return true;
|
|
75
|
+
const { handleCodeartsLogin } = await import("./codearts-login.js");
|
|
76
|
+
if (await handleCodeartsLogin(id, sub, rest)) return true;
|
|
77
|
+
const { handleTraeworkLogin, handleTraeworkCheckin } = await import("./traework-login.js");
|
|
78
|
+
if (await handleTraeworkLogin(id, sub, rest)) return true;
|
|
79
|
+
if (await handleTraeworkCheckin(id, sub, rest)) return true;
|
|
80
|
+
const { handleQoderLogin } = await import("./qoder-login.js");
|
|
81
|
+
if (await handleQoderLogin(id, sub, rest)) return true;
|
|
82
|
+
const { handleQoderCheckin } = await import("./qoder-checkin.js");
|
|
83
|
+
if (await handleQoderCheckin(id, sub, rest)) return true;
|
|
84
|
+
const { handleQwenworkLogin } = await import("./qwenwork-login.js");
|
|
85
|
+
if (await handleQwenworkLogin(id, sub, rest)) return true;
|
|
86
|
+
const { handleZcodeLogin } = await import("./zcode-login.js");
|
|
87
|
+
if (await handleZcodeLogin(id, sub, rest)) return true;
|
|
88
|
+
const { handleZcodeQuota } = await import("./zcode-quota.js");
|
|
89
|
+
if (await handleZcodeQuota(id, sub, rest)) return true;
|
|
90
|
+
const { handleProviderConfig } = await import("./config.js");
|
|
91
|
+
if (await handleProviderConfig(id, sub, rest)) return true;
|
|
92
|
+
const { handleProviderAllowlist } = await import("./allowlist.js");
|
|
93
|
+
if (await handleProviderAllowlist(id, sub, rest)) return true;
|
|
94
|
+
const { handleProviderModels } = await import("./models.js");
|
|
95
|
+
if (await handleProviderModels(id, sub, args, rest)) return true;
|
|
96
|
+
const { handleProviderBench } = await import("./bench.js");
|
|
97
|
+
if (await handleProviderBench(id, sub, rest, args)) return true;
|
|
98
|
+
const { handleClineFree } = await import("./cline-free.js");
|
|
99
|
+
if (await handleClineFree(id, sub, rest, args)) return true;
|
|
100
|
+
const { handleClineQuota } = await import("./cline-quota.js");
|
|
101
|
+
if (await handleClineQuota(id, sub, rest, args)) return true;
|
|
102
|
+
if (normalizeProviderId(id) === "cline" && sub === "migrate") {
|
|
103
|
+
const { runStateMigrations } = await import("../../../state/migrations.js");
|
|
104
|
+
const dryRun = args.includes("--dry-run") || args.includes("--dryrun");
|
|
105
|
+
const r = await runStateMigrations({ dryRun });
|
|
106
|
+
const d = r.details["cline-unify"] || {};
|
|
107
|
+
if (r.errors.length) console.error(`❌ 迁移失败: ${r.errors.map((e) => `${e.id}: ${e.error}`).join("; ")}`);
|
|
108
|
+
if (dryRun) {
|
|
109
|
+
console.log(d.changed
|
|
110
|
+
? `cline migrate 干跑:将合并遗留 cline id 配置(keys ${d.before.keys} → ${d.after.keys} / allowlist ${d.before.allowedModels} → ${d.after.allowedModels}),未写入`
|
|
111
|
+
: "cline migrate 干跑:无需迁移(未发现 providerConfigs.clinebot / cline-bot)");
|
|
112
|
+
} else if (d.applied) {
|
|
113
|
+
console.log(`✅ cline migrate 完成:keys ${d.before.keys} → ${d.after.keys} / allowlist ${d.before.allowedModels} → ${d.after.allowedModels}`);
|
|
114
|
+
if (d.backup) console.log(` 备份:${d.backup}`);
|
|
115
|
+
console.log(" 生效:mslxdff -restart");
|
|
116
|
+
} else {
|
|
117
|
+
console.log("cline migrate:无需迁移(未发现 providerConfigs.clinebot / cline-bot)");
|
|
118
|
+
}
|
|
119
|
+
process.exit(r.errors.length ? 1 : 0);
|
|
120
|
+
}
|
|
121
|
+
const { handleProviderKeys } = await import("./keys.js");
|
|
122
|
+
await handleProviderKeys(id, sub, rest, args);
|
|
123
|
+
return true;
|
|
124
|
+
}
|