UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.23 kB
import{a as getPluginCache,w as withPluginCache}from"./plugin-cache-B6QVpzXr.mjs";import{r as resolveStateDir}from"./state-dir-BwIClCab.mjs";import{o as getPluginRuntimeGatewayRequestScope}from"./gateway-request-scope-7deHmsb_.mjs";import{O as tryResolveAmbientOwnerAgentId,f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{r as cloneEnvWithPlatformSemantics}from"./config-env-vars-DCDGIBtT.mjs";import{n as prepareBundledDiscoveryMode}from"./bundled-discovery-state-CcZamNHc.mjs";import{i as preparePersistedInstalledPluginIndexCacheEntry}from"./installed-plugin-index-record-state-Dlesa-xK.mjs";import{m as resolveDiscoverableScopedChannelPluginIds}from"./channel-presence-policy-iYxMh2HT.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{l as getActivePluginRegistry}from"./runtime-Cl6PvJHC.mjs";import"./channel-plugin-ids--iuNYdtE.mjs";import{t as applyPluginAutoEnable}from"./plugin-auto-enable-DD4D-LwA.mjs";import{n as withActivatedPluginIds}from"./activation-context-BClB4krh.mjs";import{n as loadPluginRegistryHandle}from"./loader-BhonRuVa.mjs"; //!src/infra/outbound/channel-bootstrap.runtime.ts function resolveSendCapableRegistry(e,t){const n=e?.channels?.find(e=>e?.plugin?.id===t);return e&&(n?.plugin?.outbound?.sendText??n?.plugin?.message?.send?.text)?e:void 0}function resolveBootstrapPlan(e){const t=e.cfg;if(!t)return{kind:`resolved`,registry:void 0};const n=getPluginRuntimeGatewayRequestScope()?.pluginRegistry;const r=resolveSendCapableRegistry(n?.channels?.find(t=>t?.plugin?.id===e.channel)?n:getActivePluginRegistry(),e.channel);if(r)return{kind:`resolved`,registry:r};return{kind:`cold`,cfg:t,agentId:tryResolveAmbientOwnerAgentId(t,e.agentId)}}function loadBootstrapPlan(e,t,n){const{cfg:r,agentId:i}=t;const a=n?.env;const o=applyPluginAutoEnable({config:r,...a?{env:a}:{}});const s=n?n.workspaceDir:i===void 0?void 0:resolveAgentWorkspaceDir(r,i);const c=resolveDiscoverableScopedChannelPluginIds({config:o.config,activationSourceConfig:r,channelIds:[e],workspaceDir:s,env:a??process.env});const l=withActivatedPluginIds({config:o.config,pluginIds:c})??o.config;const u=withActivatedPluginIds({config:r,pluginIds:c})??r;let d;try{d=resolveSendCapableRegistry(loadPluginRegistryHandle({config:l,activationSourceConfig:u,autoEnabledReasons:o.autoEnabledReasons,onlyPluginIds:c,workspaceDir:s,...a?{env:a}:{},runtimeOptions:{allowGatewaySubagentBinding:true}}),e)}catch{}return d}function bootstrapOutboundChannelPlugin(e){const t=resolveBootstrapPlan(e);return t.kind===`resolved`?t.registry:loadBootstrapPlan(e.channel,t)}async function bootstrapOutboundChannelPluginAsync(e){e.assertCurrent?.();const t=resolveBootstrapPlan(e);if(t.kind===`resolved`)return t.registry;const n=getPluginCache();const r=cloneEnvWithPlatformSemantics(process.env);r.OPENCLAW_STATE_DIR=resolveStateDir(r);const i={env:r,workspaceDir:t.agentId===void 0?void 0:resolveAgentWorkspaceDir(t.cfg,t.agentId,r)};return withPluginCache(n,async()=>{const n=await prepareBundledDiscoveryMode(r);await preparePersistedInstalledPluginIndexCacheEntry({env:r});e.assertCurrent?.();n();return loadBootstrapPlan(e.channel,t,i)})}export{bootstrapOutboundChannelPluginAsync as n,bootstrapOutboundChannelPlugin as t};