UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

59 lines (58 loc) • 3.31 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { s as requireValidExecTarget } from "./exec-approvals-core-puBAw1bE.mjs"; import { r as markToolExecutionNotStarted } from "./tool-effect-receipt-BbbEwqBS.mjs"; //#region src/agents/bash-tools.exec-target.ts function resolveRequestedExecTarget(e) { const t = requireValidExecTarget(e.host); const n = normalizeOptionalString(e.node); if (!n) return t; if (e.host != null && t !== "node") throw markToolExecutionNotStarted(/* @__PURE__ */ new Error(`exec node=${JSON.stringify(n)} conflicts with host=${JSON.stringify(e.host)}; omit host or use host="node" to run on this node.`)); return "node"; } /** Returns true when a per-call target override is allowed by configured policy. */ function isRequestedExecTargetAllowed(e) { return e.requestedTarget === e.configuredTarget || e.configuredTarget === "auto" && (!e.sandboxAvailable || e.requestedTarget !== "gateway" && e.requestedTarget !== "node"); } /** Resolves configured/requested/elevated exec target into an effective host. */ function resolveExecTarget(e) { const t = e.sandboxRequired === true; if (t && !e.sandboxAvailable) throw markToolExecutionNotStarted(/* @__PURE__ */ new Error("This session requires a sandbox, but its sandbox runtime is unavailable.")); if (t && e.elevatedRequested) throw markToolExecutionNotStarted(/* @__PURE__ */ new Error("Elevated execution is unavailable because this session requires a sandbox.")); const n = t ? "auto" : e.configuredTarget ?? "auto"; const r = e.requestedTarget === "auto" ? null : e.requestedTarget ?? null; if (t && (r === "gateway" || r === "node")) throw markToolExecutionNotStarted(/* @__PURE__ */ new Error(`exec host not allowed (requested ${r}; this session requires a sandbox).`)); if (r && !isRequestedExecTargetAllowed({ configuredTarget: n, requestedTarget: r, sandboxAvailable: e.sandboxAvailable })) { const t = (n === "auto" && e.sandboxAvailable && (r === "gateway" || r === "node") ? [r] : [r, "auto"]).join(" or "); throw markToolExecutionNotStarted(/* @__PURE__ */ new Error(`exec host not allowed (requested ${r}; configured host is ${n}; set tools.exec.host=${t} to allow this override).`)); } const i = r ?? n; const a = e.elevatedRequested ? i === "node" ? "node" : "gateway" : i; return { configuredTarget: n, requestedTarget: r, selectedTarget: a, effectiveHost: a === "auto" ? e.sandboxAvailable ? "sandbox" : "gateway" : a }; } function resolveExecElevatedMode(e, t) { const n = e?.elevated; const r = n?.defaultLevel === "full" ? "full" : n?.defaultLevel === "ask" || n?.defaultLevel === "on" ? "ask" : "off"; if (typeof t === "boolean") return t ? r === "full" ? "full" : "ask" : "off"; return n?.enabled && n.allowed && !e?.sandboxRequired ? r : "off"; } function resolveExecHost(e, t) { const n = resolveExecElevatedMode(t, e.elevated); return resolveExecTarget({ configuredTarget: t?.host, requestedTarget: resolveRequestedExecTarget(e), elevatedRequested: n !== "off", sandboxAvailable: Boolean(t?.sandbox), sandboxRequired: t?.sandboxRequired }).effectiveHost; } //#endregion export { resolveRequestedExecTarget as a, resolveExecTarget as i, resolveExecElevatedMode as n, resolveExecHost as r, isRequestedExecTargetAllowed as t };