openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.47 kB
JavaScript
import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{c as isPathInside,n as LruCache,t as resolveStateDir,u as normalizeWindowsPathPreservingCase}from"./state-dir-C22DK7p0.mjs";import{i as resolveIdentityPathViaExistingAncestorSync}from"./path-existence-4c3xWldM.mjs";import{c as normalizeDatabasePath}from"./sqlite-worker-identity-gGA4fE_R.mjs";import{statSync}from"node:fs";import path from"node:path";
//!src/state/openclaw-state-db.paths.ts
const stateSqlitePaths=new LruCache(64);function resolveDatabasePath(e={}){return e.path===void 0?resolveOpenClawStateSqlitePath(e.env??process.env):normalizeDatabasePath(path.resolve(e.path))}function existingPathOrUndefined(e){try{statSync(e);return e}catch(e){if(hasErrnoCode(e,`ENOENT`))return;throw e}}function resolveOpenClawStateSqliteDir(e=process.env){return path.dirname(resolveOpenClawStateSqlitePath(e))}function resolveOpenClawStateSqlitePath(e=process.env){const t=resolveStateDir(e);const n=stateSqlitePaths.peek(t);if(n!==void 0)return n;const r=normalizeDatabasePath(path.join(t,`state`,`openclaw.sqlite`));stateSqlitePaths.set(t,r);return r}function resolveOpenClawStateDirForDatabasePath(e){const t=path.dirname(path.resolve(e));return path.basename(t)===`state`?path.dirname(t):t}function resolveQuarantineStorePath(e){return path.join(resolveOpenClawStateSqliteDir(e),`openclaw-quarantine.sqlite`)}function resolveOpenClawAgentDatabaseStoredPath(e,t){const n=process.platform===`win32`;const r=resolveOpenClawStateDirForDatabasePath(e);let i=n?normalizeWindowsPathPreservingCase(r):r;const a=n&&path.isAbsolute(t)?t:path.resolve(t);const o=n?normalizeWindowsPathPreservingCase(a):a;if(!path.isAbsolute(i)||!path.isAbsolute(o))return a;let s=path.relative(i,o);const c=s.startsWith(`..`)||path.isAbsolute(s)||n&&!isPathInside(r,a);if(c){const e=resolveIdentityPathViaExistingAncestorSync(i);if(n&&!isPathInside(e,a))return a;i=n?normalizeWindowsPathPreservingCase(e):e;if(!path.isAbsolute(i))return a;s=path.relative(i,o)}if(s.startsWith(`..`)||path.isAbsolute(s))return a;if(c&&!n)return s;const l=[i,path.toNamespacedPath(i)].map(e=>`${e}${e.endsWith(path.sep)?``:path.sep}`).find(e=>t.startsWith(e));return path.isAbsolute(t)&&l!==void 0?t.slice(l.length):s}function resolveOpenClawRegisteredAgentDatabasePath(e,t){return path.isAbsolute(t)?t:`${resolveOpenClawStateDirForDatabasePath(e)}${path.sep}${t}`}function describeAgentPathMigration(e){const{relativized:t,reanchored:n,deleted:r}=e;if(t===0&&n.length===0&&r.length===0)return[];const i=n.length+r.length;const a=[`${t} relativized`,n.length>0&&`${n.length} re-anchored`,r.length>0&&`${r.length} removed`].filter(Boolean);return[`Migrated agent database registry paths to state-relative storage${i>0?` (${a.join(`, `)})`:``}`,...n.map(e=>`Re-anchored agent database registry path ${e} to the current state directory`),...r.map(e=>`Removed duplicate agent database registry path ${e}`)]}function warnAgentPathMigration(e,t,n){if(t.reanchored.length===0&&t.deleted.length===0)return;e.warn(`agent database registry rows re-anchored or removed during v9 migration`,{reanchored:t.reanchored,deleted:t.deleted,path:n})}export{resolveOpenClawRegisteredAgentDatabasePath as a,resolveQuarantineStorePath as c,resolveOpenClawAgentDatabaseStoredPath as i,warnAgentPathMigration as l,existingPathOrUndefined as n,resolveOpenClawStateDirForDatabasePath as o,resolveDatabasePath as r,resolveOpenClawStateSqlitePath as s,describeAgentPathMigration as t};