flowcraft 2.2.0 → 2.3.1

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 (147) hide show
  1. package/README.md +40 -34
  2. package/dist/analysis.d.ts +3 -1
  3. package/dist/chunk-33NO4PUJ.js +74 -0
  4. package/dist/chunk-33NO4PUJ.js.map +1 -0
  5. package/dist/chunk-BC4G7OM6.js +42 -0
  6. package/dist/chunk-BC4G7OM6.js.map +1 -0
  7. package/dist/chunk-BCRWXTWX.js +21 -0
  8. package/dist/chunk-BCRWXTWX.js.map +1 -0
  9. package/dist/chunk-BN4MV36K.js +25 -0
  10. package/dist/chunk-BN4MV36K.js.map +1 -0
  11. package/dist/{chunk-ZCHFZBGL.js → chunk-C4HYIJI3.js} +120 -5
  12. package/dist/chunk-C4HYIJI3.js.map +1 -0
  13. package/dist/chunk-CD3Q4N6V.js +13 -0
  14. package/dist/chunk-CD3Q4N6V.js.map +1 -0
  15. package/dist/chunk-CD4FUZOJ.js +114 -0
  16. package/dist/chunk-CD4FUZOJ.js.map +1 -0
  17. package/dist/chunk-DL7KVYZF.js +39 -0
  18. package/dist/chunk-DL7KVYZF.js.map +1 -0
  19. package/dist/chunk-FRKO3WX4.js +32 -0
  20. package/dist/chunk-FRKO3WX4.js.map +1 -0
  21. package/dist/chunk-G53CSLBF.js +54 -0
  22. package/dist/chunk-G53CSLBF.js.map +1 -0
  23. package/dist/chunk-G5BGBPFP.js +172 -0
  24. package/dist/chunk-G5BGBPFP.js.map +1 -0
  25. package/dist/chunk-HAZ26F3P.js +98 -0
  26. package/dist/chunk-HAZ26F3P.js.map +1 -0
  27. package/dist/chunk-HKX7WQLS.js +446 -0
  28. package/dist/chunk-HKX7WQLS.js.map +1 -0
  29. package/dist/{chunk-U5V5O5MN.js → chunk-LNK7LZER.js} +5 -3
  30. package/dist/chunk-LNK7LZER.js.map +1 -0
  31. package/dist/chunk-MCGK3FXQ.js +143 -0
  32. package/dist/chunk-MCGK3FXQ.js.map +1 -0
  33. package/dist/chunk-MKNZBKSR.js +90 -0
  34. package/dist/chunk-MKNZBKSR.js.map +1 -0
  35. package/dist/chunk-MUYLRTSR.js +82 -0
  36. package/dist/chunk-MUYLRTSR.js.map +1 -0
  37. package/dist/chunk-NVJ3ZO3P.js +3 -0
  38. package/dist/{chunk-HMR2GEGE.js.map → chunk-NVJ3ZO3P.js.map} +1 -1
  39. package/dist/chunk-NVLZFLYM.js +3 -0
  40. package/dist/chunk-NVLZFLYM.js.map +1 -0
  41. package/dist/chunk-ONH7PIJZ.js +300 -0
  42. package/dist/chunk-ONH7PIJZ.js.map +1 -0
  43. package/dist/chunk-QNYXQKFW.js +25 -0
  44. package/dist/chunk-QNYXQKFW.js.map +1 -0
  45. package/dist/chunk-RM677CNU.js +52 -0
  46. package/dist/chunk-RM677CNU.js.map +1 -0
  47. package/dist/chunk-WWGFIYKW.js +47 -0
  48. package/dist/chunk-WWGFIYKW.js.map +1 -0
  49. package/dist/chunk-XNRIM27H.js +76 -0
  50. package/dist/chunk-XNRIM27H.js.map +1 -0
  51. package/dist/{chunk-QLGJUDQF.js → chunk-ZNL7ZXPR.js} +26 -11
  52. package/dist/chunk-ZNL7ZXPR.js.map +1 -0
  53. package/dist/container-factory.d.ts +17 -0
  54. package/dist/container-factory.js +13 -0
  55. package/dist/container-factory.js.map +1 -0
  56. package/dist/container.d.ts +23 -0
  57. package/dist/container.js +3 -0
  58. package/dist/container.js.map +1 -0
  59. package/dist/context.d.ts +3 -1
  60. package/dist/errors.d.ts +18 -17
  61. package/dist/errors.js +1 -1
  62. package/dist/evaluator.d.ts +3 -1
  63. package/dist/flow.d.ts +12 -2
  64. package/dist/flow.js +2 -2
  65. package/dist/index.d.ts +7 -8
  66. package/dist/index.js +26 -14
  67. package/dist/linter.d.ts +3 -1
  68. package/dist/logger.d.ts +3 -1
  69. package/dist/node.d.ts +3 -1
  70. package/dist/node.js +1 -1
  71. package/dist/nodes/batch-gather.d.ts +9 -0
  72. package/dist/nodes/batch-gather.js +4 -0
  73. package/dist/nodes/batch-gather.js.map +1 -0
  74. package/dist/nodes/batch-scatter.d.ts +9 -0
  75. package/dist/nodes/batch-scatter.js +4 -0
  76. package/dist/nodes/batch-scatter.js.map +1 -0
  77. package/dist/nodes/subflow.d.ts +9 -0
  78. package/dist/nodes/subflow.js +10 -0
  79. package/dist/nodes/subflow.js.map +1 -0
  80. package/dist/nodes/wait.d.ts +9 -0
  81. package/dist/nodes/wait.js +4 -0
  82. package/dist/nodes/wait.js.map +1 -0
  83. package/dist/runtime/adapter.d.ts +3 -5
  84. package/dist/runtime/adapter.js +19 -9
  85. package/dist/runtime/execution-context.d.ts +3 -0
  86. package/dist/runtime/execution-context.js +6 -0
  87. package/dist/runtime/execution-context.js.map +1 -0
  88. package/dist/runtime/executors.d.ts +3 -26
  89. package/dist/runtime/executors.js +2 -2
  90. package/dist/runtime/index.d.ts +5 -7
  91. package/dist/runtime/index.js +21 -10
  92. package/dist/runtime/node-executor-factory.d.ts +12 -0
  93. package/dist/runtime/node-executor-factory.js +6 -0
  94. package/dist/runtime/node-executor-factory.js.map +1 -0
  95. package/dist/runtime/orchestrator.d.ts +9 -0
  96. package/dist/runtime/orchestrator.js +8 -0
  97. package/dist/runtime/orchestrator.js.map +1 -0
  98. package/dist/runtime/orchestrators/step-by-step.d.ts +16 -0
  99. package/dist/runtime/orchestrators/step-by-step.js +5 -0
  100. package/dist/runtime/orchestrators/step-by-step.js.map +1 -0
  101. package/dist/runtime/orchestrators/utils.d.ts +35 -0
  102. package/dist/runtime/orchestrators/utils.js +4 -0
  103. package/dist/runtime/orchestrators/utils.js.map +1 -0
  104. package/dist/runtime/runtime.d.ts +3 -41
  105. package/dist/runtime/runtime.js +18 -8
  106. package/dist/runtime/state.d.ts +3 -21
  107. package/dist/runtime/state.js +2 -1
  108. package/dist/runtime/traverser.d.ts +3 -26
  109. package/dist/runtime/traverser.js +1 -2
  110. package/dist/runtime/types.d.ts +3 -16
  111. package/dist/runtime/types.js +1 -1
  112. package/dist/runtime/workflow-logic-handler.d.ts +17 -0
  113. package/dist/runtime/workflow-logic-handler.js +5 -0
  114. package/dist/runtime/workflow-logic-handler.js.map +1 -0
  115. package/dist/sanitizer.d.ts +3 -1
  116. package/dist/serializer.d.ts +3 -1
  117. package/dist/testing/event-logger.d.ts +63 -0
  118. package/dist/testing/event-logger.js +3 -0
  119. package/dist/testing/event-logger.js.map +1 -0
  120. package/dist/testing/index.d.ts +6 -0
  121. package/dist/testing/index.js +31 -0
  122. package/dist/testing/index.js.map +1 -0
  123. package/dist/testing/run-with-trace.d.ts +38 -0
  124. package/dist/testing/run-with-trace.js +29 -0
  125. package/dist/testing/run-with-trace.js.map +1 -0
  126. package/dist/testing/stepper.d.ts +79 -0
  127. package/dist/testing/stepper.js +11 -0
  128. package/dist/testing/stepper.js.map +1 -0
  129. package/dist/types-ezHUBdpL.d.ts +564 -0
  130. package/dist/types.d.ts +3 -1
  131. package/package.json +55 -51
  132. package/LICENSE +0 -21
  133. package/dist/chunk-5ZXV3R5D.js +0 -28
  134. package/dist/chunk-5ZXV3R5D.js.map +0 -1
  135. package/dist/chunk-GEKDR2SS.js +0 -201
  136. package/dist/chunk-GEKDR2SS.js.map +0 -1
  137. package/dist/chunk-HMR2GEGE.js +0 -3
  138. package/dist/chunk-M2FRTT2K.js +0 -144
  139. package/dist/chunk-M2FRTT2K.js.map +0 -1
  140. package/dist/chunk-OTS5YJ3S.js +0 -494
  141. package/dist/chunk-OTS5YJ3S.js.map +0 -1
  142. package/dist/chunk-QLGJUDQF.js.map +0 -1
  143. package/dist/chunk-U5V5O5MN.js.map +0 -1
  144. package/dist/chunk-VSGQDLBF.js +0 -61
  145. package/dist/chunk-VSGQDLBF.js.map +0 -1
  146. package/dist/chunk-ZCHFZBGL.js.map +0 -1
  147. package/dist/types-CsTeXTiA.d.ts +0 -222
