UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

68 lines (67 loc) 3.77 kB
import { c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js"; import { t as formatCliCommand } from "./command-format-CKGmlpAQ.js"; import { t as formatDocsLink } from "./links-CsLBrRff.js"; import { r as theme } from "./theme-vjDs9tao.js"; import { n as defaultRuntime } from "./runtime-B4lgFmsS.js"; import { t as danger } from "./globals-GTrXU4s9.js"; import { n as callGatewayFromCli, t as addGatewayClientOptions } from "./gateway-rpc-DV2_JEP0.js"; //#region src/cli/system-cli.ts const normalizeWakeMode = (raw) => { const mode = normalizeOptionalString(raw) ?? ""; if (!mode) return "next-heartbeat"; if (mode === "now" || mode === "next-heartbeat") return mode; throw new Error("--mode must be now or next-heartbeat"); }; async function runSystemGatewayCommand(opts, action, successText) { try { const result = await action(); if (opts.json || successText === void 0) defaultRuntime.writeJson(result); else defaultRuntime.log(successText); } catch (err) { defaultRuntime.error(danger(String(err))); defaultRuntime.exit(1); } } /** Register Gateway-backed system event, heartbeat, and presence commands. */ function registerSystemCli(program) { const system = program.command("system").description("System tools (events, heartbeat, presence)").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/system", "docs.openclaw.ai/cli/system")}\n`); addGatewayClientOptions(system.command("event").description("Enqueue a system event and optionally trigger a heartbeat").requiredOption("--text <text>", "System event text").option("--mode <mode>", "Wake mode (now|next-heartbeat)", "next-heartbeat").option("--session-key <sessionKey>", "Target a specific session for the event (defaults to the agent's main session)").option("--json", "Output JSON", false)).action(async (opts) => { await runSystemGatewayCommand(opts, async () => { const text = normalizeOptionalString(opts.text) ?? ""; if (!text) throw new Error(`--text is required. Example: ${formatCliCommand("openclaw system event --text \"deploy finished\"")}.`); const mode = normalizeWakeMode(opts.mode); const sessionKey = normalizeOptionalString(opts.sessionKey); return await callGatewayFromCli("wake", opts, sessionKey ? { mode, text, sessionKey } : { mode, text }, { expectFinal: false }); }, "ok"); }); const heartbeat = system.command("heartbeat").description("Heartbeat controls"); addGatewayClientOptions(heartbeat.command("last").description("Show the last heartbeat event").option("--json", "Output JSON", false)).action(async (opts) => { await runSystemGatewayCommand(opts, async () => { return await callGatewayFromCli("last-heartbeat", opts, void 0, { expectFinal: false }); }); }); addGatewayClientOptions(heartbeat.command("enable").description("Enable heartbeats").option("--json", "Output JSON", false)).action(async (opts) => { await runSystemGatewayCommand(opts, async () => { return await callGatewayFromCli("set-heartbeats", opts, { enabled: true }, { expectFinal: false }); }); }); addGatewayClientOptions(heartbeat.command("disable").description("Disable heartbeats").option("--json", "Output JSON", false)).action(async (opts) => { await runSystemGatewayCommand(opts, async () => { return await callGatewayFromCli("set-heartbeats", opts, { enabled: false }, { expectFinal: false }); }); }); addGatewayClientOptions(system.command("presence").description("List system presence entries").option("--json", "Output JSON", false)).action(async (opts) => { await runSystemGatewayCommand(opts, async () => { return await callGatewayFromCli("system-presence", opts, void 0, { expectFinal: false }); }); }); } //#endregion export { registerSystemCli };