openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.13 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{t as asNonArrayRecord}from"./record-coerce-BTbqdJ3-.mjs";import{s as requireValidExecTarget}from"./exec-approvals-core-BZ6-zeZE.mjs";import{r as markToolExecutionNotStarted}from"./tool-effect-receipt-B6D3MzWJ.mjs";
//!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`}function isRequestedExecTargetAllowed(e){return e.requestedTarget===e.configuredTarget||e.configuredTarget===`auto`&&(!e.sandboxAvailable||e.requestedTarget!==`gateway`&&e.requestedTarget!==`node`)}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}function canInterruptExec(e,t){try{const n=asNonArrayRecord(e);if(n.background===true||n.durable)return false;const r=resolveExecHost(n,t);return r===`gateway`||r===`sandbox`&&Boolean(t?.sandbox?.prepareProcessCleanup)}catch{return false}}export{resolveExecTarget as a,resolveExecHost as i,isRequestedExecTargetAllowed as n,resolveRequestedExecTarget as o,resolveExecElevatedMode as r,canInterruptExec as t};