fogact 1.1.9 → 1.2.0
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/web-server.js +23 -0
- package/frontend/assets/market-ui.css +11 -84
- package/frontend/index.html +2 -2
- package/frontend/user/assets/DashboardLayout-DDkxHYFj.js +1 -1
- package/frontend/user/assets/Welcome-Dtfp6oER.js +1 -1
- package/frontend/user/assets/announcement-35mOnjRL.js +1 -1
- package/frontend/user/assets/index-Da98HOxL.js +2 -2
- package/frontend/user/index.html +4 -4
- package/lib/commands/restore.js +41 -38
- package/lib/commands/test.js +15 -21
- package/lib/index.js +20 -18
- package/lib/platforms/openclaw.js +4 -4
- package/lib/platforms/opencode.js +2 -2
- package/lib/services/activation-orchestrator.js +154 -118
- package/lib/services/backup-service.js +65 -13
- package/lib/services/fogact-api.js +28 -17
- package/lib/services/node-service.js +85 -14
- package/package.json +1 -1
|
@@ -2,43 +2,114 @@
|
|
|
2
2
|
|
|
3
3
|
const { testNode } = require("./fogact-api");
|
|
4
4
|
|
|
5
|
-
async function testNodes(nodes) {
|
|
5
|
+
async function testNodes(nodes, onProgress = null) {
|
|
6
6
|
const results = [];
|
|
7
7
|
|
|
8
8
|
for (const node of nodes) {
|
|
9
|
-
|
|
9
|
+
if (onProgress) onProgress(node, results.length, nodes.length);
|
|
10
|
+
const probes = [];
|
|
11
|
+
for (let index = 0; index < 3; index += 1) {
|
|
12
|
+
const result = await testNode(node.url);
|
|
13
|
+
probes.push(result);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const availableProbes = probes.filter((probe) => probe.available);
|
|
17
|
+
const latencies = availableProbes.map((probe) => probe.latency);
|
|
18
|
+
const avgLatency = latencies.length
|
|
19
|
+
? Math.round(latencies.reduce((sum, value) => sum + value, 0) / latencies.length)
|
|
20
|
+
: -1;
|
|
21
|
+
const latencyStdDev = latencies.length
|
|
22
|
+
? Math.round(Math.sqrt(latencies.reduce((sum, value) => sum + Math.pow(value - avgLatency, 2), 0) / latencies.length))
|
|
23
|
+
: 0;
|
|
24
|
+
const successRate = availableProbes.length / probes.length;
|
|
25
|
+
const available = successRate > 0 && avgLatency >= 0;
|
|
26
|
+
|
|
10
27
|
results.push({
|
|
11
28
|
...node,
|
|
12
|
-
|
|
29
|
+
available,
|
|
30
|
+
reachable: available,
|
|
31
|
+
latency: avgLatency,
|
|
32
|
+
avgLatency,
|
|
33
|
+
latencyStdDev,
|
|
34
|
+
successRate,
|
|
35
|
+
score: scoreNode({ available, avgLatency, latencyStdDev, successRate }),
|
|
36
|
+
error: available ? undefined : probes.find((probe) => probe.error)?.error || "节点不可达",
|
|
13
37
|
});
|
|
14
38
|
}
|
|
15
39
|
|
|
16
40
|
return results;
|
|
17
41
|
}
|
|
18
42
|
|
|
19
|
-
function
|
|
20
|
-
|
|
43
|
+
function scoreNode(result) {
|
|
44
|
+
if (!result.available) return 0;
|
|
45
|
+
const latencyScore = Math.max(0, 100 - Math.round(result.avgLatency / 4));
|
|
46
|
+
const stabilityScore = Math.max(0, 100 - result.latencyStdDev * 2);
|
|
47
|
+
const reliabilityScore = Math.round((result.successRate || 0) * 100);
|
|
48
|
+
return Math.round(latencyScore * 0.7 + stabilityScore * 0.2 + reliabilityScore * 0.1);
|
|
49
|
+
}
|
|
21
50
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
function getResultLatency(result) {
|
|
52
|
+
return typeof result.avgLatency === "number" && result.avgLatency >= 0
|
|
53
|
+
? result.avgLatency
|
|
54
|
+
: result.latency;
|
|
55
|
+
}
|
|
25
56
|
|
|
26
|
-
|
|
57
|
+
function getResultScore(result) {
|
|
58
|
+
return typeof result.score === "number"
|
|
59
|
+
? result.score
|
|
60
|
+
: scoreNode({
|
|
61
|
+
available: result.available,
|
|
62
|
+
avgLatency: getResultLatency(result),
|
|
63
|
+
latencyStdDev: result.latencyStdDev || 0,
|
|
64
|
+
successRate: result.successRate || (result.available ? 1 : 0),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
27
67
|
|
|
68
|
+
function selectBestNode(testResults) {
|
|
69
|
+
const available = testResults.filter((result) => result.available);
|
|
70
|
+
if (available.length === 0) return null;
|
|
71
|
+
available.sort((left, right) => getResultScore(right) - getResultScore(left) || getResultLatency(left) - getResultLatency(right));
|
|
28
72
|
return available[0];
|
|
29
73
|
}
|
|
30
74
|
|
|
75
|
+
function latencyLabel(latency) {
|
|
76
|
+
if (latency <= 50) return `${latency}ms`;
|
|
77
|
+
if (latency <= 100) return `${latency}ms`;
|
|
78
|
+
if (latency <= 300) return `${latency}ms`;
|
|
79
|
+
return `${latency}ms`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function stabilityLabel(stdDev) {
|
|
83
|
+
if (stdDev <= 5) return "稳定";
|
|
84
|
+
if (stdDev <= 15) return "良好";
|
|
85
|
+
if (stdDev <= 30) return "一般";
|
|
86
|
+
return "波动";
|
|
87
|
+
}
|
|
88
|
+
|
|
31
89
|
function formatNodeResults(results) {
|
|
90
|
+
const sorted = [...results].sort((left, right) => right.score - left.score || left.avgLatency - right.avgLatency);
|
|
91
|
+
const best = sorted.find((result) => result.available);
|
|
32
92
|
const lines = [];
|
|
33
93
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const name = result.name || result.url;
|
|
94
|
+
lines.push(" 节点测试结果");
|
|
95
|
+
lines.push(" ───────────────────────────────────────────────────");
|
|
96
|
+
lines.push("");
|
|
38
97
|
|
|
39
|
-
|
|
98
|
+
for (const result of sorted) {
|
|
99
|
+
const mark = result.available ? "✓" : "✗";
|
|
100
|
+
const name = String(result.name || result.url).padEnd(10);
|
|
101
|
+
if (!result.available) {
|
|
102
|
+
lines.push(` ${mark} ${name} 不可达`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const bestMark = best && best.url === result.url ? " ★ 最优" : "";
|
|
106
|
+
lines.push(` ${mark} ${name} ${latencyLabel(result.avgLatency)} (±${result.latencyStdDev}ms) ${stabilityLabel(result.latencyStdDev)} ${result.score}分${bestMark}`);
|
|
40
107
|
}
|
|
41
108
|
|
|
109
|
+
const availableCount = results.filter((result) => result.available).length;
|
|
110
|
+
lines.push("");
|
|
111
|
+
lines.push(" ───────────────────────────────────────────────────");
|
|
112
|
+
lines.push(` 测试完成,共 ${results.length} 个节点,${availableCount} 个可用`);
|
|
42
113
|
return lines.join("\n");
|
|
43
114
|
}
|
|
44
115
|
|