UNPKG

eve

Version:

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

3 lines 2.59 kB
import{join}from"node:path";import{discoverAgent}from"#discover/discover-agent.js";import{hasDiscoverErrors,summarizeDiscoverDiagnostics}from"#discover/diagnostics.js";import{resolveDiscoveryProject}from"#discover/project.js";import{createDiskProjectSource}from"#discover/project-source.js";import{writeCompilerArtifacts}from"#compiler/artifacts.js";var CompileAgentError=class CompileAgentError extends Error{result;constructor(e,t){super(t),this.name=`CompileAgentError`,this.result=e}static fromDurableArtifacts(e){let[t,...n]=formatCompileAgentErrorLines(e.diagnostics);return new CompileAgentError(e,[t,`Diagnostics artifact: ${e.paths.diagnosticsPath}`,...n].join(` `))}static fromTransientArtifacts(e){return new CompileAgentError(e,formatCompileAgentErrorLines(e.diagnostics).join(` `))}};async function compileAgent(t={}){let n=await discoverAgentForCompilation(t),r=join(n.project.appRoot,`.eve`);return finishAgentCompilation(await writeAgentCompilation(n,{publishedRoot:r,writeRoot:r}),CompileAgentError.fromDurableArtifacts)}async function compileAgentInWorkspace(e){return finishAgentCompilation(await writeAgentCompilation(await discoverAgentForCompilation({startPath:e.startPath}),e.artifactLocations),CompileAgentError.fromTransientArtifacts)}async function discoverAgentForCompilation(e){let n=e.source??createDiskProjectSource(),r=await resolveDiscoveryProject(e.startPath,{source:n}),i=await discoverAgent({...r,source:n});return{diagnostics:i.diagnostics,manifest:i.manifest,project:r}}async function writeAgentCompilation(e,t){let n=await writeCompilerArtifacts({appRoot:e.project.appRoot,artifactLocations:t,diagnostics:e.diagnostics,manifest:e.manifest});return{diagnostics:e.diagnostics,manifest:n.compiledManifest,metadata:n.metadata,paths:n.paths,project:e.project}}function finishAgentCompilation(e,t){if(hasDiscoverErrors(e.diagnostics))throw t(e);return reportDiscoverWarnings(e.diagnostics),e}function reportDiscoverWarnings(e){let t=e.filter(e=>e.severity===`warning`);if(t.length!==0)for(let e of t)console.warn(`Warning [${e.code}]: ${e.message}\n source: ${e.sourcePath}`)}function formatCompileAgentErrorLines(e){let t=summarizeDiscoverDiagnostics(e),n=[`Discovery failed with ${t.errors} error(s) and ${t.warnings} warning(s).`];if(e.length===0)return n;n.push(`Discovery diagnostics:`);for(let t of e)n.push(`- ${formatDiagnosticSeverity(t.severity)}: ${t.message}`),n.push(` source: ${t.sourcePath}`);return n}function formatDiagnosticSeverity(e){return e===`error`?`Error`:`Warning`}export{CompileAgentError,compileAgent,compileAgentInWorkspace};