import{expectObjectRecord,getAuthoredModuleExport,materializeAuthoredModuleExport}from"#internal/authored-module.js";import{ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{normalizeAgentDefinition}from"#internal/authored-definition/core.js";import{loadCompiledModuleMap}from"#runtime/loaders/module-map.js";import{resolveBootstrapRuntimeModel}from"#runtime/agent/bootstrap-model.js";import{EVE_MOCK_AUTHORED_MODELS_ENV,resolveMockAuthoredRuntimeModel,shouldMockAuthoredRuntimeModels}from"#runtime/agent/mock-model-adapter.js";async function resolveRuntimeModelReference(e,t={}){let n=resolveBootstrapRuntimeModel(e);if(n!==null)return n;let r=resolveMockAuthoredRuntimeModel(e);return r===null?isSourceBackedRuntimeModelReference(e)?await loadSourceBackedRuntimeModelReference(e,t):e.id:r}async function loadSourceBackedRuntimeModelReference(i,a){if(a.compiledArtifactsSource===void 0)throw Error(`Expected an explicit compiled artifact source to resolve the authored runtime model "${i.id}".`);let o=(await loadCompiledModuleMap({compiledArtifactsSource:a.compiledArtifactsSource})).nodes[ROOT_COMPILED_AGENT_NODE_ID]?.modules[i.source.sourceId],s=normalizeAgentDefinition(await materializeAuthoredModuleExport(getAuthoredModuleExport(expectObjectRecord(o,`Missing compiled agent config module for runtime model "${i.id}" at "${i.source.logicalPath}".`),i.source)),`Expected the authored agent config export "${i.source.exportName??`default`}" from "${i.source.logicalPath}" to match the public Eve shape.`).model;if(s===void 0)throw Error(`Expected the authored agent config export "${i.source.exportName??`default`}" from "${i.source.logicalPath}" to provide a runtime model.`);return s}function isSourceBackedRuntimeModelReference(e){return e.source!==void 0}export{EVE_MOCK_AUTHORED_MODELS_ENV,resolveRuntimeModelReference,shouldMockAuthoredRuntimeModels};