mslxdff 0.1.66 → 0.1.68
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 +1 -1
- package/src/bench/probe.js +68 -0
- package/src/bench/report.js +56 -0
- package/src/bench/runner.js +74 -0
- package/src/chat/cooling.js +99 -0
- package/src/chat/direct.js +57 -0
- package/src/chat/gateway.js +148 -0
- package/src/chat/orchestrator.js +218 -0
- package/src/chat/sse.js +69 -0
- package/src/chat/upstream.js +59 -501
- package/src/cli/bootstrap.js +1 -408
- package/src/cli/commands/provider/bench.js +140 -0
- package/src/cli/commands/provider/index.js +2 -0
- package/src/cli/provider-row.js +73 -0
- package/src/cli/status.js +3 -52
- package/src/metrics.js +63 -0
- package/src/providers/dispatcher.js +18 -6
- package/src/providers/generic.js +2 -0
- package/src/providers/openrouter.js +16 -72
- package/src/providers/workbuddy/auth.js +175 -0
- package/src/providers/workbuddy/balance.js +84 -0
- package/src/providers/workbuddy/chat.js +310 -0
- package/src/providers/workbuddy/index.js +263 -0
- package/src/providers/workbuddy/models.js +111 -0
- package/src/providers/workbuddy/rotation-log.js +54 -0
- package/src/providers/workbuddy.js +2 -652
- package/src/routes/chat/broadband-handler.js +25 -46
- package/src/routes/chat/exhausted-handler.js +2 -2
- package/src/routes/chat/hedge-handler.js +65 -83
- package/src/routes/chat/local-handler.js +32 -61
- package/src/routes/chat/peer-handler.js +32 -23
- package/src/routes/chat/relay-pipeline.js +151 -0
- package/src/runtime/bootstrap.js +408 -0
- package/src/state/memory.js +2 -21
- package/src/state/merge.js +26 -0
- package/src/state/provider-config.js +143 -0
- package/src/state/schemas/provider.js +83 -133
- package/src/state/store.js +2 -28
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync, readFileSync, writeFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
function defaultDirs() {
|
|
5
|
+
const dirs = new Set();
|
|
6
|
+
try {
|
|
7
|
+
const sf = process.env.MSLXDFF_STATE_FILE;
|
|
8
|
+
if (sf) {
|
|
9
|
+
const cut = Math.max(sf.lastIndexOf("/"), sf.lastIndexOf("\\"));
|
|
10
|
+
if (cut > 0) dirs.add(sf.slice(0, cut));
|
|
11
|
+
}
|
|
12
|
+
} catch {}
|
|
13
|
+
const envDir = process.env.MSLXDFF_DAEMON_DIR || process.env.MSLXDFF_LOG_DIR;
|
|
14
|
+
if (envDir) dirs.add(envDir);
|
|
15
|
+
dirs.add(process.cwd());
|
|
16
|
+
dirs.add(join(process.cwd(), "logs"));
|
|
17
|
+
return [...dirs];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function appendRotationLog({ uid, model, totalMs, balanceHit, error, clock = Date.now, fs: fsOverride, dirs: dirsOverride, maxBytes = 1024 * 1024 } = {}) {
|
|
21
|
+
// 兼容旧调用:appendRotationLog({uid,model,totalMs,balanceHit,error}) 形式,clock/fs 可选
|
|
22
|
+
const useFs = fsOverride || { appendFileSync, mkdirSync, readFileSync, writeFileSync, statSync, join };
|
|
23
|
+
const useDirs = dirsOverride || defaultDirs();
|
|
24
|
+
try {
|
|
25
|
+
const line = `${new Date(clock()).toISOString()} uid=${uid} model=${model || "-"} totalMs=${totalMs} balanceHit=${balanceHit ? 1 : 0}${error ? ` error=${String(error).slice(0, 120)}` : ""}\n`;
|
|
26
|
+
for (const dir of useDirs) {
|
|
27
|
+
try {
|
|
28
|
+
useFs.mkdirSync(dir, { recursive: true });
|
|
29
|
+
const file = useFs.join ? useFs.join(dir, "workbuddy-rotation.log") : join(dir, "workbuddy-rotation.log");
|
|
30
|
+
useFs.appendFileSync(file, line);
|
|
31
|
+
try {
|
|
32
|
+
const st = useFs.statSync(file);
|
|
33
|
+
if (st.size > maxBytes) {
|
|
34
|
+
const content = useFs.readFileSync(file, "utf8");
|
|
35
|
+
useFs.writeFileSync(file, content.slice(-512 * 1024));
|
|
36
|
+
}
|
|
37
|
+
} catch {}
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createRotationLogger({ fs, clock = Date.now, dirs, maxBytes } = {}) {
|
|
44
|
+
return {
|
|
45
|
+
append(opts) {
|
|
46
|
+
return appendRotationLog({ ...opts, clock, fs, dirs, maxBytes });
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 供旧代码直接调用的默认 logger
|
|
52
|
+
export const defaultLogger = {
|
|
53
|
+
append: (opts) => appendRotationLog(opts),
|
|
54
|
+
};
|