feat(loops): additional logic to ensure we enforce min and max loops, removed unused type

This commit is contained in:
Waleed Latif
2025-03-03 19:47:18 -08:00
parent 0a7684c523
commit 9825e46732
2 changed files with 18 additions and 13 deletions
+18 -4
View File
@@ -35,12 +35,15 @@ export class LoopManager {
continue
}
// Check if we need to force iteration due to minimum iterations requirement
// Get min iterations for the loop
const minIterations = loop.minIterations || this.defaultMinIterations
const forceIteration = currentIteration < minIterations
// Check if loop should iterate again
const shouldIterate = forceIteration || this.shouldIterateLoop(loopId, context)
const normalIteration = this.shouldIterateLoop(loopId, context)
const forceIteration =
currentIteration < minIterations && this.allBlocksExecuted(loop.nodes, context)
const shouldIterate = normalIteration || forceIteration
if (shouldIterate) {
// Increment iteration counter
@@ -115,7 +118,7 @@ export class LoopManager {
const loop = this.loops[loopId]
if (!loop) return false
const allBlocksExecuted = loop.nodes.every((nodeId) => context.executedBlocks.has(nodeId))
const allBlocksExecuted = this.allBlocksExecuted(loop.nodes, context)
if (!allBlocksExecuted) return false
const currentIteration = context.loopIterations.get(loopId) || 0
@@ -145,6 +148,17 @@ export class LoopManager {
return false
}
/**
* Checks if all blocks in a list have been executed.
*
* @param nodeIds - IDs of nodes to check
* @param context - Current execution context
* @returns Whether all blocks have been executed
*/
private allBlocksExecuted(nodeIds: string[], context: ExecutionContext): boolean {
return nodeIds.every((nodeId) => context.executedBlocks.has(nodeId))
}
/**
* Checks if a connection forms a feedback path in a loop.
* A feedback path points to an earlier block in the loop.
-9
View File
@@ -108,15 +108,6 @@ export interface ExecutionResult {
}
}
/**
* Configuration options for workflow execution.
*/
export interface ExecutionOptions {
maxLoopIterations?: number // Maximum iterations for any loop (default: 5)
continueOnError?: boolean // Whether to continue execution after errors
timeoutMs?: number // Maximum execution time in milliseconds before timeout
}
/**
* Interface for a block executor component.
*/