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

Function parseModuleYaml

yaml-flow-editor/src/utils/parseModuleYaml.ts:39–74  ·  view source on GitHub ↗
(content: string, defaultPath: string)

Source from the content-addressed store, hash-verified

37 * Used for uploaded submodules and folder import.
38 */
39export function parseModuleYaml(content: string, defaultPath: string): ModuleTemplate {
40 const parsed = yaml.load(content) as ParsedYaml | null;
41 if (!parsed || typeof parsed !== 'object') {
42 return {
43 name: defaultPath.replace(/^.*[/\\]/, '').replace(/\.(yaml|yml)$/i, '') || 'Module',
44 path: defaultPath,
45 description: 'Invalid or empty YAML',
46 goal: '',
47 defaultParams: {},
48 workflow: [],
49 };
50 }
51
52 const name =
53 (typeof parsed.name === 'string' && parsed.name.trim()) ||
54 defaultPath.replace(/^.*[/\\]/, '').replace(/\.(yaml|yml)$/i, '') ||
55 'Module';
56 const goal = typeof parsed.goal === 'string' ? parsed.goal : '';
57 const parameters = parsed.parameters && typeof parsed.parameters === 'object'
58 ? (Object.fromEntries(
59 Object.entries(parsed.parameters).map(([k, v]) => [k, v != null ? String(v) : ''])
60 ) as Record<string, string>)
61 : {};
62 const workflow: WorkflowStep[] = Array.isArray(parsed.workflow)
63 ? parsed.workflow.map(stepToWorkflowStep).filter((s): s is WorkflowStep => s != null)
64 : [];
65
66 return {
67 name,
68 path: defaultPath,
69 description: goal || undefined,
70 goal,
71 defaultParams: parameters,
72 workflow,
73 };
74}
75
76/**
77 * Check if a parsed YAML looks like a main workflow (has workflow with multiple steps or is clearly a plan).

Callers 4

processModulesBatchFunction · 0.90
nextFunction · 0.90
findMainAndProcessFunction · 0.90
App.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected