mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
feat(loops): additional logic to ensure we enforce min and max loops, removed unused type
This commit is contained in:
+18
-4
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user