UNPKG

eve

Version:

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

1 lines 1.13 kB
import{AsyncLocalStorage}from"node:async_hooks";function createRuntimeSession(e=`test-session`){return{bundleCache:new Map,bundleCacheKeyBySourceKey:new Map,compiledArtifacts:null,id:e}}const RUNTIME_SESSION_STORAGE_GLOBAL_KEY=Symbol.for(`eve.runtime-session-storage`),RUNTIME_SESSION_DEFAULT_GLOBAL_KEY=Symbol.for(`eve.runtime-session-default`),globalContainer=globalThis;globalContainer[RUNTIME_SESSION_STORAGE_GLOBAL_KEY]===void 0&&(globalContainer[RUNTIME_SESSION_STORAGE_GLOBAL_KEY]=new AsyncLocalStorage);const runtimeSessionStorage=globalContainer[RUNTIME_SESSION_STORAGE_GLOBAL_KEY];function resolveProcessDefaultSession(){return globalContainer[RUNTIME_SESSION_DEFAULT_GLOBAL_KEY]===void 0&&(globalContainer[RUNTIME_SESSION_DEFAULT_GLOBAL_KEY]=createRuntimeSession(`process-default`)),globalContainer[RUNTIME_SESSION_DEFAULT_GLOBAL_KEY]}function getActiveRuntimeSession(){return runtimeSessionStorage.getStore()??resolveProcessDefaultSession()}async function withRuntimeSession(e,t){return await runtimeSessionStorage.run(e,async()=>await t())}export{createRuntimeSession,getActiveRuntimeSession,withRuntimeSession};