flowcraft 2.2.0 → 2.3.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.
Files changed (147) hide show
  1. package/README.md +40 -34
  2. package/dist/analysis.d.ts +3 -1
  3. package/dist/chunk-33NO4PUJ.js +74 -0
  4. package/dist/chunk-33NO4PUJ.js.map +1 -0
  5. package/dist/chunk-5KKSQWSC.js +90 -0
  6. package/dist/chunk-5KKSQWSC.js.map +1 -0
  7. package/dist/{chunk-QLGJUDQF.js → chunk-6INWPSZT.js} +6 -6
  8. package/dist/chunk-6INWPSZT.js.map +1 -0
  9. package/dist/chunk-BC4G7OM6.js +42 -0
  10. package/dist/chunk-BC4G7OM6.js.map +1 -0
  11. package/dist/chunk-BCRWXTWX.js +21 -0
  12. package/dist/chunk-BCRWXTWX.js.map +1 -0
  13. package/dist/{chunk-ZCHFZBGL.js → chunk-C4HYIJI3.js} +120 -5
  14. package/dist/chunk-C4HYIJI3.js.map +1 -0
  15. package/dist/chunk-CD3Q4N6V.js +13 -0
  16. package/dist/chunk-CD3Q4N6V.js.map +1 -0
  17. package/dist/chunk-CD4FUZOJ.js +114 -0
  18. package/dist/chunk-CD4FUZOJ.js.map +1 -0
  19. package/dist/chunk-CY755I7I.js +25 -0
  20. package/dist/chunk-CY755I7I.js.map +1 -0
  21. package/dist/chunk-DL7KVYZF.js +39 -0
  22. package/dist/chunk-DL7KVYZF.js.map +1 -0
  23. package/dist/chunk-FRKO3WX4.js +32 -0
  24. package/dist/chunk-FRKO3WX4.js.map +1 -0
  25. package/dist/chunk-G53CSLBF.js +54 -0
  26. package/dist/chunk-G53CSLBF.js.map +1 -0
  27. package/dist/chunk-G5BGBPFP.js +172 -0
  28. package/dist/chunk-G5BGBPFP.js.map +1 -0
  29. package/dist/chunk-HAZ26F3P.js +98 -0
  30. package/dist/chunk-HAZ26F3P.js.map +1 -0
  31. package/dist/chunk-IB2BISIC.js +446 -0
  32. package/dist/chunk-IB2BISIC.js.map +1 -0
  33. package/dist/{chunk-U5V5O5MN.js → chunk-LNK7LZER.js} +5 -3
  34. package/dist/chunk-LNK7LZER.js.map +1 -0
  35. package/dist/chunk-MCGK3FXQ.js +143 -0
  36. package/dist/chunk-MCGK3FXQ.js.map +1 -0
  37. package/dist/chunk-MUYLRTSR.js +82 -0
  38. package/dist/chunk-MUYLRTSR.js.map +1 -0
  39. package/dist/chunk-NVJ3ZO3P.js +3 -0
  40. package/dist/{chunk-HMR2GEGE.js.map → chunk-NVJ3ZO3P.js.map} +1 -1
  41. package/dist/chunk-NVLZFLYM.js +3 -0
  42. package/dist/chunk-NVLZFLYM.js.map +1 -0
  43. package/dist/chunk-ONH7PIJZ.js +300 -0
  44. package/dist/chunk-ONH7PIJZ.js.map +1 -0
  45. package/dist/chunk-QNYXQKFW.js +25 -0
  46. package/dist/chunk-QNYXQKFW.js.map +1 -0
  47. package/dist/chunk-RM677CNU.js +52 -0
  48. package/dist/chunk-RM677CNU.js.map +1 -0
  49. package/dist/chunk-WWGFIYKW.js +47 -0
  50. package/dist/chunk-WWGFIYKW.js.map +1 -0
  51. package/dist/chunk-XNRIM27H.js +76 -0
  52. package/dist/chunk-XNRIM27H.js.map +1 -0
  53. package/dist/container-factory.d.ts +17 -0
  54. package/dist/container-factory.js +13 -0
  55. package/dist/container-factory.js.map +1 -0
  56. package/dist/container.d.ts +23 -0
  57. package/dist/container.js +3 -0
  58. package/dist/container.js.map +1 -0
  59. package/dist/context.d.ts +3 -1
  60. package/dist/errors.d.ts +18 -17
  61. package/dist/errors.js +1 -1
  62. package/dist/evaluator.d.ts +3 -1
  63. package/dist/flow.d.ts +12 -2
  64. package/dist/flow.js +2 -2
  65. package/dist/index.d.ts +7 -8
  66. package/dist/index.js +26 -14
  67. package/dist/linter.d.ts +3 -1
  68. package/dist/logger.d.ts +3 -1
  69. package/dist/node.d.ts +3 -1
  70. package/dist/node.js +1 -1
  71. package/dist/nodes/batch-gather.d.ts +9 -0
  72. package/dist/nodes/batch-gather.js +4 -0
  73. package/dist/nodes/batch-gather.js.map +1 -0
  74. package/dist/nodes/batch-scatter.d.ts +9 -0
  75. package/dist/nodes/batch-scatter.js +4 -0
  76. package/dist/nodes/batch-scatter.js.map +1 -0
  77. package/dist/nodes/subflow.d.ts +9 -0
  78. package/dist/nodes/subflow.js +10 -0
  79. package/dist/nodes/subflow.js.map +1 -0
  80. package/dist/nodes/wait.d.ts +9 -0
  81. package/dist/nodes/wait.js +4 -0
  82. package/dist/nodes/wait.js.map +1 -0
  83. package/dist/runtime/adapter.d.ts +3 -5
  84. package/dist/runtime/adapter.js +19 -9
  85. package/dist/runtime/execution-context.d.ts +3 -0
  86. package/dist/runtime/execution-context.js +6 -0
  87. package/dist/runtime/execution-context.js.map +1 -0
  88. package/dist/runtime/executors.d.ts +3 -26
  89. package/dist/runtime/executors.js +2 -2
  90. package/dist/runtime/index.d.ts +5 -7
  91. package/dist/runtime/index.js +21 -10
  92. package/dist/runtime/node-executor-factory.d.ts +12 -0
  93. package/dist/runtime/node-executor-factory.js +6 -0
  94. package/dist/runtime/node-executor-factory.js.map +1 -0
  95. package/dist/runtime/orchestrator.d.ts +9 -0
  96. package/dist/runtime/orchestrator.js +8 -0
  97. package/dist/runtime/orchestrator.js.map +1 -0
  98. package/dist/runtime/orchestrators/step-by-step.d.ts +16 -0
  99. package/dist/runtime/orchestrators/step-by-step.js +5 -0
  100. package/dist/runtime/orchestrators/step-by-step.js.map +1 -0
  101. package/dist/runtime/orchestrators/utils.d.ts +35 -0
  102. package/dist/runtime/orchestrators/utils.js +4 -0
  103. package/dist/runtime/orchestrators/utils.js.map +1 -0
  104. package/dist/runtime/runtime.d.ts +3 -41
  105. package/dist/runtime/runtime.js +18 -8
  106. package/dist/runtime/state.d.ts +3 -21
  107. package/dist/runtime/state.js +2 -1
  108. package/dist/runtime/traverser.d.ts +3 -26
  109. package/dist/runtime/traverser.js +1 -2
  110. package/dist/runtime/types.d.ts +3 -16
  111. package/dist/runtime/types.js +1 -1
  112. package/dist/runtime/workflow-logic-handler.d.ts +17 -0
  113. package/dist/runtime/workflow-logic-handler.js +5 -0
  114. package/dist/runtime/workflow-logic-handler.js.map +1 -0
  115. package/dist/sanitizer.d.ts +3 -1
  116. package/dist/serializer.d.ts +3 -1
  117. package/dist/testing/event-logger.d.ts +63 -0
  118. package/dist/testing/event-logger.js +3 -0
  119. package/dist/testing/event-logger.js.map +1 -0
  120. package/dist/testing/index.d.ts +6 -0
  121. package/dist/testing/index.js +31 -0
  122. package/dist/testing/index.js.map +1 -0
  123. package/dist/testing/run-with-trace.d.ts +38 -0
  124. package/dist/testing/run-with-trace.js +29 -0
  125. package/dist/testing/run-with-trace.js.map +1 -0
  126. package/dist/testing/stepper.d.ts +79 -0
  127. package/dist/testing/stepper.js +11 -0
  128. package/dist/testing/stepper.js.map +1 -0
  129. package/dist/types-ezHUBdpL.d.ts +564 -0
  130. package/dist/types.d.ts +3 -1
  131. package/package.json +55 -51
  132. package/LICENSE +0 -21
  133. package/dist/chunk-5ZXV3R5D.js +0 -28
  134. package/dist/chunk-5ZXV3R5D.js.map +0 -1
  135. package/dist/chunk-GEKDR2SS.js +0 -201
  136. package/dist/chunk-GEKDR2SS.js.map +0 -1
  137. package/dist/chunk-HMR2GEGE.js +0 -3
  138. package/dist/chunk-M2FRTT2K.js +0 -144
  139. package/dist/chunk-M2FRTT2K.js.map +0 -1
  140. package/dist/chunk-OTS5YJ3S.js +0 -494
  141. package/dist/chunk-OTS5YJ3S.js.map +0 -1
  142. package/dist/chunk-QLGJUDQF.js.map +0 -1
  143. package/dist/chunk-U5V5O5MN.js.map +0 -1
  144. package/dist/chunk-VSGQDLBF.js +0 -61
  145. package/dist/chunk-VSGQDLBF.js.map +0 -1
  146. package/dist/chunk-ZCHFZBGL.js.map +0 -1
  147. package/dist/types-CsTeXTiA.d.ts +0 -222
