openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
71 lines (70 loc) • 2.75 kB
JavaScript
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import path from "node:path";
import { spawnSync } from "node:child_process";
//#region src/commands/doctor-whatsapp-responsiveness.ts
const LOCAL_TUI_SUBCOMMANDS = /* @__PURE__ */ new Set([
"chat",
"terminal",
"tui"
]);
const WHATSAPP_RESPONSIVENESS_CHECK_ID = "core/doctor/whatsapp-responsiveness";
const LOCAL_TUI_PROCESS_PROBE_TIMEOUT_MS = 1e3;
function isLocalTuiCommand(e) {
const t = e.trim().split(/\s+/u).filter(Boolean);
const n = path.basename(t[0] ?? "").replace(/\.exe$/iu, "");
if (n === "openclaw-tui") return true;
return n === "openclaw" && LOCAL_TUI_SUBCOMMANDS.has(t[1] ?? "");
}
function parsePsPidLine(e) {
const t = e.match(/^\s*(\d+)\s+(.+)$/);
if (!t) return null;
const n = Number(t[1]);
if (!Number.isFinite(n) || n <= 0 || n === process.pid) return null;
const r = t[2]?.trim() ?? "";
if (!isLocalTuiCommand(r)) return null;
return {
pid: n,
command: r
};
}
/** Lists local OpenClaw TUI processes without inferring their Gateway or activity. */
function listLocalTuiProcesses() {
if (process.platform === "win32") return [];
const e = spawnSync("ps", ["-axo", "pid=,command="], {
encoding: "utf8",
killSignal: "SIGKILL",
timeout: LOCAL_TUI_PROCESS_PROBE_TIMEOUT_MS
});
if (e.error || e.status !== 0 || typeof e.stdout !== "string") return [];
const t = /* @__PURE__ */ new Map();
for (const n of e.stdout.split(/\r?\n/)) {
const e = parsePsPidLine(n);
if (e && !t.has(e.pid)) t.set(e.pid, e);
}
return [...t.values()];
}
function hasWhatsappEnabled(e) {
const t = e.channels?.whatsapp;
if (!t || t.enabled === false) return false;
const n = Object.values(t.accounts ?? {});
return n.length === 0 || n.some((e) => e?.enabled !== false);
}
/** Collects read-only structured findings for WhatsApp responsiveness pressure. */
function collectWhatsappResponsivenessHealthFindings(e) {
if (!hasWhatsappEnabled(e.cfg) || e.status?.eventLoop?.degraded !== true) return [];
const t = (e.listLocalTuiProcesses ?? listLocalTuiProcesses)();
if (t.length === 0) return [];
return [{
checkId: WHATSAPP_RESPONSIVENESS_CHECK_ID,
severity: "warning",
category: "recommended",
docsUrl: "https://docs.openclaw.ai/gateway/diagnostics",
message: "Gateway reports pressure, and local TUI clients were detected. This snapshot does not identify the source of the pressure.",
path: "channels.whatsapp",
target: t.map((e) => String(e.pid)).join(", "),
requirement: "local-tui-event-loop-pressure",
fixHint: `Inspect Gateway diagnostics with ${formatCliCommand("openclaw gateway diagnostics export")} before deciding whether to close clients.`
}];
}
//#endregion
export { collectWhatsappResponsivenessHealthFindings };