MCPcopy Create free account
hub / github.com/anomalyco/opencode / compile

Function compile

packages/core/src/effect/layer-node.ts:250–272  ·  view source on GitHub ↗
(
  root: Node<A, E, any>,
  replacements?: ValidReplacements<Items>,
)

Source from the content-addressed store, hash-verified

248}
249
250export function compile<A, E, const Items extends Replacements = readonly []>(
251 root: Node<A, E, any>,
252 replacements?: ValidReplacements<Items>,
253): Layer.Layer<A, E> {
254 const replacementMap = replacementMapFrom(replacements)
255 const cache = new Map<AnyNode, RuntimeLayer>()
256 const compileNode = (node: AnyNode) =>
257 walk<RuntimeLayer>(
258 node,
259 (node, context) => {
260 if (node.kind === "unbound") throw new Error(`Unbound layer node: ${node.name}`)
261 const dependencies = node.dependencies.flatMap(flatten).map(context.visit)
262 const implementation = node.implementation! as RuntimeLayer
263 return dependencies.length === 0
264 ? implementation
265 : implementation.pipe(Layer.provide(dependencies as [RuntimeLayer, ...RuntimeLayer[]]))
266 },
267 { cache, resolve: (node) => replacementMap.get(node.name) ?? node },
268 )
269 const layers = flatten(root).map((node) => compileNode(node))
270 const layer = layers.reduce<RuntimeLayer>((result, layer) => layer.pipe(Layer.provideMerge(result)), Layer.empty)
271 return layer as Layer.Layer<A, E>
272}
273
274function replacementMapFrom(replacements?: Replacements) {
275 return (

Callers

nothing calls this directly

Calls 3

replacementMapFromFunction · 0.85
compileNodeFunction · 0.85
flattenFunction · 0.70

Tested by

no test coverage detected