UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

50 lines (49 loc) • 2.03 kB
//#region src/plugin-sdk/channel-send-result.ts /** Attaches the channel id to a single outbound send result. */ function attachChannelToResult(e, t) { return { ...t, channel: e }; } /** Attaches the channel id to each outbound send result in order. */ function attachChannelToResults(e, t) { return t.map((t) => attachChannelToResult(e, t)); } /** Creates an empty outbound delivery result for send paths that produced no platform id. */ function createEmptyChannelResult(e, t = {}) { return attachChannelToResult(e, { messageId: "", ...t }); } /** Wraps outbound send methods that already return delivery-shaped results without channel ids. */ function createAttachedChannelResultAdapter(e) { return { sendText: e.sendText ? async (t) => attachChannelToResult(e.channel, await e.sendText(t)) : void 0, sendMedia: e.sendMedia ? async (t) => attachChannelToResult(e.channel, await e.sendMedia(t)) : void 0, sendPoll: e.sendPoll ? async (t) => attachChannelToResult(e.channel, await e.sendPoll(t)) : void 0 }; } function buildRawChannelAdapterResult(e, t) { if (!t.ok) throw new Error(t.error?.trim() || `Channel send failed for ${e}`); return buildChannelSendResult(e, t); } /** Wraps legacy raw text/media send methods and normalizes their results. */ function createRawChannelSendResultAdapter(e) { return { sendText: e.sendText ? async (t) => buildRawChannelAdapterResult(e.channel, await e.sendText(t)) : void 0, sendMedia: e.sendMedia ? async (t) => buildRawChannelAdapterResult(e.channel, await e.sendMedia(t)) : void 0 }; } /** Normalize raw channel send results into the shape shared outbound callers expect. */ function buildChannelSendResult(e, t) { return { channel: e, ok: t.ok, messageId: t.messageId ?? "", error: t.error ? new Error(t.error) : void 0 }; } //#endregion export { createEmptyChannelResult as a, createAttachedChannelResultAdapter as i, attachChannelToResults as n, createRawChannelSendResultAdapter as o, buildChannelSendResult as r, attachChannelToResult as t };