UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.89 kB
import{Bt as e,Mt as t,Tt as n,zt as r}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{Lt as i}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{Lt as a,Pt as o}from"./openclaw-state-read-src-RL5xtYG2.mjs";import{statSync as s}from"node:fs";import c from"node:path";const l=new e(64);function resolveDatabasePath(e={}){return e.path===void 0?resolveOpenClawStateSqlitePath(e.env??process.env):i(c.resolve(e.path))}function existingPathOrUndefined(e){try{return s(e),e}catch(e){if(o(e,`ENOENT`))return;throw e}}function resolveOpenClawStateSqliteDir(e=process.env){return c.dirname(resolveOpenClawStateSqlitePath(e))}function resolveOpenClawStateSqlitePath(e=process.env){let t=r(e),n=l.peek(t);if(n!==void 0)return n;let a=i(c.join(t,`state`,`openclaw.sqlite`));return l.set(t,a),a}function resolveOpenClawStateDirForDatabasePath(e){let t=c.dirname(c.resolve(e));return c.basename(t)===`state`?c.dirname(t):t}function resolveQuarantineStorePath(e){return c.join(resolveOpenClawStateSqliteDir(e),`openclaw-quarantine.sqlite`)}function resolveOpenClawAgentDatabaseStoredPath(e,r){let i=process.platform===`win32`,o=resolveOpenClawStateDirForDatabasePath(e),s=i?t(o):o,l=i&&c.isAbsolute(r)?r:c.resolve(r),u=i?t(l):l;if(!c.isAbsolute(s)||!c.isAbsolute(u))return l;let d=c.relative(s,u),f=d.startsWith(`..`)||c.isAbsolute(d)||i&&!a(o,l);if(f){let e=n(s);if(i&&!a(e,l)||(s=i?t(e):e,!c.isAbsolute(s)))return l;d=c.relative(s,u)}if(d.startsWith(`..`)||c.isAbsolute(d))return l;if(f&&!i)return d;let p=[s,c.toNamespacedPath(s)].map(e=>`${e}${e.endsWith(c.sep)?``:c.sep}`).find(e=>r.startsWith(e));return c.isAbsolute(r)&&p!==void 0?r.slice(p.length):d}function resolveOpenClawRegisteredAgentDatabasePath(e,t){return c.isAbsolute(t)?t:`${resolveOpenClawStateDirForDatabasePath(e)}${c.sep}${t}`}function describeAgentPathMigration(e){let{relativized:t,reanchored:n,deleted:r}=e;if(t===0&&n.length===0&&r.length===0)return[];let i=n.length+r.length,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){(t.reanchored.length!==0||t.deleted.length!==0)&&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};