openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 8.27 kB
JavaScript
import{o as writeRuntimeJson,r as defaultRuntime}from"./runtime-DIcLIHcp.mjs";import{l as publicKeyRawBase64UrlFromEd25519Pem}from"./ed25519-signature-BXghQ01p.mjs";import{r as theme}from"./theme-DS2CtI9X.mjs";import{n as loadDeviceIdentityIfPresentAsync}from"./device-identity-async-BkJXqwph.mjs";import{t as ExpectedCliError}from"./expected-cli-error-oDVmXYil.mjs";import{t as formatDocsLink}from"./links-C_FK9uVv.mjs";import{n as inheritOptionFromParent}from"./command-options-Cl1CohDr.mjs";import"./device-identity-Dwje1Nh0.mjs";import{n as formatInvalidPortOption}from"./error-format-D9Q6t3gZ.mjs";import{n as createNodeWorkerCommand,t as addNodeCommandOptions}from"./command-options-Bq1F8z-f.mjs";import{a as loadNodeHostConfig}from"./config-W6i7-yzD.mjs";import{n as formatHelpExamples}from"./help-format-DLfgiheF.mjs";import{n as resolveNodePairGatewayOptions,t as resolveNodeGatewayOptions}from"./gateway-options-CK0ICeEV.mjs";import{Option}from"commander";
//!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-B-VzT7wk.mjs`);await t({desktopSharingEnabled:e.desktopSharing})}),{hidden:true});addNodeCommandOptions(t.command(`join`).description(`Enroll this node with an OpenClaw ID invitation`)).argument(`<link>`,`openclaw-node:// invitation link`).option(`--service`,`Install and run the node host as an OS service`).option(`--discovery-url <url>`,`Discovery API origin (overrides the origin carried by the invitation link)`).option(`--display-name <name>`,`Override node display name`).action(async(e,t,n)=>{try{const{runNodeJoin:r}=await import(`./openclaw-id-join-D-nrxacJ.mjs`);await r(e,{service:t.service,discoveryUrl:t.discoveryUrl,displayName:t.displayName,commands:t.commands??inheritOptionFromParent(n,`commands`),allCommands:t.allCommands??inheritOptionFromParent(n,`allCommands`)})}catch(e){defaultRuntime.error(e instanceof Error?e.message:String(e));defaultRuntime.exit(1)}});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(`--resume-device <id>`,`Resume only this saved paired device`).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,gatewayTarget:d}=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:f}=await import(`./runner-4N9Sw9ld.mjs`);await f({gatewayHost:i,gatewayPort:a,gatewayTls:s,gatewayTlsFingerprint:c,gatewayContextPath:o,gatewayCloudflareAccess:l,gatewayCandidates:u,gatewayTarget:d,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,resumeDeviceId:e.resumeDevice,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-DVJq3Imr.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-DVJq3Imr.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-DVJq3Imr.mjs`);await n(e,t)})}export{registerNodeCli};