openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
43 lines (42 loc) • 2.46 kB
JavaScript
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { E as parseSessionDeliveryRoute } from "./session-key-CqAyZeVk.mjs";
import { r as readTrimmedStringAlias } from "./string-readers-BtMVaphq.mjs";
import { t as INTERNAL_MESSAGE_CHANNEL } from "./message-channel-constants-CkbqRgGl.mjs";
import { n as normalizeMessageChannel } from "./message-channel-core-BbYZT1a-.mjs";
import "./message-channel-DTYVLJT1.mjs";
import { r as resolveOutboundChannelPlugin } from "./channel-resolution-DjtSMYUG.mjs";
import { n as listConfiguredMessageChannels, t as isConfiguredChannel } from "./channel-selection-DBeuWpKq.mjs";
//#region src/infra/outbound/internal-source-reply.ts
function hasExplicitRouteParam(e) {
return readTrimmedStringAlias(e, [
"channel",
"target",
"to",
"channelId"
]) !== void 0 || Array.isArray(e.targets) && e.targets.some((e) => normalizeOptionalString(e));
}
function hasCurrentSourceReplyContext(e) {
const t = normalizeOptionalLowercaseString(e.toolContext?.currentChannelProvider);
if (!t) return false;
if (t === "webchat") {
const t = parseSessionDeliveryRoute(e.sessionKey);
const n = t ? normalizeMessageChannel(t.channel) : void 0;
return !n || n === "webchat";
}
const n = e.toolContext?.currentMessageId;
return Boolean(normalizeOptionalString(e.toolContext?.currentChannelId) || normalizeOptionalString(e.toolContext?.currentMessagingTarget) || normalizeOptionalString(e.toolContext?.currentThreadTs) || typeof n === "number" && Number.isFinite(n) || normalizeOptionalString(n));
}
/** Return whether this send resolves to the private current-run source-reply sink. */
async function shouldUseInternalSourceReplySink(e, t) {
if (!(e.action === "send" && e.sourceReplyDeliveryMode === "message_tool_only" && hasCurrentSourceReplyContext(e) && Boolean(e.sessionKey?.trim()) && !hasExplicitRouteParam(t))) return false;
if (!normalizeOptionalString(e.toolContext?.currentChannelId) && !normalizeOptionalString(e.toolContext?.currentMessagingTarget)) return true;
const n = normalizeMessageChannel(e.toolContext?.currentChannelProvider);
if (!n || n === "webchat" || !isConfiguredChannel(e.cfg, n) || !resolveOutboundChannelPlugin({
channel: n,
cfg: e.cfg,
allowBootstrap: true
})) return true;
return !(await listConfiguredMessageChannels(e.cfg)).some((e) => e === n);
}
//#endregion
export { shouldUseInternalSourceReplySink as t };