MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / buildGraph

Function buildGraph

yaml-flow-editor/src/utils/layout.ts:379–403  ·  view source on GitHub ↗

Build in/out edge maps. Outgoing stored with sourceHandle so we can put "next" (main flow) first.

(
  nodes: FlowNode[],
  edges: FlowEdge[]
)

Source from the content-addressed store, hash-verified

377
378/** Build in/out edge maps. Outgoing stored with sourceHandle so we can put "next" (main flow) first. */
379function buildGraph(
380 nodes: FlowNode[],
381 edges: FlowEdge[]
382): {
383 inEdges: Map<string, string[]>;
384 outEdgesWithHandle: Map<string, { target: string; sourceHandle?: string }[]>;
385 idSet: Set<string>;
386} {
387 const idSet = new Set(nodes.map((n) => n.id));
388 const inEdges = new Map<string, string[]>();
389 const outEdgesWithHandle = new Map<string, { target: string; sourceHandle?: string }[]>();
390 nodes.forEach((n) => {
391 inEdges.set(n.id, []);
392 outEdgesWithHandle.set(n.id, []);
393 });
394 edges.forEach((e) => {
395 if (!idSet.has(e.source) || !idSet.has(e.target)) return;
396 inEdges.get(e.target)!.push(e.source);
397 outEdgesWithHandle.get(e.source)!.push({
398 target: e.target,
399 sourceHandle: e.sourceHandle ?? undefined,
400 });
401 });
402 return { inEdges, outEdgesWithHandle, idSet };
403}
404
405/** Main-flow handle first (next/bottom), then branch handles. */
406function nextFlowPriority(handle: string | undefined): number {

Callers 1

topoOrderIdsFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected