UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

54 lines (53 loc) • 2.22 kB
import { o as hasReplyPayloadContent } from "./payload-Cab4FCxl.mjs"; //#region src/channels/message/capabilities.ts function hasMediaPayload(e) { return Boolean(e.mediaUrl?.trim()) || Array.isArray(e.mediaUrls) && e.mediaUrls.some((e) => typeof e === "string" && e.trim().length > 0); } /** Derives the adapter capabilities core needs before it can require durable final delivery. */ function deriveDurableFinalDeliveryRequirements(e) { const t = {}; const n = [ ["text", true], ["media", hasMediaPayload(e.payload)], ["replyTo", e.replyToId != null || e.payload.replyToId != null], ["thread", e.threadId != null], ["silent", e.silent], ["messageSendingHooks", e.messageSendingHooks !== false], ["payload", e.payloadTransport], ["batch", e.batch], ["reconcileUnknownSend", e.reconcileUnknownSend], ["afterSendSuccess", e.afterSendSuccess], ["afterCommit", e.afterCommit], ...Object.entries(e.extraCapabilities ?? {}) ]; for (const [e, r] of n) if (r === true) t[e] = true; return t; } /** Matches the structured-payload branch selected by core delivery. */ function payloadRequiresDurablePayloadTransport(e, t) { return e.isError === true && t?.sendTextOnlyErrorPayloads === true || hasReplyPayloadContent({ presentation: e.presentation, interactive: e.interactive, channelData: e.channelData, location: e.location }, { extraContent: e.location != null }) || e.audioAsVoice === true || e.videoAsNote === true; } /** Derives the union of required capabilities from the final concrete batch. */ function deriveDurableFinalDeliveryRequirementsForBatch(e) { const t = e.reconcileUnknownSend && e.payloads.length > 0 ? { reconcileUnknownSend: true } : {}; for (const n of e.payloads) { const r = deriveDurableFinalDeliveryRequirements({ payload: n, replyToId: e.replyToId, threadId: e.threadId, silent: e.silent, payloadTransport: payloadRequiresDurablePayloadTransport(n), batch: e.payloads.length > 1, reconcileUnknownSend: e.reconcileUnknownSend }); Object.assign(t, r); } return t; } //#endregion export { deriveDurableFinalDeliveryRequirementsForBatch as n, payloadRequiresDurablePayloadTransport as r, deriveDurableFinalDeliveryRequirements as t };