openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.97 kB
JavaScript
import{d as withPluginRuntimeRegistryScope}from"./gateway-request-scope-7deHmsb_.mjs";import{_ as isPluginRegistryGatewayViewOf,d as getPluginRegistryGatewayOwner,u as getPluginRegistryGatewayChannelRegistration}from"./registry-lifecycle-DGwblXFd.mjs";import{t as runOutsidePluginRuntimeGenerationScope}from"./generation-scope-CxHnQlew.mjs";import{r as getPluginRuntimeLoadContext}from"./load-context-BgV8IMWg.mjs";import{r as PlatformMessageNotDispatchedError}from"./deliver-types-QUMIGH6t.mjs";import{isDeepStrictEqual}from"node:util";
//!src/channels/turn/admitting-gateway-delivery.ts
async function runAdmittingGatewayDelivery(e,t){const{registry:n}=e;const r=getPluginRegistryGatewayOwner(n);if(!r)return await t(e.cfg);const i=r.current();const reject=e=>{throw new PlatformMessageNotDispatchedError(e,{cause:new Error(e),retryable:false})};if(!i)return reject(`The Gateway that admitted this reply is closing.`);const assertCurrent=()=>{if(r.current()!==i)reject(`The reply delivery runtime changed before sending.`)};if(i===n||isPluginRegistryGatewayViewOf(n,i))return await runOutsidePluginRuntimeGenerationScope(()=>withPluginRuntimeRegistryScope(i,()=>t(e.cfg,assertCurrent)));const a=getPluginRuntimeLoadContext(i)?.rawConfig;const o=i.channels.find(t=>t.plugin.id===e.channel);const s=getPluginRegistryGatewayChannelRegistration(n,e.channel);const c=s?.config;const l=o&&s?.pluginId===o.pluginId&&s.plugin===o.plugin;if(!a||!c||!isDeepStrictEqual(a.channels?.[e.channel],c.channels?.[e.channel])||!isDeepStrictEqual(a.channels?.defaults,c.channels?.defaults)||!o||!l||!isDeepStrictEqual(a.plugins?.entries?.[o.pluginId],c.plugins?.entries?.[o.pluginId]))return reject(`The reply channel changed; delivery was not started.`);const u=e.prepareRuntimeHandoff;return await runOutsidePluginRuntimeGenerationScope(()=>withPluginRuntimeRegistryScope(i,()=>{const e=u?u(a):a;assertCurrent();return t(e,assertCurrent)}))}export{runAdmittingGatewayDelivery as t};