flowcraft 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -6
- package/dist/analysis.d.ts +3 -2
- package/dist/analysis.js +1 -1
- package/dist/{chunk-HN72TZY5.js → chunk-233SESC2.js} +34 -23
- package/dist/chunk-233SESC2.js.map +1 -0
- package/dist/{chunk-UETC63DP.js → chunk-EUJWJWFA.js} +24 -4
- package/dist/chunk-EUJWJWFA.js.map +1 -0
- package/dist/{chunk-UMXW3TCY.js → chunk-GEKDR2SS.js} +44 -8
- package/dist/chunk-GEKDR2SS.js.map +1 -0
- package/dist/chunk-M2FRTT2K.js +144 -0
- package/dist/chunk-M2FRTT2K.js.map +1 -0
- package/dist/{chunk-CO5BTPKI.js → chunk-OTS5YJ3S.js} +108 -24
- package/dist/chunk-OTS5YJ3S.js.map +1 -0
- package/dist/{chunk-5EHIPX23.js → chunk-QLGJUDQF.js} +84 -23
- package/dist/chunk-QLGJUDQF.js.map +1 -0
- package/dist/{chunk-KWQHFT7E.js → chunk-R3HQXIEL.js} +6 -6
- package/dist/chunk-R3HQXIEL.js.map +1 -0
- package/dist/{chunk-5QMPFUKA.js → chunk-U5V5O5MN.js} +11 -2
- package/dist/chunk-U5V5O5MN.js.map +1 -0
- package/dist/{chunk-CSZ6EOWG.js → chunk-VSGQDLBF.js} +3 -3
- package/dist/chunk-VSGQDLBF.js.map +1 -0
- package/dist/{chunk-5ZWYSKMH.js → chunk-ZCHFZBGL.js} +25 -8
- package/dist/chunk-ZCHFZBGL.js.map +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -1
- package/dist/evaluator.d.ts +1 -1
- package/dist/flow.d.ts +19 -8
- package/dist/flow.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -10
- package/dist/linter.d.ts +3 -3
- package/dist/linter.js +2 -2
- package/dist/logger.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/runtime/adapter.d.ts +8 -1
- package/dist/runtime/adapter.js +8 -8
- package/dist/runtime/builtin-keys.d.ts +38 -0
- package/dist/runtime/builtin-keys.js +10 -0
- package/dist/runtime/builtin-keys.js.map +1 -0
- package/dist/runtime/executors.d.ts +1 -1
- package/dist/runtime/executors.js +1 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.js +8 -8
- package/dist/runtime/runtime.d.ts +11 -4
- package/dist/runtime/runtime.js +7 -7
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/traverser.d.ts +2 -1
- package/dist/runtime/traverser.js +2 -2
- package/dist/runtime/types.d.ts +3 -2
- package/dist/sanitizer.d.ts +1 -1
- package/dist/serializer.d.ts +1 -1
- package/dist/{types-lG3xCzp_.d.ts → types-CsTeXTiA.d.ts} +24 -8
- package/dist/types.d.ts +1 -1
- package/package.json +51 -51
- package/dist/chunk-5EHIPX23.js.map +0 -1
- package/dist/chunk-5QMPFUKA.js.map +0 -1
- package/dist/chunk-5ZWYSKMH.js.map +0 -1
- package/dist/chunk-CO5BTPKI.js.map +0 -1
- package/dist/chunk-CSZ6EOWG.js.map +0 -1
- package/dist/chunk-HN72TZY5.js.map +0 -1
- package/dist/chunk-KWQHFT7E.js.map +0 -1
- package/dist/chunk-QRMUKDSP.js +0 -141
- package/dist/chunk-QRMUKDSP.js.map +0 -1
- package/dist/chunk-UETC63DP.js.map +0 -1
- package/dist/chunk-UMXW3TCY.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { WorkflowState } from './chunk-
|
|
2
|
-
import { GraphTraverser } from './chunk-
|
|
1
|
+
import { WorkflowState } from './chunk-VSGQDLBF.js';
|
|
2
|
+
import { GraphTraverser } from './chunk-GEKDR2SS.js';
|
|
3
3
|
import { sanitizeBlueprint } from './chunk-DSYAC4WB.js';
|
|
4
4
|
import { JsonSerializer } from './chunk-CYHZ2YVH.js';
|
|
5
|
-
import { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './chunk-
|
|
6
|
-
import { AsyncContextView } from './chunk-
|
|
5
|
+
import { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './chunk-M2FRTT2K.js';
|
|
6
|
+
import { AsyncContextView } from './chunk-R3HQXIEL.js';
|
|
7
7
|
import { CancelledWorkflowError, NodeExecutionError, FatalNodeExecutionError } from './chunk-5ZXV3R5D.js';
|
|
8
8
|
import { PropertyEvaluator } from './chunk-PH2IYZHV.js';
|
|
9
|
-
import { isNodeClass } from './chunk-
|
|
10
|
-
import { analyzeBlueprint } from './chunk-
|
|
9
|
+
import { isNodeClass } from './chunk-U5V5O5MN.js';
|
|
10
|
+
import { analyzeBlueprint } from './chunk-233SESC2.js';
|
|
11
11
|
import { NullLogger } from './chunk-4PELJWF7.js';
|
|
12
12
|
|
|
13
13
|
// src/runtime/runtime.ts
|
|
@@ -20,6 +20,11 @@ var FlowRuntime = class {
|
|
|
20
20
|
serializer;
|
|
21
21
|
middleware;
|
|
22
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;
|
|
23
28
|
options;
|
|
24
29
|
constructor(options) {
|
|
25
30
|
this.registry = options.registry || {};
|
|
@@ -31,6 +36,7 @@ var FlowRuntime = class {
|
|
|
31
36
|
this.serializer = options.serializer || new JsonSerializer();
|
|
32
37
|
this.middleware = options.middleware || [];
|
|
33
38
|
this.evaluator = options.evaluator || new PropertyEvaluator();
|
|
39
|
+
this.analysisCache = /* @__PURE__ */ new WeakMap();
|
|
34
40
|
this.options = options;
|
|
35
41
|
}
|
|
36
42
|
async run(blueprint, initialState = {}, options) {
|
|
@@ -48,7 +54,15 @@ var FlowRuntime = class {
|
|
|
48
54
|
blueprintId: blueprint.id,
|
|
49
55
|
executionId
|
|
50
56
|
});
|
|
51
|
-
|
|
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
|
+
})();
|
|
52
66
|
if (options?.strict && !analysis.isDag) {
|
|
53
67
|
throw new Error(`Workflow '${blueprint.id}' failed strictness check: Cycles are not allowed.`);
|
|
54
68
|
}
|
|
@@ -77,6 +91,10 @@ var FlowRuntime = class {
|
|
|
77
91
|
executionId,
|
|
78
92
|
remainingNodes: traverser.getAllNodeIds().size - state.getCompletedNodes().size
|
|
79
93
|
});
|
|
94
|
+
await this.eventBus.emit("workflow:pause", {
|
|
95
|
+
blueprintId: blueprint.id,
|
|
96
|
+
executionId
|
|
97
|
+
});
|
|
80
98
|
}
|
|
81
99
|
this.logger.info(`Workflow execution completed`, {
|
|
82
100
|
blueprintId: blueprint.id,
|
|
@@ -100,6 +118,10 @@ var FlowRuntime = class {
|
|
|
100
118
|
executionId,
|
|
101
119
|
duration
|
|
102
120
|
});
|
|
121
|
+
await this.eventBus.emit("workflow:pause", {
|
|
122
|
+
blueprintId: blueprint.id,
|
|
123
|
+
executionId
|
|
124
|
+
});
|
|
103
125
|
await this.eventBus.emit("workflow:finish", {
|
|
104
126
|
blueprintId: blueprint.id,
|
|
105
127
|
executionId,
|
|
@@ -203,7 +225,13 @@ var FlowRuntime = class {
|
|
|
203
225
|
}
|
|
204
226
|
getExecutor(nodeDef, functionRegistry) {
|
|
205
227
|
if (nodeDef.uses.startsWith("batch-") || nodeDef.uses.startsWith("loop-") || nodeDef.uses === "subflow") {
|
|
206
|
-
return new BuiltInNodeExecutor(
|
|
228
|
+
return new BuiltInNodeExecutor(
|
|
229
|
+
(nodeDef2, context) => this._executeBuiltInNode(
|
|
230
|
+
nodeDef2,
|
|
231
|
+
context,
|
|
232
|
+
functionRegistry
|
|
233
|
+
)
|
|
234
|
+
);
|
|
207
235
|
}
|
|
208
236
|
const implementation = functionRegistry?.get(nodeDef.uses) || this.registry[nodeDef.uses];
|
|
209
237
|
if (!implementation) {
|
|
@@ -260,7 +288,7 @@ var FlowRuntime = class {
|
|
|
260
288
|
throw error;
|
|
261
289
|
}
|
|
262
290
|
}
|
|
263
|
-
async determineNextNodes(blueprint, nodeId, result, context) {
|
|
291
|
+
async determineNextNodes(blueprint, nodeId, result, context, executionId) {
|
|
264
292
|
const outgoingEdges = blueprint.edges.filter((edge) => edge.source === nodeId);
|
|
265
293
|
const matched = [];
|
|
266
294
|
const evaluateEdge = async (edge) => {
|
|
@@ -277,6 +305,13 @@ var FlowRuntime = class {
|
|
|
277
305
|
if (await evaluateEdge(edge)) {
|
|
278
306
|
const targetNode = blueprint.nodes.find((n) => n.id === edge.target);
|
|
279
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
|
+
});
|
|
280
315
|
}
|
|
281
316
|
}
|
|
282
317
|
}
|
|
@@ -286,6 +321,13 @@ var FlowRuntime = class {
|
|
|
286
321
|
if (await evaluateEdge(edge)) {
|
|
287
322
|
const targetNode = blueprint.nodes.find((n) => n.id === edge.target);
|
|
288
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
|
+
});
|
|
289
331
|
}
|
|
290
332
|
}
|
|
291
333
|
}
|
|
@@ -333,30 +375,64 @@ var FlowRuntime = class {
|
|
|
333
375
|
}
|
|
334
376
|
return void 0;
|
|
335
377
|
}
|
|
336
|
-
async _executeBuiltInNode(nodeDef, contextImpl) {
|
|
378
|
+
async _executeBuiltInNode(nodeDef, contextImpl, functionRegistry) {
|
|
337
379
|
const context = contextImpl.type === "sync" ? new AsyncContextView(contextImpl) : contextImpl;
|
|
338
380
|
const { params = {}, id, inputs } = nodeDef;
|
|
339
381
|
switch (nodeDef.uses) {
|
|
340
382
|
case "batch-scatter": {
|
|
341
383
|
const inputArray = await context.get(inputs) || [];
|
|
342
|
-
if (!Array.isArray(inputArray))
|
|
384
|
+
if (!Array.isArray(inputArray))
|
|
385
|
+
throw new FatalNodeExecutionError(`Input for batch-scatter node '${id}' must be an array.`, id, "");
|
|
343
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);
|
|
344
390
|
const dynamicNodes = [];
|
|
345
|
-
|
|
391
|
+
const workerIds = [];
|
|
392
|
+
for (let i = currentIndex; i < endIndex; i++) {
|
|
346
393
|
const item = inputArray[i];
|
|
347
394
|
const itemInputKey = `${id}_${batchId}_item_${i}`;
|
|
348
395
|
await context.set(itemInputKey, item);
|
|
396
|
+
const workerId = `${params.workerUsesKey}_${batchId}_${i}`;
|
|
397
|
+
workerIds.push(workerId);
|
|
349
398
|
dynamicNodes.push({
|
|
350
|
-
id:
|
|
399
|
+
id: workerId,
|
|
351
400
|
uses: params.workerUsesKey,
|
|
352
401
|
inputs: itemInputKey
|
|
353
402
|
});
|
|
354
403
|
}
|
|
404
|
+
await context.set(`${id}_currentIndex`, endIndex);
|
|
355
405
|
const gatherNodeId = params.gatherNodeId;
|
|
356
|
-
|
|
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 } };
|
|
357
412
|
}
|
|
358
413
|
case "batch-gather": {
|
|
359
|
-
|
|
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: {} };
|
|
360
436
|
}
|
|
361
437
|
case "loop-controller": {
|
|
362
438
|
const contextData = await context.toJSON();
|
|
@@ -382,13 +458,21 @@ var FlowRuntime = class {
|
|
|
382
458
|
}
|
|
383
459
|
}
|
|
384
460
|
}
|
|
385
|
-
const subflowResult = await this.run(subBlueprint, subflowInitialContext
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
)
|
|
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
|
+
}
|
|
392
476
|
if (outputMapping) {
|
|
393
477
|
for (const [parentKey, subKey] of Object.entries(outputMapping)) {
|
|
394
478
|
const subflowFinalContext = subflowResult.context;
|
|
@@ -406,5 +490,5 @@ var FlowRuntime = class {
|
|
|
406
490
|
};
|
|
407
491
|
|
|
408
492
|
export { FlowRuntime };
|
|
409
|
-
//# sourceMappingURL=chunk-
|
|
410
|
-
//# sourceMappingURL=chunk-
|
|
493
|
+
//# sourceMappingURL=chunk-OTS5YJ3S.js.map
|
|
494
|
+
//# sourceMappingURL=chunk-OTS5YJ3S.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,IAA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CAAA,GAAK,EAAA;AAC9D,YAAA,aAAA,GAAgB,IAAI,KAAA,CAAM,CAAA,EAAG,UAAA,CAAW,OAAO,GAAG,YAAY,CAAA,QAAA,EAAW,UAAA,CAAW,MAAM,CAAA,CAAA,CAAG,CAAA;AAC7F,YAAA,aAAA,CAAc,KAAA,GAAQ,UAAA,CAAW,KAAA,IAAS,aAAA,CAAc,KAAA;AAAA,UACzD;AAEA,UAAA,MAAM,IAAI,kBAAA,CAAmB,YAAA,EAAc,EAAA,EAAI,YAAA,CAAa,IAAI,aAAa,CAAA;AAAA,QAC9E;AAEA,QAAA,IAAI,aAAA,EAAe;AAClB,UAAA,KAAA,MAAW,CAAC,SAAA,EAAW,MAAM,KAAK,MAAA,CAAO,OAAA,CAAQ,aAAa,CAAA,EAAG;AAChE,YAAA,MAAM,sBAAsB,aAAA,CAAc,OAAA;AAC1C,YAAA,IAAI,MAAA,CAAO,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,5 +1,6 @@
|
|
|
1
|
-
import { FlowRuntime } from './chunk-
|
|
1
|
+
import { FlowRuntime } from './chunk-OTS5YJ3S.js';
|
|
2
2
|
import { JsonSerializer } from './chunk-CYHZ2YVH.js';
|
|
3
|
+
import { analyzeBlueprint } from './chunk-233SESC2.js';
|
|
3
4
|
|
|
4
5
|
// src/runtime/adapter.ts
|
|
5
6
|
var BaseDistributedAdapter = class {
|
|
@@ -42,6 +43,8 @@ var BaseDistributedAdapter = class {
|
|
|
42
43
|
const hasBlueprintId = await context.has("blueprintId");
|
|
43
44
|
if (!hasBlueprintId) {
|
|
44
45
|
await context.set("blueprintId", blueprintId);
|
|
46
|
+
const blueprintKey = `flowcraft:blueprint:${runId}`;
|
|
47
|
+
await this.store.setIfNotExist(blueprintKey, blueprintId, 3600);
|
|
45
48
|
}
|
|
46
49
|
const workerState = {
|
|
47
50
|
getContext: () => context,
|
|
@@ -54,25 +57,36 @@ var BaseDistributedAdapter = class {
|
|
|
54
57
|
try {
|
|
55
58
|
const result = await this.runtime.executeNode(blueprint, nodeId, workerState);
|
|
56
59
|
await context.set(nodeId, result.output);
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
const analysis = analyzeBlueprint(blueprint);
|
|
61
|
+
const isTerminalNode = analysis.terminalNodeIds.includes(nodeId);
|
|
62
|
+
if (isTerminalNode) {
|
|
63
|
+
const completedNodes = new Set(
|
|
64
|
+
Object.keys(await context.toJSON()).filter((k) => blueprint.nodes.some((n) => n.id === k))
|
|
65
|
+
);
|
|
66
|
+
const allTerminalNodesCompleted = analysis.terminalNodeIds.every((terminalId) => completedNodes.has(terminalId));
|
|
67
|
+
if (allTerminalNodesCompleted) {
|
|
68
|
+
console.log(`[Adapter] \u2705 All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`);
|
|
69
|
+
const finalContext = await context.toJSON();
|
|
70
|
+
const finalResult = {
|
|
71
|
+
context: finalContext,
|
|
72
|
+
serializedContext: this.serializer.serialize(finalContext),
|
|
73
|
+
status: "completed"
|
|
74
|
+
};
|
|
75
|
+
await this.publishFinalResult(runId, {
|
|
76
|
+
status: "completed",
|
|
77
|
+
payload: finalResult
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
} else {
|
|
81
|
+
console.log(
|
|
82
|
+
`[Adapter] Terminal node '${nodeId}' completed for Run ID '${runId}', but other terminal nodes are still running.`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
|
-
const nextNodes = await this.runtime.determineNextNodes(blueprint, nodeId, result, context);
|
|
73
|
-
if (nextNodes.length === 0) {
|
|
86
|
+
const nextNodes = await this.runtime.determineNextNodes(blueprint, nodeId, result, context, runId);
|
|
87
|
+
if (nextNodes.length === 0 && !isTerminalNode) {
|
|
74
88
|
console.log(
|
|
75
|
-
`[Adapter]
|
|
89
|
+
`[Adapter] Non-terminal node '${nodeId}' reached end of branch for Run ID '${runId}'. This branch will now terminate.`
|
|
76
90
|
);
|
|
77
91
|
return;
|
|
78
92
|
}
|
|
@@ -90,6 +104,7 @@ var BaseDistributedAdapter = class {
|
|
|
90
104
|
const reason = error.message || "Unknown execution error";
|
|
91
105
|
console.error(`[Adapter] FATAL: Job for node '${nodeId}' failed for Run ID '${runId}': ${reason}`);
|
|
92
106
|
await this.publishFinalResult(runId, { status: "failed", reason });
|
|
107
|
+
await this.writePoisonPillForSuccessors(runId, blueprint, nodeId);
|
|
93
108
|
}
|
|
94
109
|
}
|
|
95
110
|
/**
|
|
@@ -105,9 +120,25 @@ var BaseDistributedAdapter = class {
|
|
|
105
120
|
if (predecessors.length <= 1) {
|
|
106
121
|
return true;
|
|
107
122
|
}
|
|
123
|
+
const poisonKey = `flowcraft:fanin:poison:${runId}:${targetNodeId}`;
|
|
124
|
+
const isPoisoned = !await this.store.setIfNotExist(poisonKey, "poisoned", 3600);
|
|
125
|
+
if (isPoisoned) {
|
|
126
|
+
console.log(`[Adapter] Node '${targetNodeId}' is poisoned due to failed predecessor. Failing immediately.`);
|
|
127
|
+
throw new Error(`Node '${targetNodeId}' failed due to poisoned predecessor in run '${runId}'`);
|
|
128
|
+
}
|
|
108
129
|
if (joinStrategy === "any") {
|
|
109
130
|
const lockKey = `flowcraft:joinlock:${runId}:${targetNodeId}`;
|
|
110
|
-
|
|
131
|
+
const isLocked = await this.store.setIfNotExist(lockKey, "locked", 3600);
|
|
132
|
+
if (!isLocked) {
|
|
133
|
+
const cancelKey = `flowcraft:fanin:cancel:${runId}:${targetNodeId}`;
|
|
134
|
+
const isCancelled = !await this.store.setIfNotExist(cancelKey, "cancelled", 3600);
|
|
135
|
+
if (isCancelled) {
|
|
136
|
+
console.log(`[Adapter] Node '${targetNodeId}' is cancelled due to failed predecessor. Failing immediately.`);
|
|
137
|
+
throw new Error(`Node '${targetNodeId}' failed due to cancelled predecessor in run '${runId}'`);
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
111
142
|
} else {
|
|
112
143
|
const fanInKey = `flowcraft:fanin:${runId}:${targetNodeId}`;
|
|
113
144
|
const readyCount = await this.store.increment(fanInKey, 3600);
|
|
@@ -129,9 +160,15 @@ var BaseDistributedAdapter = class {
|
|
|
129
160
|
*/
|
|
130
161
|
async reconcile(runId) {
|
|
131
162
|
const context = this.createContext(runId);
|
|
132
|
-
|
|
163
|
+
let blueprintId = await context.get("blueprintId");
|
|
133
164
|
if (!blueprintId) {
|
|
134
|
-
|
|
165
|
+
const blueprintKey = `flowcraft:blueprint:${runId}`;
|
|
166
|
+
blueprintId = await this.store.get(blueprintKey);
|
|
167
|
+
if (blueprintId) {
|
|
168
|
+
await context.set("blueprintId", blueprintId);
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error(`Cannot reconcile runId '${runId}': blueprintId not found in context or coordination store.`);
|
|
171
|
+
}
|
|
135
172
|
}
|
|
136
173
|
const blueprint = this.runtime.options.blueprints?.[blueprintId];
|
|
137
174
|
if (!blueprint) {
|
|
@@ -195,8 +232,32 @@ var BaseDistributedAdapter = class {
|
|
|
195
232
|
}
|
|
196
233
|
return newFrontier;
|
|
197
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* 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.
|
|
237
|
+
*/
|
|
238
|
+
async writePoisonPillForSuccessors(runId, blueprint, failedNodeId) {
|
|
239
|
+
const successors = blueprint.edges.filter((edge) => edge.source === failedNodeId).map((edge) => edge.target).map((targetId) => blueprint.nodes.find((node) => node.id === targetId)).filter((node) => node);
|
|
240
|
+
for (const successor of successors) {
|
|
241
|
+
if (successor) {
|
|
242
|
+
const joinStrategy = successor.config?.joinStrategy || "all";
|
|
243
|
+
if (joinStrategy === "all") {
|
|
244
|
+
const poisonKey = `flowcraft:fanin:poison:${runId}:${successor.id}`;
|
|
245
|
+
await this.store.setIfNotExist(poisonKey, "poisoned", 3600);
|
|
246
|
+
console.log(
|
|
247
|
+
`[Adapter] Wrote poison pill for 'all' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`
|
|
248
|
+
);
|
|
249
|
+
} else if (joinStrategy === "any") {
|
|
250
|
+
const cancelKey = `flowcraft:fanin:cancel:${runId}:${successor.id}`;
|
|
251
|
+
await this.store.setIfNotExist(cancelKey, "cancelled", 3600);
|
|
252
|
+
console.log(
|
|
253
|
+
`[Adapter] Wrote cancellation pill for 'any' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
198
259
|
};
|
|
199
260
|
|
|
200
261
|
export { BaseDistributedAdapter };
|
|
201
|
-
//# sourceMappingURL=chunk-
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
262
|
+
//# sourceMappingURL=chunk-QLGJUDQF.js.map
|
|
263
|
+
//# sourceMappingURL=chunk-QLGJUDQF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,OAA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AM,YAAA,GAAe,SAAA,CAAU,MAAA,EAAQ,YAAA,IAAgB,KAAA;AACvD,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC3B,UAAA,MAAM,SAAA,GAAY,CAAA,uBAAA,EAA0B,KAAK,CAAA,CAAA,EAAI,UAAU,EAAE,CAAA,CAAA;AACjE,UAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,SAAA,EAAW,YAAY,IAAI,CAAA;AAC1D,UAAA,OAAA,CAAQ,GAAA;AAAA,YACP,CAAA,iDAAA,EAAoD,SAAA,CAAU,EAAE,CAAA,6BAAA,EAAgC,YAAY,CAAA,CAAA;AAAA,WAC7G;AAAA,QACD,CAAA,MAAA,IAAW,iBAAiB,KAAA,EAAO;AAClC,UAAA,MAAM,SAAA,GAAY,CAAA,uBAAA,EAA0B,KAAK,CAAA,CAAA,EAAI,UAAU,EAAE,CAAA,CAAA;AACjE,UAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,SAAA,EAAW,aAAa,IAAI,CAAA;AAC3D,UAAA,OAAA,CAAQ,GAAA;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"]}
|
|
@@ -6,16 +6,16 @@ var Context = class {
|
|
|
6
6
|
this.data = new Map(Object.entries(initialData));
|
|
7
7
|
}
|
|
8
8
|
get(key) {
|
|
9
|
-
return this.data.get(
|
|
9
|
+
return this.data.get(key);
|
|
10
10
|
}
|
|
11
11
|
set(key, value) {
|
|
12
|
-
this.data.set(
|
|
12
|
+
this.data.set(key, value);
|
|
13
13
|
}
|
|
14
14
|
has(key) {
|
|
15
|
-
return this.data.has(
|
|
15
|
+
return this.data.has(key);
|
|
16
16
|
}
|
|
17
17
|
delete(key) {
|
|
18
|
-
return this.data.delete(
|
|
18
|
+
return this.data.delete(key);
|
|
19
19
|
}
|
|
20
20
|
toJSON() {
|
|
21
21
|
return Object.fromEntries(this.data);
|
|
@@ -45,5 +45,5 @@ var AsyncContextView = class {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
export { AsyncContextView, Context };
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-R3HQXIEL.js.map
|
|
49
|
+
//# sourceMappingURL=chunk-R3HQXI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A,CAAY,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAC/B,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACxB;AAAA,EAGA,IAAI,GAAA,EAA+B;AAClC,IAAA,OAAO,QAAQ,OAAA,CAAQ,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,GAAG,CAAC,CAAA;AAAA,EACjD;AAAA,EAGA,OAAO,GAAA,EAA+B;AACrC,IAAA,OAAO,QAAQ,OAAA,CAAQ,IAAA,CAAK,WAAA,CAAY,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,EACpD;AAAA,EAEA,MAAA,GAAuC;AACtC,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,CAAK,WAAA,CAAY,QAAQ,CAAA;AAAA,EACjD;AACD","file":"chunk-R3HQXIEL.js","sourcesContent":["import type { IAsyncContext, ISyncContext } from './types'\n\n/**\n * A default, high-performance, in-memory implementation of ISyncContext using a Map.\n */\nexport class Context<TContext extends Record<string, any>> implements ISyncContext<TContext> {\n\tpublic readonly type = 'sync' as const\n\tprivate data: Map<string, any>\n\n\tconstructor(initialData: Partial<TContext> = {}) {\n\t\tthis.data = new Map(Object.entries(initialData))\n\t}\n\n\tget<K extends keyof TContext>(key: K): TContext[K] | undefined\n\tget(key: string): any | undefined {\n\t\treturn this.data.get(key)\n\t}\n\n\tset<K extends keyof TContext>(key: K, value: TContext[K]): void\n\tset(key: string, value: any): void {\n\t\tthis.data.set(key, value)\n\t}\n\n\thas<K extends keyof TContext>(key: K): boolean\n\thas(key: string): boolean {\n\t\treturn this.data.has(key)\n\t}\n\n\tdelete<K extends keyof TContext>(key: K): boolean\n\tdelete(key: string): boolean {\n\t\treturn this.data.delete(key)\n\t}\n\n\ttoJSON(): Record<string, any> {\n\t\treturn Object.fromEntries(this.data)\n\t}\n}\n\n/**\n * An adapter that provides a consistent, Promise-based view of a synchronous context.\n * This is created by the runtime and is transparent to the node author.\n */\nexport class AsyncContextView<TContext extends Record<string, any>> implements IAsyncContext<TContext> {\n\tpublic readonly type = 'async' as const\n\n\tconstructor(private syncContext: ISyncContext<TContext>) {}\n\n\tget<K extends keyof TContext>(key: K): Promise<TContext[K] | undefined>\n\tget(key: string): Promise<any | undefined> {\n\t\treturn Promise.resolve(this.syncContext.get(key))\n\t}\n\n\tset<K extends keyof TContext>(key: K, value: TContext[K]): Promise<void>\n\tset(key: string, value: any): Promise<void> {\n\t\tthis.syncContext.set(key, value)\n\t\treturn Promise.resolve()\n\t}\n\n\thas<K extends keyof TContext>(key: K): Promise<boolean>\n\thas(key: string): Promise<boolean> {\n\t\treturn Promise.resolve(this.syncContext.has(key))\n\t}\n\n\tdelete<K extends keyof TContext>(key: K): Promise<boolean>\n\tdelete(key: string): Promise<boolean> {\n\t\treturn Promise.resolve(this.syncContext.delete(key))\n\t}\n\n\ttoJSON(): Promise<Record<string, any>> {\n\t\treturn Promise.resolve(this.syncContext.toJSON())\n\t}\n}\n"]}
|
|
@@ -33,8 +33,17 @@ var BaseNode = class {
|
|
|
33
33
|
async fallback(error, _context) {
|
|
34
34
|
throw error;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.
|
|
38
|
+
* This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.
|
|
39
|
+
* Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.
|
|
40
|
+
* @param _error The error that caused the failure.
|
|
41
|
+
* @param _context The node's execution context.
|
|
42
|
+
*/
|
|
43
|
+
async recover(_error, _context) {
|
|
44
|
+
}
|
|
36
45
|
};
|
|
37
46
|
|
|
38
47
|
export { BaseNode, isNodeClass };
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
40
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-U5V5O5MN.js.map
|
|
49
|
+
//# sourceMappingURL=chunk-U5V5O5MN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|