openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.96 kB
JavaScript
import{n as isTruthyEnvValue}from"./env-fLMEolk5.mjs";import{i as isRegularFile}from"./executable-path-BYWCW0PG.mjs";import{Jn as string,qn as strictObject}from"./schemas-DuCQi-Qb.mjs";import{t as safeParseJsonWithSchema}from"./zod-parse-sJYjlHYu.mjs";import{n as resolveStableNodePath}from"./stable-node-path-CUkQ4WiB.mjs";import{o as isUpdateOwnedGatewayServiceCommand}from"./service-update-authority-DqjrBTQ9.mjs";import{s as resolvePinnedDaemonRuntimePath}from"./runtime-paths-BOio2Rt6.mjs";import{n as buildGatewayInstallEntrypointCandidates}from"./gateway-entrypoint-CczuA1rM.mjs";import{t as OPENCLAW_WRAPPER_ENV_KEY}from"./program-args-Dls9y3ku.mjs";import path from"node:path";
//!src/cli/daemon-cli/install-restore-cli.ts
const expectedRuntimePinSchema=strictObject({revision:string(),definition:string().nullable()});function assertExpectedRuntimePin(e,t,n){const r=safeParseJsonWithSchema(expectedRuntimePinSchema,e);if(!r)throw new Error(`Invalid expected runtime pin snapshot.`);if(r.revision!==t.revision||r.definition!==(t.definition??null))throw new Error(`${n} service or runtime pin changed before installation. The newer selection was preserved; inspect it before retrying.`)}const serviceFile=string().refine(e=>path.isAbsolute(e)&&!/[\0\r\n]/.test(e)&&isRegularFile(e));const restoreServiceCliSchema=strictObject({executable:string(),entrypoint:serviceFile.refine(e=>path.basename(e)===`openclaw.mjs`||buildGatewayInstallEntrypointCandidates(path.dirname(path.dirname(e))).includes(path.normalize(e))).nullable(),sqliteLibrary:serviceFile.nullable()});async function resolveRestoreServiceCli(e,t,n){const r=safeParseJsonWithSchema(restoreServiceCliSchema,e);if(!r)throw new Error(`Invalid restore service CLI.`);const{runtime:i,runtimePath:a,wrapper:o,expectedRuntimePin:s}=t;const{executable:c,sqliteLibrary:l}=r;try{if(s===void 0)throw new Error(`requires --expected-runtime-pin.`);if(i!==`node`&&i!==`bun`&&i!==`standalone`)throw new Error(`requires an explicit --runtime ("node", "bun", or "standalone").`);if(i===`standalone`!==(r.entrypoint===null))throw new Error(`standalone recovery requires a null entrypoint; Node and Bun require an entry script.`);if(o!==void 0||n[`OPENCLAW_WRAPPER`]?.trim())throw new Error(`cannot be combined with a wrapper.`);if(a!==void 0&&path.normalize(a)!==path.normalize(c))throw new Error(`executable must match --runtime-path.`);if(isUpdateOwnedGatewayServiceCommand()||isTruthyEnvValue(process.env.OPENCLAW_UPDATE_IN_PROGRESS))throw new Error(`cannot be combined with update-owned reconciliation.`);if(l===null)delete n.OPENCLAW_SQLITE_LIBRARY;else n.OPENCLAW_SQLITE_LIBRARY=l;let e=await resolvePinnedDaemonRuntimePath(c,i,n);if(i===`node`&&a===void 0&&e)e=await resolveStableNodePath(e);return{serviceCli:r,runtimePath:e}}catch(e){throw new Error(`--restore-service-cli ${e instanceof Error?e.message:String(e)}`,{cause:e})}}export{resolveRestoreServiceCli as n,assertExpectedRuntimePin as t};