openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.87 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{h as readRuntimeConfig}from"./runtime-snapshot-Bg5K4JNu.mjs";import{t as INTERNAL_MESSAGE_CHANNEL}from"./message-channel-constants-BbP_hczw.mjs";import{n as normalizeMessageChannel}from"./message-channel-core-D_hPOadj.mjs";import{t as isDeliverableMessageChannel}from"./message-channel-normalize-hDAO6_JQ.mjs";import{r as listChannelPlugins,t as getChannelPlugin}from"./registry-CpNh6QcT.mjs";import"./message-channel-514k57tV.mjs";import{n as resolveChannelApprovalCapability}from"./plugins-DxOycUNJ.mjs";import"./config-DkZ8y8Gv.mjs";import{t as canChannelEnforcePluginReviewerPolicy}from"./approval-channel-policy-support-C1UTUR8o.mjs";
//!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`)}export{resolveExecApprovalInitiatingSurfaceStateAsync as a,resolveApprovalInitiatingSurfaceStateAsync as i,describeNativePluginApprovalClientSetup as n,supportsNativeExecApprovalClient as o,listNativeExecApprovalClientLabels as r,describeNativeExecApprovalClientSetup as t};