openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.78 kB
JavaScript
import{M as e}from"./transcript-chat-message-content-Cx-VPFHv.mjs";import{c as t}from"./transcript-sqlite-database-admission-Cro6ZHgY.mjs";import{t as n}from"./transcript-state-dir-BTeq06tQ.mjs";import{C as r}from"./transcript-sqlite-schema-facts-C4Tsn8VX.mjs";import{n as i}from"./transcript-agent-id-DmscQLD6.mjs";import{n as a,r as o,s}from"./transcript-openclaw-agent-db.paths-5mfY5--s.mjs";import"./transcript-session-key-DI46891-.mjs";import{i as c,n as l,t as u}from"./transcript-session-sqlite-target-paths-qm0GE1oO.mjs";import{E as d,t as f}from"./session-transcript.worker.js";import{J as p}from"./transcript-openclaw-state-db-cache-DY0tZ0IC.mjs";import{a as m,o as h,t as g}from"./transcript-openclaw-agent-db-owner-read-DYchwk6B.mjs";import _ from"node:path";import{lstatSync as v,readdirSync as y}from"node:fs";function sameSessionTranscriptStorePath(e,n){if(e===n)return!0;if(!e||!n)return!1;let i=t(e),a=t(n);if(!i||!a)return!1;let o=r(e),s=r(n);return o||s?!!(o&&s&&o.namespace===s.namespace&&o.storeId===s.storeId):i.key===a.key&&i.birthtime===a.birthtime}const b=/* @__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=d(Object.fromEntries(Object.keys(e).filter(e=>b.has(e.toUpperCase())).map(t=>[t,e[t]])));return{OPENCLAW_STATE_DIR:n(t),...p(t)?{OPENCLAW_SUPERVISOR_MODE:`external`}:{}}}function captureSessionTranscriptTargetBinding(e){let t=s(e.storePath,e);return{...e,storePath:_.resolve(e.storePath),env:captureSessionTranscriptStorageEnvironment(t?.env??e.env??process.env)}}var x=/* @__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??m({env:t})}async function prepareSqliteTargetFromSessionStorePath(e,t={},n){n?.throwIfAborted();let r=c(e);if(r.agentId)return r;let i=captureSessionTranscriptStorageEnvironment(t.env??process.env),a=h({env:i}),o={storePath:_.resolve(e.trim()),agentId:t.agentId,defaultAgentId:t.defaultAgentId,env:i},{resolveSessionSqliteTargetInWorker:s}=await import(`./transcript-session-transcript-read-worker-runtime-C8oGrkEo.mjs`),l=await a.read(n),u=readSessionStoreRegistryRows(l.result.status===`available`?l.result.entries:l.result);return n?.throwIfAborted(),s({...o,registeredDatabases:u},n)}function resolvePersistedOwners(e,t,n,r){let a=[...new Set(t.filter(t=>n(t.path,e)).map(e=>i(e.agentId)))],o;return a.length===1?hasFilesystemEntry(e,r.onReadError):o=resolveDatabaseOwner(e,r.readCandidates,r.onReadError),{registeredOwners:a,databaseOwner:o}}function resolveDatabaseOwner(e,t,n){if(!hasFilesystemEntry(e,n))return;let r=t?f(e,t):e,a=g(r);return a.status===`owned`?i(a.agentId):void 0}function hasFilesystemEntry(e,t){try{return v(e),!0}catch(e){if(e.code===`ENOENT`)return!1;throw t?.(e),e}}function resolveCustomStoreSqlitePath(e){let t=_.resolve(e.unsuffixedPath),n=_.basename(t,`.sqlite`),r=_.dirname(t),o=i(e.options.defaultAgentId??`main`),s=i(e.options.agentId??o),c=readSessionStoreRegistryRows(e.options.registeredDatabases,e.options.env,e.options.onReadError),u=e.options.isSameDatabasePath??a(),resolvePersistedOwner=t=>{let{registeredOwners:n,databaseOwner:r}=resolvePersistedOwners(t,c,u,e.options);return{effectiveOwner:n.length===1?n[0]:n.length===0?r:void 0,registeredOwners:n}},{registeredOwners:d,effectiveOwner:f}=resolvePersistedOwner(t),resolveSuffixedTarget=t=>{let i=`${n}.${t}`,a=/* @__PURE__ */ new Set;for(let e of c){if(!u(_.dirname(e.path),r))continue;let t=l(_.basename(e.path),i);t!==void 0&&a.add(t)}try{for(let e of y(r)){let t=l(e,i);t!==void 0&&a.add(t)}}catch(t){if(t.code!==`ENOENT`)throw e.options.onReadError?.(t),t}let candidatePathAt=e=>_.join(r,e===1?`${i}.sqlite`:`${i}.${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 s=1;for(let e of o)if(e===s)s+=1;else if(e>s)break;for(let n=s;;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}}},p=resolveSuffixedTarget(o),m=s===o?p:resolveSuffixedTarget(s),h=p.owned,g=m.owned,v=d.length===0&&!hasFilesystemEntry(t,e.options.onReadError),b=f||h||!v?void 0:o,x=f??b,S=s===f||!g&&s===b,C=f?d.length===1?`database-registry`:`database-path`:h?`registered-suffixed`:d.length>1?`ambiguous-registry`:v?`configured-default`:`occupied-unsuffixed`;return{agentId:s,path:S?t:m.path,ownerSource:C,...x?{unsuffixedOwnerAgentId:x}:{}}}function resolveSqliteTargetFromSessionStorePath(e,t={}){let n=c(e),r=t.agentId?i(t.agentId):void 0;if(r&&o(n.path,{agentId:r,env:t.env}))return{agentId:r,path:n.path};if(n.agentId)return n;if(n.shared){let e=readSessionStoreRegistryRows(t.registeredDatabases,t.env,t.onReadError),{registeredOwners:r,databaseOwner:o}=resolvePersistedOwners(n.path,e,t.isSameDatabasePath??a(),t),s=i(t.defaultAgentId??`main`);return{agentId:(r.length===1?r[0]:void 0)??o??s,path:n.path,shared:!0,ownerSource:r.length===1?`database-registry`:o?`database-path`:r.length>1?`ambiguous-registry`:`configured-default`}}return resolveCustomStoreSqlitePath({unsuffixedPath:n.path,options:t})}function listDurableSqliteTargetOwnersForSessionStorePath(e){let t=/* @__PURE__ */ new Set;for(let n of u(e)){let e=resolveDatabaseOwner(n);e&&t.add(e)}return[...t]}function listDurableSqliteTargetPathsForSessionStorePath(e){return u(e).filter((e,t)=>t===0||resolveDatabaseOwner(e)!==void 0)}export{resolveSqliteTargetFromSessionStorePath as a,captureSessionTranscriptTargetBinding as c,readSessionStoreRegistryRows as i,sameSessionTranscriptStorePath as l,listDurableSqliteTargetOwnersForSessionStorePath as n,x as o,prepareSqliteTargetFromSessionStorePath as r,captureSessionTranscriptStorageEnvironment as s,SessionStoreRegistryReadRequired as t};