openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 21.2 kB
JavaScript
import{D as e,E as t,H as n,N as r,Q as i,b as a,et as o,g as s,h as c,it as l,nt as u,p as d,rt as f,v as p}from"./disk-budget.worker-paths-DAFiPrD7.mjs";import{x as m}from"./disk-budget.worker-sqlite-readonly-worker-WKiVGIHU.mjs";import{L as h,R as g}from"./disk-budget.worker-sqlite-lifecycle-errors-BU4Ayp4j.mjs";import"./disk-budget.worker-subsystem-BalNE4hU.mjs";import{l as _}from"./disk-budget.worker-openclaw-agent-db.paths-BlkaCq0b.mjs";import{n as ee,r as te}from"./disk-budget.worker-path-existence-OmZIMgK8.mjs";import{ut as ne,vt as re,xt as ie}from"./disk-budget.worker-openclaw-state-db-cache-BtIdgwlz.mjs";import{_ as ae,o as v,s as y}from"./disk-budget.worker.js";import{Ht as b,In as x,Ln as S,P as C,Ut as w,Wt as T,Zt as oe}from"./disk-budget.worker-sqlite-worker-operation-settlement-9_4LJ7KU.mjs";import"./disk-budget.worker-worker-task-pool-CyvplXuz.mjs";import"./disk-budget.worker-sqlite-database-admission-turn-COmFWqhk.mjs";import{isMainThread as se}from"node:worker_threads";import{AsyncLocalStorage as ce}from"node:async_hooks";import E from"node:fs";import D from"node:fs/promises";import O from"node:os";import k from"node:path";import{isProxy as A}from"node:util/types";import"@openclaw/fs-safe/advanced";import{spawn as j}from"node:child_process";import{EventEmitter as M}from"node:events";const N=/^(?:(?:pnpm|npm|bunx|npx)\s+)?openclaw(?=\s|$)/,P=/(?:^|\s)--container(?:\s|=|$)/,F=/(?:^|\s)--profile(?:\s|=|$)/,I=/(?:^|\s)--dev(?:\s|$)/,L=/^(?:\s+--(?:dev|no-color|(?:profile|log-level)[=\s]+\S+))*\s+update(?:\s|$)/,R=/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/;function formatCliCommand(e,t=process.env){let n=t.OPENCLAW_CONTAINER_HINT?.trim(),r=n&&R.test(n)?n:void 0,i=c(t.OPENCLAW_PROFILE);if(!r&&!i||!N.test(e))return e;let a;return r&&!P.test(e)&&!L.test(e.replace(N,``))&&(a=`--container ${r}`),!r&&i&&!F.test(e)&&!I.test(e)&&(a=`--profile ${i}`),a?e.replace(N,e=>`${e} ${a}`):e}function hasExplicitModelPolicyAllow(e){return i(e)&&Object.hasOwn(e,`allow`)}const z={};let B=/* @__PURE__ */ new WeakSet,V=0;function boundFrozenPlainData(e){V>262144&&(B=new WeakSet([e]),V=1)}function isPlainDataObject(e){if(A(e))return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Array.isArray(e)&&t===Array.prototype}function inspectPlainData(e,t,n=!0){if(!e||typeof e!=`object`)return typeof e!=`function`;if(B.has(e))return!0;if(!t&&n&&(A(e)||!Object.isFrozen(e)))return!1;let r=!0,i=/* @__PURE__ */ new Set,a=[e];for(;a.length;){let e=a.pop();if(!i.has(e)){if(isPlainDataObject(e)){if(!t&&n&&!Object.isFrozen(e))return!1;i.add(e);for(let n of Reflect.ownKeys(e)){let i=Object.getOwnPropertyDescriptor(e,n),o=i.value;if(!(`value`in i)||typeof o==`function`){if(!t)return!1;r=!1}else o&&typeof o==`object`&&!B.has(o)&&a.push(o)}t&&Object.freeze(e)}else{if(!t)return!1;r=!1}}}if(r&&(t||n)){for(let e of i)B.add(e);V+=i.size,boundFrozenPlainData(e)}return r}function isDeeplyFrozenPlainData(e){return inspectPlainData(e,!1)}const H=[{id:`openclaw`,kind:`system`},{id:`crestodian`,kind:`system`}],U=new Set(H.map(e=>_(e.id)));function isReservedSystemAgentId(e){return U.has(_(e))}let W;const G=/* @__PURE__ */ new WeakMap;function readAgentRosterFacts(e){if(e===void 0)return W.facts;let t=z.current,n=t?.config===e?t.revision:void 0;if(n===void 0&&!isDeeplyFrozenPlainData(e))return;let r=G.get(e);return r&&r.publication===n||(r={publication:n,facts:{}},G.set(e,r)),r.facts}function collectAgentEntries(e,t,n){let r=readAgentRosterProperty(e);if(r?.kind===`entries`&&i(r.value)){let e=[];for(let a in r.value){if(!Object.hasOwn(r.value,a))continue;let o=r.value[a];if(i(o)){let r={...o,id:a};if(e.push(t?{entry:r,source:{kind:`entries`,key:a}}:r),e.length===n)break}}return e}if(r?.kind!==`list`||!Array.isArray(r.value))return[];let a=[];return r.value.some((e,t)=>(typeof e==`object`&&e&&a.push({entry:e,source:{kind:`list`,index:t}}),a.length===n)),t?a:a.map(({entry:e})=>e)}function listAgentEntriesWithSource(e){return collectAgentEntries(e,!0)}function listAgentEntries(e){return collectAgentEntries(e,!1)}function readAgentRosterProperty(e){if(!i(e))return;let t=e.agents;if(i(t))for(let e of[`entries`,`list`]){let n=t[e];if(Object.hasOwn(t,e)&&n!==void 0)return{kind:e,value:n}}}function hasAgentRosterProperty(e){return readAgentRosterProperty(e)!==void 0}function listAgentIds(e){let t=readAgentRosterFacts(e);if(t?.agentIds)return t.agentIds;let n=listAgentEntries(e),r=n.length===0&&!hasAgentRosterProperty(e)?[v]:[...new Set(n.map(e=>_(e?.id)))];return t&&(Object.freeze(r),t.agentIds=r),r}function listGatewayOwnedAgentIds(e){return[.../* @__PURE__ */ new Set([...listAgentIds(e),...H.map(({id:e})=>e)])]}function tryResolveSoleAgentId(e){let t=collectAgentEntries(e,!1,2);return t.length===0?hasAgentRosterProperty(e)?void 0:v:t.length===1?_(t[0].id):void 0}function tryResolveRawLegacyDefaultAgentId(e){if(e.agents?.ownership===`explicit`)return;let t=collectAgentEntries(e,!1).filter(e=>e.default===!0);return t.length===1?_(t[0].id):void 0}function tryResolveDefaultAgentId(e){return tryResolveRawLegacyDefaultAgentId(e)??tryResolveSoleAgentId(e)}function tryResolveLegacyDataOwner(e){return tryResolveDefaultAgentId(e)}function isPerAgentSessionStoreConfig(e){return!e?.trim()||e.includes(`{agentId}`)}function resolvePersistedSessionStoreOwner(e){if(isPerAgentSessionStoreConfig(e.session?.store))return{kind:`none`};let t=e.agents?.defaults?.sessionStore?.agentId?.trim();if(!t)return{kind:`none`};let n=_(t);return listAgentIds(e).some(e=>_(e)===n)?{kind:`configured`,agentId:n}:{kind:`retired`,agentId:n}}function resolvePersistedSessionStoreOwnerForKey(e,t){return y(t)===`legacy_or_alias`?resolvePersistedSessionStoreOwner(e):{kind:`none`}}let K,le=0;function startHost(){let e=j(process.execPath,[...S(x(`directoryWatchHost`)),String(process.pid)],{stdio:[`pipe`,`pipe`,`ignore`],detached:!0,env:{...process.env,NODE_OPTIONS:void 0}}),t={child:e,watches:/* @__PURE__ */ new Map,retired:0},n=``;e.stdout.setEncoding(`utf8`).on(`data`,e=>{let r=(n+e).split(`
`);n=r.pop()??``;for(let e of r){let n=JSON.parse(e),r=t.watches.get(n.id);r&&(n.event?r.emit(`change`,n.event,n.filename??void 0):(t.watches.delete(n.id),r.emit(`error`,/* @__PURE__ */ Error(`Directory watch host lost the watch`),!0)))}});let lost=()=>{K===t&&(K=void 0);let e=Array.from(t.watches.values());t.watches.clear();for(let t of e)t.emit(`error`,/* @__PURE__ */ Error(`Directory watch host exited`),!1)};e.on(`error`,lost).on(`exit`,lost),e.stdin.on(`error`,()=>{}),e.unref();for(let t of[e.stdin,e.stdout])t.unref?.();return t}function register(e,t,n){e.watches.set(t,n),e.child.stdin.write(`${JSON.stringify({id:t,path:n.path,recursive:n.recursive})}\n`)}function watchDirectory(e,t,n=!1){let r=le++,i=Object.assign(new M,{path:e,recursive:n});i.on(`change`,t);try{register(K??=startHost(),r,i)}catch(e){K?.watches.delete(r),queueMicrotask(()=>i.emit(`error`,e,!1))}return Object.assign(i,{close(){i.removeAllListeners(`change`);let e=K;if(e?.watches.delete(r)){if(e.watches.size&&(process.platform!==`darwin`||++e.retired<64))e.child.stdin.write(`${JSON.stringify({id:r})}\n`);else{if(K=void 0,e.watches.size){let t=K=startHost();for(let[n,r]of e.watches)register(t,n,r);e.watches.clear()}e.child.stdin.end()}}}})}const q=/* @__PURE__ */ new Map,J=/* @__PURE__ */ new Map;let Y,X=1/0;const Z=3e4;function nextFallback(e=Z){let t=Date.now(),n=(Math.floor(t/e)+1)*e;return{atMs:n,elapsedAtMs:performance.now()+n-t}}function fallbackRemaining(e){return Math.min(e.nextFallback.atMs-Date.now(),e.nextFallback.elapsedAtMs-performance.now())}function retainEarlierFallback(e,t){e.nextFallback.atMs=Math.min(e.nextFallback.atMs,t.atMs),e.nextFallback.elapsedAtMs=Math.min(e.nextFallback.elapsedAtMs,t.elapsedAtMs)}function scheduleFallback(e){if(!q.size)return;let t=e?fallbackRemaining(e):Math.min(...Array.from(q.values(),fallbackRemaining)),n=performance.now()+Math.max(0,Math.ceil(t));Y&&X<=n||(clearTimeout(Y),X=n,Y=o(()=>setTimeout(()=>{reconcile()},Math.max(0,Math.ceil(t))).unref()))}async function reconcile(){Y=void 0;let e=Array.from(q.values()).filter(e=>fallbackRemaining(e)<=0),t=/* @__PURE__ */ new Map;for(let n of e){n.nextFallback=nextFallback(n.reconcileIntervalMs);let e=n.source;if((!e||!await D.access(e.path).then(()=>!0,()=>!1)||e.path!==n.path&&await D.access(n.path).then(()=>!0,()=>!1))&&n.source===e)for(let r of e?.directories??[n])t.set(r,e)}for(let[e,n]of t)(q.get(e.key)!==e||e.source!==n)&&t.delete(e);for(let e of t.keys())detach(e);for(let e of t.keys())attach(e);for(let t of e)q.get(t.key)===t&¬ify(t);scheduleFallback()}function detach(e){let t=e.source;e.source=void 0,t&&(t.directories=t.directories.filter(t=>t!==e),t.directories.length||(J.delete(t.key),t.watcher.close()))}function notify(e,t,n){for(let r of e.listeners)r(t,n)}function attach(e,t=e.watchRoot){let n=e.recursive&&t===e.watchRoot,i=JSON.stringify([t,n]),a=J.get(i);if(a){a.directories=[...a.directories,e],e.source=a;return}let s=k.basename(t),c=o(()=>watchDirectory(t,(e,n)=>{let a=J.get(i);if(!a||a.watcher!==c)return;a.admitted=!0;let o=a.directories,l=e===`rename`&&(!n||n===s),u;for(let i of o)(i.path===t||!n||l||r(i.path,u??=k.resolve(t,n))||r(u,i.path))&¬ify(i,i.path===t?n:void 0,e);if(e===`rename`){let e;for(let i of o)(l||i.watchRoot!==t&&n!==void 0&&r(u??=k.resolve(t,n),i.watchRoot))&&(e??=[]).push(i);if(!e)return;for(let t of e)detach(t);for(let t of e)q.get(t.key)===t&&(attach(t),retainEarlierFallback(t,nextFallback(t.reconcileIntervalMs)),scheduleFallback(t))}},n)),l={key:i,path:t,watcher:c,admitted:!1,directories:[e]};J.set(i,l),e.source=l,c.on(`error`,(e,n)=>{for(let e of l.directories){detach(e);let r=k.dirname(t);n&&!l.admitted&&r!==t?attach(e,r):(notify(e),retainEarlierFallback(e,nextFallback()),scheduleFallback(e))}})}function observeOwnedDirectory(e,t,n={}){let r=k.resolve(e),i=n.watchRoot?k.resolve(n.watchRoot):r,a=n.recursive??!1,o=n.reconcileIntervalMs??Z,s=JSON.stringify([r,i,a,o]),c=q.get(s);c||(c={key:s,path:r,watchRoot:i,recursive:a,reconcileIntervalMs:o,listeners:[],nextFallback:{atMs:1/0,elapsedAtMs:1/0}},q.set(s,c),attach(c));let listener=(e,n)=>t(e,n);return c.listeners=[...c.listeners,listener],retainEarlierFallback(c,nextFallback(o)),scheduleFallback(c),{isWatching:()=>c.listeners.includes(listener)&&c.source!==void 0,close(){c.listeners=c.listeners.filter(e=>e!==listener),!(c.listeners.length||q.get(s)!==c)&&(q.delete(s),detach(c),q.size||(clearTimeout(Y),Y=void 0))}}}const Q=/* @__PURE__ */ new Map,$=u(Symbol.for(`openclaw.agentDirPreparedPaths`),e=>{for(let t of e.values())t.close();e.clear()},`shared-state`);function registryPath(e,t,n=!1,r){let i=k.resolve(a(e,t)),o=ae()?.ownsSchemaMaintenance===!0,s=o?void 0:$.get(i);if(s)return s.key;let c=r??normalizeAgentDirRegistryPath(i,t);if(o||!se||!n&&!Q.has(c))return c;let l=[],u={key:c,close:()=>l.forEach(e=>e.close())};$.set(i,u);let d=!1;for(let e=i;k.dirname(e)!==e;e=k.dirname(e)){let t=k.basename(e);l.push(observeOwnedDirectory(k.dirname(e),e=>{d||e!==void 0&&e!==t||(d=!0,ee(i).then(e=>{$.get(i)===u&&e!==c&&($.delete(i),u.close())}).catch(()=>{}).finally(()=>{d=!1}))}))}let f=Math.max(256,Q.size+1);for(let[e,t]of $){if($.size<=f)break;$.delete(e),t.close()}return c}function normalizeAgentDirRegistryPath(e,t=process.env){return te(a(e,t))}function registerResolvedAgentDir(e){let t=registryPath(e.agentDir,e.env,!0),n=Q.get(t)??/* @__PURE__ */ new Set,r=_(e.agentId);return!n.has(r)&&(n.add(r),Q.set(t,n),!0)}function resolveDefaultAgentWorkspaceDir(e=process.env,n=O.homedir){let r=e.OPENCLAW_WORKSPACE_DIR?.trim();if(r)return k.resolve(r);if(e.OPENCLAW_STATE_DIR?.trim())return k.join(d(e,n),`workspace`);let i=p(e,n),a=e.OPENCLAW_PROFILE?.trim();return a&&t(a)!=="default"?k.join(s(a,e,n),`workspace`):k.join(i,`.openclaw`,`workspace`)}resolveDefaultAgentWorkspaceDir();var AgentSelectionRequiredError=class extends Error{constructor(e,t){let n=t?.surface??`this operation`,r=t?.hint??`Select an agent explicitly; CLI callers can pass --agent <id>, channels can add a binding, and ambient services can set their agentId target.`;super(`Multiple agents are configured, but ${n} has no explicit owner. ${r}`),this.code=`AGENT_SELECTION_REQUIRED`,this.name=`AgentSelectionRequiredError`,this.agentIds=e,this.hint=r}};function tryResolveLegacyDataOwnerAgentId(e){let t=readAgentRosterFacts(e);if(t?.legacyDataOwnerAgentId)return t.legacyDataOwnerAgentId.value;let n=tryResolveLegacyDataOwner(e);return t&&(t.legacyDataOwnerAgentId={value:n}),n}function tryResolveLegacyCompatibilityAgentId(t){let n=readAgentRosterFacts(t);if(n?.compatibilityAgentId)return n.compatibilityAgentId.value;let r;if(t.agents?.ownership===`explicit`){let n=e(t.agents.defaults?.systemAgent?.agentId),i=n?_(n):void 0;r=i&&listAgentIds(t).includes(i)?i:void 0}else r=tryResolveLegacyDataOwnerAgentId(t);return n&&(n.compatibilityAgentId={value:r}),r}function tryResolveAmbientOwnerAgentId(t,n){let r=e(n)??e(t.agents?.defaults?.systemAgent?.agentId);return r?_(r):tryResolveLegacyCompatibilityAgentId(t)??tryResolveSoleAgentId(t)}function resolveAgentEntry(e,t){let n=_(t),r=readAgentRosterFacts(e);if(r){let t=(r.entryByNormalizedId??=buildAgentEntryIndex(e)).get(n);return t?t.clone?{...t.entry}:t.entry:void 0}let a=readAgentRosterProperty(e);if(a?.kind===`entries`&&i(a.value)){let e=a.value;for(let t in e){if(!Object.hasOwn(e,t))continue;let r=e[t];if(i(r)&&_(t)===n)return{...r,id:t}}}else if(a?.kind===`list`&&Array.isArray(a.value))return a.value.find(e=>typeof e==`object`&&!!e&&_(e.id)===n)}function buildAgentEntryIndex(e){let t=/* @__PURE__ */ new Map;for(let{entry:n,source:r}of listAgentEntriesWithSource(e)){let e=_(n?.id);t.has(e)||t.set(e,{clone:r.kind===`entries`,entry:n})}return t}function resolveAgentConfig(e,t){let n=_(t),r=resolveAgentEntry(e,n)??(!hasAgentRosterProperty(e)&&n===`main`?{id:n}:void 0);if(!r)return;let i=e.agents?.defaults;return{name:r.name,workspace:r.workspace,workspaceFileMode:r.workspaceFileMode??i?.workspaceFileMode,agentDir:r.agentDir,model:r.model,...r.models?{models:r.models}:{},...r.params?{params:r.params}:{},...r.runtime?{runtime:r.runtime}:{},...hasExplicitModelPolicyAllow(r.modelPolicy)?{modelPolicy:r.modelPolicy}:{},utilityModel:r.utilityModel,decisionModel:r.decisionModel,thinkingDefault:r.thinkingDefault,verboseDefault:r.verboseDefault??i?.verboseDefault,toolProgressDetail:r.toolProgressDetail??i?.toolProgressDetail,reasoningDefault:r.reasoningDefault,fastModeDefault:r.fastModeDefault??i?.fastModeDefault,newSessionPermissionMode:r.newSessionPermissionMode,contextInjection:r.contextInjection,bootstrapMaxChars:r.bootstrapMaxChars,bootstrapTotalMaxChars:r.bootstrapTotalMaxChars,experimental:r.experimental?{...i?.experimental,...r.experimental}:i?.experimental,skills:r.skills,memory:r.memory,humanDelay:r.humanDelay,typingMode:r.typingMode??i?.typingMode,tts:r.tts,...r.compaction?{compaction:r.compaction}:{},contextLimits:r.contextLimits?{...i?.contextLimits,...r.contextLimits}:i?.contextLimits,heartbeat:r.heartbeat,identity:r.identity,groupChat:r.groupChat,subagents:r.subagents,embeddedAgent:r.embeddedAgent,sandbox:r.sandbox,tools:r.tools}}function resolveEffectiveAgentDir(e,t,n){let r=_(t),i=resolveAgentConfig(e,r)?.agentDir?.trim(),o=n?.env??process.env;return i?a(i,o,n?.homedir):k.join(d(o,n?.homedir),`agents`,r,`agent`)}function resolveAgentDir(e,t,n=process.env){let r=resolveEffectiveAgentDir(e,t,{env:n});return registerResolvedAgentDir({agentId:t,agentDir:r,env:n}),r}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=>!E.lstatSync(e.destinationPath,{throwIfNoEntry:!1})))return i}throw Error(`Could not choose recovery paths for ${e[0]??`SQLite files`}`)}function formatAgentDatabaseCorruptionRepairHint(e,t){if(!b(t).includes(`creating its private snapshot:`)&&n(t).some(e=>w(e)||[`SQLITE_CORRUPT`,`SQLITE_NOTADB`].includes(oe(e)??``)||e instanceof Error&&ne(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(ie(e).filter(e=>E.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.`}f(Symbol.for(`openclaw.sessionRowChanges`),`close-and-restart`),f(Symbol.for(`openclaw.sessionRowFactChanges`),`close-and-restart`),f(Symbol.for(`openclaw.sessionRowProjectionChanges`),`close-and-restart`),l(Symbol.for(`openclaw.sessionRowInvalidationSources`),()=>/* @__PURE__ */ new WeakMap),l(Symbol.for(`openclaw.sessionRowPrivateFacts`),()=>/* @__PURE__ */ new WeakMap),l(Symbol.for(`openclaw.sessionRowChangeCaptures`),()=>/* @__PURE__ */ new WeakMap),l(Symbol.for(`openclaw.sessionRowChangeRevision`),()=>({value:0}));const ue=/* @__PURE__ */ new WeakMap;new ce;function isAgentDatabasePreparationRetryable(e){return!h(e)&&(T(e)||g(e,`overloaded`)||e instanceof C&&e.code===`overloaded`)}function createAgentDatabaseInspectionRefusal(e){let t=re(process.env)&&e.reason.includes(`creating its private snapshot:`)&&/(?:code=(?:ENOSPC|EDQUOT)\b|errcode=13\b)/u.test(e.reason),r=n(e.cause).some(e=>e instanceof Error&&e.name===`DataCloneError`),i=!e.pending&&T(e.cause),a=e.cause instanceof m,o={agentId:e.agentId,paths:e.paths,code:e.pending?`agent-database-inspection-pending`:`agent-database-inspection-failed`,reason:i?`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.`:t?`Free space in the reported snapshot cache, then retry the update. This candidate snapshot failure does not require repairing the serving database.`:r?`A worker request could not be serialized. Update OpenClaw and restart the Gateway; repeating database migration will not repair this request.`:a?`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 ue.set(o,e.cause),o}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=_(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 listAgentIds(e).includes(t)&&!isReservedSystemAgentId(t)&&t!==tryResolveAmbientOwnerAgentId(e)&&t!==tryResolveLegacyCompatibilityAgentId(e)}let isAgentDatabaseStartupReadReady=()=>!1;export{tryResolveSoleAgentId as _,isAgentDatabaseStartupReadReady as a,resolveEffectiveAgentDir as c,resolvePersistedSessionStoreOwnerForKey as d,isPerAgentSessionStoreConfig as f,readAgentRosterProperty as g,listGatewayOwnedAgentIds as h,inspectAgentDatabaseAdmission as i,tryResolveLegacyCompatibilityAgentId as l,listAgentIds as m,createAgentDatabaseHeldRefusal as n,AgentSelectionRequiredError as o,listAgentEntries as p,createAgentDatabaseInspectionRefusal as r,resolveAgentDir as s,canIsolateAgentDatabase as t,observeOwnedDirectory as u,isDeeplyFrozenPlainData as v,formatCliCommand as y};