UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

71 lines (70 loc) • 4.57 kB
import { l as normalizeOptionalString } from "./string-coerce-1VuiLaaR.mjs"; import { i as getLoadedChannelPluginForRead } from "./registry-loaded-BugfxX6l.mjs"; import "./message-channel-constants-B3vfipkP.mjs"; import { n as normalizeMessageChannel } from "./message-channel-core-CqBAHB04.mjs"; import "./message-channel-j-k-Nup3.mjs"; import { t as normalizeChatType } from "./chat-type-D-T98NfH.mjs"; import { f as stringifyRouteThreadId } from "./channel-route-BIxMkFzo.mjs"; import { i as sessionDeliveryRoute, r as sessionDeliveryOrigin, t as deliveryContextFromSession } from "./delivery-context.read-CR06zOJ4.mjs"; import { n as stripOutboundTargetKindPrefix, r as stripTargetProviderPrefix } from "./channel-target-prefix-He7OrqGf.mjs"; //#region src/auto-reply/reply/effective-reply-route.ts /** Resolves the effective reply route from current context and persisted session route. */ /** Normalizes an external target without collapsing provider-owned topic suffixes. */ function normalizeEffectiveReplyTarget(raw, channel, threadId) { let target = normalizeOptionalString(raw); if (target && channel && threadId != null) target = getLoadedChannelPluginForRead(channel)?.threading?.resolveCurrentChannelId?.({ to: target, threadId }) ?? target; return target ? normalizeOptionalString(stripOutboundTargetKindPrefix(stripTargetProviderPrefix(target, channel ?? ""))) : void 0; } function isSessionsSendInterSessionHandoff(inputProvenance) { return inputProvenance?.kind === "inter_session" && inputProvenance.sourceTool?.toLowerCase() === "sessions_send"; } function resolveTrustedInheritedThreadId(entry) { const deliveryThreadId = deliveryContextFromSession(entry)?.threadId; if (deliveryThreadId == null) return; const routeThread = sessionDeliveryRoute(entry)?.thread; if (routeThread?.id != null && (routeThread.source === "explicit" || routeThread.source === "target" || routeThread.source === "turn") && stringifyRouteThreadId(routeThread.id) === stringifyRouteThreadId(deliveryThreadId)) return deliveryThreadId; } /** Resolves current, inherited, or persisted reply route for a session turn. */ function resolveEffectiveReplyRoute(params) { const currentSurface = normalizeMessageChannel(params.ctx.Provider) ?? normalizeMessageChannel(params.ctx.Surface) ?? normalizeMessageChannel(params.ctx.OriginatingChannel); const persistedDeliveryContext = deliveryContextFromSession(params.entry); const persistedRoute = sessionDeliveryRoute(params.entry); const persistedOrigin = sessionDeliveryOrigin(params.entry); const persistedDeliveryChannel = normalizeMessageChannel(persistedDeliveryContext?.channel); const liveChatType = normalizeChatType(params.ctx.ChatType); const persistedChatType = persistedRoute?.target?.chatType ?? params.entry?.chatType ?? normalizeChatType(persistedOrigin?.chatType); if (isSessionsSendInterSessionHandoff(params.ctx.InputProvenance) && currentSurface === "webchat" && persistedDeliveryChannel && persistedDeliveryChannel !== "webchat" && persistedDeliveryContext?.to) { const inheritedThreadId = resolveTrustedInheritedThreadId(params.entry); return { channel: persistedDeliveryChannel, to: persistedDeliveryContext.to, accountId: persistedDeliveryContext.accountId, ...inheritedThreadId !== void 0 ? { threadId: inheritedThreadId } : {}, ...persistedChatType ? { chatType: persistedChatType } : {}, inheritedExternalRoute: true }; } if (params.ctx.InternalTurnSource === void 0) return { channel: params.ctx.OriginatingChannel, to: params.ctx.OriginatingTo, accountId: params.ctx.AccountId, ...params.ctx.MessageThreadId !== void 0 ? { threadId: params.ctx.MessageThreadId } : {}, ...liveChatType ? { chatType: liveChatType } : {} }; const persistedChannel = persistedDeliveryContext?.channel; const liveChannel = params.ctx.OriginatingChannel; const canInheritPersistedTuple = !liveChannel || normalizeMessageChannel(liveChannel) === normalizeMessageChannel(persistedChannel); const chatType = liveChatType ?? (canInheritPersistedTuple ? persistedChatType : void 0); return { channel: liveChannel ?? persistedChannel, to: params.ctx.OriginatingTo ?? (canInheritPersistedTuple ? persistedDeliveryContext?.to : void 0), accountId: params.ctx.AccountId ?? (canInheritPersistedTuple ? persistedDeliveryContext?.accountId : void 0), ...params.ctx.MessageThreadId !== void 0 ? { threadId: params.ctx.MessageThreadId } : {}, ...chatType ? { chatType } : {} }; } //#endregion export { resolveEffectiveReplyRoute as n, normalizeEffectiveReplyTarget as t };