UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

118 lines (117 loc) • 4.85 kB
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs"; import { t as warnPluginSdkDeprecation } from "./sdk-deprecation-D5N9acnu.mjs"; import "./routing-DmgGYTrU.mjs"; import { t as matchesApprovalRequestFilters } from "./approval-request-filters-BbqeKS4j.mjs"; import { f as getExecApprovalReplyMetadata } from "./exec-approval-reply-CfpNUvnC.mjs"; //#region src/plugin-sdk/approval-client-helpers.ts function isApprovalTargetsMode(e) { const t = e.approvals?.exec; if (!t?.enabled) return false; return t.mode === "targets" || t.mode === "both"; } /** Return whether a channel account has an enabled approval client and at least one approver. */ function isChannelExecApprovalClientEnabledFromConfig(e) { if (e.approverCount <= 0) return false; return e.enabled === true || e.enabled === "auto"; } /** * Return whether a sender is one of the configured global exec approval forward targets. * Channel plugins provide the target matcher because `to` shapes differ by provider. */ function isChannelExecApprovalTargetRecipient(e) { const t = e.normalizeSenderId ?? normalizeOptionalString; const n = e.senderId ? t(e.senderId) : void 0; const r = normalizeOptionalLowercaseString(e.channel); if (!n || !isApprovalTargetsMode(e.cfg)) return false; const i = e.cfg.approvals?.exec?.targets; if (!i) return false; const a = e.accountId ? normalizeAccountId(e.accountId) : void 0; return i.some((t) => { if (normalizeOptionalLowercaseString(t.channel) !== r) return false; if (a && t.accountId && normalizeAccountId(t.accountId) !== a) return false; return e.matchTarget({ target: t, normalizedSenderId: n, normalizedAccountId: a }); }); } /** @deprecated Use createChannelExecApprovalProfileAsync for worker-owned account matching. Final compatibility day: 2026-12-31. Removal in the first January 2027 stable release. */ function createChannelExecApprovalProfile(e) { warnPluginSdkDeprecation({ family: "approval-session-routing", method: "createChannelExecApprovalProfile", replacement: "createChannelExecApprovalProfileAsync" }); const t = createChannelExecApprovalProfileBase(e); return { ...t, shouldHandleRequest: (n) => (!e.matchesRequestAccount || e.matchesRequestAccount(n)) && t.shouldHandleRequest(n) }; } function createChannelExecApprovalProfileBase(e) { const t = e.normalizeSenderId ?? normalizeOptionalString; const isClientEnabled = (t) => { return isChannelExecApprovalClientEnabledFromConfig({ enabled: e.resolveConfig(t)?.enabled, approverCount: e.resolveApprovers(t).length }); }; const isApprover = (n) => { const r = n.senderId ? t(n.senderId) : void 0; if (!r) return false; return e.resolveApprovers(n).includes(r); }; const isAuthorizedSender = (t) => { return isApprover(t) || (e.isTargetRecipient?.(t) ?? false); }; const resolveTarget = (t) => { return e.resolveConfig(t)?.target ?? "dm"; }; const shouldHandleRequest = (t) => { const n = e.resolveConfig(t); const r = e.resolveApprovers(t).length; if (!isChannelExecApprovalClientEnabledFromConfig({ enabled: n?.enabled, approverCount: r })) return false; return matchesApprovalRequestFilters({ request: t.request.request, agentFilter: n?.agentFilter, sessionFilter: n?.sessionFilter, fallbackAgentIdFromSessionKey: e.fallbackAgentIdFromSessionKey === true }); }; const shouldSuppressLocalPrompt = (t) => { if (e.requireClientEnabledForLocalPromptSuppression !== false && !isClientEnabled(t)) return false; return getExecApprovalReplyMetadata(t.payload) !== null; }; return { /** Whether this account has an enabled channel approval client and approvers. */ isClientEnabled, /** Whether a sender is in the resolved approver set. */ isApprover, /** Whether a sender is either an approver or a configured approval target. */ isAuthorizedSender, /** Preferred delivery target, defaulting to approver DMs. */ resolveTarget, /** Whether this profile should handle a forwarded approval request. */ shouldHandleRequest, /** Whether a local approval prompt should be suppressed for an already-rendered payload. */ shouldSuppressLocalPrompt }; } /** Build a profile that awaits worker-owned account eligibility. */ function createChannelExecApprovalProfileAsync(e) { const t = createChannelExecApprovalProfileBase({ ...e, matchesRequestAccount: void 0 }); return { ...t, shouldHandleRequest: async (n) => t.shouldHandleRequest(n) && (!e.matchesRequestAccount || await e.matchesRequestAccount(n)) }; } //#endregion export { isChannelExecApprovalTargetRecipient as i, createChannelExecApprovalProfileAsync as n, isChannelExecApprovalClientEnabledFromConfig as r, createChannelExecApprovalProfile as t };