@useorgx/openclaw-plugin 0.4.0 → 0.4.3
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 +4 -0
- package/dashboard/dist/assets/BqukHQH-.js +8 -0
- package/dashboard/dist/assets/{motion-x9c01cgK.js → CE5pVdev.js} +1 -1
- package/dashboard/dist/assets/Cpr7n8fE.js +1 -0
- package/dashboard/dist/assets/Nip3CrNC.js +1 -0
- package/dashboard/dist/assets/TN5wE36J.js +1 -0
- package/dashboard/dist/assets/X6IcjS74.js +212 -0
- package/dashboard/dist/assets/jyFhCND-.css +1 -0
- package/dashboard/dist/index.html +9 -6
- package/dist/adapters/outbox.d.ts +0 -1
- package/dist/adapters/outbox.js +0 -1
- package/dist/agent-context-store.d.ts +0 -1
- package/dist/agent-context-store.js +0 -1
- package/dist/agent-run-store.d.ts +0 -1
- package/dist/agent-run-store.js +0 -1
- package/dist/api.d.ts +0 -1
- package/dist/api.js +0 -1
- package/dist/auth-store.d.ts +0 -1
- package/dist/auth-store.js +0 -1
- package/dist/byok-store.d.ts +0 -1
- package/dist/byok-store.js +181 -55
- package/dist/contracts/client.d.ts +0 -1
- package/dist/contracts/client.js +0 -1
- package/dist/contracts/types.d.ts +0 -1
- package/dist/contracts/types.js +0 -1
- package/dist/dashboard-api.d.ts +0 -1
- package/dist/dashboard-api.js +0 -1
- package/dist/fs-utils.d.ts +0 -1
- package/dist/fs-utils.js +0 -1
- package/dist/gateway-watchdog-runner.d.ts +1 -0
- package/dist/gateway-watchdog-runner.js +6 -0
- package/dist/gateway-watchdog.d.ts +11 -0
- package/dist/gateway-watchdog.js +221 -0
- package/dist/http-handler.d.ts +0 -1
- package/dist/http-handler.js +729 -79
- package/dist/index.d.ts +0 -1
- package/dist/index.js +7 -1
- package/dist/local-openclaw.d.ts +0 -1
- package/dist/local-openclaw.js +0 -1
- package/dist/openclaw-settings.d.ts +17 -0
- package/dist/openclaw-settings.js +118 -0
- package/dist/outbox.d.ts +0 -1
- package/dist/outbox.js +0 -1
- package/dist/paths.d.ts +0 -1
- package/dist/paths.js +0 -1
- package/dist/reporting/outbox-replay.d.ts +0 -1
- package/dist/reporting/outbox-replay.js +0 -1
- package/dist/reporting/rollups.d.ts +0 -1
- package/dist/reporting/rollups.js +0 -1
- package/dist/runtime-instance-store.d.ts +0 -1
- package/dist/runtime-instance-store.js +0 -1
- package/dist/snapshot-store.d.ts +0 -1
- package/dist/snapshot-store.js +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/package.json +2 -2
- package/dashboard/dist/assets/MissionControlView-DVNfDWKZ.js +0 -1
- package/dashboard/dist/assets/SessionInspector-BaqnAys4.js +0 -1
- package/dashboard/dist/assets/index-B4Yix84X.js +0 -212
- package/dashboard/dist/assets/index-BWSvw1HR.css +0 -1
- package/dashboard/dist/assets/react-vendor-C2t2w4r2.js +0 -32
- package/dashboard/dist/assets/vendor-C-AHK0Ly.js +0 -9
- package/dist/adapters/outbox.d.ts.map +0 -1
- package/dist/adapters/outbox.js.map +0 -1
- package/dist/agent-context-store.d.ts.map +0 -1
- package/dist/agent-context-store.js.map +0 -1
- package/dist/agent-run-store.d.ts.map +0 -1
- package/dist/agent-run-store.js.map +0 -1
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js.map +0 -1
- package/dist/auth-store.d.ts.map +0 -1
- package/dist/auth-store.js.map +0 -1
- package/dist/byok-store.d.ts.map +0 -1
- package/dist/byok-store.js.map +0 -1
- package/dist/contracts/client.d.ts.map +0 -1
- package/dist/contracts/client.js.map +0 -1
- package/dist/contracts/types.d.ts.map +0 -1
- package/dist/contracts/types.js.map +0 -1
- package/dist/dashboard-api.d.ts.map +0 -1
- package/dist/dashboard-api.js.map +0 -1
- package/dist/fs-utils.d.ts.map +0 -1
- package/dist/fs-utils.js.map +0 -1
- package/dist/http-handler.d.ts.map +0 -1
- package/dist/http-handler.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/local-openclaw.d.ts.map +0 -1
- package/dist/local-openclaw.js.map +0 -1
- package/dist/mcp-apps/orgx-live.html +0 -690
- package/dist/outbox.d.ts.map +0 -1
- package/dist/outbox.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/reporting/outbox-replay.d.ts.map +0 -1
- package/dist/reporting/outbox-replay.js.map +0 -1
- package/dist/reporting/rollups.d.ts.map +0 -1
- package/dist/reporting/rollups.js.map +0 -1
- package/dist/runtime-instance-store.d.ts.map +0 -1
- package/dist/runtime-instance-store.js.map +0 -1
- package/dist/snapshot-store.d.ts.map +0 -1
- package/dist/snapshot-store.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dashboard/dist/assets/{tanstack-C-KIc3Wc.js → C-KIc3Wc.js} +0 -0
- /package/dashboard/dist/assets/{orgx-logo-Fm0FhtnV.png → Fm0FhtnV.png} +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { getOpenClawDir } from "./paths.js";
|
|
6
|
+
import { readOpenClawGatewayPort, readOpenClawSettingsSnapshot } from "./openclaw-settings.js";
|
|
7
|
+
const DEFAULT_MONITOR_INTERVAL_MS = 30_000;
|
|
8
|
+
const DEFAULT_FAILURES_BEFORE_RESTART = 2;
|
|
9
|
+
const DEFAULT_PROBE_TIMEOUT_MS = 2_500;
|
|
10
|
+
const WATCHDOG_PID_FILE = join(getOpenClawDir(), "orgx-gateway-watchdog.pid");
|
|
11
|
+
function readEnvNumber(name, fallback, min) {
|
|
12
|
+
const raw = (process.env[name] ?? "").trim();
|
|
13
|
+
if (!raw)
|
|
14
|
+
return fallback;
|
|
15
|
+
const parsed = Number.parseInt(raw, 10);
|
|
16
|
+
if (!Number.isFinite(parsed) || parsed < min)
|
|
17
|
+
return fallback;
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
function isPidAlive(pid) {
|
|
21
|
+
if (!Number.isFinite(pid) || pid <= 0)
|
|
22
|
+
return false;
|
|
23
|
+
try {
|
|
24
|
+
process.kill(pid, 0);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function readWatchdogPid() {
|
|
32
|
+
try {
|
|
33
|
+
if (!existsSync(WATCHDOG_PID_FILE))
|
|
34
|
+
return null;
|
|
35
|
+
const raw = readFileSync(WATCHDOG_PID_FILE, "utf8").trim();
|
|
36
|
+
const parsed = Number.parseInt(raw, 10);
|
|
37
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
38
|
+
return null;
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function writeWatchdogPid(pid) {
|
|
46
|
+
const dir = getOpenClawDir();
|
|
47
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
48
|
+
writeFileSync(WATCHDOG_PID_FILE, `${pid}\n`, { mode: 0o600 });
|
|
49
|
+
}
|
|
50
|
+
function clearWatchdogPid() {
|
|
51
|
+
try {
|
|
52
|
+
rmSync(WATCHDOG_PID_FILE, { force: true });
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// best effort
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function runCommandCollect(input) {
|
|
59
|
+
const timeoutMs = input.timeoutMs ?? 10_000;
|
|
60
|
+
return await new Promise((resolve, reject) => {
|
|
61
|
+
const child = spawn(input.command, input.args, {
|
|
62
|
+
env: process.env,
|
|
63
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
64
|
+
});
|
|
65
|
+
let stdout = "";
|
|
66
|
+
let stderr = "";
|
|
67
|
+
const timer = timeoutMs
|
|
68
|
+
? setTimeout(() => {
|
|
69
|
+
try {
|
|
70
|
+
child.kill("SIGKILL");
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// best effort
|
|
74
|
+
}
|
|
75
|
+
reject(new Error(`Command timed out after ${timeoutMs}ms`));
|
|
76
|
+
}, timeoutMs)
|
|
77
|
+
: null;
|
|
78
|
+
child.stdout?.on("data", (chunk) => {
|
|
79
|
+
stdout += chunk.toString("utf8");
|
|
80
|
+
});
|
|
81
|
+
child.stderr?.on("data", (chunk) => {
|
|
82
|
+
stderr += chunk.toString("utf8");
|
|
83
|
+
});
|
|
84
|
+
child.on("error", (err) => {
|
|
85
|
+
if (timer)
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
reject(err);
|
|
88
|
+
});
|
|
89
|
+
child.on("close", (code) => {
|
|
90
|
+
if (timer)
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
resolve({ stdout, stderr, exitCode: typeof code === "number" ? code : null });
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function probeGateway(port, timeoutMs) {
|
|
97
|
+
const controller = new AbortController();
|
|
98
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
99
|
+
try {
|
|
100
|
+
// Any HTTP response (including 404) means the gateway port is reachable.
|
|
101
|
+
await fetch(`http://127.0.0.1:${port}/`, {
|
|
102
|
+
method: "GET",
|
|
103
|
+
signal: controller.signal,
|
|
104
|
+
headers: {
|
|
105
|
+
"cache-control": "no-cache",
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
clearTimeout(timeout);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function restartGateway(logger) {
|
|
118
|
+
const restart = await runCommandCollect({
|
|
119
|
+
command: "openclaw",
|
|
120
|
+
args: ["gateway", "restart", "--json"],
|
|
121
|
+
timeoutMs: 30_000,
|
|
122
|
+
});
|
|
123
|
+
if (restart.exitCode === 0) {
|
|
124
|
+
logger.warn?.("[orgx] Gateway watchdog restarted OpenClaw gateway service");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const start = await runCommandCollect({
|
|
128
|
+
command: "openclaw",
|
|
129
|
+
args: ["gateway", "start", "--json"],
|
|
130
|
+
timeoutMs: 30_000,
|
|
131
|
+
});
|
|
132
|
+
if (start.exitCode !== 0) {
|
|
133
|
+
throw new Error(start.stderr.trim() || restart.stderr.trim() || "Failed to restart gateway");
|
|
134
|
+
}
|
|
135
|
+
logger.warn?.("[orgx] Gateway watchdog started OpenClaw gateway service");
|
|
136
|
+
}
|
|
137
|
+
export async function runGatewayWatchdogDaemon(logger = console) {
|
|
138
|
+
const monitorIntervalMs = readEnvNumber("ORGX_GATEWAY_WATCHDOG_INTERVAL_MS", DEFAULT_MONITOR_INTERVAL_MS, 5_000);
|
|
139
|
+
const failuresBeforeRestart = readEnvNumber("ORGX_GATEWAY_WATCHDOG_FAILURES", DEFAULT_FAILURES_BEFORE_RESTART, 1);
|
|
140
|
+
const probeTimeoutMs = readEnvNumber("ORGX_GATEWAY_WATCHDOG_TIMEOUT_MS", DEFAULT_PROBE_TIMEOUT_MS, 500);
|
|
141
|
+
let consecutiveFailures = 0;
|
|
142
|
+
let restartInFlight = false;
|
|
143
|
+
const cleanup = () => {
|
|
144
|
+
const pid = readWatchdogPid();
|
|
145
|
+
if (pid === process.pid) {
|
|
146
|
+
clearWatchdogPid();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
process.on("SIGTERM", () => {
|
|
150
|
+
cleanup();
|
|
151
|
+
process.exit(0);
|
|
152
|
+
});
|
|
153
|
+
process.on("SIGINT", () => {
|
|
154
|
+
cleanup();
|
|
155
|
+
process.exit(0);
|
|
156
|
+
});
|
|
157
|
+
process.on("exit", cleanup);
|
|
158
|
+
writeWatchdogPid(process.pid);
|
|
159
|
+
logger.info?.("[orgx] Gateway watchdog daemon started", {
|
|
160
|
+
intervalMs: monitorIntervalMs,
|
|
161
|
+
failuresBeforeRestart,
|
|
162
|
+
});
|
|
163
|
+
const tick = async () => {
|
|
164
|
+
if (restartInFlight)
|
|
165
|
+
return;
|
|
166
|
+
const snapshot = readOpenClawSettingsSnapshot();
|
|
167
|
+
const port = readOpenClawGatewayPort(snapshot.raw);
|
|
168
|
+
const healthy = await probeGateway(port, probeTimeoutMs);
|
|
169
|
+
if (healthy) {
|
|
170
|
+
consecutiveFailures = 0;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
consecutiveFailures += 1;
|
|
174
|
+
logger.warn?.("[orgx] Gateway watchdog probe failed", {
|
|
175
|
+
port,
|
|
176
|
+
consecutiveFailures,
|
|
177
|
+
threshold: failuresBeforeRestart,
|
|
178
|
+
});
|
|
179
|
+
if (consecutiveFailures < failuresBeforeRestart) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
restartInFlight = true;
|
|
183
|
+
try {
|
|
184
|
+
await restartGateway(logger);
|
|
185
|
+
consecutiveFailures = 0;
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
logger.warn?.("[orgx] Gateway watchdog failed to restart gateway", {
|
|
189
|
+
error: err instanceof Error ? err.message : String(err),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
restartInFlight = false;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
await tick();
|
|
197
|
+
setInterval(() => {
|
|
198
|
+
void tick();
|
|
199
|
+
}, monitorIntervalMs);
|
|
200
|
+
}
|
|
201
|
+
export function ensureGatewayWatchdog(logger) {
|
|
202
|
+
if (process.env.ORGX_DISABLE_GATEWAY_WATCHDOG === "1") {
|
|
203
|
+
logger.debug?.("[orgx] Gateway watchdog disabled via ORGX_DISABLE_GATEWAY_WATCHDOG=1");
|
|
204
|
+
return { started: false, pid: null };
|
|
205
|
+
}
|
|
206
|
+
const existing = readWatchdogPid();
|
|
207
|
+
if (existing && isPidAlive(existing)) {
|
|
208
|
+
return { started: false, pid: existing };
|
|
209
|
+
}
|
|
210
|
+
if (existing && !isPidAlive(existing)) {
|
|
211
|
+
clearWatchdogPid();
|
|
212
|
+
}
|
|
213
|
+
const runnerPath = fileURLToPath(new URL("./gateway-watchdog-runner.js", import.meta.url));
|
|
214
|
+
const child = spawn(process.execPath, [runnerPath], {
|
|
215
|
+
env: process.env,
|
|
216
|
+
stdio: "ignore",
|
|
217
|
+
detached: true,
|
|
218
|
+
});
|
|
219
|
+
child.unref();
|
|
220
|
+
return { started: true, pid: child.pid ?? null };
|
|
221
|
+
}
|
package/dist/http-handler.d.ts
CHANGED