UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

89 lines (88 loc) • 4.59 kB
import { a as resolveApprovalApprovers } from "./approval-auth-helpers-nDvq-VbZ.mjs"; import { t as matchesApprovalRequestFilters } from "./approval-request-filters-BbqeKS4j.mjs"; import { i as isChannelExecApprovalTargetRecipient, n as createChannelExecApprovalProfileAsync, r as isChannelExecApprovalClientEnabledFromConfig } from "./approval-client-helpers-CHZa9PWz.mjs"; import "./approval-client-runtime-CGzu5ZKQ.mjs"; import { o as doesApprovalRequestSelectChannelAccountAsync } from "./approval-request-account-binding-DOCAr58L.mjs"; import "./approval-native-runtime-DBG67Vog.mjs"; import { i as resolveTelegramAccount, r as resolveDefaultTelegramAccountId } from "./accounts-C26vVqsr.mjs"; import { o as normalizeTelegramChatId, u as resolveTelegramTargetChatType } from "./topic-conversation-CDf2PinB.mjs"; //#region extensions/telegram/src/exec-approvals.ts function normalizeTelegramDirectApproverId(e) { const t = normalizeTelegramChatId(String(e)); return t && !t.startsWith("-") ? t : void 0; } function resolveTelegramExecApprovalConfig(e) { const t = resolveTelegramAccount(e); const n = t.config.execApprovals; const r = t.enabled && t.tokenSource !== "none" ? n?.enabled ?? "auto" : false; return { ...n, enabled: r }; } function getTelegramExecApprovalApprovers(e) { return resolveApprovalApprovers({ explicit: resolveTelegramExecApprovalConfig(e)?.approvers, allowFrom: Array.isArray(e.cfg.commands?.ownerAllowFrom) ? e.cfg.commands.ownerAllowFrom : [], normalizeApprover: normalizeTelegramDirectApproverId }); } function isTelegramExecApprovalTargetRecipient(e) { return isChannelExecApprovalTargetRecipient({ ...e, channel: "telegram", matchTarget: ({ target: e, normalizedSenderId: t }) => { const n = e.to ? normalizeTelegramDirectApproverId(e.to) : void 0; return n !== void 0 && n === t; } }); } function isTelegramExecApprovalAccountEligible(e) { const t = resolveTelegramAccount(e); if (!t.enabled || t.tokenSource === "none") return false; const n = resolveTelegramExecApprovalConfig(e); return isChannelExecApprovalClientEnabledFromConfig({ enabled: n?.enabled, approverCount: getTelegramExecApprovalApprovers(e).length }) && matchesApprovalRequestFilters({ request: e.request.request, agentFilter: n?.agentFilter, sessionFilter: n?.sessionFilter, fallbackAgentIdFromSessionKey: true }); } async function matchesTelegramRequestAccount(e) { const t = e.accountId ?? resolveDefaultTelegramAccountId(e.cfg); return doesApprovalRequestSelectChannelAccountAsync({ ...e, channel: "telegram", defaultAccountId: resolveDefaultTelegramAccountId(e.cfg), eligibleAccountIds: isTelegramExecApprovalAccountEligible({ ...e, accountId: t }) ? [t] : [] }); } const telegramExecApprovalProfile = createChannelExecApprovalProfileAsync({ resolveConfig: resolveTelegramExecApprovalConfig, resolveApprovers: getTelegramExecApprovalApprovers, isTargetRecipient: isTelegramExecApprovalTargetRecipient, matchesRequestAccount: matchesTelegramRequestAccount, fallbackAgentIdFromSessionKey: true, requireClientEnabledForLocalPromptSuppression: false }); const isTelegramExecApprovalClientEnabled = telegramExecApprovalProfile.isClientEnabled; const isTelegramExecApprovalApprover = telegramExecApprovalProfile.isApprover; const isTelegramExecApprovalAuthorizedSender = telegramExecApprovalProfile.isAuthorizedSender; const resolveTelegramExecApprovalTarget = telegramExecApprovalProfile.resolveTarget; const shouldHandleTelegramExecApprovalRequest = telegramExecApprovalProfile.shouldHandleRequest; function shouldInjectTelegramExecApprovalButtons(e) { if (!isTelegramExecApprovalClientEnabled(e)) return false; const t = resolveTelegramExecApprovalTarget(e); const n = resolveTelegramTargetChatType(e.to); return t === "both" || n === "direct" && t === "dm" || n === "group" && t === "channel"; } const shouldSuppressLocalTelegramExecApprovalPrompt = telegramExecApprovalProfile.shouldSuppressLocalPrompt; const isTelegramExecApprovalHandlerConfigured = telegramExecApprovalProfile.isClientEnabled; //#endregion export { isTelegramExecApprovalHandlerConfigured as a, resolveTelegramExecApprovalTarget as c, shouldSuppressLocalTelegramExecApprovalPrompt as d, isTelegramExecApprovalClientEnabled as i, shouldHandleTelegramExecApprovalRequest as l, isTelegramExecApprovalApprover as n, isTelegramExecApprovalTargetRecipient as o, isTelegramExecApprovalAuthorizedSender as r, resolveTelegramExecApprovalConfig as s, getTelegramExecApprovalApprovers as t, shouldInjectTelegramExecApprovalButtons as u };