package/README.md CHANGED
@@ -8,15 +8,15 @@ Build complex, multi-step processes with a lightweight, composable, and type-saf
8
8
 
9
9
  ## Key Features
10
10
 
11
- - **Zero Dependencies**: Lightweight and dependency-free, ensuring a small footprint and easy integration.
12
- - **Declarative Workflows**: Define workflows as serializable objects with nodes and edges.
13
- - **Unopinionated Logic**: Nodes can be simple functions or structured classes, supporting any logic.
14
- - **Progressive Scalability**: Run in-memory or scale to distributed systems using the same blueprint.
15
- - **Resilient Execution**: Built-in support for retries, fallbacks, timeouts, and graceful cancellation.
16
- - **Advanced Patterns**: Includes batch processing and loop constructs for complex workflows.
17
- - **Extensibility**: Pluggable loggers, evaluators, serializers, and middleware for custom behavior.
18
- - **Static Analysis**: Tools to detect cycles, validate blueprints, and generate visual diagrams.
19
- - **Type-Safe API**: Fully typed with TypeScript for a robust developer experience.
11
+ - **Zero Dependencies**: Lightweight and dependency-free, ensuring easy integration in any runtime.
12
+ - **Declarative Workflows**: Define workflows as [serializable](https://flowcraft.js.org/guide/core-concepts#workflow-blueprint) objects with [nodes and edges](https://flowcraft.js.org/guide/core-concepts#nodes-edges).
13
+ - **Unopinionated Logic**: Nodes can be simple [functions](https://flowcraft.js.org/guide/core-concepts#function-based-nodes) or structured [classes](https://flowcraft.js.org/guide/core-concepts#class-based-nodes), supporting any logic.
14
+ - **Progressive Scalability**: Run [in-memory](https://flowcraft.js.org/guide/programmatic) or scale to [distributed systems](https://flowcraft.js.org/guide/distributed-execution) using the same blueprint.
15
+ - **Resilient Execution**: Built-in support for [retries](https://flowcraft.js.org/guide/error-handling#retries), [fallbacks](https://flowcraft.js.org/guide/error-handling#fallbacks), [timeouts](https://flowcraft.js.org/guide/core-concepts#config), and [cancellation](https://flowcraft.js.org/guide/core-concepts#cancellation).
16
+ - **Advanced Patterns**: Includes [batches](https://flowcraft.js.org/guide/batches), [loops](https://flowcraft.js.org/guide/loops), [subflows](https://flowcraft.js.org/guide/subflows), and [HITL](https://flowcraft.js.org/guide/hitl) constructs for complex workflows.
17
+ - **Extensibility**: Pluggable [loggers](https://flowcraft.js.org/guide/loggers), [evaluators](https://flowcraft.js.org/guide/evaluators), [serializers](https://flowcraft.js.org/guide/serializers), and [middleware](https://flowcraft.js.org/guide/middleware) for custom behavior.
18
+ - **Static Analysis**: Tools to [detect cycles](https://flowcraft.js.org/guide/static-analysis#detecting-cycles), [validate blueprints](https://flowcraft.js.org/guide/static-analysis#linting-a-blueprint), and [generate visual diagrams](https://flowcraft.js.org/guide/visualizing-workflows#generatemermaid).
19
+ - **Type-Safe API**: [Fully typed](https://flowcraft.js.org/guide/core-concepts#context) with TypeScript for a robust developer experience.
20
20
 
21
21
  ## Installation
22
22
 
@@ -32,21 +32,27 @@ Define and run a simple workflow in a few lines of code.
32
32
  ```typescript
33
33
  import { createFlow, FlowRuntime } from 'flowcraft'
34
34
 
35
- // 1. Define the workflow structure using the fluent API
35
+ // 1. Define your functions for the nodes
36
+ async function startNode({ context }: NodeContext) {
37
+ const output = await context.get('value')
38
+ return { output }
39
+ }
40
+ async function doubleNode({ input }: NodeContext) {
41
+ return { output: input * 2 }
42
+ }
43
+
44
+ // 2. Define the workflow structure
36
45
  const flow = createFlow('simple-workflow')
37
- .node('start', async () => ({ output: 42 }))
38
- .node('double', async ({ input }) => ({ output: input * 2 }))
46
+ .node('start', startNode)
47
+ .node('double', doubleNode)
39
48
  .edge('start', 'double')
40
- .toBlueprint()
41
49
 
42
- // 2. Create a runtime with the node implementations
43
- const runtime = new FlowRuntime({
44
- registry: flow.getFunctionRegistry(),
45
- })
50
+ // 3. Initialize the runtime
51
+ const runtime = new FlowRuntime()
46
52
 
47
- // 3. Execute the workflow
53
+ // 4. Execute the workflow
48
54
  async function run() {
49
- const result = await runtime.run(flow)
55
+ const result = await runtime.run(blueprint, { value: 42 })
50
56
  console.log(result.context) // { start: 42, double: 84 }
51
57
  console.log(result.status) // 'completed'
52
58
  }
@@ -56,18 +62,18 @@ run()
56
62
 
57
63
  ## Core Concepts
58
64
 
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.
65
+ - **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.
66
+ - **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.
67
+ - **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.
68
+ - **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.
69
+ - **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
70
 
65
71
  ## Resiliency and Error Handling
66
72
 
67
73
  Design robust workflows with built-in resiliency features.
68
74
 
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.
75
+ - **Retries**: Configure the `maxRetries` property on a node to automatically retry it on failure.
76
+ - **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
77
 
72
78
  For more granular control, you can implement a node using the `BaseNode` class, which provides `prep`, `exec`, `post`, `fallback`, and `recover` lifecycle methods.
73
79
 
@@ -75,19 +81,19 @@ For more granular control, you can implement a node using the `BaseNode` class,
75
81
 
76
82
  Flowcraft includes tools to help you validate and visualize your workflows.
77
83
 
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.
84
+ - **Linter (`lintBlueprint`)**: Statically analyze a blueprint to find common errors, such as orphan nodes, invalid edges, or nodes with missing implementations.
85
+ - **Analysis (`analyzeBlueprint`)**: Programmatically inspect a blueprint to detect cycles, find start/terminal nodes, and get other graph metrics.
86
+ - **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
87
 
82
88
  ## Extensibility and Customization
83
89
 
84
90
  The `FlowRuntime` can be configured with pluggable components to tailor its behavior to your specific needs:
85
91
 
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.).
92
+ - **Logger**: Provide a custom `ILogger` implementation (e.g., Pino, Winston) to integrate with your existing logging infrastructure.
93
+ - **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.
94
+ - **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.
95
+ - **Middleware**: Wrap node execution with custom logic for cross-cutting concerns like distributed tracing, performance monitoring, or advanced authorization.
96
+ - **Event Bus**: An event emitter for monitoring workflow and node lifecycle events (`workflow:start`, `node:finish`, etc.).
91
97
 
92
98
  ## Distributed Execution
93
99
 
@@ -1,4 +1,6 @@
1
- import { W as WorkflowBlueprint } from './types-CsTeXTiA.js';
1
+ import { g as WorkflowBlueprint } from './types-ezHUBdpL.js';
2
+ import './errors.js';
3
+ import './container.js';
2
4
 
3
5
  /**
4
6
  * A list of cycles found in the graph. Each cycle is an array of node IDs.
@@ -0,0 +1,74 @@
1
+ import { executeBatch, processResults } from './chunk-HAZ26F3P.js';
2
+ import { ExecutionContext } from './chunk-FRKO3WX4.js';
3
+ import { FlowcraftError } from './chunk-BCRWXTWX.js';
4
+
5
+ // src/runtime/orchestrator.ts
6
+ var DefaultOrchestrator = class {
7
+ async run(context, traverser) {
8
+ const hardwareConcurrency = globalThis.navigator?.hardwareConcurrency || 4;
9
+ const maxConcurrency = context.concurrency ?? Math.min(hardwareConcurrency, 10);
10
+ try {
11
+ context.signal?.throwIfAborted();
12
+ } catch (error) {
13
+ if (error instanceof DOMException && error.name === "AbortError") {
14
+ throw new FlowcraftError("Workflow cancelled", { isFatal: false });
15
+ }
16
+ throw error;
17
+ }
18
+ let iterations = 0;
19
+ const maxIterations = 1e4;
20
+ while (traverser.hasMoreWork()) {
21
+ if (++iterations > maxIterations) {
22
+ throw new Error("Traversal exceeded maximum iterations, possible infinite loop");
23
+ }
24
+ try {
25
+ context.signal?.throwIfAborted();
26
+ } catch (error) {
27
+ if (error instanceof DOMException && error.name === "AbortError") {
28
+ throw new FlowcraftError("Workflow cancelled", { isFatal: false });
29
+ }
30
+ throw error;
31
+ }
32
+ const readyNodes = traverser.getReadyNodes();
33
+ const dynamicBlueprint = traverser.getDynamicBlueprint();
34
+ const updatedContext = new ExecutionContext(
35
+ dynamicBlueprint,
36
+ context.state,
37
+ context.nodeRegistry,
38
+ context.executionId,
39
+ context.runtime,
40
+ context.services,
41
+ context.signal,
42
+ context.concurrency
43
+ );
44
+ const settledResults = await executeBatch(
45
+ readyNodes,
46
+ dynamicBlueprint,
47
+ context.state,
48
+ (nodeId) => context.runtime.getExecutorForNode(nodeId, updatedContext),
49
+ context.runtime,
50
+ maxConcurrency
51
+ );
52
+ await processResults(
53
+ settledResults,
54
+ traverser,
55
+ context.state,
56
+ context.runtime,
57
+ context.blueprint,
58
+ context.executionId
59
+ );
60
+ if (context.state.isAwaiting()) {
61
+ break;
62
+ }
63
+ }
64
+ const isTraversalComplete = !traverser.hasMoreWork();
65
+ const status = context.state.getStatus(isTraversalComplete);
66
+ const result = await context.state.toResult(context.services.serializer);
67
+ result.status = status;
68
+ return result;
69
+ }
70
+ };
71
+
72
+ export { DefaultOrchestrator };
73
+ //# sourceMappingURL=chunk-33NO4PUJ.js.map
74
+ //# sourceMappingURL=chunk-33NO4PUJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/orchestrator.ts"],"names":[],"mappings":";;;;;AAOO,IAAM,sBAAN,MAAmD;AAAA,EACzD,MAAM,GAAA,CAAI,OAAA,EAAqC,SAAA,EAAyD;AACvG,IAAA,MAAM,mBAAA,GAAsB,UAAA,CAAW,SAAA,EAAW,mBAAA,IAAuB,CAAA;AACzE,IAAA,MAAM,iBAAiB,OAAA,CAAQ,WAAA,IAAe,IAAA,CAAK,GAAA,CAAI,qBAAqB,EAAE,CAAA;AAE9E,IAAA,IAAI;AACH,MAAA,OAAA,CAAQ,QAAQ,cAAA,EAAe;AAAA,IAChC,SAAS,KAAA,EAAO;AACf,MAAA,IAAI,KAAA,YAAiB,YAAA,IAAgB,KAAA,CAAM,IAAA,KAAS,YAAA,EAAc;AACjE,QAAA,MAAM,IAAI,cAAA,CAAe,oBAAA,EAAsB,EAAE,OAAA,EAAS,OAAO,CAAA;AAAA,MAClE;AACA,MAAA,MAAM,KAAA;AAAA,IACP;AAEA,IAA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AA,CAAQ,OAAA;AAAA,QACR,OAAA,CAAQ,SAAA;AAAA,QACR,OAAA,CAAQ;AAAA,OACT;AAEA,MAAA,IAAI,OAAA,CAAQ,KAAA,CAAM,UAAA,EAAW,EAAG;AAC/B,QAAA;AAAA,MACD;AAAA,IACD;AAEA,IAAA,MAAM,mBAAA,GAAsB,CAAC,SAAA,CAAU,WAAA,EAAY;AACnD,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,KAAA,CAAM,SAAA,CAAU,mBAAmB,CAAA;AAC1D,IAAA,MAAM,SAAS,MAAM,OAAA,CAAQ,MAAM,QAAA,CAAS,OAAA,CAAQ,SAAS,UAAU,CAAA;AACvE,IAAA,MAAA,CAAO,MAAA,GAAS,MAAA;AAChB,IAAA,OAAO,MAAA;AAAA,EACR;AACD","file":"chunk-33NO4PUJ.js","sourcesContent":["import { FlowcraftError } from '../errors'\nimport type { WorkflowResult } from '../types'\nimport { ExecutionContext } from './execution-context'\nimport { executeBatch, processResults } from './orchestrators/utils'\nimport type { GraphTraverser } from './traverser'\nimport type { IOrchestrator } from './types'\n\nexport class DefaultOrchestrator implements IOrchestrator {\n\tasync run(context: ExecutionContext<any, any>, traverser: GraphTraverser): Promise<WorkflowResult<any>> {\n\t\tconst hardwareConcurrency = globalThis.navigator?.hardwareConcurrency || 4\n\t\tconst maxConcurrency = context.concurrency ?? Math.min(hardwareConcurrency, 10)\n\n\t\ttry {\n\t\t\tcontext.signal?.throwIfAborted()\n\t\t} catch (error) {\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\tthrow new FlowcraftError('Workflow cancelled', { isFatal: false })\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\n\t\tlet iterations = 0\n\t\tconst maxIterations = 10000\n\n\t\twhile (traverser.hasMoreWork()) {\n\t\t\tif (++iterations > maxIterations) {\n\t\t\t\tthrow new Error('Traversal exceeded maximum iterations, possible infinite loop')\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tcontext.signal?.throwIfAborted()\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\tthrow new FlowcraftError('Workflow cancelled', { isFatal: false })\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\n\t\t\tconst readyNodes = traverser.getReadyNodes()\n\t\t\tconst dynamicBlueprint = traverser.getDynamicBlueprint()\n\t\t\tconst updatedContext = new ExecutionContext(\n\t\t\t\tdynamicBlueprint,\n\t\t\t\tcontext.state,\n\t\t\t\tcontext.nodeRegistry,\n\t\t\t\tcontext.executionId,\n\t\t\t\tcontext.runtime,\n\t\t\t\tcontext.services,\n\t\t\t\tcontext.signal,\n\t\t\t\tcontext.concurrency,\n\t\t\t)\n\t\t\tconst settledResults = await executeBatch(\n\t\t\t\treadyNodes,\n\t\t\t\tdynamicBlueprint,\n\t\t\t\tcontext.state,\n\t\t\t\t(nodeId: string) => context.runtime.getExecutorForNode(nodeId, updatedContext),\n\t\t\t\tcontext.runtime,\n\t\t\t\tmaxConcurrency,\n\t\t\t)\n\n\t\t\tawait processResults(\n\t\t\t\tsettledResults,\n\t\t\t\ttraverser,\n\t\t\t\tcontext.state,\n\t\t\t\tcontext.runtime,\n\t\t\t\tcontext.blueprint,\n\t\t\t\tcontext.executionId,\n\t\t\t)\n\n\t\t\tif (context.state.isAwaiting()) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst isTraversalComplete = !traverser.hasMoreWork()\n\t\tconst status = context.state.getStatus(isTraversalComplete)\n\t\tconst result = await context.state.toResult(context.services.serializer)\n\t\tresult.status = status\n\t\treturn result\n\t}\n}\n"]}
@@ -0,0 +1,90 @@
1
+ import { GraphTraverser } from './chunk-G5BGBPFP.js';
2
+ import { analyzeBlueprint } from './chunk-233SESC2.js';
3
+ import { ExecutionContext } from './chunk-FRKO3WX4.js';
4
+ import { WorkflowState } from './chunk-CD4FUZOJ.js';
5
+ import { FlowcraftError } from './chunk-BCRWXTWX.js';
6
+ import { BaseNode } from './chunk-LNK7LZER.js';
7
+
8
+ // src/nodes/subflow.ts
9
+ var SubflowNode = class extends BaseNode {
10
+ async exec(_prepResult, context) {
11
+ const { blueprintId, inputs, outputs } = this.params ?? {};
12
+ const { runtime, workflowState } = context.dependencies;
13
+ if (!blueprintId) {
14
+ throw new FlowcraftError(`Subflow node '${this.nodeId}' is missing 'blueprintId' parameter.`, { isFatal: true });
15
+ }
16
+ const subBlueprint = runtime.blueprints?.[blueprintId] || runtime.runtime?.blueprints?.[blueprintId];
17
+ if (!subBlueprint) {
18
+ throw new FlowcraftError(`Sub-blueprint '${blueprintId}' not found in runtime registry.`, { isFatal: true });
19
+ }
20
+ const subflowInitialContext = {};
21
+ if (inputs) {
22
+ for (const [targetKey, sourceKey] of Object.entries(inputs)) {
23
+ let value = await context.context.get(sourceKey);
24
+ if (value === void 0) {
25
+ value = await context.context.get(`_outputs.${sourceKey}`);
26
+ }
27
+ subflowInitialContext[targetKey] = value;
28
+ }
29
+ } else if (context.input !== void 0) {
30
+ const subAnalysis2 = analyzeBlueprint(subBlueprint);
31
+ for (const startNodeId of subAnalysis2.startNodeIds) {
32
+ const inputKey = `_inputs.${startNodeId}`;
33
+ subflowInitialContext[inputKey] = context.input;
34
+ }
35
+ }
36
+ const subflowState = new WorkflowState(subflowInitialContext);
37
+ const subflowExecContext = new ExecutionContext(
38
+ subBlueprint,
39
+ subflowState,
40
+ runtime.nodeRegistry,
41
+ runtime.executionId,
42
+ runtime.runtime,
43
+ runtime.services,
44
+ runtime.signal,
45
+ runtime.concurrency
46
+ );
47
+ const subflowTraverser = new GraphTraverser(subBlueprint);
48
+ const subflowResult = await runtime.runtime.orchestrator.run(subflowExecContext, subflowTraverser);
49
+ if (subflowResult.status === "awaiting") {
50
+ workflowState.markAsAwaiting(this.nodeId ?? "");
51
+ const subflowStateKey = `_subflowState.${this.nodeId}`;
52
+ await context.context.set(subflowStateKey, subflowResult.serializedContext);
53
+ return { output: void 0 };
54
+ }
55
+ if (subflowResult.status !== "completed") {
56
+ const firstError = subflowResult.errors?.[0];
57
+ const errorMessage = firstError?.message || "Unknown error";
58
+ throw new FlowcraftError(
59
+ `Sub-workflow '${blueprintId}' did not complete successfully. Status: ${subflowResult.status}. Error: ${errorMessage}`,
60
+ {
61
+ cause: firstError,
62
+ nodeId: this.nodeId,
63
+ blueprintId
64
+ }
65
+ );
66
+ }
67
+ const subflowFinalContext = subflowResult.context;
68
+ if (outputs) {
69
+ for (const [parentKey, subKey] of Object.entries(outputs)) {
70
+ const value = subflowFinalContext[`_outputs.${subKey}`] ?? subflowFinalContext[subKey];
71
+ await context.context.set(parentKey, value);
72
+ }
73
+ return { output: subflowFinalContext };
74
+ }
75
+ const subAnalysis = analyzeBlueprint(subBlueprint);
76
+ if (subAnalysis.terminalNodeIds.length === 1) {
77
+ const terminalId = subAnalysis.terminalNodeIds[0];
78
+ return { output: subflowFinalContext[`_outputs.${terminalId}`] };
79
+ }
80
+ const terminalOutputs = {};
81
+ for (const terminalId of subAnalysis.terminalNodeIds) {
82
+ terminalOutputs[terminalId] = subflowFinalContext[`_outputs.${terminalId}`];
83
+ }
84
+ return terminalOutputs;
85
+ }
86
+ };
87
+
88
+ export { SubflowNode };
89
+ //# sourceMappingURL=chunk-5KKSQWSC.js.map
90
+ //# sourceMappingURL=chunk-5KKSQWSC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/nodes/subflow.ts"],"names":["subAnalysis"],"mappings":";;;;;;;;AAQO,IAAM,WAAA,GAAN,cAA0B,QAAA,CAAS;AAAA,EACzC,MAAM,IAAA,CACL,WAAA,EACA,OAAA,EACqC;AACrC,IAAA,MAAM,EAAE,WAAA,EAAa,MAAA,EAAQ,SAAQ,GAAI,IAAA,CAAK,UAAU,EAAC;AACzD,IAAA,MAAM,EAAE,OAAA,EAAS,aAAA,EAAc,GAAI,OAAA,CAAQ,YAAA;AAE3C,IAAA,IAAI,CAAC,WAAA,EAAa;AACjB,MAAA,MAAM,IAAI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ACZ,MAAA,KAAA,MAAW,CAAC,SAAA,EAAW,MAAM,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAiC,CAAA,EAAG;AACpF,QAAA,MAAM,QAAQ,mBAAA,CAAoB,CAAA,SAAA,EAAY,MAAM,CAAA,CAAE,CAAA,IAAK,oBAAoB,MAAM,CAAA;AACrF,QAAA,MAAM,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAkB,KAAK,CAAA;AAAA,MAClD;AACA,MAAA,OAAO,EAAE,QAAQ,mBAAA,EAAoB;AAAA,IACtC;AAEA,IAAA,MAAM,WAAA,GAAc,iBAAiB,YAAY,CAAA;AACjD,IAAA,IAAI,WAAA,CAAY,eAAA,CAAgB,MAAA,KAAW,CAAA,EAAG;AAC7C,MAAA,MAAM,UAAA,GAAa,WAAA,CAAY,eAAA,CAAgB,CAAC,CAAA;AAChD,MAAA,OAAO,EAAE,MAAA,EAAQ,mBAAA,CAAoB,CAAA,SAAA,EAAY,UAAU,EAAE,CAAA,EAAE;AAAA,IAChE;AAEA,IAAA,MAAM,kBAAuC,EAAC;AAC9C,IAAA,KAAA,MAAW,UAAA,IAAc,YAAY,eAAA,EAAiB;AACrD,MAAA,eAAA,CAAgB,UAAU,CAAA,GAAI,mBAAA,CAAoB,CAAA,SAAA,EAAY,UAAU,CAAA,CAAE,CAAA;AAAA,IAC3E;AACA,IAAA,OAAO,eAAA;AAAA,EACR;AACD","file":"chunk-5KKSQWSC.js","sourcesContent":["import { analyzeBlueprint } from '../analysis'\nimport { FlowcraftError } from '../errors'\nimport { BaseNode } from '../node'\nimport { ExecutionContext } from '../runtime/execution-context'\nimport { WorkflowState } from '../runtime/state'\nimport { GraphTraverser } from '../runtime/traverser'\nimport type { NodeContext, NodeResult } from '../types'\n\nexport class SubflowNode extends BaseNode {\n\tasync exec(\n\t\t_prepResult: any,\n\t\tcontext: NodeContext<Record<string, any>, any, any>,\n\t): Promise<Omit<NodeResult, 'error'>> {\n\t\tconst { blueprintId, inputs, outputs } = this.params ?? {}\n\t\tconst { runtime, workflowState } = context.dependencies\n\n\t\tif (!blueprintId) {\n\t\t\tthrow new FlowcraftError(`Subflow node '${this.nodeId}' is missing 'blueprintId' parameter.`, { isFatal: true })\n\t\t}\n\n\t\tconst subBlueprint =\n\t\t\t(runtime as any).blueprints?.[blueprintId] || (runtime as any).runtime?.blueprints?.[blueprintId]\n\t\tif (!subBlueprint) {\n\t\t\tthrow new FlowcraftError(`Sub-blueprint '${blueprintId}' not found in runtime registry.`, { isFatal: true })\n\t\t}\n\n\t\tconst subflowInitialContext: Record<string, any> = {}\n\n\t\tif (inputs) {\n\t\t\t// explicit inputs\n\t\t\tfor (const [targetKey, sourceKey] of Object.entries(inputs as Record<string, string>)) {\n\t\t\t\tlet value = await context.context.get(sourceKey as any)\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tvalue = await context.context.get(`_outputs.${sourceKey}` as any)\n\t\t\t\t}\n\t\t\t\tsubflowInitialContext[targetKey] = value\n\t\t\t}\n\t\t} else if (context.input !== undefined) {\n\t\t\t// pass the parent node's input to the subflow's start nodes\n\t\t\tconst subAnalysis = analyzeBlueprint(subBlueprint)\n\t\t\tfor (const startNodeId of subAnalysis.startNodeIds) {\n\t\t\t\tconst inputKey = `_inputs.${startNodeId}`\n\t\t\t\tsubflowInitialContext[inputKey] = context.input\n\t\t\t}\n\t\t}\n\n\t\tconst subflowState = new WorkflowState(subflowInitialContext)\n\t\tconst subflowExecContext = new ExecutionContext(\n\t\t\tsubBlueprint,\n\t\t\tsubflowState,\n\t\t\truntime.nodeRegistry,\n\t\t\truntime.executionId,\n\t\t\truntime.runtime,\n\t\t\truntime.services,\n\t\t\truntime.signal,\n\t\t\truntime.concurrency,\n\t\t)\n\t\tconst subflowTraverser = new GraphTraverser(subBlueprint)\n\n\t\tconst subflowResult = await runtime.runtime.orchestrator.run(subflowExecContext, subflowTraverser)\n\n\t\tif (subflowResult.status === 'awaiting') {\n\t\t\tworkflowState.markAsAwaiting(this.nodeId ?? '')\n\t\t\tconst subflowStateKey = `_subflowState.${this.nodeId}`\n\t\t\tawait context.context.set(subflowStateKey as any, subflowResult.serializedContext)\n\t\t\treturn { output: undefined }\n\t\t}\n\n\t\tif (subflowResult.status !== 'completed') {\n\t\t\tconst firstError = subflowResult.errors?.[0]\n\t\t\tconst errorMessage = firstError?.message || 'Unknown error'\n\t\t\tthrow new FlowcraftError(\n\t\t\t\t`Sub-workflow '${blueprintId}' did not complete successfully. Status: ${subflowResult.status}. Error: ${errorMessage}`,\n\t\t\t\t{\n\t\t\t\t\tcause: firstError,\n\t\t\t\t\tnodeId: this.nodeId,\n\t\t\t\t\tblueprintId,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tconst subflowFinalContext = subflowResult.context as Record<string, any>\n\n\t\tif (outputs) {\n\t\t\tfor (const [parentKey, subKey] of Object.entries(outputs as Record<string, string>)) {\n\t\t\t\tconst value = subflowFinalContext[`_outputs.${subKey}`] ?? subflowFinalContext[subKey]\n\t\t\t\tawait context.context.set(parentKey as any, value)\n\t\t\t}\n\t\t\treturn { output: subflowFinalContext } // Return the whole context if mapping is used\n\t\t}\n\n\t\tconst subAnalysis = analyzeBlueprint(subBlueprint)\n\t\tif (subAnalysis.terminalNodeIds.length === 1) {\n\t\t\tconst terminalId = subAnalysis.terminalNodeIds[0]\n\t\t\treturn { output: subflowFinalContext[`_outputs.${terminalId}`] }\n\t\t}\n\n\t\tconst terminalOutputs: Record<string, any> = {}\n\t\tfor (const terminalId of subAnalysis.terminalNodeIds) {\n\t\t\tterminalOutputs[terminalId] = subflowFinalContext[`_outputs.${terminalId}`]\n\t\t}\n\t\treturn terminalOutputs\n\t}\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { FlowRuntime } from './chunk-OTS5YJ3S.js';
2
- import { JsonSerializer } from './chunk-CYHZ2YVH.js';
1
+ import { FlowRuntime } from './chunk-IB2BISIC.js';
3
2
  import { analyzeBlueprint } from './chunk-233SESC2.js';
3
+ import { JsonSerializer } from './chunk-CYHZ2YVH.js';
4
4
 
5
5
  // src/runtime/adapter.ts
6
6
  var BaseDistributedAdapter = class {
@@ -56,7 +56,7 @@ var BaseDistributedAdapter = class {
56
56
  };
57
57
  try {
58
58
  const result = await this.runtime.executeNode(blueprint, nodeId, workerState);
59
- await context.set(nodeId, result.output);
59
+ await context.set(`_outputs.${nodeId}`, result.output);
60
60
  const analysis = analyzeBlueprint(blueprint);
61
61
  const isTerminalNode = analysis.terminalNodeIds.includes(nodeId);
62
62
  if (isTerminalNode) {
@@ -65,7 +65,7 @@ var BaseDistributedAdapter = class {
65
65
  );
66
66
  const allTerminalNodesCompleted = analysis.terminalNodeIds.every((terminalId) => completedNodes.has(terminalId));
67
67
  if (allTerminalNodesCompleted) {
68
- console.log(`[Adapter] \u2705 All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`);
68
+ console.log(`[Adapter] All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`);
69
69
  const finalContext = await context.toJSON();
70
70
  const finalResult = {
71
71
  context: finalContext,
@@ -259,5 +259,5 @@ var BaseDistributedAdapter = class {
259
259
  };
260
260
 
261
261
  export { BaseDistributedAdapter };
262
- //# sourceMappingURL=chunk-QLGJUDQF.js.map
263
- //# sourceMappingURL=chunk-QLGJUDQF.js.map
262
+ //# sourceMappingURL=chunk-6INWPSZT.js.map
263
+ //# sourceMappingURL=chunk-6INWPSZT.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,UAA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IAAI,CAAA;AAEvB,IAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AACnC,MAAA,IAAI,SAAA,EAAW;AACd,QAAA,MAAM,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-6INWPSZT.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(`_outputs.${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"]}
@@ -0,0 +1,42 @@
1
+ import { BaseNode } from './chunk-LNK7LZER.js';
2
+
3
+ // src/nodes/batch-gather.ts
4
+ var BatchGatherNode = class extends BaseNode {
5
+ async exec(_prepResult, context) {
6
+ const { gatherNodeId, outputKey } = this.params || {};
7
+ const hasMore = await context.context.get(`${gatherNodeId}_hasMore`) || false;
8
+ const dynamicNodes = [];
9
+ let results = [];
10
+ if (hasMore) {
11
+ const newScatterId = `${gatherNodeId}_scatter_next`;
12
+ dynamicNodes.push({
13
+ id: newScatterId,
14
+ uses: "batch-scatter",
15
+ inputs: context.input,
16
+ params: { ...this.params, gatherNodeId }
17
+ });
18
+ } else {
19
+ const allWorkerIds = await context.context.get(`${gatherNodeId}_allWorkerIds`) || [];
20
+ results = [];
21
+ for (const workerId of allWorkerIds) {
22
+ const result = await context.context.get(`_outputs.${workerId}`);
23
+ if (result !== void 0) results.push(result);
24
+ }
25
+ await context.context.set(outputKey, results);
26
+ const parentBatchId = gatherNodeId.replace("_gather", "");
27
+ await context.dependencies.runtime.services.eventBus.emit({
28
+ type: "batch:finish",
29
+ payload: {
30
+ batchId: parentBatchId,
31
+ gatherNodeId,
32
+ results
33
+ }
34
+ });
35
+ }
36
+ return { dynamicNodes, output: results };
37
+ }
38
+ };
39
+
40
+ export { BatchGatherNode };
41
+ //# sourceMappingURL=chunk-BC4G7OM6.js.map
42
+ //# sourceMappingURL=chunk-BC4G7OM6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/nodes/batch-gather.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,QAAA,CAAS;AAAA,EAC7C,MAAM,IAAA,CAAK,WAAA,EAAkB,OAAA,EAAyE;AACrG,IAAA,MAAM,EAAE,YAAA,EAAc,SAAA,EAAU,GAAK,IAAA,CAAK,UAAkB,EAAC;AAC7D,IAAA,MAAM,OAAA,GAAW,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAA,EAAG,YAAY,UAAU,CAAA,IAAM,KAAA;AAC1E,IAAA,MAAM,eAAsB,EAAC;AAC7B,IAAA,IAAI,UAAiB,EAAC;AACtB,IAAA,IAAI,OAAA,EAAS;AAEZ,MAAA,MAAM,YAAA,GAAe,GAAG,YAAY,CAAA,aAAA,CAAA;AACpC,MAAA,YAAA,CAAa,IAAA,CAAK;AAAA,QACjB,EAAA,EAAI,YAAA;AAAA,QACJ,IAAA,EAAM,eAAA;AAAA,QACN,QAAQ,OAAA,CAAQ,KAAA;AAAA,QAChB,MAAA,EAAQ,EAAE,GAAG,IAAA,CAAK,QAAQ,YAAA;AAAa,OACvC,CAAA;AAAA,IACF,CAAA,MAAO;AAEN,MAAA,MAAM,YAAA,GAAiB,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAA,EAAG,YAAY,CAAA,aAAA,CAAe,CAAA,IAAmB,EAAC;AACnG,MAAA,OAAA,GAAU,EAAC;AACX,MAAA,KAAA,MAAW,YAAY,YAAA,EAAc;AACpC,QAAA,MAAM,SAAS,MAAM,OAAA,CAAQ,QAAQ,GAAA,CAAI,CAAA,SAAA,EAAY,QAAQ,CAAA,CAAS,CAAA;AACtE,QAAA,IAAI,MAAA,KAAW,MAAA,EAAW,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAA;AAAA,MAC9C;AACA,MAAA,MAAM,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAkB,OAAO,CAAA;AAEnD,MAAA,MAAM,aAAA,GAAgB,YAAA,CAAa,OAAA,CAAQ,SAAA,EAAW,EAAE,CAAA;AACxD,MAAA,MAAM,OAAA,CAAQ,YAAA,CAAa,OAAA,CAAQ,QAAA,CAAS,SAAS,IAAA,CAAK;AAAA,QACzD,IAAA,EAAM,cAAA;AAAA,QACN,OAAA,EAAS;AAAA,UACR,OAAA,EAAS,aAAA;AAAA,UACT,YAAA;AAAA,UACA;AAAA;AACD,OACA,CAAA;AAAA,IACF;AACA,IAAA,OAAO,EAAE,YAAA,EAAc,MAAA,EAAQ,OAAA,EAAQ;AAAA,EACxC;AACD","file":"chunk-BC4G7OM6.js","sourcesContent":["import { BaseNode } from '../node'\nimport type { NodeContext, NodeResult } from '../types'\n\nexport class BatchGatherNode extends BaseNode {\n\tasync exec(_prepResult: any, context: NodeContext<any, any, any>): Promise<Omit<NodeResult, 'error'>> {\n\t\tconst { gatherNodeId, outputKey } = (this.params as any) || {}\n\t\tconst hasMore = (await context.context.get(`${gatherNodeId}_hasMore`)) || false\n\t\tconst dynamicNodes: any[] = []\n\t\tlet results: any[] = []\n\t\tif (hasMore) {\n\t\t\t// create a new scatter node for the next chunk\n\t\t\tconst newScatterId = `${gatherNodeId}_scatter_next`\n\t\t\tdynamicNodes.push({\n\t\t\t\tid: newScatterId,\n\t\t\t\tuses: 'batch-scatter',\n\t\t\t\tinputs: context.input,\n\t\t\t\tparams: { ...this.params, gatherNodeId },\n\t\t\t})\n\t\t} else {\n\t\t\t// collect results from all chunks into outputKey\n\t\t\tconst allWorkerIds = ((await context.context.get(`${gatherNodeId}_allWorkerIds`)) as string[]) || []\n\t\t\tresults = []\n\t\t\tfor (const workerId of allWorkerIds) {\n\t\t\t\tconst result = await context.context.get(`_outputs.${workerId}` as any)\n\t\t\t\tif (result !== undefined) results.push(result)\n\t\t\t}\n\t\t\tawait context.context.set(outputKey as any, results)\n\n\t\t\tconst parentBatchId = gatherNodeId.replace('_gather', '')\n\t\t\tawait context.dependencies.runtime.services.eventBus.emit({\n\t\t\t\ttype: 'batch:finish',\n\t\t\t\tpayload: {\n\t\t\t\t\tbatchId: parentBatchId,\n\t\t\t\t\tgatherNodeId,\n\t\t\t\t\tresults,\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\treturn { dynamicNodes, output: results }\n\t}\n}\n"]}
@@ -0,0 +1,21 @@
1
+ // src/errors.ts
2
+ var FlowcraftError = class extends Error {
3
+ message;
4
+ nodeId;
5
+ blueprintId;
6
+ executionId;
7
+ isFatal;
8
+ constructor(message, options = {}) {
9
+ super(message, { cause: options.cause });
10
+ this.name = "FlowcraftError";
11
+ this.message = message;
12
+ this.nodeId = options.nodeId;
13
+ this.blueprintId = options.blueprintId;
14
+ this.executionId = options.executionId;
15
+ this.isFatal = options.isFatal ?? false;
16
+ }
17
+ };
18
+
19
+ export { FlowcraftError };
20
+ //# sourceMappingURL=chunk-BCRWXTWX.js.map
21
+ //# sourceMappingURL=chunk-BCRWXTWX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";AAIO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EACzB,OAAA;AAAA,EACA,MAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA,OAAA;AAAA,EAEhB,WAAA,CACC,OAAA,EACA,OAAA,GAMI,EAAC,EACJ;AAED,IAAA,KAAA,CAAM,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,CAAQ,OAAO,CAAA;AACvC,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAEf,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,cAAc,OAAA,CAAQ,WAAA;AAC3B,IAAA,IAAA,CAAK,cAAc,OAAA,CAAQ,WAAA;AAC3B,IAAA,IAAA,CAAK,OAAA,GAAU,QAAQ,OAAA,IAAW,KAAA;AAAA,EACnC;AACD","file":"chunk-BCRWXTWX.js","sourcesContent":["/**\n * A single, comprehensive error class for the framework.\n * Use this for all errors to ensure consistent structure and easy debugging.\n */\nexport class FlowcraftError extends Error {\n\tpublic readonly message: string\n\tpublic readonly nodeId?: string\n\tpublic readonly blueprintId?: string\n\tpublic readonly executionId?: string\n\tpublic readonly isFatal: boolean\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\tcause?: Error\n\t\t\tnodeId?: string\n\t\t\tblueprintId?: string\n\t\t\texecutionId?: string\n\t\t\tisFatal?: boolean\n\t\t} = {},\n\t) {\n\t\t// Pass the cause to the parent Error constructor for proper chaining\n\t\tsuper(message, { cause: options.cause })\n\t\tthis.name = 'FlowcraftError'\n\t\tthis.message = message\n\n\t\tthis.nodeId = options.nodeId\n\t\tthis.blueprintId = options.blueprintId\n\t\tthis.executionId = options.executionId\n\t\tthis.isFatal = options.isFatal ?? false\n\t}\n}\n"]}