UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

50 lines (49 loc) • 3.05 kB
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-6kR-86XC.mjs"; import { T as parseSessionDeliveryRoute } from "./session-key-BC4m_Ly5.mjs"; import { n as readTrimmedStringAlias } from "./string-readers-BqCEHg4q.mjs"; import "./message-channel-constants-Dq-VU_KZ.mjs"; import { n as normalizeMessageChannel } from "./message-channel-core-JDeu-bNU.mjs"; import "./message-channel-BCUrZuO3.mjs"; import { r as resolveOutboundChannelPlugin } from "./channel-resolution-ojzsCEFE.mjs"; import { n as listConfiguredMessageChannels, t as isConfiguredChannel } from "./channel-selection-By0gjaC_.mjs"; //#region src/infra/outbound/internal-source-reply.ts function hasExternalSessionDeliveryRoute(sessionKey) { const route = parseSessionDeliveryRoute(sessionKey); if (!route) return false; const channel = normalizeMessageChannel(route.channel); return Boolean(channel && channel !== "webchat"); } function hasExplicitRouteParam(params) { return readTrimmedStringAlias(params, [ "channel", "target", "to", "channelId" ]) !== void 0 || Array.isArray(params.targets) && params.targets.some((value) => normalizeOptionalString(value)); } function hasCurrentSourceReplyContext(input) { const provider = normalizeOptionalLowercaseString(input.toolContext?.currentChannelProvider); if (!provider) return false; if (provider === "webchat") return !hasExternalSessionDeliveryRoute(input.sessionKey); const currentMessageId = input.toolContext?.currentMessageId; return Boolean(normalizeOptionalString(input.toolContext?.currentChannelId) || normalizeOptionalString(input.toolContext?.currentMessagingTarget) || normalizeOptionalString(input.toolContext?.currentThreadTs) || typeof currentMessageId === "number" && Number.isFinite(currentMessageId) || normalizeOptionalString(currentMessageId)); } async function hasConfiguredCurrentSourceChannel(input) { const provider = normalizeMessageChannel(input.toolContext?.currentChannelProvider) ?? normalizeOptionalLowercaseString(input.toolContext?.currentChannelProvider); if (!provider || provider === "webchat") return false; if (!isConfiguredChannel(input.cfg, provider)) return false; if (!resolveOutboundChannelPlugin({ channel: provider, cfg: input.cfg, allowBootstrap: true })) return false; return (await listConfiguredMessageChannels(input.cfg)).some((channel) => channel === provider); } /** Return whether this send resolves to the private current-run source-reply sink. */ async function shouldUseInternalSourceReplySink(input, params) { if (!(input.action === "send" && input.sourceReplyDeliveryMode === "message_tool_only" && hasCurrentSourceReplyContext(input) && Boolean(input.sessionKey?.trim()) && !hasExplicitRouteParam(params))) return false; if (!normalizeOptionalString(input.toolContext?.currentChannelId) && !normalizeOptionalString(input.toolContext?.currentMessagingTarget)) return true; return !await hasConfiguredCurrentSourceChannel(input); } //#endregion export { shouldUseInternalSourceReplySink as t };