import{join}from"node:path";import{collectModuleRefsForManifest}from"#compiler/module-map.js";import{ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{loadAuthoredModuleNamespace}from"#internal/authored-module-loader.js";import{loadCompiledManifest}from"#runtime/loaders/manifest.js";async function loadCompiledModuleMapFromAuthoredSource(e){return await hydrateCompiledModuleMapFromManifest(await loadCompiledManifest({compiledArtifactsSource:e.compiledArtifactsSource}))}async function hydrateCompiledModuleMapFromManifest(e){let t={},r=[{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}))];for(let e of r)t[e.nodeId]={modules:await hydrateCompiledNodeScope({agentRoot:e.agentRoot,manifest:e.manifest})};return{nodes:t}}async function hydrateCompiledNodeScope(n){let i=collectModuleRefsForManifest(n.manifest).sort((e,t)=>e.sourceId.localeCompare(t.sourceId)),a={};for(let t of i){let i=join(n.agentRoot,t.logicalPath);a[t.sourceId]=await loadAuthoredModuleNamespace(i)}return a}export{loadCompiledModuleMapFromAuthoredSource};