UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.88 kB
import{o as getPluginRuntimeGatewayRequestScope}from"./gateway-request-scope-7deHmsb_.mjs";import{l as getActivePluginRegistry}from"./runtime-Cl6PvJHC.mjs";import{t as INTERNAL_MESSAGE_CHANNEL}from"./message-channel-constants-BbP_hczw.mjs";import{n as normalizeMessageChannel}from"./message-channel-core-D_hPOadj.mjs";import{t as isDeliverableMessageChannel}from"./message-channel-normalize-hDAO6_JQ.mjs";import{n as getLoadedChannelPlugin,t as getChannelPlugin}from"./registry-CpNh6QcT.mjs";import"./message-channel-514k57tV.mjs";import"./plugins-DxOycUNJ.mjs";import{t as findChannelPluginInRegistry}from"./runtime-visible-channels-Cx_NfvRz.mjs";import{n as bootstrapOutboundChannelPluginAsync,t as bootstrapOutboundChannelPlugin}from"./channel-bootstrap.runtime-DbWlS-Er.mjs"; //!src/infra/outbound/channel-resolution.ts function normalizeDeliverableOutboundChannel(e){const t=normalizeMessageChannel(e);return t&&isDeliverableMessageChannel(t)?t:void 0}function getOutboundRuntimeRegistry(){return getPluginRuntimeGatewayRequestScope()?.pluginRegistry??getActivePluginRegistry()}function resolveSendCapableMessageAdapter(e){const t=e?.message;return typeof t?.send?.text===`function`?t:void 0}function hasOutboundSurface(e,t=false){return t?Boolean(e?.outbound?.sendText||e?.outbound?.deliveryMode===`gateway`||resolveSendCapableMessageAdapter(e)):Boolean(e?.outbound??resolveSendCapableMessageAdapter(e))}function resolveRuntimeOutboundPluginCandidate(e){return[e.loaded,e.runtime,e.bundled].find(t=>hasOutboundSurface(t,e.requireActivatedRuntime))??(e.requireActivatedRuntime?void 0:e.loaded??e.setupFallback??e.bundled)}function resolveOutboundPluginFromRuntimeRegistry(e,t=getOutboundRuntimeRegistry(),n=false){const r=findChannelPluginInRegistry(t,e);return hasOutboundSurface(r,n)?r:void 0}function*resolveOutboundChannelPluginSteps(e){const t=normalizeMessageChannel(e.channel);let n=t&&isDeliverableMessageChannel(t)?t:void 0;let r=false;let i;if(!n&&t&&t!==`webchat`){const a=resolveOutboundPluginFromRuntimeRegistry(t,getOutboundRuntimeRegistry()??void 0,true);if(a)n=a.id;else if(e.allowBootstrap===true){i=yield{channel:t,cfg:e.cfg,agentId:e.agentId};n=resolveOutboundPluginFromRuntimeRegistry(t,i,true)?.id??t;r=true}}if(!n)return;const a=findChannelPluginInRegistry(i??getPluginRuntimeGatewayRequestScope()?.pluginRegistry,n);if(a){if(e.allowBootstrap!==true||hasOutboundSurface(a,true))return a;if(r)return;return resolveOutboundPluginFromRuntimeRegistry(n,yield{...e,channel:n},true)}const o=getLoadedChannelPlugin(n);const s=e.allowBootstrap===true;const c=resolveRuntimeOutboundPluginCandidate({loaded:o,runtime:resolveOutboundPluginFromRuntimeRegistry(n,i,s),setupFallback:findChannelPluginInRegistry(i??getOutboundRuntimeRegistry(),n),bundled:getChannelPlugin(n),requireActivatedRuntime:s});if(c)return c;if(e.allowBootstrap!==true||r)return;const l=yield{channel:n,cfg:e.cfg,agentId:e.agentId};return resolveRuntimeOutboundPluginCandidate({loaded:getLoadedChannelPlugin(n),runtime:resolveOutboundPluginFromRuntimeRegistry(n,l,true),bundled:getChannelPlugin(n),requireActivatedRuntime:true})}function resolveOutboundChannelPlugin(e){const t=resolveOutboundChannelPluginSteps(e);let n=t.next();while(!n.done)n=t.next(bootstrapOutboundChannelPlugin(n.value));return n.value}async function resolveOutboundChannelPluginAsync(e){const t=resolveOutboundChannelPluginSteps(e);let n=t.next();while(!n.done){const r=await bootstrapOutboundChannelPluginAsync({...n.value,assertCurrent:e.assertCurrent});n=t.next(r)}return n.value}async function resolveOutboundChannelMessageAdapter(e){const t=await resolveOutboundChannelPluginAsync(e);e.assertCurrent?.();return resolveSendCapableMessageAdapter(t)}export{resolveOutboundChannelPluginAsync as i,resolveOutboundChannelMessageAdapter as n,resolveOutboundChannelPlugin as r,normalizeDeliverableOutboundChannel as t};