eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.72 kB
JavaScript
import{join}from"node:path";import{collectModuleRefsForManifest,compiledModuleMapSchema}from"#compiler/module-map.js";import{ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{formatValidationError}from"#runtime/validation.js";import{loadAuthoredModuleNamespace}from"#internal/authored-module-loader.js";import{loadCompiledManifest}from"#runtime/loaders/manifest.js";import{readMaterializedAuthoredModuleIndex}from"#internal/materialized-authored-modules.js";import{pathToFileURL}from"node:url";const EXT_CONFIG_SCOPE=Symbol.for(`eve.ext-config-scope`);async function loadCompiledModuleMapFromAuthoredSource(e){return await hydrateCompiledModuleMapFromManifest(await loadCompiledManifest({compiledArtifactsSource:e.compiledArtifactsSource}),e.compiledArtifactsSource.appRoot)}async function hydrateCompiledModuleMapFromManifest(e,t){let n=await readMaterializedAuthoredModuleIndex(t);if(n!==void 0)return await loadMaterializedCompiledModuleMap({moduleMapPath:n.moduleMap,runtimeAppRoot:t});let i={},a=[{agentRoot:e.agentRoot,manifest:e,nodeId:ROOT_COMPILED_AGENT_NODE_ID},...[...e.subagents].sort((e,t)=>e.nodeId.localeCompare(t.nodeId)).map(e=>({agentRoot:e.agent.agentRoot,manifest:e.agent,nodeId:e.nodeId}))],o={byMountNamespace:new Map(e.extensionMounts.map(e=>[e.namespace,e.packageNamespace])),byMountSourceId:new Map(e.extensionMounts.map(e=>[e.mountSourceId,e.packageNamespace]))};for(let e of a)i[e.nodeId]={modules:await hydrateCompiledNodeScope({agentRoot:e.agentRoot,manifest:e.manifest,scopeIndex:o})};return{nodes:i}}async function loadMaterializedCompiledModuleMap(t){let r=join(t.runtimeAppRoot,`.eve`,`compile`,t.moduleMapPath),a=await import(`${pathToFileURL(r).href}?generation=${encodeURIComponent(t.moduleMapPath)}`),o=compiledModuleMapSchema.safeParse(a.moduleMap??a.default);if(!o.success)throw Error(`Expected materialized authored module map "${r}" to export a valid compiled eve module map. ${formatValidationError(o.error)}`);return o.data}function extensionNamespaceForSourceId(e,t){let n=e.match(/^ext:([^:]+):/);return n===null?void 0:t.byMountNamespace.get(n[1])}async function hydrateCompiledNodeScope(n){let r=collectModuleRefsForManifest(n.manifest).sort((e,t)=>e.sourceId.localeCompare(t.sourceId)),i=n.manifest.config.build?.externalDependencies??[],o=globalThis,s={};for(let t of r){let r=join(n.agentRoot,t.logicalPath),c=extensionNamespaceForSourceId(t.sourceId,n.scopeIndex),l=n.scopeIndex.byMountSourceId.get(t.sourceId);l!==void 0&&(o[EXT_CONFIG_SCOPE]=l);try{s[t.sourceId]=await loadAuthoredModuleNamespace(r,{externalDependencies:i,extensionScopeNamespace:c})}finally{l!==void 0&&(o[EXT_CONFIG_SCOPE]=void 0)}}return s}export{loadCompiledModuleMapFromAuthoredSource};