mslxdff 0.1.231 → 0.1.232
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/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 +145 -145
- package/src/chat-pipeline/policy.js +84 -84
- package/src/cli/commands/group.js +266 -266
- 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 +139 -139
- package/src/cli/commands/provider/models.js +149 -149
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/provider/raccoon-quota.js +156 -156
- package/src/cli/commands/sync.js +310 -310
- package/src/cli/status.js +279 -279
- package/src/daemon.js +246 -246
- 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/peers.js +345 -345
- package/src/providers/agentrouter.js +238 -238
- package/src/providers/base.js +164 -164
- 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/chat.js +207 -207
- package/src/providers/dispatcher.js +147 -147
- 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/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 -203
- 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 +337 -337
- package/src/providers/qwenwork/payload.js +144 -144
- 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/const.js +202 -202
- package/src/providers/raccoon/credits.js +285 -285
- package/src/providers/registry.js +89 -89
- package/src/providers/workbuddy/auth.js +16 -0
- package/src/providers/workbuddy/chat.js +298 -264
- package/src/providers/workbuddy/client-headers.js +148 -0
- package/src/providers/workbuddy/desktop-info.js +17 -1
- package/src/providers/workbuddy/models.js +8 -20
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/reasoning.js +32 -32
- package/src/routes/chat/broadband-handler.js +80 -80
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +282 -282
- package/src/routes/chat/via-route-handler.js +156 -156
- package/src/routes/hedge.js +260 -260
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +373 -373
- package/src/routes/stream.js +347 -347
- package/src/runtime/bootstrap.js +75 -75
- package/src/runtime/keep-warm.js +135 -135
- package/src/runtime/provider-gate.js +75 -75
- package/src/runtime/providers-setup.js +187 -187
- package/src/runtime/raccoon-checkin.js +175 -175
- package/src/server.js +85 -85
- 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 +355 -355
- package/docs/cli_help_mini.md +0 -148
- package/src/providers/AGENTS.md +0 -49
- package/src/routes/AGENTS.md +0 -37
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { defaultStateFile } from "../../../state.js";
|
|
3
|
-
import { logDir } from "../../../logs.js";
|
|
4
|
-
import { normalizeProviderId } from "../../../providers/model-id.js";
|
|
5
|
-
|
|
6
|
-
export async function handleProviderModels(id, sub, args, rest) {
|
|
7
|
-
if (!(sub === "models" || sub === "show-models" || sub === "list-models" || sub === "ls")) return false;
|
|
8
|
-
// 供应商 id 归一(clinebot/cline-bot → cline):老脚本 `-provider clinebot models` 仍走 cline 直查
|
|
9
|
-
id = normalizeProviderId(id);
|
|
10
|
-
const { loadProviderConfig, loadProviderKeys, isModelAllowed } = await import("../../../state.js");
|
|
11
|
-
const wantsJson = args.includes("--json") || args.includes("-json");
|
|
12
|
-
const cfg = loadProviderConfig(id);
|
|
13
|
-
if (id === "opencode" || id === "oc") {
|
|
14
|
-
try {
|
|
15
|
-
const cacheFile = join(logDir(), "models.json");
|
|
16
|
-
const { readFileSync } = await import("node:fs");
|
|
17
|
-
const raw = JSON.parse(readFileSync(cacheFile, "utf8"));
|
|
18
|
-
const ids = (raw.data || []).map((m) => m.id).filter((x) => !String(x).includes("/"));
|
|
19
|
-
if (wantsJson) {
|
|
20
|
-
console.log(JSON.stringify({ object: "list", data: ids.map((id) => ({ id, object: "model" })) }, null, 2));
|
|
21
|
-
} else {
|
|
22
|
-
console.log(`opencode models (${ids.length}):`);
|
|
23
|
-
for (const mid of ids) console.log(` ${mid}`);
|
|
24
|
-
}
|
|
25
|
-
} catch (e) {
|
|
26
|
-
console.error(`could not read models cache: ${String(e?.message || e)}`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
process.exit(0);
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const { createGenericProvider } = await import("../../../providers/generic.js");
|
|
33
|
-
const { createWorkbuddyProvider } = await import("../../../providers/workbuddy.js");
|
|
34
|
-
const baseUrl = cfg?.baseUrl || (id === "workbuddy" ? "https://copilot.tencent.com" : "");
|
|
35
|
-
const keys = loadProviderKeys(id);
|
|
36
|
-
const auths = cfg?.auths || [];
|
|
37
|
-
let provider;
|
|
38
|
-
if (id === "workbuddy") {
|
|
39
|
-
provider = createWorkbuddyProvider({ baseUrl, apiKeys: keys, auths, file: defaultStateFile() });
|
|
40
|
-
} else if (id === "cline") {
|
|
41
|
-
// 与聚合目录同源:recommended-models 的 free(generic 的 /api/v1/models 是全量目录,含大量不可用条目)
|
|
42
|
-
const { createClineProvider } = await import("../../../providers/cline.js");
|
|
43
|
-
provider = createClineProvider({ id, baseUrl: baseUrl || undefined, apiKeys: keys, file: defaultStateFile() });
|
|
44
|
-
} else if (id === "codearts") {
|
|
45
|
-
const { createCodeartsProvider } = await import("../../../providers/codearts.js");
|
|
46
|
-
provider = createCodeartsProvider({ baseUrl: baseUrl || undefined, apiKeys: keys, file: defaultStateFile() });
|
|
47
|
-
} else if (id === "traework") {
|
|
48
|
-
const { createTraeworkProvider } = await import("../../../providers/traework.js");
|
|
49
|
-
provider = createTraeworkProvider({ baseUrl: baseUrl || undefined, apiKeys: keys, auths, file: defaultStateFile() });
|
|
50
|
-
} else if (id === "qoder") {
|
|
51
|
-
const { createQoderProvider } = await import("../../../providers/qoder/index.js");
|
|
52
|
-
provider = createQoderProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
53
|
-
} else if (id === "qwenwork") {
|
|
54
|
-
const { createQwenworkProvider } = await import("../../../providers/qwenwork/index.js");
|
|
55
|
-
provider = createQwenworkProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
56
|
-
} else if (id === "globalqwenwork") {
|
|
57
|
-
const { createGlobalQwenworkProvider } = await import("../../../providers/globalqwenwork/index.js");
|
|
58
|
-
provider = createGlobalQwenworkProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
59
|
-
} else if (id === "zcode") {
|
|
60
|
-
const { createZcodeProvider } = await import("../../../providers/zcode/index.js");
|
|
61
|
-
provider = createZcodeProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
62
|
-
} else if (id === "raccoon") {
|
|
63
|
-
const { createRaccoonProvider } = await import("../../../providers/raccoon/index.js");
|
|
64
|
-
provider = createRaccoonProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
65
|
-
} else if (id === "railway") {
|
|
66
|
-
// 免凭证型:无可执行端点差异,但必须用定制工厂(generic 会把付费模型一起列出来)
|
|
67
|
-
const { createRailwayProvider } = await import("../../../providers/railway.js");
|
|
68
|
-
provider = createRailwayProvider({ baseUrl: baseUrl || undefined, file: defaultStateFile() });
|
|
69
|
-
} else {
|
|
70
|
-
if (!baseUrl) {
|
|
71
|
-
console.error(`provider ${id}: missing baseUrl — set via: mslxdff -provider ${id} set-url <baseUrl>`);
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
provider = createGenericProvider({ id, baseUrl, apiKeys: keys, file: defaultStateFile() });
|
|
75
|
-
}
|
|
76
|
-
const all = await provider.listModels();
|
|
77
|
-
const markAllowed = (mid) => {
|
|
78
|
-
const raw = String(mid || "").includes("/") ? String(mid).split("/").slice(1).join("/") : String(mid);
|
|
79
|
-
const checkRaw = mid.startsWith(`${id}/`) ? mid.slice(id.length + 1) : raw;
|
|
80
|
-
return isModelAllowed(id, checkRaw);
|
|
81
|
-
};
|
|
82
|
-
if (wantsJson) {
|
|
83
|
-
const filtered = all.filter((m) => markAllowed(m.id));
|
|
84
|
-
console.log(JSON.stringify({ object: "list", data: filtered }, null, 2));
|
|
85
|
-
} else {
|
|
86
|
-
const allowedCount = all.filter((m) => markAllowed(m.id)).length;
|
|
87
|
-
console.log(`${id} models (${all.length} total, ${allowedCount} ✓ allowed${allowedCount !== all.length ? `, ${all.length - allowedCount} x blocked by allowlist` : ""}):`);
|
|
88
|
-
const fmtPrice = (m) => {
|
|
89
|
-
const c = String(m.credits || "").trim();
|
|
90
|
-
if (c) {
|
|
91
|
-
const m0 = c.match(/x\s*([\d.]+)/i);
|
|
92
|
-
if (m0) return `x${m0[1]}`;
|
|
93
|
-
return c.replace(/\s*credits\s*/gi, "").trim().replace(/\s+/g, " ");
|
|
94
|
-
}
|
|
95
|
-
if (m.pricing && typeof m.pricing === "object") {
|
|
96
|
-
const p = m.pricing.prompt ?? m.pricing.input ?? m.pricing.completion ?? "";
|
|
97
|
-
if (p) return String(p);
|
|
98
|
-
}
|
|
99
|
-
if (m.price_factor != null && String(m.price_factor).trim() !== "") return `x${m.price_factor}`;
|
|
100
|
-
if (m.price != null && String(m.price).trim()) return String(m.price).trim();
|
|
101
|
-
if (String(m.id).endsWith("/auto")) return "浮动";
|
|
102
|
-
return "—";
|
|
103
|
-
};
|
|
104
|
-
const fmtBadge = (m) => {
|
|
105
|
-
const tags = Array.isArray(m.tags) ? m.tags : [];
|
|
106
|
-
const b = tags.find((t) => String(t).includes("限时免费") || String(t).toLowerCase().includes("free"));
|
|
107
|
-
if (!b) return "";
|
|
108
|
-
const part = String(b).split(":")[1];
|
|
109
|
-
return part ? ` [${part}]` : ` [${b}]`;
|
|
110
|
-
};
|
|
111
|
-
// 能力列:上下文 k + 📷识图 🧠推理 🔧工具调用(workbuddy 原生字段;其他供应商无这些字段则显示 —)
|
|
112
|
-
const fmtCaps = (m) => {
|
|
113
|
-
const ctx = Number(m.maxInputTokens ?? m.context_length) || null;
|
|
114
|
-
const reasoning = m.supportsReasoning ?? m.is_reasoning;
|
|
115
|
-
const hasAny = ctx || m.supportsImages != null || reasoning != null || m.supportsToolCall != null;
|
|
116
|
-
if (!hasAny) return "—";
|
|
117
|
-
const parts = [];
|
|
118
|
-
if (ctx) parts.push(ctx >= 1_000_000 ? `${Math.round(ctx / 100000) / 10}M` : `${Math.round(ctx / 1000)}k`);
|
|
119
|
-
if (m.supportsImages && !m.disabledMultimodal) parts.push("📷");
|
|
120
|
-
if (reasoning) parts.push("🧠");
|
|
121
|
-
if (m.supportsToolCall) parts.push("🔧");
|
|
122
|
-
return parts.join(" ");
|
|
123
|
-
};
|
|
124
|
-
const idW = Math.max(22, ...all.map((m) => String(m.id).length)) + 2;
|
|
125
|
-
const priceW = Math.max(6, ...all.map((m) => fmtPrice(m).length)) + 2;
|
|
126
|
-
const capsW = Math.max(4, ...all.map((m) => fmtCaps(m).length)) + 2;
|
|
127
|
-
for (const m of all) {
|
|
128
|
-
const ok = markAllowed(m.id);
|
|
129
|
-
const price = fmtPrice(m);
|
|
130
|
-
const badge = fmtBadge(m);
|
|
131
|
-
const name = m.name ? ` ${m.name}` : "";
|
|
132
|
-
const blocked = ok ? "" : " [blocked — allowlist]";
|
|
133
|
-
const line = ` ${ok ? "✓" : "x"} ${String(m.id).padEnd(idW)}${String(price).padEnd(priceW)}${fmtCaps(m).padEnd(capsW)}${name}${badge}${blocked}`;
|
|
134
|
-
console.log(line);
|
|
135
|
-
}
|
|
136
|
-
if (!all.length) console.log(` (no models — check baseUrl/keys or try: curl ${baseUrl}/models)`);
|
|
137
|
-
else if (allowedCount === 0) console.log(` tip: all blocked — mslxdff -provider ${id} allowAny on 或 allowlist set <model...>`);
|
|
138
|
-
else if (allowedCount !== all.length) console.log(` tip: blocked 仅影响 /v1/chat 调用,展示已全量列出`);
|
|
139
|
-
if (id === "zcode") {
|
|
140
|
-
console.log(` tip: 目录/额度/模型调用全通(上游 v3.14.4 起模型请求免验证码,docs/adr/0038);额度耗尽返回 429 quota_exhausted,按日窗口重置`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
try { await provider.close?.(); } catch {}
|
|
144
|
-
} catch (e) {
|
|
145
|
-
console.error(`could not list ${id} models: ${String(e?.message || e)}`);
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
process.exit(0);
|
|
149
|
-
}
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { defaultStateFile } from "../../../state.js";
|
|
3
|
+
import { logDir } from "../../../logs.js";
|
|
4
|
+
import { normalizeProviderId } from "../../../providers/model-id.js";
|
|
5
|
+
|
|
6
|
+
export async function handleProviderModels(id, sub, args, rest) {
|
|
7
|
+
if (!(sub === "models" || sub === "show-models" || sub === "list-models" || sub === "ls")) return false;
|
|
8
|
+
// 供应商 id 归一(clinebot/cline-bot → cline):老脚本 `-provider clinebot models` 仍走 cline 直查
|
|
9
|
+
id = normalizeProviderId(id);
|
|
10
|
+
const { loadProviderConfig, loadProviderKeys, isModelAllowed } = await import("../../../state.js");
|
|
11
|
+
const wantsJson = args.includes("--json") || args.includes("-json");
|
|
12
|
+
const cfg = loadProviderConfig(id);
|
|
13
|
+
if (id === "opencode" || id === "oc") {
|
|
14
|
+
try {
|
|
15
|
+
const cacheFile = join(logDir(), "models.json");
|
|
16
|
+
const { readFileSync } = await import("node:fs");
|
|
17
|
+
const raw = JSON.parse(readFileSync(cacheFile, "utf8"));
|
|
18
|
+
const ids = (raw.data || []).map((m) => m.id).filter((x) => !String(x).includes("/"));
|
|
19
|
+
if (wantsJson) {
|
|
20
|
+
console.log(JSON.stringify({ object: "list", data: ids.map((id) => ({ id, object: "model" })) }, null, 2));
|
|
21
|
+
} else {
|
|
22
|
+
console.log(`opencode models (${ids.length}):`);
|
|
23
|
+
for (const mid of ids) console.log(` ${mid}`);
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(`could not read models cache: ${String(e?.message || e)}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const { createGenericProvider } = await import("../../../providers/generic.js");
|
|
33
|
+
const { createWorkbuddyProvider } = await import("../../../providers/workbuddy.js");
|
|
34
|
+
const baseUrl = cfg?.baseUrl || (id === "workbuddy" ? "https://copilot.tencent.com" : "");
|
|
35
|
+
const keys = loadProviderKeys(id);
|
|
36
|
+
const auths = cfg?.auths || [];
|
|
37
|
+
let provider;
|
|
38
|
+
if (id === "workbuddy") {
|
|
39
|
+
provider = createWorkbuddyProvider({ baseUrl, apiKeys: keys, auths, file: defaultStateFile() });
|
|
40
|
+
} else if (id === "cline") {
|
|
41
|
+
// 与聚合目录同源:recommended-models 的 free(generic 的 /api/v1/models 是全量目录,含大量不可用条目)
|
|
42
|
+
const { createClineProvider } = await import("../../../providers/cline.js");
|
|
43
|
+
provider = createClineProvider({ id, baseUrl: baseUrl || undefined, apiKeys: keys, file: defaultStateFile() });
|
|
44
|
+
} else if (id === "codearts") {
|
|
45
|
+
const { createCodeartsProvider } = await import("../../../providers/codearts.js");
|
|
46
|
+
provider = createCodeartsProvider({ baseUrl: baseUrl || undefined, apiKeys: keys, file: defaultStateFile() });
|
|
47
|
+
} else if (id === "traework") {
|
|
48
|
+
const { createTraeworkProvider } = await import("../../../providers/traework.js");
|
|
49
|
+
provider = createTraeworkProvider({ baseUrl: baseUrl || undefined, apiKeys: keys, auths, file: defaultStateFile() });
|
|
50
|
+
} else if (id === "qoder") {
|
|
51
|
+
const { createQoderProvider } = await import("../../../providers/qoder/index.js");
|
|
52
|
+
provider = createQoderProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
53
|
+
} else if (id === "qwenwork") {
|
|
54
|
+
const { createQwenworkProvider } = await import("../../../providers/qwenwork/index.js");
|
|
55
|
+
provider = createQwenworkProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
56
|
+
} else if (id === "globalqwenwork") {
|
|
57
|
+
const { createGlobalQwenworkProvider } = await import("../../../providers/globalqwenwork/index.js");
|
|
58
|
+
provider = createGlobalQwenworkProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
59
|
+
} else if (id === "zcode") {
|
|
60
|
+
const { createZcodeProvider } = await import("../../../providers/zcode/index.js");
|
|
61
|
+
provider = createZcodeProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
62
|
+
} else if (id === "raccoon") {
|
|
63
|
+
const { createRaccoonProvider } = await import("../../../providers/raccoon/index.js");
|
|
64
|
+
provider = createRaccoonProvider({ id, apiKeys: keys, file: defaultStateFile() });
|
|
65
|
+
} else if (id === "railway") {
|
|
66
|
+
// 免凭证型:无可执行端点差异,但必须用定制工厂(generic 会把付费模型一起列出来)
|
|
67
|
+
const { createRailwayProvider } = await import("../../../providers/railway.js");
|
|
68
|
+
provider = createRailwayProvider({ baseUrl: baseUrl || undefined, file: defaultStateFile() });
|
|
69
|
+
} else {
|
|
70
|
+
if (!baseUrl) {
|
|
71
|
+
console.error(`provider ${id}: missing baseUrl — set via: mslxdff -provider ${id} set-url <baseUrl>`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
provider = createGenericProvider({ id, baseUrl, apiKeys: keys, file: defaultStateFile() });
|
|
75
|
+
}
|
|
76
|
+
const all = await provider.listModels();
|
|
77
|
+
const markAllowed = (mid) => {
|
|
78
|
+
const raw = String(mid || "").includes("/") ? String(mid).split("/").slice(1).join("/") : String(mid);
|
|
79
|
+
const checkRaw = mid.startsWith(`${id}/`) ? mid.slice(id.length + 1) : raw;
|
|
80
|
+
return isModelAllowed(id, checkRaw);
|
|
81
|
+
};
|
|
82
|
+
if (wantsJson) {
|
|
83
|
+
const filtered = all.filter((m) => markAllowed(m.id));
|
|
84
|
+
console.log(JSON.stringify({ object: "list", data: filtered }, null, 2));
|
|
85
|
+
} else {
|
|
86
|
+
const allowedCount = all.filter((m) => markAllowed(m.id)).length;
|
|
87
|
+
console.log(`${id} models (${all.length} total, ${allowedCount} ✓ allowed${allowedCount !== all.length ? `, ${all.length - allowedCount} x blocked by allowlist` : ""}):`);
|
|
88
|
+
const fmtPrice = (m) => {
|
|
89
|
+
const c = String(m.credits || "").trim();
|
|
90
|
+
if (c) {
|
|
91
|
+
const m0 = c.match(/x\s*([\d.]+)/i);
|
|
92
|
+
if (m0) return `x${m0[1]}`;
|
|
93
|
+
return c.replace(/\s*credits\s*/gi, "").trim().replace(/\s+/g, " ");
|
|
94
|
+
}
|
|
95
|
+
if (m.pricing && typeof m.pricing === "object") {
|
|
96
|
+
const p = m.pricing.prompt ?? m.pricing.input ?? m.pricing.completion ?? "";
|
|
97
|
+
if (p) return String(p);
|
|
98
|
+
}
|
|
99
|
+
if (m.price_factor != null && String(m.price_factor).trim() !== "") return `x${m.price_factor}`;
|
|
100
|
+
if (m.price != null && String(m.price).trim()) return String(m.price).trim();
|
|
101
|
+
if (String(m.id).endsWith("/auto")) return "浮动";
|
|
102
|
+
return "—";
|
|
103
|
+
};
|
|
104
|
+
const fmtBadge = (m) => {
|
|
105
|
+
const tags = Array.isArray(m.tags) ? m.tags : [];
|
|
106
|
+
const b = tags.find((t) => String(t).includes("限时免费") || String(t).toLowerCase().includes("free"));
|
|
107
|
+
if (!b) return "";
|
|
108
|
+
const part = String(b).split(":")[1];
|
|
109
|
+
return part ? ` [${part}]` : ` [${b}]`;
|
|
110
|
+
};
|
|
111
|
+
// 能力列:上下文 k + 📷识图 🧠推理 🔧工具调用(workbuddy 原生字段;其他供应商无这些字段则显示 —)
|
|
112
|
+
const fmtCaps = (m) => {
|
|
113
|
+
const ctx = Number(m.maxInputTokens ?? m.context_length) || null;
|
|
114
|
+
const reasoning = m.supportsReasoning ?? m.is_reasoning;
|
|
115
|
+
const hasAny = ctx || m.supportsImages != null || reasoning != null || m.supportsToolCall != null;
|
|
116
|
+
if (!hasAny) return "—";
|
|
117
|
+
const parts = [];
|
|
118
|
+
if (ctx) parts.push(ctx >= 1_000_000 ? `${Math.round(ctx / 100000) / 10}M` : `${Math.round(ctx / 1000)}k`);
|
|
119
|
+
if (m.supportsImages && !m.disabledMultimodal) parts.push("📷");
|
|
120
|
+
if (reasoning) parts.push("🧠");
|
|
121
|
+
if (m.supportsToolCall) parts.push("🔧");
|
|
122
|
+
return parts.join(" ");
|
|
123
|
+
};
|
|
124
|
+
const idW = Math.max(22, ...all.map((m) => String(m.id).length)) + 2;
|
|
125
|
+
const priceW = Math.max(6, ...all.map((m) => fmtPrice(m).length)) + 2;
|
|
126
|
+
const capsW = Math.max(4, ...all.map((m) => fmtCaps(m).length)) + 2;
|
|
127
|
+
for (const m of all) {
|
|
128
|
+
const ok = markAllowed(m.id);
|
|
129
|
+
const price = fmtPrice(m);
|
|
130
|
+
const badge = fmtBadge(m);
|
|
131
|
+
const name = m.name ? ` ${m.name}` : "";
|
|
132
|
+
const blocked = ok ? "" : " [blocked — allowlist]";
|
|
133
|
+
const line = ` ${ok ? "✓" : "x"} ${String(m.id).padEnd(idW)}${String(price).padEnd(priceW)}${fmtCaps(m).padEnd(capsW)}${name}${badge}${blocked}`;
|
|
134
|
+
console.log(line);
|
|
135
|
+
}
|
|
136
|
+
if (!all.length) console.log(` (no models — check baseUrl/keys or try: curl ${baseUrl}/models)`);
|
|
137
|
+
else if (allowedCount === 0) console.log(` tip: all blocked — mslxdff -provider ${id} allowAny on 或 allowlist set <model...>`);
|
|
138
|
+
else if (allowedCount !== all.length) console.log(` tip: blocked 仅影响 /v1/chat 调用,展示已全量列出`);
|
|
139
|
+
if (id === "zcode") {
|
|
140
|
+
console.log(` tip: 目录/额度/模型调用全通(上游 v3.14.4 起模型请求免验证码,docs/adr/0038);额度耗尽返回 429 quota_exhausted,按日窗口重置`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
try { await provider.close?.(); } catch {}
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.error(`could not list ${id} models: ${String(e?.message || e)}`);
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
process.exit(0);
|
|
149
|
+
}
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
// mslxdff -provider qwenwork login — 千问办公设备授权(PKCE + poll),对齐 qoder-login。
|
|
2
|
-
// 授权后落盘 auths/qwenwork-<uid>.json + state 双写,默认 allowAny=false 并种 3 个实测模型(ADR-0037)。
|
|
3
|
-
import { compatFetch } from "../../../compat.js";
|
|
4
|
-
import { normalizeProviderId } from "../../../providers/model-id.js";
|
|
5
|
-
import { newDeviceFlow, pollGrant, userInfo, accountContext, expiryUnix } from "../../../providers/qwenwork/upstream.js";
|
|
6
|
-
|
|
7
|
-
const POLL_MS = 3000;
|
|
8
|
-
const POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
9
|
-
|
|
10
|
-
export async function handleQwenworkLogin(id, sub, rest = [], deps = {}) {
|
|
11
|
-
if (normalizeProviderId(id) !== "qwenwork") return false;
|
|
12
|
-
if (sub !== "login" && sub !== "auth" && sub !== "oauth") return false;
|
|
13
|
-
const fetchImpl = deps.fetchImpl || compatFetch;
|
|
14
|
-
const log = deps.log || ((m) => console.log(m));
|
|
15
|
-
|
|
16
|
-
const flow = await newDeviceFlow();
|
|
17
|
-
log("=".repeat(60));
|
|
18
|
-
log(" 千问办公(QwenWork)登录");
|
|
19
|
-
log("=".repeat(60));
|
|
20
|
-
log("");
|
|
21
|
-
log(" 1. 在浏览器打开下面链接,用已登录千问办公的账号确认授权");
|
|
22
|
-
log(" 2. 授权成功后会自动完成,不要关闭本终端");
|
|
23
|
-
log("");
|
|
24
|
-
log(` ${flow.url}`);
|
|
25
|
-
log("");
|
|
26
|
-
log("🔄 等待你授权(自动轮询,每 3 秒,最多 10 分钟)...");
|
|
27
|
-
|
|
28
|
-
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
29
|
-
let grant = null;
|
|
30
|
-
for (;;) {
|
|
31
|
-
if (Date.now() > deadline) {
|
|
32
|
-
console.error("\n❌ 授权超时(10 分钟),请重新运行 mslxdff -provider qwenwork login");
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
let outcome;
|
|
36
|
-
try {
|
|
37
|
-
outcome = await pollGrant(flow.nonce, flow.verifier, fetchImpl);
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.error(`\n❌ 轮询失败: ${e.message}`);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
if (!outcome.pending) { grant = outcome.grant; break; }
|
|
43
|
-
try { process.stdout.write("."); } catch {}
|
|
44
|
-
await new Promise((r) => setTimeout(r, POLL_MS));
|
|
45
|
-
}
|
|
46
|
-
const accessToken = grant.token || grant.device_token;
|
|
47
|
-
const refreshToken = grant.refresh_token || "";
|
|
48
|
-
if (!accessToken) {
|
|
49
|
-
console.error("\n❌ 未获取到 token");
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
log(`\n✅ 授权成功!token=${String(accessToken).slice(0, 12)}...`);
|
|
53
|
-
if (refreshToken) log(` refreshToken=${String(refreshToken).slice(0, 12)}...`);
|
|
54
|
-
|
|
55
|
-
let uid = String(grant.user_id || "");
|
|
56
|
-
let name = String(grant.user_name || "");
|
|
57
|
-
let email = "";
|
|
58
|
-
try {
|
|
59
|
-
const info = await userInfo(accessToken, fetchImpl);
|
|
60
|
-
if (info?.id) uid = String(info.id);
|
|
61
|
-
if (info?.name) name = String(info.name);
|
|
62
|
-
if (info?.email) email = String(info.email);
|
|
63
|
-
log(` UID: ${uid} 昵称: ${name || "(空)"} 邮箱: ${email || "(空)"}`);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
log(` ⚠️ userinfo 失败: ${e.message}(用 grant 兜底)`);
|
|
66
|
-
if (!uid) uid = String(accessToken).slice(0, 8);
|
|
67
|
-
}
|
|
68
|
-
if (!uid) {
|
|
69
|
-
console.error("❌ 无法获取用户标识");
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const { saveQwenworkAccount } = await import("../../../providers/qwenwork/account-store.js");
|
|
74
|
-
const save = deps.saveAccount || saveQwenworkAccount;
|
|
75
|
-
const saved = await save({
|
|
76
|
-
uid,
|
|
77
|
-
accessToken,
|
|
78
|
-
refreshToken,
|
|
79
|
-
expiresAt: expiryUnix(grant),
|
|
80
|
-
name,
|
|
81
|
-
email,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
log("");
|
|
85
|
-
log("=".repeat(60));
|
|
86
|
-
log("✅ 登录完成!");
|
|
87
|
-
log(` UID: ${uid}`);
|
|
88
|
-
log(` 账号数: ${saved.accounts}${saved.updated ? "(旧号凭证已更新)" : ""}`);
|
|
89
|
-
log(` 数据文件: ${saved.file}`);
|
|
90
|
-
log("=".repeat(60));
|
|
91
|
-
// 安全默认:allowAny 关 + 只放 3 个实测模型(与 qoder 惯例故意不同,见 ADR-0037)
|
|
92
|
-
try {
|
|
93
|
-
const { saveProviderAllowAnyModels, saveProviderAllowedModels } = await import("../../../state.js");
|
|
94
|
-
saveProviderAllowAnyModels("qwenwork", false);
|
|
95
|
-
saveProviderAllowedModels("qwenwork", ["flash", "pro", "qwen3.8-max-preview"]);
|
|
96
|
-
log(" allowAnyModels=off + allowlist 已种 flash/pro/qwen3.8-max-preview(额度池供应商,防 auto 烧分)");
|
|
97
|
-
} catch {}
|
|
98
|
-
// 额度展示
|
|
99
|
-
try {
|
|
100
|
-
const ctx = await accountContext(accessToken, fetchImpl);
|
|
101
|
-
const plan = ctx?.plan || {};
|
|
102
|
-
const quota = ctx?.quota || {};
|
|
103
|
-
if (plan?.name || quota?.remaining !== undefined) {
|
|
104
|
-
log(` 套餐: ${plan?.name || "-"} 积分剩余: ${quota?.remaining ?? "-"}`);
|
|
105
|
-
}
|
|
106
|
-
} catch {
|
|
107
|
-
log(" 额度查询失败,不影响使用");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
log("下一步:");
|
|
111
|
-
log(" mslxdff -provider qwenwork models 列模型列表");
|
|
112
|
-
log(" mslxdff -restart(用户终端跑) 重启网关使新账号生效");
|
|
113
|
-
log(" 然后 curl http://localhost:8989/v1/chat/completions -d '{\"model\":\"qwenwork/flash\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}]}'");
|
|
114
|
-
log("");
|
|
115
|
-
log("多账号:重复 `mslxdff -provider qwenwork login` 追加,每号独立 uid,对话自动轮换");
|
|
116
|
-
|
|
117
|
-
if (!deps.noExit) process.exit(0);
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
1
|
+
// mslxdff -provider qwenwork login — 千问办公设备授权(PKCE + poll),对齐 qoder-login。
|
|
2
|
+
// 授权后落盘 auths/qwenwork-<uid>.json + state 双写,默认 allowAny=false 并种 3 个实测模型(ADR-0037)。
|
|
3
|
+
import { compatFetch } from "../../../compat.js";
|
|
4
|
+
import { normalizeProviderId } from "../../../providers/model-id.js";
|
|
5
|
+
import { newDeviceFlow, pollGrant, userInfo, accountContext, expiryUnix } from "../../../providers/qwenwork/upstream.js";
|
|
6
|
+
|
|
7
|
+
const POLL_MS = 3000;
|
|
8
|
+
const POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
export async function handleQwenworkLogin(id, sub, rest = [], deps = {}) {
|
|
11
|
+
if (normalizeProviderId(id) !== "qwenwork") return false;
|
|
12
|
+
if (sub !== "login" && sub !== "auth" && sub !== "oauth") return false;
|
|
13
|
+
const fetchImpl = deps.fetchImpl || compatFetch;
|
|
14
|
+
const log = deps.log || ((m) => console.log(m));
|
|
15
|
+
|
|
16
|
+
const flow = await newDeviceFlow();
|
|
17
|
+
log("=".repeat(60));
|
|
18
|
+
log(" 千问办公(QwenWork)登录");
|
|
19
|
+
log("=".repeat(60));
|
|
20
|
+
log("");
|
|
21
|
+
log(" 1. 在浏览器打开下面链接,用已登录千问办公的账号确认授权");
|
|
22
|
+
log(" 2. 授权成功后会自动完成,不要关闭本终端");
|
|
23
|
+
log("");
|
|
24
|
+
log(` ${flow.url}`);
|
|
25
|
+
log("");
|
|
26
|
+
log("🔄 等待你授权(自动轮询,每 3 秒,最多 10 分钟)...");
|
|
27
|
+
|
|
28
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
29
|
+
let grant = null;
|
|
30
|
+
for (;;) {
|
|
31
|
+
if (Date.now() > deadline) {
|
|
32
|
+
console.error("\n❌ 授权超时(10 分钟),请重新运行 mslxdff -provider qwenwork login");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
let outcome;
|
|
36
|
+
try {
|
|
37
|
+
outcome = await pollGrant(flow.nonce, flow.verifier, fetchImpl);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(`\n❌ 轮询失败: ${e.message}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
if (!outcome.pending) { grant = outcome.grant; break; }
|
|
43
|
+
try { process.stdout.write("."); } catch {}
|
|
44
|
+
await new Promise((r) => setTimeout(r, POLL_MS));
|
|
45
|
+
}
|
|
46
|
+
const accessToken = grant.token || grant.device_token;
|
|
47
|
+
const refreshToken = grant.refresh_token || "";
|
|
48
|
+
if (!accessToken) {
|
|
49
|
+
console.error("\n❌ 未获取到 token");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
log(`\n✅ 授权成功!token=${String(accessToken).slice(0, 12)}...`);
|
|
53
|
+
if (refreshToken) log(` refreshToken=${String(refreshToken).slice(0, 12)}...`);
|
|
54
|
+
|
|
55
|
+
let uid = String(grant.user_id || "");
|
|
56
|
+
let name = String(grant.user_name || "");
|
|
57
|
+
let email = "";
|
|
58
|
+
try {
|
|
59
|
+
const info = await userInfo(accessToken, fetchImpl);
|
|
60
|
+
if (info?.id) uid = String(info.id);
|
|
61
|
+
if (info?.name) name = String(info.name);
|
|
62
|
+
if (info?.email) email = String(info.email);
|
|
63
|
+
log(` UID: ${uid} 昵称: ${name || "(空)"} 邮箱: ${email || "(空)"}`);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
log(` ⚠️ userinfo 失败: ${e.message}(用 grant 兜底)`);
|
|
66
|
+
if (!uid) uid = String(accessToken).slice(0, 8);
|
|
67
|
+
}
|
|
68
|
+
if (!uid) {
|
|
69
|
+
console.error("❌ 无法获取用户标识");
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { saveQwenworkAccount } = await import("../../../providers/qwenwork/account-store.js");
|
|
74
|
+
const save = deps.saveAccount || saveQwenworkAccount;
|
|
75
|
+
const saved = await save({
|
|
76
|
+
uid,
|
|
77
|
+
accessToken,
|
|
78
|
+
refreshToken,
|
|
79
|
+
expiresAt: expiryUnix(grant),
|
|
80
|
+
name,
|
|
81
|
+
email,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
log("");
|
|
85
|
+
log("=".repeat(60));
|
|
86
|
+
log("✅ 登录完成!");
|
|
87
|
+
log(` UID: ${uid}`);
|
|
88
|
+
log(` 账号数: ${saved.accounts}${saved.updated ? "(旧号凭证已更新)" : ""}`);
|
|
89
|
+
log(` 数据文件: ${saved.file}`);
|
|
90
|
+
log("=".repeat(60));
|
|
91
|
+
// 安全默认:allowAny 关 + 只放 3 个实测模型(与 qoder 惯例故意不同,见 ADR-0037)
|
|
92
|
+
try {
|
|
93
|
+
const { saveProviderAllowAnyModels, saveProviderAllowedModels } = await import("../../../state.js");
|
|
94
|
+
saveProviderAllowAnyModels("qwenwork", false);
|
|
95
|
+
saveProviderAllowedModels("qwenwork", ["flash", "pro", "qwen3.8-max-preview"]);
|
|
96
|
+
log(" allowAnyModels=off + allowlist 已种 flash/pro/qwen3.8-max-preview(额度池供应商,防 auto 烧分)");
|
|
97
|
+
} catch {}
|
|
98
|
+
// 额度展示
|
|
99
|
+
try {
|
|
100
|
+
const ctx = await accountContext(accessToken, fetchImpl);
|
|
101
|
+
const plan = ctx?.plan || {};
|
|
102
|
+
const quota = ctx?.quota || {};
|
|
103
|
+
if (plan?.name || quota?.remaining !== undefined) {
|
|
104
|
+
log(` 套餐: ${plan?.name || "-"} 积分剩余: ${quota?.remaining ?? "-"}`);
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
log(" 额度查询失败,不影响使用");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
log("下一步:");
|
|
111
|
+
log(" mslxdff -provider qwenwork models 列模型列表");
|
|
112
|
+
log(" mslxdff -restart(用户终端跑) 重启网关使新账号生效");
|
|
113
|
+
log(" 然后 curl http://localhost:8989/v1/chat/completions -d '{\"model\":\"qwenwork/flash\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}]}'");
|
|
114
|
+
log("");
|
|
115
|
+
log("多账号:重复 `mslxdff -provider qwenwork login` 追加,每号独立 uid,对话自动轮换");
|
|
116
|
+
|
|
117
|
+
if (!deps.noExit) process.exit(0);
|
|
118
|
+
return true;
|
|
119
|
+
}
|