UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

96 lines (95 loc) • 3.36 kB
import { c as normalizeOptionalLowercaseString } from "./string-coerce-1VuiLaaR.mjs"; //#region src/infra/exec-approvals-core.ts const EXEC_TARGET_VALUES = [ "auto", "sandbox", "gateway", "node" ]; function normalizeExecTarget(value) { const normalized = normalizeOptionalLowercaseString(value); if (normalized === "auto" || normalized === "sandbox" || normalized === "gateway" || normalized === "node") return normalized; return null; } function requireValidExecTarget(value) { if (value == null) return null; if (typeof value !== "string") throw new Error(`Invalid exec host value type ${typeof value}. Allowed values: ${EXEC_TARGET_VALUES.join(", ")}.`); const normalized = normalizeOptionalLowercaseString(value); if (!normalized) return null; const target = normalizeExecTarget(normalized); if (target) return target; throw new Error(`Invalid exec host "${value}". Allowed values: ${EXEC_TARGET_VALUES.join(", ")}.`); } function normalizeExecSecurity(value) { const normalized = normalizeOptionalLowercaseString(value); if (normalized === "deny" || normalized === "allowlist" || normalized === "full") return normalized; return null; } function normalizeExecAsk(value) { const normalized = normalizeOptionalLowercaseString(value); if (normalized === "off" || normalized === "on-miss" || normalized === "always") return normalized; return null; } function normalizeExecMode(value) { const normalized = normalizeOptionalLowercaseString(value); if (normalized === "deny" || normalized === "allowlist" || normalized === "ask" || normalized === "auto" || normalized === "full") return normalized; return null; } function resolveExecModeFromPolicy(params) { if (params.security === "deny") return "deny"; if (params.security === "allowlist" && params.ask === "off") return "allowlist"; if (params.security === "full" && params.ask !== "always") return "full"; return "ask"; } function resolveExactExecModeFromPolicy(params) { if (params.ask === "always" || params.security === "full" && params.ask === "on-miss") return null; return resolveExecModeFromPolicy(params); } function resolveExecPolicyForMode(mode) { switch (mode) { 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(mode)}`); } function resolveExecModePolicy(params) { if (!params.mode) return { mode: resolveExecModeFromPolicy({ security: params.security, ask: params.ask }), security: params.security, ask: params.ask, autoReview: false }; return { mode: params.mode, ...resolveExecPolicyForMode(params.mode) }; } const DEFAULT_EXEC_APPROVAL_TIMEOUT_MS = 18e5; //#endregion export { normalizeExecTarget as a, resolveExecModeFromPolicy as c, normalizeExecSecurity as i, resolveExecModePolicy as l, normalizeExecAsk as n, requireValidExecTarget as o, normalizeExecMode as r, resolveExactExecModeFromPolicy as s, DEFAULT_EXEC_APPROVAL_TIMEOUT_MS as t, resolveExecPolicyForMode as u };