UNPKG

eve

Version:

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

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