UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

111 lines (110 loc) • 2.94 kB
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs"; //#region src/infra/exec-approvals-core.ts const EXEC_APPROVAL_DECISIONS = [ "allow-once", "allow-always", "deny" ]; const EXEC_TARGET_VALUES = [ "auto", "sandbox", "gateway", "node" ]; function normalizeExecPolicyValue(e, t) { const n = normalizeOptionalLowercaseString(e); return t.find((e) => e === n) ?? null; } function normalizeExecTarget(e) { return normalizeExecPolicyValue(e, EXEC_TARGET_VALUES); } function requireValidExecTarget(e) { if (e == null) return null; if (typeof e !== "string") throw new Error(`Invalid exec host value type ${typeof e}. Allowed values: ${EXEC_TARGET_VALUES.join(", ")}.`); const t = normalizeOptionalLowercaseString(e); if (!t) return null; const n = normalizeExecTarget(t); if (n) return n; throw new Error(`Invalid exec host "${e}". Allowed values: ${EXEC_TARGET_VALUES.join(", ")}.`); } function normalizeExecSecurity(e) { return normalizeExecPolicyValue(e, [ "deny", "allowlist", "full" ]); } function normalizeExecAsk(e) { return normalizeExecPolicyValue(e, [ "off", "on-miss", "always" ]); } function normalizeExecMode(e) { return normalizeExecPolicyValue(e, [ "deny", "allowlist", "ask", "auto", "full" ]); } function resolveExecModeFromPolicy(e) { if (e.security === "deny") return "deny"; if (e.security === "allowlist" && e.ask === "off") return "allowlist"; if (e.security === "full" && e.ask !== "always") return "full"; return "ask"; } function resolveExactExecModeFromPolicy(e) { if (e.ask === "always" || e.security === "full" && e.ask === "on-miss") return null; return resolveExecModeFromPolicy(e); } function resolveExecPolicyForMode(e) { switch (e) { case "deny": return { security: "deny", ask: "off", autoReview: false }; case "allowlist": return { security: "allowlist", ask: "off", autoReview: false }; case "ask": return { security: "allowlist", ask: "on-miss", autoReview: false }; case "auto": return { security: "allowlist", ask: "on-miss", autoReview: true }; case "full": return { security: "full", ask: "off", autoReview: false }; } throw new Error(`Unsupported exec mode: ${String(e)}`); } function resolveExecModePolicy(e) { if (!e.mode) return { mode: resolveExecModeFromPolicy({ security: e.security, ask: e.ask }), security: e.security, ask: e.ask, autoReview: false }; return { mode: e.mode, ...resolveExecPolicyForMode(e.mode) }; } const DEFAULT_EXEC_APPROVAL_TIMEOUT_MS = 18e5; //#endregion export { normalizeExecSecurity as a, resolveExactExecModeFromPolicy as c, resolveExecPolicyForMode as d, normalizeExecMode as i, resolveExecModeFromPolicy as l, EXEC_APPROVAL_DECISIONS as n, normalizeExecTarget as o, normalizeExecAsk as r, requireValidExecTarget as s, DEFAULT_EXEC_APPROVAL_TIMEOUT_MS as t, resolveExecModePolicy as u };