* Run a full plan through the parallel executor. * Processes batches in order; within each batch, steps run concurrently. * * @param {number[][]} batches - from toParallelBatches() * @param {string[]} planSteps - all plan step texts * @param {object[]} systemMessages - shared system prompt mess
( batches, planSteps, systemMessages, chatCompletionFn, executeToolFn, config, ctx, onBatchComplete, )
| 155 | * @returns {Promise<Array<{stepIndex, content, toolResults}>>} |
| 156 | */ |
| 157 | async function runParallelPlan( |
| 158 | batches, |
| 159 | planSteps, |
| 160 | systemMessages, |
| 161 | chatCompletionFn, |
| 162 | executeToolFn, |
| 163 | config, |
| 164 | ctx, |
| 165 | onBatchComplete, |
| 166 | ) { |
| 167 | const allResults = []; |
| 168 | |
| 169 | for (let batchIdx = 0; batchIdx < batches.length; batchIdx++) { |
| 170 | const batch = batches[batchIdx]; |
| 171 | const batchResults = await executeBatch( |
| 172 | batch, |
| 173 | planSteps, |
| 174 | systemMessages, |
| 175 | chatCompletionFn, |
| 176 | executeToolFn, |
| 177 | config, |
| 178 | ctx, |
| 179 | ); |
| 180 | |
| 181 | for (const r of batchResults) { |
| 182 | allResults[r.stepIndex] = r; |
| 183 | } |
| 184 | |
| 185 | if (typeof onBatchComplete === 'function') { |
| 186 | try { onBatchComplete(batchIdx, batchResults); } catch {} |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // Return results sorted by original step order |
| 191 | return allResults.filter(Boolean); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Merge parallel execution results into a single conversationHistory entry. |
nothing calls this directly
no test coverage detected