UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 1.48 kB
import{isEveDevEnvironment}from"#internal/application/optional-package-install.js";import{truncateTail}from"#execution/sandbox/truncate-output.js";async function executeBashOnSandbox(e,t){let n=await runWithDevelopmentSandboxProgress(e,t.command),r=truncateTail(n.stdout),i=truncateTail(n.stderr),a=r.truncated||i.truncated,o=r.output;r.truncated&&(o=`[stdout truncated: showing last ${r.outputLines} of ${r.totalLines} lines]\n`+o);let s=i.output;return i.truncated&&(s=`[stderr truncated: showing last ${i.outputLines} of ${i.totalLines} lines]\n`+s),{exitCode:n.exitCode,stderr:s,stdout:o,truncated:a}}async function runWithDevelopmentSandboxProgress(e,t){if(logDevelopmentSandboxCommand(`eve: starting sandbox command: ${formatCommand(t)}`),!isEveDevEnvironment())return await e.run({command:t});let n=Date.now(),r=setInterval(()=>{logDevelopmentSandboxCommand(`eve: waiting for sandbox command (${Math.round((Date.now()-n)/1e3)}s elapsed): ${formatCommand(t)}`)},5e3);r.unref?.();try{let n=await e.run({command:t});return logDevelopmentSandboxCommand(`eve: sandbox command finished (exit ${n.exitCode}): ${formatCommand(t)}`),n}catch(e){throw logDevelopmentSandboxCommand(`eve: sandbox command failed: ${formatCommand(t)}`),e}finally{clearInterval(r)}}function logDevelopmentSandboxCommand(e){isEveDevEnvironment()&&console.log(e)}function formatCommand(e){let t=e.replaceAll(/\s+/g,` `).trim();return t.length<=240?t:`${t.slice(0,239)}…`}export{executeBashOnSandbox};