UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

107 lines (106 loc) • 4.37 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { h as readRuntimeConfig } from "./runtime-snapshot-WbwbY5b7.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 { r as listChannelPlugins, t as getChannelPlugin } from "./registry-ByqVE5S3.mjs"; import "./message-channel-DTYVLJT1.mjs"; import { n as resolveChannelApprovalCapability } from "./plugins-BoMiRtiY.mjs"; import "./config-CMA-J084.mjs"; import { t as canChannelEnforcePluginReviewerPolicy } from "./approval-channel-policy-support-CGr6SWrA.mjs"; //#region src/infra/exec-approval-surface.ts function labelForChannel(e) { if (e === "tui") return "terminal UI"; if (e === "webchat") return "Web UI"; return getChannelPlugin(e ?? "")?.meta.label ?? (e ? e[0]?.toUpperCase() + e.slice(1) : "this platform"); } function hasNativeExecApprovalCapability(e) { const t = resolveChannelApprovalCapability(getChannelPlugin(e ?? "")); if (!t?.native && !t?.nativeAsync) return false; return Boolean(t.getExecInitiatingSurfaceStateAsync || t.getExecInitiatingSurfaceState || t.getActionAvailabilityStateAsync || t.getActionAvailabilityState); } function resolveExecApprovalInitiatingSurfaceStateAsync(e) { return resolveApprovalInitiatingSurfaceStateAsync({ ...e, approvalKind: "exec" }); } async function resolveApprovalInitiatingSurfaceStateAsync(e) { const t = normalizeMessageChannel(e.channel); const n = labelForChannel(t); const r = normalizeOptionalString(e.accountId); if (!t || t === "webchat" || t === "tui") return { kind: "enabled", channel: t, channelLabel: n, accountId: r }; const i = e.cfg ?? readRuntimeConfig(); const a = resolveChannelApprovalCapability(getChannelPlugin(t)); if (e.approvalKind === "plugin" && !canChannelEnforcePluginReviewerPolicy(i, t, a)) return { kind: "disabled", channel: t, channelLabel: n, accountId: r }; const o = a?.getExecInitiatingSurfaceStateAsync ?? a?.getExecInitiatingSurfaceState; const s = (e.approvalKind === "exec" ? await o?.({ cfg: i, accountId: e.accountId, action: "approve" }) : void 0) ?? await (a?.getActionAvailabilityStateAsync ?? a?.getActionAvailabilityState)?.({ cfg: i, accountId: e.accountId, action: "approve", approvalKind: e.approvalKind, ...e.request ? { request: e.request } : {} }); if (s) return { ...s, channel: t, channelLabel: n, accountId: r }; if (isDeliverableMessageChannel(t)) return { kind: "enabled", channel: t, channelLabel: n, accountId: r }; return { kind: "unsupported", channel: t, channelLabel: n, accountId: r }; } function supportsNativeExecApprovalClient(e) { const t = normalizeMessageChannel(e); if (!t || t === "webchat" || t === "tui") return true; return hasNativeExecApprovalCapability(t); } function listNativeExecApprovalClientLabels(e) { const t = normalizeMessageChannel(e?.excludeChannel); return listChannelPlugins().filter((e) => e.id !== t).filter((e) => hasNativeExecApprovalCapability(e.id)).map((e) => normalizeOptionalString(e.meta.label)).filter((e) => Boolean(e)).toSorted((e, t) => e.localeCompare(t)); } function describeNativeApprovalClientSetup(e, t) { const n = normalizeMessageChannel(e.channel); if (!n || n === "webchat" || n === "tui") return null; const r = normalizeOptionalString(e.channelLabel) ?? labelForChannel(n); const i = normalizeOptionalString(e.accountId); const a = resolveChannelApprovalCapability(getChannelPlugin(n)); const o = { channel: n, channelLabel: r, accountId: i }; return t === "exec" ? a?.describeExecApprovalSetup?.(o) ?? null : a?.describePluginApprovalSetup?.(o) ?? null; } function describeNativeExecApprovalClientSetup(e) { return describeNativeApprovalClientSetup(e, "exec"); } function describeNativePluginApprovalClientSetup(e) { return describeNativeApprovalClientSetup(e, "plugin"); } //#endregion export { resolveExecApprovalInitiatingSurfaceStateAsync as a, resolveApprovalInitiatingSurfaceStateAsync as i, describeNativePluginApprovalClientSetup as n, supportsNativeExecApprovalClient as o, listNativeExecApprovalClientLabels as r, describeNativeExecApprovalClientSetup as t };