openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
68 lines (67 loc) • 3.26 kB
JavaScript
import { d as normalizeChannelRouteRef } from "./channel-route-D7X5briz.js";
import { t as deliveryContextFromChannelRoute } from "./delivery-context.shared-CpAdEETO.js";
import { a as normalizeChannelId, t as getChannelPlugin } from "./registry-MkxNn1Ue.js";
import { t as normalizeConversationTargetParams } from "./delivery-context-DNxwKU0n.js";
//#region src/channels/route-projection.ts
/** Formats a conversation id into a deliverable target, using channel hooks before generic fallback. */
function formatConversationTarget(params) {
const { channel, conversationId, parentConversationId } = normalizeConversationTargetParams(params);
if (!channel || !conversationId) return;
const normalizedChannel = normalizeChannelId(channel);
const pluginTarget = normalizedChannel ? getChannelPlugin(normalizedChannel)?.messaging?.resolveDeliveryTarget?.({
conversationId,
parentConversationId
}) : null;
if (pluginTarget?.to?.trim()) return pluginTarget.to.trim();
return `channel:${conversationId}`;
}
/** Resolves a channel conversation into target/thread fields for delivery routing. */
function resolveConversationDeliveryTarget(params) {
const { channel, conversationId, parentConversationId } = normalizeConversationTargetParams(params);
const pluginTarget = channel && conversationId ? getChannelPlugin(normalizeChannelId(channel) ?? channel)?.messaging?.resolveDeliveryTarget?.({
conversationId,
parentConversationId
}) : null;
if (pluginTarget) return {
...pluginTarget.to?.trim() ? { to: pluginTarget.to.trim() } : {},
...pluginTarget.threadId?.trim() ? { threadId: pluginTarget.threadId.trim() } : {}
};
return { to: formatConversationTarget(params) };
}
/** Converts a channel route back to legacy delivery context metadata. */
function deliveryContextFromRoute(route) {
return deliveryContextFromChannelRoute(route);
}
/** Converts a persisted conversation reference into a channel route. */
function routeFromConversationRef(conversation) {
if (!conversation) return;
const target = resolveConversationDeliveryTarget({
channel: conversation.channel,
conversationId: conversation.conversationId,
parentConversationId: conversation.parentConversationId
});
return normalizeChannelRouteRef({
channel: conversation.channel,
accountId: conversation.accountId,
to: target.to,
threadId: target.threadId,
threadSource: target.threadId ? "target" : void 0
});
}
/** Extracts a channel route from a session binding record. */
function routeFromBindingRecord(binding) {
return routeFromConversationRef(binding?.conversation);
}
/** Projects route fields used by older session and delivery callers. */
function routeToDeliveryFields(route) {
const deliveryContext = deliveryContextFromRoute(route);
return {
...deliveryContext ? { deliveryContext } : {},
...deliveryContext?.channel ? { channel: deliveryContext.channel } : {},
...deliveryContext?.to ? { to: deliveryContext.to } : {},
...deliveryContext?.accountId ? { accountId: deliveryContext.accountId } : {},
...deliveryContext?.threadId != null ? { threadId: deliveryContext.threadId } : {}
};
}
//#endregion
export { routeToDeliveryFields as i, routeFromBindingRecord as n, routeFromConversationRef as r, formatConversationTarget as t };