UNPKG

eve

Version:

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

1 lines 1.58 kB
import{loadContext}from"#context/container.js";import{SandboxKey,SessionKey}from"#context/keys.js";import{createSandboxSkillHandle}from"#runtime/skills/sandbox-access.js";function buildCallbackContext(){let e=loadContext(),t=e.require(SessionKey);return{session:{id:t.sessionId,auth:t.auth,turn:t.turn,parent:t.parent},getSandbox(){let t=e.get(SandboxKey);if(t===void 0)throw Error(`eve sandbox runtime access is unavailable in the current async context. Call ctx.getSandbox() only from authored runtime functions such as tools, hooks, and channel events.`);return t.get().then(e=>{if(e===null)throw Error(`The sandbox is not available in the current authored runtime context.`);return withRuntimeSandboxLifecycle(e,async e=>{if(t.delete===void 0)throw Error(`The active sandbox runtime does not support deletion.`);await t.delete(e)},async()=>await t.stop())})},getSkill(t){let n=e.get(SandboxKey);if(n===void 0)throw Error(`eve sandbox runtime access is unavailable in the current async context. Call ctx.getSkill() only from authored runtime functions such as tools, hooks, and channel events.`);return createSandboxSkillHandle(n,t)}}}function withRuntimeSandboxLifecycle(e,t,n){return{delete:t,id:e.id,readBinaryFile:t=>e.readBinaryFile(t),readFile:t=>e.readFile(t),readTextFile:t=>e.readTextFile(t),removePath:t=>e.removePath(t),resolvePath:t=>e.resolvePath(t),run:t=>e.run(t),setNetworkPolicy:t=>e.setNetworkPolicy(t),spawn:t=>e.spawn(t),stop:n,writeBinaryFile:t=>e.writeBinaryFile(t),writeFile:t=>e.writeFile(t),writeTextFile:t=>e.writeTextFile(t)}}export{buildCallbackContext};