flowcraft 2.1.0 → 2.1.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 (48) hide show
  1. package/README.md +51 -5
  2. package/dist/analysis.d.ts +1 -1
  3. package/dist/{chunk-CO5BTPKI.js → chunk-3XVVR2SR.js} +14 -7
  4. package/dist/chunk-3XVVR2SR.js.map +1 -0
  5. package/dist/{chunk-5ZWYSKMH.js → chunk-4A627Q6L.js} +3 -3
  6. package/dist/chunk-4A627Q6L.js.map +1 -0
  7. package/dist/chunk-M2FRTT2K.js +144 -0
  8. package/dist/chunk-M2FRTT2K.js.map +1 -0
  9. package/dist/{chunk-UMXW3TCY.js → chunk-NBIRTKZ7.js} +32 -5
  10. package/dist/chunk-NBIRTKZ7.js.map +1 -0
  11. package/dist/{chunk-5EHIPX23.js → chunk-O3XD45IL.js} +53 -19
  12. package/dist/chunk-O3XD45IL.js.map +1 -0
  13. package/dist/{chunk-5QMPFUKA.js → chunk-U5V5O5MN.js} +11 -2
  14. package/dist/chunk-U5V5O5MN.js.map +1 -0
  15. package/dist/context.d.ts +1 -1
  16. package/dist/evaluator.d.ts +1 -1
  17. package/dist/flow.d.ts +3 -3
  18. package/dist/flow.js +2 -2
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +6 -6
  21. package/dist/linter.d.ts +1 -1
  22. package/dist/logger.d.ts +1 -1
  23. package/dist/node.d.ts +1 -1
  24. package/dist/node.js +1 -1
  25. package/dist/runtime/adapter.d.ts +5 -1
  26. package/dist/runtime/adapter.js +5 -5
  27. package/dist/runtime/executors.d.ts +1 -1
  28. package/dist/runtime/executors.js +1 -1
  29. package/dist/runtime/index.d.ts +1 -1
  30. package/dist/runtime/index.js +5 -5
  31. package/dist/runtime/runtime.d.ts +3 -2
  32. package/dist/runtime/runtime.js +4 -4
  33. package/dist/runtime/state.d.ts +1 -1
  34. package/dist/runtime/traverser.d.ts +2 -1
  35. package/dist/runtime/traverser.js +1 -1
  36. package/dist/runtime/types.d.ts +2 -1
  37. package/dist/sanitizer.d.ts +1 -1
  38. package/dist/serializer.d.ts +1 -1
  39. package/dist/{types-lG3xCzp_.d.ts → types-CQCe_nBM.d.ts} +8 -0
  40. package/dist/types.d.ts +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-5EHIPX23.js.map +0 -1
  43. package/dist/chunk-5QMPFUKA.js.map +0 -1
  44. package/dist/chunk-5ZWYSKMH.js.map +0 -1
  45. package/dist/chunk-CO5BTPKI.js.map +0 -1
  46. package/dist/chunk-QRMUKDSP.js +0 -141
  47. package/dist/chunk-QRMUKDSP.js.map +0 -1
  48. package/dist/chunk-UMXW3TCY.js.map +0 -1
package/README.md CHANGED
@@ -24,32 +24,78 @@ Build complex, multi-step processes with a lightweight, composable, and type-saf
24
24
  npm install flowcraft
25
25
  ```
26
26
 
27
+
27
28
  ## Usage
28
29
 
30
+ Define and run a simple workflow in a few lines of code.
31
+
29
32
  ```typescript
30
- import { createFlow, FlowRuntime } from './index'
33
+ import { createFlow, FlowRuntime } from 'flowcraft'
31
34
 
35
+ // 1. Define the workflow structure using the fluent API
32
36
  const flow = createFlow('simple-workflow')
33
37
  .node('start', async () => ({ output: 42 }))
34
- .node('double', async ({ input }) => ({ output: input * 2 }), { inputs: 'start' })
38
+ .node('double', async ({ input }) => ({ output: input * 2 }))
35
39
  .edge('start', 'double')
36
40
  .toBlueprint()
37
41
 
42
+ // 2. Create a runtime with the node implementations
38
43
  const runtime = new FlowRuntime({
39
44
  registry: flow.getFunctionRegistry(),
40
45
  })
41
46
 
47
+ // 3. Execute the workflow
42
48
  async function run() {
43
- const result = await runtime.run(flow, {})
44
- console.log(result) // { context: { start: 42, double: 84 }, status: 'completed' }
49
+ const result = await runtime.run(flow)
50
+ console.log(result.context) // { start: 42, double: 84 }
51
+ console.log(result.status) // 'completed'
45
52
  }
46
53
 
47
54
  run()
