UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

103 lines (102 loc) • 4.31 kB
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs"; import { f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs"; import { n as listBundledChannelCatalogEntries } from "./bundled-channel-catalog-read-CmfX8BTg.mjs"; import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs"; import "./registry-BB86xKJa.mjs"; import { r as listChannelPlugins, t as getChannelPlugin } from "./registry-ByqVE5S3.mjs"; import { r as setChannelAgentToolMeta } from "./channel-tool-metadata-ZKqhsBg_.mjs"; import { n as resolveChannelApprovalCapability } from "./plugins-BoMiRtiY.mjs"; import { c as resolveMessageActionDiscoveryChannelId, o as resolveCurrentChannelMessageToolDiscoveryAdapter, t as createMessageActionDiscoveryContext } from "./message-action-discovery-D58BOJ5F.mjs"; //#region src/channels/plugins/native-approval-prompt.ts const NATIVE_APPROVAL_PROMPT_RUNTIME_CAPABILITY = "nativeApprovals"; const NATIVE_APPROVAL_PROMPT_RUNTIME_CAPABILITY_NORMALIZED = "nativeapprovals"; function channelPluginHasNativeApprovalPromptUi(e) { const t = resolveChannelApprovalCapability(e); return Boolean(t?.native || t?.nativeRuntime); } function isKnownNativeApprovalPromptChannel(e) { const t = normalizeOptionalLowercaseString(e); return Boolean(t && listBundledChannelCatalogEntries().some((e) => e.id === t && e.channel.approvalFlags?.includes("native"))); } function hasNativeApprovalPromptRuntimeCapability(e) { return Boolean(e?.some((e) => normalizeOptionalLowercaseString(e) === NATIVE_APPROVAL_PROMPT_RUNTIME_CAPABILITY_NORMALIZED)); } //#endregion //#region src/agents/channel-tools.ts /** * Channel-owned agent tool and prompt helpers. * Discovers channel tools, message actions, prompt capabilities, reaction * guidance, and weakly-attached channel metadata for wrapped tools. */ /** * Get the list of supported message actions for a specific channel. * Returns an empty array if channel is not found or has no actions configured. */ function* listChannelSupportedActionsSteps(e) { const t = resolveMessageActionDiscoveryChannelId(e.channel); if (!t) return []; const n = resolveCurrentChannelMessageToolDiscoveryAdapter(t, e.preparedMessageToolCatalog); if (!n?.actions) return []; return (yield { pluginId: n.pluginId, actions: n.actions, context: createMessageActionDiscoveryContext(e), includeActions: true }).actions; } function listChannelAgentTools(e) { const t = []; for (const n of listChannelPlugins()) { const r = n.agentTools; if (!r) continue; const i = typeof r === "function" ? r(e) : r; if (Array.isArray(i)) { for (const e of i) setChannelAgentToolMeta(e, { channelId: n.id }); t.push(...i); } } return t; } /** Resolve channel-specific message tool hints for system prompt assembly. */ function resolveChannelMessageToolHints(e) { const t = normalizeAnyChannelId(e.channel); if (!t) return []; const n = getChannelPlugin(t)?.agentPrompt?.messageToolHints; if (!n) return []; const r = e.cfg ?? {}; return normalizeStringEntries(n({ cfg: r, accountId: e.accountId })); } /** Resolve channel prompt capabilities, including native approval UI support. */ function resolveChannelPromptCapabilities(e) { const t = normalizeAnyChannelId(e.channel); if (!t) return []; const n = getChannelPlugin(t); const r = e.cfg ?? {}; const i = normalizeStringEntries(n?.agentPrompt?.messageToolCapabilities?.({ cfg: r, accountId: e.accountId }) ?? []); if (channelPluginHasNativeApprovalPromptUi(n)) i.push(NATIVE_APPROVAL_PROMPT_RUNTIME_CAPABILITY); return i; } /** Resolve optional channel reaction guidance for assistant replies. */ function resolveChannelReactionGuidance(e) { const t = normalizeAnyChannelId(e.channel); if (!t) return; const n = getChannelPlugin(t)?.agentPrompt?.reactionGuidance; if (!n) return; const r = n({ cfg: e.cfg ?? {}, accountId: e.accountId }); if (!r?.level) return; return { level: r.level, channel: r.channelLabel?.trim() || t }; } //#endregion export { resolveChannelReactionGuidance as a, resolveChannelPromptCapabilities as i, listChannelSupportedActionsSteps as n, hasNativeApprovalPromptRuntimeCapability as o, resolveChannelMessageToolHints as r, isKnownNativeApprovalPromptChannel as s, listChannelAgentTools as t };