mslxdff 0.1.104 → 0.1.105
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
|
@@ -9,6 +9,7 @@ import { handlePeerRelay } from "../routes/chat/peer-handler.js";
|
|
|
9
9
|
import { handleBroadbandRelay } from "../routes/chat/broadband-handler.js";
|
|
10
10
|
import { handleViaRoute } from "../routes/chat/via-route-handler.js";
|
|
11
11
|
import { handleExhaustedLocal, handleExhaustedAll } from "../routes/chat/exhausted-handler.js";
|
|
12
|
+
import { shouldUseGroupForModel } from "../state/schemas/use-group.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* 串行 trial — 从 engine.js 抽出的第二段:via-route 单路径 → 串行 trial →
|
|
@@ -112,7 +113,8 @@ export async function runSerialTrial(ctx, deps = {}) {
|
|
|
112
113
|
const isStream = Boolean(body.stream);
|
|
113
114
|
const d = hedgeDelayMs();
|
|
114
115
|
const hasPeers = Boolean(peers) && peers.ordered().length > 0;
|
|
115
|
-
const
|
|
116
|
+
const canUseGroup = shouldUseGroupForModel(model);
|
|
117
|
+
const doHedge = canUseGroup && shouldHedge({ isStream, canForwardPeers, hedgeDelayMs: d, hasPeers, model }) && upRes.status === 200 && upRes.body;
|
|
116
118
|
if (doHedge) {
|
|
117
119
|
const hr = await hedge({ upRes, model, body, order, idx, lastErr, requested, useAuto, lockModel, auto, peers, handlerCtx, evt, logCall, logError, mark, perf0, stages, startedAt, plugins, res, hedgeDelayMs: d });
|
|
118
120
|
if (hr.handled) return { done: true };
|
|
@@ -128,12 +130,20 @@ export async function runSerialTrial(ctx, deps = {}) {
|
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
if (canForwardPeers) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
if (!shouldUseGroupForModel(model)) {
|
|
134
|
+
evt("group-skip", { reqId, model, reason: "useGroup=off for opencode (peer)" });
|
|
135
|
+
} else {
|
|
136
|
+
const pr = await peerRelay({ model, body, lastErr, requested, useAuto, lockModel, auto, peers, handlerCtx, evt, logCall, mark, perf0, stages, startedAt, plugins, res });
|
|
137
|
+
if (pr.handled) return { done: true };
|
|
138
|
+
}
|
|
133
139
|
}
|
|
134
140
|
if (groups) {
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
if (!shouldUseGroupForModel(model)) {
|
|
142
|
+
evt("group-skip", { reqId, model, reason: "useGroup=off for opencode (broadband)" });
|
|
143
|
+
} else {
|
|
144
|
+
const br = await broadbandRelay({ model, body, hops, lastErr, requested, useAuto, lockModel, auto, groups, token, bus, logs, handlerCtx, evt, mark, perf0, stages, res, startedAt, plugins });
|
|
145
|
+
if (br.handled) return { done: true };
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
148
|
if (canFallback) { evt("fallback", { reqId, from: model, to: order[idx + 1] ?? null, reason: lastErr?.message || `upstream ${lastErr?.status ?? 502}` }); continue; }
|
|
139
149
|
await exhaustedLocal({ res, body, lastErr, order, handlerCtx: { ...handlerCtx, model, reqId }, evt, logCall, mark, perf0, stages, done, requested, useAuto });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { loadUseGroup, saveUseGroup, getEffectiveUseGroup, getUseGroupEnv } from "../../state/schemas/use-group.js";
|
|
2
|
+
import { argValue } from "../policy.js";
|
|
3
|
+
|
|
4
|
+
function parseInput(v) {
|
|
5
|
+
if (v === undefined || v === null || v === "") return null;
|
|
6
|
+
const s = String(v).trim().toLowerCase();
|
|
7
|
+
if (["1", "true", "on", "yes", "enable", "enabled", "open"].includes(s)) return true;
|
|
8
|
+
if (["0", "false", "off", "no", "disable", "disabled", "close", "closed"].includes(s)) return false;
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function handleUseGroup(args) {
|
|
13
|
+
const hasFlag = args.some((a) => ["-use-group", "--use-group", "-use_group", "--use_group", "-usegroup", "--usegroup"].includes(a));
|
|
14
|
+
if (!hasFlag) return false;
|
|
15
|
+
|
|
16
|
+
// 取值:支持 -use-group true / -use-group=true / --use-group=off
|
|
17
|
+
let raw = argValue(args, "-use-group", "--use-group", "-use_group", "--use_group", "-usegroup", "--usegroup");
|
|
18
|
+
// 兼容 -use-group=true 这种等号形态
|
|
19
|
+
if (raw === null || raw === undefined) {
|
|
20
|
+
const eq = args.find((a) => a.startsWith("-use-group=") || a.startsWith("--use-group=") || a.startsWith("-use_group=") || a.startsWith("--use_group="));
|
|
21
|
+
if (eq) raw = eq.split("=")[1];
|
|
22
|
+
}
|
|
23
|
+
// 如果 flag 后面紧跟的不是另一个 flag,则视为值;否则视为查询
|
|
24
|
+
if (raw !== null && raw !== undefined && String(raw).startsWith("-")) raw = null;
|
|
25
|
+
|
|
26
|
+
const envVal = getUseGroupEnv();
|
|
27
|
+
const effective = getEffectiveUseGroup();
|
|
28
|
+
const stored = loadUseGroup();
|
|
29
|
+
|
|
30
|
+
if (raw === null || raw === undefined || raw === "") {
|
|
31
|
+
// 查询模式
|
|
32
|
+
console.log(`use-group: ${effective ? "on" : "off"} (effective)`);
|
|
33
|
+
console.log(` stored: ${stored ? "on" : "off"} (state.json useGroup)`);
|
|
34
|
+
if (envVal !== null) console.log(` env MSLXDFF_USE_GROUP=${envVal ? "on" : "off"} (overrides stored)`);
|
|
35
|
+
console.log(` default: on`);
|
|
36
|
+
console.log(` usage: mslxdff -use-group on|off (opencode 供应商本机失败时是否走组员网络,默认 on)`);
|
|
37
|
+
console.log(` env: MSLXDFF_USE_GROUP=0|1 (优先级高于 state)`);
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const parsed = parseInput(raw);
|
|
42
|
+
if (parsed === null) {
|
|
43
|
+
console.error(`invalid value for -use-group: ${raw} (expected on/off/true/false/1/0)`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (envVal !== null) {
|
|
48
|
+
console.log(`note: env MSLXDFF_USE_GROUP=${envVal ? "on" : "off"} is set and overrides stored value; unset env to use stored value`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
saveUseGroup(parsed);
|
|
52
|
+
console.log(`use-group set to ${parsed ? "on" : "off"} (stored in state.json)`);
|
|
53
|
+
console.log(` opencode 供应商:本机失败时 ${parsed ? "允许" : "不再"} 通过组员网络请求上游`);
|
|
54
|
+
if (!parsed) console.log(` 提示:opencode 请求将仅在本机重试,不再走 peer/broadband 组员中继`);
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
package/src/cli/help.js
CHANGED
|
@@ -43,6 +43,7 @@ Usage:
|
|
|
43
43
|
mslxdff -autostart status 查看自启状态
|
|
44
44
|
mslxdff -chat ["prompt"] chat REPL(mimo-v2.5-free 优先/big-pickle 兜底,自然语言转命令,模糊匹配由模型完成,历史持久化,超长自动压缩,仅拦 -uninstall,daemon 重启不影响)
|
|
45
45
|
mslxdff -resetban [ip] clear join-failure bans (all, or one ip)
|
|
46
|
+
mslxdff -use-group [on|off] opencode 供应商本机失败时是否走组员网络(默认 on;off 则仅本机,MSLXDFF_USE_GROUP 环境变量可覆盖)
|
|
46
47
|
mslxdff -help show this help
|
|
47
48
|
|
|
48
49
|
Environment:
|
|
@@ -62,6 +63,7 @@ Environment:
|
|
|
62
63
|
MSLXDFF_BAN_THRESHOLD failed joins before an ip is banned (default 5)
|
|
63
64
|
MSLXDFF_BAN_WINDOW_MS ban duration after too many failures (default 48h)
|
|
64
65
|
MSLXDFF_HEDGE_DELAY_MS hedge peer race when local stream first chunk slow (default 1000, 0/off to disable)
|
|
66
|
+
MSLXDFF_USE_GROUP opencode 组员中继开关(默认 on;0/off/false 关闭后 opencode 仅本机,不走 peer/broadband)
|
|
65
67
|
MSLXDFF_AUTO_UPDATE auto-update: hourly by default, 0/off/false to disable, 1/true or ms
|
|
66
68
|
MSLXDFF_AUTO_UPDATE_MS same as above, explicit ms (overrides AUTO_UPDATE)
|
|
67
69
|
`);
|
package/src/cli/index.js
CHANGED
|
@@ -49,6 +49,8 @@ export async function run(args = process.argv.slice(2)) {
|
|
|
49
49
|
if (await handleLeaveGroup(args)) return;
|
|
50
50
|
if (await handleDelGroup(args)) return;
|
|
51
51
|
|
|
52
|
+
const { handleUseGroup } = await import("./commands/use-group.js");
|
|
53
|
+
if (await handleUseGroup(args)) return;
|
|
52
54
|
const { handlePort, handleDaemonFlag, handleBareRun } = await import("./commands/daemon.js");
|
|
53
55
|
if (await handlePort(args)) return;
|
|
54
56
|
if (await handleDaemonFlag(args, VERSION)) return;
|
package/src/state/facade.js
CHANGED
|
@@ -57,3 +57,4 @@ export {
|
|
|
57
57
|
export { loadPeers, savePeers, loadPeerErrors, savePeerErrors, loadPeerStats, savePeerStats } from "./schemas/peer.js";
|
|
58
58
|
export { loadGroups, loadGroupsJoined, saveGroupsJoined, loadBans, saveBans, saveGroups } from "./schemas/group.js";
|
|
59
59
|
export { loadTimezone, loadTimezoneState, saveTimezone, clearTimezone, getTimezoneEnv, DEFAULT_TZ, isValidTimezone } from "./schemas/timezone.js";
|
|
60
|
+
export { loadUseGroup, saveUseGroup, getEffectiveUseGroup, shouldUseGroupForModel, isUseGroupEnabled, getUseGroupEnv } from "./schemas/use-group.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
+
|
|
3
|
+
function parseBool(v) {
|
|
4
|
+
if (typeof v === "boolean") return v;
|
|
5
|
+
if (typeof v === "number") return v !== 0;
|
|
6
|
+
if (typeof v === "string") {
|
|
7
|
+
const s = v.trim().toLowerCase();
|
|
8
|
+
if (["0", "false", "off", "no", "disable", "disabled", "close", "closed"].includes(s)) return false;
|
|
9
|
+
if (["1", "true", "on", "yes", "enable", "enabled", "open"].includes(s)) return true;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function loadUseGroup({ file = defaultStateFile() } = {}) {
|
|
15
|
+
const raw = readState(file).useGroup;
|
|
16
|
+
const parsed = parseBool(raw);
|
|
17
|
+
return parsed === null ? true : parsed; // 默认开
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function saveUseGroup(value, { file = defaultStateFile() } = {}) {
|
|
21
|
+
const b = Boolean(value);
|
|
22
|
+
writeStateImmediate(file, { useGroup: b });
|
|
23
|
+
return b;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getUseGroupEnv() {
|
|
27
|
+
const raw = process.env.MSLXDFF_USE_GROUP;
|
|
28
|
+
if (raw === undefined || raw === null || raw === "") return null;
|
|
29
|
+
return parseBool(raw);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getEffectiveUseGroup({ file = defaultStateFile() } = {}) {
|
|
33
|
+
const env = getUseGroupEnv();
|
|
34
|
+
if (env !== null) return env;
|
|
35
|
+
return loadUseGroup({ file });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 仅对 opencode 供应商生效:opencode 的模型为裸 id 或 opencode/ 前缀
|
|
39
|
+
export function shouldUseGroupForModel(model, { file = defaultStateFile() } = {}) {
|
|
40
|
+
const m = String(model || "").trim();
|
|
41
|
+
if (!m) return getEffectiveUseGroup({ file });
|
|
42
|
+
// 带前缀:判断是否为 opencode
|
|
43
|
+
if (m.includes("/")) {
|
|
44
|
+
const head = m.split("/")[0].trim().toLowerCase();
|
|
45
|
+
if (head === "opencode" || head === "oc") {
|
|
46
|
+
return getEffectiveUseGroup({ file });
|
|
47
|
+
}
|
|
48
|
+
return true; // 其他供应商不受此开关限制
|
|
49
|
+
}
|
|
50
|
+
// 裸 id 视为 opencode
|
|
51
|
+
return getEffectiveUseGroup({ file });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isUseGroupEnabled({ file } = {}) {
|
|
55
|
+
return getEffectiveUseGroup({ file });
|
|
56
|
+
}
|