eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.73 kB
JavaScript
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 new Proxy(Object.create(null),{get(r,i){if(i===`delete`)return t;if(i===`stop`)return n;let a=Reflect.get(e,i,e);return typeof a==`function`?a.bind(e):a},getOwnPropertyDescriptor(t,n){if(n===`delete`||n===`stop`)return{configurable:!0,enumerable:!0,writable:!1};let r=Reflect.getOwnPropertyDescriptor(e,n);return r===void 0?void 0:{...r,configurable:!0}},has(t,n){return n===`delete`||n===`stop`||Reflect.has(e,n)},ownKeys(){return[...new Set([...Reflect.ownKeys(e),`delete`,`stop`])]}})}export{buildCallbackContext,withRuntimeSandboxLifecycle};