UNPKG

eve

Version:

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

1 lines 1.9 kB
import{createAgentModuleBinding}from"#compiler/source-graph.js";import{collectSelectedSourceIds,mergeExternalDependencies}from"#compiler/normalize-manifest-helpers.js";function finalizeNodeSourceState(e,t){let n=e.graph,r=new Map(n.orderedCandidates.map(e=>{let n=finalizeCandidateExternalDependencies(e,t);return[e.sourceId,n]})),candidateFor=e=>{let t=r.get(e.sourceId);if(t===void 0)throw Error(`Agent source candidate "${e.sourceId}" is missing from its node.`);return t},i={candidates:n.projected.candidates.map(candidateFor),resources:n.projected.resources.map(e=>({...e,candidate:candidateFor(e.candidate)})),subagents:n.projected.subagents.map(e=>({...e,candidate:candidateFor(e.candidate)}))},a={composition:{entries:n.composed.composition.entries.map(e=>({...e,source:finalizeDescriptorExternalDependencies(e.source,t)}))},selected:new Map([...n.composed.selected].map(([e,t])=>[e,candidateFor(t)]))},o=collectSelectedSourceIds(a),s=Object.fromEntries([...r.values()].filter(e=>o.has(e.sourceId)&&e.backing.kind!==`resource`).map(e=>[e.sourceId,createAgentModuleBinding(e)]));return e.evaluation.setBindings(s),{bindings:s,composed:a,orderedCandidates:n.orderedCandidates.map(candidateFor),projected:i,sourcesBySourceId:new Map([...n.sourcesBySourceId].map(([e,t])=>[e,{...t,candidate:candidateFor(t.candidate)}])),subagentsBySourceId:new Map(i.subagents.map(e=>[e.candidate.sourceId,e])),evaluation:e.evaluation}}function finalizeCandidateExternalDependencies(e,t){return e.backing.kind===`filesystem`?{...e,backing:finalizeBackingExternalDependencies(e.backing,t)}:e}function finalizeDescriptorExternalDependencies(e,t){return e.backing.kind===`filesystem`?{...e,backing:finalizeBackingExternalDependencies(e.backing,t)}:e}function finalizeBackingExternalDependencies(e,t){return{...e,externalDependencies:mergeExternalDependencies(t,e.externalDependencies)}}export{finalizeNodeSourceState};