ai-workflows 2.0.2 → 2.1.3

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.
Files changed (98) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/.turbo/turbo-test.log +169 -0
  3. package/CHANGELOG.md +29 -0
  4. package/LICENSE +21 -0
  5. package/README.md +303 -184
  6. package/dist/barrier.d.ts +153 -0
  7. package/dist/barrier.d.ts.map +1 -0
  8. package/dist/barrier.js +339 -0
  9. package/dist/barrier.js.map +1 -0
  10. package/dist/cascade-context.d.ts +149 -0
  11. package/dist/cascade-context.d.ts.map +1 -0
  12. package/dist/cascade-context.js +324 -0
  13. package/dist/cascade-context.js.map +1 -0
  14. package/dist/cascade-executor.d.ts +196 -0
  15. package/dist/cascade-executor.d.ts.map +1 -0
  16. package/dist/cascade-executor.js +384 -0
  17. package/dist/cascade-executor.js.map +1 -0
  18. package/dist/context.d.ts.map +1 -1
  19. package/dist/context.js +4 -1
  20. package/dist/context.js.map +1 -1
  21. package/dist/dependency-graph.d.ts +157 -0
  22. package/dist/dependency-graph.d.ts.map +1 -0
  23. package/dist/dependency-graph.js +382 -0
  24. package/dist/dependency-graph.js.map +1 -0
  25. package/dist/every.d.ts +31 -2
  26. package/dist/every.d.ts.map +1 -1
  27. package/dist/every.js +63 -32
  28. package/dist/every.js.map +1 -1
  29. package/dist/graph/index.d.ts +8 -0
  30. package/dist/graph/index.d.ts.map +1 -0
  31. package/dist/graph/index.js +8 -0
  32. package/dist/graph/index.js.map +1 -0
  33. package/dist/graph/topological-sort.d.ts +121 -0
  34. package/dist/graph/topological-sort.d.ts.map +1 -0
  35. package/dist/graph/topological-sort.js +292 -0
  36. package/dist/graph/topological-sort.js.map +1 -0
  37. package/dist/index.d.ts +6 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +10 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/on.d.ts +35 -10
  42. package/dist/on.d.ts.map +1 -1
  43. package/dist/on.js +52 -18
  44. package/dist/on.js.map +1 -1
  45. package/dist/send.d.ts +0 -5
  46. package/dist/send.d.ts.map +1 -1
  47. package/dist/send.js +1 -14
  48. package/dist/send.js.map +1 -1
  49. package/dist/timer-registry.d.ts +52 -0
  50. package/dist/timer-registry.d.ts.map +1 -0
  51. package/dist/timer-registry.js +120 -0
  52. package/dist/timer-registry.js.map +1 -0
  53. package/dist/types.d.ts +171 -9
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/types.js +17 -1
  56. package/dist/types.js.map +1 -1
  57. package/dist/workflow.d.ts.map +1 -1
  58. package/dist/workflow.js +22 -18
  59. package/dist/workflow.js.map +1 -1
  60. package/package.json +12 -16
  61. package/src/barrier.ts +466 -0
  62. package/src/cascade-context.ts +488 -0
  63. package/src/cascade-executor.ts +587 -0
  64. package/src/context.js +83 -0
  65. package/src/context.ts +12 -7
  66. package/src/dependency-graph.ts +518 -0
  67. package/src/every.js +267 -0
  68. package/src/every.ts +104 -35
  69. package/src/graph/index.ts +19 -0
  70. package/src/graph/topological-sort.ts +414 -0
  71. package/src/index.js +71 -0
  72. package/src/index.ts +78 -0
  73. package/src/on.js +79 -0
  74. package/src/on.ts +81 -25
  75. package/src/send.js +111 -0
  76. package/src/send.ts +1 -16
  77. package/src/timer-registry.ts +145 -0
  78. package/src/types.js +4 -0
  79. package/src/types.ts +218 -11
  80. package/src/workflow.js +455 -0
  81. package/src/workflow.ts +32 -23
  82. package/test/barrier-join.test.ts +434 -0
  83. package/test/barrier-unhandled-rejections.test.ts +359 -0
  84. package/test/cascade-context.test.ts +390 -0
  85. package/test/cascade-executor.test.ts +859 -0
  86. package/test/context.test.js +116 -0
  87. package/test/dependency-graph.test.ts +512 -0
  88. package/test/every.test.js +282 -0
  89. package/test/graph/topological-sort.test.ts +586 -0
  90. package/test/on.test.js +80 -0
  91. package/test/schedule-timer-cleanup.test.ts +344 -0
  92. package/test/send-race-conditions.test.ts +410 -0
  93. package/test/send.test.js +89 -0
  94. package/test/type-safety-every.test.ts +303 -0
  95. package/test/types-event-handler.test.ts +225 -0
  96. package/test/types-proxy-autocomplete.test.ts +345 -0
  97. package/test/workflow.test.js +224 -0
  98. package/vitest.config.js +7 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Topological Sort Implementation for Workflow Execution Ordering
