eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.23 kB
JavaScript
import{rm}from"node:fs/promises";import{materializeAuthoredModules}from"#internal/materialized-authored-modules.js";import{activateDevelopmentRuntimeArtifactsSnapshotTransaction,pruneDevelopmentRuntimeArtifactsSnapshots,stageDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts.js";const developmentGenerationPruneStates=new Map;async function stageDevelopmentGeneration(n){let r=await stageDevelopmentRuntimeArtifactsSnapshot(n);try{let e=await materializeAuthoredModules({runtimeAppRoot:r.runtimeAppRoot});return{...r,fingerprint:e.fingerprint}}catch(t){try{await rm(r.snapshotRoot,{force:!0,recursive:!0})}catch(e){throw AggregateError([t,e],`Failed to materialize and discard development generation "${r.snapshotRoot}".`)}throw t}}async function publishDevelopmentGeneration(e){let t=await stageDevelopmentGeneration(e);return await activateDevelopmentGeneration({appRoot:e.project.appRoot,generation:t}),t}async function activateDevelopmentGeneration(e){(await activateDevelopmentGenerationTransaction(e)).commit()}async function activateDevelopmentGenerationTransaction(e){let t=await activateDevelopmentRuntimeArtifactsSnapshotTransaction({appRoot:e.appRoot,snapshot:e.generation}),r=!1;return{commit(){r||(r=!0,t.commit(),requestDevelopmentGenerationPrune(e.appRoot))},async rollback(){r||(r=!0,await t.rollback())}}}async function discardDevelopmentGeneration(t){await rm(t.snapshotRoot,{force:!0,recursive:!0})}function requestDevelopmentGenerationPrune(e){let t=developmentGenerationPruneStates.get(e)??{requested:!1,running:void 0};developmentGenerationPruneStates.set(e,t),t.requested=!0,t.running===void 0&&startDevelopmentGenerationPruning(e,t)}function startDevelopmentGenerationPruning(e,t){t.running=(async()=>{for(;t.requested;)t.requested=!1,await pruneDevelopmentRuntimeArtifactsSnapshots({appRoot:e})})().catch(e=>{console.warn(`[eve:dev] failed to prune runtime generations: ${String(e)}`)}).finally(()=>{t.running=void 0,t.requested?startDevelopmentGenerationPruning(e,t):developmentGenerationPruneStates.delete(e)})}export{activateDevelopmentGeneration,activateDevelopmentGenerationTransaction,discardDevelopmentGeneration,publishDevelopmentGeneration,stageDevelopmentGeneration};