UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

57 lines (56 loc) • 2.4 kB
import { n as EXEC_APPROVAL_DECISIONS, r as normalizeExecAsk } from "./exec-approvals-core-puBAw1bE.mjs"; import { isDeepStrictEqual } from "node:util"; //#region src/infra/exec-approvals-policy.ts function requiresExecApproval(e) { if (e.ask === "always") return true; if (e.durableApprovalSatisfied === true) return false; return e.ask === "on-miss" && e.security === "allowlist" && (!e.analysisOk || !e.allowlistSatisfied); } function minSecurity(e, t) { const n = { deny: 0, allowlist: 1, full: 2 }; return n[e] <= n[t] ? e : t; } function maxAsk(e, t) { const n = { off: 0, "on-miss": 1, always: 2 }; return n[e] >= n[t] ? e : t; } const OPTIONAL_EXEC_APPROVAL_DECISIONS = ["allow-always"]; function normalizeExecApprovalUnavailableDecisions(e) { return OPTIONAL_EXEC_APPROVAL_DECISIONS.filter((t) => Array.isArray(e) && e.includes(t)); } function resolveExecApprovalAllowedDecisions(e) { if (normalizeExecAsk(e?.ask) === "always" || e?.allowAlwaysPersistence?.kind === "one-shot") return ["allow-once", "deny"]; return EXEC_APPROVAL_DECISIONS; } function resolveExecApprovalUnavailableDecisions(e) { const t = new Set(resolveExecApprovalAllowedDecisions(e)); return OPTIONAL_EXEC_APPROVAL_DECISIONS.filter((e) => !t.has(e)); } function resolveExecApprovalRequestAllowedDecisions(e) { const t = resolveExecApprovalAllowedDecisions({ ask: e?.ask }); const n = new Set(normalizeExecApprovalUnavailableDecisions(e?.unavailableDecisions)); if (n.size === 0) return t; return t.filter((e) => !n.has(e)); } /** These worker commands may change grants/usage, never host execution floors. */ function assertExecApprovalsHostPolicyUnchanged(e, t) { const fields = (e) => ({ security: e.defaults?.security, ask: e.defaults?.ask, agents: Object.fromEntries(Object.entries(e.agents ?? {}).filter(([, e]) => e.security !== void 0 || e.ask !== void 0).map(([e, t]) => [e, { security: t.security, ask: t.ask }])) }); if (!isDeepStrictEqual(fields(e), fields(t))) throw new Error("Exec grant workers cannot change host security or ask policy"); } //#endregion export { requiresExecApproval as a, resolveExecApprovalUnavailableDecisions as c, normalizeExecApprovalUnavailableDecisions as i, maxAsk as n, resolveExecApprovalAllowedDecisions as o, minSecurity as r, resolveExecApprovalRequestAllowedDecisions as s, assertExecApprovalsHostPolicyUnchanged as t };