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

Function findMainAndProcess

yaml-flow-editor/src/App.tsx:1337–1398  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1335 };
1336
1337 const findMainAndProcess = () => {
1338 try {
1339 const withWorkflow = parsedList.filter(
1340 (p) => p.parsed && typeof p.parsed === 'object' && Array.isArray(p.parsed.workflow) && p.parsed.workflow.length > 0
1341 );
1342 const notInModules = withWorkflow.filter(
1343 (p) => !/[/\\]modules?[/\\]/i.test(p.path) && !p.path.startsWith('modules/')
1344 );
1345 const mainCandidate = notInModules.find((p) => looksLikeMainPlan(p.parsed!))
1346 ?? notInModules[0]
1347 ?? withWorkflow[0];
1348 const mainPath = mainCandidate?.path;
1349
1350 if (withWorkflow.length > 1) {
1351 setFolderImportAllContents(contents);
1352 setFolderImportCandidates(withWorkflow.map((p) => ({ path: p.path, content: p.content })));
1353 setFolderImportSelectedPath(mainPath || withWorkflow[0]?.path || '');
1354 setFolderImportOpen(true);
1355 return;
1356 }
1357
1358 setFolderImportAllContents(contents);
1359 applyFolderImportSelection(mainPath);
1360 } catch (e) {
1361 console.error('Error in findMainAndProcess:', e);
1362 // Still try to update modules even if main graph fails
1363 try {
1364 const newUploaded = contents.map((c) => {
1365 try {
1366 const template = parseModuleYaml(c.content, c.path);
1367 return { path: c.path, content: c.content, template };
1368 } catch {
1369 return {
1370 path: c.path,
1371 content: c.content,
1372 template: {
1373 name: c.path.split('/').pop()?.replace(/\.(yaml|yml)$/i, '') || 'Module',
1374 path: c.path,
1375 description: 'Failed to parse',
1376 goal: '',
1377 defaultParams: {},
1378 workflow: [],
1379 },
1380 };
1381 }
1382 });
1383 setTimeout(() => {
1384 try {
1385 setUploadedModules((prev) => {
1386 const byPath = new Map(prev.map((m) => [m.path, m]));
1387 newUploaded.forEach((u) => byPath.set(u.path, u));
1388 return Array.from(byPath.values());
1389 });
1390 } catch (e2) {
1391 console.error('Failed to update modules after error:', e2);
1392 }
1393 }, 100);
1394 } catch (e2) {

Callers 1

parseBatchFunction · 0.85

Calls 2

looksLikeMainPlanFunction · 0.90
parseModuleYamlFunction · 0.90

Tested by

no test coverage detected