UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

31 lines (30 loc) • 1.47 kB
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs"; import { O as validateAgentRunDelegatedAuthority, c as getActiveAgentRunDelegatedAuthority } from "./agent-run-registry-D7vkrqFT.mjs"; //#region src/infra/mcp-tool-approval-binding.ts const bindings = resolveGlobalSingleton(Symbol.for("openclaw.mcpToolApprovalBindings"), () => /* @__PURE__ */ new WeakMap()); function registerMcpToolApprovalBinding(e) { const t = getActiveAgentRunDelegatedAuthority(e.authority.operationalRunInstance); if (!t || !validateAgentRunDelegatedAuthority(e.authority)) return () => {}; const n = bindings.get(t) ?? /* @__PURE__ */ new Set(); n.add(e); bindings.set(t, n); return () => n.delete(e); } function takeMcpToolApprovalBinding(e) { if (!validateAgentRunDelegatedAuthority(e.authority)) return; const t = getActiveAgentRunDelegatedAuthority(e.authority.operationalRunInstance); const n = t && bindings.get(t); const r = [...n ?? []].filter((t) => t.agentId === e.agentId && t.toolCallId === e.toolCallId && t.server === e.server && t.tool === e.tool); if (r.length !== 1) return; const i = r[0]; n.delete(i); return () => { try { return validateAgentRunDelegatedAuthority(i.authority) && i.isActive() && validateAgentRunDelegatedAuthority(i.authority) && validateAgentRunDelegatedAuthority(e.authority); } catch { return false; } }; } //#endregion export { takeMcpToolApprovalBinding as n, registerMcpToolApprovalBinding as t };