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

Function processAsync

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

Source from the content-addressed store, hash-verified

1287
1288 // Process files asynchronously to avoid blocking UI
1289 const processAsync = () => {
1290 try {
1291 // Parse all files to find main candidate
1292 const parsedList: Array<{ path: string; content: string; parsed: { name?: string; workflow?: unknown[] } | null }> = [];
1293
1294 const parseBatch = (startIndex: number) => {
1295 try {
1296 const endIndex = Math.min(startIndex + BATCH_SIZE, contents.length);
1297 const batch = contents.slice(startIndex, endIndex);
1298
1299 // Parse this batch
1300 batch.forEach((c) => {
1301 try {
1302 parsedList.push({
1303 path: c.path,
1304 content: c.content,
1305 parsed: yamlLib.load(c.content) as { name?: string; workflow?: unknown[] } | null,
1306 });
1307 } catch (e) {
1308 console.warn(`Failed to parse ${c.path}:`, e);
1309 parsedList.push({
1310 path: c.path,
1311 content: c.content,
1312 parsed: null,
1313 });
1314 }
1315 });
1316
1317 // Continue with next batch or finish
1318 if (endIndex < contents.length) {
1319 if (typeof requestIdleCallback !== 'undefined') {
1320 requestIdleCallback(() => parseBatch(endIndex), { timeout: 100 });
1321 } else {
1322 setTimeout(() => parseBatch(endIndex), 0);
1323 }
1324 } else {
1325 // All parsed, now find main candidate and process
1326 findMainAndProcess();
1327 }
1328 } catch (e) {
1329 console.error('Error in parseBatch:', e);
1330 // Still try to process what we have
1331 if (parsedList.length > 0) {
1332 findMainAndProcess();
1333 }
1334 }
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]

Callers

nothing calls this directly

Calls 1

parseBatchFunction · 0.85

Tested by

no test coverage detected