UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

41 lines (40 loc) • 2.04 kB
import { l as isRecord, t as asNonArrayRecord } from "./record-coerce-CVPuDqcc.mjs"; //#region src/agents/mcp-codex-tool-approval.ts function normalizeApprovalMode(e) { return e === "auto" || e === "prompt" || e === "approve" ? e : void 0; } function isOpenClawLoopbackServer(e, t) { return e === "openclaw" && typeof t.url === "string" && /^https?:\/\/(?:127\.0\.0\.1|localhost):\d+\/mcp(?:[?#].*)?$/.test(t.url); } /** Mirrors the approval default projected into Codex native MCP config. */ function resolveProjectedMcpCodexToolApprovalMode(e, t, n, r) { const i = asNonArrayRecord(t.codex); const a = isRecord(n?.tools) ? n.tools : void 0; return normalizeApprovalMode((r && isRecord(a?.[r]) ? a[r] : void 0)?.approval_mode) ?? normalizeApprovalMode(i.defaultToolsApprovalMode) ?? normalizeApprovalMode(i.default_tools_approval_mode) ?? normalizeApprovalMode(n?.default_tools_approval_mode) ?? (isOpenClawLoopbackServer(e, t) ? "approve" : void 0); } function normalizeMcpCodexToolAnnotations(e) { if (!isRecord(e)) return {}; const t = {}; for (const n of [ "readOnlyHint", "destructiveHint", "idempotentHint", "openWorldHint" ]) if (typeof e[n] === "boolean") t[n] = e[n]; return t; } /** Explicit server policy outranks the prepared session posture. */ function requiresMcpCodexToolApproval(e) { const t = e.mode ?? (e.fullPermission ? "approve" : "auto"); if (t === "approve") return false; if (t === "prompt") return true; const n = e.annotations ?? {}; if (n.destructiveHint === true) return true; if (n.readOnlyHint === true) return false; return n.destructiveHint !== false || n.openWorldHint !== false; } function formatMcpCodexApprovalRemedy(e) { return `Run openclaw mcp configure ${e && /^[\w.][\w.-]{0,127}$/.test(e) ? e : "<server>"} --approval approve for a trusted server, or change the session permission mode.`; } //#endregion export { resolveProjectedMcpCodexToolApprovalMode as i, normalizeMcpCodexToolAnnotations as n, requiresMcpCodexToolApproval as r, formatMcpCodexApprovalRemedy as t };