openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.66 kB
JavaScript
import { a as resolveGatewaySupervisorLogPaths, r as resolveGatewayLogPaths } from "./restart-logs-BvZvRKQN.js";
import fs from "node:fs/promises";
//#region src/daemon/diagnostics.ts
/** Reads recent gateway service logs for actionable daemon restart diagnostics. */
const GATEWAY_LOG_ERROR_PATTERNS = [
/refusing to bind gateway/i,
/gateway auth mode/i,
/gateway start blocked/i,
/failed to bind gateway socket/i,
/tailscale .* requires/i
];
async function readLastLogLine(filePath) {
try {
const lines = (await fs.readFile(filePath, "utf8")).split(/\r?\n/).map((line) => line.trim());
for (let i = lines.length - 1; i >= 0; i -= 1) if (lines[i]) return lines[i];
return null;
} catch {
return null;
}
}
async function readLastGatewayErrorLine(env, options) {
const platform = options?.platform ?? process.platform;
const readStderr = platform !== "darwin";
const { stdoutPath, stderrPath } = platform === "darwin" ? resolveGatewaySupervisorLogPaths(env, { platform }) : resolveGatewayLogPaths(env);
const stderrRaw = readStderr ? await fs.readFile(stderrPath, "utf8").catch(() => "") : "";
const stdoutRaw = await fs.readFile(stdoutPath, "utf8").catch(() => "");
const lines = [...stderrRaw.split(/\r?\n/), ...stdoutRaw.split(/\r?\n/)].map((line) => line.trim());
for (let i = lines.length - 1; i >= 0; i -= 1) {
const line = lines[i];
if (!line) continue;
if (GATEWAY_LOG_ERROR_PATTERNS.some((pattern) => pattern.test(line))) return line;
}
return readStderr ? await readLastLogLine(stderrPath) ?? await readLastLogLine(stdoutPath) : await readLastLogLine(stdoutPath);
}
//#endregion
export { readLastGatewayErrorLine as t };