openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 7.75 kB
JavaScript
import{r as e}from"./openclaw-state-read-semver-CqfGj9gv.mjs";import{H as t,U as n}from"./openclaw-state-read-sqlite-readonly-worker-umlSCyCR.mjs";import{o as r}from"./openclaw-state-read-sqlite-database-admission-Ck6VG7rE.mjs";import{a as i}from"./openclaw-state-read-tmp-openclaw-dir-C3Ynn93H.mjs";import{O as a}from"./openclaw-state-read-openclaw-state-db-cache-BVY8IYkn.mjs";import{s as o}from"./openclaw-state-read-openclaw-state-db-contract-DiFTYPe3.mjs";import{a as s}from"./openclaw-state-read-sqlite-busy-timeout-D5Khm-oR.mjs";import{h as c,u as l}from"./openclaw-state-read-sqlite-schema-facts-DxLfPKu-.mjs";import{n as u,r as d}from"./openclaw-state-read-node-sqlite-UqZdY7HG.mjs";import{n as f}from"./openclaw-state-read-agent-id-DmscQLD6.mjs";import{n as p,t as m}from"./openclaw-state-read-gateway-supervision-queMstQ7.mjs";import"./openclaw-state-read-session-key-DaKMXMbu.mjs";import{b as h,l as g,v as _,y as v}from"./openclaw-state-read-agent-scope-config-DBTVDK8I.mjs";import{C as y,P as b,a as x,i as S,t as C,v as w,x as T}from"./openclaw-state-read-session-store-read-candidates-Mon1wMui.mjs";import{a as E,i as D}from"./openclaw-state-read-openclaw-agent-db-registry-listing-0iIGDbl2.mjs";import{lstatSync as O,readdirSync as k}from"node:fs";import A from"node:path";import{isMainThread as j}from"node:worker_threads";function resolveSessionStoreCompatibilityAgentId(e){let t=e.agents?.defaults?.sessionStore?.agentId?.trim();return t?f(t):g(e)??`main`}function inspectOpenClawAgentDatabaseOwner(e,t){if(j&&S()){let n=r(e,T,()=>void 0);if(!t?.revalidateSchema&&n?.role===`agent`&&n.agentId)return{status:`owned`,agentId:f(n.agentId)};throw Error(`PostgreSQL agent ownership requires worker preparation before synchronous inspection; use the asynchronous agent database preparation owner.`)}let n,i;try{let r=A.resolve(e),a=b.databases.get(r);if(!t?.revalidateSchema&&a?.db.isOpen&&!b.failures.has(r))return c(a.db,()=>w(a.db,e)),b.idleTimers.get(a.db)?.refresh(),{status:`owned`,agentId:a.agentId};n=S()?u(d(e),{timeout:o}):p(e,{readOnly:!0}),s(n,o),S()?i=x(n,void 0,e,!0):t?.revalidateSchema&&l(n),w(i??n,e);let m=y(i??n);return m?m.role!==`agent`||!m.agentId?{status:`unreadable`}:{status:`owned`,agentId:f(m.agentId)}:{status:`unowned`}}catch{return{status:`unreadable`}}finally{try{i?.close()}finally{n?.close()}}}const M=/* @__PURE__ */ new Set([`OPENCLAW_STATE_DIR`,`OPENCLAW_SUPERVISOR_MODE`,`OPENCLAW_HOME`,`HOME`,`USERPROFILE`,`PREFIX`,`ANDROID_DATA`,`OPENCLAW_TEST_FAST`,`VITEST`,`VITEST_POOL_ID`,`VITEST_WORKER_ID`,`NODE_ENV`]);function captureSessionTranscriptStorageEnvironment(e){let t=a(Object.fromEntries(Object.keys(e).filter(e=>M.has(e.toUpperCase())).map(t=>[t,e[t]])));return{OPENCLAW_STATE_DIR:i(t),...m(t)?{OPENCLAW_SUPERVISOR_MODE:`external`}:{}}}var N=/* @__PURE__ */ e({SessionStoreRegistryReadRequired:()=>SessionStoreRegistryReadRequired,listDurableSqliteTargetOwnersForSessionStorePath:()=>listDurableSqliteTargetOwnersForSessionStorePath,listDurableSqliteTargetPathsForSessionStorePath:()=>listDurableSqliteTargetPathsForSessionStorePath,prepareSqliteTargetFromSessionStorePath:()=>prepareSqliteTargetFromSessionStorePath,readSessionStoreRegistryRows:()=>readSessionStoreRegistryRows,resolveSqliteTargetFromSessionStorePath:()=>resolveSqliteTargetFromSessionStorePath}),SessionStoreRegistryReadRequired=class extends Error{};function readSessionStoreRegistryRows(e,t,n){if(e&&`status`in e){if(e.status===`deferred`)throw new SessionStoreRegistryReadRequired(`Session target discovery requires registry rows`);let t=/* @__PURE__ */ Error(`Session target registry is unavailable`);throw n?.(t),t}return e??D({env:t})}async function prepareSqliteTargetFromSessionStorePath(e,t={},n){n?.throwIfAborted();let r=h(e);if(r.agentId)return r;let i=captureSessionTranscriptStorageEnvironment(t.env??process.env),a=E({env:i}),o={storePath:A.resolve(e.trim()),agentId:t.agentId,defaultAgentId:t.defaultAgentId,env:i},{resolveSessionSqliteTargetInWorker:s}=await import(`./openclaw-state-read-session-transcript-read-worker-runtime-BcXjnapU.mjs`),c=await a.read(n),l=readSessionStoreRegistryRows(c.result.status===`available`?c.result.entries:c.result);return n?.throwIfAborted(),s({...o,registeredDatabases:l},n)}function resolvePersistedOwners(e,t,n,r){let i=[...new Set(t.filter(t=>n(t.path,e)).map(e=>f(e.agentId)))],a;return i.length===1?hasFilesystemEntry(e,r.onReadError):a=resolveDatabaseOwner(e,r.readCandidates,r.onReadError),{registeredOwners:i,databaseOwner:a}}function resolveDatabaseOwner(e,t,n){if(!hasFilesystemEntry(e,n))return;let r=inspectOpenClawAgentDatabaseOwner(t?C(e,t):e);return r.status===`owned`?f(r.agentId):void 0}function hasFilesystemEntry(e,t){try{return O(e),!0}catch(e){if(e.code===`ENOENT`)return!1;throw t?.(e),e}}function resolveCustomStoreSqlitePath(e){let n=A.resolve(e.unsuffixedPath),r=A.basename(n,`.sqlite`),i=A.dirname(n),a=f(e.options.defaultAgentId??`main`),o=f(e.options.agentId??a),s=readSessionStoreRegistryRows(e.options.registeredDatabases,e.options.env,e.options.onReadError),c=e.options.isSameDatabasePath??t(),resolvePersistedOwner=t=>{let{registeredOwners:n,databaseOwner:r}=resolvePersistedOwners(t,s,c,e.options);return{effectiveOwner:n.length===1?n[0]:n.length===0?r:void 0,registeredOwners:n}},{registeredOwners:l,effectiveOwner:u}=resolvePersistedOwner(n),resolveSuffixedTarget=t=>{let n=`${r}.${t}`,a=/* @__PURE__ */ new Set;for(let e of s){if(!c(A.dirname(e.path),i))continue;let t=v(A.basename(e.path),n);t!==void 0&&a.add(t)}try{for(let e of k(i)){let t=v(e,n);t!==void 0&&a.add(t)}}catch(t){if(t.code!==`ENOENT`)throw e.options.onReadError?.(t),t}let candidatePathAt=e=>A.join(i,e===1?`${n}.sqlite`:`${n}.${e}.sqlite`),o=[...a].toSorted((e,t)=>e-t);for(let e of o){let n=candidatePathAt(e);if(resolvePersistedOwner(n).effectiveOwner===t)return{owned:!0,path:n}}let l=1;for(let e of o)if(e===l)l+=1;else if(e>l)break;for(let n=l;;n+=1){let r=candidatePathAt(n),i=resolvePersistedOwner(r);if(i.effectiveOwner===t)return{owned:!0,path:r};if(i.registeredOwners.length===0&&!hasFilesystemEntry(r,e.options.onReadError))return{owned:!1,path:r}}},d=resolveSuffixedTarget(a),p=o===a?d:resolveSuffixedTarget(o),m=d.owned,h=p.owned,g=l.length===0&&!hasFilesystemEntry(n,e.options.onReadError),_=u||m||!g?void 0:a,y=u??_,b=o===u||!h&&o===_,x=u?l.length===1?`database-registry`:`database-path`:m?`registered-suffixed`:l.length>1?`ambiguous-registry`:g?`configured-default`:`occupied-unsuffixed`;return{agentId:o,path:b?n:p.path,ownerSource:x,...y?{unsuffixedOwnerAgentId:y}:{}}}function resolveSqliteTargetFromSessionStorePath(e,r={}){let i=h(e),a=r.agentId?f(r.agentId):void 0;if(a&&n(i.path,{agentId:a,env:r.env}))return{agentId:a,path:i.path};if(i.agentId)return i;if(i.shared){let e=readSessionStoreRegistryRows(r.registeredDatabases,r.env,r.onReadError),{registeredOwners:n,databaseOwner:a}=resolvePersistedOwners(i.path,e,r.isSameDatabasePath??t(),r),o=f(r.defaultAgentId??`main`);return{agentId:(n.length===1?n[0]:void 0)??a??o,path:i.path,shared:!0,ownerSource:n.length===1?`database-registry`:a?`database-path`:n.length>1?`ambiguous-registry`:`configured-default`}}return resolveCustomStoreSqlitePath({unsuffixedPath:i.path,options:r})}function listDurableSqliteTargetOwnersForSessionStorePath(e){let t=/* @__PURE__ */ new Set;for(let n of _(e)){let e=resolveDatabaseOwner(n);e&&t.add(e)}return[...t]}function listDurableSqliteTargetPathsForSessionStorePath(e){return _(e).filter((e,t)=>t===0||resolveDatabaseOwner(e)!==void 0)}export{inspectOpenClawAgentDatabaseOwner as a,captureSessionTranscriptStorageEnvironment as i,resolveSqliteTargetFromSessionStorePath as n,resolveSessionStoreCompatibilityAgentId as o,N as r,readSessionStoreRegistryRows as t};