mslxdff 0.1.161 → 0.1.163
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/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 +127 -126
- package/src/chat-pipeline/policy.js +76 -76
- package/src/cli/commands/group.js +249 -249
- package/src/cli/commands/model/picks.js +50 -50
- package/src/cli/commands/provider/bench-via.js +247 -247
- package/src/cli/commands/provider/bench.js +141 -141
- package/src/cli/commands/provider/index.js +126 -126
- package/src/cli/commands/provider/models.js +142 -142
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/stats.js +21 -9
- package/src/cli/commands/sync.js +232 -232
- package/src/cli/format.js +1 -0
- package/src/cli/help.js +1 -1
- package/src/cli/status.js +279 -279
- package/src/daemon.js +101 -101
- 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 +4 -3
- package/src/models.js +225 -225
- 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/dispatcher.js +26 -14
- 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/globalworkbuddy/account-store.js +198 -0
- package/src/providers/globalworkbuddy/auth.js +97 -0
- package/src/providers/globalworkbuddy/catalog.js +138 -0
- package/src/providers/globalworkbuddy/constants.js +73 -0
- package/src/providers/globalworkbuddy/device-auth.js +120 -0
- package/src/providers/globalworkbuddy/errors.js +98 -0
- package/src/providers/globalworkbuddy/headers.js +89 -0
- package/src/providers/globalworkbuddy/models.js +96 -0
- package/src/providers/globalworkbuddy/payload.js +80 -0
- package/src/providers/keyring.js +60 -60
- package/src/providers/qoder/aggregate.js +12 -3
- package/src/providers/qoder/chat.js +200 -183
- package/src/providers/qoder/index.js +249 -230
- package/src/providers/qoder/models.js +7 -3
- package/src/providers/qoder/payload.js +7 -1
- package/src/providers/qoder/request.js +2 -1
- package/src/providers/qoder/sse.js +145 -103
- package/src/providers/qoder/stream.js +16 -4
- package/src/providers/qwenwork/account-store.js +133 -133
- package/src/providers/qwenwork/constants.js +67 -67
- package/src/providers/qwenwork/cosy.js +120 -120
- package/src/providers/qwenwork/crypto.js +218 -218
- package/src/providers/qwenwork/http.js +20 -20
- package/src/providers/qwenwork/index.js +327 -327
- package/src/providers/qwenwork/payload.js +142 -142
- package/src/providers/qwenwork/rsa.js +54 -54
- package/src/providers/qwenwork/sse.js +268 -268
- package/src/providers/qwenwork/stream.js +130 -130
- package/src/providers/qwenwork/upstream.js +120 -120
- package/src/providers/qwenwork.js +1 -1
- package/src/providers/registry.js +74 -74
- 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/reasoning.js +32 -32
- package/src/routes/chat/exhausted-handler.js +13 -2
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +292 -276
- package/src/routes/chat/via-route-handler.js +146 -146
- 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-scan.js +22 -5
- package/src/routes/stream.js +385 -386
- package/src/runtime/bootstrap.js +45 -45
- package/src/runtime/provider-gate.js +34 -34
- package/src/runtime/providers-setup.js +165 -165
- package/src/runtime/server-lifecycle.js +5 -6
- package/src/server.js +69 -64
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- package/src/talk-full-redact.js +129 -0
- package/src/talk-full.js +130 -0
- package/src/talk-log.js +42 -15
- package/src/transport/index.js +244 -244
- package/src/transport/pool.js +56 -56
- package/src/transport/retry.js +24 -24
- package/src/transport/sse.js +93 -93
- package/src/upstream-engine/sdk/responses.js +5 -0
- package/src/upstream-probe/display.js +52 -52
- package/src/upstream-probe/probe.js +49 -49
- package/src/upstream-probe/rotate.js +110 -110
- package/src/upstream-probe/start.js +45 -45
- package/src/upstream.js +289 -289
- package/src/usage/report.js +14 -8
- package/docs/cli_help_mini.md +0 -135
- package/src/providers/AGENTS.md +0 -46
- package/src/routes/AGENTS.md +0 -37
|
@@ -1,142 +1,142 @@
|
|
|
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 {
|
|
63
|
-
if (!baseUrl) {
|
|
64
|
-
console.error(`provider ${id}: missing baseUrl — set via: mslxdff -provider ${id} set-url <baseUrl>`);
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
provider = createGenericProvider({ id, baseUrl, apiKeys: keys, file: defaultStateFile() });
|
|
68
|
-
}
|
|
69
|
-
const all = await provider.listModels();
|
|
70
|
-
const markAllowed = (mid) => {
|
|
71
|
-
const raw = String(mid || "").includes("/") ? String(mid).split("/").slice(1).join("/") : String(mid);
|
|
72
|
-
const checkRaw = mid.startsWith(`${id}/`) ? mid.slice(id.length + 1) : raw;
|
|
73
|
-
return isModelAllowed(id, checkRaw);
|
|
74
|
-
};
|
|
75
|
-
if (wantsJson) {
|
|
76
|
-
const filtered = all.filter((m) => markAllowed(m.id));
|
|
77
|
-
console.log(JSON.stringify({ object: "list", data: filtered }, null, 2));
|
|
78
|
-
} else {
|
|
79
|
-
const allowedCount = all.filter((m) => markAllowed(m.id)).length;
|
|
80
|
-
console.log(`${id} models (${all.length} total, ${allowedCount} ✓ allowed${allowedCount !== all.length ? `, ${all.length - allowedCount} x blocked by allowlist` : ""}):`);
|
|
81
|
-
const fmtPrice = (m) => {
|
|
82
|
-
const c = String(m.credits || "").trim();
|
|
83
|
-
if (c) {
|
|
84
|
-
const m0 = c.match(/x\s*([\d.]+)/i);
|
|
85
|
-
if (m0) return `x${m0[1]}`;
|
|
86
|
-
return c.replace(/\s*credits\s*/gi, "").trim().replace(/\s+/g, " ");
|
|
87
|
-
}
|
|
88
|
-
if (m.pricing && typeof m.pricing === "object") {
|
|
89
|
-
const p = m.pricing.prompt ?? m.pricing.input ?? m.pricing.completion ?? "";
|
|
90
|
-
if (p) return String(p);
|
|
91
|
-
}
|
|
92
|
-
if (m.price_factor != null && String(m.price_factor).trim() !== "") return `x${m.price_factor}`;
|
|
93
|
-
if (m.price != null && String(m.price).trim()) return String(m.price).trim();
|
|
94
|
-
if (String(m.id).endsWith("/auto")) return "浮动";
|
|
95
|
-
return "—";
|
|
96
|
-
};
|
|
97
|
-
const fmtBadge = (m) => {
|
|
98
|
-
const tags = Array.isArray(m.tags) ? m.tags : [];
|
|
99
|
-
const b = tags.find((t) => String(t).includes("限时免费") || String(t).toLowerCase().includes("free"));
|
|
100
|
-
if (!b) return "";
|
|
101
|
-
const part = String(b).split(":")[1];
|
|
102
|
-
return part ? ` [${part}]` : ` [${b}]`;
|
|
103
|
-
};
|
|
104
|
-
// 能力列:上下文 k + 📷识图 🧠推理 🔧工具调用(workbuddy 原生字段;其他供应商无这些字段则显示 —)
|
|
105
|
-
const fmtCaps = (m) => {
|
|
106
|
-
const ctx = Number(m.maxInputTokens ?? m.context_length) || null;
|
|
107
|
-
const reasoning = m.supportsReasoning ?? m.is_reasoning;
|
|
108
|
-
const hasAny = ctx || m.supportsImages != null || reasoning != null || m.supportsToolCall != null;
|
|
109
|
-
if (!hasAny) return "—";
|
|
110
|
-
const parts = [];
|
|
111
|
-
if (ctx) parts.push(ctx >= 1_000_000 ? `${Math.round(ctx / 100000) / 10}M` : `${Math.round(ctx / 1000)}k`);
|
|
112
|
-
if (m.supportsImages && !m.disabledMultimodal) parts.push("📷");
|
|
113
|
-
if (reasoning) parts.push("🧠");
|
|
114
|
-
if (m.supportsToolCall) parts.push("🔧");
|
|
115
|
-
return parts.join(" ");
|
|
116
|
-
};
|
|
117
|
-
const idW = Math.max(22, ...all.map((m) => String(m.id).length)) + 2;
|
|
118
|
-
const priceW = Math.max(6, ...all.map((m) => fmtPrice(m).length)) + 2;
|
|
119
|
-
const capsW = Math.max(4, ...all.map((m) => fmtCaps(m).length)) + 2;
|
|
120
|
-
for (const m of all) {
|
|
121
|
-
const ok = markAllowed(m.id);
|
|
122
|
-
const price = fmtPrice(m);
|
|
123
|
-
const badge = fmtBadge(m);
|
|
124
|
-
const name = m.name ? ` ${m.name}` : "";
|
|
125
|
-
const blocked = ok ? "" : " [blocked — allowlist]";
|
|
126
|
-
const line = ` ${ok ? "✓" : "x"} ${String(m.id).padEnd(idW)}${String(price).padEnd(priceW)}${fmtCaps(m).padEnd(capsW)}${name}${badge}${blocked}`;
|
|
127
|
-
console.log(line);
|
|
128
|
-
}
|
|
129
|
-
if (!all.length) console.log(` (no models — check baseUrl/keys or try: curl ${baseUrl}/models)`);
|
|
130
|
-
else if (allowedCount === 0) console.log(` tip: all blocked — mslxdff -provider ${id} allowAny on 或 allowlist set <model...>`);
|
|
131
|
-
else if (allowedCount !== all.length) console.log(` tip: blocked 仅影响 /v1/chat 调用,展示已全量列出`);
|
|
132
|
-
if (id === "zcode") {
|
|
133
|
-
console.log(` tip: 目录/额度/模型调用全通(上游 v3.14.4 起模型请求免验证码,docs/adr/0038);额度耗尽返回 429 quota_exhausted,按日窗口重置`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
try { await provider.close?.(); } catch {}
|
|
137
|
-
} catch (e) {
|
|
138
|
-
console.error(`could not list ${id} models: ${String(e?.message || e)}`);
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
process.exit(0);
|
|
142
|
-
}
|
|
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 {
|
|
63
|
+
if (!baseUrl) {
|
|
64
|
+
console.error(`provider ${id}: missing baseUrl — set via: mslxdff -provider ${id} set-url <baseUrl>`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
provider = createGenericProvider({ id, baseUrl, apiKeys: keys, file: defaultStateFile() });
|
|
68
|
+
}
|
|
69
|
+
const all = await provider.listModels();
|
|
70
|
+
const markAllowed = (mid) => {
|
|
71
|
+
const raw = String(mid || "").includes("/") ? String(mid).split("/").slice(1).join("/") : String(mid);
|
|
72
|
+
const checkRaw = mid.startsWith(`${id}/`) ? mid.slice(id.length + 1) : raw;
|
|
73
|
+
return isModelAllowed(id, checkRaw);
|
|
74
|
+
};
|
|
75
|
+
if (wantsJson) {
|
|
76
|
+
const filtered = all.filter((m) => markAllowed(m.id));
|
|
77
|
+
console.log(JSON.stringify({ object: "list", data: filtered }, null, 2));
|
|
78
|
+
} else {
|
|
79
|
+
const allowedCount = all.filter((m) => markAllowed(m.id)).length;
|
|
80
|
+
console.log(`${id} models (${all.length} total, ${allowedCount} ✓ allowed${allowedCount !== all.length ? `, ${all.length - allowedCount} x blocked by allowlist` : ""}):`);
|
|
81
|
+
const fmtPrice = (m) => {
|
|
82
|
+
const c = String(m.credits || "").trim();
|
|
83
|
+
if (c) {
|
|
84
|
+
const m0 = c.match(/x\s*([\d.]+)/i);
|
|
85
|
+
if (m0) return `x${m0[1]}`;
|
|
86
|
+
return c.replace(/\s*credits\s*/gi, "").trim().replace(/\s+/g, " ");
|
|
87
|
+
}
|
|
88
|
+
if (m.pricing && typeof m.pricing === "object") {
|
|
89
|
+
const p = m.pricing.prompt ?? m.pricing.input ?? m.pricing.completion ?? "";
|
|
90
|
+
if (p) return String(p);
|
|
91
|
+
}
|
|
92
|
+
if (m.price_factor != null && String(m.price_factor).trim() !== "") return `x${m.price_factor}`;
|
|
93
|
+
if (m.price != null && String(m.price).trim()) return String(m.price).trim();
|
|
94
|
+
if (String(m.id).endsWith("/auto")) return "浮动";
|
|
95
|
+
return "—";
|
|
96
|
+
};
|
|
97
|
+
const fmtBadge = (m) => {
|
|
98
|
+
const tags = Array.isArray(m.tags) ? m.tags : [];
|
|
99
|
+
const b = tags.find((t) => String(t).includes("限时免费") || String(t).toLowerCase().includes("free"));
|
|
100
|
+
if (!b) return "";
|
|
101
|
+
const part = String(b).split(":")[1];
|
|
102
|
+
return part ? ` [${part}]` : ` [${b}]`;
|
|
103
|
+
};
|
|
104
|
+
// 能力列:上下文 k + 📷识图 🧠推理 🔧工具调用(workbuddy 原生字段;其他供应商无这些字段则显示 —)
|
|
105
|
+
const fmtCaps = (m) => {
|
|
106
|
+
const ctx = Number(m.maxInputTokens ?? m.context_length) || null;
|
|
107
|
+
const reasoning = m.supportsReasoning ?? m.is_reasoning;
|
|
108
|
+
const hasAny = ctx || m.supportsImages != null || reasoning != null || m.supportsToolCall != null;
|
|
109
|
+
if (!hasAny) return "—";
|
|
110
|
+
const parts = [];
|
|
111
|
+
if (ctx) parts.push(ctx >= 1_000_000 ? `${Math.round(ctx / 100000) / 10}M` : `${Math.round(ctx / 1000)}k`);
|
|
112
|
+
if (m.supportsImages && !m.disabledMultimodal) parts.push("📷");
|
|
113
|
+
if (reasoning) parts.push("🧠");
|
|
114
|
+
if (m.supportsToolCall) parts.push("🔧");
|
|
115
|
+
return parts.join(" ");
|
|
116
|
+
};
|
|
117
|
+
const idW = Math.max(22, ...all.map((m) => String(m.id).length)) + 2;
|
|
118
|
+
const priceW = Math.max(6, ...all.map((m) => fmtPrice(m).length)) + 2;
|
|
119
|
+
const capsW = Math.max(4, ...all.map((m) => fmtCaps(m).length)) + 2;
|
|
120
|
+
for (const m of all) {
|
|
121
|
+
const ok = markAllowed(m.id);
|
|
122
|
+
const price = fmtPrice(m);
|
|
123
|
+
const badge = fmtBadge(m);
|
|
124
|
+
const name = m.name ? ` ${m.name}` : "";
|
|
125
|
+
const blocked = ok ? "" : " [blocked — allowlist]";
|
|
126
|
+
const line = ` ${ok ? "✓" : "x"} ${String(m.id).padEnd(idW)}${String(price).padEnd(priceW)}${fmtCaps(m).padEnd(capsW)}${name}${badge}${blocked}`;
|
|
127
|
+
console.log(line);
|
|
128
|
+
}
|
|
129
|
+
if (!all.length) console.log(` (no models — check baseUrl/keys or try: curl ${baseUrl}/models)`);
|
|
130
|
+
else if (allowedCount === 0) console.log(` tip: all blocked — mslxdff -provider ${id} allowAny on 或 allowlist set <model...>`);
|
|
131
|
+
else if (allowedCount !== all.length) console.log(` tip: blocked 仅影响 /v1/chat 调用,展示已全量列出`);
|
|
132
|
+
if (id === "zcode") {
|
|
133
|
+
console.log(` tip: 目录/额度/模型调用全通(上游 v3.14.4 起模型请求免验证码,docs/adr/0038);额度耗尽返回 429 quota_exhausted,按日窗口重置`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
try { await provider.close?.(); } catch {}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.error(`could not list ${id} models: ${String(e?.message || e)}`);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
process.exit(0);
|
|
142
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `-stats`
|
|
1
|
+
// `-stats` 模型用量报表:每窗口每模型 token 消耗 + 首字/总耗时/速度。默认窗口 = 今日 0 点至现在,--hours N 切近 N 小时滚动。
|
|
2
2
|
// 数据来自 src/usage/(逐请求 JSONL),不是 state.json 的终生 EMA —— 见 .scratch/stats-report/SPEC.md
|
|
3
3
|
import { usageReport } from "../../usage/report.js";
|
|
4
4
|
import { usageEnabled, usageKeepDays } from "../../usage/record.js";
|
|
@@ -9,10 +9,18 @@ export function isStatsFlag(args) {
|
|
|
9
9
|
return FLAGS.some((f) => args.includes(f));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// 默认窗口起点 = 本地当日 0 点(setHours 归零,随系统本地时区)。
|
|
13
|
+
export function startOfTodayMs(now = Date.now()) {
|
|
14
|
+
const d = new Date(now);
|
|
15
|
+
d.setHours(0, 0, 0, 0);
|
|
16
|
+
return d.getTime();
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
export function parseStatsArgs(args) {
|
|
13
20
|
const hoursIdx = args.findIndex((a) => a === "--hours" || a === "-hours");
|
|
14
21
|
const rawHours = hoursIdx >= 0 ? Number(args[hoursIdx + 1]) : NaN;
|
|
15
|
-
|
|
22
|
+
// null = 默认「今日 00:00 至今」窗口;显式但非法(非数/≤0)的 --hours 同样视为 null,不再回退 24h
|
|
23
|
+
const hours = Number.isFinite(rawHours) && Math.floor(rawHours) >= 1 ? Math.min(168, Math.floor(rawHours)) : null; // 0<N<1 折成 0 会造成「近 0h 标签配 24h 数据」,与非法同路走当日窗口
|
|
16
24
|
const modelIdx = args.findIndex((a) => a === "--model" || a === "-model");
|
|
17
25
|
const rawModel = modelIdx >= 0 && args[modelIdx + 1] && !String(args[modelIdx + 1]).startsWith("-") ? args[modelIdx + 1] : null;
|
|
18
26
|
return { hours, model: rawModel, json: args.includes("--json") };
|
|
@@ -80,11 +88,12 @@ function performanceRow(id, r) {
|
|
|
80
88
|
return [id, ttfb, fmtMs(r.avgTotalMs), fmtTps(r.avgTps), `${Number(r.ttfSamples) || 0}/${samples}`];
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
export function renderStats(report, { hours =
|
|
91
|
+
export function renderStats(report, { hours = null, model = null } = {}) {
|
|
92
|
+
const rangeLabel = hours == null ? "今日 00:00 至今" : `近 ${hours}h`;
|
|
84
93
|
const lines = [];
|
|
85
94
|
const { models, totals } = report;
|
|
86
95
|
if (!models.length) {
|
|
87
|
-
lines.push(
|
|
96
|
+
lines.push(`暂无用量记录(${rangeLabel}${model ? ` · 模型 ${model}` : ""})— 经 8989 网关发一次请求后出现`);
|
|
88
97
|
lines.push("提示:mslxdff -status 看当前体检 · mslxdff -log 20 看最近事件");
|
|
89
98
|
lines.push("说明:-chat 直连 mimo/big-pickle 不经网关,不计入本表");
|
|
90
99
|
return lines.join("\n");
|
|
@@ -93,7 +102,7 @@ export function renderStats(report, { hours = 24, model = null } = {}) {
|
|
|
93
102
|
const right = "right";
|
|
94
103
|
const tokenRows = [...models.map((m) => tokenRow(m.id, m)), tokenRow("合计", totals)];
|
|
95
104
|
const performanceRows = [...models.map((m) => performanceRow(m.id, m)), performanceRow("合计", totals)];
|
|
96
|
-
lines.push(
|
|
105
|
+
lines.push(`模型用量报告(${rangeLabel}${model ? ` · 筛选 ${model}` : ""})`);
|
|
97
106
|
lines.push(`成功请求:${totals.requests} 次 · 模型:${models.length} 个`);
|
|
98
107
|
lines.push("");
|
|
99
108
|
lines.push("Token 用量");
|
|
@@ -109,14 +118,15 @@ export function renderStats(report, { hours = 24, model = null } = {}) {
|
|
|
109
118
|
lines.push("口径差异:-status / -model stats 的首字仍取自 state 的终生 EMA(按转发入口量),与本表**不同源**。");
|
|
110
119
|
lines.push("范围:只含经 8989 网关的成功请求;不含失败请求和 -chat 直连。");
|
|
111
120
|
const keepDays = usageKeepDays();
|
|
112
|
-
if (hours > keepDays * 24) {
|
|
113
|
-
lines.push(
|
|
121
|
+
if (hours != null && hours > keepDays * 24) {
|
|
122
|
+
lines.push(`警告:查询窗口 ${hours}h 超过数据保留 ${keepDays} 天,历史可能不完整。`);
|
|
114
123
|
} else {
|
|
115
124
|
lines.push(`数据保留 ${keepDays} 天;更早的历史已删除。`);
|
|
116
125
|
}
|
|
117
126
|
lines.push("明细口径:本表按模型聚合,不展开 via、interrupted 和单次 tps。");
|
|
118
127
|
lines.push("数值使用 k/M 缩写;需要精确值或机器处理请加 --json。");
|
|
119
|
-
lines.push("
|
|
128
|
+
lines.push("可调:默认统计今日 0 点至现在 · mslxdff -stats --hours N(近 N 小时滚动,上限 168)| --model <id> | --json");
|
|
129
|
+
lines.push("时区:「今日 0 点」按系统本地时区计,与用量日文件的日切同源。");
|
|
120
130
|
return lines.join("\n");
|
|
121
131
|
}
|
|
122
132
|
|
|
@@ -127,7 +137,9 @@ export async function handleStats(args) {
|
|
|
127
137
|
console.log("用量记录已关闭(MSLXDFF_USAGE_LOG=0)—— 去掉该 env 后重启 daemon 即可恢复采集。");
|
|
128
138
|
return true;
|
|
129
139
|
}
|
|
130
|
-
const
|
|
140
|
+
const now = Date.now();
|
|
141
|
+
const since = hours == null ? startOfTodayMs(now) : null; // 缺省/非法 --hours → 当日 0 点起,毫秒精确不漂移
|
|
142
|
+
const report = await usageReport({ hours, since, model, now });
|
|
131
143
|
if (json) {
|
|
132
144
|
console.log(JSON.stringify(report, null, 2));
|
|
133
145
|
return true;
|