openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 5.48 kB
JavaScript
import{c as resolveOpenClawCliInvocation}from"./cli-invocation-Covx3kvQ.mjs";import{s as normalizeNullableString}from"./string-coerce-CpTFcSwY.mjs";import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as resolveRuntimeArgs}from"./runtime-worker-url-Dqf-I1cs.mjs";import{i as resolveExternalPackageRuntimeEntrypointUrl}from"./runtime-process-url-DJ272Tuo.mjs";import{m as statIfExists}from"./path-existence-BR9MXlgL.mjs";import{i as parsePackageOpenClawSchemaVersions,n as OPENCLAW_STATE_SCHEMA_VERSION,t as OPENCLAW_AGENT_SCHEMA_VERSION}from"./openclaw-schema-versions-rhFQpVhP.mjs";import"./openclaw-state-db-contract-G6fQNIi2.mjs";import{n as openNodeSqliteDatabase}from"./node-sqlite-DXyF1fBG.mjs";import{s as resolveOpenClawStateSqlitePath}from"./openclaw-state-db.paths-CbgXfEg1.mjs";import{a as prepareSqliteReadOnlyLocation}from"./sqlite-snapshot-source-DbIgYrJe.mjs";import{l as resolveSqliteInspectionBudget,p as runSqliteReadOnlyWorker}from"./sqlite-readonly-worker-C1mJaAX6.mjs";import"./openclaw-agent-db-contract-CiyWpx1X.mjs";import{l as tryReadJson}from"./json-files-BBQ_0Np0.mjs";import{n as runCommandWithTimeout}from"./exec-runner-BiCq-T1F.mjs";import"./exec-c5tqm8tb.mjs";import{n as readAgentDatabasePreflightTargets}from"./openclaw-agent-db-registry.read-BLUjVOoj.mjs";import{t as prepareGitCandidateNodeRuntime}from"./update-runner-git-node-preflight-CdpstA4D.mjs";import{r as preflightOpenClawDatabaseSchemas}from"./openclaw-database-preflight-CvnmOivM.mjs";import{fileURLToPath}from"node:url";import path from"node:path";import fs from"node:fs/promises";
//!src/node-host/auto-update-compatibility.ts
const MANUAL_UPDATE_GUIDANCE=`Update OpenClaw manually with openclaw update, then restart the node.`;function assertNodeRuntimeSchemaVersions(e){if(e?.state!==40||e.agent!==42)throw new Error(`Node auto-update deferred: the release changes database schemas. ${MANUAL_UPDATE_GUIDANCE}`)}async function readNodeRuntimeUpdateManifest(e){const t=asNullableRecord(await tryReadJson(path.join(e,`package.json`),{maxBytes:1048576}));const n=normalizeNullableString(t?.version);if(t?.name!==`openclaw`||!n)throw new Error(`Node auto-update candidate has no valid OpenClaw package manifest.`);const r=parsePackageOpenClawSchemaVersions(t);assertNodeRuntimeSchemaVersions(r);for(const t of[`openclaw.mjs`,`node-host-launcher.mjs`,`dist/node-host-launcher-bootstrap.js`])if(!(await fs.stat(path.join(e,t))).isFile())throw new Error(`Node auto-update candidate is missing ${t}.`);if(!(await Promise.all([`dist/entry.js`,`dist/entry.mjs`].map(async t=>{return(await statIfExists(path.join(e,t)))?.isFile()??false}))).some(Boolean))throw new Error(`Node auto-update candidate is missing its built CLI entrypoint.`);return{version:n,schemaVersions:r}}async function assertNodeRuntimeUpdateCompatible(e){e.signal?.throwIfAborted();const{schemaVersions:t}=await readNodeRuntimeUpdateManifest(e.packageRoot);const n=process.versions.bun?null:(await prepareGitCandidateNodeRuntime(e.packageRoot,void 0,`current-runtime`)).step;if(n)throw new Error(n.stderrTail??`Node runtime is incompatible with the update.`);const r={...process.env,OPENCLAW_STATE_DIR:e.stateDir};const i=await preflightOpenClawDatabaseSchemas({env:r,signal:e.signal,supportedVersions:t,verifyCurrentSchemaShape:true});if(i.incompatible.length||i.indeterminate.length||i.pendingMigrations?.length)throw new Error(`Node auto-update deferred: existing databases require migration or repair. ${MANUAL_UPDATE_GUIDANCE}`);const a=resolveOpenClawStateSqlitePath(r);if(!await statIfExists(a))return;const preflightCopy=async(t,n)=>{const i=await prepareSqliteReadOnlyLocation(await fs.realpath(t),{preserveSourceArtifacts:true,signal:e.signal});let o;try{const s=await runSqliteReadOnlyWorker(i.location,{mode:`consolidated`,stagingRoot:path.dirname(i.location),signal:e.signal});const{timeoutMs:c}=resolveSqliteInspectionBudget(`node update compatibility`,t,(await fs.stat(s)).size);const l=resolveOpenClawCliInvocation({execArgv:resolveRuntimeArgs(),entryPath:fileURLToPath(resolveExternalPackageRuntimeEntrypointUrl(`cliLauncher`,e.packageRoot)),args:[`database`,n===void 0?`preflight`:`preflight-agent`,s,...n===void 0?[]:[`--agent-id`,n],`--json`]});const u=await runCommandWithTimeout([l.command,...l.args],{timeoutMs:c,signal:e.signal,killProcessTree:true,env:r});let d=null;try{d=asNullableRecord(JSON.parse(u.stdout))}catch{}const f=n===void 0?`openclaw.state-schema-preflight.v1`:`openclaw.agent-schema-preflight.v1`;if(u.code!==0||d?.schema!==f||d.status!==`exact`){const e=normalizeNullableString(d?.reason)??u.stderr.trim();throw new Error(`Node auto-update candidate rejected the copied database${e?`: ${e}`:`.`} ${MANUAL_UPDATE_GUIDANCE}`)}if(n!==void 0)o={agents:[]};else{const e=openNodeSqliteDatabase(s,{readOnly:true});try{o={agents:readAgentDatabasePreflightTargets(e,a)}}finally{e.close()}}}catch(e){o={error:e}}try{if(!await i.cleanupAsync())throw new Error(`Node auto-update database snapshot cleanup failed: ${i.cleanupRoot??i.location}`)}catch(e){throw`error`in o?new AggregateError([o.error,e],`Node auto-update compatibility and cleanup failed`):e}if(`error`in o)throw o.error;return o.agents};const o=await preflightCopy(a);for(const e of o){if(!await statIfExists(e.path))continue;await preflightCopy(e.path,e.agentId)}e.signal?.throwIfAborted()}export{assertNodeRuntimeUpdateCompatible as n,readNodeRuntimeUpdateManifest as r,assertNodeRuntimeSchemaVersions as t};