UNPKG

eve

Version:

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

2 lines • 1.77 kB
import{truncateTail}from"#execution/sandbox/truncate-output.js";function createLoggingSandboxSession(e){let{log:t,session:n}=e;return{...n,async run(e){t?.(`preparation run: ${formatCommand(e.command)}`);let r=await n.run(e);if(r.exitCode===1)throw Error(formatPreparationRunFailure(e.command,r));return r},async spawn(e){return t?.(`preparation spawn: ${formatCommand(e.command)}`),await n.spawn(e)},...n.setNetworkPolicy===void 0?{}:{async setNetworkPolicy(e){return t?.(`preparation set network policy: ${formatNetworkPolicy(e)}`),await n.setNetworkPolicy(e)}},async writeFile(e){return t?.(`preparation write file: ${e.path}`),await n.writeFile(e)},async writeBinaryFile(e){return t?.(`preparation write binary file: ${e.path} (${e.content.byteLength} bytes)`),await n.writeBinaryFile(e)},async writeTextFile(e){return t?.(`preparation write text file: ${e.path} (${e.content.length} chars)`),await n.writeTextFile(e)},async removePath(e){return t?.(`preparation remove path: ${e.path}`),await n.removePath(e)}}}function formatPreparationRunFailure(e,t){return[`Sandbox preparation failed because sandbox.run command exited with code 1:`,e,``,`stdout:`,formatCapturedOutput(`stdout`,t.stdout),``,`stderr:`,formatCapturedOutput(`stderr`,t.stderr)].join(` `)}function formatCapturedOutput(e,t){let n=truncateTail(t);return n.truncated?`[${e} truncated: showing last ${n.outputLines} of ${n.totalLines} lines]\n${n.output}`:n.output}function formatCommand(e){return truncateOneLine(e)}function formatNetworkPolicy(e){return truncateOneLine(typeof e==`string`?e:JSON.stringify(e,(e,t)=>e===`transform`?`[redacted]`:t))}function truncateOneLine(e){let t=e.replaceAll(/\s+/g,` `).trim();return t.length<=240?t:`${t.slice(0,239)}…`}export{createLoggingSandboxSession};