openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.96 kB
JavaScript
import{t as e}from"./transcript-errno-CsW5NI8i.mjs";import{i as t,n}from"./transcript-path-guards-DYqTo0Vr.mjs";import{c as r}from"./transcript-sqlite-worker-identity-C2ykgpDo.mjs";import{n as i,t as a}from"./transcript-state-dir-BTeq06tQ.mjs";import{r as o}from"./transcript-path-existence-DsAt-_G2.mjs";import s from"node:path";import{statSync as c}from"node:fs";const l=new i(64);function resolveDatabasePath(e={}){return e.path===void 0?resolveOpenClawStateSqlitePath(e.env??process.env):r(s.resolve(e.path))}function existingPathOrUndefined(t){try{return c(t),t}catch(t){if(e(t,`ENOENT`))return;throw t}}function resolveOpenClawStateSqliteDir(e=process.env){return s.dirname(resolveOpenClawStateSqlitePath(e))}function resolveOpenClawStateSqlitePath(e=process.env){let t=a(e),n=l.peek(t);if(n!==void 0)return n;let i=r(s.join(t,`state`,`openclaw.sqlite`));return l.set(t,i),i}function resolveOpenClawStateDirForDatabasePath(e){let t=s.dirname(s.resolve(e));return s.basename(t)===`state`?s.dirname(t):t}function resolveQuarantineStorePath(e){return s.join(resolveOpenClawStateSqliteDir(e),`openclaw-quarantine.sqlite`)}function resolveOpenClawAgentDatabaseStoredPath(e,r){let i=process.platform===`win32`,a=resolveOpenClawStateDirForDatabasePath(e),c=i?t(a):a,l=i&&s.isAbsolute(r)?r:s.resolve(r),u=i?t(l):l;if(!s.isAbsolute(c)||!s.isAbsolute(u))return l;let d=s.relative(c,u),f=d.startsWith(`..`)||s.isAbsolute(d)||i&&!n(a,l);if(f){let e=o(c);if(i&&!n(e,l)||(c=i?t(e):e,!s.isAbsolute(c)))return l;d=s.relative(c,u)}if(d.startsWith(`..`)||s.isAbsolute(d))return l;if(f&&!i)return d;let p=[c,s.toNamespacedPath(c)].map(e=>`${e}${e.endsWith(s.sep)?``:s.sep}`).find(e=>r.startsWith(e));return s.isAbsolute(r)&&p!==void 0?r.slice(p.length):d}function resolveOpenClawRegisteredAgentDatabasePath(e,t){return s.isAbsolute(t)?t:`${resolveOpenClawStateDirForDatabasePath(e)}${s.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};