openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
137 lines (136 loc) • 8.08 kB
JavaScript
import { o as writeRuntimeJson, r as defaultRuntime } from "./runtime-B-SLYP-m.mjs";
import { l as publicKeyRawBase64UrlFromEd25519Pem } from "./ed25519-signature-CUaH7IDK.mjs";
import { r as theme } from "./theme-BOI0xyRZ.mjs";
import { n as loadDeviceIdentityIfPresentAsync } from "./device-identity-async-B1EfjFkw.mjs";
import { t as ExpectedCliError } from "./failure-output-DVVDqwuu.mjs";
import { t as formatDocsLink } from "./links-41lO3DKP.mjs";
import { n as inheritOptionFromParent } from "./command-options-D76J8Wl7.mjs";
import "./device-identity-JBn8J50B.mjs";
import { n as formatInvalidPortOption } from "./error-format-O7EzXfiI.mjs";
import { n as createNodeWorkerCommand, t as addNodeCommandOptions } from "./command-options-pF05i-p6.mjs";
import { a as loadNodeHostConfig } from "./config-BmUu42pB.mjs";
import { n as formatHelpExamples } from "./help-format-D2ytHW5E.mjs";
import { n as resolveNodePairGatewayOptions, t as resolveNodeGatewayOptions } from "./gateway-options-BJTgGucZ.mjs";
import { Option } from "commander";
//#region src/cli/node-cli/register.ts
function addNodeGatewayOptions(e) {
return e.option("--host <host>", "Gateway host").option("--port <port>", "Gateway port").option("--context-path <path>", "Gateway WebSocket context path (e.g. /openclaw-gw)").option("--tls", "Use TLS for the gateway connection").option("--no-tls", "Disable TLS for the gateway connection").option("--tls-fingerprint <sha256>", "Expected TLS certificate fingerprint (sha256)").option("--node-id <id>", "Override the generated node instance id").option("--display-name <name>", "Override node display name");
}
function registerNodeCli(e) {
const t = addNodeCommandOptions(e.command("node").description("Run and manage the headless node host service")).addHelpText("after", () => `\n${theme.heading("Examples:")}\n${formatHelpExamples([
["openclaw node run --host 127.0.0.1 --port 18789", "Run the node host in the foreground."],
["openclaw node status", "Check node host service status."],
["openclaw node install", "Install the node host service."],
["openclaw node start", "Start the installed node host service."],
["openclaw node restart", "Restart the installed node host service."]
])}\n\n${theme.muted("Docs:")} ${formatDocsLink("/cli/node", "docs.openclaw.ai/cli/node")}\n`);
t.addCommand(createNodeWorkerCommand().action(async (e) => {
const { runNodeHostWorker: t } = await import("./worker-DpDsY2kh.mjs");
await t({ desktopSharingEnabled: e.desktopSharing });
}), { hidden: true });
addNodeGatewayOptions(addNodeCommandOptions(t.command("run").description("Run the headless node host (foreground)")).option("--pair <code-or-url>", "Pair with a setup code or oc-pair URL; explicit gateway flags take precedence").addOption(new Option("--pair-if-needed <code-or-url>", "Use the saved device token when available; otherwise pair with this setup code").conflicts("pair"))).option("--session-host", "Host worker sessions for this foreground process").addOption(new Option("--ephemeral").hideHelp()).addOption(new Option("--desktop-sharing").hideHelp()).addOption(new Option("--no-desktop-sharing").hideHelp()).option("--auth-from-env", "Use environment Gateway credentials instead of the paired device token").addOption(new Option("--parent-stdin").hideHelp()).option("--share-installed-apps", "Share installed macOS applications with the Gateway").option("--no-share-installed-apps", "Disable installed application sharing").action(async (e, t) => {
let n;
let r;
try {
const t = e.pair ?? e.pairIfNeeded;
n = t ? resolveNodePairGatewayOptions(t, { allowExpired: e.pairIfNeeded !== void 0 }) : void 0;
const i = await loadNodeHostConfig();
r = resolveNodeGatewayOptions(e, i, n);
} catch (e) {
defaultRuntime.error(e instanceof Error ? e.message : String(e));
defaultRuntime.exit(1);
return;
}
const { host: i, port: a, contextPath: o, tls: s, tlsFingerprint: c, cloudflareAccess: l, gatewayCandidates: u } = r;
if (a === null) {
defaultRuntime.error(formatInvalidPortOption("--port"));
defaultRuntime.exit(1);
return;
}
if (e.tls === false && e.tlsFingerprint !== void 0) {
defaultRuntime.error("--no-tls cannot be combined with --tls-fingerprint");
defaultRuntime.exit(1);
return;
}
const { runNodeHost: d } = await import("./runner-D9R1KB0E.mjs");
await d({
gatewayHost: i,
gatewayPort: a,
gatewayTls: s,
gatewayTlsFingerprint: c,
gatewayContextPath: o,
gatewayCloudflareAccess: l,
gatewayCandidates: u,
gatewayBootstrapToken: n?.bootstrapToken,
gatewayBootstrapExpiresAtMs: n?.expiresAtMs,
preferGatewayBootstrapToken: e.pair !== void 0,
...e.ephemeral === true || e.sessionHost === true ? { forceWorkerRuns: true } : {},
...e.ephemeral === true ? { ephemeral: true } : {},
nodeId: e.nodeId,
displayName: e.displayName,
installedAppsSharing: e.shareInstalledApps,
desktopSharingEnabled: e.desktopSharing,
gatewayAuthFromEnv: e.authFromEnv,
parentStdin: e.parentStdin,
commands: e.commands ?? inheritOptionFromParent(t, "commands"),
allCommands: e.allCommands ?? inheritOptionFromParent(t, "allCommands")
});
});
t.command("status").description("Show node host status").option("--json", "Output JSON", false).action(async (e) => {
const { runNodeDaemonStatus: t } = await import("./daemon-DagNKL51.mjs");
await t(e);
});
t.command("identity").description("Print the node host device identity (device id + public key)").option("--identity <key>", "Identity key: primary, node, or shareExtension", "primary").option("--json", "Output JSON", false).action(async (e) => {
const t = e.identity ?? "primary";
if (![
"primary",
"node",
"shareExtension"
].includes(t)) {
const e = "identity must be primary, node, or shareExtension";
throw new ExpectedCliError({
message: e,
humanOutput: e,
machineOutput: e
});
}
const n = await loadDeviceIdentityIfPresentAsync({ identityKey: t });
if (!n) {
const e = "no node device identity found (start the node host once with `openclaw node run` or `openclaw node install`)";
throw new ExpectedCliError({
message: e,
humanOutput: e,
machineOutput: e
});
}
const r = {
deviceId: n.deviceId,
publicKey: publicKeyRawBase64UrlFromEd25519Pem(n.publicKeyPem)
};
if (e.json) {
writeRuntimeJson(defaultRuntime, r, 0);
return;
}
defaultRuntime.log(`deviceId: ${r.deviceId}`);
defaultRuntime.log(`publicKey: ${r.publicKey}`);
});
addNodeGatewayOptions(addNodeCommandOptions(t.command("install").description("Install the node host service (launchd/systemd/schtasks)"))).option("--share-installed-apps", "Share installed macOS applications with the Gateway").option("--no-share-installed-apps", "Disable installed application sharing").option("--runtime <runtime>", "Service runtime (node|bun|standalone). Default: node").option("--runtime-path <path>", "Pin an absolute Node/Bun executable path").addOption(new Option("--expected-runtime-pin <json>", "Require the observed runtime intent").hideHelp()).addOption(new Option("--restore-service-cli <json>", "Restore a retained service CLI").hideHelp()).option("--auth-from-env", "Persist environment Gateway credentials instead of the paired device token").option("--force", "Reinstall/overwrite if already installed", false).option("--json", "Output JSON", false).action(async (e, t) => {
const { runNodeDaemonInstall: n } = await import("./daemon-DagNKL51.mjs");
await n({
...e,
commands: e.commands ?? inheritOptionFromParent(t, "commands"),
allCommands: e.allCommands ?? inheritOptionFromParent(t, "allCommands")
});
});
for (const e of [
"uninstall",
"stop",
"start",
"restart"
]) t.command(e).description(`${e.charAt(0).toUpperCase()}${e.slice(1)} the node host service (launchd/systemd/schtasks)`).option("--json", "Output JSON", false).action(async (t) => {
const { runNodeDaemonLifecycle: n } = await import("./daemon-DagNKL51.mjs");
await n(e, t);
});
}
//#endregion
export { registerNodeCli };