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

Function collectDependentModules

yaml-flow-editor/src/utils/collectModules.ts:9–182  ·  view source on GitHub ↗
(
  mainYaml: string,
  modulesByPath: Record<string, { content: string }>,
  nodes: FlowNode[],
)

Source from the content-addressed store, hash-verified

7 * Returns a Map of modulePath → yamlContent for every transitively-referenced module.
8 */
9export function collectDependentModules(
10 mainYaml: string,
11 modulesByPath: Record<string, { content: string }>,
12 nodes: FlowNode[],
13): Map<string, string> {
14 const result = new Map<string, string>();
15 const visited = new Set<string>();
16
17 // Collect per-node moduleContents overrides (call/parallel/gather nodes)
18 const nodeOverrides: Record<string, string> = {};
19 for (const node of nodes) {
20 const data = node.data as Record<string, unknown>;
21 const mc = data.moduleContents as Record<string, string> | undefined;
22 if (mc) {
23 for (const [path, content] of Object.entries(mc)) {
24 nodeOverrides[path] = content;
25 }
26 }
27 }
28
29 // Resolve module content by path: node overrides > global modulesByPath (with normalization)
30 function resolveContent(modulePath: string): string | undefined {
31 if (nodeOverrides[modulePath]) return nodeOverrides[modulePath];
32
33 // Direct lookup
34 if (modulesByPath[modulePath]) return modulesByPath[modulePath].content;
35
36 // Normalize: strip leading ./
37 const stripped = modulePath.replace(/^\.\//, '');
38 if (modulesByPath[stripped]) return modulesByPath[stripped].content;
39
40 // Strip workflows/ prefix
41 const noPrefix = stripped.replace(/^workflows\//, '');
42 if (modulesByPath[noPrefix]) return modulesByPath[noPrefix].content;
43
44 // Suffix match: find any key ending with the path
45 const keys = Object.keys(modulesByPath);
46 const suffixMatch = keys.find(
47 (k) => k.endsWith('/' + stripped) || k.endsWith('/' + noPrefix),
48 );
49 if (suffixMatch) return modulesByPath[suffixMatch].content;
50
51 return undefined;
52 }
53
54 // Extract module paths from a list of workflow steps
55 function extractModulePaths(steps: WorkflowStep[]): string[] {
56 const paths: string[] = [];
57 for (const step of steps) {
58 if ('call' in step && step.call) {
59 const c = step.call as { module?: string };
60 if (c.module) paths.push(c.module);
61 }
62 if ('parallel' in step && step.parallel) {
63 const p = step.parallel as { module?: string };
64 if (p.module) paths.push(p.module);
65 }
66 if ('gather' in step && step.gather) {

Callers 1

App.tsxFile · 0.90

Calls 3

processFunction · 0.85
resolveContentFunction · 0.85

Tested by

no test coverage detected