UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

116 lines (115 loc) • 4.65 kB
import { o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs"; import { l as getActivePluginRegistry } from "./runtime-ezCEpumg.mjs"; import { t as INTERNAL_MESSAGE_CHANNEL } from "./message-channel-constants-CkbqRgGl.mjs"; import { n as normalizeMessageChannel } from "./message-channel-core-BbYZT1a-.mjs"; import { t as isDeliverableMessageChannel } from "./message-channel-normalize-CFHSufeo.mjs"; import { n as getLoadedChannelPlugin, t as getChannelPlugin } from "./registry-ByqVE5S3.mjs"; import "./message-channel-DTYVLJT1.mjs"; import "./plugins-BoMiRtiY.mjs"; import { t as findChannelPluginInRegistry } from "./runtime-visible-channels-CE896D4p.mjs"; import { n as bootstrapOutboundChannelPluginAsync, t as bootstrapOutboundChannelPlugin } from "./channel-bootstrap.runtime-u-Awxx13.mjs"; //#region src/infra/outbound/channel-resolution.ts /** Normalizes a raw channel id and rejects non-deliverable/internal channels. */ function normalizeDeliverableOutboundChannel(e) { const t = normalizeMessageChannel(e); return t && isDeliverableMessageChannel(t) ? t : void 0; } function getOutboundRuntimeRegistry() { return getPluginRuntimeGatewayRequestScope()?.pluginRegistry ?? getActivePluginRegistry(); } function resolveSendCapableMessageAdapter(e) { const t = e?.message; return typeof t?.send?.text === "function" ? t : void 0; } function hasOutboundSurface(e, t = false) { return t ? Boolean(e?.outbound?.sendText || e?.outbound?.deliveryMode === "gateway" || resolveSendCapableMessageAdapter(e)) : Boolean(e?.outbound ?? resolveSendCapableMessageAdapter(e)); } function resolveRuntimeOutboundPluginCandidate(e) { return [ e.loaded, e.runtime, e.bundled ].find((t) => hasOutboundSurface(t, e.requireActivatedRuntime)) ?? (e.requireActivatedRuntime ? void 0 : e.loaded ?? e.setupFallback ?? e.bundled); } function resolveOutboundPluginFromRuntimeRegistry(e, t = getOutboundRuntimeRegistry(), n = false) { const r = findChannelPluginInRegistry(t, e); return hasOutboundSurface(r, n) ? r : void 0; } function* resolveOutboundChannelPluginSteps(e) { const t = normalizeMessageChannel(e.channel); let n = t && isDeliverableMessageChannel(t) ? t : void 0; let r = false; let i; if (!n && t && t !== "webchat") { const a = resolveOutboundPluginFromRuntimeRegistry(t, getOutboundRuntimeRegistry() ?? void 0, true); if (a) n = a.id; else if (e.allowBootstrap === true) { i = yield { channel: t, cfg: e.cfg, agentId: e.agentId }; n = resolveOutboundPluginFromRuntimeRegistry(t, i, true)?.id ?? t; r = true; } } if (!n) return; const a = findChannelPluginInRegistry(i ?? getPluginRuntimeGatewayRequestScope()?.pluginRegistry, n); if (a) { if (e.allowBootstrap !== true || hasOutboundSurface(a, true)) return a; if (r) return; return resolveOutboundPluginFromRuntimeRegistry(n, yield { ...e, channel: n }, true); } const o = getLoadedChannelPlugin(n); const s = e.allowBootstrap === true; const c = resolveRuntimeOutboundPluginCandidate({ loaded: o, runtime: resolveOutboundPluginFromRuntimeRegistry(n, i, s), setupFallback: findChannelPluginInRegistry(i ?? getOutboundRuntimeRegistry(), n), bundled: getChannelPlugin(n), requireActivatedRuntime: s }); if (c) return c; if (e.allowBootstrap !== true || r) return; const l = yield { channel: n, cfg: e.cfg, agentId: e.agentId }; return resolveRuntimeOutboundPluginCandidate({ loaded: getLoadedChannelPlugin(n), runtime: resolveOutboundPluginFromRuntimeRegistry(n, l, true), bundled: getChannelPlugin(n), requireActivatedRuntime: true }); } /** Resolves a deliverable outbound channel plugin, optionally bootstrapping it. */ function resolveOutboundChannelPlugin(e) { const t = resolveOutboundChannelPluginSteps(e); let n = t.next(); while (!n.done) n = t.next(bootstrapOutboundChannelPlugin(n.value)); return n.value; } async function resolveOutboundChannelPluginAsync(e) { const t = resolveOutboundChannelPluginSteps(e); let n = t.next(); while (!n.done) { const r = await bootstrapOutboundChannelPluginAsync({ ...n.value, assertCurrent: e.assertCurrent }); n = t.next(r); } return n.value; } /** Resolves the message adapter after any required bootstrap metadata is ready. */ async function resolveOutboundChannelMessageAdapter(e) { const t = await resolveOutboundChannelPluginAsync(e); e.assertCurrent?.(); return resolveSendCapableMessageAdapter(t); } //#endregion export { resolveOutboundChannelPluginAsync as i, resolveOutboundChannelMessageAdapter as n, resolveOutboundChannelPlugin as r, normalizeDeliverableOutboundChannel as t };