@@ -1,494 +0,0 @@
1
- import { WorkflowState } from './chunk-VSGQDLBF.js';
2
- import { GraphTraverser } from './chunk-GEKDR2SS.js';
3
- import { sanitizeBlueprint } from './chunk-DSYAC4WB.js';
4
- import { JsonSerializer } from './chunk-CYHZ2YVH.js';
5
- import { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './chunk-M2FRTT2K.js';
6
- import { AsyncContextView } from './chunk-R3HQXIEL.js';
7
- import { CancelledWorkflowError, NodeExecutionError, FatalNodeExecutionError } from './chunk-5ZXV3R5D.js';
8
- import { PropertyEvaluator } from './chunk-PH2IYZHV.js';
9
- import { isNodeClass } from './chunk-U5V5O5MN.js';
10
- import { analyzeBlueprint } from './chunk-233SESC2.js';
11
- import { NullLogger } from './chunk-4PELJWF7.js';
12
-
13
- // src/runtime/runtime.ts
14
- var FlowRuntime = class {
15
- registry;
16
- blueprints;
17
- dependencies;
18
- logger;
19
- eventBus;
20
- serializer;
21
- middleware;
22
- evaluator;
23
- /**
24
- * Cache for blueprint analysis results to avoid recomputing for the same blueprint object.
25
- * Uses WeakMap to allow garbage collection of unused blueprints.
26
- */
27
- analysisCache;
28
- options;
29
- constructor(options) {
30
- this.registry = options.registry || {};
31
- this.blueprints = options.blueprints || {};
32
- this.dependencies = options.dependencies || {};
33
- this.logger = options.logger || new NullLogger();
34
- this.eventBus = options.eventBus || { emit: () => {
35
- } };
36
- this.serializer = options.serializer || new JsonSerializer();
37
- this.middleware = options.middleware || [];
38
- this.evaluator = options.evaluator || new PropertyEvaluator();
39
- this.analysisCache = /* @__PURE__ */ new WeakMap();
40
- this.options = options;
41
- }
42
- async run(blueprint, initialState = {}, options) {
43
- const executionId = globalThis.crypto?.randomUUID();
44
- const startTime = Date.now();
45
- const contextData = typeof initialState === "string" ? this.serializer.deserialize(initialState) : initialState;
46
- blueprint = sanitizeBlueprint(blueprint);
47
- const state = new WorkflowState(contextData);
48
- this.logger.info(`Starting workflow execution`, {
49
- blueprintId: blueprint.id,
50
- executionId
51
- });
52
- try {
53
- await this.eventBus.emit("workflow:start", {
54
- blueprintId: blueprint.id,
55
- executionId
56
- });
57
- await this.eventBus.emit("workflow:resume", {
58
- blueprintId: blueprint.id,
59
- executionId
60
- });
61
- const analysis = this.analysisCache.get(blueprint) ?? (() => {
62
- const computed = analyzeBlueprint(blueprint);
63
- this.analysisCache.set(blueprint, computed);
64
- return computed;
65
- })();
66
- if (options?.strict && !analysis.isDag) {
67
- throw new Error(`Workflow '${blueprint.id}' failed strictness check: Cycles are not allowed.`);
68
- }
69
- if (!analysis.isDag) {
70
- this.logger.warn(`Workflow contains cycles`, {
71
- blueprintId: blueprint.id
72
- });
73
- }
74
- const traverser = new GraphTraverser(
75
- blueprint,
76
- this,
77
- state,
78
- options?.functionRegistry,
79
- executionId,
80
- options?.signal,
81
- options?.concurrency
82
- );
83
- await traverser.traverse();
84
- const status = state.getStatus(traverser.getAllNodeIds(), traverser.getFallbackNodeIds());
85
- const result = state.toResult(this.serializer);
86
- result.status = status;
87
- const duration = Date.now() - startTime;
88
- if (status === "stalled") {
89
- await this.eventBus.emit("workflow:stall", {
90
- blueprintId: blueprint.id,
91
- executionId,
92
- remainingNodes: traverser.getAllNodeIds().size - state.getCompletedNodes().size
93
- });
94
- await this.eventBus.emit("workflow:pause", {
95
- blueprintId: blueprint.id,
96
- executionId
97
- });
98
- }
99
- this.logger.info(`Workflow execution completed`, {
100
- blueprintId: blueprint.id,
101
- executionId,
102
- status,
103
- duration,
104
- errors: result.errors?.length || 0
105
- });
106
- await this.eventBus.emit("workflow:finish", {
107
- blueprintId: blueprint.id,
108
- executionId,
109
- status,
110
- errors: result.errors
111
- });
112
- return result;
113
- } catch (error) {
114
- const duration = Date.now() - startTime;
115
- if (error instanceof DOMException ? error.name === "AbortError" : error instanceof CancelledWorkflowError) {
116
- this.logger.info(`Workflow execution cancelled`, {
117
- blueprintId: blueprint.id,
118
- executionId,
119
- duration
120
- });
121
- await this.eventBus.emit("workflow:pause", {
122
- blueprintId: blueprint.id,
123
- executionId
124
- });
125
- await this.eventBus.emit("workflow:finish", {
126
- blueprintId: blueprint.id,
127
- executionId,
128
- status: "cancelled",
129
- error
130
- });
131
- return {
132
- context: {},
133
- serializedContext: "{}",
134
- status: "cancelled"
135
- };
136
- }
137
- this.logger.error(`Workflow execution failed`, {
138
- blueprintId: blueprint.id,
139
- executionId,
140
- duration,
141
- error: error instanceof Error ? error.message : String(error)
142
- });
143
- throw error;
144
- }
145
- }
146
- async executeNode(blueprint, nodeId, state, allPredecessors, functionRegistry, executionId, signal) {
147
- const nodeDef = blueprint.nodes.find((n) => n.id === nodeId);
148
- if (!nodeDef) {
149
- throw new NodeExecutionError(
150
- `Node '${nodeId}' not found in blueprint.`,
151
- nodeId,
152
- blueprint.id,
153
- void 0,
154
- executionId
155
- );
156
- }
157
- const contextImpl = state.getContext();
158
- const asyncContext = contextImpl.type === "sync" ? new AsyncContextView(contextImpl) : contextImpl;
159
- const nodeContext = {
160
- context: asyncContext,
161
- input: await this._resolveNodeInput(nodeDef, asyncContext, allPredecessors),
162
- params: nodeDef.params || {},
163
- dependencies: { ...this.dependencies, logger: this.logger },
164
- signal
165
- };
166
- const beforeHooks = this.middleware.map((m) => m.beforeNode).filter((hook) => !!hook);
167
- const afterHooks = this.middleware.map((m) => m.afterNode).filter((hook) => !!hook);
168
- const aroundHooks = this.middleware.map((m) => m.aroundNode).filter((hook) => !!hook);
169
- const executor = this.getExecutor(nodeDef, functionRegistry);
170
- const coreExecution = async () => {
171
- let result;
172
- let error;
173
- try {
174
- for (const hook of beforeHooks) await hook(nodeContext.context, nodeId);
175
- result = await this.executeWithFallback(
176
- blueprint,
177
- nodeDef,
178
- nodeContext,
179
- executor,
180
- executionId,
181
- signal,
182
- state,
183
- functionRegistry
184
- );
185
- return result;
186
- } catch (e) {
187
- error = e;
188
- throw e;
189
- } finally {
190
- for (const hook of afterHooks) await hook(nodeContext.context, nodeId, result, error);
191
- }
192
- };
193
- let executionChain = coreExecution;
194
- for (let i = aroundHooks.length - 1; i >= 0; i--) {
195
- const hook = aroundHooks[i];
196
- const next = executionChain;
197
- executionChain = () => hook(nodeContext.context, nodeId, next);
198
- }
199
- try {
200
- await this.eventBus.emit("node:start", {
201
- blueprintId: blueprint.id,
202
- nodeId,
203
- executionId
204
- });
205
- const result = await executionChain();
206
- await this.eventBus.emit("node:finish", {
207
- blueprintId: blueprint.id,
208
- nodeId,
209
- result,
210
- executionId
211
- });
212
- return result;
213
- } catch (error) {
214
- await this.eventBus.emit("node:error", {
215
- blueprintId: blueprint.id,
216
- nodeId,
217
- error,
218
- executionId
219
- });
220
- if (error instanceof DOMException && error.name === "AbortError") {
221
- throw new CancelledWorkflowError("Workflow cancelled");
222
- }
223
- throw error instanceof NodeExecutionError ? error : new NodeExecutionError(`Node '${nodeId}' failed execution.`, nodeId, blueprint.id, error, executionId);
224
- }
225
- }
226
- getExecutor(nodeDef, functionRegistry) {
227
- if (nodeDef.uses.startsWith("batch-") || nodeDef.uses.startsWith("loop-") || nodeDef.uses === "subflow") {
228
- return new BuiltInNodeExecutor(
229
- (nodeDef2, context) => this._executeBuiltInNode(
230
- nodeDef2,
231
- context,
232
- functionRegistry
233
- )
234
- );
235
- }
236
- const implementation = functionRegistry?.get(nodeDef.uses) || this.registry[nodeDef.uses];
237
- if (!implementation) {
238
- throw new FatalNodeExecutionError(
239
- `Implementation for '${nodeDef.uses}' not found for node '${nodeDef.id}'.`,
240
- nodeDef.id,
241
- ""
242
- );
243
- }
244
- const maxRetries = nodeDef.config?.maxRetries ?? 1;
245
- return isNodeClass(implementation) ? new ClassNodeExecutor(implementation, maxRetries, this.eventBus) : new FunctionNodeExecutor(implementation, maxRetries, this.eventBus);
246
- }
247
- async executeWithFallback(blueprint, nodeDef, context, executor, executionId, signal, state, functionRegistry) {
248
- try {
249
- return await executor.execute(nodeDef, context, executionId, signal);
250
- } catch (error) {
251
- const isFatal = error instanceof FatalNodeExecutionError || error instanceof NodeExecutionError && error.originalError instanceof FatalNodeExecutionError;
252
- if (isFatal) throw error;
253
- const fallbackNodeId = nodeDef.config?.fallback;
254
- if (fallbackNodeId && state) {
255
- context.dependencies.logger.warn(`Executing fallback for node`, {
256
- nodeId: nodeDef.id,
257
- fallbackNodeId,
258
- error: error instanceof Error ? error.message : String(error),
259
- executionId
260
- });
261
- await this.eventBus.emit("node:fallback", {
262
- blueprintId: blueprint.id,
263
- nodeId: nodeDef.id,
264
- executionId,
265
- fallback: fallbackNodeId
266
- });
267
- const fallbackNode = blueprint.nodes.find((n) => n.id === fallbackNodeId);
268
- if (!fallbackNode) {
269
- throw new NodeExecutionError(
270
- `Fallback node '${fallbackNodeId}' not found in blueprint.`,
271
- nodeDef.id,
272
- blueprint.id,
273
- void 0,
274
- executionId
275
- );
276
- }
277
- const fallbackExecutor = this.getExecutor(fallbackNode, functionRegistry);
278
- const fallbackResult = await fallbackExecutor.execute(fallbackNode, context, executionId, signal);
279
- state.markFallbackExecuted();
280
- state.addCompletedNode(fallbackNodeId, fallbackResult.output);
281
- context.dependencies.logger.info(`Fallback execution completed`, {
282
- nodeId: nodeDef.id,
283
- fallbackNodeId,
284
- executionId
285
- });
286
- return { ...fallbackResult, _fallbackExecuted: true };
287
- }
288
- throw error;
289
- }
290
- }
291
- async determineNextNodes(blueprint, nodeId, result, context, executionId) {
292
- const outgoingEdges = blueprint.edges.filter((edge) => edge.source === nodeId);
293
- const matched = [];
294
- const evaluateEdge = async (edge) => {
295
- if (!edge.condition) return true;
296
- const contextData = context.type === "sync" ? context.toJSON() : await context.toJSON();
297
- return !!this.evaluator.evaluate(edge.condition, {
298
- ...contextData,
299
- result
300
- });
301
- };
302
- if (result.action) {
303
- const actionEdges = outgoingEdges.filter((edge) => edge.action === result.action);
304
- for (const edge of actionEdges) {
305
- if (await evaluateEdge(edge)) {
306
- const targetNode = blueprint.nodes.find((n) => n.id === edge.target);
307
- if (targetNode) matched.push({ node: targetNode, edge });
308
- } else {
309
- await this.eventBus.emit("node:skipped", {
310
- blueprintId: blueprint.id,
311
- nodeId,
312
- edge,
313
- executionId
314
- });
315
- }
316
- }
317
- }
318
- if (matched.length === 0) {
319
- const defaultEdges = outgoingEdges.filter((edge) => !edge.action);
320
- for (const edge of defaultEdges) {
321
- if (await evaluateEdge(edge)) {
322
- const targetNode = blueprint.nodes.find((n) => n.id === edge.target);
323
- if (targetNode) matched.push({ node: targetNode, edge });
324
- } else {
325
- await this.eventBus.emit("node:skipped", {
326
- blueprintId: blueprint.id,
327
- nodeId,
328
- edge,
329
- executionId
330
- });
331
- }
332
- }
333
- }
334
- this.logger.debug(`Determined next nodes for ${nodeId}`, {
335
- matchedNodes: matched.map((m) => m.node.id),
336
- action: result.action
337
- });
338
- return matched;
339
- }
340
- async applyEdgeTransform(edge, sourceResult, targetNode, context, allPredecessors) {
341
- const asyncContext = context.type === "sync" ? new AsyncContextView(context) : context;
342
- const finalInput = edge.transform ? this.evaluator.evaluate(edge.transform, {
343
- input: sourceResult.output,
344
- context: await asyncContext.toJSON()
345
- }) : sourceResult.output;
346
- const inputKey = `${targetNode.id}_input`;
347
- await asyncContext.set(inputKey, finalInput);
348
- if (targetNode.config?.joinStrategy === "any") {
349
- targetNode.inputs = inputKey;
350
- } else if (!targetNode.inputs) {
351
- const predecessors = allPredecessors?.get(targetNode.id);
352
- if (!predecessors || predecessors.size === 1) {
353
- targetNode.inputs = inputKey;
354
- }
355
- }
356
- }
357
- async _resolveNodeInput(nodeDef, context, allPredecessors) {
358
- if (nodeDef.inputs) {
359
- if (typeof nodeDef.inputs === "string") return await context.get(nodeDef.inputs);
360
- if (typeof nodeDef.inputs === "object") {
361
- const input = {};
362
- for (const key in nodeDef.inputs) {
363
- const contextKey = nodeDef.inputs[key];
364
- input[key] = await context.get(contextKey);
365
- }
366
- return input;
367
- }
368
- }
369
- if (allPredecessors) {
370
- const predecessors = allPredecessors.get(nodeDef.id);
371
- if (predecessors && predecessors.size === 1) {
372
- const singlePredecessorId = predecessors.values().next().value;
373
- return await context.get(singlePredecessorId);
374
- }
375
- }
376
- return void 0;
377
- }
378
- async _executeBuiltInNode(nodeDef, contextImpl, functionRegistry) {
379
- const context = contextImpl.type === "sync" ? new AsyncContextView(contextImpl) : contextImpl;
380
- const { params = {}, id, inputs } = nodeDef;
381
- switch (nodeDef.uses) {
382
- case "batch-scatter": {
383
- const inputArray = await context.get(inputs) || [];
384
- if (!Array.isArray(inputArray))
385
- throw new FatalNodeExecutionError(`Input for batch-scatter node '${id}' must be an array.`, id, "");
386
- const batchId = globalThis.crypto.randomUUID();
387
- const chunkSize = params.chunkSize || inputArray.length;
388
- const currentIndex = await context.get(`${id}_currentIndex`) || 0;
389
- const endIndex = Math.min(currentIndex + chunkSize, inputArray.length);
390
- const dynamicNodes = [];
391
- const workerIds = [];
392
- for (let i = currentIndex; i < endIndex; i++) {
393
- const item = inputArray[i];
394
- const itemInputKey = `${id}_${batchId}_item_${i}`;
395
- await context.set(itemInputKey, item);
396
- const workerId = `${params.workerUsesKey}_${batchId}_${i}`;
397
- workerIds.push(workerId);
398
- dynamicNodes.push({
399
- id: workerId,
400
- uses: params.workerUsesKey,
401
- inputs: itemInputKey
402
- });
403
- }
404
- await context.set(`${id}_currentIndex`, endIndex);
405
- const gatherNodeId = params.gatherNodeId;
406
- const hasMore = endIndex < inputArray.length;
407
- await context.set(`${gatherNodeId}_hasMore`, hasMore);
408
- const existingWorkerIds = await context.get(`${gatherNodeId}_allWorkerIds`) || [];
409
- const allWorkerIds = [...existingWorkerIds, ...workerIds];
410
- await context.set(`${gatherNodeId}_allWorkerIds`, allWorkerIds);
411
- return { dynamicNodes, output: { gatherNodeId, hasMore } };
412
- }
413
- case "batch-gather": {
414
- const { gatherNodeId, outputKey } = params;
415
- const hasMore = await context.get(`${gatherNodeId}_hasMore`) || false;
416
- const dynamicNodes = [];
417
- if (hasMore) {
418
- const newScatterId = `${gatherNodeId}_scatter_next`;
419
- dynamicNodes.push({
420
- id: newScatterId,
421
- uses: "batch-scatter",
422
- inputs,
423
- // use the same input as the original scatter
424
- params: { ...params, gatherNodeId }
425
- });
426
- } else {
427
- const allWorkerIds = await context.get(`${gatherNodeId}_allWorkerIds`) || [];
428
- const results = [];
429
- for (const workerId of allWorkerIds) {
430
- const result = await context.get(workerId);
431
- if (result !== void 0) results.push(result);
432
- }
433
- await context.set(outputKey, results);
434
- }
435
- return { dynamicNodes, output: {} };
436
- }
437
- case "loop-controller": {
438
- const contextData = await context.toJSON();
439
- const shouldContinue = !!this.evaluator.evaluate(params.condition, contextData);
440
- return { action: shouldContinue ? "continue" : "break" };
441
- }
442
- case "subflow": {
443
- const { blueprintId, inputs: inputMapping, outputs: outputMapping } = params;
444
- if (!blueprintId)
445
- throw new FatalNodeExecutionError(`Subflow node '${id}' is missing the 'blueprintId' parameter.`, id, "");
446
- const subBlueprint = this.blueprints[blueprintId];
447
- if (!subBlueprint)
448
- throw new FatalNodeExecutionError(
449
- `Sub-blueprint with ID '${blueprintId}' not found in runtime registry.`,
450
- id,
451
- ""
452
- );
453
- const subflowInitialContext = {};
454
- if (inputMapping) {
455
- for (const [targetKey, sourceKey] of Object.entries(inputMapping)) {
456
- if (await context.has(sourceKey)) {
457
- subflowInitialContext[targetKey] = await context.get(sourceKey);
458
- }
459
- }
460
- }
461
- const subflowResult = await this.run(subBlueprint, subflowInitialContext, {
462
- functionRegistry
463
- });
464
- if (subflowResult.status !== "completed") {
465
- const errorMessage = `Sub-workflow '${blueprintId}' did not complete successfully. Status: ${subflowResult.status}`;
466
- let originalError;
467
- if (subflowResult.errors && subflowResult.errors.length > 0) {
468
- const firstError = subflowResult.errors[0];
469
- const innerError = firstError.originalError?.originalError;
470
- const errorDetails = innerError ? `: ${innerError.message}` : "";
471
- originalError = new Error(`${firstError.message}${errorDetails} (Node: ${firstError.nodeId})`);
472
- originalError.stack = firstError.stack || originalError.stack;
473
- }
474
- throw new NodeExecutionError(errorMessage, id, subBlueprint.id, originalError);
475
- }
476
- if (outputMapping) {
477
- for (const [parentKey, subKey] of Object.entries(outputMapping)) {
478
- const subflowFinalContext = subflowResult.context;
479
- if (Object.hasOwn(subflowFinalContext, subKey)) {
480
- await context.set(parentKey, subflowFinalContext[subKey]);
481
- }
482
- }
483
- }
484
- return { output: subflowResult.context };
485
- }
486
- default:
487
- throw new FatalNodeExecutionError(`Unknown built-in node type: '${nodeDef.uses}'`, id, "");
488
- }
489
- }
490
- };
491
-
492
- export { FlowRuntime };
493
- //# sourceMappingURL=chunk-OTS5YJ3S.js.map
494
- //# sourceMappingURL=chunk-OTS5YJ3S.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/runtime/runtime.ts"],"names":["nodeDef"],"mappings":";;;;;;;;;;;;;AAsCO,IAAM,cAAN,MAEP;AAAA,EACQ,QAAA;AAAA,EACC,UAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,aAAA;AAAA,EACD,OAAA;AAAA,EAEP,YAAY,OAAA,EAAwC;AACnD,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA,CAAQ,QAAA,IAAY,EAAC;AACrC,IAAA,IAAA,CAAK,UAAA,GAAa,OAAA,CAAQ,UAAA,IAAc,EAAC;AACzC,IAAA,IAAA,CAAK,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAiB,EAAC;AAC9C,IAAA,IAAA,CAAK,MAAA,GAAS,OAAA,CAAQ,MAAA,IAAU,IAAI,UAAA,EAAW;AAC/C,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA,CAAQ,QAAA,IAAY,EAAE,MAAM,MAAM;AAAA,IAAC,CAAA,EAAE;AACrD,IAAA,IAAA,CAAK,UAAA,GAAa,OAAA,CAAQ,UAAA,IAAc,IAAI,cAAA,EAAe;AAC3D,IAAA,IAAA,CAAK,UAAA,GAAa,OAAA,CAAQ,UAAA,IAAc,EAAC;AACzC,IAAA,IAAA,CAAK,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,IAAI,iBAAA,EAAkB;AAC5D,IAAA,IAAA,CAAK,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MAAA,CAAO,mBAAA,EAAqB,MAAgB,CAAA,EAAG;AACzD,cAAA,MAAM,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAkB,mBAAA,CAAoB,MAAgB,CAAC,CAAA;AAAA,YAC1E;AAAA,UACD;AAAA,QACD;AAEA,QAAA,OAAO,EAAE,MAAA,EAAQ,aAAA,CAAc,OAAA,EAAQ;AAAA,MACxC;AAAA,MACA;AACC,QAAA,MAAM,IAAI,uBAAA,CAAwB,CAAA,6BAAA,EAAgC,QAAQ,IAAI,CAAA,CAAA,CAAA,EAAK,IAAI,EAAE,CAAA;AAAA;AAC3F,EACD;AACD","file":"chunk-OTS5YJ3S.js","sourcesContent":["import type { BlueprintAnalysis } from '../analysis'\nimport { analyzeBlueprint } from '../analysis'\nimport { AsyncContextView } from '../context'\nimport { CancelledWorkflowError, FatalNodeExecutionError, NodeExecutionError } from '../errors'\nimport { PropertyEvaluator } from '../evaluator'\nimport { NullLogger } from '../logger'\nimport type { BaseNode } from '../node'\nimport { isNodeClass } from '../node'\nimport { sanitizeBlueprint } from '../sanitizer'\nimport { JsonSerializer } from '../serializer'\nimport type {\n\tContextImplementation,\n\tEdgeDefinition,\n\tIAsyncContext,\n\tIEvaluator,\n\tIEventBus,\n\tILogger,\n\tISerializer,\n\tISyncContext,\n\tMiddleware,\n\tNodeClass,\n\tNodeContext,\n\tNodeDefinition,\n\tNodeFunction,\n\tNodeResult,\n\tRuntimeOptions,\n\tWorkflowBlueprint,\n\tWorkflowResult,\n} from '../types'\nimport type { DynamicKeys } from './builtin-keys'\nimport type { ExecutionStrategy } from './executors'\nimport { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './executors'\nimport { WorkflowState } from './state'\nimport { GraphTraverser } from './traverser'\nimport type { IRuntime } from './types'\n\ntype InternalFlowContext<TContext extends Record<string, any>> = TContext & Partial<DynamicKeys>\n\nexport class FlowRuntime<TContext extends Record<string, any>, TDependencies extends Record<string, any>>\n\timplements IRuntime<TContext, TDependencies>\n{\n\tpublic registry: Record<string, NodeFunction | NodeClass | typeof BaseNode>\n\tprivate blueprints: Record<string, WorkflowBlueprint>\n\tprivate dependencies: TDependencies\n\tprivate logger: ILogger\n\tprivate eventBus: IEventBus\n\tprivate serializer: ISerializer\n\tprivate middleware: Middleware[]\n\tprivate evaluator: IEvaluator\n\t/**\n\t * Cache for blueprint analysis results to avoid recomputing for the same blueprint object.\n\t * Uses WeakMap to allow garbage collection of unused blueprints.\n\t */\n\tprivate analysisCache: WeakMap<WorkflowBlueprint, BlueprintAnalysis>\n\tpublic options: RuntimeOptions<TDependencies>\n\n\tconstructor(options: RuntimeOptions<TDependencies>) {\n\t\tthis.registry = options.registry || {}\n\t\tthis.blueprints = options.blueprints || {}\n\t\tthis.dependencies = options.dependencies || ({} as TDependencies)\n\t\tthis.logger = options.logger || new NullLogger()\n\t\tthis.eventBus = options.eventBus || { emit: () => {} }\n\t\tthis.serializer = options.serializer || new JsonSerializer()\n\t\tthis.middleware = options.middleware || []\n\t\tthis.evaluator = options.evaluator || new PropertyEvaluator()\n\t\tthis.analysisCache = new WeakMap()\n\t\tthis.options = options\n\t}\n\n\tasync run(\n\t\tblueprint: WorkflowBlueprint,\n\t\tinitialState: Partial<TContext> | string = {},\n\t\toptions?: {\n\t\t\tfunctionRegistry?: Map<string, any>\n\t\t\tstrict?: boolean\n\t\t\tsignal?: AbortSignal\n\t\t\tconcurrency?: number\n\t\t},\n\t): Promise<WorkflowResult<TContext>> {\n\t\tconst executionId = globalThis.crypto?.randomUUID()\n\t\tconst startTime = Date.now()\n\t\tconst contextData =\n\t\t\ttypeof initialState === 'string' ? (this.serializer.deserialize(initialState) as Partial<TContext>) : initialState\n\t\tblueprint = sanitizeBlueprint(blueprint)\n\t\tconst state = new WorkflowState<TContext>(contextData)\n\n\t\tthis.logger.info(`Starting workflow execution`, {\n\t\t\tblueprintId: blueprint.id,\n\t\t\texecutionId,\n\t\t})\n\n\t\ttry {\n\t\t\tawait this.eventBus.emit('workflow:start', {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\texecutionId,\n\t\t\t})\n\t\t\tawait this.eventBus.emit('workflow:resume', {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\texecutionId,\n\t\t\t})\n\t\t\t// use cached analysis if available, otherwise compute and cache it\n\t\t\tconst analysis =\n\t\t\t\tthis.analysisCache.get(blueprint) ??\n\t\t\t\t(() => {\n\t\t\t\t\tconst computed = analyzeBlueprint(blueprint)\n\t\t\t\t\tthis.analysisCache.set(blueprint, computed)\n\t\t\t\t\treturn computed\n\t\t\t\t})()\n\t\t\tif (options?.strict && !analysis.isDag) {\n\t\t\t\tthrow new Error(`Workflow '${blueprint.id}' failed strictness check: Cycles are not allowed.`)\n\t\t\t}\n\t\t\tif (!analysis.isDag) {\n\t\t\t\tthis.logger.warn(`Workflow contains cycles`, {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t})\n\t\t\t}\n\t\t\tconst traverser = new GraphTraverser<TContext, TDependencies>(\n\t\t\t\tblueprint,\n\t\t\t\tthis,\n\t\t\t\tstate,\n\t\t\t\toptions?.functionRegistry,\n\t\t\t\texecutionId,\n\t\t\t\toptions?.signal,\n\t\t\t\toptions?.concurrency,\n\t\t\t)\n\t\t\tawait traverser.traverse()\n\t\t\tconst status = state.getStatus(traverser.getAllNodeIds(), traverser.getFallbackNodeIds())\n\t\t\tconst result = state.toResult(this.serializer)\n\t\t\tresult.status = status\n\t\t\tconst duration = Date.now() - startTime\n\t\t\tif (status === 'stalled') {\n\t\t\t\tawait this.eventBus.emit('workflow:stall', {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tremainingNodes: traverser.getAllNodeIds().size - state.getCompletedNodes().size,\n\t\t\t\t})\n\t\t\t\tawait this.eventBus.emit('workflow:pause', {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t}\n\t\t\tthis.logger.info(`Workflow execution completed`, {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\texecutionId,\n\t\t\t\tstatus,\n\t\t\t\tduration,\n\t\t\t\terrors: result.errors?.length || 0,\n\t\t\t})\n\t\t\tawait this.eventBus.emit('workflow:finish', {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\texecutionId,\n\t\t\t\tstatus,\n\t\t\t\terrors: result.errors,\n\t\t\t})\n\t\t\treturn result\n\t\t} catch (error) {\n\t\t\tconst duration = Date.now() - startTime\n\t\t\tif (error instanceof DOMException ? error.name === 'AbortError' : error instanceof CancelledWorkflowError) {\n\t\t\t\tthis.logger.info(`Workflow execution cancelled`, {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tduration,\n\t\t\t\t})\n\t\t\t\tawait this.eventBus.emit('workflow:pause', {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t\tawait this.eventBus.emit('workflow:finish', {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tstatus: 'cancelled',\n\t\t\t\t\terror,\n\t\t\t\t})\n\t\t\t\treturn {\n\t\t\t\t\tcontext: {} as TContext,\n\t\t\t\t\tserializedContext: '{}',\n\t\t\t\t\tstatus: 'cancelled',\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.logger.error(`Workflow execution failed`, {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\texecutionId,\n\t\t\t\tduration,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t})\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync executeNode(\n\t\tblueprint: WorkflowBlueprint,\n\t\tnodeId: string,\n\t\tstate: WorkflowState<TContext>,\n\t\tallPredecessors?: Map<string, Set<string>>,\n\t\tfunctionRegistry?: Map<string, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<NodeResult<any, any>> {\n\t\tconst nodeDef = blueprint.nodes.find((n) => n.id === nodeId)\n\t\tif (!nodeDef) {\n\t\t\tthrow new NodeExecutionError(\n\t\t\t\t`Node '${nodeId}' not found in blueprint.`,\n\t\t\t\tnodeId,\n\t\t\t\tblueprint.id,\n\t\t\t\tundefined,\n\t\t\t\texecutionId,\n\t\t\t)\n\t\t}\n\n\t\tconst contextImpl = state.getContext()\n\t\tconst asyncContext: IAsyncContext<TContext> =\n\t\t\tcontextImpl.type === 'sync'\n\t\t\t\t? new AsyncContextView(contextImpl as ISyncContext<TContext>)\n\t\t\t\t: (contextImpl as IAsyncContext<TContext>)\n\t\tconst nodeContext: NodeContext<TContext, TDependencies, any> = {\n\t\t\tcontext: asyncContext,\n\t\t\tinput: await this._resolveNodeInput(nodeDef, asyncContext, allPredecessors),\n\t\t\tparams: nodeDef.params || {},\n\t\t\tdependencies: { ...this.dependencies, logger: this.logger },\n\t\t\tsignal,\n\t\t}\n\n\t\tconst beforeHooks = this.middleware\n\t\t\t.map((m) => m.beforeNode)\n\t\t\t.filter((hook): hook is NonNullable<Middleware['beforeNode']> => !!hook)\n\t\tconst afterHooks = this.middleware\n\t\t\t.map((m) => m.afterNode)\n\t\t\t.filter((hook): hook is NonNullable<Middleware['afterNode']> => !!hook)\n\t\tconst aroundHooks = this.middleware\n\t\t\t.map((m) => m.aroundNode)\n\t\t\t.filter((hook): hook is NonNullable<Middleware['aroundNode']> => !!hook)\n\n\t\tconst executor = this.getExecutor(nodeDef, functionRegistry)\n\t\tconst coreExecution = async (): Promise<NodeResult> => {\n\t\t\tlet result: NodeResult | undefined\n\t\t\tlet error: Error | undefined\n\t\t\ttry {\n\t\t\t\tfor (const hook of beforeHooks) await hook(nodeContext.context, nodeId)\n\t\t\t\tresult = await this.executeWithFallback(\n\t\t\t\t\tblueprint,\n\t\t\t\t\tnodeDef,\n\t\t\t\t\tnodeContext,\n\t\t\t\t\texecutor,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tsignal,\n\t\t\t\t\tstate,\n\t\t\t\t\tfunctionRegistry,\n\t\t\t\t)\n\t\t\t\treturn result\n\t\t\t} catch (e: any) {\n\t\t\t\terror = e\n\t\t\t\tthrow e\n\t\t\t} finally {\n\t\t\t\tfor (const hook of afterHooks) await hook(nodeContext.context, nodeId, result, error)\n\t\t\t}\n\t\t}\n\n\t\tlet executionChain: () => Promise<NodeResult> = coreExecution\n\t\tfor (let i = aroundHooks.length - 1; i >= 0; i--) {\n\t\t\tconst hook = aroundHooks[i]\n\t\t\tconst next = executionChain\n\t\t\texecutionChain = () => hook(nodeContext.context, nodeId, next)\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventBus.emit('node:start', {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\tnodeId,\n\t\t\t\texecutionId,\n\t\t\t})\n\t\t\tconst result = await executionChain()\n\t\t\tawait this.eventBus.emit('node:finish', {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\tnodeId,\n\t\t\t\tresult,\n\t\t\t\texecutionId,\n\t\t\t})\n\t\t\treturn result\n\t\t} catch (error: any) {\n\t\t\tawait this.eventBus.emit('node:error', {\n\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\tnodeId,\n\t\t\t\terror,\n\t\t\t\texecutionId,\n\t\t\t})\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t}\n\t\t\tthrow error instanceof NodeExecutionError\n\t\t\t\t? error\n\t\t\t\t: new NodeExecutionError(`Node '${nodeId}' failed execution.`, nodeId, blueprint.id, error, executionId)\n\t\t}\n\t}\n\n\tprivate getExecutor(nodeDef: NodeDefinition, functionRegistry?: Map<string, any>): ExecutionStrategy {\n\t\tif (nodeDef.uses.startsWith('batch-') || nodeDef.uses.startsWith('loop-') || nodeDef.uses === 'subflow') {\n\t\t\treturn new BuiltInNodeExecutor((nodeDef, context) =>\n\t\t\t\tthis._executeBuiltInNode(\n\t\t\t\t\tnodeDef,\n\t\t\t\t\tcontext as ContextImplementation<InternalFlowContext<TContext>>,\n\t\t\t\t\tfunctionRegistry,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\tconst implementation = functionRegistry?.get(nodeDef.uses) || this.registry[nodeDef.uses]\n\t\tif (!implementation) {\n\t\t\tthrow new FatalNodeExecutionError(\n\t\t\t\t`Implementation for '${nodeDef.uses}' not found for node '${nodeDef.id}'.`,\n\t\t\t\tnodeDef.id,\n\t\t\t\t'',\n\t\t\t)\n\t\t}\n\t\tconst maxRetries = nodeDef.config?.maxRetries ?? 1\n\t\treturn isNodeClass(implementation)\n\t\t\t? new ClassNodeExecutor(implementation, maxRetries, this.eventBus)\n\t\t\t: new FunctionNodeExecutor(implementation, maxRetries, this.eventBus)\n\t}\n\n\tprivate async executeWithFallback(\n\t\tblueprint: WorkflowBlueprint,\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<TContext, TDependencies, any>,\n\t\texecutor: ExecutionStrategy,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t\tstate?: WorkflowState<TContext>,\n\t\tfunctionRegistry?: Map<string, any>,\n\t): Promise<NodeResult<any, any>> {\n\t\ttry {\n\t\t\treturn await executor.execute(nodeDef, context, executionId, signal)\n\t\t} catch (error) {\n\t\t\tconst isFatal =\n\t\t\t\terror instanceof FatalNodeExecutionError ||\n\t\t\t\t(error instanceof NodeExecutionError && error.originalError instanceof FatalNodeExecutionError)\n\t\t\tif (isFatal) throw error\n\t\t\tconst fallbackNodeId = nodeDef.config?.fallback\n\t\t\tif (fallbackNodeId && state) {\n\t\t\t\tcontext.dependencies.logger.warn(`Executing fallback for node`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tfallbackNodeId,\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t\tawait this.eventBus.emit('node:fallback', {\n\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tfallback: fallbackNodeId,\n\t\t\t\t})\n\t\t\t\tconst fallbackNode = blueprint.nodes.find((n: NodeDefinition) => n.id === fallbackNodeId)\n\t\t\t\tif (!fallbackNode) {\n\t\t\t\t\tthrow new NodeExecutionError(\n\t\t\t\t\t\t`Fallback node '${fallbackNodeId}' not found in blueprint.`,\n\t\t\t\t\t\tnodeDef.id,\n\t\t\t\t\t\tblueprint.id,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\texecutionId,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst fallbackExecutor = this.getExecutor(fallbackNode, functionRegistry)\n\t\t\t\tconst fallbackResult = await fallbackExecutor.execute(fallbackNode, context, executionId, signal)\n\t\t\t\tstate.markFallbackExecuted()\n\t\t\t\tstate.addCompletedNode(fallbackNodeId, fallbackResult.output)\n\t\t\t\tcontext.dependencies.logger.info(`Fallback execution completed`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tfallbackNodeId,\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t\treturn { ...fallbackResult, _fallbackExecuted: true }\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync determineNextNodes(\n\t\tblueprint: WorkflowBlueprint,\n\t\tnodeId: string,\n\t\tresult: NodeResult<any, any>,\n\t\tcontext: ContextImplementation<TContext>,\n\t\texecutionId?: string,\n\t): Promise<{ node: NodeDefinition; edge: EdgeDefinition }[]> {\n\t\tconst outgoingEdges = blueprint.edges.filter((edge) => edge.source === nodeId)\n\t\tconst matched: { node: NodeDefinition; edge: EdgeDefinition }[] = []\n\t\tconst evaluateEdge = async (edge: EdgeDefinition): Promise<boolean> => {\n\t\t\tif (!edge.condition) return true\n\t\t\tconst contextData = context.type === 'sync' ? context.toJSON() : await context.toJSON()\n\t\t\treturn !!this.evaluator.evaluate(edge.condition, {\n\t\t\t\t...contextData,\n\t\t\t\tresult,\n\t\t\t})\n\t\t}\n\t\tif (result.action) {\n\t\t\tconst actionEdges = outgoingEdges.filter((edge) => edge.action === result.action)\n\t\t\tfor (const edge of actionEdges) {\n\t\t\t\tif (await evaluateEdge(edge)) {\n\t\t\t\t\tconst targetNode = blueprint.nodes.find((n) => n.id === edge.target)\n\t\t\t\t\tif (targetNode) matched.push({ node: targetNode, edge })\n\t\t\t\t} else {\n\t\t\t\t\tawait this.eventBus.emit('node:skipped', {\n\t\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\t\tnodeId,\n\t\t\t\t\t\tedge,\n\t\t\t\t\t\texecutionId,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (matched.length === 0) {\n\t\t\tconst defaultEdges = outgoingEdges.filter((edge) => !edge.action)\n\t\t\tfor (const edge of defaultEdges) {\n\t\t\t\tif (await evaluateEdge(edge)) {\n\t\t\t\t\tconst targetNode = blueprint.nodes.find((n) => n.id === edge.target)\n\t\t\t\t\tif (targetNode) matched.push({ node: targetNode, edge })\n\t\t\t\t} else {\n\t\t\t\t\tawait this.eventBus.emit('node:skipped', {\n\t\t\t\t\t\tblueprintId: blueprint.id,\n\t\t\t\t\t\tnodeId,\n\t\t\t\t\t\tedge,\n\t\t\t\t\t\texecutionId,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.logger.debug(`Determined next nodes for ${nodeId}`, {\n\t\t\tmatchedNodes: matched.map((m) => m.node.id),\n\t\t\taction: result.action,\n\t\t})\n\t\treturn matched\n\t}\n\n\tpublic async applyEdgeTransform(\n\t\tedge: EdgeDefinition,\n\t\tsourceResult: NodeResult<any, any>,\n\t\ttargetNode: NodeDefinition,\n\t\tcontext: ContextImplementation<TContext>,\n\t\tallPredecessors?: Map<string, Set<string>>,\n\t): Promise<void> {\n\t\tconst asyncContext = context.type === 'sync' ? new AsyncContextView(context) : context\n\t\tconst finalInput = edge.transform\n\t\t\t? this.evaluator.evaluate(edge.transform, {\n\t\t\t\t\tinput: sourceResult.output,\n\t\t\t\t\tcontext: await asyncContext.toJSON(),\n\t\t\t\t})\n\t\t\t: sourceResult.output\n\t\tconst inputKey = `${targetNode.id}_input`\n\t\tawait asyncContext.set(inputKey as any, finalInput)\n\t\tif (targetNode.config?.joinStrategy === 'any') {\n\t\t\ttargetNode.inputs = inputKey\n\t\t} else if (!targetNode.inputs) {\n\t\t\tconst predecessors = allPredecessors?.get(targetNode.id)\n\t\t\tif (!predecessors || predecessors.size === 1) {\n\t\t\t\ttargetNode.inputs = inputKey\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async _resolveNodeInput(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: IAsyncContext<TContext>,\n\t\tallPredecessors?: Map<string, Set<string>>,\n\t): Promise<any> {\n\t\tif (nodeDef.inputs) {\n\t\t\tif (typeof nodeDef.inputs === 'string') return await context.get(nodeDef.inputs as any)\n\t\t\tif (typeof nodeDef.inputs === 'object') {\n\t\t\t\tconst input: Record<string, any> = {}\n\t\t\t\tfor (const key in nodeDef.inputs) {\n\t\t\t\t\tconst contextKey = nodeDef.inputs[key]\n\t\t\t\t\tinput[key] = await context.get(contextKey as any)\n\t\t\t\t}\n\t\t\t\treturn input\n\t\t\t}\n\t\t}\n\t\tif (allPredecessors) {\n\t\t\tconst predecessors = allPredecessors.get(nodeDef.id)\n\t\t\tif (predecessors && predecessors.size === 1) {\n\t\t\t\tconst singlePredecessorId = predecessors.values().next().value\n\t\t\t\treturn await context.get(singlePredecessorId as any)\n\t\t\t}\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprotected async _executeBuiltInNode(\n\t\tnodeDef: NodeDefinition,\n\t\tcontextImpl: ContextImplementation<InternalFlowContext<TContext>>,\n\t\tfunctionRegistry?: Map<string, any>,\n\t): Promise<NodeResult<any, any>> {\n\t\tconst context = contextImpl.type === 'sync' ? new AsyncContextView(contextImpl) : contextImpl\n\t\tconst { params = {}, id, inputs } = nodeDef\n\t\tswitch (nodeDef.uses) {\n\t\t\tcase 'batch-scatter': {\n\t\t\t\tconst inputArray = (await context.get(inputs as any)) || []\n\t\t\t\tif (!Array.isArray(inputArray))\n\t\t\t\t\tthrow new FatalNodeExecutionError(`Input for batch-scatter node '${id}' must be an array.`, id, '')\n\t\t\t\tconst batchId = globalThis.crypto.randomUUID()\n\t\t\t\tconst chunkSize = params.chunkSize || inputArray.length\n\t\t\t\tconst currentIndex = (await context.get(`${id}_currentIndex`)) || 0\n\t\t\t\tconst endIndex = Math.min(currentIndex + chunkSize, inputArray.length)\n\t\t\t\tconst dynamicNodes: NodeDefinition[] = []\n\t\t\t\tconst workerIds = []\n\t\t\t\tfor (let i = currentIndex; i < endIndex; i++) {\n\t\t\t\t\tconst item = inputArray[i]\n\t\t\t\t\tconst itemInputKey = `${id}_${batchId}_item_${i}`\n\t\t\t\t\tawait context.set(itemInputKey, item)\n\t\t\t\t\tconst workerId = `${params.workerUsesKey}_${batchId}_${i}`\n\t\t\t\t\tworkerIds.push(workerId)\n\t\t\t\t\tdynamicNodes.push({\n\t\t\t\t\t\tid: workerId,\n\t\t\t\t\t\tuses: params.workerUsesKey,\n\t\t\t\t\t\tinputs: itemInputKey,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// update current index for next chunk\n\t\t\t\tawait context.set(`${id}_currentIndex`, endIndex)\n\t\t\t\tconst gatherNodeId = params.gatherNodeId\n\t\t\t\tconst hasMore = endIndex < inputArray.length\n\t\t\t\tawait context.set(`${gatherNodeId}_hasMore`, hasMore)\n\t\t\t\t// accumulate worker ids for all chunks\n\t\t\t\tconst existingWorkerIds = (await context.get(`${gatherNodeId}_allWorkerIds`)) || []\n\t\t\t\tconst allWorkerIds = [...existingWorkerIds, ...workerIds]\n\t\t\t\tawait context.set(`${gatherNodeId}_allWorkerIds`, allWorkerIds)\n\t\t\t\treturn { dynamicNodes, output: { gatherNodeId, hasMore } }\n\t\t\t}\n\t\t\tcase 'batch-gather': {\n\t\t\t\tconst { gatherNodeId, outputKey } = params\n\t\t\t\tconst hasMore = (await context.get(`${gatherNodeId}_hasMore`)) || false\n\t\t\t\tconst dynamicNodes: NodeDefinition[] = []\n\t\t\t\tif (hasMore) {\n\t\t\t\t\t// create a new scatter node for the next chunk\n\t\t\t\t\tconst newScatterId = `${gatherNodeId}_scatter_next`\n\t\t\t\t\tdynamicNodes.push({\n\t\t\t\t\t\tid: newScatterId,\n\t\t\t\t\t\tuses: 'batch-scatter',\n\t\t\t\t\t\tinputs: inputs, // use the same input as the original scatter\n\t\t\t\t\t\tparams: { ...params, gatherNodeId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\t// collect results from all chunks into outputKey\n\t\t\t\t\tconst allWorkerIds = ((await context.get(`${gatherNodeId}_allWorkerIds`)) as string[]) || []\n\t\t\t\t\tconst results = []\n\t\t\t\t\tfor (const workerId of allWorkerIds) {\n\t\t\t\t\t\t// the output of a node is stored with the node's ID as the key.\n\t\t\t\t\t\tconst result = await context.get(workerId)\n\t\t\t\t\t\tif (result !== undefined) results.push(result)\n\t\t\t\t\t}\n\t\t\t\t\tawait context.set(outputKey as any, results)\n\t\t\t\t}\n\t\t\t\treturn { dynamicNodes, output: {} }\n\t\t\t}\n\t\t\tcase 'loop-controller': {\n\t\t\t\tconst contextData = await context.toJSON()\n\t\t\t\tconst shouldContinue = !!this.evaluator.evaluate(params.condition, contextData)\n\t\t\t\treturn { action: shouldContinue ? 'continue' : 'break' }\n\t\t\t}\n\t\t\tcase 'subflow': {\n\t\t\t\tconst { blueprintId, inputs: inputMapping, outputs: outputMapping } = params\n\t\t\t\tif (!blueprintId)\n\t\t\t\t\tthrow new FatalNodeExecutionError(`Subflow node '${id}' is missing the 'blueprintId' parameter.`, id, '')\n\n\t\t\t\tconst subBlueprint = this.blueprints[blueprintId]\n\t\t\t\tif (!subBlueprint)\n\t\t\t\t\tthrow new FatalNodeExecutionError(\n\t\t\t\t\t\t`Sub-blueprint with ID '${blueprintId}' not found in runtime registry.`,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\t'',\n\t\t\t\t\t)\n\n\t\t\t\tconst subflowInitialContext: Record<string, any> = {}\n\n\t\t\t\tif (inputMapping) {\n\t\t\t\t\tfor (const [targetKey, sourceKey] of Object.entries(inputMapping)) {\n\t\t\t\t\t\tif (await context.has(sourceKey as any)) {\n\t\t\t\t\t\t\tsubflowInitialContext[targetKey] = await context.get(sourceKey as any)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst subflowResult = await this.run(subBlueprint, subflowInitialContext as Partial<TContext>, {\n\t\t\t\t\tfunctionRegistry,\n\t\t\t\t})\n\n\t\t\t\tif (subflowResult.status !== 'completed') {\n\t\t\t\t\tconst errorMessage = `Sub-workflow '${blueprintId}' did not complete successfully. Status: ${subflowResult.status}`\n\t\t\t\t\tlet originalError: Error | undefined\n\n\t\t\t\t\tif (subflowResult.errors && subflowResult.errors.length > 0) {\n\t\t\t\t\t\tconst firstError = subflowResult.errors[0]\n\t\t\t\t\t\tconst innerError = firstError.originalError?.originalError\n\t\t\t\t\t\tconst errorDetails = innerError ? `: ${innerError.message}` : ''\n\t\t\t\t\t\toriginalError = new Error(`${firstError.message}${errorDetails} (Node: ${firstError.nodeId})`)\n\t\t\t\t\t\toriginalError.stack = firstError.stack || originalError.stack\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow new NodeExecutionError(errorMessage, id, subBlueprint.id, originalError)\n\t\t\t\t}\n\n\t\t\t\tif (outputMapping) {\n\t\t\t\t\tfor (const [parentKey, subKey] of Object.entries(outputMapping)) {\n\t\t\t\t\t\tconst subflowFinalContext = subflowResult.context as Record<string, any>\n\t\t\t\t\t\tif (Object.hasOwn(subflowFinalContext, subKey as string)) {\n\t\t\t\t\t\t\tawait context.set(parentKey as any, subflowFinalContext[subKey as string])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { output: subflowResult.context }\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new FatalNodeExecutionError(`Unknown built-in node type: '${nodeDef.uses}'`, id, '')\n\t\t}\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/runtime/adapter.ts"],"names":["nodeId"],"mappings":";;;;;AA4CO,IAAe,yBAAf,MAAsC;AAAA,EACzB,OAAA;AAAA,EACA,KAAA;AAAA,EACA,UAAA;AAAA,EAEnB,YAAY,OAAA,EAAyB;AACpC,IAAA,IAAA,CAAK,OAAA,GAAU,IAAI,WAAA,CAAY,OAAA,CAAQ,cAAc,CAAA;AACrD,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,iBAAA;AACrB,IAAA,IAAA,CAAK,UAAA,GAAa,OAAA,CAAQ,cAAA,CAAe,UAAA,IAAc,IAAI,cAAA,EAAe;AAC1E,IAAA,OAAA,CAAQ,IAAI,+CAA+C,CAAA;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA,EAKO,KAAA,GAAc;AACpB,IAAA,OAAA,CAAQ,IAAI,8BAA8B,CAAA;AAC1C,IAAA,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA,EAsCA,MAAgB,UAAA,CAAW,MAAA,EAAgB,YAAA,EAAsB,OAAA,EAAgC;AAAA,EAEjG;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,UAAU,GAAA,EAAgC;AACzD,IAAA,MAAM,EAAE,KAAA,EAAO,WAAA,EAAa,MAAA,EAAO,GAAI,GAAA;AAEvC,IAAA,MAAM,IAAA,CAAK,UAAA,CAAW,KAAA,EAAO,WAAA,EAAa,MAAM,CAAA;AAEhD,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,OAAA,CAAQ,OAAA,CAAQ,aAAa,WAAW,CAAA;AAC/D,IAAA,IAAI,CAAC,SAAA,EAAW;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A;AAAA,YACP,CAAA,uDAAA,EAA0D,SAAA,CAAU,EAAE,CAAA,6BAAA,EAAgC,YAAY,CAAA,CAAA;AAAA,WACnH;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD","file":"chunk-QLGJUDQF.js","sourcesContent":["import { analyzeBlueprint } from '../analysis'\nimport { JsonSerializer } from '../serializer'\nimport type {\n\tIAsyncContext,\n\tISerializer,\n\tNodeResult,\n\tRuntimeOptions,\n\tWorkflowBlueprint,\n\tWorkflowResult,\n} from '../types'\nimport { FlowRuntime } from './runtime'\n\n/**\n * Defines the contract for an atomic, distributed key-value store required by\n * the adapter for coordination tasks like fan-in joins and locking.\n */\nexport interface ICoordinationStore {\n\t/** Atomically increments a key and returns the new value. Ideal for 'all' joins. */\n\tincrement: (key: string, ttlSeconds: number) => Promise<number>\n\t/** Sets a key only if it does not already exist. Ideal for 'any' joins (locking). */\n\tsetIfNotExist: (key: string, value: string, ttlSeconds: number) => Promise<boolean>\n\t/** Deletes a key. Used for cleanup. */\n\tdelete: (key: string) => Promise<void>\n\t/** Gets the value of a key. */\n\tget: (key: string) => Promise<string | undefined>\n}\n\n/** Configuration options for constructing a BaseDistributedAdapter. */\nexport interface AdapterOptions {\n\truntimeOptions: RuntimeOptions<any>\n\tcoordinationStore: ICoordinationStore\n}\n\n/** The data payload expected for a job in the queue. */\nexport interface JobPayload {\n\trunId: string\n\tblueprintId: string\n\tnodeId: string\n}\n\n/**\n * The base class for all distributed adapters. It handles the technology-agnostic\n * orchestration logic and leaves queue-specific implementation to subclasses.\n */\nexport abstract class BaseDistributedAdapter {\n\tprotected readonly runtime: FlowRuntime<any, any>\n\tprotected readonly store: ICoordinationStore\n\tprotected readonly serializer: ISerializer\n\n\tconstructor(options: AdapterOptions) {\n\t\tthis.runtime = new FlowRuntime(options.runtimeOptions)\n\t\tthis.store = options.coordinationStore\n\t\tthis.serializer = options.runtimeOptions.serializer || new JsonSerializer()\n\t\tconsole.log('[Adapter] BaseDistributedAdapter initialized.')\n\t}\n\n\t/**\n\t * Starts the worker, which begins listening for and processing jobs from the queue.\n\t */\n\tpublic start(): void {\n\t\tconsole.log('[Adapter] Starting worker...')\n\t\tthis.processJobs(this.handleJob.bind(this))\n\t}\n\n\t/**\n\t * Creates a technology-specific distributed context for a given workflow run.\n\t * @param runId The unique ID for the workflow execution.\n\t */\n\tprotected abstract createContext(runId: string): IAsyncContext<Record<string, any>>\n\t/**\n\t * Sets up the listener for the message queue. The implementation should call the\n\t * provided `handler` function for each new job received.\n\t * @param handler The core logic to execute for each job.\n\t */\n\tprotected abstract processJobs(handler: (job: JobPayload) => Promise<void>): void\n\n\t/**\n\t * Enqueues a new job onto the message queue.\n\t * @param job The payload for the job to be enqueued.\n\t */\n\tprotected abstract enqueueJob(job: JobPayload): Promise<void>\n\n\t/**\n\t * Publishes the final result of a completed or failed workflow run.\n\t * @param runId The unique ID of the workflow run.\n\t * @param result The final status and payload of the workflow.\n\t */\n\tprotected abstract publishFinalResult(\n\t\trunId: string,\n\t\tresult: {\n\t\t\tstatus: 'completed' | 'failed'\n\t\t\tpayload?: WorkflowResult\n\t\t\treason?: string\n\t\t},\n\t): Promise<void>\n\n\t/**\n\t * Hook called at the start of job processing. Subclasses can override this\n\t * to perform additional setup (e.g., timestamp tracking for reconciliation).\n\t */\n\tprotected async onJobStart(_runId: string, _blueprintId: string, _nodeId: string): Promise<void> {\n\t\t// default implementation does nothing\n\t}\n\n\t/**\n\t * The main handler for processing a single job from the queue.\n\t */\n\tprotected async handleJob(job: JobPayload): Promise<void> {\n\t\tconst { runId, blueprintId, nodeId } = job\n\n\t\tawait this.onJobStart(runId, blueprintId, nodeId)\n\n\t\tconst blueprint = this.runtime.options.blueprints?.[blueprintId]\n\t\tif (!blueprint) {\n\t\t\tconst reason = `Blueprint with ID '${blueprintId}' not found in the worker's runtime registry.`\n\t\t\tconsole.error(`[Adapter] FATAL: ${reason}`)\n\t\t\tawait this.publishFinalResult(runId, { status: 'failed', reason })\n\t\t\treturn\n\t\t}\n\n\t\tconst context = this.createContext(runId)\n\n\t\t// persist the blueprintId for the reconcile method to find later\n\t\tconst hasBlueprintId = await context.has('blueprintId' as any)\n\t\tif (!hasBlueprintId) {\n\t\t\tawait context.set('blueprintId' as any, blueprintId)\n\t\t\t// also store in coordination store as fallback\n\t\t\tconst blueprintKey = `flowcraft:blueprint:${runId}`\n\t\t\tawait this.store.setIfNotExist(blueprintKey, blueprintId, 3600)\n\t\t}\n\t\tconst workerState = {\n\t\t\tgetContext: () => context,\n\t\t\tmarkFallbackExecuted: () => {},\n\t\t\taddError: (nodeId: string, error: Error) => {\n\t\t\t\tconsole.error(`[Adapter] Error in node ${nodeId}:`, error)\n\t\t\t},\n\t\t} as any\n\n\t\ttry {\n\t\t\tconst result: NodeResult<any, any> = await this.runtime.executeNode(blueprint, nodeId, workerState)\n\t\t\tawait context.set(nodeId as any, result.output)\n\n\t\t\tconst analysis = analyzeBlueprint(blueprint)\n\t\t\tconst isTerminalNode = analysis.terminalNodeIds.includes(nodeId)\n\n\t\t\tif (isTerminalNode) {\n\t\t\t\tconst completedNodes = new Set(\n\t\t\t\t\tObject.keys(await context.toJSON()).filter((k) => blueprint.nodes.some((n) => n.id === k)),\n\t\t\t\t)\n\t\t\t\tconst allTerminalNodesCompleted = analysis.terminalNodeIds.every((terminalId) => completedNodes.has(terminalId))\n\n\t\t\t\tif (allTerminalNodesCompleted) {\n\t\t\t\t\tconsole.log(`[Adapter] ✅ All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`)\n\t\t\t\t\tconst finalContext = await context.toJSON()\n\t\t\t\t\tconst finalResult: WorkflowResult = {\n\t\t\t\t\t\tcontext: finalContext,\n\t\t\t\t\t\tserializedContext: this.serializer.serialize(finalContext),\n\t\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\t}\n\t\t\t\t\tawait this.publishFinalResult(runId, {\n\t\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\t\tpayload: finalResult,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`[Adapter] Terminal node '${nodeId}' completed for Run ID '${runId}', but other terminal nodes are still running.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst nextNodes = await this.runtime.determineNextNodes(blueprint, nodeId, result, context, runId)\n\n\t\t\t// stop if a branch terminates but it wasn't a terminal node\n\t\t\tif (nextNodes.length === 0 && !isTerminalNode) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Adapter] Non-terminal node '${nodeId}' reached end of branch for Run ID '${runId}'. This branch will now terminate.`,\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfor (const { node: nextNodeDef, edge } of nextNodes) {\n\t\t\t\tawait this.runtime.applyEdgeTransform(edge, result, nextNodeDef, context)\n\t\t\t\tconst isReady = await this.isReadyForFanIn(runId, blueprint, nextNodeDef.id)\n\t\t\t\tif (isReady) {\n\t\t\t\t\tconsole.log(`[Adapter] Node '${nextNodeDef.id}' is ready. Enqueuing job.`)\n\t\t\t\t\tawait this.enqueueJob({ runId, blueprintId, nodeId: nextNodeDef.id })\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(`[Adapter] Node '${nextNodeDef.id}' is waiting for other predecessors to complete.`)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error: any) {\n\t\t\tconst reason = error.message || 'Unknown execution error'\n\t\t\tconsole.error(`[Adapter] FATAL: Job for node '${nodeId}' failed for Run ID '${runId}': ${reason}`)\n\t\t\tawait this.publishFinalResult(runId, { status: 'failed', reason })\n\t\t\tawait this.writePoisonPillForSuccessors(runId, blueprint, nodeId)\n\t\t}\n\t}\n\n\t/**\n\t * Encapsulates the fan-in join logic using the coordination store.\n\t */\n\tprotected async isReadyForFanIn(runId: string, blueprint: WorkflowBlueprint, targetNodeId: string): Promise<boolean> {\n\t\tconst targetNode = blueprint.nodes.find((n) => n.id === targetNodeId)\n\t\tif (!targetNode) {\n\t\t\tthrow new Error(`Node '${targetNodeId}' not found in blueprint`)\n\t\t}\n\t\tconst joinStrategy = targetNode.config?.joinStrategy || 'all'\n\t\tconst predecessors = blueprint.edges.filter((e) => e.target === targetNodeId)\n\n\t\tif (predecessors.length <= 1) {\n\t\t\treturn true\n\t\t}\n\n\t\tconst poisonKey = `flowcraft:fanin:poison:${runId}:${targetNodeId}`\n\t\tconst isPoisoned = !(await this.store.setIfNotExist(poisonKey, 'poisoned', 3600))\n\t\tif (isPoisoned) {\n\t\t\tconsole.log(`[Adapter] Node '${targetNodeId}' is poisoned due to failed predecessor. Failing immediately.`)\n\t\t\tthrow new Error(`Node '${targetNodeId}' failed due to poisoned predecessor in run '${runId}'`)\n\t\t}\n\n\t\tif (joinStrategy === 'any') {\n\t\t\tconst lockKey = `flowcraft:joinlock:${runId}:${targetNodeId}`\n\t\t\tconst isLocked = await this.store.setIfNotExist(lockKey, 'locked', 3600)\n\t\t\tif (!isLocked) {\n\t\t\t\t// Check if it's cancelled\n\t\t\t\tconst cancelKey = `flowcraft:fanin:cancel:${runId}:${targetNodeId}`\n\t\t\t\tconst isCancelled = !(await this.store.setIfNotExist(cancelKey, 'cancelled', 3600))\n\t\t\t\tif (isCancelled) {\n\t\t\t\t\tconsole.log(`[Adapter] Node '${targetNodeId}' is cancelled due to failed predecessor. Failing immediately.`)\n\t\t\t\t\tthrow new Error(`Node '${targetNodeId}' failed due to cancelled predecessor in run '${runId}'`)\n\t\t\t\t}\n\t\t\t\treturn false // Already locked by another predecessor\n\t\t\t}\n\t\t\treturn true\n\t\t} else {\n\t\t\tconst fanInKey = `flowcraft:fanin:${runId}:${targetNodeId}`\n\t\t\tconst readyCount = await this.store.increment(fanInKey, 3600)\n\t\t\tif (readyCount >= predecessors.length) {\n\t\t\t\tawait this.store.delete(fanInKey)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t}\n\n\t/**\n\t * Reconciles the state of a workflow run. It inspects the persisted\n\t * context to find completed nodes, determines the next set of executable\n\t * nodes (the frontier), and enqueues jobs for them if they aren't\n\t * already running. This is the core of the resume functionality.\n\t *\n\t * @param runId The unique ID of the workflow execution to reconcile.\n\t * @returns The set of node IDs that were enqueued for execution.\n\t */\n\tpublic async reconcile(runId: string): Promise<Set<string>> {\n\t\tconst context = this.createContext(runId)\n\t\tlet blueprintId = (await context.get('blueprintId' as any)) as string | undefined\n\n\t\tif (!blueprintId) {\n\t\t\t// fallback to coordination store\n\t\t\tconst blueprintKey = `flowcraft:blueprint:${runId}`\n\t\t\tblueprintId = await this.store.get(blueprintKey)\n\t\t\tif (blueprintId) {\n\t\t\t\t// set it back in context for future use\n\t\t\t\tawait context.set('blueprintId' as any, blueprintId)\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Cannot reconcile runId '${runId}': blueprintId not found in context or coordination store.`)\n\t\t\t}\n\t\t}\n\t\tconst blueprint = this.runtime.options.blueprints?.[blueprintId]\n\t\tif (!blueprint) {\n\t\t\tthrow new Error(`Cannot reconcile runId '${runId}': Blueprint with ID '${blueprintId}' not found.`)\n\t\t}\n\n\t\tconst state = await context.toJSON()\n\t\t// filter out internal keys\n\t\tconst completedNodes = new Set(Object.keys(state).filter((k) => blueprint.nodes.some((n) => n.id === k)))\n\n\t\tconst frontier = this.calculateResumedFrontier(blueprint, completedNodes)\n\n\t\tconst enqueuedNodes = new Set<string>()\n\t\tfor (const nodeId of frontier) {\n\t\t\tconst nodeDef = blueprint.nodes.find((n) => n.id === nodeId)\n\t\t\tconst joinStrategy = nodeDef?.config?.joinStrategy || 'all'\n\n\t\t\tlet shouldEnqueue = false\n\n\t\t\tif (joinStrategy === 'any') {\n\t\t\t\t// acquire the permanent join lock\n\t\t\t\tconst lockKey = `flowcraft:joinlock:${runId}:${nodeId}`\n\t\t\t\tif (await this.store.setIfNotExist(lockKey, 'locked-by-reconcile', 3600)) {\n\t\t\t\t\tshouldEnqueue = true\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(`[Adapter] Reconciling: Node '${nodeId}' is an 'any' join and is already locked.`, { runId })\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// 'all' joins and single-predecessor nodes use a temporary lock\n\t\t\t\tconst lockKey = `flowcraft:nodelock:${runId}:${nodeId}`\n\t\t\t\tif (await this.store.setIfNotExist(lockKey, 'locked', 120)) {\n\t\t\t\t\tshouldEnqueue = true\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(`[Adapter] Reconciling: Node '${nodeId}' is already locked.`, { runId })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (shouldEnqueue) {\n\t\t\t\tconsole.log(`[Adapter] Reconciling: Enqueuing ready job for node '${nodeId}'`, { runId })\n\t\t\t\tawait this.enqueueJob({ runId, blueprintId: blueprint.id, nodeId })\n\t\t\t\tenqueuedNodes.add(nodeId)\n\t\t\t}\n\t\t}\n\n\t\treturn enqueuedNodes\n\t}\n\n\tprivate calculateResumedFrontier(blueprint: WorkflowBlueprint, completedNodes: Set<string>): Set<string> {\n\t\tconst newFrontier = new Set<string>()\n\t\tconst allPredecessors = new Map<string, Set<string>>()\n\t\t// (logic extracted from the GraphTraverser)\n\t\tfor (const node of blueprint.nodes) {\n\t\t\tallPredecessors.set(node.id, new Set())\n\t\t}\n\t\tfor (const edge of blueprint.edges) {\n\t\t\tallPredecessors.get(edge.target)?.add(edge.source)\n\t\t}\n\n\t\tfor (const node of blueprint.nodes) {\n\t\t\tif (completedNodes.has(node.id)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst predecessors = allPredecessors.get(node.id) ?? new Set()\n\t\t\tif (predecessors.size === 0 && !completedNodes.has(node.id)) {\n\t\t\t\tnewFrontier.add(node.id)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst joinStrategy = node.config?.joinStrategy || 'all'\n\t\t\tconst completedPredecessors = [...predecessors].filter((p) => completedNodes.has(p))\n\n\t\t\tconst isReady =\n\t\t\t\tjoinStrategy === 'any' ? completedPredecessors.length > 0 : completedPredecessors.length === predecessors.size\n\n\t\t\tif (isReady) {\n\t\t\t\tnewFrontier.add(node.id)\n\t\t\t}\n\t\t}\n\t\treturn newFrontier\n\t}\n\n\t/**\n\t * Writes a poison pill for 'all' join successors and a cancellation pill for 'any' join successors of a failed node to prevent stalling or ambiguous states.\n\t */\n\tprivate async writePoisonPillForSuccessors(\n\t\trunId: string,\n\t\tblueprint: WorkflowBlueprint,\n\t\tfailedNodeId: string,\n\t): Promise<void> {\n\t\tconst successors = blueprint.edges\n\t\t\t.filter((edge) => edge.source === failedNodeId)\n\t\t\t.map((edge) => edge.target)\n\t\t\t.map((targetId) => blueprint.nodes.find((node) => node.id === targetId))\n\t\t\t.filter((node) => node)\n\n\t\tfor (const successor of successors) {\n\t\t\tif (successor) {\n\t\t\t\tconst joinStrategy = successor.config?.joinStrategy || 'all'\n\t\t\t\tif (joinStrategy === 'all') {\n\t\t\t\t\tconst poisonKey = `flowcraft:fanin:poison:${runId}:${successor.id}`\n\t\t\t\t\tawait this.store.setIfNotExist(poisonKey, 'poisoned', 3600)\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`[Adapter] Wrote poison pill for 'all' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`,\n\t\t\t\t\t)\n\t\t\t\t} else if (joinStrategy === 'any') {\n\t\t\t\t\tconst cancelKey = `flowcraft:fanin:cancel:${runId}:${successor.id}`\n\t\t\t\t\tawait this.store.setIfNotExist(cancelKey, 'cancelled', 3600)\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`[Adapter] Wrote cancellation pill for 'any' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/node.ts"],"names":[],"mappings":";AAGO,SAAS,YAAY,IAAA,EAA8B;AACzD,EAAA,OAAO,OAAO,IAAA,KAAS,UAAA,IAAc,CAAC,CAAC,KAAK,SAAA,EAAW,IAAA;AACxD;AAOO,IAAe,WAAf,MAML;AAAA;AAAA;AAAA;AAAA,EAID,YAAsB,MAAA,EAA8B;AAA9B,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOrD,MAAM,KAAK,OAAA,EAAqE;AAC/E,IAAA,OAAO,OAAA,CAAQ,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAM,IAAA,CACL,UAAA,EACA,QAAA,EACwC;AACxC,IAAA,OAAO,UAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,QAAA,CACL,KAAA,EACA,QAAA,EACuD;AAEvD,IAAA,MAAM,KAAA;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OAAA,CAAQ,MAAA,EAAe,QAAA,EAAuE;AAAA,EAEpG;AACD","file":"chunk-U5V5O5MN.js","sourcesContent":["import type { NodeClass, NodeContext, NodeResult, RuntimeDependencies } from './types'\n\n/** A type guard to reliably distinguish a NodeClass from a NodeFunction. */\nexport function isNodeClass(impl: any): impl is NodeClass {\n\treturn typeof impl === 'function' && !!impl.prototype?.exec\n}\n\n/**\n * A structured, class-based node for complex logic with a safe, granular lifecycle.\n * This class is generic, allowing implementations to specify the exact context\n * and dependency types they expect.\n */\nexport abstract class BaseNode<\n\tTContext extends Record<string, any> = Record<string, any>,\n\tTDependencies extends RuntimeDependencies = RuntimeDependencies,\n\tTInput = any,\n\tTOutput = any,\n\tTAction extends string = string,\n> {\n\t/**\n\t * @param params Static parameters for this node instance, passed from the blueprint.\n\t */\n\tconstructor(protected params?: Record<string, any>) {}\n\n\t/**\n\t * Phase 1: Gathers and prepares data for execution. This phase is NOT retried on failure.\n\t * @param context The node's execution context.\n\t * @returns The data needed for the `exec` phase.\n\t */\n\tasync prep(context: NodeContext<TContext, TDependencies, TInput>): Promise<any> {\n\t\treturn context.input\n\t}\n\n\t/**\n\t * Phase 2: Performs the core, isolated logic. This is the ONLY phase that is retried.\n\t * @param prepResult The data returned from the `prep` phase.\n\t * @param context The node's execution context.\n\t */\n\tabstract exec(\n\t\tprepResult: any,\n\t\tcontext: NodeContext<TContext, TDependencies, TInput>,\n\t): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>\n\n\t/**\n\t * Phase 3: Processes the result and saves state. This phase is NOT retried.\n\t * @param execResult The successful result from the `exec` or `fallback` phase.\n\t * @param _context The node's execution context.\n\t */\n\tasync post(\n\t\texecResult: Omit<NodeResult<TOutput, TAction>, 'error'>,\n\t\t_context: NodeContext<TContext, TDependencies, TInput>,\n\t): Promise<NodeResult<TOutput, TAction>> {\n\t\treturn execResult\n\t}\n\n\t/**\n\t * An optional safety net that runs if all `exec` retries fail.\n\t * @param error The final error from the last `exec` attempt.\n\t * @param _context The node's execution context.\n\t */\n\tasync fallback(\n\t\terror: Error,\n\t\t_context: NodeContext<TContext, TDependencies, TInput>,\n\t): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>> {\n\t\t// By default, re-throw the error, failing the node.\n\t\tthrow error\n\t}\n\n\t/**\n\t * An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.\n\t * This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.\n\t * Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.\n\t * @param _error The error that caused the failure.\n\t * @param _context The node's execution context.\n\t */\n\tasync recover(_error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<void> {\n\t\t// Default no-op implementation. Subclasses can override for cleanup.\n\t}\n}\n"]}