Skip to content

Commit 7169f33

Browse files
committed
fix(nodes): simplify response format for loops/parallels
1 parent 79bea15 commit 7169f33

File tree

5 files changed

+19
-34
lines changed

5 files changed

+19
-34
lines changed

apps/sim/executor/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,6 @@ export class Executor {
13321332
context,
13331333
parallelInfo.parallelId,
13341334
parallelInfo.iterationIndex,
1335-
actualBlockId,
13361335
output
13371336
)
13381337
}

apps/sim/executor/loops.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,7 @@ describe('LoopManager', () => {
316316
expect(loopState).toBeDefined()
317317
expect(loopState?.maxIterations).toBe(3)
318318
expect(loopState?.loopType).toBe('for')
319-
expect(loopState?.executionResults.get('iteration_0')).toEqual({
320-
'block-1': output,
321-
})
319+
expect(loopState?.executionResults.get('iteration_0')).toEqual(output)
322320
})
323321

324322
test('should add to existing loop state', () => {
@@ -341,10 +339,7 @@ describe('LoopManager', () => {
341339
const loopState = mockContext.loopExecutions.get('loop-1')
342340
const iterationResults = loopState?.executionResults.get('iteration_0')
343341

344-
expect(iterationResults).toEqual({
345-
'block-1': output1,
346-
'block-2': output2,
347-
})
342+
expect(iterationResults).toEqual(output2)
348343
})
349344

350345
test('should handle forEach loop state creation', () => {

apps/sim/executor/loops.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ export class LoopManager {
5555
const currentIteration = context.loopIterations.get(loopId) || 0
5656

5757
// Store the results from this iteration before potentially resetting blocks
58-
const iterationResults: Record<string, any> = {}
58+
const iterationResults: any[] = []
5959
for (const nodeId of loop.nodes) {
6060
const blockState = context.blockStates.get(nodeId)
6161
if (blockState?.output) {
62-
iterationResults[nodeId] = blockState.output
62+
// Just push the output directly, not nested under block ID
63+
iterationResults.push(blockState.output)
6364
}
6465
}
6566

6667
// Store the iteration results
67-
if (Object.keys(iterationResults).length > 0) {
68+
if (iterationResults.length > 0) {
6869
this.storeIterationResult(
6970
context,
7071
loopId,
@@ -117,8 +118,13 @@ export class LoopManager {
117118
if (loopState) {
118119
for (let i = 0; i < maxIterations; i++) {
119120
const result = loopState.executionResults.get(`iteration_${i}`)
120-
if (result?.iteration) {
121-
results.push(result.iteration)
121+
if (result) {
122+
// If result is an array (from multiple blocks in the loop), flatten it
123+
if (Array.isArray(result)) {
124+
results.push(...result)
125+
} else {
126+
results.push(result)
127+
}
122128
}
123129
}
124130
}
@@ -240,7 +246,7 @@ export class LoopManager {
240246
context: ExecutionContext,
241247
loopId: string,
242248
iterationIndex: number,
243-
blockId: string,
249+
_blockId: string, // Not used anymore since we're storing results directly
244250
output: any
245251
): void {
246252
if (!context.loopExecutions) {
@@ -266,16 +272,9 @@ export class LoopManager {
266272
context.loopExecutions.set(loopId, loopState)
267273
}
268274

269-
// Get or create the iteration results object
275+
// Store the output directly for this iteration
270276
const iterationKey = `iteration_${iterationIndex}`
271-
let iterationResults = loopState.executionResults.get(iterationKey)
272-
if (!iterationResults) {
273-
iterationResults = {}
274-
loopState.executionResults.set(iterationKey, iterationResults)
275-
}
276-
277-
// Store the block's output for this iteration
278-
iterationResults[blockId] = output
277+
loopState.executionResults.set(iterationKey, output)
279278
}
280279

281280
/**

apps/sim/executor/parallels.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,9 @@ describe('ParallelManager', () => {
275275

276276
const output = { response: { result: 'test result' } }
277277

278-
manager.storeIterationResult(context, 'parallel-1', 1, 'func-1', output)
278+
manager.storeIterationResult(context, 'parallel-1', 1, output)
279279

280-
expect(state.executionResults.get('iteration_1')).toEqual({
281-
'func-1': output,
282-
})
280+
expect(state.executionResults.get('iteration_1')).toEqual(output)
283281
})
284282
})
285283

apps/sim/executor/parallels.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,11 @@ export class ParallelManager {
210210
context: ExecutionContext,
211211
parallelId: string,
212212
iterationIndex: number,
213-
blockId: string,
214213
output: NormalizedBlockOutput
215214
): void {
216215
const parallelState = context.parallelExecutions?.get(parallelId)
217216
if (parallelState) {
218-
const existingResults =
219-
parallelState.executionResults.get(`iteration_${iterationIndex}`) || {}
220-
parallelState.executionResults.set(`iteration_${iterationIndex}`, {
221-
...existingResults,
222-
[blockId]: output,
223-
})
217+
parallelState.executionResults.set(`iteration_${iterationIndex}`, output)
224218
}
225219
}
226220
}

0 commit comments

Comments
 (0)