UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

70 lines (69 loc) • 3.24 kB
import { t as deliverInboundReplyWithMessageSendContext } from "../channel-outbound-DQFse8vD.mjs"; import { S as normalizeOutboundReplyPayloadCore } from "../reply-payload-CwASJYas.mjs"; import { c as mapReplyDispatchCounts } from "../reply-dispatcher-DVZA5pVi.mjs"; import { i as throwIfDurableInboundReplyDeliveryFailed, r as isDurableInboundReplyDeliveryHandled, t as deliverInboundReplyWithMessageSendContextCore } from "../durable-delivery-w3MeWAQt.mjs"; import { c as hasFinalChannelTurnDispatch, d as recordChannelBotPairLoopAndCheckSuppression, l as hasVisibleChannelTurnDispatch, u as resolveChannelTurnDispatchCounts } from "../execution-CaU-Nl7N.mjs"; import { t as recordDroppedChannelTurnHistory } from "../run-channel-turn-DeX5OqYI.mjs"; import { a as runChannelInboundEvent, n as dispatchChannelInboundReply, o as runPreparedInboundReply } from "../channel-inbound-DA48LBlQ.mjs"; //#region 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 } }); } //#endregion export { deliverInboundReplyWithMessageSendContext, dispatchChannelInboundReply, dispatchInboundReplyWithBase, hasFinalChannelTurnDispatch as hasFinalInboundReplyDispatch, hasVisibleChannelTurnDispatch as hasVisibleInboundReplyDispatch, recordChannelBotPairLoopAndCheckSuppression, recordDroppedChannelTurnHistory as recordDroppedChannelInboundHistory, recordDroppedChannelTurnHistory, resolveChannelTurnDispatchCounts as resolveInboundReplyDispatchCounts, runChannelInboundEvent, runPreparedInboundReply };