mslxdff 0.1.85 → 0.1.86
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/package.json
CHANGED
|
@@ -1,4 +1,64 @@
|
|
|
1
1
|
export async function handleProviderConfig(id, sub, rest) {
|
|
2
|
+
if (sub === "del" || sub === "delete" || sub === "rm" || sub === "remove-provider" || sub === "del-provider") {
|
|
3
|
+
const nid = String(id || "").trim().toLowerCase();
|
|
4
|
+
if (nid === "opencode" || nid === "oc") {
|
|
5
|
+
console.error("opencode 是内置供应商,不能删除");
|
|
6
|
+
process.exit(1);
|
|
7
|
+
}
|
|
8
|
+
const { loadProviderConfigs, saveProviderConfig, saveProviderShareKeys } = await import("../../../state.js");
|
|
9
|
+
const { isPidAlive, readPid } = await import("../../../daemon.js");
|
|
10
|
+
const configs = loadProviderConfigs();
|
|
11
|
+
if (!configs[id] && !configs[nid]) {
|
|
12
|
+
// 也查旧的 providerKeys
|
|
13
|
+
const { readState } = await import("../../../state/store.js");
|
|
14
|
+
const { defaultStateFile } = await import("../../../state/store.js");
|
|
15
|
+
const raw = readState(defaultStateFile());
|
|
16
|
+
const hasLegacy = raw.providerKeys && raw.providerKeys[id];
|
|
17
|
+
if (!hasLegacy) {
|
|
18
|
+
console.error(`provider not found: ${id}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// 真删:空对象会触发 saveProviderConfig 的 delete 分支
|
|
23
|
+
saveProviderConfig(id, { baseUrl: "", keys: [], auths: [], allowedModels: [], modelsPath: "", chatPath: "" });
|
|
24
|
+
// 兼容旧路径的残留
|
|
25
|
+
try {
|
|
26
|
+
const { readState, writeStateImmediate, defaultStateFile } = await import("../../../state/store.js");
|
|
27
|
+
const file = defaultStateFile();
|
|
28
|
+
const raw = readState(file);
|
|
29
|
+
let changed = false;
|
|
30
|
+
if (raw.providerKeys && raw.providerKeys[id] !== undefined) {
|
|
31
|
+
const nk = { ...raw.providerKeys };
|
|
32
|
+
delete nk[id];
|
|
33
|
+
writeStateImmediate(file, { providerKeys: nk });
|
|
34
|
+
changed = true;
|
|
35
|
+
}
|
|
36
|
+
if (raw.providerShareKeys && raw.providerShareKeys[id] !== undefined) {
|
|
37
|
+
const ns = { ...raw.providerShareKeys };
|
|
38
|
+
delete ns[id];
|
|
39
|
+
writeStateImmediate(file, { providerShareKeys: ns });
|
|
40
|
+
changed = true;
|
|
41
|
+
}
|
|
42
|
+
// 清理模型错误/延迟中该供应商前缀的条目(可选,不阻塞)
|
|
43
|
+
void changed;
|
|
44
|
+
} catch {}
|
|
45
|
+
try { saveProviderShareKeys(id, false); } catch {}
|
|
46
|
+
console.log(`已删除供应商: ${id} — 配置已清空`);
|
|
47
|
+
// 需要重启才生效,自动重启
|
|
48
|
+
const pid = readPid();
|
|
49
|
+
if (pid && isPidAlive(pid)) {
|
|
50
|
+
console.log("检测到 daemon 运行中,自动重启以生效…");
|
|
51
|
+
const { spawnSync } = await import("node:child_process");
|
|
52
|
+
const { fileURLToPath } = await import("node:url");
|
|
53
|
+
const bin = fileURLToPath(new URL("../../../../bin/mslxdff.js", import.meta.url));
|
|
54
|
+
const r = spawnSync(process.execPath, [bin, "-restart"], { stdio: "inherit" });
|
|
55
|
+
if (r.status !== 0) console.log("自动重启失败,请手动执行: mslxdff -restart");
|
|
56
|
+
else console.log("已自动重启完成");
|
|
57
|
+
} else {
|
|
58
|
+
console.log("daemon 未运行,下次启动时生效");
|
|
59
|
+
}
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
2
62
|
if (sub === "set-models-path" || sub === "setModelsPath" || sub === "models-path") {
|
|
3
63
|
const p = rest[1];
|
|
4
64
|
if (!p) {
|
|
@@ -6,73 +6,12 @@ export async function handleProviders(args) {
|
|
|
6
6
|
const idx = args.findIndex((x) => x === "-providers" || x === "--providers");
|
|
7
7
|
const sub = args[idx + 1];
|
|
8
8
|
if (!sub || sub === "list" || sub === "status") {
|
|
9
|
-
const {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const orShare = loadProviderShareKeys("openrouter");
|
|
16
|
-
const orAllowed = loadProviderAllowedModels("openrouter");
|
|
17
|
-
const genericIds = new Set(Object.keys(configs).filter((id) => id !== "opencode" && id !== "openrouter"));
|
|
18
|
-
try {
|
|
19
|
-
const raw = JSON.parse(readFileSync(defaultStateFile(), "utf8"));
|
|
20
|
-
const pk = raw.providerKeys || {};
|
|
21
|
-
for (const id of Object.keys(pk)) if (id !== "opencode" && id !== "openrouter") genericIds.add(id);
|
|
22
|
-
const cfgRaw = raw.providerConfigs || {};
|
|
23
|
-
for (const id of Object.keys(cfgRaw)) if (id !== "opencode" && id !== "openrouter") genericIds.add(id);
|
|
24
|
-
} catch {}
|
|
25
|
-
for (const k of Object.keys(process.env)) {
|
|
26
|
-
const m = k.match(/^MSLXDFF_(.+)_KEY$/);
|
|
27
|
-
if (m) {
|
|
28
|
-
const id = m[1].toLowerCase().replace(/__/g, "-");
|
|
29
|
-
if (id !== "openrouter" && id !== "opencode") genericIds.add(id);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
const raw = JSON.parse(readFileSync(defaultStateFile(), "utf8"));
|
|
34
|
-
const cfgs = raw.providerConfigs || {};
|
|
35
|
-
for (const id of Object.keys(cfgs)) {
|
|
36
|
-
if (id === "opencode" || id === "openrouter") continue;
|
|
37
|
-
const am = cfgs[id]?.allowedModels;
|
|
38
|
-
if (Array.isArray(am) && am.length) genericIds.add(id);
|
|
39
|
-
}
|
|
40
|
-
} catch {}
|
|
41
|
-
const list = [];
|
|
42
|
-
const { loadProviderAllowAnyModels: _la0 } = await import("../../../state.js");
|
|
43
|
-
const opAllowAny = _la0("opencode");
|
|
44
|
-
const orAllowAny = _la0("openrouter");
|
|
45
|
-
const opAllowed = loadProviderAllowedModels("opencode");
|
|
46
|
-
list.push({ id: "opencode", enabled: opencodeEnabled, baseUrl: opencodeBase, keys: [], share: false, allowed: opAllowed, allowAny: opAllowAny, note: "built-in, no key, cannot share" });
|
|
47
|
-
list.push({ id: "openrouter", enabled: orKeys.length > 0, baseUrl: orBase, keys: orKeys, share: orShare, allowed: orAllowed, allowAny: orAllowAny, note: orKeys.length ? "" : "no keys" });
|
|
48
|
-
for (const gid of [...genericIds].sort()) {
|
|
49
|
-
const cfg = configs[gid];
|
|
50
|
-
const keys = loadProviderKeys(gid);
|
|
51
|
-
const baseUrl = loadProviderBaseUrl(gid) || cfg?.baseUrl || "";
|
|
52
|
-
const share = loadProviderShareKeys(gid);
|
|
53
|
-
const allowed = loadProviderAllowedModels(gid);
|
|
54
|
-
const allowAny = _la0(gid);
|
|
55
|
-
const enabled = Boolean(baseUrl && keys.length);
|
|
56
|
-
let note = "";
|
|
57
|
-
if (!baseUrl && !keys.length && !allowed.length && allowAny === false) note = "no baseUrl, no keys, BLOCKED (allowAny OFF)";
|
|
58
|
-
else if (!baseUrl && !keys.length && !allowed.length) note = "no baseUrl, no keys";
|
|
59
|
-
else if (!baseUrl && !allowed.length && !allowAny) note = "missing baseUrl, BLOCKED";
|
|
60
|
-
else if (!keys.length && !allowed.length && !allowAny) note = "no keys, BLOCKED";
|
|
61
|
-
else if (!baseUrl) note = "missing baseUrl";
|
|
62
|
-
else if (!keys.length) note = "no keys";
|
|
63
|
-
list.push({ id: gid, enabled, baseUrl: baseUrl || "(none)", keys, share, allowed, allowAny, note });
|
|
64
|
-
}
|
|
65
|
-
console.log(`providers (${list.length}):`);
|
|
66
|
-
for (const p of list) {
|
|
67
|
-
const state = p.enabled ? "enabled " : "disabled";
|
|
68
|
-
const keysInfo = p.keys.length ? `${p.keys.length} key${p.keys.length > 1 ? "s" : ""} ${p.keys.map((k) => `${k.slice(0, 4)}…${k.slice(-4)}`).join(", ")}` : "0 keys";
|
|
69
|
-
const shareInfo = p.id === "opencode" ? "cannot share" : `share=${p.share ? "ON" : "off"}`;
|
|
70
|
-
const allowInfo = p.allowed.length ? `allow=${p.allowed.length}(${p.allowed.slice(0, 3).join(",")}${p.allowed.length > 3 ? "..." : ""})` : (p.allowAny ? "allow=all" : "allow=none(BLOCKED)");
|
|
71
|
-
const note = p.note ? ` (${p.note})` : "";
|
|
72
|
-
console.log(` ${p.id.padEnd(12)} ${state} ${keysInfo.padEnd(28)} ${allowInfo.padEnd(22)} baseUrl=${p.baseUrl} ${shareInfo}${note}`);
|
|
73
|
-
}
|
|
74
|
-
console.log(`\nuse: mslxdff -provider <id> list to inspect one, mslxdff -provider <id> allowlist set <model...> to restrict`);
|
|
75
|
-
console.log(` mslxdff -provider <id> allowAny on|off (empty allowlist = block or allow all)`);
|
|
9
|
+
const { buildProviderRows, formatProviderSection } = await import("../../provider-row.js");
|
|
10
|
+
const rows = buildProviderRows({});
|
|
11
|
+
const enabled = rows.filter((r) => r.enabled).length;
|
|
12
|
+
console.log(`providers ${rows.length} 个 · ${enabled} 已启用 — mslxdff -provider <id> list 查看详情`);
|
|
13
|
+
console.log(formatProviderSection(rows));
|
|
14
|
+
console.log(`\n提示: mslxdff -provider <id> list 单看一个 · allowlist set <model...> 限制模型 · allowAny on|off 空名单放行/阻断`);
|
|
76
15
|
process.exit(0);
|
|
77
16
|
}
|
|
78
17
|
console.error("usage: mslxdff -providers list");
|
|
@@ -106,68 +45,11 @@ export async function handleProvider(args) {
|
|
|
106
45
|
process.exit(1);
|
|
107
46
|
}
|
|
108
47
|
if (id === "list" || id === "status") {
|
|
109
|
-
const {
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const orShare = loadProviderShareKeys("openrouter");
|
|
115
|
-
const genericIds = new Set(Object.keys(configs).filter((x) => x !== "opencode" && x !== "openrouter"));
|
|
116
|
-
try {
|
|
117
|
-
const raw = JSON.parse(readFileSync(defaultStateFile(), "utf8"));
|
|
118
|
-
const pk = raw.providerKeys || {};
|
|
119
|
-
for (const k of Object.keys(pk)) if (k !== "opencode" && k !== "openrouter") genericIds.add(k);
|
|
120
|
-
const cfgRaw = raw.providerConfigs || {};
|
|
121
|
-
for (const k of Object.keys(cfgRaw)) if (k !== "opencode" && k !== "openrouter") genericIds.add(k);
|
|
122
|
-
} catch {}
|
|
123
|
-
for (const k of Object.keys(process.env)) {
|
|
124
|
-
const m = k.match(/^MSLXDFF_(.+)_KEY$/);
|
|
125
|
-
if (m) {
|
|
126
|
-
const gid = m[1].toLowerCase().replace(/__/g, "-");
|
|
127
|
-
if (gid !== "openrouter" && gid !== "opencode") genericIds.add(gid);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
const raw = JSON.parse(readFileSync(defaultStateFile(), "utf8"));
|
|
132
|
-
const cfgs = raw.providerConfigs || {};
|
|
133
|
-
for (const gid of Object.keys(cfgs)) {
|
|
134
|
-
if (gid === "opencode" || gid === "openrouter") continue;
|
|
135
|
-
const am = cfgs[gid]?.allowedModels;
|
|
136
|
-
if (Array.isArray(am) && am.length) genericIds.add(gid);
|
|
137
|
-
}
|
|
138
|
-
} catch {}
|
|
139
|
-
const list = [];
|
|
140
|
-
const { loadProviderAllowAnyModels: _la0 } = await import("../../../state.js");
|
|
141
|
-
const { loadProviderAllowedModels } = await import("../../../state.js");
|
|
142
|
-
const opAllowed = loadProviderAllowedModels("opencode");
|
|
143
|
-
const opAllowAny = _la0("opencode");
|
|
144
|
-
const orAllowed = loadProviderAllowedModels("openrouter");
|
|
145
|
-
const orAllowAny = _la0("openrouter");
|
|
146
|
-
list.push({ id: "opencode", enabled: true, baseUrl: opencodeBase, keys: [], share: false, allowed: opAllowed, allowAny: opAllowAny, note: "built-in, no key, cannot share" });
|
|
147
|
-
list.push({ id: "openrouter", enabled: orKeys.length > 0, baseUrl: orBase, keys: orKeys, share: orShare, allowed: orAllowed, allowAny: orAllowAny, note: orKeys.length ? "" : "no keys" });
|
|
148
|
-
for (const gid of [...genericIds].sort()) {
|
|
149
|
-
const cfg = configs[gid];
|
|
150
|
-
const keys = loadProviderKeys(gid);
|
|
151
|
-
const baseUrl = loadProviderBaseUrl(gid) || cfg?.baseUrl || "";
|
|
152
|
-
const share = loadProviderShareKeys(gid);
|
|
153
|
-
const allowed = loadProviderAllowedModels(gid);
|
|
154
|
-
const allowAny = _la0(gid);
|
|
155
|
-
const enabled = Boolean(baseUrl && keys.length);
|
|
156
|
-
let note = "";
|
|
157
|
-
if (!baseUrl && !keys.length) note = "no baseUrl, no keys";
|
|
158
|
-
else if (!baseUrl) note = "missing baseUrl";
|
|
159
|
-
else if (!keys.length) note = "no keys";
|
|
160
|
-
list.push({ id: gid, enabled, baseUrl: baseUrl || "(none)", keys, share, note });
|
|
161
|
-
}
|
|
162
|
-
console.log(`providers (${list.length}):`);
|
|
163
|
-
for (const p of list) {
|
|
164
|
-
const state = p.enabled ? "enabled " : "disabled";
|
|
165
|
-
const keysInfo = p.keys.length ? `${p.keys.length} key${p.keys.length > 1 ? "s" : ""} ${p.keys.map((k) => `${k.slice(0, 4)}…${k.slice(-4)}`).join(", ")}` : "0 keys";
|
|
166
|
-
const shareInfo = p.id === "opencode" ? "cannot share" : `share=${p.share ? "ON" : "off"}`;
|
|
167
|
-
const note = p.note ? ` (${p.note})` : "";
|
|
168
|
-
console.log(` ${p.id.padEnd(12)} ${state} ${keysInfo.padEnd(28)} baseUrl=${p.baseUrl} ${shareInfo}${note}`);
|
|
169
|
-
}
|
|
170
|
-
console.log(`\nuse: mslxdff -provider <id> list to inspect one, mslxdff -provider add <id> <baseUrl> <key> to add generic`);
|
|
48
|
+
const { buildProviderRows, formatProviderSection } = await import("../../provider-row.js");
|
|
49
|
+
const rows = buildProviderRows({});
|
|
50
|
+
const enabled = rows.filter((r) => r.enabled).length;
|
|
51
|
+
console.log(`providers ${rows.length} 个 · ${enabled} 已启用 — mslxdff -provider <id> list 单看一个`);
|
|
52
|
+
console.log(formatProviderSection(rows));
|
|
171
53
|
process.exit(0);
|
|
172
54
|
}
|
|
173
55
|
if (id === "add") {
|
package/src/cli/provider-row.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
-
import { loadProviderKeys, loadProviderAuths, loadProviderConfigs, loadProviderAllowedModels, loadProviderShareKeys, loadProviderBaseUrl } from "../state.js";
|
|
2
|
+
import { loadProviderKeys, loadProviderAuths, loadProviderConfigs, loadProviderAllowedModels, loadProviderAllowAnyModels, loadProviderShareKeys, loadProviderBaseUrl } from "../state.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 聚合 genericIds:来自 providerConfigs + providerKeys + env MSLXDFF_*_KEY
|
|
@@ -12,7 +12,8 @@ export function buildProviderRows({ stateFile, env = process.env } = {}) {
|
|
|
12
12
|
const upstreamBase = env.UPSTREAM_BASE_URL || "https://opencode.ai";
|
|
13
13
|
const rows = [];
|
|
14
14
|
const opAllowed = (() => { try { return loadProviderAllowedModels("opencode", stateFile ? { file: stateFile } : undefined); } catch { return []; } })();
|
|
15
|
-
|
|
15
|
+
const opAllowAny = (() => { try { return loadProviderAllowAnyModels("opencode", stateFile ? { file: stateFile } : undefined); } catch { return true; } })();
|
|
16
|
+
rows.push({ id: "opencode", enabled: true, baseUrl: upstreamBase, keys: [], allowed: opAllowed, allowAny: opAllowAny !== false, share: false, note: "built-in, no key, cannot share", authCount: 0 });
|
|
16
17
|
|
|
17
18
|
const genericIds = new Set(Object.keys(configs).filter((id) => id !== "opencode"));
|
|
18
19
|
try {
|
|
@@ -30,16 +31,22 @@ export function buildProviderRows({ stateFile, env = process.env } = {}) {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
// 保证 openrouter 始终可见(即使 0 keys,供用户发现)
|
|
35
|
+
genericIds.add("openrouter");
|
|
33
36
|
for (const gid of [...genericIds].sort()) {
|
|
34
37
|
const cfg = configs[gid];
|
|
35
38
|
let keys = [];
|
|
36
39
|
let baseUrl = "";
|
|
37
40
|
let share = false;
|
|
38
41
|
let allowed = [];
|
|
42
|
+
let allowAny = false;
|
|
39
43
|
try { keys = loadProviderKeys(gid, stateFile ? { file: stateFile } : undefined); } catch {}
|
|
40
44
|
try { baseUrl = loadProviderBaseUrl(gid, stateFile ? { file: stateFile } : undefined) || cfg?.baseUrl || (gid === "openrouter" ? "https://openrouter.ai/api/v1" : gid === "workbuddy" ? "https://copilot.tencent.com" : ""); } catch { baseUrl = cfg?.baseUrl || ""; }
|
|
41
45
|
try { share = loadProviderShareKeys(gid, stateFile ? { file: stateFile } : undefined); } catch {}
|
|
42
46
|
try { allowed = loadProviderAllowedModels(gid, stateFile ? { file: stateFile } : undefined); } catch {}
|
|
47
|
+
try { allowAny = loadProviderAllowAnyModels(gid, stateFile ? { file: stateFile } : undefined); } catch {}
|
|
48
|
+
// openrouter 特殊:opencode 例外默认 allowAny true,其余默认 false
|
|
49
|
+
if (gid === "opencode") allowAny = true;
|
|
43
50
|
let enabled = Boolean(baseUrl && keys.length) || (gid === "openrouter" && keys.length > 0);
|
|
44
51
|
const auths = gid === "workbuddy" ? (() => { try { return loadProviderAuths(gid, stateFile ? { file: stateFile } : undefined) || []; } catch { return []; } })() : [];
|
|
45
52
|
let note = "";
|
|
@@ -54,20 +61,68 @@ export function buildProviderRows({ stateFile, env = process.env } = {}) {
|
|
|
54
61
|
} else if (gid === "workbuddy" && auths.length && auths.length !== keys.length) {
|
|
55
62
|
note = `${auths.length} auth(s) / ${keys.length} key(s) — 数量不一致请重跑 workbuddy-token-auto.js`;
|
|
56
63
|
}
|
|
57
|
-
rows.push({ id: gid, enabled, baseUrl: baseUrl || "(none)", keys, allowed, share, note, authCount: auths.length });
|
|
64
|
+
rows.push({ id: gid, enabled, baseUrl: baseUrl || "(none)", keys, allowed, allowAny, share, note, authCount: auths.length });
|
|
58
65
|
}
|
|
59
66
|
return rows;
|
|
60
67
|
}
|
|
61
68
|
|
|
69
|
+
function maskKey(k) {
|
|
70
|
+
const s = String(k || "").trim();
|
|
71
|
+
if (s.length <= 8) return `${s.slice(0, 3)}…${s.slice(-2)}`;
|
|
72
|
+
return `${s.slice(0, 3)}…${s.slice(-4)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
62
75
|
export function formatProviderRow(p) {
|
|
63
|
-
const
|
|
64
|
-
const
|
|
76
|
+
const isBlocked = !p.allowed.length && !p.allowAny && p.id !== "opencode";
|
|
77
|
+
const dot = !p.enabled ? "○" : isBlocked ? "◐" : "●";
|
|
78
|
+
const state = !p.enabled ? "未启用" : isBlocked ? "已启用·阻断" : "已启用";
|
|
79
|
+
// keys
|
|
65
80
|
let keysInfo;
|
|
66
|
-
if (p.id === "opencode") keysInfo = "无需 key
|
|
67
|
-
else
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
if (p.id === "opencode") keysInfo = "无需 key";
|
|
82
|
+
else if (!p.keys.length) keysInfo = "0 keys";
|
|
83
|
+
else if (p.keys.length === 1) keysInfo = `1 key ${maskKey(p.keys[0])}`;
|
|
84
|
+
else keysInfo = `${p.keys.length} keys ${p.keys.slice(0, 2).map(maskKey).join(", ")}${p.keys.length > 2 ? ` +${p.keys.length - 2}` : ""}`;
|
|
85
|
+
if (p.authCount) keysInfo += ` · ${p.authCount} acc`;
|
|
86
|
+
// allow — 空名单 + allowAny OFF = 阻断(安全默认)
|
|
87
|
+
let allowInfo;
|
|
88
|
+
if (!p.allowed.length) {
|
|
89
|
+
if (p.id === "opencode") allowInfo = "allow all";
|
|
90
|
+
else if (p.allowAny) allowInfo = "allow all";
|
|
91
|
+
else allowInfo = "allow none (BLOCKED)";
|
|
92
|
+
} else {
|
|
93
|
+
const head = p.allowed.slice(0, 2).join(", ");
|
|
94
|
+
const more = p.allowed.length > 2 ? ` …+${p.allowed.length - 2}` : "";
|
|
95
|
+
allowInfo = `allow ${p.allowed.length} → ${head}${more}`;
|
|
96
|
+
}
|
|
97
|
+
// share
|
|
98
|
+
const shareInfo = p.id === "opencode" ? "无法共享" : `共享 ${p.share ? "开" : "关"}`;
|
|
99
|
+
// base
|
|
100
|
+
const base = p.baseUrl && p.baseUrl !== "(none)" ? p.baseUrl : "(none)";
|
|
101
|
+
const baseLine = ` └ ${base}${p.note ? ` · ${p.note}` : ""}`;
|
|
102
|
+
// 主行:id 固定 12,状态 6,keys 22,allow 自适应,share 固定
|
|
103
|
+
const main = ` ${dot} ${p.id.padEnd(12)} ${state} ${keysInfo.padEnd(22)} ${allowInfo.padEnd(28)} ${shareInfo}`;
|
|
104
|
+
return `${main}\n${baseLine}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function formatProviderSection(rows) {
|
|
108
|
+
if (!rows.length) {
|
|
109
|
+
return [
|
|
110
|
+
" (空) 暂无供应商 — 加一个试试:",
|
|
111
|
+
" mslxdff -provider add myapi https://api.example.com/v1 sk-xxx",
|
|
112
|
+
" 或 node workbuddy-token-auto.js (WorkBuddy 一键接入)",
|
|
113
|
+
].join("\n");
|
|
114
|
+
}
|
|
115
|
+
const enabled = rows.filter((r) => r.enabled);
|
|
116
|
+
const disabled = rows.filter((r) => !r.enabled);
|
|
117
|
+
const out = [];
|
|
118
|
+
if (enabled.length) {
|
|
119
|
+
out.push(` 已启用 (${enabled.length})`);
|
|
120
|
+
for (const p of enabled) out.push(formatProviderRow(p));
|
|
121
|
+
}
|
|
122
|
+
if (disabled.length) {
|
|
123
|
+
if (enabled.length) out.push("");
|
|
124
|
+
out.push(` 未启用 / 需配置 (${disabled.length})`);
|
|
125
|
+
for (const p of disabled) out.push(formatProviderRow(p));
|
|
126
|
+
}
|
|
127
|
+
return out.join("\n");
|
|
73
128
|
}
|
package/src/cli/status.js
CHANGED
|
@@ -13,7 +13,7 @@ import { refreshGroupMembers } from "../groups.js";
|
|
|
13
13
|
import { fmtShanghaiYMDHM } from "../time.js";
|
|
14
14
|
import { fmtStatus, fmtUptime, fmtTs } from "./format.js";
|
|
15
15
|
import { compareSemver } from "./policy.js";
|
|
16
|
-
import { buildProviderRows, formatProviderRow } from "./provider-row.js";
|
|
16
|
+
import { buildProviderRows, formatProviderRow, formatProviderSection } from "./provider-row.js";
|
|
17
17
|
|
|
18
18
|
export async function printStatus(VERSION) {
|
|
19
19
|
const daemon = readPid();
|
|
@@ -53,12 +53,12 @@ export async function printStatus(VERSION) {
|
|
|
53
53
|
try {
|
|
54
54
|
const providerRows = buildProviderRows({});
|
|
55
55
|
const enabledCount = providerRows.filter((r) => r.enabled).length;
|
|
56
|
-
console.log(`\nupstream providers
|
|
57
|
-
|
|
58
|
-
console.log(formatProviderRow(p));
|
|
59
|
-
}
|
|
56
|
+
console.log(`\nupstream providers ${providerRows.length} 个 · ${enabledCount} 已启用 — mslxdff -providers list 查看详情`);
|
|
57
|
+
console.log(formatProviderSection(providerRows));
|
|
60
58
|
if (enabledCount === 1 && providerRows.length === 1) {
|
|
61
|
-
console.log(
|
|
59
|
+
console.log(`\n 空状态:仅 opencode 内置免费通道`);
|
|
60
|
+
console.log(` → 加一个私有上游:mslxdff -provider add bai https://api.b.ai/v1 <key>`);
|
|
61
|
+
console.log(` → 或 WorkBuddy 一键接入:node workbuddy-token-auto.js`);
|
|
62
62
|
}
|
|
63
63
|
} catch (e) {
|
|
64
64
|
console.log(`\nupstream providers: (unavailable — ${String(e?.message || e).slice(0, 80)})`);
|