@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
package/LICENSE
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
|
|
5
|
+
Licensor: DEFAI Private Limited
|
|
6
|
+
Licensed Work: AutomatosX
|
|
7
|
+
The Licensed Work is (c) 2024-2025 DEFAI Private Limited
|
|
8
|
+
Additional Use Grant: You may make production use of the Licensed Work,
|
|
9
|
+
provided that your organization has less than US$2,000,000 in annual gross
|
|
10
|
+
revenue in the prior fiscal year. "Production use" means use in a live
|
|
11
|
+
production environment to support business or operational activities for end
|
|
12
|
+
users.
|
|
13
|
+
Change Date: Four years after the release date of the Licensed Work version
|
|
14
|
+
Change License: Apache License, Version 2.0
|
|
15
|
+
|
|
16
|
+
Terms
|
|
17
|
+
|
|
18
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
19
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
20
|
+
Licensor may make an Additional Use Grant, above, permitting other uses of the
|
|
21
|
+
Licensed Work. The rights granted to you under this license are subject to the
|
|
22
|
+
following condition.
|
|
23
|
+
|
|
24
|
+
If you make any use of the Licensed Work, you must ensure that the Licensed
|
|
25
|
+
Work, or any modified version of it, carries prominent notices stating that
|
|
26
|
+
you have modified the Licensed Work.
|
|
27
|
+
|
|
28
|
+
This license does not grant permission to use the Licensor's trademarks.
|
|
29
|
+
|
|
30
|
+
The Licensed Work is provided "as is", without warranty of any kind, express
|
|
31
|
+
or implied, including but not limited to the warranties of merchantability,
|
|
32
|
+
fitness for a particular purpose and noninfringement. In no event shall the
|
|
33
|
+
Licensor be liable for any claim, damages or other liability, whether in an
|
|
34
|
+
action of contract, tort or otherwise, arising from, out of or in connection
|
|
35
|
+
with the Licensed Work or the use or other dealings in the Licensed Work.
|
|
36
|
+
|
|
37
|
+
On the Change Date, the Licensed Work will be made available under the Change
|
|
38
|
+
License.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages shared immutable context for parallel agent execution.
|
|
5
|
+
* Ensures context is frozen before execution and cannot be modified.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-APE-003: Shared context immutable during execution
|
|
9
|
+
* - INV-APE-300: Context snapshot timing (frozen before first task)
|
|
10
|
+
*/
|
|
11
|
+
import type { ContextManager } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when context mutation is attempted
|
|
14
|
+
*/
|
|
15
|
+
export declare class ContextMutationError extends Error {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
static readonly code: "PARALLEL_CONTEXT_MUTATION";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a context manager for shared immutable context
|
|
21
|
+
*/
|
|
22
|
+
export declare function createContextManager(): ContextManager;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a proxy that throws on any mutation attempt
|
|
25
|
+
* Alternative approach for stricter runtime enforcement
|
|
26
|
+
*/
|
|
27
|
+
export declare function createImmutableContextProxy<T extends Record<string, unknown>>(data: T): Readonly<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Validates that context data is JSON-serializable
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateContextData(data: unknown): {
|
|
32
|
+
valid: boolean;
|
|
33
|
+
errors: string[];
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=context-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.d.ts","sourceRoot":"","sources":["../src/context-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;IAK3B,MAAM,CAAC,QAAQ,CAAC,IAAI,8BAAgD;CACrE;AAsBD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAkDrD;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3E,IAAI,EAAE,CAAC,GACN,QAAQ,CAAC,CAAC,CAAC,CAyCb;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,GACZ;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAqCtC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages shared immutable context for parallel agent execution.
|
|
5
|
+
* Ensures context is frozen before execution and cannot be modified.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-APE-003: Shared context immutable during execution
|
|
9
|
+
* - INV-APE-300: Context snapshot timing (frozen before first task)
|
|
10
|
+
*/
|
|
11
|
+
import { ParallelExecutionErrorCodes } from '@defai.digital/contracts';
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when context mutation is attempted
|
|
14
|
+
*/
|
|
15
|
+
export class ContextMutationError extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'ContextMutationError';
|
|
19
|
+
}
|
|
20
|
+
static code = ParallelExecutionErrorCodes.CONTEXT_MUTATION;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Deep freeze an object and all nested objects
|
|
24
|
+
* INV-APE-003: Ensures true immutability
|
|
25
|
+
*/
|
|
26
|
+
function deepFreeze(obj) {
|
|
27
|
+
// Get property names
|
|
28
|
+
const propNames = Object.getOwnPropertyNames(obj);
|
|
29
|
+
// Freeze nested objects first
|
|
30
|
+
for (const name of propNames) {
|
|
31
|
+
const value = obj[name];
|
|
32
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
33
|
+
deepFreeze(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Freeze self
|
|
37
|
+
return Object.freeze(obj);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a context manager for shared immutable context
|
|
41
|
+
*/
|
|
42
|
+
export function createContextManager() {
|
|
43
|
+
let context = null;
|
|
44
|
+
let frozen = false;
|
|
45
|
+
return {
|
|
46
|
+
/**
|
|
47
|
+
* Create frozen shared context
|
|
48
|
+
* INV-APE-300: Context snapshot timing
|
|
49
|
+
*/
|
|
50
|
+
create(data) {
|
|
51
|
+
// Deep clone to prevent external mutation
|
|
52
|
+
const clonedData = JSON.parse(JSON.stringify(data));
|
|
53
|
+
// Create context object
|
|
54
|
+
const newContext = {
|
|
55
|
+
data: clonedData,
|
|
56
|
+
createdAt: new Date().toISOString(),
|
|
57
|
+
version: '1',
|
|
58
|
+
};
|
|
59
|
+
// Deep freeze the entire context
|
|
60
|
+
// INV-APE-003: Immutable during execution
|
|
61
|
+
context = deepFreeze(newContext);
|
|
62
|
+
frozen = true;
|
|
63
|
+
return context;
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Get read-only view of context
|
|
67
|
+
*/
|
|
68
|
+
get() {
|
|
69
|
+
return context;
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Check if context is frozen/immutable
|
|
73
|
+
*/
|
|
74
|
+
isFrozen() {
|
|
75
|
+
return frozen && context !== null && Object.isFrozen(context);
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Clear context (for cleanup after execution)
|
|
79
|
+
*/
|
|
80
|
+
clear() {
|
|
81
|
+
context = null;
|
|
82
|
+
frozen = false;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a proxy that throws on any mutation attempt
|
|
88
|
+
* Alternative approach for stricter runtime enforcement
|
|
89
|
+
*/
|
|
90
|
+
export function createImmutableContextProxy(data) {
|
|
91
|
+
const handler = {
|
|
92
|
+
get(target, prop, receiver) {
|
|
93
|
+
const value = Reflect.get(target, prop, receiver);
|
|
94
|
+
// Recursively wrap nested objects
|
|
95
|
+
if (value && typeof value === 'object') {
|
|
96
|
+
return createImmutableContextProxy(value);
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
},
|
|
100
|
+
set(_target, prop) {
|
|
101
|
+
throw new ContextMutationError(`Cannot modify shared context: attempted to set "${String(prop)}". ` +
|
|
102
|
+
'Shared context is immutable during parallel execution (INV-APE-003).');
|
|
103
|
+
},
|
|
104
|
+
deleteProperty(_target, prop) {
|
|
105
|
+
throw new ContextMutationError(`Cannot modify shared context: attempted to delete "${String(prop)}". ` +
|
|
106
|
+
'Shared context is immutable during parallel execution (INV-APE-003).');
|
|
107
|
+
},
|
|
108
|
+
defineProperty(_target, prop) {
|
|
109
|
+
throw new ContextMutationError(`Cannot modify shared context: attempted to define "${String(prop)}". ` +
|
|
110
|
+
'Shared context is immutable during parallel execution (INV-APE-003).');
|
|
111
|
+
},
|
|
112
|
+
setPrototypeOf() {
|
|
113
|
+
throw new ContextMutationError('Cannot modify shared context prototype. ' +
|
|
114
|
+
'Shared context is immutable during parallel execution (INV-APE-003).');
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
return new Proxy(data, handler);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Validates that context data is JSON-serializable
|
|
121
|
+
*/
|
|
122
|
+
export function validateContextData(data) {
|
|
123
|
+
const errors = [];
|
|
124
|
+
try {
|
|
125
|
+
// Check JSON serializability
|
|
126
|
+
JSON.stringify(data);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
errors.push(`Context data is not JSON-serializable: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
130
|
+
return { valid: false, errors };
|
|
131
|
+
}
|
|
132
|
+
// Check for functions (not serializable)
|
|
133
|
+
function checkForFunctions(obj, path) {
|
|
134
|
+
if (typeof obj === 'function') {
|
|
135
|
+
errors.push(`Context contains function at ${path}`);
|
|
136
|
+
}
|
|
137
|
+
else if (obj && typeof obj === 'object') {
|
|
138
|
+
if (Array.isArray(obj)) {
|
|
139
|
+
obj.forEach((item, index) => checkForFunctions(item, `${path}[${index}]`));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
143
|
+
checkForFunctions(value, path ? `${path}.${key}` : key);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
checkForFunctions(data, '');
|
|
149
|
+
// Check for circular references (JSON.stringify would have failed)
|
|
150
|
+
// Already caught above
|
|
151
|
+
return {
|
|
152
|
+
valid: errors.length === 0,
|
|
153
|
+
errors,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=context-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../src/context-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGvE;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,2BAA2B,CAAC,gBAAgB,CAAC;;AAGtE;;;GAGG;AACH,SAAS,UAAU,CAAmB,GAAM;IAC1C,qBAAqB;IACrB,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAgB,CAAC;IAEjE,8BAA8B;IAC9B,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAClE,UAAU,CAAC,KAAe,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,cAAc;IACd,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,OAAO,GAAyB,IAAI,CAAC;IACzC,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,OAAO;QACL;;;WAGG;QACH,MAAM,CAAC,IAA6B;YAClC,0CAA0C;YAC1C,MAA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AK,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;YAC7E,CAAC;iBAAM,CAAC;gBACN,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAA8B,CAAC,EAAE,CAAC;oBAC1E,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;gBAC1D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAE5B,mEAAmE;IACnE,uBAAuB;IAEvB,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DAG Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analyzes task dependencies and builds execution layers using topological sort.
|
|
5
|
+
* Detects circular dependencies and validates DAG structure.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-APE-002: Dependencies honored (DAG ordering)
|
|
9
|
+
* - INV-APE-200: Circular dependencies detected before execution
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentParallelTask } from '@defai.digital/contracts';
|
|
12
|
+
import type { DAGAnalyzer } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when DAG analysis fails
|
|
15
|
+
*/
|
|
16
|
+
export declare class DAGAnalysisError extends Error {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly cycleNodes?: string[] | undefined;
|
|
19
|
+
constructor(code: string, message: string, cycleNodes?: string[] | undefined);
|
|
20
|
+
static circularDependency(nodeIds: string[]): DAGAnalysisError;
|
|
21
|
+
static invalidDependency(taskId: string, depId: string): DAGAnalysisError;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a DAG analyzer for parallel task execution
|
|
25
|
+
* Uses Kahn's algorithm for topological sorting
|
|
26
|
+
*/
|
|
27
|
+
export declare function createDAGAnalyzer(): DAGAnalyzer;
|
|
28
|
+
/**
|
|
29
|
+
* Utility: Find tasks in a cycle using DFS
|
|
30
|
+
*/
|
|
31
|
+
export declare function findCyclePath(tasks: AgentParallelTask[]): string[] | null;
|
|
32
|
+
//# sourceMappingURL=dag-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dag-analyzer.d.ts","sourceRoot":"","sources":["../src/dag-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAgC,MAAM,YAAY,CAAC;AAE5E;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,IAAI,EAAE,MAAM;aAEZ,UAAU,CAAC,EAAE,MAAM,EAAE;gBAFrB,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,EAAE,YAAA;IAMvC,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,gBAAgB;IAQ9D,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB;CAM1E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAqL/C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAkDzE"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DAG Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analyzes task dependencies and builds execution layers using topological sort.
|
|
5
|
+
* Detects circular dependencies and validates DAG structure.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-APE-002: Dependencies honored (DAG ordering)
|
|
9
|
+
* - INV-APE-200: Circular dependencies detected before execution
|
|
10
|
+
*/
|
|
11
|
+
import { ParallelExecutionErrorCodes } from '@defai.digital/contracts';
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when DAG analysis fails
|
|
14
|
+
*/
|
|
15
|
+
export class DAGAnalysisError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
cycleNodes;
|
|
18
|
+
constructor(code, message, cycleNodes) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.cycleNodes = cycleNodes;
|
|
22
|
+
this.name = 'DAGAnalysisError';
|
|
23
|
+
}
|
|
24
|
+
static circularDependency(nodeIds) {
|
|
25
|
+
return new DAGAnalysisError(ParallelExecutionErrorCodes.CIRCULAR_DEPENDENCY, `Circular dependency detected: ${nodeIds.join(' -> ')}`, nodeIds);
|
|
26
|
+
}
|
|
27
|
+
static invalidDependency(taskId, depId) {
|
|
28
|
+
return new DAGAnalysisError(ParallelExecutionErrorCodes.INVALID_PLAN, `Task "${taskId}" depends on non-existent task "${depId}"`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a DAG analyzer for parallel task execution
|
|
33
|
+
* Uses Kahn's algorithm for topological sorting
|
|
34
|
+
*/
|
|
35
|
+
export function createDAGAnalyzer() {
|
|
36
|
+
/**
|
|
37
|
+
* Build execution layers using Kahn's algorithm
|
|
38
|
+
* INV-APE-002: Ensures dependencies honored
|
|
39
|
+
* INV-APE-200: Detects cycles via incomplete processing
|
|
40
|
+
*/
|
|
41
|
+
function buildLayers(tasks) {
|
|
42
|
+
// Handle empty input
|
|
43
|
+
if (tasks.length === 0) {
|
|
44
|
+
return {
|
|
45
|
+
layers: [],
|
|
46
|
+
totalLayers: 0,
|
|
47
|
+
maxParallelism: 0,
|
|
48
|
+
hasCycles: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Build task lookup map
|
|
52
|
+
const taskMap = new Map();
|
|
53
|
+
for (const task of tasks) {
|
|
54
|
+
taskMap.set(task.taskId, task);
|
|
55
|
+
}
|
|
56
|
+
// Validate all dependencies exist
|
|
57
|
+
for (const task of tasks) {
|
|
58
|
+
for (const depId of task.dependencies) {
|
|
59
|
+
if (!taskMap.has(depId)) {
|
|
60
|
+
throw DAGAnalysisError.invalidDependency(task.taskId, depId);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Calculate in-degree for each task
|
|
65
|
+
const inDegree = new Map();
|
|
66
|
+
for (const task of tasks) {
|
|
67
|
+
inDegree.set(task.taskId, task.dependencies.length);
|
|
68
|
+
}
|
|
69
|
+
// Build reverse dependency map (who depends on me)
|
|
70
|
+
const dependents = new Map();
|
|
71
|
+
for (const task of tasks) {
|
|
72
|
+
dependents.set(task.taskId, []);
|
|
73
|
+
}
|
|
74
|
+
for (const task of tasks) {
|
|
75
|
+
for (const depId of task.dependencies) {
|
|
76
|
+
const depList = dependents.get(depId) ?? [];
|
|
77
|
+
depList.push(task.taskId);
|
|
78
|
+
dependents.set(depId, depList);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Build layers using BFS
|
|
82
|
+
const layers = [];
|
|
83
|
+
let processedCount = 0;
|
|
84
|
+
// Start with tasks that have no dependencies
|
|
85
|
+
let currentLayerTaskIds = Array.from(inDegree.entries())
|
|
86
|
+
.filter(([_, degree]) => degree === 0)
|
|
87
|
+
.map(([id]) => id);
|
|
88
|
+
let layerIndex = 0;
|
|
89
|
+
while (currentLayerTaskIds.length > 0) {
|
|
90
|
+
// Get tasks for current layer, sorted by priority (descending)
|
|
91
|
+
const layerTasks = currentLayerTaskIds
|
|
92
|
+
.map((id) => taskMap.get(id))
|
|
93
|
+
.sort((a, b) => (b.priority ?? 50) - (a.priority ?? 50));
|
|
94
|
+
layers.push({
|
|
95
|
+
index: layerIndex,
|
|
96
|
+
tasks: layerTasks,
|
|
97
|
+
});
|
|
98
|
+
processedCount += layerTasks.length;
|
|
99
|
+
// Find next layer
|
|
100
|
+
const nextLayerTaskIds = [];
|
|
101
|
+
for (const taskId of currentLayerTaskIds) {
|
|
102
|
+
const deps = dependents.get(taskId) ?? [];
|
|
103
|
+
for (const depId of deps) {
|
|
104
|
+
const degree = (inDegree.get(depId) ?? 0) - 1;
|
|
105
|
+
inDegree.set(depId, degree);
|
|
106
|
+
if (degree === 0) {
|
|
107
|
+
nextLayerTaskIds.push(depId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
currentLayerTaskIds = nextLayerTaskIds;
|
|
112
|
+
layerIndex++;
|
|
113
|
+
}
|
|
114
|
+
// Check for cycles - if we didn't process all tasks, there's a cycle
|
|
115
|
+
const hasCycles = processedCount !== tasks.length;
|
|
116
|
+
let cycleNodes;
|
|
117
|
+
if (hasCycles) {
|
|
118
|
+
// Find nodes involved in cycle (those not processed)
|
|
119
|
+
cycleNodes = tasks
|
|
120
|
+
.filter((t) => (inDegree.get(t.taskId) ?? 0) > 0)
|
|
121
|
+
.map((t) => t.taskId);
|
|
122
|
+
}
|
|
123
|
+
// Calculate max parallelism (largest layer)
|
|
124
|
+
const maxParallelism = Math.max(0, ...layers.map((l) => l.tasks.length));
|
|
125
|
+
const result = {
|
|
126
|
+
layers,
|
|
127
|
+
totalLayers: layers.length,
|
|
128
|
+
maxParallelism,
|
|
129
|
+
hasCycles,
|
|
130
|
+
};
|
|
131
|
+
// Only include cycleNodes if there are cycles
|
|
132
|
+
if (cycleNodes) {
|
|
133
|
+
result.cycleNodes = cycleNodes;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Validate DAG structure
|
|
139
|
+
*/
|
|
140
|
+
function validate(tasks) {
|
|
141
|
+
const errors = [];
|
|
142
|
+
// Check for duplicate task IDs
|
|
143
|
+
const taskIds = new Set();
|
|
144
|
+
for (const task of tasks) {
|
|
145
|
+
if (taskIds.has(task.taskId)) {
|
|
146
|
+
errors.push(`Duplicate task ID: ${task.taskId}`);
|
|
147
|
+
}
|
|
148
|
+
taskIds.add(task.taskId);
|
|
149
|
+
}
|
|
150
|
+
// Check for self-dependencies
|
|
151
|
+
for (const task of tasks) {
|
|
152
|
+
if (task.dependencies.includes(task.taskId)) {
|
|
153
|
+
errors.push(`Task "${task.taskId}" depends on itself`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Check for missing dependencies
|
|
157
|
+
for (const task of tasks) {
|
|
158
|
+
for (const depId of task.dependencies) {
|
|
159
|
+
if (!taskIds.has(depId)) {
|
|
160
|
+
errors.push(`Task "${task.taskId}" depends on non-existent task "${depId}"`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Check for cycles
|
|
165
|
+
if (errors.length === 0) {
|
|
166
|
+
const result = buildLayers(tasks);
|
|
167
|
+
if (result.hasCycles) {
|
|
168
|
+
errors.push(`Circular dependency detected involving: ${result.cycleNodes?.join(', ')}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
valid: errors.length === 0,
|
|
173
|
+
errors,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
analyze(tasks) {
|
|
178
|
+
const result = buildLayers(tasks);
|
|
179
|
+
// Throw if cycles detected
|
|
180
|
+
if (result.hasCycles && result.cycleNodes) {
|
|
181
|
+
throw DAGAnalysisError.circularDependency(result.cycleNodes);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
},
|
|
185
|
+
validate,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Utility: Find tasks in a cycle using DFS
|
|
190
|
+
*/
|
|
191
|
+
export function findCyclePath(tasks) {
|
|
192
|
+
const taskMap = new Map();
|
|
193
|
+
for (const task of tasks) {
|
|
194
|
+
taskMap.set(task.taskId, task);
|
|
195
|
+
}
|
|
196
|
+
const visited = new Set();
|
|
197
|
+
const recursionStack = new Set();
|
|
198
|
+
const path = [];
|
|
199
|
+
function dfs(taskId) {
|
|
200
|
+
visited.add(taskId);
|
|
201
|
+
recursionStack.add(taskId);
|
|
202
|
+
path.push(taskId);
|
|
203
|
+
const task = taskMap.get(taskId);
|
|
204
|
+
if (task) {
|
|
205
|
+
for (const depId of task.dependencies) {
|
|
206
|
+
if (!visited.has(depId)) {
|
|
207
|
+
if (dfs(depId)) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else if (recursionStack.has(depId)) {
|
|
212
|
+
// Found cycle
|
|
213
|
+
path.push(depId);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
recursionStack.delete(taskId);
|
|
219
|
+
path.pop();
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
for (const task of tasks) {
|
|
223
|
+
if (!visited.has(task.taskId)) {
|
|
224
|
+
if (dfs(task.taskId)) {
|
|
225
|
+
// Trim path to only include cycle
|
|
226
|
+
const lastNode = path[path.length - 1];
|
|
227
|
+
if (lastNode) {
|
|
228
|
+
const cycleStart = path.indexOf(lastNode);
|
|
229
|
+
return path.slice(cycleStart);
|
|
230
|
+
}
|
|
231
|
+
return path;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=dag-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dag-analyzer.js","sourceRoot":"","sources":["../src/dag-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGvE;;GAEG;AACH,MA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,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBACrB,kCAAkC;gBAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBACvC,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBAChC,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @defai.digital/agent-parallel
|
|
3
|
+
*
|
|
4
|
+
* Parallel Agent Execution Domain
|
|
5
|
+
*
|
|
6
|
+
* Provides orchestration for executing multiple agents in parallel
|
|
7
|
+
* with DAG-based dependency management, shared immutable context,
|
|
8
|
+
* and configurable result aggregation.
|
|
9
|
+
*
|
|
10
|
+
* @module @defai.digital/agent-parallel
|
|
11
|
+
*/
|
|
12
|
+
export { createAgentParallelOrchestrator, ParallelExecutionError, } from './orchestrator.js';
|
|
13
|
+
export { createDAGAnalyzer, DAGAnalysisError, findCyclePath, } from './dag-analyzer.js';
|
|
14
|
+
export { createContextManager, createImmutableContextProxy, validateContextData, ContextMutationError, } from './context-manager.js';
|
|
15
|
+
export { createResultAggregator, AggregationStrategies, createKeyedAggregator, createTransformAggregator, getAggregationStrategy, } from './result-aggregator.js';
|
|
16
|
+
export type { AgentParallelOrchestrator, AgentParallelOrchestratorOptions, AgentExecutorPort, AgentExecuteRequest, AgentExecuteResult, DAGAnalyzer, DAGAnalysisResult, TaskLayer, ContextManager, ResultAggregator, ResultAggregatorOptions, AggregationStrategy, CustomAggregator, ParallelProgressEvent, ParallelProgressEventType, ParallelProgressCallback, } from './types.js';
|
|
17
|
+
export { StubAgentExecutor } from './types.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EAEV,yBAAyB,EACzB,gCAAgC,EAEhC,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAElB,WAAW,EACX,iBAAiB,EACjB,SAAS,EAET,cAAc,EAEd,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,EAEhB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @defai.digital/agent-parallel
|
|
3
|
+
*
|
|
4
|
+
* Parallel Agent Execution Domain
|
|
5
|
+
*
|
|
6
|
+
* Provides orchestration for executing multiple agents in parallel
|
|
7
|
+
* with DAG-based dependency management, shared immutable context,
|
|
8
|
+
* and configurable result aggregation.
|
|
9
|
+
*
|
|
10
|
+
* @module @defai.digital/agent-parallel
|
|
11
|
+
*/
|
|
12
|
+
// Main Orchestrator
|
|
13
|
+
export { createAgentParallelOrchestrator, ParallelExecutionError, } from './orchestrator.js';
|
|
14
|
+
// DAG Analyzer
|
|
15
|
+
export { createDAGAnalyzer, DAGAnalysisError, findCyclePath, } from './dag-analyzer.js';
|
|
16
|
+
// Context Manager
|
|
17
|
+
export { createContextManager, createImmutableContextProxy, validateContextData, ContextMutationError, } from './context-manager.js';
|
|
18
|
+
// Result Aggregator
|
|
19
|
+
export { createResultAggregator, AggregationStrategies, createKeyedAggregator, createTransformAggregator, getAggregationStrategy, } from './result-aggregator.js';
|
|
20
|
+
// Stub implementation for testing
|
|
21
|
+
export { StubAgentExecutor } from './types.js';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,oBAAoB;AACpB,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,eAAe;AACf,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,kBAAkB;AAClB,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAE9B,oBAAoB;AACpB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AA4BhC,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 type { AgentParallelOrchestrator, AgentParallelOrchestratorOptions } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown during parallel execution
|
|
17
|
+
*/
|
|
18
|
+
export declare class ParallelExecutionError extends Error {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly taskId?: string | undefined;
|
|
21
|
+
constructor(code: string, message: string, taskId?: string | undefined);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a parallel agent orchestrator
|
|
25
|
+
*/
|
|
26
|
+
export declare function createAgentParallelOrchestrator(options: AgentParallelOrchestratorOptions): AgentParallelOrchestrator;
|
|
27
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAaH,OAAO,KAAK,EACV,yBAAyB,EACzB,gCAAgC,EAGjC,MAAM,YAAY,CAAC;AAMpB;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;aAE7B,IAAI,EAAE,MAAM;aAEZ,MAAM,CAAC,EAAE,MAAM;gBAFf,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA;CAKlC;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,gCAAgC,GACxC,yBAAyB,CA2hB3B"}
|