3
+ *
4
+ * Provides multiple algorithms for topologically sorting workflow steps:
5
+ * - Kahn's algorithm (BFS-based, good for detecting cycles)
6
+ * - DFS-based algorithm (classic approach, provides cycle path)
7
+ *
8
+ * Features:
9
+ * - Cycle detection with path reporting
10
+ * - Parallel execution level grouping
11
+ * - Stable, deterministic ordering
12
+ * - Support for missing dependency handling
13
+ */
14
+ /**
15
+ * A node that can be topologically sorted
16
+ */
17
+ export interface SortableNode {
18
+ /** Unique identifier for the node */
19
+ id: string;
20
+ /** IDs of nodes this node depends on */
21
+ dependencies: string[];
22
+ }
23
+ /**
24
+ * Execution level containing nodes that can run in parallel
25
+ */
26
+ export interface ExecutionLevel {
27
+ /** Level number (0 = no dependencies, 1 = depends on level 0, etc.) */
28
+ level: number;
29
+ /** Node IDs that can run concurrently at this level */
30
+ nodes: string[];
31
+ }
32
+ /**
33
+ * Options for topological sort
34
+ */
35
+ export interface TopologicalSortOptions {
36
+ /** Throw CycleDetectedError instead of returning hasCycle: true (default: false) */
37
+ throwOnCycle?: boolean;
38
+ /** Which algorithm to use (default: 'kahn') */
39
+ algorithm?: 'kahn' | 'dfs';
40
+ /** Throw on missing dependencies (default: false) */
41
+ strict?: boolean;
42
+ }
43
+ /**
44
+ * Result of topological sort operation
45
+ */
46
+ export interface TopologicalSortResult {
47
+ /** Sorted node IDs in execution order */
48
+ order: string[];
49
+ /** Whether a cycle was detected */
50
+ hasCycle: boolean;
51
+ /** Path of nodes forming the cycle (if detected) */
52
+ cyclePath?: string[];
53
+ /** Additional metadata from the algorithm */
54
+ metadata?: {
55
+ /** In-degrees for each node (Kahn's algorithm) */
56
+ inDegrees?: Record<string, number>;
57
+ };
58
+ }
59
+ /**
60
+ * Error thrown when a cycle is detected in the dependency graph
61
+ */
62
+ export declare class CycleDetectedError extends Error {
63
+ /** The path of nodes forming the cycle */
64
+ cyclePath: string[];
65
+ constructor(cyclePath: string[]);
66
+ }
67
+ /**
68
+ * Error thrown when a dependency references a non-existent node
69
+ */
70
+ export declare class MissingNodeError extends Error {
71
+ /** The missing node ID */
72
+ missingNode: string;
73
+ /** The node that references the missing node */
74
+ referencedBy: string;
75
+ constructor(missingNode: string, referencedBy: string);
76
+ }
77
+ /**
78
+ * Topological sort using Kahn's algorithm (BFS-based)
79
+ *
80
+ * Algorithm:
81
+ * 1. Calculate in-degree for each node
82
+ * 2. Add all nodes with in-degree 0 to queue
83
+ * 3. While queue not empty:
84
+ * - Remove node from queue, add to result
85
+ * - Decrease in-degree of all dependents
86
+ * - Add nodes with in-degree 0 to queue
87
+ * 4. If result size < node count, cycle exists
88
+ */
89
+ export declare function topologicalSortKahn(nodes: SortableNode[], options?: TopologicalSortOptions): TopologicalSortResult;
90
+ /**
91
+ * Topological sort using DFS-based algorithm
92
+ *
93
+ * Algorithm:
94
+ * 1. For each unvisited node:
95
+ * - Mark as "in progress"
96
+ * - Recursively visit all dependencies
97
+ * - Mark as "visited" and add to result (in reverse)
98
+ * 2. If we encounter a node "in progress", we found a cycle
99
+ */
100
+ export declare function topologicalSortDFS(nodes: SortableNode[], options?: TopologicalSortOptions): TopologicalSortResult;
101
+ /**
102
+ * Main topological sort function with algorithm selection
103
+ *
104
+ * @param nodes - Array of nodes to sort
105
+ * @param options - Sort options
106
+ * @returns Sorted result with order and cycle information
107
+ */
108
+ export declare function topologicalSort(nodes: SortableNode[], options?: TopologicalSortOptions): TopologicalSortResult;
109
+ /**
110
+ * Get execution levels for parallel execution
111
+ *
112
+ * Groups nodes by their execution level:
113
+ * - Level 0: Nodes with no dependencies
114
+ * - Level N: Nodes whose dependencies are all at level < N
115
+ *
116
+ * @param nodes - Array of nodes to analyze
117
+ * @returns Array of execution levels, sorted by level number
118
+ * @throws CycleDetectedError if a cycle is detected
119
+ */
120
+ export declare function getExecutionLevels(nodes: SortableNode[]): ExecutionLevel[];
121
+ //# sourceMappingURL=topological-sort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topological-sort.d.ts","sourceRoot":"","sources":["../../src/graph/topological-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAA;IACV,wCAAwC;IACxC,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,uDAAuD;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,oFAAoF;IACpF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAC1B,qDAAqD;IACrD,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,mCAAmC;IACnC,QAAQ,EAAE,OAAO,CAAA;IACjB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE;QACT,kDAAkD;QAClD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACnC,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,0CAA0C;IAC1C,SAAS,EAAE,MAAM,EAAE,CAAA;gBAEP,SAAS,EAAE,MAAM,EAAE;CAMhC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAA;gBAER,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAQtD;AA8CD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EAAE,EACrB,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CAmDvB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,EAAE,EACrB,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CA2EvB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EAAE,EACrB,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CAsBvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,cAAc,EAAE,CAqE1E"}
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Topological Sort Implementation for Workflow Execution Ordering
3
+ *
4
+ * Provides multiple algorithms for topologically sorting workflow steps:
5
+ * - Kahn's algorithm (BFS-based, good for detecting cycles)
6
+ * - DFS-based algorithm (classic approach, provides cycle path)
7
+ *
8
+ * Features:
9
+ * - Cycle detection with path reporting
10
+ * - Parallel execution level grouping
11
+ * - Stable, deterministic ordering
12
+ * - Support for missing dependency handling
13
+ */
14
+ /**
15
+ * Error thrown when a cycle is detected in the dependency graph
16
+ */
17
+ export class CycleDetectedError extends Error {
18
+ /** The path of nodes forming the cycle */
19
+ cyclePath;
20
+ constructor(cyclePath) {
21
+ const pathStr = cyclePath.join(' -> ');
22
+ super(`Cycle detected in dependency graph: ${pathStr}`);
23
+ this.name = 'CycleDetectedError';
24
+ this.cyclePath = cyclePath;
25
+ }
26
+ }
27
+ /**
28
+ * Error thrown when a dependency references a non-existent node
29
+ */
30
+ export class MissingNodeError extends Error {
31
+ /** The missing node ID */
32
+ missingNode;
33
+ /** The node that references the missing node */
34
+ referencedBy;
35
+ constructor(missingNode, referencedBy) {
36
+ super(`Missing dependency '${missingNode}' referenced by '${referencedBy}'`);
37
+ this.name = 'MissingNodeError';
38
+ this.missingNode = missingNode;
39
+ this.referencedBy = referencedBy;
40
+ }
41
+ }
42
+ /**
43
+ * Build adjacency list and compute in-degrees for Kahn's algorithm
44
+ */
45
+ function buildGraph(nodes, strict) {
46
+ const nodeSet = new Set(nodes.map((n) => n.id));
47
+ const adjacencyList = new Map();
48
+ const inDegrees = new Map();
49
+ // Initialize all nodes
50
+ for (const node of nodes) {
51
+ adjacencyList.set(node.id, []);
52
+ inDegrees.set(node.id, 0);
53
+ }
54
+ // Build edges (dependency -> dependent)
55
+ for (const node of nodes) {
56
+ // Deduplicate dependencies
57
+ const uniqueDeps = [...new Set(node.dependencies)];
58
+ for (const dep of uniqueDeps) {
59
+ if (!nodeSet.has(dep)) {
60
+ if (strict) {
61
+ throw new MissingNodeError(dep, node.id);
62
+ }
63
+ // Skip missing dependencies in non-strict mode
64
+ continue;
65
+ }
66
+ // Add edge from dependency to this node
67
+ adjacencyList.get(dep).push(node.id);
68
+ inDegrees.set(node.id, inDegrees.get(node.id) + 1);
69
+ }
70
+ }
71
+ return { adjacencyList, inDegrees, nodeSet };
72
+ }
73
+ /**
74
+ * Topological sort using Kahn's algorithm (BFS-based)
75
+ *
76
+ * Algorithm:
77
+ * 1. Calculate in-degree for each node
78
+ * 2. Add all nodes with in-degree 0 to queue
79
+ * 3. While queue not empty:
80
+ * - Remove node from queue, add to result
81
+ * - Decrease in-degree of all dependents
82
+ * - Add nodes with in-degree 0 to queue
83
+ * 4. If result size < node count, cycle exists
84
+ */
85
+ export function topologicalSortKahn(nodes, options = {}) {
86
+ const { strict = false } = options;
87
+ if (nodes.length === 0) {
88
+ return { order: [], hasCycle: false };
89
+ }
90
+ const { adjacencyList, inDegrees, nodeSet } = buildGraph(nodes, strict);
91
+ const order = [];
92
+ const inDegreesCopy = new Map(inDegrees);
93
+ // Start with nodes that have no dependencies (in-degree 0)
94
+ // Sort alphabetically for determinism
95
+ const queue = [...nodeSet]
96
+ .filter((id) => inDegreesCopy.get(id) === 0)
97
+ .sort();
98
+ while (queue.length > 0) {
99
+ // Sort queue for deterministic ordering
100
+ queue.sort();
101
+ const current = queue.shift();
102
+ order.push(current);
103
+ // Decrease in-degree for all dependents
104
+ for (const dependent of adjacencyList.get(current) || []) {
105
+ const newDegree = inDegreesCopy.get(dependent) - 1;
106
+ inDegreesCopy.set(dependent, newDegree);
107
+ if (newDegree === 0) {
108
+ queue.push(dependent);
109
+ }
110
+ }
111
+ }
112
+ // If we didn't process all nodes, there's a cycle
113
+ const hasCycle = order.length < nodeSet.size;
114
+ // Convert in-degrees to record
115
+ const inDegreesRecord = {};
116
+ for (const [id, degree] of inDegrees) {
117
+ inDegreesRecord[id] = degree;
118
+ }
119
+ return {
120
+ order,
121
+ hasCycle,
122
+ metadata: {
123
+ inDegrees: inDegreesRecord,
124
+ },
125
+ };
126
+ }
127
+ /**
128
+ * Topological sort using DFS-based algorithm
129
+ *
130
+ * Algorithm:
131
+ * 1. For each unvisited node:
132
+ * - Mark as "in progress"
133
+ * - Recursively visit all dependencies
134
+ * - Mark as "visited" and add to result (in reverse)
135
+ * 2. If we encounter a node "in progress", we found a cycle
136
+ */
137
+ export function topologicalSortDFS(nodes, options = {}) {
138
+ const { strict = false } = options;
139
+ if (nodes.length === 0) {
140
+ return { order: [], hasCycle: false };
141
+ }
142
+ const nodeMap = new Map(nodes.map((n) => [n.id, n]));
143
+ const nodeSet = new Set(nodes.map((n) => n.id));
144
+ const visited = new Set();
145
+ const inProgress = new Set();
146
+ const order = [];
147
+ let cyclePath;
148
+ function dfs(nodeId, path) {
149
+ if (inProgress.has(nodeId)) {
150
+ // Found a cycle - construct the cycle path
151
+ const cycleStart = path.indexOf(nodeId);
152
+ cyclePath = [...path.slice(cycleStart), nodeId];
153
+ return true; // Cycle detected
154
+ }
155
+ if (visited.has(nodeId)) {
156
+ return false; // Already processed
157
+ }
158
+ inProgress.add(nodeId);
159
+ path.push(nodeId);
160
+ const node = nodeMap.get(nodeId);
161
+ if (node) {
162
+ // Deduplicate and sort dependencies for determinism
163
+ const uniqueDeps = [...new Set(node.dependencies)].sort();
164
+ for (const dep of uniqueDeps) {
165
+ if (!nodeSet.has(dep)) {
166
+ if (strict) {
167
+ throw new MissingNodeError(dep, nodeId);
168
+ }
169
+ continue; // Skip missing deps in non-strict mode
170
+ }
171
+ if (dfs(dep, path)) {
172
+ return true; // Propagate cycle detection
173
+ }
174
+ }
175
+ }
176
+ path.pop();
177
+ inProgress.delete(nodeId);
178
+ visited.add(nodeId);
179
+ order.push(nodeId);
180
+ return false;
181
+ }
182
+ // Process nodes in sorted order for determinism
183
+ const sortedNodeIds = [...nodeSet].sort();
184
+ for (const nodeId of sortedNodeIds) {
185
+ if (!visited.has(nodeId)) {
186
+ if (dfs(nodeId, [])) {
187
+ break; // Stop on first cycle
188
+ }
189
+ }
190
+ }
191
+ const hasCycle = cyclePath !== undefined;
192
+ return {
193
+ order: hasCycle ? order : order, // DFS produces correct order
194
+ hasCycle,
195
+ cyclePath,
196
+ };
197
+ }
198
+ /**
199
+ * Main topological sort function with algorithm selection
200
+ *
201
+ * @param nodes - Array of nodes to sort
202
+ * @param options - Sort options
203
+ * @returns Sorted result with order and cycle information
204
+ */
205
+ export function topologicalSort(nodes, options = {}) {
206
+ const { algorithm = 'dfs', throwOnCycle = false } = options;
207
+ let result;
208
+ if (algorithm === 'kahn') {
209
+ result = topologicalSortKahn(nodes, options);
210
+ // Kahn's algorithm doesn't provide cycle path, so detect it separately
211
+ if (result.hasCycle) {
212
+ const dfsResult = topologicalSortDFS(nodes, options);
213
+ result.cyclePath = dfsResult.cyclePath;
214
+ }
215
+ }
216
+ else {
217
+ result = topologicalSortDFS(nodes, options);
218
+ }
219
+ if (result.hasCycle && throwOnCycle) {
220
+ throw new CycleDetectedError(result.cyclePath || ['unknown']);
221
+ }
222
+ return result;
223
+ }
224
+ /**
225
+ * Get execution levels for parallel execution
226
+ *
227
+ * Groups nodes by their execution level:
228
+ * - Level 0: Nodes with no dependencies
229
+ * - Level N: Nodes whose dependencies are all at level < N
230
+ *
231
+ * @param nodes - Array of nodes to analyze
232
+ * @returns Array of execution levels, sorted by level number
233
+ * @throws CycleDetectedError if a cycle is detected
234
+ */
235
+ export function getExecutionLevels(nodes) {
236
+ if (nodes.length === 0) {
237
+ return [];
238
+ }
239
+ // First, verify no cycles exist
240
+ const sortResult = topologicalSort(nodes, { throwOnCycle: true });
241
+ const nodeMap = new Map(nodes.map((n) => [n.id, n]));
242
+ const nodeSet = new Set(nodes.map((n) => n.id));
243
+ const levels = new Map();
244
+ // Calculate level for each node
245
+ function calculateLevel(nodeId) {
246
+ if (levels.has(nodeId)) {
247
+ return levels.get(nodeId);
248
+ }
249
+ const node = nodeMap.get(nodeId);
250
+ if (!node) {
251
+ return 0;
252
+ }
253
+ // Filter to only existing dependencies
254
+ const validDeps = node.dependencies.filter((d) => nodeSet.has(d));
255
+ if (validDeps.length === 0) {
256
+ levels.set(nodeId, 0);
257
+ return 0;
258
+ }
259
+ let maxDepLevel = -1;
260
+ for (const dep of validDeps) {
261
+ const depLevel = calculateLevel(dep);
262
+ maxDepLevel = Math.max(maxDepLevel, depLevel);
263
+ }
264
+ const level = maxDepLevel + 1;
265
+ levels.set(nodeId, level);
266
+ return level;
267
+ }
268
+ // Calculate levels for all nodes
269
+ for (const node of nodes) {
270
+ calculateLevel(node.id);
271
+ }
272
+ // Group nodes by level
273
+ const levelGroups = new Map();
274
+ for (const [nodeId, level] of levels) {
275
+ if (!levelGroups.has(level)) {
276
+ levelGroups.set(level, []);
277
+ }
278
+ levelGroups.get(level).push(nodeId);
279
+ }
280
+ // Convert to sorted array of ExecutionLevels
281
+ const result = [];
282
+ const sortedLevels = [...levelGroups.keys()].sort((a, b) => a - b);
283
+ for (const level of sortedLevels) {
284
+ result.push({
285
+ level,
286
+ // Sort nodes within level for determinism
287
+ nodes: levelGroups.get(level).sort(),
288
+ });
289
+ }
290
+ return result;
291
+ }
292
+ //# sourceMappingURL=topological-sort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topological-sort.js","sourceRoot":"","sources":["../../src/graph/topological-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmDH;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,0CAA0C;IAC1C,SAAS,CAAU;IAEnB,YAAY,SAAmB;QAC7B,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACtC,KAAK,CAAC,uCAAuC,OAAO,EAAE,CAAC,CAAA;QACvD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,0BAA0B;IAC1B,WAAW,CAAQ;IACnB,gDAAgD;IAChD,YAAY,CAAQ;IAEpB,YAAY,WAAmB,EAAE,YAAoB;QACnD,KAAK,CACH,uBAAuB,WAAW,oBAAoB,YAAY,GAAG,CACtE,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;CACF;AAED;;GAEG;AACH,SAAS,UAAU,CACjB,KAAqB,EACrB,MAAe;IAMf,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAoB,CAAA;IACjD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAA;IAE3C,uBAAuB;IACv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EAAE,QAAQ,CAAC,CAAA;QAC/C,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,GAAG,CAAC,CAAA;QAC7B,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACzB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,iCAAiC;IACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,uBAAuB;IACvB,MAAM,WAAW,GAAG,IAAI,GAAG,EAAoB,CAAA;IAC/C,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC5B,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;IAED,6CAA6C;IAC7C,MAAM,MAAM,GAAqB,EAAE,CAAA;IACnC,MAAM,YAAY,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAElE,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC;YACV,KAAK;YACL,0CAA0C;YAC1C,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,EAAE;SACtC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -64,5 +64,10 @@ export { on, registerEventHandler, getEventHandlers, clearEventHandlers } from '
64
64
  export { every, registerScheduleHandler, getScheduleHandlers, clearScheduleHandlers, setCronConverter, toCron, intervalToMs, formatInterval, } from './every.js';
