openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.83 kB
JavaScript
import{t as deliverInboundReplyWithMessageSendContext}from"../channel-outbound-BZrgY7lw.mjs";import{S as normalizeOutboundReplyPayloadCore}from"../reply-payload-C6sYX5Rf.mjs";import{c as mapReplyDispatchCounts}from"../reply-dispatcher-CyCal3OZ.mjs";import{i as throwIfDurableInboundReplyDeliveryFailed,r as isDurableInboundReplyDeliveryHandled,t as deliverInboundReplyWithMessageSendContextCore}from"../durable-delivery-BBZNkKxX.mjs";import{a as resolveChannelTurnDispatchCounts,i as hasVisibleChannelTurnDispatch,o as recordChannelBotPairLoopAndCheckSuppression,r as hasFinalChannelTurnDispatch}from"../execution-Cpe8EZ0A.mjs";import{t as recordDroppedChannelTurnHistory}from"../run-channel-turn-KxIBuYA-.mjs";import{a as runChannelInboundEvent,n as dispatchChannelInboundReply,o as runPreparedInboundReply}from"../channel-inbound-DZDqWdoL.mjs";
//!src/plugin-sdk/inbound-reply-dispatch.ts
function withLegacyDispatchCounts(e){return async t=>{const n=await e(t);const r=n.settledReceipt;if(!r)return n;const i=mapReplyDispatchCounts(r.counts,e=>e.delivered);const a=mapReplyDispatchCounts(r.counts,e=>e.failedBeforeSend+e.failedAfterSend);return{...n,queuedFinal:i.final>0,counts:i,...Object.values(a).some(e=>e>0)?{failedCounts:a}:{}}}}function buildInboundReplyDispatchBase(e){return{cfg:e.cfg,channel:e.channel,accountId:e.accountId,agentId:e.route.agentId,routeSessionKey:e.route.sessionKey,storePath:e.storePath,ctxPayload:e.ctxPayload,recordInboundSession:e.core.channel.session.recordInboundSession,dispatchReplyWithBufferedBlockDispatcher:withLegacyDispatchCounts(e.core.channel.reply.dispatchReplyWithBufferedBlockDispatcher)}}async function dispatchInboundReplyWithBase(e){const t=buildInboundReplyDispatchBase(e);const{deliver:n,durable:r,onDispatchError:i,onRecordError:a,replyOptions:o}=e;await dispatchChannelInboundReply({...t,delivery:{preparePayload:e=>e&&typeof e===`object`?normalizeOutboundReplyPayloadCore(e):{},deliver:async(e,i)=>{if(r){const n=await deliverInboundReplyWithMessageSendContextCore({cfg:t.cfg,channel:t.channel,accountId:t.accountId,agentId:t.agentId,ctxPayload:t.ctxPayload,payload:e,info:i,...r});throwIfDurableInboundReplyDeliveryFailed(n);if(isDurableInboundReplyDeliveryHandled(n))return n.delivery}return await n(e)},onError:i},replyPipeline:{},replyOptions:o,record:{onRecordError:a}})}export{deliverInboundReplyWithMessageSendContext,dispatchChannelInboundReply,dispatchInboundReplyWithBase,hasFinalChannelTurnDispatch as hasFinalInboundReplyDispatch,hasVisibleChannelTurnDispatch as hasVisibleInboundReplyDispatch,recordChannelBotPairLoopAndCheckSuppression,recordDroppedChannelTurnHistory as recordDroppedChannelInboundHistory,recordDroppedChannelTurnHistory,resolveChannelTurnDispatchCounts as resolveInboundReplyDispatchCounts,runChannelInboundEvent,runPreparedInboundReply};