UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.12 kB
import{n as e}from"./transcript-agent-id-DmscQLD6.mjs";import{n as t}from"./transcript-openclaw-agent-db.paths-5mfY5--s.mjs";import"./transcript-session-key-DI46891-.mjs";import{a as n}from"./transcript-paths-EL7FYwW9.mjs";import{t as r}from"./session-transcript.worker.js";import{h as i,x as a}from"./transcript-agent-scope-config-D354VjAZ.mjs";import"./transcript-openclaw-agent-trajectory-storage-migration-DjoMAPIY.mjs";import{n as o,t as s}from"./transcript-targets-configured-agents-ZCfYBBxv.mjs";import{a as c}from"./transcript-session-sqlite-target-BaCO1IZI.mjs";import{t as l}from"./transcript-legacy.default-agent-owner-DiLLYgpC.mjs";import{t as u}from"./transcript-targets-discovery.native-OUy_jLR1.mjs";function resolveGatewaySessionStoreCandidates(e,t,r,a=!1,o=process.env,s){let c=r?.get(t);if(c)return c;if(!s)throw Error(`Session store discovery must be prepared in the read worker`);let l=e.session?.store,u={agentId:t,storePath:n(l,{agentId:t,env:o})},d={existing:s(t,!r&&a&&!i(l)?u.storePath:void 0),fallback:u};return r?.set(t,d),d}function resolveGatewaySessionStoreLookupCandidates(t){let r=s(t.cfg,t.agentId);if(!r&&t.registeredDatabases){let i=t.registeredDatabases.filter(n=>e(n.agentId)===t.agentId).map(e=>({agentId:e.agentId,path:e.path}));return{configured:r,fallback:{agentId:t.agentId,storePath:n(t.cfg.session?.store,{agentId:t.agentId,env:t.env})},candidates:i.map(e=>({agentId:e.agentId,storePath:e.path})),readSources:i}}let{existing:i,fallback:a}=resolveGatewaySessionStoreCandidates(t.cfg,t.agentId,t.targetDiscoveryCache,r,t.env,t.resolveExistingTargets);return{configured:r,fallback:a,candidates:r?[a,...i.filter(e=>e.storePath!==a.storePath)]:i}}function sessionStoreRoutingConfig(e){return{agents:{ownership:`explicit`,entries:Object.fromEntries(e.agentIds.map(e=>[e,{}])),defaults:{sessionStore:{agentId:e.compatibilityAgentId}}},session:{store:e.store}}}function resolveGatewaySessionStoreReadSources(e){let n=sessionStoreRoutingConfig(e.routing);return a(n,()=>{let i=e.registeredDatabases.filter(e=>e.schemaVersion===42),a=/* @__PURE__ */ new Set([...o(n),...i.map(e=>e.agentId)]),s=t(),d=u(n,{env:e.env,registeredDatabases:i,readCandidates:e.candidates,isSameDatabasePath:s}),f=/* @__PURE__ */ new Map,bindCurrentSource=t=>(e.candidates&&r(t.path,e.candidates),s(t.path,t.path),t.agentId===e.currentSource.agentId&&s(t.path,e.currentSource.path)?e.currentSource:t);for(let t of a){let r,a=!1;try{let{candidates:o,readSources:u}=resolveGatewaySessionStoreLookupCandidates({...e,cfg:n,agentId:t,registeredDatabases:i,resolveExistingTargets:d});if(r=[],u)a=!0,r=u;else for(let t of o){let a=c(t.storePath,{agentId:t.agentId,defaultAgentId:l(n),env:e.env,registeredDatabases:i,readCandidates:e.candidates,isSameDatabasePath:s});if(a.ownerSource===`ambiguous-registry`){r.length=0;break}r.push({agentId:a.agentId??t.agentId,path:a.path})}let p=[];for(let e of r){let t=bindCurrentSource(e);p.some(e=>(!a||e.agentId===t.agentId)&&s(e.path,t.path))||p.push(t)}f.set(t,p)}catch{f.set(t,[]);continue}}return{sources:Object.fromEntries(f)}})}export{resolveGatewaySessionStoreReadSources};