openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.16 kB
JavaScript
import{J as e,Ot as t}from"./sqlite-readonly-subsystem-Bfq7Sewc.mjs";import{b as n,j as r}from"./sqlite-readonly-sqlite-snapshot-staging-owner-Bx_sVS1z.mjs";import"./sqlite-readonly-openclaw-state-db-engine-pc5Xuwy7.mjs";import{G as i,K as a,et as o,ft as s,pt as c,q as l}from"./sqlite-readonly-sqlite-database-admission-Bj6bmeyX.mjs";import"./sqlite-readonly-openclaw-state-db-async-lifecycle-BwAy3Dr9.mjs";import{f as u,l as d}from"./sqlite-readonly-sqlite-snapshot-source-DID1ReIT.mjs";import"./sqlite-readonly-errors-_ACXy9m3.mjs";import{J as f,Q as p,R as m,z as h}from"./sqlite-readonly-openclaw-state-db-readonly-CQZBUV1N.mjs";import{u as g}from"./sqlite-readonly-worker-task-pool-BzpvPJI8.mjs";import"./sqlite-readonly-acquire-with-wait-BsupS0ie.mjs";import{i as _}from"./sqlite-readonly-sqlite-integrity-voG-Avxn.mjs";import v from"node:fs";import{AsyncLocalStorage as y}from"node:async_hooks";const b=/^(?:(?:pnpm|npm|bunx|npx)\s+)?openclaw(?=\s|$)/,x=/(?:^|\s)--container(?:\s|=|$)/,S=/(?:^|\s)--profile(?:\s|=|$)/,C=/(?:^|\s)--dev(?:\s|$)/,w=/^(?:\s+--(?:dev|no-color|(?:profile|log-level)[=\s]+\S+))*\s+update(?:\s|$)/,T=/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/;function formatCliCommand(t,n=process.env){let r=n.OPENCLAW_CONTAINER_HINT?.trim(),i=r&&T.test(r)?r:void 0,a=e(n.OPENCLAW_PROFILE);if(!i&&!a||!b.test(t))return t;let o;return i&&!x.test(t)&&!w.test(t.replace(b,``))&&(o=`--container ${i}`),!i&&a&&!S.test(t)&&!C.test(t)&&(o=`--profile ${a}`),o?t.replace(b,e=>`${e} ${o}`):t}function quotePowerShellArg(e){return`'${e.replace(/['‘-‛]/gu,`$&$&`)}'`}function quoteCliArg(e){return/^[A-Za-z0-9_/:=.,@%+-]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`}function planSqliteRecoveryMoves(e){let t=`.corrupt-${Date.now()}`;for(let n=0;n<100;n+=1){let r=n===0?t:`${t}.${n}`,i=e.map(e=>({destinationPath:`${e}${r}`,sourcePath:e}));if(i.every(e=>!v.lstatSync(e.destinationPath,{throwIfNoEntry:!1})))return i}throw Error(`Could not choose recovery paths for ${e[0]??`SQLite files`}`)}function formatAgentDatabaseCorruptionRepairHint(e,n){if(!i(n).includes(`creating its private snapshot:`)&&t(n).some(e=>a(e)||[`SQLITE_CORRUPT`,`SQLITE_NOTADB`].includes(o(e)??``)||e instanceof Error&&_(e)))return`Stop the Gateway, back up this database and its SQLite sidecars, then run "${formatCliCommand(`openclaw doctor --session-sqlite recover --session-sqlite-agent ${quoteCliArg(e)}`)}" against the same state/config. Recovery repairs supported index corruption or preserves damaged files with a .corrupt-<timestamp> suffix. Restore a verified backup if you need the previous sessions, then restart the Gateway.`}function formatAgentDatabaseOwnershipRepairHint(e){let t=planSqliteRecoveryMoves(u(e).filter(e=>v.lstatSync(e,{throwIfNoEntry:!1})));t.sort((t,n)=>Number(t.sourcePath===e)-Number(n.sourcePath===e));let n=t.map(({sourcePath:e,destinationPath:t})=>process.platform===`win32`?`Move-Item -LiteralPath ${quotePowerShellArg(e)} -Destination ${quotePowerShellArg(t)} -ErrorAction Stop`:`mv -n -- ${quoteCliArg(e)} ${quoteCliArg(t)}`).join(process.platform===`win32`?`; `:` && `);return`Preserve and inspect this database before accepting a fresh agent. With all OpenClaw processes stopped, the explicit quarantine move is${process.platform===`win32`?` (PowerShell)`:``}:\n${n}\nThen run openclaw doctor --fix and restart the Gateway.`}const E=/* @__PURE__ */ new WeakMap;new y;function isAgentDatabasePreparationRetryable(e){return!s(e)&&(l(e)||c(e,`overloaded`)||e instanceof g&&e.code===`overloaded`)}function createAgentDatabaseInspectionRefusal(e){let r=d(process.env)&&e.reason.includes(`creating its private snapshot:`)&&/(?:code=(?:ENOSPC|EDQUOT)\b|errcode=13\b)/u.test(e.reason),i=t(e.cause).some(e=>e instanceof Error&&e.name===`DataCloneError`),a=!e.pending&&l(e.cause),o=e.cause instanceof n,s={agentId:e.agentId,paths:e.paths,code:e.pending?`agent-database-inspection-pending`:`agent-database-inspection-failed`,reason:a?`database locked by another process`:e.reason,repairHint:!e.pending&&isAgentDatabasePreparationRetryable(e.cause)?`Wait for competing database work to finish, then restart the Gateway to retry admission. Lock or worker capacity contention does not require database repair.`:r?`Free space in the reported snapshot cache, then retry the update. This candidate snapshot failure does not require repairing the serving database.`:i?`A worker request could not be serialized. Update OpenClaw and restart the Gateway; repeating database migration will not repair this request.`:o?`Sessions remain unavailable because newer config or plugin changes kept replacing this agent's runtime preparation. Restart the Gateway to retry admission. This failure does not require database repair.`:e.pending?`Startup preparation is in progress or waiting for capacity. Retry the request after startup preparation finishes. Pending startup does not indicate a database failure.`:`Sessions remain unavailable. ${formatAgentDatabaseCorruptionRepairHint(e.agentId,e.cause)??`Stop the Gateway, run "openclaw doctor --fix" to inspect and repair this agent database, and restart.`}`};return E.set(s,e.cause),s}function createAgentDatabaseHeldRefusal(e,t){return{agentId:e,paths:t,code:`agent-database-held`,reason:`Agent ${e} database is held for explicit restoration.`,repairHint:`Run openclaw doctor --fix for restoration guidance, then restore the preserved store with agents add. Held databases are not live agents.`}}function inspectAgentDatabaseAdmission(e){let t=r(e.agentId),n=e.metadata;if(n?.role===`agent`&&n.agentId&&n.agentId!==t)return{agentId:t,paths:[e.path],embeddedOwnerId:n.agentId,code:`agent-database-ownership-mismatch`,reason:`Refused agent ${t}: database ${e.path} belongs to agent ${n.agentId}; requested agent ${t}.`,repairHint:formatAgentDatabaseOwnershipRepairHint(e.path)}}function canIsolateAgentDatabase(e,t){return f(e).includes(t)&&!p(t)&&t!==m(e)&&t!==h(e)}let isAgentDatabaseStartupReadReady=()=>!1;export{isAgentDatabaseStartupReadReady as a,inspectAgentDatabaseAdmission as i,createAgentDatabaseHeldRefusal as n,formatCliCommand as o,createAgentDatabaseInspectionRefusal as r,canIsolateAgentDatabase as t};