openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 12.9 kB
JavaScript
import{i as e}from"./transcript-global-singleton-DIJgobpU.mjs";import{n as t,t as n,x as r}from"./transcript-plugin-instance-invocation-7y9lfaeO.mjs";import{g as i}from"./transcript-agent-creation-claim-Da8lP1e6.mjs";import{l as a,s as o,t as s}from"./transcript-state-dir-DEo0wD2Q.mjs";import{n as c}from"./transcript-agent-id-DmscQLD6.mjs";import{n as l}from"./transcript-openclaw-agent-db.paths-DbFl2s5M.mjs";import"./transcript-session-key-MDDhuEG9.mjs";import"./transcript-openclaw-agent-db-BuScZLmj.mjs";import{t as u}from"./transcript-agent-deletion-journal-status-BsvZaPJC.mjs";import{d,m as f}from"./transcript-agent-scope-config-l-KZcQvf.mjs";import{n as p}from"./transcript-immutable-data-Dv9CHHEc.mjs";import{i as m}from"./transcript-session-sqlite-target-paths-C_ECqUX6.mjs";import{a as h}from"./transcript-paths-CuGliRzI.mjs";import{a as g,h as _}from"./transcript-openclaw-agent-db-borrower-BzSv4n5d.mjs";import"./transcript-openclaw-agent-db-contract-DXUC0rkZ.mjs";import"./transcript-session-canonical-key-9wlUjrYM.mjs";import{n as v}from"./transcript-targets-configured-agents-DkRzTT-S.mjs";import{i as y,o as b}from"./transcript-openclaw-agent-db-registry-listing-hSVmRkvc.mjs";import"./transcript-agent-scope-B3Lazcye.mjs";import"./transcript-main-session-kIGO4exC.mjs";import{a as x,f as S,i as C,o as w,r as T,u as E}from"./transcript-targets-CmXj-vJd.mjs";import{i as D,n as O,r as k}from"./transcript-agent-deletion-discovery-BprDt56b.mjs";import"./transcript-agent-database-preparation-context-Cnho682S.mjs";import{i as A,t as j}from"./transcript-session-actor-storage-binding-BeZZBFjA.mjs";import"./transcript-session-accessor.memory-exact-read-zFq3jq1X.mjs";import{n as M}from"./transcript-targets-discovery.native-B8PzBbMW.mjs";import N from"node:path";import P from"node:fs";import"node:util";Object.getOwnPropertyDescriptor(Promise.prototype,`then`),Object.getOwnPropertyDescriptor(Promise,Symbol.species);const F=e(Symbol.for(`openclaw.pluginRuntimeExecutionFrame`),()=>class RuntimeFrame extends n{constructor(e,t,n,r=e.invocation){super(e,r),this.gatewayScope=t,this.generationRegistry=n}get runtimePluginId(){return this.gatewayScope?.pluginId}withScopes(e){return new RuntimeFrame(e,this.gatewayScope,this.generationRegistry)}});function getPluginRuntimeExecutionFrame(e=t()){return e instanceof F?e:void 0}const{getGatewayContextBindingSlot:I,prepareGatewayContextBindingOwner:L}=e(Symbol.for(`openclaw.gatewayContextBindingOwner`),()=>{let e=Symbol(`gatewayContextBindingOwner`);class GatewayContextBindingOwner{#e;constructor(e){this.#e=e,Object.setPrototypeOf(this,null)}static read(e,t){return typeof e==`object`&&e&&#e in e&&e.#e===t?e:void 0}}function readSlot(t){let n=Object.getOwnPropertyDescriptor(t,e)?.value;return GatewayContextBindingOwner.read(n,t)}function prepareOwner(t){return readSlot(t)||Object.defineProperty(t,e,{value:new GatewayContextBindingOwner(t)}),t}return{getGatewayContextBindingSlot:readSlot,prepareGatewayContextBindingOwner:prepareOwner}}),{bindGatewayContextResolver:R,getGatewayContextLifetime:z,getGatewayContextResolver:B,clearGatewayContextResolver:V}=e(Symbol.for(`openclaw.gatewayContextBindings`),()=>{let e=Symbol(`gatewayContextBinding`),t=Symbol(`gatewayContextLifetime`);class GatewayContextBinding{#e;#t;constructor(e){this.#e=e,Object.setPrototypeOf(this,null)}static read(e,t){return typeof e==`object`&&e&&#e in e&&e.#e===t?e:void 0}static get(e){return e.#t}static set(e,t){e.#t=t}}class GatewayContextLifetime{#e;#t=new AbortController;constructor(e){this.#e=e,Object.setPrototypeOf(this,null)}static read(e,t){return typeof e==`object`&&e&&#e in e&&e.#e===t?e.#t:void 0}}function getGatewayContextBinding(t){let n=I(t),r=n&&Object.getOwnPropertyDescriptor(n,e)?.value;return GatewayContextBinding.read(r,t)}function getLifetime(e){let n=Object.getOwnPropertyDescriptor(e,t)?.value,r=GatewayContextLifetime.read(n,e);if(r)return r;let i=new GatewayContextLifetime(e);return Object.defineProperty(e,t,{value:i}),GatewayContextLifetime.read(i,e)}function bindResolver(t,n){if(n){L(t);let r=getGatewayContextBinding(t);if(!r){let n=I(t);r=new GatewayContextBinding(t),Object.defineProperty(n,e,{value:r})}GatewayContextBinding.set(r,n)}}function readResolver(e){let t=getGatewayContextBinding(e);return t?GatewayContextBinding.get(t):void 0}function clearResolver(e){let t=getGatewayContextBinding(e),n=t!==void 0&&GatewayContextBinding.get(t)!==void 0;return t&&GatewayContextBinding.set(t,void 0),n}return{bindGatewayContextResolver:bindResolver,getGatewayContextLifetime:getLifetime,getGatewayContextResolver:readResolver,clearGatewayContextResolver:clearResolver}});e(Symbol.for(`openclaw.expiredPluginRegistryScopeError`),()=>class extends Error{constructor(){super(`Plugin registry scope is no longer available`)}});function getPluginRuntimeGatewayRequestScope(){return getPluginRuntimeExecutionFrame()?.gatewayScope}const H=/* @__PURE__ */ new WeakMap;function createGatewayConfiguredDatabaseMatcher(e,t){let n=D(),r=b({env:t}),i=JSON.stringify([s(t),o(t),a(`.`)]),c=p(e)?H.get(e):void 0,u=c&&c.admission===n&&c.registryToken===r&&c.context===i?c.paths:new Set(x(e,{env:t}));u!==c?.paths&&p(e)&&H.set(e,{admission:n,registryToken:r,context:i,paths:u});let d,f=u.values();return e=>{if(u.has(e))return!0;if(!P.statSync(e,{throwIfNoEntry:!1}))return!1;d??={key:l().createIndex(),paths:/* @__PURE__ */ new Set};let t=d.key(e);if(d.paths.has(t))return!0;for(let e of f)try{if(!P.statSync(e,{throwIfNoEntry:!1}))continue;let n=d.key(e);if(d.paths.add(n),n===t)return!0}catch{}return!1}}function storeTargetKey(e){return`${e.agentId}\0${e.storePath}`}function isStorePathTemplate(e){return typeof e==`string`&&e.includes(`{agentId}`)}function resolveCombinedDatabasePath(e,t){let n=[...new Set(e.map(e=>r(t.get(storeTargetKey(e)),`physical store`).storePath))];return n.length===1?r(n[0],`database path at 0`):`(multiple)`}function discoveryReadOptions(e){return e?{env:e.env,readCandidates:e.readCandidates,registeredDatabases:(e.snapshot?.registeredAgentDatabases??[]).filter(e=>e.schemaVersion===38)}:{}}function gatewayDiscoveryReadOptions(e,t){let n=createGatewayRetainedStoreMatcher(e,t),r=t?.recoveryExclusions;return{...discoveryReadOptions(t),excludeTarget:e=>{let t=m(e.storePath).path;return r?.agentIds.includes(e.agentId)===!0||r?.storePaths.includes(e.storePath)===!0||r?.databasePaths.includes(t)===!0||!!n(t,e.agentId)}}}function resolveSharedStoreRowOwner(e,t,n,r){let i=h(e.session?.store,{agentId:S(e),env:r});if(!n.has(i))return;let a=d(e);return a.kind===`configured`?{agentId:a.agentId,target:t}:void 0}function createGatewayRetainedStoreMatcher(e,t){let n=discoveryReadOptions(t),r=n.env??process.env,readConfiguredTargets=t=>w(e,{env:r,...n,excludeTarget:e=>t(m(e.storePath).path,e.agentId)}),a=t?void 0:u(i(r)),o=t?.snapshot??(a&&{retainedDeletions:a,registeredAgentDatabases:y({env:r})});if(!t&&!o&&getPluginRuntimeGatewayRequestScope())throw Error(`Session discovery requires worker preparation; await the asynchronous session store loader.`);return t||o?k(r,readConfiguredTargets,o,`database`,`runtime-discovery`):O(r,readConfiguredTargets,`database`,`runtime-discovery`)}function capturePhysicalStoreTargets(){let e=/* @__PURE__ */ new Map;return{physicalTargets:e,onResolvedTarget:(t,n)=>{e.set(storeTargetKey(t),n)}}}let U;function resolvePreparedConfiguredSessionStoreTargets(e,t){let n=gatewayDiscoveryReadOptions(e,t),r=t?void 0:b(),a=t?void 0:u(i()),o=t?void 0:U;if(o?.cfg===e&&o.registryToken===r&&o.deletionFacts===a)return o.resolved;let s=e.session?.store,l=c(S(e)),d=v(e),f=new Set(d),p=[],{physicalTargets:m,onResolvedTarget:g}=capturePhysicalStoreTargets(),_,x=E([...(n.registeredDatabases??y()).map(({agentId:e,path:t})=>({agentId:e,storePath:t})),...d.map(e=>({agentId:e,storePath:h(s,{agentId:e,env:n.env})}))].filter(e=>!n.excludeTarget(e)),{defaultAgentId:l,...n,onResolvedTarget:g,onDiagnostic:e=>p.push(e.message),onSharedTarget:(t,r)=>{_??=resolveSharedStoreRowOwner(e,t,r,n.env)}}),C=Object.freeze({configuredAgentIds:f,defaultAgentId:l,diagnostics:Object.freeze(p),durableStorePath:resolveCombinedDatabasePath(x,m),durableTargets:Object.freeze(x.map(e=>Object.freeze({...e}))),incognitoTargets:[],sharedStoreRowOwner:_,physicalTargets:m,storeConfig:s});return r&&(U={cfg:e,registryToken:r,deletionFacts:a,resolved:C}),C}function listMemorySessionStoreTargets(e){let t=j({env:e}),n=t?N.resolve(t.path,`../../../..`):s(e),r=A.list().filter(e=>N.resolve(e.path,`../../../..`)===n).map(e=>({agentId:e.agentId,storePath:e.path}));return t&&!r.some(e=>e.storePath===t.path)&&r.push({agentId:t.agentId,storePath:t.path}),r}function resolveGatewaySessionStoreTopology(e,t){let n=gatewayDiscoveryReadOptions(e,t.discovery),r=e.session?.store,i=[],a=typeof t.agentId==`string`&&t.agentId.trim()?c(t.agentId):void 0,o=t.includeIncognito===!1?[]:listMemorySessionStoreTargets(n.env).filter(e=>!a||e.agentId===a);if(t.configuredAgentsOnly===!0&&!a)return{...resolvePreparedConfiguredSessionStoreTargets(e,t.discovery),incognitoTargets:o};let s=c(S(e)),{physicalTargets:l,onResolvedTarget:u}=capturePhysicalStoreTargets();if(r&&!isStorePathTemplate(r)){let t=[.../* @__PURE__ */ new Set([...f(e).map(e=>c(e.id)),...M(e,n),s,...a?[a]:[]])],d;return{defaultAgentId:s,diagnostics:i,durableTargets:E(t.map(e=>({agentId:e,storePath:h(r,{agentId:e,env:n.env})})).filter(e=>!n.excludeTarget(e)),{defaultAgentId:s,...n,onResolvedTarget:u,onDiagnostic:e=>i.push(e.message),onSharedTarget:(t,r)=>{d??=resolveSharedStoreRowOwner(e,t,r,n.env)}}),incognitoTargets:o,requestedAgentId:a,preparedAgentIds:a?new Set(t):void 0,sharedStoreRowOwner:d,physicalTargets:l,storeConfig:r}}return{defaultAgentId:s,diagnostics:i,durableTargets:a?E(T(e,a,n),{defaultAgentId:s,onResolvedTarget:u,...n}):C(e,{onResolvedTarget:u,...n}),incognitoTargets:o,physicalTargets:l,requestedAgentId:a,preparedAgentIds:a?/* @__PURE__ */ new Set([a]):void 0,storeConfig:r}}function resolveGatewaySessionStoreTargets(e,t={}){let n=gatewayDiscoveryReadOptions(e,t.discovery);t.agentId?.trim()&&g(t.agentId,{env:n.env});let r=resolveGatewaySessionStoreTopology(e,t);if(t.preserveSentinelOwners===`physical`){let{physicalTargets:t,onResolvedTarget:i}=capturePhysicalStoreTargets(),a=/* @__PURE__ */ new Map,o=C(e,{...n,onResolvedTarget:({agentId:e},t)=>a.set(t.storePath,{agentId:e,order:a.size})}),s=E([...r.durableTargets,...o,...(n.registeredDatabases??y()).filter(({path:e})=>![...r.physicalTargets.values()].some(t=>t.storePath===e)).map(({agentId:e,path:t})=>({agentId:e,storePath:t}))].filter(e=>!n.excludeTarget(e)),{defaultAgentId:r.defaultAgentId,onResolvedTarget:i,...n});r={...r,durableTargets:s,physicalTargets:t,groupDiscovery:a}}let i=createGatewayRetainedStoreMatcher(e,t.discovery),a=r.durableTargets.filter(e=>{let t=r.physicalTargets.get(storeTargetKey(e));return!i(t?.storePath??e.storePath,e.agentId)});return r={...r,durableTargets:a,...r.durableStorePath===void 0?{}:{durableStorePath:resolveCombinedDatabasePath(a,r.physicalTargets)}},applyGatewaySessionStoreAdmission(e,t,r)}function applyGatewaySessionStoreAdmission(e,t,n){let r=[...n.diagnostics],i=t.discovery?.env??process.env;t.agentId?.trim()&&g(t.agentId,{env:i});let a=t.preserveSentinelOwners===`physical`&&D()?createGatewayConfiguredDatabaseMatcher(e,i):void 0,admitted=e=>{let t=n.physicalTargets.get(storeTargetKey(e));if(a&&t&&!a(t.storePath))return!1;let o=_(e.agentId,{env:i})??(t&&_(t.agentId,{env:i}));if(!o)return!0;let s=`${o.reason}\n${o.repairHint}`;return r.includes(s)||r.push(s),!1},o=n.durableTargets.filter(admitted),s=n.incognitoTargets.filter(e=>admitted(e));return o.length===n.durableTargets.length&&s.length===n.incognitoTargets.length?n:{...n,diagnostics:r,durableTargets:o,incognitoTargets:s,...n.durableStorePath===void 0?{}:{durableStorePath:resolveCombinedDatabasePath(o,n.physicalTargets)}}}function prepareCombinedSessionStore(e,t){let n=resolveGatewaySessionStoreTargets(e,t);return{projection:t.projection??`list`,targets:n,reads:n.durableTargets.map(e=>({target:e,storeTarget:r(n.physicalTargets.get(storeTargetKey(e)),`physical store`)}))}}function readCombinedSessionStoreTopology(e){let t={...e.options,includeIncognito:!1,discovery:{...e.options.discovery,readCandidates:e.candidates}},n=[[`all`,{}],[`configured`,{configuredAgentsOnly:!0}],...(e.scopeAgentIds?[.../* @__PURE__ */ new Set([...e.scopeAgentIds,...M(e.config,{env:t.discovery.env,registeredDatabases:t.discovery.snapshot?.registeredAgentDatabases??[]})])]:[]).map(e=>[`agent:${e}`,{agentId:e}])],r=e.scopeAgentIds?new Map(n.map(([n,r])=>{try{return[n,resolveGatewaySessionStoreTargets(e.config,{...r,includeIncognito:!1,discovery:t.discovery})]}catch(e){return[n,e instanceof Error?e:Error(String(e))]}})):void 0;return{kind:`combined-store-topology`,prepared:prepareCombinedSessionStore(e.config,t),...r?{scopes:r}:{}}}export{readCombinedSessionStoreTopology};