@defai.digital/agent-parallel 13.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +38 -0
- package/dist/context-manager.d.ts +35 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +156 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/dag-analyzer.d.ts +32 -0
- package/dist/dag-analyzer.d.ts.map +1 -0
- package/dist/dag-analyzer.js +237 -0
- package/dist/dag-analyzer.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrator.d.ts +27 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +494 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/result-aggregator.d.ts +64 -0
- package/dist/result-aggregator.d.ts.map +1 -0
- package/dist/result-aggregator.js +187 -0
- package/dist/result-aggregator.js.map +1 -0
- package/dist/types.d.ts +207 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +54 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
- package/src/context-manager.ts +194 -0
- package/src/dag-analyzer.ts +285 -0
- package/src/index.ts +70 -0
- package/src/orchestrator.ts +595 -0
- package/src/result-aggregator.ts +238 -0
- package/src/types.ts +320 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Agent Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Main orchestration logic for executing multiple agents in parallel
|
|
5
|
+
* with DAG-based dependency management.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-APE-001: Concurrent agents MUST NOT exceed maxConcurrentAgents
|
|
9
|
+
* - INV-APE-002: Dependencies honored (DAG ordering)
|
|
10
|
+
* - INV-APE-003: Shared context immutable during execution
|
|
11
|
+
* - INV-APE-004: Result aggregation follows configured strategy
|
|
12
|
+
* - INV-APE-005: Timeout enforced per-agent independently
|
|
13
|
+
*/
|
|
14
|
+
import { createDefaultAgentParallelExecutionConfig, ParallelExecutionErrorCodes, } from '@defai.digital/contracts';
|
|
15
|
+
import { createDAGAnalyzer, DAGAnalysisError } from './dag-analyzer.js';
|
|
16
|
+
import { createContextManager } from './context-manager.js';
|
|
17
|
+
import { createResultAggregator } from './result-aggregator.js';
|
|
18
|
+
/**
|
|
19
|
+
* Error thrown during parallel execution
|
|
20
|
+
*/
|
|
21
|
+
export class ParallelExecutionError extends Error {
|
|
22
|
+
code;
|
|
23
|
+
taskId;
|
|
24
|
+
constructor(code, message, taskId) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.taskId = taskId;
|
|
28
|
+
this.name = 'ParallelExecutionError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a parallel agent orchestrator
|
|
33
|
+
*/
|
|
34
|
+
export function createAgentParallelOrchestrator(options) {
|
|
35
|
+
const { agentExecutor, defaultConfig, onProgress } = options;
|
|
36
|
+
const dagAnalyzer = createDAGAnalyzer();
|
|
37
|
+
const contextManager = createContextManager();
|
|
38
|
+
const resultAggregator = createResultAggregator();
|
|
39
|
+
const config = {
|
|
40
|
+
...createDefaultAgentParallelExecutionConfig(),
|
|
41
|
+
...defaultConfig,
|
|
42
|
+
};
|
|
43
|
+
// Track active executions for proper cancellation scoping
|
|
44
|
+
// Each execution has its own cancelled state to prevent cross-execution interference
|
|
45
|
+
const activeExecutions = new Map();
|
|
46
|
+
let currentGroupId = null;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a specific execution is cancelled
|
|
49
|
+
*/
|
|
50
|
+
function isCancelled(groupId) {
|
|
51
|
+
return activeExecutions.get(groupId)?.cancelled ?? false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Mark an execution as cancelled
|
|
55
|
+
*/
|
|
56
|
+
function setCancelled(groupId) {
|
|
57
|
+
const execution = activeExecutions.get(groupId);
|
|
58
|
+
if (execution) {
|
|
59
|
+
execution.cancelled = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Emit progress event
|
|
64
|
+
*/
|
|
65
|
+
function emitProgress(event, groupId) {
|
|
66
|
+
const gId = groupId ?? currentGroupId;
|
|
67
|
+
if (onProgress && gId) {
|
|
68
|
+
onProgress({
|
|
69
|
+
...event,
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
groupId: gId,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Execute a single task with timeout
|
|
77
|
+
* INV-APE-005: Timeout enforced independently
|
|
78
|
+
*/
|
|
79
|
+
async function executeTask(task, sharedContext, taskConfig, layerIndex, groupId) {
|
|
80
|
+
const startTime = Date.now();
|
|
81
|
+
const startedAt = new Date().toISOString();
|
|
82
|
+
emitProgress({
|
|
83
|
+
type: 'task.started',
|
|
84
|
+
taskId: task.taskId,
|
|
85
|
+
agentId: task.agentId,
|
|
86
|
+
layerIndex,
|
|
87
|
+
}, groupId);
|
|
88
|
+
// Task-specific timeout or default
|
|
89
|
+
const timeout = task.timeout ?? taskConfig.agentTimeout;
|
|
90
|
+
try {
|
|
91
|
+
// Check cancellation (scoped to this execution)
|
|
92
|
+
if (isCancelled(groupId)) {
|
|
93
|
+
return {
|
|
94
|
+
taskId: task.taskId,
|
|
95
|
+
agentId: task.agentId,
|
|
96
|
+
status: 'cancelled',
|
|
97
|
+
success: false,
|
|
98
|
+
errorCode: ParallelExecutionErrorCodes.CANCELLED,
|
|
99
|
+
durationMs: Date.now() - startTime,
|
|
100
|
+
layer: layerIndex,
|
|
101
|
+
startedAt,
|
|
102
|
+
completedAt: new Date().toISOString(),
|
|
103
|
+
retryCount: 0,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Check if agent exists
|
|
107
|
+
const exists = await agentExecutor.exists(task.agentId);
|
|
108
|
+
if (!exists) {
|
|
109
|
+
const errorMsg = `Agent "${task.agentId}" not found`;
|
|
110
|
+
const result = {
|
|
111
|
+
taskId: task.taskId,
|
|
112
|
+
agentId: task.agentId,
|
|
113
|
+
status: 'failed',
|
|
114
|
+
success: false,
|
|
115
|
+
error: errorMsg,
|
|
116
|
+
errorCode: ParallelExecutionErrorCodes.AGENT_NOT_FOUND,
|
|
117
|
+
durationMs: Date.now() - startTime,
|
|
118
|
+
layer: layerIndex,
|
|
119
|
+
startedAt,
|
|
120
|
+
completedAt: new Date().toISOString(),
|
|
121
|
+
retryCount: 0,
|
|
122
|
+
};
|
|
123
|
+
emitProgress({
|
|
124
|
+
type: 'task.failed',
|
|
125
|
+
taskId: task.taskId,
|
|
126
|
+
agentId: task.agentId,
|
|
127
|
+
layerIndex,
|
|
128
|
+
message: errorMsg,
|
|
129
|
+
});
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
// Build input with shared context
|
|
133
|
+
const input = taskConfig.shareContext && sharedContext
|
|
134
|
+
? { ...sharedContext, __taskInput: task.input }
|
|
135
|
+
: task.input;
|
|
136
|
+
// Execute with timeout
|
|
137
|
+
// Build execution request, only include optional fields if defined
|
|
138
|
+
const execRequest = {
|
|
139
|
+
agentId: task.agentId,
|
|
140
|
+
input,
|
|
141
|
+
timeout,
|
|
142
|
+
};
|
|
143
|
+
if (task.provider)
|
|
144
|
+
execRequest.provider = task.provider;
|
|
145
|
+
if (task.model)
|
|
146
|
+
execRequest.model = task.model;
|
|
147
|
+
const executePromise = agentExecutor.execute(execRequest);
|
|
148
|
+
// Create timeout with cleanup to prevent memory leak
|
|
149
|
+
let timeoutId;
|
|
150
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
151
|
+
timeoutId = setTimeout(() => {
|
|
152
|
+
reject(new Error(`Task timeout after ${timeout}ms`));
|
|
153
|
+
}, timeout);
|
|
154
|
+
});
|
|
155
|
+
let execResult;
|
|
156
|
+
try {
|
|
157
|
+
execResult = await Promise.race([executePromise, timeoutPromise]);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
// Clean up timeout to prevent memory leak
|
|
161
|
+
if (timeoutId !== undefined) {
|
|
162
|
+
clearTimeout(timeoutId);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const completedAt = new Date().toISOString();
|
|
166
|
+
const durationMs = Date.now() - startTime;
|
|
167
|
+
if (execResult.success) {
|
|
168
|
+
emitProgress({
|
|
169
|
+
type: 'task.completed',
|
|
170
|
+
taskId: task.taskId,
|
|
171
|
+
agentId: task.agentId,
|
|
172
|
+
layerIndex,
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
taskId: task.taskId,
|
|
176
|
+
agentId: task.agentId,
|
|
177
|
+
status: 'completed',
|
|
178
|
+
success: true,
|
|
179
|
+
output: execResult.output,
|
|
180
|
+
durationMs,
|
|
181
|
+
layer: layerIndex,
|
|
182
|
+
startedAt,
|
|
183
|
+
completedAt,
|
|
184
|
+
retryCount: 0,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
emitProgress({
|
|
189
|
+
type: 'task.failed',
|
|
190
|
+
taskId: task.taskId,
|
|
191
|
+
agentId: task.agentId,
|
|
192
|
+
layerIndex,
|
|
193
|
+
message: execResult.error ?? 'Task execution failed',
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
taskId: task.taskId,
|
|
197
|
+
agentId: task.agentId,
|
|
198
|
+
status: 'failed',
|
|
199
|
+
success: false,
|
|
200
|
+
error: execResult.error,
|
|
201
|
+
errorCode: execResult.errorCode ?? ParallelExecutionErrorCodes.TASK_FAILED,
|
|
202
|
+
durationMs,
|
|
203
|
+
layer: layerIndex,
|
|
204
|
+
startedAt,
|
|
205
|
+
completedAt,
|
|
206
|
+
retryCount: 0,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
const completedAt = new Date().toISOString();
|
|
212
|
+
const durationMs = Date.now() - startTime;
|
|
213
|
+
const isTimeout = error instanceof Error && error.message.includes('timeout');
|
|
214
|
+
emitProgress({
|
|
215
|
+
type: 'task.failed',
|
|
216
|
+
taskId: task.taskId,
|
|
217
|
+
agentId: task.agentId,
|
|
218
|
+
layerIndex,
|
|
219
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
taskId: task.taskId,
|
|
223
|
+
agentId: task.agentId,
|
|
224
|
+
status: isTimeout ? 'timeout' : 'failed',
|
|
225
|
+
success: false,
|
|
226
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
227
|
+
errorCode: isTimeout
|
|
228
|
+
? ParallelExecutionErrorCodes.TASK_TIMEOUT
|
|
229
|
+
: ParallelExecutionErrorCodes.TASK_FAILED,
|
|
230
|
+
durationMs,
|
|
231
|
+
layer: layerIndex,
|
|
232
|
+
startedAt,
|
|
233
|
+
completedAt,
|
|
234
|
+
retryCount: 0,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Execute a layer of tasks with concurrency limit
|
|
240
|
+
* INV-APE-001: Respects maxConcurrentAgents
|
|
241
|
+
*/
|
|
242
|
+
async function executeLayer(layer, sharedContext, taskConfig, failedTaskIds, groupId) {
|
|
243
|
+
const results = [];
|
|
244
|
+
const pending = new Set();
|
|
245
|
+
emitProgress({
|
|
246
|
+
type: 'layer.started',
|
|
247
|
+
layerIndex: layer.index,
|
|
248
|
+
totalTasks: layer.tasks.length,
|
|
249
|
+
}, groupId);
|
|
250
|
+
// Filter out tasks whose dependencies failed
|
|
251
|
+
// INV-APE-201: Dependency cascading
|
|
252
|
+
const tasksToExecute = [];
|
|
253
|
+
const skippedTasks = [];
|
|
254
|
+
for (const task of layer.tasks) {
|
|
255
|
+
const dependencyFailed = task.dependencies.some((depId) => failedTaskIds.has(depId));
|
|
256
|
+
if (dependencyFailed) {
|
|
257
|
+
skippedTasks.push(task);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
tasksToExecute.push(task);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Mark skipped tasks
|
|
264
|
+
for (const task of skippedTasks) {
|
|
265
|
+
const now = new Date().toISOString();
|
|
266
|
+
const result = {
|
|
267
|
+
taskId: task.taskId,
|
|
268
|
+
agentId: task.agentId,
|
|
269
|
+
status: 'skipped',
|
|
270
|
+
success: false,
|
|
271
|
+
error: 'Dependency failed',
|
|
272
|
+
errorCode: ParallelExecutionErrorCodes.DEPENDENCY_FAILED,
|
|
273
|
+
durationMs: 0,
|
|
274
|
+
layer: layer.index,
|
|
275
|
+
startedAt: now,
|
|
276
|
+
completedAt: now,
|
|
277
|
+
retryCount: 0,
|
|
278
|
+
};
|
|
279
|
+
results.push(result);
|
|
280
|
+
failedTaskIds.add(task.taskId);
|
|
281
|
+
emitProgress({
|
|
282
|
+
type: 'task.skipped',
|
|
283
|
+
taskId: task.taskId,
|
|
284
|
+
agentId: task.agentId,
|
|
285
|
+
layerIndex: layer.index,
|
|
286
|
+
message: 'Dependency failed',
|
|
287
|
+
}, groupId);
|
|
288
|
+
}
|
|
289
|
+
// Execute remaining tasks with concurrency control
|
|
290
|
+
let taskIndex = 0;
|
|
291
|
+
async function executeAndCollect(task) {
|
|
292
|
+
const result = await executeTask(task, sharedContext, taskConfig, layer.index, groupId);
|
|
293
|
+
results.push(result);
|
|
294
|
+
if (!result.success) {
|
|
295
|
+
failedTaskIds.add(task.taskId);
|
|
296
|
+
// Handle failFast strategy (scoped to this execution)
|
|
297
|
+
if (taskConfig.failureStrategy === 'failFast' && !isCancelled(groupId)) {
|
|
298
|
+
setCancelled(groupId);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// INV-APE-001: Concurrency limit enforcement
|
|
303
|
+
while (taskIndex < tasksToExecute.length || pending.size > 0) {
|
|
304
|
+
// Check cancellation (scoped to this execution)
|
|
305
|
+
if (isCancelled(groupId) && taskConfig.failureStrategy === 'failFast') {
|
|
306
|
+
// Mark remaining as cancelled
|
|
307
|
+
while (taskIndex < tasksToExecute.length) {
|
|
308
|
+
const task = tasksToExecute[taskIndex++];
|
|
309
|
+
const now = new Date().toISOString();
|
|
310
|
+
results.push({
|
|
311
|
+
taskId: task.taskId,
|
|
312
|
+
agentId: task.agentId,
|
|
313
|
+
status: 'cancelled',
|
|
314
|
+
success: false,
|
|
315
|
+
errorCode: ParallelExecutionErrorCodes.CANCELLED,
|
|
316
|
+
durationMs: 0,
|
|
317
|
+
layer: layer.index,
|
|
318
|
+
startedAt: now,
|
|
319
|
+
completedAt: now,
|
|
320
|
+
retryCount: 0,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
// Start new tasks up to concurrency limit
|
|
326
|
+
while (pending.size < taskConfig.maxConcurrentAgents &&
|
|
327
|
+
taskIndex < tasksToExecute.length) {
|
|
328
|
+
const task = tasksToExecute[taskIndex++];
|
|
329
|
+
const promise = executeAndCollect(task).finally(() => {
|
|
330
|
+
pending.delete(promise);
|
|
331
|
+
});
|
|
332
|
+
pending.add(promise);
|
|
333
|
+
}
|
|
334
|
+
// Wait for at least one to complete
|
|
335
|
+
if (pending.size > 0) {
|
|
336
|
+
await Promise.race(pending);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
emitProgress({
|
|
340
|
+
type: 'layer.completed',
|
|
341
|
+
layerIndex: layer.index,
|
|
342
|
+
completedTasks: results.filter((r) => r.success).length,
|
|
343
|
+
failedTasks: results.filter((r) => !r.success).length,
|
|
344
|
+
}, groupId);
|
|
345
|
+
return results;
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
getConfig() {
|
|
349
|
+
return { ...config };
|
|
350
|
+
},
|
|
351
|
+
buildExecutionPlan(tasks) {
|
|
352
|
+
const planId = crypto.randomUUID();
|
|
353
|
+
const analysis = dagAnalyzer.analyze(tasks);
|
|
354
|
+
const layers = analysis.layers.map((layer) => ({
|
|
355
|
+
index: layer.index,
|
|
356
|
+
tasks: layer.tasks,
|
|
357
|
+
taskCount: layer.tasks.length,
|
|
358
|
+
}));
|
|
359
|
+
return {
|
|
360
|
+
planId,
|
|
361
|
+
layers,
|
|
362
|
+
totalTasks: tasks.length,
|
|
363
|
+
totalLayers: analysis.totalLayers,
|
|
364
|
+
maxParallelism: analysis.maxParallelism,
|
|
365
|
+
hasCycles: analysis.hasCycles,
|
|
366
|
+
createdAt: new Date().toISOString(),
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
async executeParallel(tasks, configOverride, sharedContext) {
|
|
370
|
+
const groupId = crypto.randomUUID();
|
|
371
|
+
currentGroupId = groupId;
|
|
372
|
+
// Register this execution with its own cancellation state
|
|
373
|
+
activeExecutions.set(groupId, { cancelled: false });
|
|
374
|
+
const startTime = Date.now();
|
|
375
|
+
const startedAt = new Date().toISOString();
|
|
376
|
+
// Merge config
|
|
377
|
+
const taskConfig = {
|
|
378
|
+
...config,
|
|
379
|
+
...configOverride,
|
|
380
|
+
};
|
|
381
|
+
// Setup context if provided
|
|
382
|
+
// INV-APE-003: Context frozen before execution
|
|
383
|
+
// INV-APE-300: Context snapshot timing
|
|
384
|
+
if (sharedContext && taskConfig.shareContext) {
|
|
385
|
+
contextManager.create(sharedContext);
|
|
386
|
+
}
|
|
387
|
+
emitProgress({
|
|
388
|
+
type: 'execution.started',
|
|
389
|
+
totalTasks: tasks.length,
|
|
390
|
+
}, groupId);
|
|
391
|
+
try {
|
|
392
|
+
// Analyze DAG
|
|
393
|
+
// INV-APE-002: Dependencies honored
|
|
394
|
+
// INV-APE-200: Cycles detected
|
|
395
|
+
const analysis = dagAnalyzer.analyze(tasks);
|
|
396
|
+
// Track failed tasks for dependency cascading
|
|
397
|
+
const failedTaskIds = new Set();
|
|
398
|
+
// Execute layers sequentially, tasks within layers in parallel
|
|
399
|
+
const allResults = [];
|
|
400
|
+
let peakConcurrency = 0;
|
|
401
|
+
for (const layer of analysis.layers) {
|
|
402
|
+
if (isCancelled(groupId) && taskConfig.failureStrategy === 'failFast') {
|
|
403
|
+
// Mark remaining layers as cancelled
|
|
404
|
+
for (const task of layer.tasks) {
|
|
405
|
+
const now = new Date().toISOString();
|
|
406
|
+
allResults.push({
|
|
407
|
+
taskId: task.taskId,
|
|
408
|
+
agentId: task.agentId,
|
|
409
|
+
status: 'cancelled',
|
|
410
|
+
success: false,
|
|
411
|
+
errorCode: ParallelExecutionErrorCodes.CANCELLED,
|
|
412
|
+
durationMs: 0,
|
|
413
|
+
layer: layer.index,
|
|
414
|
+
startedAt: now,
|
|
415
|
+
completedAt: now,
|
|
416
|
+
retryCount: 0,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const layerResults = await executeLayer(layer, sharedContext, taskConfig, failedTaskIds, groupId);
|
|
422
|
+
allResults.push(...layerResults);
|
|
423
|
+
// Track peak concurrency
|
|
424
|
+
const layerConcurrency = Math.min(layer.tasks.length, taskConfig.maxConcurrentAgents);
|
|
425
|
+
if (layerConcurrency > peakConcurrency) {
|
|
426
|
+
peakConcurrency = layerConcurrency;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
// Aggregate results
|
|
430
|
+
// INV-APE-004: Follows configured strategy
|
|
431
|
+
const aggregatedOutput = resultAggregator.aggregate(allResults, {
|
|
432
|
+
strategy: taskConfig.resultAggregation,
|
|
433
|
+
});
|
|
434
|
+
const completedAt = new Date().toISOString();
|
|
435
|
+
const totalDurationMs = Date.now() - startTime;
|
|
436
|
+
const failedTasks = allResults
|
|
437
|
+
.filter((r) => !r.success && r.status !== 'cancelled' && r.status !== 'skipped')
|
|
438
|
+
.map((r) => r.taskId);
|
|
439
|
+
const cancelledTasks = allResults
|
|
440
|
+
.filter((r) => r.status === 'cancelled')
|
|
441
|
+
.map((r) => r.taskId);
|
|
442
|
+
const skippedTasks = allResults
|
|
443
|
+
.filter((r) => r.status === 'skipped')
|
|
444
|
+
.map((r) => r.taskId);
|
|
445
|
+
emitProgress({
|
|
446
|
+
type: 'execution.completed',
|
|
447
|
+
totalTasks: tasks.length,
|
|
448
|
+
completedTasks: allResults.filter((r) => r.success).length,
|
|
449
|
+
failedTasks: failedTasks.length,
|
|
450
|
+
}, groupId);
|
|
451
|
+
return {
|
|
452
|
+
groupId,
|
|
453
|
+
taskResults: allResults,
|
|
454
|
+
aggregatedOutput,
|
|
455
|
+
allSucceeded: failedTasks.length === 0 && cancelledTasks.length === 0,
|
|
456
|
+
failedTasks,
|
|
457
|
+
cancelledTasks: cancelledTasks.length > 0 ? cancelledTasks : undefined,
|
|
458
|
+
skippedTasks: skippedTasks.length > 0 ? skippedTasks : undefined,
|
|
459
|
+
totalDurationMs,
|
|
460
|
+
tasksExecuted: allResults.filter((r) => r.status !== 'skipped' && r.status !== 'cancelled').length,
|
|
461
|
+
tasksSkipped: skippedTasks.length + cancelledTasks.length,
|
|
462
|
+
layerCount: analysis.totalLayers,
|
|
463
|
+
peakConcurrency,
|
|
464
|
+
config: taskConfig,
|
|
465
|
+
startedAt,
|
|
466
|
+
completedAt,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
// Handle DAG analysis errors
|
|
471
|
+
if (error instanceof DAGAnalysisError) {
|
|
472
|
+
throw new ParallelExecutionError(error.code, error.message);
|
|
473
|
+
}
|
|
474
|
+
throw error;
|
|
475
|
+
}
|
|
476
|
+
finally {
|
|
477
|
+
// Cleanup - remove execution state to prevent memory leak
|
|
478
|
+
contextManager.clear();
|
|
479
|
+
activeExecutions.delete(groupId);
|
|
480
|
+
currentGroupId = null;
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
cancel() {
|
|
484
|
+
// Cancel all active executions
|
|
485
|
+
for (const [gId, state] of activeExecutions) {
|
|
486
|
+
state.cancelled = true;
|
|
487
|
+
emitProgress({
|
|
488
|
+
type: 'execution.cancelled',
|
|
489
|
+
}, gId);
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAOL,yCAAyC,EACzC,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AASlC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAE7B;IAEA;IAHlB,YACkB,IAAY,EAC5B,OAAe,EACC,MAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAS;QAG/B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAyC;IAEzC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE7D,MAAM,WAAW,GAAG,iBAAiB,EAAE,CAAC;IACxC,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;IAC9C,MAAM,gBAAgB,GAAG,sBAAsB,EAAE,CAAC;IAElD,MAAM,MAAM,GAAiC;QAC3C,GAAG,yCAAyC,EAAE;QAC9C,GAAG,aAAa;KACjB,CAAC;IAEF,0DAA0D;IAC1D,qFAAqF;IACrF,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkC,CAAC;IACnE,IAAI,cAAc,GAAkB,IAAI,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AAI,CAAC;YACxB,CAAC;QACH,CAAC;QAED,MAAM;YACJ,+BAA+B;YAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,gBAAgB,EAAE,CAAC;gBAC5C,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;gBACvB,YAAY,CAAC;oBACX,IAAI,EAAE,qBAAqB;iBAC5B,EAAE,GAAG,CAAC,CAAC;YACV,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Aggregator
|
|
3
|
+
*
|
|
4
|
+
* Combines results from parallel agent execution based on configured strategy.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-APE-004: Result aggregation follows configured strategy
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentParallelTaskResult } from '@defai.digital/contracts';
|
|
10
|
+
import type { ResultAggregator, CustomAggregator, AggregationStrategy } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Merge strategy: Combine all outputs into single object
|
|
13
|
+
* INV-APE-004: Later tasks override earlier for same keys
|
|
14
|
+
*/
|
|
15
|
+
declare function mergeResults(results: AgentParallelTaskResult[]): unknown;
|
|
16
|
+
/**
|
|
17
|
+
* List strategy: Return array of individual results
|
|
18
|
+
* INV-APE-004: Ordered by task definition order (taskId)
|
|
19
|
+
*/
|
|
20
|
+
declare function listResults(results: AgentParallelTaskResult[]): unknown;
|
|
21
|
+
/**
|
|
22
|
+
* First success strategy: Return first successful result
|
|
23
|
+
* INV-APE-004: First by layer, then by completion time
|
|
24
|
+
*/
|
|
25
|
+
declare function firstSuccessResult(results: AgentParallelTaskResult[]): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a result aggregator
|
|
28
|
+
*/
|
|
29
|
+
export declare function createResultAggregator(): ResultAggregator;
|
|
30
|
+
/**
|
|
31
|
+
* Built-in aggregation strategies for convenience
|
|
32
|
+
*/
|
|
33
|
+
export declare const AggregationStrategies: {
|
|
34
|
+
/**
|
|
35
|
+
* Merge all successful outputs into single object
|
|
36
|
+
*/
|
|
37
|
+
readonly merge: typeof mergeResults;
|
|
38
|
+
/**
|
|
39
|
+
* Return array of all successful results
|
|
40
|
+
*/
|
|
41
|
+
readonly list: typeof listResults;
|
|
42
|
+
/**
|
|
43
|
+
* Return first successful result only
|
|
44
|
+
*/
|
|
45
|
+
readonly firstSuccess: typeof firstSuccessResult;
|
|
46
|
+
/**
|
|
47
|
+
* Create custom strategy from function
|
|
48
|
+
*/
|
|
49
|
+
readonly custom: (fn: CustomAggregator) => CustomAggregator;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Utility: Create a keyed aggregator that groups results by a key
|
|
53
|
+
*/
|
|
54
|
+
export declare function createKeyedAggregator(keyFn: (result: AgentParallelTaskResult) => string): CustomAggregator;
|
|
55
|
+
/**
|
|
56
|
+
* Utility: Create aggregator that filters by success and transforms
|
|
57
|
+
*/
|
|
58
|
+
export declare function createTransformAggregator<T>(transform: (output: unknown, result: AgentParallelTaskResult) => T): CustomAggregator;
|
|
59
|
+
/**
|
|
60
|
+
* Get aggregation strategy from string
|
|
61
|
+
*/
|
|
62
|
+
export declare function getAggregationStrategy(name: string): AggregationStrategy;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=result-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-aggregator.d.ts","sourceRoot":"","sources":["../src/result-aggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EACV,gBAAgB,EAEhB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAmCpB;;;GAGG;AACH,iBAAS,YAAY,CAAC,OAAO,EAAE,uBAAuB,EAAE,GAAG,OAAO,CA4BjE;AAED;;;GAGG;AACH,iBAAS,WAAW,CAAC,OAAO,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAUhE;AAED;;;GAGG;AACH,iBAAS,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAevE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAqCzD;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB;IAChC;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;0BACU,gBAAgB;CACrB,CAAC;AAEX;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,MAAM,GACjD,gBAAgB,CAgBlB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,uBAAuB,KAAK,CAAC,GACjE,gBAAgB,CAMlB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,GACX,mBAAmB,CAQrB"}
|