UNPKG

eve

Version:

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

1 lines • 4.92 kB
import{stageDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{createDevelopmentApplicationNitro}from"#internal/nitro/host/create-application-nitro.js";import{prepareDevelopmentApplicationHost}from"#internal/nitro/host/prepare-application-host.js";import{buildDevelopmentHostCandidate}from"#internal/nitro/host/dev-host-candidate.js";import{computeDevelopmentHostFingerprint}from"#internal/nitro/host/dev-host-fingerprint.js";import{removeDevelopmentHostWorkspace}from"#internal/nitro/host/dev-host-workspace.js";import"#internal/nitro/host/drained-nitro-dev-server.js";import{activateDevelopmentGeneration,discardDevelopmentGeneration}from"#internal/nitro/development-generation.js";var PostCommitDevelopmentRebuildError=class extends Error{constructor(e){super(`The development worker was replaced but its generation failed to activate. The server keeps serving the previous generation; the next rebuild retries activation.`,{cause:e}),this.name=`PostCommitDevelopmentRebuildError`}},DevelopmentWorkflowWorldChangeRequiresRestartError=class extends Error{constructor(){super(`Changing experimental.workflow.world between the parent-owned local World and a custom World requires restarting eve dev.`),this.name=`DevelopmentWorkflowWorldChangeRequiresRestartError`}};async function createDevelopmentAuthoredRebuildCoordinator(e){return new TransactionalDevelopmentAuthoredRebuildCoordinator({currentHostFingerprint:await computeDevelopmentHostFingerprint(e.initialHost),developmentExtensions:e.developmentExtensions,currentRuntimeFingerprint:e.initialHost.generation.fingerprint,devServer:e.devServer,initialHost:e.initialHost})}var TransactionalDevelopmentAuthoredRebuildCoordinator=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=e.initialHost,this.#t=e.currentHostFingerprint,this.#r=e.developmentExtensions,this.#n=e.currentRuntimeFingerprint,this.#i=e.devServer,this.#a=usesParentDevelopmentWorkflowWorld(e.initialHost.compileResult.manifest.config.experimental?.workflow?.world)}async rebuild(e){let t=this.#e,n=stageDevelopmentEnvironmentFiles(t.appRoot),r;try{if(r=await prepareDevelopmentApplicationHost(t.appRoot,{changedPaths:e.changedPaths,developmentExtensions:this.#r,previousExtensions:t.workspaceExtensions}),usesParentDevelopmentWorkflowWorld(r.compileResult.manifest.config.experimental?.workflow?.world)!==this.#a)throw new DevelopmentWorkflowWorldChangeRequiresRestartError;let i=await computeDevelopmentHostFingerprint(r),a=r.generation.fingerprint,o=i!==this.#t,s=a!==this.#n;if(!o&&!s){let e={...t,workspaceExtensions:r.workspaceExtensions};return await discardPreparedHost(r),r=void 0,this.#s(e,this.#t,this.#n),n.commit(),{host:e,kind:`unchanged`}}if(!o){await removeDevelopmentHostWorkspace(r.workspace);let e=retainActiveHostWorkspace(t,r);return await activateDevelopmentGeneration({appRoot:e.appRoot,generation:e.generation}),this.#s(e,i,a),r=void 0,n.commit(),{host:e,kind:`runtime`}}let c=await this.#o({hasRuntimeChange:s,nextHost:r,nextHostFingerprint:i,nextRuntimeFingerprint:a});return r=void 0,n.commit(),c}catch(e){throw e instanceof PostCommitDevelopmentRebuildError?(n.commit(),e):(n.rollback(),r===void 0?e:await discardFailedHost(e,r))}}async#o(e){let t=e.nextHost;e.hasRuntimeChange||(await discardDevelopmentGeneration(e.nextHost.generation),t={...e.nextHost,generation:this.#e.generation});let n=await createDevelopmentApplicationNitro(t),r=await buildDevelopmentHostCandidate({host:t,nitro:n}),i=t.workspace;if(await this.#i.replaceWorker({dispose:async()=>await removeDevelopmentHostWorkspace(i),entry:r.entry,workerData:r.workerData}),e.hasRuntimeChange)try{await activateDevelopmentGeneration({appRoot:t.appRoot,generation:t.generation})}catch(n){throw await discardDevelopmentGeneration(t.generation).catch(()=>void 0),this.#s({...t,generation:this.#e.generation},e.nextHostFingerprint,this.#n),new PostCommitDevelopmentRebuildError(n)}return this.#s(t,e.nextHostFingerprint,e.hasRuntimeChange?e.nextRuntimeFingerprint:this.#n),{host:t,kind:`structural`}}#s(e,t,n){this.#e=e,this.#t=t,this.#n=n}};function retainActiveHostWorkspace(e,t){return{...t,compiledArtifacts:e.compiledArtifacts,workflowBuildDir:e.workflowBuildDir,workspace:e.workspace}}async function discardPreparedHost(e){let t=(await Promise.allSettled([discardDevelopmentGeneration(e.generation),removeDevelopmentHostWorkspace(e.workspace)])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length>0)throw AggregateError(t,`Failed to discard development host "${e.workspace.rootDir}".`)}async function discardFailedHost(e,t){try{return await discardPreparedHost(t),e}catch(t){return AggregateError([e,t],`Development rebuild rollback failed.`,{cause:e})}}export{DevelopmentWorkflowWorldChangeRequiresRestartError,PostCommitDevelopmentRebuildError,createDevelopmentAuthoredRebuildCoordinator};