65
65
  export { send, getEventBus } from './send.js';
66
66
  export { createWorkflowContext, createIsolatedContext } from './context.js';
67
- export type { EventHandler, ScheduleHandler, WorkflowContext, WorkflowState, WorkflowHistoryEntry, EventRegistration, ScheduleRegistration, ScheduleInterval, WorkflowDefinition, WorkflowOptions, ParsedEvent, OnProxy, EveryProxy, HandlerFunction, DatabaseContext, ActionData, ArtifactData, } from './types.js';
67
+ export { createCascadeContext, recordStep, withCascadeContext, type CascadeContext, type CascadeStep, type CascadeContextOptions, type SerializedCascadeContext, type SerializedCascadeStep, type TraceContext, type FiveWHEvent, type StepStatus, } from './cascade-context.js';
68
+ export { DependencyGraph, CircularDependencyError, MissingDependencyError, type GraphNode, type ParallelGroup, type GraphJSON, type EventRegistrationWithDeps, } from './dependency-graph.js';
69
+ export { topologicalSort, topologicalSortKahn, topologicalSortDFS, getExecutionLevels, CycleDetectedError, MissingNodeError, type SortableNode, type ExecutionLevel, type TopologicalSortOptions, type TopologicalSortResult, } from './graph/topological-sort.js';
70
+ export { Barrier, BarrierTimeoutError, createBarrier, waitForAll, waitForAny, withConcurrencyLimit, type BarrierOptions, type BarrierProgress, type BarrierResult, type WaitForAllOptions, type WaitForAnyOptions, type WaitForAnyResult, type ConcurrencyOptions, } from './barrier.js';
71
+ export { CascadeExecutor, CascadeTimeoutError, TierSkippedError, AllTiersFailedError, TIER_ORDER, DEFAULT_TIER_TIMEOUTS, type CapabilityTier, type TierHandler, type TierContext, type TierResult, type TierRetryConfig, type CascadeConfig, type CascadeResult, type CascadeMetrics, type SkipCondition, } from './cascade-executor.js';
72
+ export type { EventHandler, ScheduleHandler, WorkflowContext, WorkflowState, WorkflowHistoryEntry, EventRegistration, ScheduleRegistration, ScheduleInterval, WorkflowDefinition, WorkflowOptions, ParsedEvent, OnProxy, EveryProxy, HandlerFunction, DatabaseContext, ActionData, ArtifactData, DependencyConfig, DependencyType, } from './types.js';
68
73
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAGH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAG9F,OAAO,EAAE,EAAE,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGxF,OAAO,EACL,KAAK,EACL,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAG7C,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAG3E,YAAY,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,OAAO,EACP,UAAU,EACV,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAGH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAG9F,OAAO,EAAE,EAAE,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGxF,OAAO,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B,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,uBAAuB,CAAA;AAG9B,YAAY,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,OAAO,EACP,UAAU,EACV,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -69,4 +69,14 @@ export { every, registerScheduleHandler, getScheduleHandlers, clearScheduleHandl
69
69
  export { send, getEventBus } from './send.js';
70
70
  // Context
71
71
  export { createWorkflowContext, createIsolatedContext } from './context.js';
72
+ // Cascade Context - Correlation IDs and step metadata
73
+ export { createCascadeContext, recordStep, withCascadeContext, } from './cascade-context.js';
74
+ // Dependency Graph
75
+ export { DependencyGraph, CircularDependencyError, MissingDependencyError, } from './dependency-graph.js';
76
+ // Topological Sort - Execution ordering algorithms
77
+ export { topologicalSort, topologicalSortKahn, topologicalSortDFS, getExecutionLevels, CycleDetectedError, MissingNodeError, } from './graph/topological-sort.js';
78
+ // Barrier/Join Semantics - Parallel step coordination
79
+ export { Barrier, BarrierTimeoutError, createBarrier, waitForAll, waitForAny, withConcurrencyLimit, } from './barrier.js';
80
+ // Cascade Executor - code -> generative -> agentic -> human pattern
81
+ export { CascadeExecutor, CascadeTimeoutError, TierSkippedError, AllTiersFailedError, TIER_ORDER, DEFAULT_TIER_TIMEOUTS, } from './cascade-executor.js';
72
82
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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UAAU,EACV,kBAAkB,GASnB,MAAM,sBAAsB,CAAA;AAE7B,mBAAmB;AACnB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,sBAAsB,GAKvB,MAAM,uBAAuB,CAAA;AAE9B,mDAAmD;AACnD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GAKjB,MAAM,6BAA6B,CAAA;AAEpC,sDAAsD;AACtD,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,UAAU,EACV,oBAAoB,GAQrB,MAAM,cAAc,CAAA;AAErB,oEAAoE;AACpE,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,qBAAqB,GAUtB,MAAM,uBAAuB,CAAA"}
package/dist/on.d.ts CHANGED
@@ -5,8 +5,12 @@
5
5
  * on.Customer.created(customer => { ... })
6
6
  * on.Order.completed(order => { ... })
7
7
  * on.Payment.failed(payment => { ... })
8
+ *
9
+ * With dependencies:
10
+ * on.Step2.complete(handler, { dependsOn: 'Step1.complete' })
11
+ * on.Step3.complete(handler, { dependsOn: ['Step1.complete', 'Step2.complete'] })
8
12
  */
9
- import type { EventHandler, EventRegistration } from './types.js';
13
+ import type { EventHandler, EventRegistration, DependencyConfig, OnProxy } from './types.js';
10
14
  /**
11
15
  * Get all registered event handlers
12
16
  */
@@ -18,15 +22,37 @@ export declare function clearEventHandlers(): void;
18
22
  /**
19
23
  * Register an event handler directly
20
24
  */
21
- export declare function registerEventHandler(noun: string, event: string, handler: EventHandler): void;
25
+ export declare function registerEventHandler(noun: string, event: string, handler: EventHandler, dependencies?: DependencyConfig): void;
26
+ /**
27
+ * Handler registration callback type
28
+ * Used by createTypedOnProxy to customize handler registration
29
+ */
30
+ export type OnProxyRegistrationCallback = (noun: string, event: string, handler: EventHandler, dependencies?: DependencyConfig) => void;
22
31
  /**
23
- * Event proxy type for on.Noun.event pattern
32
+ * Create a typed OnProxy with proper TypeScript generics
33
+ *
34
+ * This factory function creates a two-level proxy that allows:
35
+ * proxy.Customer.created(handler)
36
+ * proxy.Order.shipped(handler)
37
+ *
38
+ * The first property access captures the noun (Customer, Order)
39
+ * The second property access captures the event (created, shipped)
40
+ * The function call invokes the registration callback
41
+ *
42
+ * @param registerCallback - Function called when a handler is registered
43
+ * @returns A properly typed OnProxy
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * // Create proxy with custom registration
48
+ * const myOn = createTypedOnProxy((noun, event, handler, deps) => {
49
+ * myRegistry.push({ noun, event, handler, deps })
50
+ * })
51
+ *
52
+ * myOn.Customer.created(handler) // Properly typed!
53
+ * ```
24
54
  */
25
- type EventProxy = {
26
- [noun: string]: {
27
- [event: string]: (handler: EventHandler) => void;
28
- };
29
- };
55
+ export declare function createTypedOnProxy(registerCallback: OnProxyRegistrationCallback): OnProxy;
30
56
  /**
31
57
  * The `on` object for registering event handlers
32
58
  *
@@ -44,6 +70,5 @@ type EventProxy = {
44
70
  * })
45
71
  * ```
46
72
  */
47
- export declare const on: EventProxy;
48
- export {};
73
+ export declare const on: OnProxy;
49
74
  //# sourceMappingURL=on.d.ts.map
package/dist/on.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../src/on.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAOjE;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,iBAAiB,EAAE,CAEtD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,YAAY,GACpB,IAAI,CAON;AAED;;GAEG;AACH,KAAK,UAAU,GAAG;IAChB,CAAC,IAAI,EAAE,MAAM,GAAG;QACd,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;KACjD,CAAA;CACF,CAAA;AA6BD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,EAAE,YAAkB,CAAA"}
1
+ {"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../src/on.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EAIR,MAAM,YAAY,CAAA;AAOnB;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,iBAAiB,EAAE,CAEtD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,YAAY,EACrB,YAAY,CAAC,EAAE,gBAAgB,GAC9B,IAAI,CAQN;AAED;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,CACxC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,YAAY,EACrB,YAAY,CAAC,EAAE,gBAAgB,KAC5B,IAAI,CAAA;AAET;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,2BAA2B,GAAG,OAAO,CA+BzF;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,EAAE,SAAkB,CAAA"}
package/dist/on.js CHANGED
@@ -5,6 +5,10 @@
5
5
  * on.Customer.created(customer => { ... })
6
6
  * on.Order.completed(order => { ... })
7
7
  * on.Payment.failed(payment => { ... })
8
+ *
9
+ * With dependencies:
10
+ * on.Step2.complete(handler, { dependsOn: 'Step1.complete' })
11
+ * on.Step3.complete(handler, { dependsOn: ['Step1.complete', 'Step2.complete'] })
8
12
  */
9
13
  /**
10
14
  * Registry of event handlers
@@ -25,39 +29,69 @@ export function clearEventHandlers() {
25
29
  /**
26
30
  * Register an event handler directly
27
31
  */
28
- export function registerEventHandler(noun, event, handler) {
32
+ export function registerEventHandler(noun, event, handler, dependencies) {
29
33
  eventRegistry.push({
30
34
  noun,
31
35
  event,
32
36
  handler,
33
37
  source: handler.toString(),
38
+ dependencies,
34
39
  });
35
40
  }
36
41
  /**
37
- * Create the `on` proxy
42
+ * Create a typed OnProxy with proper TypeScript generics
38
43
  *
39
- * This creates a proxy that allows:
40
- * on.Customer.created(handler)
41
- * on.Order.shipped(handler)
44
+ * This factory function creates a two-level proxy that allows:
45
+ * proxy.Customer.created(handler)
46
+ * proxy.Order.shipped(handler)
42
47
  *
43
48
  * The first property access captures the noun (Customer, Order)
44
49
  * The second property access captures the event (created, shipped)
45
- * The function call registers the handler
50
+ * The function call invokes the registration callback
51
+ *
52
+ * @param registerCallback - Function called when a handler is registered
53
+ * @returns A properly typed OnProxy
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * // Create proxy with custom registration
58
+ * const myOn = createTypedOnProxy((noun, event, handler, deps) => {
59
+ * myRegistry.push({ noun, event, handler, deps })
60
+ * })
61
+ *
62
+ * myOn.Customer.created(handler) // Properly typed!
63
+ * ```
46
64
  */
47
- function createOnProxy() {
48
- return new Proxy({}, {
49
- get(_target, noun) {
50
- // Return a proxy for the event level
51
- return new Proxy({}, {
52
- get(_eventTarget, event) {
53
- // Return a function that registers the handler
54
- return (handler) => {
55
- registerEventHandler(noun, event, handler);
56
- };
57
- }
58
- });
65
+ export function createTypedOnProxy(registerCallback) {
66
+ // Create typed handler for the noun level (event accessors)
67
+ const createNounHandler = (noun) => ({
68
+ get(_target, event, _receiver) {
69
+ // Return a function that registers the handler with optional dependencies
70
+ return (handler, dependencies) => {
71
+ registerCallback(noun, event, handler, dependencies);
72
+ };
59
73
  }
60
74
  });
75
+ // Create typed handler for the top-level proxy (noun accessors)
76
+ const onHandler = {
77
+ get(_target, noun, _receiver) {
78
+ // Return a proxy for the event level with typed handler
79
+ const eventTarget = {};
80
+ return new Proxy(eventTarget, createNounHandler(noun));
81
+ }
82
+ };
83
+ // Create and return the typed OnProxy
84
+ const target = {};
85
+ return new Proxy(target, onHandler);
86
+ }
87
+ /**
88
+ * Create the `on` proxy using the global event registry
89
+ *
90
+ * This is the default implementation that uses registerEventHandler
91
+ * for backward compatibility with the standalone `on` export.
92
+ */
93
+ function createOnProxy() {
94
+ return createTypedOnProxy(registerEventHandler);
61
95
  }
62
96
  /**
63
97
  * The `on` object for registering event handlers
package/dist/on.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"on.js","sourceRoot":"","sources":["../src/on.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;GAEG;AACH,MAAM,aAAa,GAAwB,EAAE,CAAA;AAE7C;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CAAC,GAAG,aAAa,CAAC,CAAA;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAA;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,KAAa,EACb,OAAqB;IAErB,aAAa,CAAC,IAAI,CAAC;QACjB,IAAI;QACJ,KAAK;QACL,OAAO;QACP,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE;KAC3B,CAAC,CAAA;AACJ,CAAC;AAWD;;;;;;;;;;GAUG;AACH,SAAS,aAAa;IACpB,OAAO,IAAI,KAAK,CAAC,EAAgB,EAAE;QACjC,GAAG,CAAC,OAAO,EAAE,IAAY;YACvB,qCAAqC;YACrC,OAAO,IAAI,KAAK,CAAC,EAAE,EAAE;gBACnB,GAAG,CAAC,YAAY,EAAE,KAAa;oBAC7B,+CAA+C;oBAC/C,OAAO,CAAC,OAAqB,EAAE,EAAE;wBAC/B,oBAAoB,CAAC,IAAI,EAA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