mslxdff 0.1.170 → 0.1.171
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/docs/cli_help_mini.md +143 -0
- package/package.json +1 -1
- package/src/anthropic/count-tokens.js +39 -0
- package/src/anthropic/translate.js +20 -41
- 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 +131 -131
- 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 +133 -133
- package/src/cli/commands/provider/models.js +145 -145
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/sync.js +310 -310
- package/src/cli/status.js +279 -279
- package/src/daemon.js +112 -112
- 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/providers/AGENTS.md +49 -0
- 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/concurrency.js +34 -0
- package/src/providers/codearts/index.js +11 -3
- 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/payload.js +4 -2
- 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 -200
- 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 +327 -327
- package/src/providers/qwenwork/payload.js +144 -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/raccoon/chat.js +10 -5
- package/src/providers/raccoon/const.js +4 -4
- package/src/providers/registry.js +79 -79
- package/src/providers/workbuddy/chat.js +248 -248
- package/src/providers/workbuddy/payload.js +16 -7
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/providers/zcode/chat.js +7 -0
- package/src/reasoning.js +32 -32
- package/src/responses/translate.js +4 -0
- package/src/routes/AGENTS.md +37 -0
- package/src/routes/chat/exhausted-handler.js +5 -0
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +294 -291
- package/src/routes/chat/via-route-handler.js +146 -146
- package/src/routes/hedge.js +255 -255
- package/src/routes/messages-route.js +1 -1
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +273 -273
- package/src/routes/stream-scan.js +47 -21
- package/src/routes/stream.js +385 -385
- package/src/runtime/bootstrap.js +50 -50
- package/src/runtime/provider-gate.js +36 -36
- package/src/runtime/providers-setup.js +165 -165
- package/src/server.js +69 -69
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- package/src/talk-full.js +1 -0
- package/src/talk-log.js +3 -2
- package/src/thinking-effort.js +67 -0
- 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/convert.js +6 -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-responses.js +5 -0
- package/src/upstream.js +289 -289
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
// ADR-0015 轮转调度:每 tick 探 1 家供应商(direct + 逐 peer relay),EMA 合并旧值后落 via-routes.json
|
|
2
|
-
// 复用 bench/via-routes.js 的表格式与读写;探针写 provider:<id> 键,getViaRoute 精确键优先、provider 级回退。
|
|
3
|
-
import { directProbe, relayViaProbe } from "./probe.js";
|
|
4
|
-
import { classifyProvider, emaMerge } from "../providers/classify.js";
|
|
5
|
-
import { saveViaRoutes, loadViaRoutes } from "../bench/via-routes.js";
|
|
6
|
-
import { errMsg } from "../cli/util.js";
|
|
7
|
-
|
|
8
|
-
export const PROBE_DELAY_MS = Number(process.env.MSLXDFF_BENCH_DELAY_MS || 120) || 0;
|
|
9
|
-
|
|
10
|
-
// 从 providerConfigs 收集探针目标:local-only(workbuddy/cline系)/quota-pool(opencode) 排除,无 baseUrl 跳过
|
|
11
|
-
export function probeTargetsFromState({ loadProviderConfigs, loadProviderKeys, loadProviderBaseUrl } = {}) {
|
|
12
|
-
const out = [];
|
|
13
|
-
const ids = new Set(Object.keys(loadProviderConfigs?.() || {}));
|
|
14
|
-
for (const id of ids) {
|
|
15
|
-
if (classifyProvider(id) !== "latency-compare") continue;
|
|
16
|
-
const cfg = (loadProviderConfigs?.() || {})[id] || {};
|
|
17
|
-
const baseUrl = String(loadProviderBaseUrl?.(id) || cfg.baseUrl || "").replace(/\/+$/, "");
|
|
18
|
-
if (!baseUrl) continue;
|
|
19
|
-
out.push({ id, baseUrl, modelsPath: cfg.modelsPath || "/models", key: (loadProviderKeys?.(id) || [])[0] || "" });
|
|
20
|
-
}
|
|
21
|
-
return out;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function nextCursor(cursor, total) {
|
|
25
|
-
if (!Number.isInteger(total) || total <= 0) return 0;
|
|
26
|
-
const c = Number.isInteger(cursor) ? cursor : 0;
|
|
27
|
-
return c + 1 >= total ? 0 : c + 1;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function peerLabel(p) {
|
|
31
|
-
const raw = String(p?.url || "");
|
|
32
|
-
if (!raw) return "";
|
|
33
|
-
if (raw.includes("://")) {
|
|
34
|
-
try { const u = new URL(raw); return `${u.hostname}${u.port ? `:${u.port}` : ""}`; } catch { return raw.slice(-16); }
|
|
35
|
-
}
|
|
36
|
-
return raw;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 单 tick:探 targets[cursor] 一家;返回 { probed, skipped }
|
|
40
|
-
export async function rotateTick({
|
|
41
|
-
targets,
|
|
42
|
-
cursor = 0,
|
|
43
|
-
peers,
|
|
44
|
-
timeoutMs = 5000,
|
|
45
|
-
delayMs = PROBE_DELAY_MS,
|
|
46
|
-
evt = () => {},
|
|
47
|
-
fetchImpl,
|
|
48
|
-
clock = Date.now,
|
|
49
|
-
sampleMs,
|
|
50
|
-
file,
|
|
51
|
-
} = {}) {
|
|
52
|
-
const list = Array.isArray(targets) ? targets : [];
|
|
53
|
-
if (!list.length) return { probed: null, skipped: true };
|
|
54
|
-
const idx = cursor % list.length;
|
|
55
|
-
const target = list[idx];
|
|
56
|
-
const peerList = (peers?.all?.() || []).filter((p) => p?.url && !String(p.url).startsWith("relay://"));
|
|
57
|
-
if (!peerList.length) {
|
|
58
|
-
evt("upstream-probe-skip", { provider: target.id, reason: "no peers" });
|
|
59
|
-
return { probed: null, skipped: true };
|
|
60
|
-
}
|
|
61
|
-
const authHeader = target.key ? `Bearer ${target.key}` : "";
|
|
62
|
-
const direct = await directProbe({ baseUrl: target.baseUrl, modelsPath: target.modelsPath, key: target.key, timeoutMs, fetchImpl, clock, sampleMs });
|
|
63
|
-
const via = {};
|
|
64
|
-
for (const p of peerList) {
|
|
65
|
-
const label = peerLabel(p) || String(p.url);
|
|
66
|
-
const r = await relayViaProbe({ peerUrl: p.url, peerToken: p.token || "", targetUrl: `${target.baseUrl}${target.modelsPath}`, authHeader, timeoutMs, fetchImpl, clock, sampleMs });
|
|
67
|
-
via[label] = { ok: r.ok, ttfbMs: r.ok ? r.ttfbMs : null, totalMs: r.ok ? r.ttfbMs : null, label: r.ok ? null : r.label };
|
|
68
|
-
if (delayMs) await new Promise((res) => setTimeout(res, delayMs));
|
|
69
|
-
}
|
|
70
|
-
const prev = loadViaRoutes(file).routes?.[`provider:${target.id}`] || null;
|
|
71
|
-
const fresh = prev?.at && Date.now() - Date.parse(prev.at) < 10 * 60_000 ? prev : null;
|
|
72
|
-
const merged = mergeEntry({ prev: fresh, direct, via });
|
|
73
|
-
const results = [{ model: `provider:${target.id}`, ...merged, provider: target.id }];
|
|
74
|
-
try {
|
|
75
|
-
saveViaRoutes(results, { file, meta: { probe: true } });
|
|
76
|
-
} catch (e) {
|
|
77
|
-
evt("upstream-probe-error", { provider: target.id, error: errMsg(e).slice(0, 120) });
|
|
78
|
-
return { probed: target.id, skipped: false, error: errMsg(e) };
|
|
79
|
-
}
|
|
80
|
-
evt("upstream-probe", { provider: target.id, direct: direct.ok ? direct.ttfbMs : null, best: merged.best, peers: Object.keys(via).length });
|
|
81
|
-
return { probed: target.id, skipped: false };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// best 计算 + EMA 合并(相对 direct:via 胜出记负 delta)
|
|
85
|
-
function mergeEntry({ prev, direct, via }) {
|
|
86
|
-
const ema = (p, r) => emaMerge(p, r?.ok ? r.ttfbMs : null);
|
|
87
|
-
const directOut = {
|
|
88
|
-
ok: Boolean(direct?.ok),
|
|
89
|
-
ttfbMs: direct?.ok ? ema(prev?.direct?.ttfbMs, direct) : null,
|
|
90
|
-
totalMs: direct?.ok ? ema(prev?.direct?.totalMs ?? prev?.direct?.ttfbMs, direct) : null,
|
|
91
|
-
label: direct?.ok ? null : (direct?.label || "offline"),
|
|
92
|
-
error: direct?.ok ? null : (direct?.label || null),
|
|
93
|
-
};
|
|
94
|
-
const viaOut = {};
|
|
95
|
-
for (const [k, v] of Object.entries(via || {})) {
|
|
96
|
-
viaOut[k] = v.ok
|
|
97
|
-
? { ok: true, ttfbMs: ema(prev?.via?.[k]?.ttfbMs, v), totalMs: ema(prev?.via?.[k]?.totalMs ?? prev?.via?.[k]?.ttfbMs, v) }
|
|
98
|
-
: { ok: false, ttfbMs: v.ttfbMs ?? null, totalMs: v.totalMs ?? null, label: v.label || "offline" };
|
|
99
|
-
}
|
|
100
|
-
const directMs = directOut.ok ? (directOut.ttfbMs ?? directOut.totalMs) : Infinity;
|
|
101
|
-
let best = "direct";
|
|
102
|
-
let bestMs = directMs;
|
|
103
|
-
for (const [k, v] of Object.entries(viaOut)) {
|
|
104
|
-
if (!v.ok) continue;
|
|
105
|
-
const t = v.ttfbMs ?? v.totalMs;
|
|
106
|
-
if (Number.isFinite(t) && t < bestMs) { bestMs = t; best = `via:${k}`; }
|
|
107
|
-
}
|
|
108
|
-
const deltaMs = best.startsWith("via:") && Number.isFinite(directMs) ? Math.round(bestMs - directMs) : null;
|
|
109
|
-
return { best, direct: directOut, via: viaOut, deltaMs };
|
|
110
|
-
}
|
|
1
|
+
// ADR-0015 轮转调度:每 tick 探 1 家供应商(direct + 逐 peer relay),EMA 合并旧值后落 via-routes.json
|
|
2
|
+
// 复用 bench/via-routes.js 的表格式与读写;探针写 provider:<id> 键,getViaRoute 精确键优先、provider 级回退。
|
|
3
|
+
import { directProbe, relayViaProbe } from "./probe.js";
|
|
4
|
+
import { classifyProvider, emaMerge } from "../providers/classify.js";
|
|
5
|
+
import { saveViaRoutes, loadViaRoutes } from "../bench/via-routes.js";
|
|
6
|
+
import { errMsg } from "../cli/util.js";
|
|
7
|
+
|
|
8
|
+
export const PROBE_DELAY_MS = Number(process.env.MSLXDFF_BENCH_DELAY_MS || 120) || 0;
|
|
9
|
+
|
|
10
|
+
// 从 providerConfigs 收集探针目标:local-only(workbuddy/cline系)/quota-pool(opencode) 排除,无 baseUrl 跳过
|
|
11
|
+
export function probeTargetsFromState({ loadProviderConfigs, loadProviderKeys, loadProviderBaseUrl } = {}) {
|
|
12
|
+
const out = [];
|
|
13
|
+
const ids = new Set(Object.keys(loadProviderConfigs?.() || {}));
|
|
14
|
+
for (const id of ids) {
|
|
15
|
+
if (classifyProvider(id) !== "latency-compare") continue;
|
|
16
|
+
const cfg = (loadProviderConfigs?.() || {})[id] || {};
|
|
17
|
+
const baseUrl = String(loadProviderBaseUrl?.(id) || cfg.baseUrl || "").replace(/\/+$/, "");
|
|
18
|
+
if (!baseUrl) continue;
|
|
19
|
+
out.push({ id, baseUrl, modelsPath: cfg.modelsPath || "/models", key: (loadProviderKeys?.(id) || [])[0] || "" });
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function nextCursor(cursor, total) {
|
|
25
|
+
if (!Number.isInteger(total) || total <= 0) return 0;
|
|
26
|
+
const c = Number.isInteger(cursor) ? cursor : 0;
|
|
27
|
+
return c + 1 >= total ? 0 : c + 1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function peerLabel(p) {
|
|
31
|
+
const raw = String(p?.url || "");
|
|
32
|
+
if (!raw) return "";
|
|
33
|
+
if (raw.includes("://")) {
|
|
34
|
+
try { const u = new URL(raw); return `${u.hostname}${u.port ? `:${u.port}` : ""}`; } catch { return raw.slice(-16); }
|
|
35
|
+
}
|
|
36
|
+
return raw;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 单 tick:探 targets[cursor] 一家;返回 { probed, skipped }
|
|
40
|
+
export async function rotateTick({
|
|
41
|
+
targets,
|
|
42
|
+
cursor = 0,
|
|
43
|
+
peers,
|
|
44
|
+
timeoutMs = 5000,
|
|
45
|
+
delayMs = PROBE_DELAY_MS,
|
|
46
|
+
evt = () => {},
|
|
47
|
+
fetchImpl,
|
|
48
|
+
clock = Date.now,
|
|
49
|
+
sampleMs,
|
|
50
|
+
file,
|
|
51
|
+
} = {}) {
|
|
52
|
+
const list = Array.isArray(targets) ? targets : [];
|
|
53
|
+
if (!list.length) return { probed: null, skipped: true };
|
|
54
|
+
const idx = cursor % list.length;
|
|
55
|
+
const target = list[idx];
|
|
56
|
+
const peerList = (peers?.all?.() || []).filter((p) => p?.url && !String(p.url).startsWith("relay://"));
|
|
57
|
+
if (!peerList.length) {
|
|
58
|
+
evt("upstream-probe-skip", { provider: target.id, reason: "no peers" });
|
|
59
|
+
return { probed: null, skipped: true };
|
|
60
|
+
}
|
|
61
|
+
const authHeader = target.key ? `Bearer ${target.key}` : "";
|
|
62
|
+
const direct = await directProbe({ baseUrl: target.baseUrl, modelsPath: target.modelsPath, key: target.key, timeoutMs, fetchImpl, clock, sampleMs });
|
|
63
|
+
const via = {};
|
|
64
|
+
for (const p of peerList) {
|
|
65
|
+
const label = peerLabel(p) || String(p.url);
|
|
66
|
+
const r = await relayViaProbe({ peerUrl: p.url, peerToken: p.token || "", targetUrl: `${target.baseUrl}${target.modelsPath}`, authHeader, timeoutMs, fetchImpl, clock, sampleMs });
|
|
67
|
+
via[label] = { ok: r.ok, ttfbMs: r.ok ? r.ttfbMs : null, totalMs: r.ok ? r.ttfbMs : null, label: r.ok ? null : r.label };
|
|
68
|
+
if (delayMs) await new Promise((res) => setTimeout(res, delayMs));
|
|
69
|
+
}
|
|
70
|
+
const prev = loadViaRoutes(file).routes?.[`provider:${target.id}`] || null;
|
|
71
|
+
const fresh = prev?.at && Date.now() - Date.parse(prev.at) < 10 * 60_000 ? prev : null;
|
|
72
|
+
const merged = mergeEntry({ prev: fresh, direct, via });
|
|
73
|
+
const results = [{ model: `provider:${target.id}`, ...merged, provider: target.id }];
|
|
74
|
+
try {
|
|
75
|
+
saveViaRoutes(results, { file, meta: { probe: true } });
|
|
76
|
+
} catch (e) {
|
|
77
|
+
evt("upstream-probe-error", { provider: target.id, error: errMsg(e).slice(0, 120) });
|
|
78
|
+
return { probed: target.id, skipped: false, error: errMsg(e) };
|
|
79
|
+
}
|
|
80
|
+
evt("upstream-probe", { provider: target.id, direct: direct.ok ? direct.ttfbMs : null, best: merged.best, peers: Object.keys(via).length });
|
|
81
|
+
return { probed: target.id, skipped: false };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// best 计算 + EMA 合并(相对 direct:via 胜出记负 delta)
|
|
85
|
+
function mergeEntry({ prev, direct, via }) {
|
|
86
|
+
const ema = (p, r) => emaMerge(p, r?.ok ? r.ttfbMs : null);
|
|
87
|
+
const directOut = {
|
|
88
|
+
ok: Boolean(direct?.ok),
|
|
89
|
+
ttfbMs: direct?.ok ? ema(prev?.direct?.ttfbMs, direct) : null,
|
|
90
|
+
totalMs: direct?.ok ? ema(prev?.direct?.totalMs ?? prev?.direct?.ttfbMs, direct) : null,
|
|
91
|
+
label: direct?.ok ? null : (direct?.label || "offline"),
|
|
92
|
+
error: direct?.ok ? null : (direct?.label || null),
|
|
93
|
+
};
|
|
94
|
+
const viaOut = {};
|
|
95
|
+
for (const [k, v] of Object.entries(via || {})) {
|
|
96
|
+
viaOut[k] = v.ok
|
|
97
|
+
? { ok: true, ttfbMs: ema(prev?.via?.[k]?.ttfbMs, v), totalMs: ema(prev?.via?.[k]?.totalMs ?? prev?.via?.[k]?.ttfbMs, v) }
|
|
98
|
+
: { ok: false, ttfbMs: v.ttfbMs ?? null, totalMs: v.totalMs ?? null, label: v.label || "offline" };
|
|
99
|
+
}
|
|
100
|
+
const directMs = directOut.ok ? (directOut.ttfbMs ?? directOut.totalMs) : Infinity;
|
|
101
|
+
let best = "direct";
|
|
102
|
+
let bestMs = directMs;
|
|
103
|
+
for (const [k, v] of Object.entries(viaOut)) {
|
|
104
|
+
if (!v.ok) continue;
|
|
105
|
+
const t = v.ttfbMs ?? v.totalMs;
|
|
106
|
+
if (Number.isFinite(t) && t < bestMs) { bestMs = t; best = `via:${k}`; }
|
|
107
|
+
}
|
|
108
|
+
const deltaMs = best.startsWith("via:") && Number.isFinite(directMs) ? Math.round(bestMs - directMs) : null;
|
|
109
|
+
return { best, direct: directOut, via: viaOut, deltaMs };
|
|
110
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
// ADR-0015 daemon 装配:60s 节拍轮转探针;0=完全关闭
|
|
2
|
-
import { probeTargetsFromState, rotateTick, nextCursor } from "./rotate.js";
|
|
3
|
-
import { loadProviderConfigs, loadProviderKeys, loadProviderBaseUrl } from "../state.js";
|
|
4
|
-
import { loadPeers } from "../state.js";
|
|
5
|
-
|
|
6
|
-
export function upstreamProbeIntervalMs() {
|
|
7
|
-
const n = Number(process.env.MSLXDFF_UPSTREAM_PROBE_MS);
|
|
8
|
-
return Number.isInteger(n) && n >= 0 ? n : 60_000;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function startUpstreamProbe({ evt = () => {}, peers, file, delayMs } = {}) {
|
|
12
|
-
const interval = upstreamProbeIntervalMs();
|
|
13
|
-
if (interval === 0) return null;
|
|
14
|
-
let cursor = 0;
|
|
15
|
-
let busy = false;
|
|
16
|
-
const loadTargets = () => {
|
|
17
|
-
try {
|
|
18
|
-
return probeTargetsFromState({
|
|
19
|
-
loadProviderConfigs: () => loadProviderConfigs({}),
|
|
20
|
-
loadProviderKeys: (id) => loadProviderKeys(id, {}),
|
|
21
|
-
loadProviderBaseUrl: (id) => loadProviderBaseUrl(id, {}),
|
|
22
|
-
});
|
|
23
|
-
} catch {
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const tick = async () => {
|
|
28
|
-
if (busy) return;
|
|
29
|
-
busy = true;
|
|
30
|
-
try {
|
|
31
|
-
const targets = loadTargets();
|
|
32
|
-
if (!targets.length) return;
|
|
33
|
-
const out = await rotateTick({ targets, cursor, peers, evt, file, delayMs });
|
|
34
|
-
if (out.probed != null) cursor = nextCursor(cursor, targets.length);
|
|
35
|
-
} catch {
|
|
36
|
-
// 探针永不影响主链路
|
|
37
|
-
} finally {
|
|
38
|
-
busy = false;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
void tick();
|
|
42
|
-
const timer = setInterval(tick, interval);
|
|
43
|
-
timer.unref?.();
|
|
44
|
-
return { stop: () => clearInterval(timer), interval, tick };
|
|
45
|
-
}
|
|
1
|
+
// ADR-0015 daemon 装配:60s 节拍轮转探针;0=完全关闭
|
|
2
|
+
import { probeTargetsFromState, rotateTick, nextCursor } from "./rotate.js";
|
|
3
|
+
import { loadProviderConfigs, loadProviderKeys, loadProviderBaseUrl } from "../state.js";
|
|
4
|
+
import { loadPeers } from "../state.js";
|
|
5
|
+
|
|
6
|
+
export function upstreamProbeIntervalMs() {
|
|
7
|
+
const n = Number(process.env.MSLXDFF_UPSTREAM_PROBE_MS);
|
|
8
|
+
return Number.isInteger(n) && n >= 0 ? n : 60_000;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function startUpstreamProbe({ evt = () => {}, peers, file, delayMs } = {}) {
|
|
12
|
+
const interval = upstreamProbeIntervalMs();
|
|
13
|
+
if (interval === 0) return null;
|
|
14
|
+
let cursor = 0;
|
|
15
|
+
let busy = false;
|
|
16
|
+
const loadTargets = () => {
|
|
17
|
+
try {
|
|
18
|
+
return probeTargetsFromState({
|
|
19
|
+
loadProviderConfigs: () => loadProviderConfigs({}),
|
|
20
|
+
loadProviderKeys: (id) => loadProviderKeys(id, {}),
|
|
21
|
+
loadProviderBaseUrl: (id) => loadProviderBaseUrl(id, {}),
|
|
22
|
+
});
|
|
23
|
+
} catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const tick = async () => {
|
|
28
|
+
if (busy) return;
|
|
29
|
+
busy = true;
|
|
30
|
+
try {
|
|
31
|
+
const targets = loadTargets();
|
|
32
|
+
if (!targets.length) return;
|
|
33
|
+
const out = await rotateTick({ targets, cursor, peers, evt, file, delayMs });
|
|
34
|
+
if (out.probed != null) cursor = nextCursor(cursor, targets.length);
|
|
35
|
+
} catch {
|
|
36
|
+
// 探针永不影响主链路
|
|
37
|
+
} finally {
|
|
38
|
+
busy = false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
void tick();
|
|
42
|
+
const timer = setInterval(tick, interval);
|
|
43
|
+
timer.unref?.();
|
|
44
|
+
return { stop: () => clearInterval(timer), interval, tick };
|
|
45
|
+
}
|
|
@@ -71,6 +71,11 @@ export function chatToResponsesBody(chatBody) {
|
|
|
71
71
|
// 流式意图透传:客户端要 SSE 就向上游要 SSE(reshapeResponsesSse 负责转回 chat SSE)。
|
|
72
72
|
// 写死 stream:false 是历史折衷(当时聚合 JSON 直回),已由完整 SSE 转换取代。
|
|
73
73
|
const out = { model: chatBody.model, input, stream: chatBody?.stream === true };
|
|
74
|
+
// 思考档位透传:responses 形状上游用 reasoning.effort(与 /v1/responses 入站同口径),
|
|
75
|
+
// 客户端声明不在此丢掉(change fix-thinking-effort-passthrough)。
|
|
76
|
+
if (typeof chatBody.reasoning_effort === "string" && chatBody.reasoning_effort.trim()) {
|
|
77
|
+
out.reasoning = { effort: chatBody.reasoning_effort.trim() };
|
|
78
|
+
}
|
|
74
79
|
if (system) out.instructions = system;
|
|
75
80
|
// responses 的 tools 形状为平铺 {type,name,description,parameters},而 chat 为 {type,function:{name,...}}
|
|
76
81
|
if (Array.isArray(chatBody.tools) && chatBody.tools.length) {
|