48
55
  ```
49
56
 
57
+ ## Core Concepts
58
+
59
+ - **Blueprint**: A serializable object that represents the structure of your workflow. It contains all the nodes and edges and can be stored as JSON or YAML. This is the single source of truth for a workflow's logic.
60
+ - **Node**: A single unit of work. Node logic can be implemented as a simple async function or a structured class that extends `BaseNode` for more complex lifecycle management.
61
+ - **Edge**: A connection between two nodes that defines the direction of the flow. Edges can be conditional, allowing you to create branching logic based on the output or `action` of a source node.
62
+ - **Runtime**: The `FlowRuntime` is the engine that interprets a blueprint and executes its nodes in the correct order. It manages state, handles resiliency, and coordinates the entire process.
63
+ - **Context**: An object that holds the state of a single workflow execution. The outputs of completed nodes are stored in the context and can be accessed by subsequent nodes.
64
+
65
+ ## Resiliency and Error Handling
66
+
67
+ Design robust workflows with built-in resiliency features.
68
+
69
+ - **Retries**: Configure the `maxRetries` property on a node to automatically retry it on failure.
70
+ - **Fallbacks**: Specify a `fallback` node ID in a node's configuration. If the node fails all its retry attempts, the fallback node will be executed instead, preventing the entire workflow from failing.
71
+
72
+ For more granular control, you can implement a node using the `BaseNode` class, which provides `prep`, `exec`, `post`, `fallback`, and `recover` lifecycle methods.
73
+
74
+ ## Tooling and Utilities
75
+
76
+ Flowcraft includes tools to help you validate and visualize your workflows.
77
+
78
+ - **Linter (`lintBlueprint`)**: Statically analyze a blueprint to find common errors, such as orphan nodes, invalid edges, or nodes with missing implementations.
79
+ - **Analysis (`analyzeBlueprint`)**: Programmatically inspect a blueprint to detect cycles, find start/terminal nodes, and get other graph metrics.
80
+ - **Diagram Generation (`generateMermaid`)**: Automatically generate a [Mermaid](https://mermaid-js.github.io/mermaid/#/) syntax string from a blueprint to easily visualize your workflow's structure.
81
+
82
+ ## Extensibility and Customization
83
+
84
+ The `FlowRuntime` can be configured with pluggable components to tailor its behavior to your specific needs:
85
+
86
+ - **Logger**: Provide a custom `ILogger` implementation (e.g., Pino, Winston) to integrate with your existing logging infrastructure.
87
+ - **Serializer**: Replace the default `JsonSerializer` with a more robust one (e.g., `superjson`) to handle complex data types like `Date`, `Map`, and `Set` in the workflow context.
88
+ - **Evaluator**: Swap the default `PropertyEvaluator` for a more powerful expression engine (like `jsep` or `govaluate`) to enable complex logic in edge conditions. For trusted environments, an `UnsafeEvaluator` is also available.
89
+ - **Middleware**: Wrap node execution with custom logic for cross-cutting concerns like distributed tracing, performance monitoring, or advanced authorization.
90
+ - **Event Bus**: An event emitter for monitoring workflow and node lifecycle events (`workflow:start`, `node:finish`, etc.).
91
+
92
+ ## Distributed Execution
93
+
94
+ Flowcraft's architecture is designed for progressive scalability. The `BaseDistributedAdapter` provides a foundation for running workflows across multiple machines. Flowcraft provides official adapters for [BullMQ](https://www.npmjs.com/package/@flowcraft/bullmq-adapter), [AWS](https://www.npmjs.com/package/@flowcraft/sqs-adapter), [GCP](https://www.npmjs.com/package/@flowcraft/gcp-adapter), [Azure](https://www.npmjs.com/package/@flowcraft/azure-adapter), [RabbitMQ](https://www.npmjs.com/package/@flowcraft/rabbitmq-adapter), and [Kafka](https://www.npmjs.com/package/@flowcraft/kafka-adapter).
95
+
50
96
  ## Documentation
51
97
 
52
- For a complete overview of all features, patterns, examples, and APIs, see the **[Flowcraft documentation](https://flowcraft.js.org/)**.
98
+ For a complete overview of features, patterns, examples, and APIs, see the full [documentation](https://flowcraft.js.org/).
53
99
 
54
100
  ## License
55
101
 
@@ -1,4 +1,4 @@
1
- import { W as WorkflowBlueprint } from './types-lG3xCzp_.js';
1
+ import { W as WorkflowBlueprint } from './types-CQCe_nBM.js';
2
2
 
3
3
  /**
4
4
  * A list of cycles found in the graph. Each cycle is an array of node IDs.
@@ -1,12 +1,12 @@
1
1
  import { WorkflowState } from './chunk-CSZ6EOWG.js';
2
- import { GraphTraverser } from './chunk-UMXW3TCY.js';
2
+ import { GraphTraverser } from './chunk-NBIRTKZ7.js';
3
3
  import { sanitizeBlueprint } from './chunk-DSYAC4WB.js';
4
4
  import { JsonSerializer } from './chunk-CYHZ2YVH.js';
5
- import { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './chunk-QRMUKDSP.js';
5
+ import { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './chunk-M2FRTT2K.js';
6
6
  import { AsyncContextView } from './chunk-KWQHFT7E.js';
7
7
  import { CancelledWorkflowError, NodeExecutionError, FatalNodeExecutionError } from './chunk-5ZXV3R5D.js';
8
8
  import { PropertyEvaluator } from './chunk-PH2IYZHV.js';
9
- import { isNodeClass } from './chunk-5QMPFUKA.js';
9
+ import { isNodeClass } from './chunk-U5V5O5MN.js';
10
10
  import { analyzeBlueprint } from './chunk-HN72TZY5.js';
11
11
  import { NullLogger } from './chunk-4PELJWF7.js';
12
12
 
@@ -20,6 +20,7 @@ var FlowRuntime = class {
20
20
  serializer;
21
21
  middleware;
22
22
  evaluator;
23
+ analysisCache;
23
24
  options;
24
25
  constructor(options) {
25
26
  this.registry = options.registry || {};
@@ -31,6 +32,7 @@ var FlowRuntime = class {
31
32
  this.serializer = options.serializer || new JsonSerializer();
32
33
  this.middleware = options.middleware || [];
33
34
  this.evaluator = options.evaluator || new PropertyEvaluator();
35
+ this.analysisCache = /* @__PURE__ */ new WeakMap();
34
36
  this.options = options;
35
37
  }
36
38
  async run(blueprint, initialState = {}, options) {
@@ -48,7 +50,11 @@ var FlowRuntime = class {
48
50
  blueprintId: blueprint.id,
49
51
  executionId
50
52
  });
51
- const analysis = analyzeBlueprint(blueprint);
53
+ const analysis = this.analysisCache.get(blueprint) ?? (() => {
54
+ const computed = analyzeBlueprint(blueprint);
55
+ this.analysisCache.set(blueprint, computed);
56
+ return computed;
57
+ })();
52
58
  if (options?.strict && !analysis.isDag) {
53
59
  throw new Error(`Workflow '${blueprint.id}' failed strictness check: Cycles are not allowed.`);
54
60
  }
@@ -339,7 +345,8 @@ var FlowRuntime = class {
339
345
  switch (nodeDef.uses) {
340
346
  case "batch-scatter": {
341
347
  const inputArray = await context.get(inputs) || [];
342
- if (!Array.isArray(inputArray)) throw new Error(`Input for batch-scatter node '${id}' must be an array.`);
348
+ if (!Array.isArray(inputArray))
349
+ throw new FatalNodeExecutionError(`Input for batch-scatter node '${id}' must be an array.`, id, "");
343
350
  const batchId = globalThis.crypto.randomUUID();
344
351
  const dynamicNodes = [];
345
352
  for (let i = 0; i < inputArray.length; i++) {
@@ -406,5 +413,5 @@ var FlowRuntime = class {
406
413
  };
407
414
 
408
415
  export { FlowRuntime };
409
- //# sourceMappingURL=chunk-CO5BTPKI.js.map
410
- //# sourceMappingURL=chunk-CO5BTPKI.js.map
416
+ //# sourceMappingURL=chunk-3XVVR2SR.js.map
417
+ //# sourceMappingURL=chunk-3XVVR2SR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/runtime.ts"],"names":["nodeDef"],"mappings":";;;;;;;;;;;;;AAmCO,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,EACA,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,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A,QACD;AAEA,QAAA,MAAM,aAAA,GAAgB,MAAM,IAAA,CAAK,GAAA,CAAI,cAAc,qBAA0C,CAAA;AAE7F,QAAA,IAAI,cAAc,MAAA,KAAW,WAAA;AAC5B,UAAA,MAAM,IAAI,kBAAA;AAAA,YACT,CAAA,cAAA,EAAiB,WAAW,CAAA,yCAAA,EAA4C,aAAA,CAAc,MAAM,CAAA,CAAA;AAAA,YAC5F,EAAA;AAAA,YACA,YAAA,CAAa;AAAA,WACd;AAED,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-3XVVR2SR.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 { ExecutionStrategy } from './executors'\nimport { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor } from './executors'\nimport { WorkflowState } from './state'\nimport { GraphTraverser } from './traverser'\nimport type { IRuntime } from './types'\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\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\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}\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: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) => this._executeBuiltInNode(nodeDef, context))\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): 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}\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}\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<TContext>,\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 dynamicNodes: NodeDefinition[] = []\n\t\t\t\tfor (let i = 0; i < inputArray.length; 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 as any, item)\n\t\t\t\t\tdynamicNodes.push({\n\t\t\t\t\t\tid: `${params.workerUsesKey}_${batchId}_${i}`,\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\tconst gatherNodeId = params.gatherNodeId\n\t\t\t\treturn { dynamicNodes, output: { gatherNodeId } }\n\t\t\t}\n\t\t\tcase 'batch-gather': {\n\t\t\t\treturn { 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\n\t\t\t\tif (subflowResult.status !== 'completed')\n\t\t\t\t\tthrow new NodeExecutionError(\n\t\t\t\t\t\t`Sub-workflow '${blueprintId}' did not complete successfully. Status: ${subflowResult.status}`,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tsubBlueprint.id,\n\t\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,4 +1,4 @@
1
- import { isNodeClass } from './chunk-5QMPFUKA.js';
1
+ import { isNodeClass } from './chunk-U5V5O5MN.js';
2
2
 
3
3
  // src/flow.ts
4
4
  function _hashFunction(fn) {
@@ -143,5 +143,5 @@ function createFlow(id) {
143
143
  }
144
144
 
145
145
  export { Flow, createFlow };
146
- //# sourceMappingURL=chunk-5ZWYSKMH.js.map
147
- //# sourceMappingURL=chunk-5ZWYSKMH.js.map
146
+ //# sourceMappingURL=chunk-4A627Q6L.js.map
147
+ //# sourceMappingURL=chunk-4A627Q6L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/flow.ts"],"names":[],"mappings":";;;AAMA,SAAS,cAAc,EAAA,EAAwF;AAC9G,EAAA,MAAM,MAAA,GAAS,GAAG,QAAA,EAAS;AAC3B,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,MAAA,CAAO,QAAQ,CAAA,EAAA,EAAK;AACvC,IAAA,MAAM,IAAA,GAAO,MAAA,CAAO,UAAA,CAAW,CAAC,CAAA;AAChC,IAAA,IAAA,GAAA,CAAQ,IAAA,IAAQ,KAAK,IAAA,GAAO,IAAA;AAC5B,IAAA,IAAA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,SAAS,EAAE,GAAG,SAAA,CAAU,MAAA,EAAQ,cAAc,KAAA,EAAM;AAC9D,MAAA,OAAA,CAAQ,SAAS,EAAE,GAAG,OAAA,CAAQ,MAAA,EAAQ,cAAc,KAAA,EAAM;AAAA,IAC3D;AAEA,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACb;AAAA,EAEA,mBAAA,GAAsB;AACrB,IAAA,OAAO,IAAA,CAAK,gBAAA;AAAA,EACb;AACD;AAKO,SAAS,WAGd,EAAA,EAA2C;AAC5C,EAAA,OAAO,IAAI,KAAK,EAAE,CAAA;AACnB","file":"chunk-4A627Q6L.js","sourcesContent":["import { isNodeClass } from './node'\nimport type { EdgeDefinition, NodeClass, NodeDefinition, NodeFunction, WorkflowBlueprint } from './types'\n\n/**\n * Generates a deterministic hash for a function based on its source code.\n */\nfunction _hashFunction(fn: NodeFunction<any, any, any, any, any> | NodeClass<any, any, any, any, any>): string {\n\tconst source = fn.toString()\n\tlet hash = 0\n\tfor (let i = 0; i < source.length; i++) {\n\t\tconst char = source.charCodeAt(i)\n\t\thash = (hash << 5) - hash + char\n\t\thash = hash & hash // Convert to 32-bit integer\n\t}\n\treturn Math.abs(hash).toString(16)\n}\n\n/**\n * A fluent API for programmatically constructing a WorkflowBlueprint.\n */\nexport class Flow<\n\tTContext extends Record<string, any> = Record<string, any>,\n\tTDependencies extends Record<string, any> = Record<string, any>,\n> {\n\tprivate blueprint: Partial<WorkflowBlueprint>\n\tprivate functionRegistry: Map<string, NodeFunction | NodeClass>\n\tprivate loopControllerIds: Map<string, string>\n\tprivate loopDefinitions: Array<{\n\t\tid: string\n\t\tstartNodeId: string\n\t\tendNodeId: string\n\t}>\n\n\tconstructor(id: string) {\n\t\tthis.blueprint = { id, nodes: [], edges: [] }\n\t\tthis.functionRegistry = new Map()\n\t\tthis.loopControllerIds = new Map()\n\t\tthis.loopDefinitions = []\n\t}\n\n\tnode<TInput = any, TOutput = any, TAction extends string = string>(\n\t\tid: string,\n\t\timplementation:\n\t\t\t| NodeFunction<TContext, TDependencies, TInput, TOutput, TAction>\n\t\t\t| NodeClass<TContext, TDependencies, TInput, TOutput, TAction>,\n\t\toptions?: Omit<NodeDefinition, 'id' | 'uses'>,\n\t): this {\n\t\tlet usesKey: string\n\n\t\tif (isNodeClass(implementation)) {\n\t\t\tusesKey =\n\t\t\t\timplementation.name && implementation.name !== 'BaseNode'\n\t\t\t\t\t? implementation.name\n\t\t\t\t\t: `class_${_hashFunction(implementation)}`\n\t\t\tthis.functionRegistry.set(usesKey, implementation)\n\t\t} else {\n\t\t\tusesKey = `fn_${_hashFunction(implementation)}`\n\t\t\tthis.functionRegistry.set(usesKey, implementation as unknown as NodeFunction)\n\t\t}\n\n\t\tconst nodeDef: NodeDefinition = { id, uses: usesKey, ...options }\n\t\tthis.blueprint.nodes?.push(nodeDef)\n\t\treturn this\n\t}\n\n\tedge(source: string, target: string, options?: Omit<EdgeDefinition, 'source' | 'target'>): this {\n\t\tconst edgeDef: EdgeDefinition = { source, target, ...options }\n\t\tthis.blueprint.edges?.push(edgeDef)\n\t\treturn this\n\t}\n\n\t/**\n\t * Creates a batch processing pattern.\n\t * It takes an input array, runs a worker node on each item in parallel, and gathers the results.\n\t * @param id The base ID for this batch operation.\n\t * @param worker The node implementation to run on each item.\n\t * @param options Configuration for the batch operation.\n\t * @param options.inputKey The key in the context that holds the input array for the batch.\n\t * @param options.outputKey The key in the context where the array of results will be stored.\n\t * @returns The Flow instance for chaining.\n\t */\n\tbatch<TInput = any, TOutput = any, TAction extends string = string>(\n\t\tid: string,\n\t\tworker:\n\t\t\t| NodeFunction<TContext, TDependencies, TInput, TOutput, TAction>\n\t\t\t| NodeClass<TContext, TDependencies, TInput, TOutput, TAction>,\n\t\toptions: {\n\t\t\t/** The key in the context that holds the input array for the batch. */\n\t\t\tinputKey: keyof TContext\n\t\t\t/** The key in the context where the array of results will be stored. */\n\t\t\toutputKey: keyof TContext\n\t\t},\n\t): this {\n\t\tconst { inputKey, outputKey } = options\n\t\tconst scatterId = `${id}_scatter`\n\t\tconst gatherId = `${id}_gather`\n\n\t\t// register worker implementation under a unique key.\n\t\tlet workerUsesKey: string\n\t\tif (isNodeClass(worker)) {\n\t\t\tworkerUsesKey =\n\t\t\t\tworker.name && worker.name !== 'BaseNode' ? worker.name : `class_batch_worker_${_hashFunction(worker)}`\n\t\t\tthis.functionRegistry.set(workerUsesKey, worker)\n\t\t} else {\n\t\t\tworkerUsesKey = `fn_batch_worker_${_hashFunction(worker)}`\n\t\t\tthis.functionRegistry.set(workerUsesKey, worker as unknown as NodeFunction)\n\t\t}\n\n\t\t// scatter node: takes an array and dynamically schedules worker nodes\n\t\tthis.blueprint.nodes?.push({\n\t\t\tid: scatterId,\n\t\t\tuses: 'batch-scatter', // built-in\n\t\t\tinputs: inputKey as string,\n\t\t\tparams: { workerUsesKey, outputKey: outputKey as string, gatherNodeId: gatherId },\n\t\t})\n\n\t\t// gather node: waits for all workers to finish and collects the results\n\t\tthis.blueprint.nodes?.push({\n\t\t\tid: gatherId,\n\t\t\tuses: 'batch-gather', // built-in\n\t\t\tparams: { outputKey },\n\t\t\tconfig: { joinStrategy: 'all' }, // important: must wait for all scattered jobs\n\t\t})\n\n\t\t// edge to connect scatter and gather nodes. orchestrator will manage dynamic workers\n\t\tthis.edge(scatterId, gatherId)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * Creates a loop pattern in the workflow graph.\n\t * @param id A unique identifier for the loop construct.\n\t * @param options Defines the start, end, and continuation condition of the loop.\n\t * @param options.startNodeId The ID of the first node inside the loop body.\n\t * @param options.endNodeId The ID of the last node inside the loop body.\n\t * @param options.condition An expression that, if true, causes the loop to run again.\n\t */\n\tloop(\n\t\tid: string,\n\t\toptions: {\n\t\t\t/** The ID of the first node inside the loop body. */\n\t\t\tstartNodeId: string\n\t\t\t/** The ID of the last node inside the loop body. */\n\t\t\tendNodeId: string\n\t\t\t/** An expression that, if true, causes the loop to run again. */\n\t\t\tcondition: string\n\t\t},\n\t): this {\n\t\tconst { startNodeId, endNodeId, condition } = options\n\t\tconst controllerId = `${id}-loop`\n\n\t\tthis.loopControllerIds.set(id, controllerId)\n\n\t\tthis.loopDefinitions.push({ id, startNodeId, endNodeId })\n\n\t\t// controller node: evaluates the loop condition\n\t\tthis.blueprint.nodes?.push({\n\t\t\tid: controllerId,\n\t\t\tuses: 'loop-controller', // built-in\n\t\t\tparams: { condition },\n\t\t\tconfig: { joinStrategy: 'any' }, // to allow re-execution on each loop iteration\n\t\t})\n\n\t\tthis.edge(endNodeId, controllerId)\n\n\t\tthis.edge(controllerId, startNodeId, {\n\t\t\taction: 'continue',\n\t\t\ttransform: `context.${endNodeId}`, // pass the end node's value to the start node\n\t\t})\n\n\t\treturn this\n\t}\n\n\tgetLoopControllerId(id: string): string {\n\t\tconst controllerId = this.loopControllerIds.get(id)\n\t\tif (!controllerId) {\n\t\t\tthrow new Error(`Loop with id '${id}' not found. Ensure you have defined it using the .loop() method.`)\n\t\t}\n\t\treturn controllerId\n\t}\n\n\ttoBlueprint(): WorkflowBlueprint {\n\t\tif (!this.blueprint.nodes || this.blueprint.nodes.length === 0) {\n\t\t\tthrow new Error('Cannot build a blueprint with no nodes.')\n\t\t}\n\n\t\tfor (const loopDef of this.loopDefinitions) {\n\t\t\tconst startNode = this.blueprint.nodes?.find((n) => n.id === loopDef.startNodeId)\n\t\t\tconst endNode = this.blueprint.nodes?.find((n) => n.id === loopDef.endNodeId)\n\n\t\t\tif (!startNode) {\n\t\t\t\tthrow new Error(`Loop '${loopDef.id}' references non-existent start node '${loopDef.startNodeId}'.`)\n\t\t\t}\n\t\t\tif (!endNode) {\n\t\t\t\tthrow new Error(`Loop '${loopDef.id}' references non-existent end node '${loopDef.endNodeId}'.`)\n\t\t\t}\n\n\t\t\tstartNode.config = { ...startNode.config, joinStrategy: 'any' }\n\t\t\tendNode.config = { ...endNode.config, joinStrategy: 'any' }\n\t\t}\n\n\t\treturn this.blueprint as WorkflowBlueprint\n\t}\n\n\tgetFunctionRegistry() {\n\t\treturn this.functionRegistry\n\t}\n}\n\n/**\n * Helper function to create a new Flow builder instance.\n */\nexport function createFlow<\n\tTContext extends Record<string, any> = Record<string, any>,\n\tTDependencies extends Record<string, any> = Record<string, any>,\n>(id: string): Flow<TContext, TDependencies> {\n\treturn new Flow(id)\n}\n"]}
@@ -0,0 +1,144 @@
1
+ import { CancelledWorkflowError, FatalNodeExecutionError } from './chunk-5ZXV3R5D.js';
2
+
3
+ // src/runtime/executors.ts
4
+ async function withRetries(executor, maxRetries, nodeDef, context, executionId, signal, eventBus) {
5
+ let lastError;
6
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
7
+ try {
8
+ signal?.throwIfAborted();
9
+ const result = await executor();
10
+ if (attempt > 1) {
11
+ context.dependencies.logger.info(`Node execution succeeded after retry`, {
12
+ nodeId: nodeDef.id,
13
+ attempt,
14
+ executionId
15
+ });
16
+ }
17
+ return result;
18
+ } catch (error) {
19
+ lastError = error;
20
+ if (error instanceof DOMException && error.name === "AbortError") {
21
+ throw new CancelledWorkflowError("Workflow cancelled");
22
+ }
23
+ if (error instanceof FatalNodeExecutionError) break;
24
+ if (attempt < maxRetries) {
25
+ context.dependencies.logger.warn(`Node execution failed, retrying`, {
26
+ nodeId: nodeDef.id,
27
+ attempt,
28
+ maxRetries,
29
+ error: error instanceof Error ? error.message : String(error),
30
+ executionId
31
+ });
32
+ if (eventBus) {
33
+ await eventBus.emit("node:retry", {
34
+ blueprintId: context.dependencies.blueprint?.id || "",
35
+ nodeId: nodeDef.id,
36
+ attempt,
37
+ executionId
38
+ });
39
+ }
40
+ } else {
41
+ context.dependencies.logger.error(`Node execution failed after all retries`, {
42
+ nodeId: nodeDef.id,
43
+ attempts: maxRetries,
44
+ error: error instanceof Error ? error.message : String(error),
45
+ executionId
46
+ });
47
+ }
48
+ }
49
+ }
50
+ throw lastError;
51
+ }
52
+ var FunctionNodeExecutor = class {
53
+ constructor(implementation, maxRetries, eventBus) {
54
+ this.implementation = implementation;
55
+ this.maxRetries = maxRetries;
56
+ this.eventBus = eventBus;
57
+ }
58
+ async execute(nodeDef, context, executionId, signal) {
59
+ return withRetries(
60
+ () => this.implementation(context),
61
+ this.maxRetries,
62
+ nodeDef,
63
+ context,
64
+ executionId,
65
+ signal,
66
+ this.eventBus
67
+ );
68
+ }
69
+ };
70
+ var ClassNodeExecutor = class {
71
+ constructor(implementation, maxRetries, eventBus) {
72
+ this.implementation = implementation;
73
+ this.maxRetries = maxRetries;
74
+ this.eventBus = eventBus;
75
+ }
76
+ async execute(nodeDef, context, executionId, signal) {
77
+ const instance = new this.implementation(nodeDef.params || {});
78
+ let lastError;
79
+ try {
80
+ signal?.throwIfAborted();
81
+ const prepResult = await instance.prep(context);
82
+ let execResult;
83
+ try {
84
+ execResult = await withRetries(
85
+ () => instance.exec(prepResult, context),
86
+ this.maxRetries,
87
+ nodeDef,
88
+ context,
89
+ executionId,
90
+ signal,
91
+ this.eventBus
92
+ );
93
+ } catch (error) {
94
+ lastError = error instanceof Error ? error : new Error(String(error));
95
+ if (error instanceof DOMException && error.name === "AbortError") {
96
+ throw new CancelledWorkflowError("Workflow cancelled");
97
+ }
98
+ if (error instanceof FatalNodeExecutionError) {
99
+ throw error;
100
+ }
101
+ }
102
+ if (lastError) {
103
+ signal?.throwIfAborted();
104
+ execResult = await instance.fallback(lastError, context);
105
+ }
106
+ signal?.throwIfAborted();
107
+ if (!execResult) {
108
+ throw new Error("Execution failed after all retries");
109
+ }
110
+ return await instance.post(execResult, context);
111
+ } catch (error) {
112
+ lastError = error instanceof Error ? error : new Error(String(error));
113
+ if (error instanceof DOMException && error.name === "AbortError") {
114
+ throw new CancelledWorkflowError("Workflow cancelled");
115
+ }
116
+ throw error;
117
+ } finally {
118
+ if (lastError) {
119
+ try {
120
+ await instance.recover(lastError, context);
121
+ } catch (recoverError) {
122
+ context.dependencies.logger.warn(`Recover phase failed`, {
123
+ nodeId: nodeDef.id,
124
+ originalError: lastError.message,
125
+ recoverError: recoverError instanceof Error ? recoverError.message : String(recoverError),
126
+ executionId
127
+ });
128
+ }
129
+ }
130
+ }
131
+ }
132
+ };
133
+ var BuiltInNodeExecutor = class {
134
+ constructor(executeBuiltIn) {
135
+ this.executeBuiltIn = executeBuiltIn;
136
+ }
137
+ async execute(nodeDef, context) {
138
+ return this.executeBuiltIn(nodeDef, context.context);
139
+ }
140
+ };
141
+
142
+ export { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor };
143
+ //# sourceMappingURL=chunk-M2FRTT2K.js.map
144
+ //# sourceMappingURL=chunk-M2FRTT2K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/executors.ts"],"names":[],"mappings":";;;AAWA,eAAe,YACd,QAAA,EACA,UAAA,EACA,SACA,OAAA,EACA,WAAA,EACA,QACA,QAAA,EACa;AACb,EAAA,IAAI,SAAA;AACJ,EAAA,KAAA,IAAS,OAAA,GAAU,CAAA,EAAG,OAAA,IAAW,UAAA,EAAY,OAAA,EAAA,EAAW;AACvD,IAAA,IAAI;AACH,MAAA,MAAA,EAAQ,cAAA,EAAe;AACvB,MAAA,MAAM,MAAA,GAAS,MAAM,QAAA,EAAS;AAC9B,MAAA,IAAI,UAAU,CAAA,EAAG;AAChB,QAAA,OAAA,CAAQ,YAAA,CAAa,MAAA,CAAO,IAAA,CAAK,CAAA,oCAAA,CAAA,EAAwC;AAAA,UACxE,QAAQ,OAAA,CAAQ,EAAA;AAAA,UAChB,OAAA;AAAA,UACA;AAAA,SACA,CAAA;AAAA,MACF;AACA,MAAA,OAAO,MAAA;AAAA,IACR,SAAS,KAAA,EAAO;AACf,MAAA,SAAA,GAAY,KAAA;AACZ,MAAA,IAAI,KAAA,YAAiB,YAAA,IAAgB,KAAA,CAAM,IAAA,KAAS,YAAA,EAAc;AACjE,QAAA,MAAM,IAAI,uBAAuB,oBAAoB,CAAA;AAAA,MACtD;AACA,MAAA,IAAI,iBAAiB,uBAAA,EAAyB;AAC9C,MAAA,IAAI,UAAU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AA,EACD;AACD;AAEO,IAAM,sBAAN,MAAuD;AAAA,EAC7D,YACS,cAAA,EAIP;AAJO,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA;AAAA,EAIN;AAAA,EAEH,MAAM,OAAA,CACL,OAAA,EACA,OAAA,EACgC;AAChC,IAAA,OAAO,IAAA,CAAK,cAAA,CAAe,OAAA,EAAS,OAAA,CAAQ,OAAqC,CAAA;AAAA,EAClF;AACD","file":"chunk-M2FRTT2K.js","sourcesContent":["import { CancelledWorkflowError, FatalNodeExecutionError } from '../errors'\nimport type {\n\tContextImplementation,\n\tIEventBus,\n\tNodeClass,\n\tNodeContext,\n\tNodeDefinition,\n\tNodeFunction,\n\tNodeResult,\n} from '../types'\n\nasync function withRetries<T>(\n\texecutor: () => Promise<T>,\n\tmaxRetries: number,\n\tnodeDef: NodeDefinition,\n\tcontext: NodeContext<any, any, any>,\n\texecutionId?: string,\n\tsignal?: AbortSignal,\n\teventBus?: IEventBus,\n): Promise<T> {\n\tlet lastError: any\n\tfor (let attempt = 1; attempt <= maxRetries; attempt++) {\n\t\ttry {\n\t\t\tsignal?.throwIfAborted()\n\t\t\tconst result = await executor()\n\t\t\tif (attempt > 1) {\n\t\t\t\tcontext.dependencies.logger.info(`Node execution succeeded after retry`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tattempt,\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn result\n\t\t} catch (error) {\n\t\t\tlastError = error\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\tif (error instanceof FatalNodeExecutionError) break\n\t\t\tif (attempt < maxRetries) {\n\t\t\t\tcontext.dependencies.logger.warn(`Node execution failed, retrying`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tattempt,\n\t\t\t\t\tmaxRetries,\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\tif (eventBus) {\n\t\t\t\t\tawait eventBus.emit('node:retry', {\n\t\t\t\t\t\tblueprintId: context.dependencies.blueprint?.id || '',\n\t\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\texecutionId,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontext.dependencies.logger.error(`Node execution failed after all retries`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tattempts: maxRetries,\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}\n\t\t}\n\t}\n\tthrow lastError\n}\n\nexport interface ExecutionStrategy {\n\texecute: (\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<any, any, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t) => Promise<NodeResult<any, any>>\n}\n\nexport class FunctionNodeExecutor implements ExecutionStrategy {\n\tconstructor(\n\t\tprivate implementation: NodeFunction,\n\t\tprivate maxRetries: number,\n\t\tprivate eventBus: IEventBus,\n\t) {}\n\n\tasync execute(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<any, any, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<NodeResult<any, any>> {\n\t\treturn withRetries(\n\t\t\t() => this.implementation(context),\n\t\t\tthis.maxRetries,\n\t\t\tnodeDef,\n\t\t\tcontext,\n\t\t\texecutionId,\n\t\t\tsignal,\n\t\t\tthis.eventBus,\n\t\t)\n\t}\n}\n\nexport class ClassNodeExecutor implements ExecutionStrategy {\n\tconstructor(\n\t\tprivate implementation: NodeClass,\n\t\tprivate maxRetries: number,\n\t\tprivate eventBus: IEventBus,\n\t) {}\n\n\tasync execute(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<any, any, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<NodeResult<any, any>> {\n\t\tconst instance = new this.implementation(nodeDef.params || {})\n\t\tlet lastError: Error | undefined\n\t\ttry {\n\t\t\tsignal?.throwIfAborted()\n\t\t\tconst prepResult = await instance.prep(context)\n\t\t\tlet execResult: Omit<NodeResult, 'error'> | undefined\n\t\t\ttry {\n\t\t\t\texecResult = await withRetries(\n\t\t\t\t\t() => instance.exec(prepResult, context),\n\t\t\t\t\tthis.maxRetries,\n\t\t\t\t\tnodeDef,\n\t\t\t\t\tcontext,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tsignal,\n\t\t\t\t\tthis.eventBus,\n\t\t\t\t)\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error instanceof Error ? error : new Error(String(error))\n\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t\t}\n\t\t\t\tif (error instanceof FatalNodeExecutionError) {\n\t\t\t\t\tthrow error\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (lastError) {\n\t\t\t\tsignal?.throwIfAborted()\n\t\t\t\texecResult = await instance.fallback(lastError, context)\n\t\t\t}\n\t\t\tsignal?.throwIfAborted()\n\t\t\tif (!execResult) {\n\t\t\t\tthrow new Error('Execution failed after all retries')\n\t\t\t}\n\t\t\treturn await instance.post(execResult, context)\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error))\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\n\t\t} finally {\n\t\t\tif (lastError) {\n\t\t\t\ttry {\n\t\t\t\t\tawait instance.recover(lastError, context)\n\t\t\t\t} catch (recoverError) {\n\t\t\t\t\tcontext.dependencies.logger.warn(`Recover phase failed`, {\n\t\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\t\toriginalError: lastError.message,\n\t\t\t\t\t\trecoverError: recoverError instanceof Error ? recoverError.message : String(recoverError),\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}\n}\n\nexport class BuiltInNodeExecutor implements ExecutionStrategy {\n\tconstructor(\n\t\tprivate executeBuiltIn: (\n\t\t\tnodeDef: NodeDefinition,\n\t\t\tcontext: ContextImplementation<any>,\n\t\t) => Promise<NodeResult<any, any>>,\n\t) {}\n\n\tasync execute(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<Record<string, unknown>, Record<string, unknown>, any>,\n\t): Promise<NodeResult<any, any>> {\n\t\treturn this.executeBuiltIn(nodeDef, context.context as ContextImplementation<any>)\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { CancelledWorkflowError } from './chunk-5ZXV3R5D.js';
1
+ import { CancelledWorkflowError, NodeExecutionError } from './chunk-5ZXV3R5D.js';
2
2
  import { analyzeBlueprint } from './chunk-HN72TZY5.js';
3
3
 
4
4
  // src/runtime/traverser.ts
@@ -34,6 +34,23 @@ var GraphTraverser = class {
34
34
  isFallbackNode(nodeId) {
35
35
  return this.dynamicBlueprint.nodes.some((n) => n.config?.fallback === nodeId);
36
36
  }
37
+ getEffectiveJoinStrategy(nodeId) {
38
+ const node = this.dynamicBlueprint.nodes.find((n) => n.id === nodeId);
39
+ const baseJoinStrategy = node?.config?.joinStrategy || "all";
40
+ if (node?.uses === "loop-controller") {
41
+ return "any";
42
+ }
43
+ const predecessors = this.allPredecessors.get(nodeId);
44
+ if (predecessors) {
45
+ for (const predecessorId of predecessors) {
46
+ const predecessorNode = this.dynamicBlueprint.nodes.find((n) => n.id === predecessorId);
47
+ if (predecessorNode?.uses === "loop-controller") {
48
+ return "any";
49
+ }
50
+ }
51
+ }
52
+ return baseJoinStrategy;
53
+ }
37
54
  async traverse() {
38
55
  try {
39
56
  this.signal?.throwIfAborted();
@@ -74,7 +91,7 @@ var GraphTraverser = class {
74
91
  const loopControllerMatch = matched.find((m) => m.node.uses === "loop-controller");
75
92
  const finalMatched = loopControllerMatch ? [loopControllerMatch] : matched;
76
93
  for (const { node, edge } of finalMatched) {
77
- const joinStrategy = node.config?.joinStrategy || "all";
94
+ const joinStrategy = this.getEffectiveJoinStrategy(node.id);
78
95
  if (joinStrategy !== "any" && this.state.getCompletedNodes().has(node.id)) continue;
79
96
  await this.runtime.applyEdgeTransform(edge, result, node, this.state.getContext(), this.allPredecessors);
80
97
  const requiredPredecessors = this.allPredecessors.get(node.id);
@@ -85,7 +102,7 @@ var GraphTraverser = class {
85
102
  if (matched.length === 0) {
86
103
  for (const [potentialNextId, predecessors] of this.allPredecessors) {
87
104
  if (predecessors.has(nodeId) && !this.state.getCompletedNodes().has(potentialNextId)) {
88
- const joinStrategy = this.dynamicBlueprint.nodes.find((n) => n.id === potentialNextId)?.config?.joinStrategy || "all";
105
+ const joinStrategy = this.getEffectiveJoinStrategy(potentialNextId);
89
106
  const isReady = joinStrategy === "any" ? [...predecessors].some((p) => completedThisTurn.has(p)) : [...predecessors].every((p) => this.state.getCompletedNodes().has(p));
90
107
  if (isReady) this.frontier.add(potentialNextId);
91
108
  }
@@ -136,6 +153,16 @@ var GraphTraverser = class {
136
153
  if (result.dynamicNodes && result.dynamicNodes.length > 0) {
137
154
  const gatherNodeId = result.output?.gatherNodeId;
138
155
  for (const dynamicNode of result.dynamicNodes) {
156
+ const implementation = this.functionRegistry?.get(dynamicNode.uses) || this.runtime.registry[dynamicNode.uses];
157
+ if (!implementation) {
158
+ throw new NodeExecutionError(
159
+ `Implementation for '${dynamicNode.uses}' not found for dynamic node '${dynamicNode.id}' generated by node '${nodeId}'.`,
160
+ dynamicNode.id,
161
+ this.dynamicBlueprint.id,
162
+ void 0,
163
+ this.executionId
164
+ );
165
+ }
139
166
  this.dynamicBlueprint.nodes.push(dynamicNode);
140
167
  this.allPredecessors.set(dynamicNode.id, /* @__PURE__ */ new Set([nodeId]));
141
168
  if (gatherNodeId) {
@@ -161,5 +188,5 @@ var GraphTraverser = class {
161
188
  };
162
189
 
163
190
  export { GraphTraverser };
164
- //# sourceMappingURL=chunk-UMXW3TCY.js.map
165
- //# sourceMappingURL=chunk-UMXW3TCY.js.map
191
+ //# sourceMappingURL=chunk-NBIRTKZ7.js.map
192
+ //# sourceMappingURL=chunk-NBIRTKZ7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/traverser.ts"],"names":["nodeId"],"mappings":";;;;AAMO,IAAM,iBAAN,MAAsG;AAAA,EAK5G,YACC,SAAA,EACQ,OAAA,EACA,OACA,gBAAA,EACA,WAAA,EACA,QACA,WAAA,EACP;AANO,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AACA,IAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AAER,IAAA,IAAA,CAAK,gBAAA,GAAmB,gBAAgB,SAAS,CAAA;AACjD,IAAA,IAAA,CAAK,eAAA,uBAAsB,GAAA,EAAyB;AACpD,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,gBAAA,CAAiB,KAAA,EAAO;AAC/C,MAAA,IAAA,CAAK,gBAAgB,GAAA,CAAI,IAAA,CAAK,EAAA,kBAAI,IAAI,KAAK,CAAA;AAAA,IAC5C;AACA,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,gBAAA,CAAiB,KAAA,EAAO;AAC/C,MAAA,IAAA,CAAK,gBAAgB,GAAA,CAAI,IAAA,CAAK,MAAM,CAAA,EAAG,GAAA,CAAI,KAAK,MAAM,CAAA;AAAA,IACvD;AACA,IAAA,MAAM,QAAA,GAAW,iBAAiB,SAAS,CAAA;AAC3C,IAAA,IAAA,CAAK,QAAA,GAAW,IAAI,GAAA,CA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IAAI,WAAA,CAAY,EAAA,sBAAQ,GAAA,CAAI,CAAC,MAAM,CAAC,CAAC,CAAA;AAC1D,QAAA,IAAI,YAAA,EAAc;AACjB,UAAA,IAAA,CAAK,gBAAgB,GAAA,CAAI,YAAY,CAAA,EAAG,GAAA,CAAI,YAAY,EAAE,CAAA;AAAA,QAC3D;AACA,QAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,WAAA,CAAY,EAAE,CAAA;AAAA,MACjC;AAAA,IACD;AAAA,EACD;AAAA,EAEA,aAAA,GAA6B;AAC5B,IAAA,OAAO,IAAI,GAAA,CAAI,IAAA,CAAK,gBAAA,CAAiB,KAAA,CAAM,IAAI,CAAC,CAAA,KAAM,CAAA,CAAE,EAAE,CAAC,CAAA;AAAA,EAC5D;AAAA,EAEA,kBAAA,GAAkC;AACjC,IAAA,MAAM,eAAA,uBAAsB,GAAA,EAAY;AACxC,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,gBAAA,CAAiB,KAAA,EAAO;AAC/C,MAAA,IAAI,KAAK,MAAA,EAAQ,QAAA,kBAA0B,GAAA,CAAI,IAAA,CAAK,OAAO,QAAQ,CAAA;AAAA,IACpE;AACA,IAAA,OAAO,eAAA;AAAA,EACR;AAAA,EAEA,mBAAA,GAAyC;AACxC,IAAA,OAAO,IAAA,CAAK,gBAAA;AAAA,EACb;AACD","file":"chunk-NBIRTKZ7.js","sourcesContent":["import { analyzeBlueprint } from '../analysis'\nimport { CancelledWorkflowError, NodeExecutionError } from '../errors'\nimport type { NodeResult, WorkflowBlueprint } from '../types'\nimport type { WorkflowState } from './state'\nimport type { IRuntime } from './types'\n\nexport class GraphTraverser<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {\n\tprivate frontier = new Set<string>()\n\tprivate allPredecessors: Map<string, Set<string>>\n\tprivate dynamicBlueprint: WorkflowBlueprint\n\n\tconstructor(\n\t\tblueprint: WorkflowBlueprint,\n\t\tprivate runtime: IRuntime<TContext, TDependencies>,\n\t\tprivate state: WorkflowState<TContext>,\n\t\tprivate functionRegistry: Map<string, any> | undefined,\n\t\tprivate executionId: string,\n\t\tprivate signal?: AbortSignal,\n\t\tprivate concurrency?: number,\n\t) {\n\t\tthis.dynamicBlueprint = structuredClone(blueprint) as WorkflowBlueprint\n\t\tthis.allPredecessors = new Map<string, Set<string>>()\n\t\tfor (const node of this.dynamicBlueprint.nodes) {\n\t\t\tthis.allPredecessors.set(node.id, new Set())\n\t\t}\n\t\tfor (const edge of this.dynamicBlueprint.edges) {\n\t\t\tthis.allPredecessors.get(edge.target)?.add(edge.source)\n\t\t}\n\t\tconst analysis = analyzeBlueprint(blueprint)\n\t\tthis.frontier = new Set(analysis.startNodeIds.filter((id) => !this.isFallbackNode(id)))\n\t\tif (this.frontier.size === 0 && analysis.cycles.length > 0 && this.runtime.options.strict !== true) {\n\t\t\tconst uniqueStartNodes = new Set<string>()\n\t\t\tfor (const cycle of analysis.cycles) {\n\t\t\t\tif (cycle.length > 0) uniqueStartNodes.add(cycle[0])\n\t\t\t}\n\t\t\tthis.frontier = new Set(uniqueStartNodes)\n\t\t}\n\t}\n\n\tprivate isFallbackNode(nodeId: string): boolean {\n\t\treturn this.dynamicBlueprint.nodes.some((n) => n.config?.fallback === nodeId)\n\t}\n\n\tprivate getEffectiveJoinStrategy(nodeId: string): 'any' | 'all' {\n\t\tconst node = this.dynamicBlueprint.nodes.find((n) => n.id === nodeId)\n\t\tconst baseJoinStrategy = node?.config?.joinStrategy || 'all'\n\n\t\tif (node?.uses === 'loop-controller') {\n\t\t\treturn 'any'\n\t\t}\n\n\t\tconst predecessors = this.allPredecessors.get(nodeId)\n\t\tif (predecessors) {\n\t\t\tfor (const predecessorId of predecessors) {\n\t\t\t\tconst predecessorNode = this.dynamicBlueprint.nodes.find((n) => n.id === predecessorId)\n\t\t\t\tif (predecessorNode?.uses === 'loop-controller') {\n\t\t\t\t\treturn 'any'\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn baseJoinStrategy\n\t}\n\n\tasync traverse(): Promise<void> {\n\t\ttry {\n\t\t\tthis.signal?.throwIfAborted()\n\t\t} catch (error) {\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError')\n\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\tthrow error\n\t\t}\n\t\tlet iterations = 0\n\t\tconst maxIterations = 10000\n\t\twhile (this.frontier.size > 0) {\n\t\t\tif (++iterations > maxIterations) throw new Error('Traversal exceeded maximum iterations, possible infinite loop')\n\n\t\t\ttry {\n\t\t\t\tthis.signal?.throwIfAborted()\n\t\t\t\tconst currentJobs = Array.from(this.frontier)\n\t\t\t\tthis.frontier.clear()\n\t\t\t\tconst settledResults = await this.executeWithConcurrency(currentJobs)\n\t\t\t\tconst completedThisTurn = new Set<string>()\n\t\t\t\tfor (const promiseResult of settledResults) {\n\t\t\t\t\tif (promiseResult.status === 'rejected') {\n\t\t\t\t\t\tconst { nodeId, error } = promiseResult.reason\n\t\t\t\t\t\tif (error instanceof CancelledWorkflowError) throw error\n\t\t\t\t\t\tthis.state.addError(nodeId, error as Error)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst { nodeId, result } = promiseResult.value\n\t\t\t\t\tthis.state.addCompletedNode(nodeId, result.output)\n\t\t\t\t\tcompletedThisTurn.add(nodeId)\n\t\t\t\t\tif (result._fallbackExecuted) this.state.markFallbackExecuted()\n\t\t\t\t\tawait this.handleDynamicNodes(nodeId, result)\n\t\t\t\t\tif (!result._fallbackExecuted) {\n\t\t\t\t\t\tconst matched = await this.runtime.determineNextNodes(\n\t\t\t\t\t\t\tthis.dynamicBlueprint,\n\t\t\t\t\t\t\tnodeId,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tthis.state.getContext(),\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\t// if one of the next nodes is a loop controller, prioritize it to avoid ambiguity from manual cycle edges.\n\t\t\t\t\t\tconst loopControllerMatch = matched.find((m) => m.node.uses === 'loop-controller')\n\t\t\t\t\t\tconst finalMatched = loopControllerMatch ? [loopControllerMatch] : matched\n\n\t\t\t\t\t\tfor (const { node, edge } of finalMatched) {\n\t\t\t\t\t\t\tconst joinStrategy = this.getEffectiveJoinStrategy(node.id)\n\t\t\t\t\t\t\tif (joinStrategy !== 'any' && this.state.getCompletedNodes().has(node.id)) continue\n\t\t\t\t\t\t\tawait this.runtime.applyEdgeTransform(edge, result, node, this.state.getContext(), this.allPredecessors)\n\t\t\t\t\t\t\tconst requiredPredecessors = this.allPredecessors.get(node.id)\n\t\t\t\t\t\t\tif (!requiredPredecessors) continue\n\t\t\t\t\t\t\tconst isReady =\n\t\t\t\t\t\t\t\tjoinStrategy === 'any'\n\t\t\t\t\t\t\t\t\t? [...requiredPredecessors].some((p) => completedThisTurn.has(p))\n\t\t\t\t\t\t\t\t\t: [...requiredPredecessors].every((p) => this.state.getCompletedNodes().has(p))\n\t\t\t\t\t\t\tif (isReady) this.frontier.add(node.id)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (matched.length === 0) {\n\t\t\t\t\t\t\tfor (const [potentialNextId, predecessors] of this.allPredecessors) {\n\t\t\t\t\t\t\t\tif (predecessors.has(nodeId) && !this.state.getCompletedNodes().has(potentialNextId)) {\n\t\t\t\t\t\t\t\t\tconst joinStrategy = this.getEffectiveJoinStrategy(potentialNextId)\n\t\t\t\t\t\t\t\t\tconst isReady =\n\t\t\t\t\t\t\t\t\t\tjoinStrategy === 'any'\n\t\t\t\t\t\t\t\t\t\t\t? [...predecessors].some((p) => completedThisTurn.has(p))\n\t\t\t\t\t\t\t\t\t\t\t: [...predecessors].every((p) => this.state.getCompletedNodes().has(p))\n\t\t\t\t\t\t\t\t\tif (isReady) this.frontier.add(potentialNextId)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async executeWithConcurrency(\n\t\tnodeIds: string[],\n\t): Promise<\n\t\tArray<\n\t\t\t| { status: 'fulfilled'; value: { nodeId: string; result: NodeResult<any, any> } }\n\t\t\t| { status: 'rejected'; reason: { nodeId: string; error: unknown } }\n\t\t>\n\t> {\n\t\tconst maxConcurrency = this.concurrency || nodeIds.length\n\t\tconst results: Array<\n\t\t\t| { status: 'fulfilled'; value: { nodeId: string; result: NodeResult<any, any> } }\n\t\t\t| { status: 'rejected'; reason: { nodeId: string; error: unknown } }\n\t\t> = []\n\n\t\tfor (let i = 0; i < nodeIds.length; i += maxConcurrency) {\n\t\t\tconst batch = nodeIds.slice(i, i + maxConcurrency)\n\t\t\tconst batchPromises = batch.map(async (nodeId) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await this.runtime.executeNode(\n\t\t\t\t\t\tthis.dynamicBlueprint,\n\t\t\t\t\t\tnodeId,\n\t\t\t\t\t\tthis.state,\n\t\t\t\t\t\tthis.allPredecessors,\n\t\t\t\t\t\tthis.functionRegistry,\n\t\t\t\t\t\tthis.executionId,\n\t\t\t\t\t\tthis.signal,\n\t\t\t\t\t)\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tstatus: 'fulfilled' as const,\n\t\t\t\t\t\tvalue: { nodeId, result },\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tstatus: 'rejected' as const,\n\t\t\t\t\t\treason: { nodeId, error },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tawait Promise.all(batchPromises)\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprivate async handleDynamicNodes(nodeId: string, result: NodeResult<any, any>) {\n\t\tif (result.dynamicNodes && result.dynamicNodes.length > 0) {\n\t\t\tconst gatherNodeId = result.output?.gatherNodeId\n\t\t\tfor (const dynamicNode of result.dynamicNodes) {\n\t\t\t\tconst implementation = this.functionRegistry?.get(dynamicNode.uses) || this.runtime.registry[dynamicNode.uses]\n\t\t\t\tif (!implementation) {\n\t\t\t\t\tthrow new NodeExecutionError(\n\t\t\t\t\t\t`Implementation for '${dynamicNode.uses}' not found for dynamic node '${dynamicNode.id}' generated by node '${nodeId}'.`,\n\t\t\t\t\t\tdynamicNode.id,\n\t\t\t\t\t\tthis.dynamicBlueprint.id,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tthis.executionId,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tthis.dynamicBlueprint.nodes.push(dynamicNode)\n\t\t\t\tthis.allPredecessors.set(dynamicNode.id, new Set([nodeId]))\n\t\t\t\tif (gatherNodeId) {\n\t\t\t\t\tthis.allPredecessors.get(gatherNodeId)?.add(dynamicNode.id)\n\t\t\t\t}\n\t\t\t\tthis.frontier.add(dynamicNode.id)\n\t\t\t}\n\t\t}\n\t}\n\n\tgetAllNodeIds(): Set<string> {\n\t\treturn new Set(this.dynamicBlueprint.nodes.map((n) => n.id))\n\t}\n\n\tgetFallbackNodeIds(): Set<string> {\n\t\tconst fallbackNodeIds = new Set<string>()\n\t\tfor (const node of this.dynamicBlueprint.nodes) {\n\t\t\tif (node.config?.fallback) fallbackNodeIds.add(node.config.fallback)\n\t\t}\n\t\treturn fallbackNodeIds\n\t}\n\n\tgetDynamicBlueprint(): WorkflowBlueprint {\n\t\treturn this.dynamicBlueprint\n\t}\n}\n"]}