flowcraft 2.7.1 → 2.8.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 (229) hide show
  1. package/README.md +1 -1
  2. package/dist/index-D3dyjW2G.d.mts +1269 -0
  3. package/dist/index.d.mts +2 -0
  4. package/dist/index.mjs +727 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/replay-BB11M6K1.mjs +107 -0
  7. package/dist/replay-BB11M6K1.mjs.map +1 -0
  8. package/dist/runtime-CmefIAu_.mjs +2216 -0
  9. package/dist/runtime-CmefIAu_.mjs.map +1 -0
  10. package/dist/{sdk.d.ts → sdk.d.mts} +14 -12
  11. package/dist/sdk.mjs +29 -0
  12. package/dist/sdk.mjs.map +1 -0
  13. package/dist/testing/index.d.mts +172 -0
  14. package/dist/testing/index.mjs +277 -0
  15. package/dist/testing/index.mjs.map +1 -0
  16. package/package.json +59 -59
  17. package/LICENSE +0 -21
  18. package/dist/adapters/index.d.ts +0 -4
  19. package/dist/adapters/index.js +0 -4
  20. package/dist/adapters/index.js.map +0 -1
  21. package/dist/adapters/persistent-event-bus.d.ts +0 -69
  22. package/dist/adapters/persistent-event-bus.js +0 -3
  23. package/dist/adapters/persistent-event-bus.js.map +0 -1
  24. package/dist/analysis.d.ts +0 -53
  25. package/dist/analysis.js +0 -3
  26. package/dist/analysis.js.map +0 -1
  27. package/dist/chunk-27STBUGG.js +0 -44
  28. package/dist/chunk-27STBUGG.js.map +0 -1
  29. package/dist/chunk-2TSADFQX.js +0 -46
  30. package/dist/chunk-2TSADFQX.js.map +0 -1
  31. package/dist/chunk-3Y5O5EGB.js +0 -3
  32. package/dist/chunk-3Y5O5EGB.js.map +0 -1
  33. package/dist/chunk-4PELJWF7.js +0 -29
  34. package/dist/chunk-4PELJWF7.js.map +0 -1
  35. package/dist/chunk-55J6XMHW.js +0 -3
  36. package/dist/chunk-55J6XMHW.js.map +0 -1
  37. package/dist/chunk-6RKHCJUU.js +0 -29
  38. package/dist/chunk-6RKHCJUU.js.map +0 -1
  39. package/dist/chunk-7EBKWATZ.js +0 -86
  40. package/dist/chunk-7EBKWATZ.js.map +0 -1
  41. package/dist/chunk-7EMUOH77.js +0 -90
  42. package/dist/chunk-7EMUOH77.js.map +0 -1
  43. package/dist/chunk-7M6FHFHP.js +0 -25
  44. package/dist/chunk-7M6FHFHP.js.map +0 -1
  45. package/dist/chunk-AKDL2ZX7.js +0 -287
  46. package/dist/chunk-AKDL2ZX7.js.map +0 -1
  47. package/dist/chunk-BC4G7OM6.js +0 -42
  48. package/dist/chunk-BC4G7OM6.js.map +0 -1
  49. package/dist/chunk-BCMR7Y4U.js +0 -76
  50. package/dist/chunk-BCMR7Y4U.js.map +0 -1
  51. package/dist/chunk-BCRWXTWX.js +0 -21
  52. package/dist/chunk-BCRWXTWX.js.map +0 -1
  53. package/dist/chunk-BEHVGFIM.js +0 -532
  54. package/dist/chunk-BEHVGFIM.js.map +0 -1
  55. package/dist/chunk-DL7KVYZF.js +0 -39
  56. package/dist/chunk-DL7KVYZF.js.map +0 -1
  57. package/dist/chunk-DV2CXHOY.js +0 -74
  58. package/dist/chunk-DV2CXHOY.js.map +0 -1
  59. package/dist/chunk-H4JTZYIT.js +0 -172
  60. package/dist/chunk-H4JTZYIT.js.map +0 -1
  61. package/dist/chunk-HFJXYY4E.js +0 -3
  62. package/dist/chunk-HFJXYY4E.js.map +0 -1
  63. package/dist/chunk-HNHM3FDK.js +0 -52
  64. package/dist/chunk-HNHM3FDK.js.map +0 -1
  65. package/dist/chunk-HXSK5P2X.js +0 -150
  66. package/dist/chunk-HXSK5P2X.js.map +0 -1
  67. package/dist/chunk-I53JB2KW.js +0 -26
  68. package/dist/chunk-I53JB2KW.js.map +0 -1
  69. package/dist/chunk-IDTYHLDQ.js +0 -16
  70. package/dist/chunk-IDTYHLDQ.js.map +0 -1
  71. package/dist/chunk-IKOTX22J.js +0 -85
  72. package/dist/chunk-IKOTX22J.js.map +0 -1
  73. package/dist/chunk-L3MX5MTA.js +0 -33
  74. package/dist/chunk-L3MX5MTA.js.map +0 -1
  75. package/dist/chunk-L46TQXCV.js +0 -144
  76. package/dist/chunk-L46TQXCV.js.map +0 -1
  77. package/dist/chunk-LM4ACVHL.js +0 -73
  78. package/dist/chunk-LM4ACVHL.js.map +0 -1
  79. package/dist/chunk-LNK7LZER.js +0 -51
  80. package/dist/chunk-LNK7LZER.js.map +0 -1
  81. package/dist/chunk-N63S5NEG.js +0 -107
  82. package/dist/chunk-N63S5NEG.js.map +0 -1
  83. package/dist/chunk-NVLZFLYM.js +0 -3
  84. package/dist/chunk-NVLZFLYM.js.map +0 -1
  85. package/dist/chunk-ONH7PIJZ.js +0 -300
  86. package/dist/chunk-ONH7PIJZ.js.map +0 -1
  87. package/dist/chunk-PH2IYZHV.js +0 -48
  88. package/dist/chunk-PH2IYZHV.js.map +0 -1
  89. package/dist/chunk-RAZWRNAJ.js +0 -54
  90. package/dist/chunk-RAZWRNAJ.js.map +0 -1
  91. package/dist/chunk-RM677CNU.js +0 -52
  92. package/dist/chunk-RM677CNU.js.map +0 -1
  93. package/dist/chunk-TKSSRS5U.js +0 -39
  94. package/dist/chunk-TKSSRS5U.js.map +0 -1
  95. package/dist/chunk-U7DKCIWT.js +0 -340
  96. package/dist/chunk-U7DKCIWT.js.map +0 -1
  97. package/dist/chunk-UNORA7EM.js +0 -103
  98. package/dist/chunk-UNORA7EM.js.map +0 -1
  99. package/dist/chunk-WWGFIYKW.js +0 -47
  100. package/dist/chunk-WWGFIYKW.js.map +0 -1
  101. package/dist/chunk-XZZWIJ4G.js +0 -25
  102. package/dist/chunk-XZZWIJ4G.js.map +0 -1
  103. package/dist/chunk-ZETQCNEF.js +0 -139
  104. package/dist/chunk-ZETQCNEF.js.map +0 -1
  105. package/dist/chunk-ZLW4QOTS.js +0 -192
  106. package/dist/chunk-ZLW4QOTS.js.map +0 -1
  107. package/dist/container-factory.d.ts +0 -17
  108. package/dist/container-factory.js +0 -13
  109. package/dist/container-factory.js.map +0 -1
  110. package/dist/container.d.ts +0 -23
  111. package/dist/container.js +0 -3
  112. package/dist/container.js.map +0 -1
  113. package/dist/context.d.ts +0 -65
  114. package/dist/context.js +0 -3
  115. package/dist/context.js.map +0 -1
  116. package/dist/error-mapper.d.ts +0 -15
  117. package/dist/error-mapper.js +0 -4
  118. package/dist/error-mapper.js.map +0 -1
  119. package/dist/errors.d.ts +0 -20
  120. package/dist/errors.js +0 -3
  121. package/dist/errors.js.map +0 -1
  122. package/dist/evaluator.d.ts +0 -32
  123. package/dist/evaluator.js +0 -3
  124. package/dist/evaluator.js.map +0 -1
  125. package/dist/flow.d.ts +0 -85
  126. package/dist/flow.js +0 -4
  127. package/dist/flow.js.map +0 -1
  128. package/dist/index.d.ts +0 -18
  129. package/dist/index.js +0 -38
  130. package/dist/index.js.map +0 -1
  131. package/dist/linter.d.ts +0 -26
  132. package/dist/linter.js +0 -4
  133. package/dist/linter.js.map +0 -1
  134. package/dist/logger.d.ts +0 -20
  135. package/dist/logger.js +0 -3
  136. package/dist/logger.js.map +0 -1
  137. package/dist/node.d.ts +0 -3
  138. package/dist/node.js +0 -3
  139. package/dist/node.js.map +0 -1
  140. package/dist/nodes/batch-gather.d.ts +0 -9
  141. package/dist/nodes/batch-gather.js +0 -4
  142. package/dist/nodes/batch-gather.js.map +0 -1
  143. package/dist/nodes/batch-scatter.d.ts +0 -9
  144. package/dist/nodes/batch-scatter.js +0 -4
  145. package/dist/nodes/batch-scatter.js.map +0 -1
  146. package/dist/nodes/sleep.d.ts +0 -9
  147. package/dist/nodes/sleep.js +0 -4
  148. package/dist/nodes/sleep.js.map +0 -1
  149. package/dist/nodes/subflow.d.ts +0 -9
  150. package/dist/nodes/subflow.js +0 -10
  151. package/dist/nodes/subflow.js.map +0 -1
  152. package/dist/nodes/wait.d.ts +0 -9
  153. package/dist/nodes/wait.js +0 -4
  154. package/dist/nodes/wait.js.map +0 -1
  155. package/dist/nodes/webhook.d.ts +0 -13
  156. package/dist/nodes/webhook.js +0 -4
  157. package/dist/nodes/webhook.js.map +0 -1
  158. package/dist/runtime/adapter.d.ts +0 -114
  159. package/dist/runtime/adapter.js +0 -28
  160. package/dist/runtime/adapter.js.map +0 -1
  161. package/dist/runtime/builtin-keys.d.ts +0 -38
  162. package/dist/runtime/builtin-keys.js +0 -10
  163. package/dist/runtime/builtin-keys.js.map +0 -1
  164. package/dist/runtime/execution-context.d.ts +0 -3
  165. package/dist/runtime/execution-context.js +0 -6
  166. package/dist/runtime/execution-context.js.map +0 -1
  167. package/dist/runtime/executors.d.ts +0 -3
  168. package/dist/runtime/executors.js +0 -4
  169. package/dist/runtime/executors.js.map +0 -1
  170. package/dist/runtime/index.d.ts +0 -7
  171. package/dist/runtime/index.js +0 -31
  172. package/dist/runtime/index.js.map +0 -1
  173. package/dist/runtime/node-executor-factory.d.ts +0 -12
  174. package/dist/runtime/node-executor-factory.js +0 -6
  175. package/dist/runtime/node-executor-factory.js.map +0 -1
  176. package/dist/runtime/orchestrator.d.ts +0 -9
  177. package/dist/runtime/orchestrator.js +0 -8
  178. package/dist/runtime/orchestrator.js.map +0 -1
  179. package/dist/runtime/orchestrators/replay.d.ts +0 -45
  180. package/dist/runtime/orchestrators/replay.js +0 -3
  181. package/dist/runtime/orchestrators/replay.js.map +0 -1
  182. package/dist/runtime/orchestrators/step-by-step.d.ts +0 -16
  183. package/dist/runtime/orchestrators/step-by-step.js +0 -5
  184. package/dist/runtime/orchestrators/step-by-step.js.map +0 -1
  185. package/dist/runtime/orchestrators/utils.d.ts +0 -35
  186. package/dist/runtime/orchestrators/utils.js +0 -4
  187. package/dist/runtime/orchestrators/utils.js.map +0 -1
  188. package/dist/runtime/runtime.d.ts +0 -3
  189. package/dist/runtime/runtime.js +0 -27
  190. package/dist/runtime/runtime.js.map +0 -1
  191. package/dist/runtime/scheduler.d.ts +0 -3
  192. package/dist/runtime/scheduler.js +0 -3
  193. package/dist/runtime/scheduler.js.map +0 -1
  194. package/dist/runtime/state.d.ts +0 -3
  195. package/dist/runtime/state.js +0 -5
  196. package/dist/runtime/state.js.map +0 -1
  197. package/dist/runtime/traverser.d.ts +0 -3
  198. package/dist/runtime/traverser.js +0 -4
  199. package/dist/runtime/traverser.js.map +0 -1
  200. package/dist/runtime/types.d.ts +0 -3
  201. package/dist/runtime/types.js +0 -3
  202. package/dist/runtime/types.js.map +0 -1
  203. package/dist/runtime/workflow-logic-handler.d.ts +0 -17
  204. package/dist/runtime/workflow-logic-handler.js +0 -5
  205. package/dist/runtime/workflow-logic-handler.js.map +0 -1
  206. package/dist/sanitizer.d.ts +0 -12
  207. package/dist/sanitizer.js +0 -3
  208. package/dist/sanitizer.js.map +0 -1
  209. package/dist/sdk.js +0 -20
  210. package/dist/sdk.js.map +0 -1
  211. package/dist/serializer.d.ts +0 -18
  212. package/dist/serializer.js +0 -3
  213. package/dist/serializer.js.map +0 -1
  214. package/dist/testing/event-logger.d.ts +0 -63
  215. package/dist/testing/event-logger.js +0 -3
  216. package/dist/testing/event-logger.js.map +0 -1
  217. package/dist/testing/index.d.ts +0 -7
  218. package/dist/testing/index.js +0 -37
  219. package/dist/testing/index.js.map +0 -1
  220. package/dist/testing/run-with-trace.d.ts +0 -38
  221. package/dist/testing/run-with-trace.js +0 -33
  222. package/dist/testing/run-with-trace.js.map +0 -1
  223. package/dist/testing/stepper.d.ts +0 -79
  224. package/dist/testing/stepper.js +0 -11
  225. package/dist/testing/stepper.js.map +0 -1
  226. package/dist/types-CKhffqyb.d.ts +0 -666
  227. package/dist/types.d.ts +0 -3
  228. package/dist/types.js +0 -3
  229. package/dist/types.js.map +0 -1
@@ -1,287 +0,0 @@
1
- import { isNodeClass } from './chunk-LNK7LZER.js';
2
-
3
- // src/flow.ts
4
- var hashCounter = 0;
5
- function _hashFunction(fn) {
6
- const source = fn.toString();
7
- let hash = 0;
8
- for (let i = 0; i < source.length; i++) {
9
- const char = source.charCodeAt(i);
10
- hash = (hash << 5) - hash + char;
11
- hash = hash & hash;
12
- }
13
- return (Math.abs(hash) + hashCounter++).toString(16);
14
- }
15
- var FlowBuilder = class {
16
- blueprint;
17
- functionRegistry;
18
- loopControllerIds;
19
- loopDefinitions;
20
- batchDefinitions;
21
- cycleEntryPoints;
22
- constructor(id) {
23
- this.blueprint = { id, nodes: [], edges: [] };
24
- this.functionRegistry = /* @__PURE__ */ new Map();
25
- this.loopControllerIds = /* @__PURE__ */ new Map();
26
- this.loopDefinitions = [];
27
- this.batchDefinitions = [];
28
- this.cycleEntryPoints = /* @__PURE__ */ new Map();
29
- }
30
- node(id, implementation, options) {
31
- let usesKey;
32
- if (isNodeClass(implementation)) {
33
- usesKey = implementation.name && implementation.name !== "BaseNode" ? implementation.name : `class_${_hashFunction(implementation)}`;
34
- this.functionRegistry.set(usesKey, implementation);
35
- } else {
36
- usesKey = `fn_${_hashFunction(implementation)}`;
37
- this.functionRegistry.set(usesKey, implementation);
38
- }
39
- const nodeDef = { id, uses: usesKey, ...options };
40
- this.blueprint.nodes?.push(nodeDef);
41
- return this;
42
- }
43
- edge(source, target, options) {
44
- const edgeDef = { source, target, ...options };
45
- this.blueprint.edges?.push(edgeDef);
46
- return this;
47
- }
48
- /**
49
- * Creates a batch processing pattern.
50
- * It takes an input array, runs a worker node on each item in parallel, and gathers the results.
51
- * This method augments the Flow's TContext with a new key for the output array.
52
- *
53
- * @param id The base ID for this batch operation.
54
- * @param worker The node implementation to run on each item.
55
- * @param options Configuration for the batch operation.
56
- * @returns The Flow instance with an updated context type for chaining.
57
- */
58
- batch(id, worker, options) {
59
- const { inputKey, outputKey } = options;
60
- const scatterId = `${id}_scatter`;
61
- const gatherId = `${id}_gather`;
62
- this.batchDefinitions.push({ id, scatterId, gatherId });
63
- let workerUsesKey;
64
- if (isNodeClass(worker)) {
65
- workerUsesKey = worker.name && worker.name !== "BaseNode" ? worker.name : `class_batch_worker_${_hashFunction(worker)}`;
66
- this.functionRegistry.set(workerUsesKey, worker);
67
- } else {
68
- workerUsesKey = `fn_batch_worker_${_hashFunction(worker)}`;
69
- this.functionRegistry.set(workerUsesKey, worker);
70
- }
71
- this.blueprint.nodes?.push({
72
- id: scatterId,
73
- uses: "batch-scatter",
74
- inputs: inputKey,
75
- params: { workerUsesKey, outputKey, gatherNodeId: gatherId, chunkSize: options.chunkSize }
76
- });
77
- this.blueprint.nodes?.push({
78
- id: gatherId,
79
- uses: "batch-gather",
80
- params: { outputKey, gatherNodeId: gatherId },
81
- config: { joinStrategy: "all" }
82
- });
83
- this.edge(scatterId, gatherId);
84
- return this;
85
- }
86
- /**
87
- * Creates a sleep node that pauses workflow execution for a specified duration.
88
- * @param id A unique identifier for the sleep node.
89
- * @param options Configuration for the sleep duration.
90
- */
91
- sleep(id, options) {
92
- const nodeDef = {
93
- id,
94
- uses: "sleep",
95
- params: { duration: options.duration }
96
- };
97
- this.blueprint.nodes?.push(nodeDef);
98
- return this;
99
- }
100
- /**
101
- * Creates a wait node that pauses workflow execution for external input.
102
- * @param id A unique identifier for the wait node.
103
- * @param options Optional configuration for the wait node.
104
- */
105
- wait(id, options) {
106
- const nodeDef = { id, uses: "wait", ...options };
107
- this.blueprint.nodes?.push(nodeDef);
108
- return this;
109
- }
110
- /**
111
- * Creates a loop pattern in the workflow graph.
112
- * @param id A unique identifier for the loop construct.
113
- * @param options Defines the start, end, and continuation condition of the loop.
114
- * @param options.startNodeId The ID of the first node inside the loop body.
115
- * @param options.endNodeId The ID of the last node inside the loop body.
116
- * @param options.condition An expression that, if true, causes the loop to run again.
117
- */
118
- loop(id, options) {
119
- const { startNodeId, endNodeId, condition } = options;
120
- const controllerId = `${id}-loop`;
121
- this.loopControllerIds.set(id, controllerId);
122
- this.loopDefinitions.push({ id, startNodeId, endNodeId, condition });
123
- this.blueprint.nodes?.push({
124
- id: controllerId,
125
- uses: "loop-controller",
126
- params: { condition },
127
- config: { joinStrategy: "any" }
128
- });
129
- this.edge(endNodeId, controllerId);
130
- this.edge(controllerId, startNodeId, {
131
- action: "continue",
132
- transform: `context.${endNodeId}`
133
- });
134
- return this;
135
- }
136
- getLoopControllerId(id) {
137
- const controllerId = this.loopControllerIds.get(id);
138
- if (!controllerId) {
139
- throw new Error(`Loop with id '${id}' not found. Ensure you have defined it using the .loop() method.`);
140
- }
141
- return controllerId;
142
- }
143
- /**
144
- * Sets the preferred entry point for a cycle in non-DAG workflows.
145
- * This helps remove ambiguity when the runtime needs to choose a starting node for cycles.
146
- * @param nodeId The ID of the node to use as the entry point for cycles containing this node.
147
- */
148
- setCycleEntryPoint(nodeId) {
149
- this.cycleEntryPoints.set(nodeId, nodeId);
150
- return this;
151
- }
152
- toBlueprint() {
153
- if (!this.blueprint.nodes || this.blueprint.nodes.length === 0) {
154
- throw new Error("Cannot build a blueprint with no nodes.");
155
- }
156
- const finalEdges = [];
157
- const processedOriginalEdges = /* @__PURE__ */ new Set();
158
- const allOriginalEdges = this.blueprint.edges || [];
159
- for (const loopDef of this.loopDefinitions) {
160
- const controllerId = this.getLoopControllerId(loopDef.id);
161
- const edgesToRewire = allOriginalEdges.filter((e) => e.source === loopDef.endNodeId && e.target !== controllerId);
162
- for (const edge of edgesToRewire) {
163
- finalEdges.push({ ...edge, source: controllerId, action: edge.action || "break" });
164
- processedOriginalEdges.add(edge);
165
- }
166
- }
167
- for (const batchDef of this.batchDefinitions) {
168
- const incomingEdges = allOriginalEdges.filter((e) => e.target === batchDef.id);
169
- for (const edge of incomingEdges) {
170
- finalEdges.push({ ...edge, target: batchDef.scatterId });
171
- processedOriginalEdges.add(edge);
172
- }
173
- const outgoingEdges = allOriginalEdges.filter((e) => e.source === batchDef.id);
174
- for (const edge of outgoingEdges) {
175
- finalEdges.push({ ...edge, source: batchDef.gatherId });
176
- processedOriginalEdges.add(edge);
177
- }
178
- }
179
- for (const edge of allOriginalEdges) {
180
- if (!processedOriginalEdges.has(edge)) {
181
- finalEdges.push(edge);
182
- }
183
- }
184
- this.blueprint.edges = finalEdges;
185
- for (const loopDef of this.loopDefinitions) {
186
- const startNode = this.blueprint.nodes?.find((n) => n.id === loopDef.startNodeId);
187
- const endNode = this.blueprint.nodes?.find((n) => n.id === loopDef.endNodeId);
188
- if (!startNode) {
189
- throw new Error(`Loop '${loopDef.id}' references non-existent start node '${loopDef.startNodeId}'.`);
190
- }
191
- if (!endNode) {
192
- throw new Error(`Loop '${loopDef.id}' references non-existent end node '${loopDef.endNodeId}'.`);
193
- }
194
- startNode.config = { ...startNode.config, joinStrategy: "any" };
195
- endNode.config = { ...endNode.config, joinStrategy: "any" };
196
- }
197
- if (this.cycleEntryPoints.size > 0) {
198
- this.blueprint.metadata = {
199
- ...this.blueprint.metadata,
200
- cycleEntryPoints: Array.from(this.cycleEntryPoints.keys())
201
- };
202
- }
203
- return this.blueprint;
204
- }
205
- getFunctionRegistry() {
206
- return this.functionRegistry;
207
- }
208
- toGraphRepresentation() {
209
- const blueprint = this.toBlueprint();
210
- const uiNodes = [];
211
- const uiEdges = [];
212
- const ignoredNodeIds = /* @__PURE__ */ new Set();
213
- for (const loopDef of this.loopDefinitions) {
214
- const controllerId = this.loopControllerIds.get(loopDef.id);
215
- if (!controllerId) continue;
216
- ignoredNodeIds.add(controllerId);
217
- uiEdges.push({
218
- source: loopDef.endNodeId,
219
- target: loopDef.startNodeId,
220
- data: {
221
- isLoopback: true,
222
- condition: loopDef.condition,
223
- label: `continue if: ${loopDef.condition}`
224
- }
225
- });
226
- const breakEdges = blueprint.edges.filter((edge) => edge.source === controllerId && edge.action === "break");
227
- for (const breakEdge of breakEdges) {
228
- uiEdges.push({
229
- ...breakEdge,
230
- source: loopDef.endNodeId
231
- });
232
- }
233
- }
234
- const scatterNodes = blueprint.nodes.filter((n) => n.uses === "batch-scatter");
235
- for (const scatterNode of scatterNodes) {
236
- const gatherNodeId = scatterNode.params?.gatherNodeId;
237
- if (!gatherNodeId) continue;
238
- ignoredNodeIds.add(scatterNode.id);
239
- ignoredNodeIds.add(gatherNodeId);
240
- const batchId = scatterNode.id.replace("_scatter", "");
241
- const gatherNode = blueprint.nodes.find((n) => n.id === gatherNodeId);
242
- uiNodes.push({
243
- id: batchId,
244
- uses: scatterNode.params?.workerUsesKey,
245
- type: "batch-worker",
246
- data: {
247
- label: `Batch: ${batchId}`,
248
- isBatchPlaceholder: true,
249
- workerUsesKey: scatterNode.params?.workerUsesKey,
250
- inputKey: scatterNode.inputs,
251
- outputKey: gatherNode?.params?.outputKey
252
- }
253
- });
254
- const incomingEdges = blueprint.edges.filter((e) => e.target === scatterNode.id);
255
- for (const edge of incomingEdges) {
256
- uiEdges.push({ ...edge, target: batchId });
257
- }
258
- const outgoingEdges = blueprint.edges.filter((e) => e.source === gatherNodeId);
259
- for (const edge of outgoingEdges) {
260
- uiEdges.push({ ...edge, source: batchId });
261
- }
262
- }
263
- for (const node of blueprint.nodes) {
264
- if (!ignoredNodeIds.has(node.id)) {
265
- uiNodes.push(node);
266
- }
267
- }
268
- for (const edge of blueprint.edges) {
269
- if (!ignoredNodeIds.has(edge.source) && !ignoredNodeIds.has(edge.target)) {
270
- const alreadyAdded = uiEdges.some(
271
- (e) => e.source === edge.source && e.target === edge.target && e.action === edge.action
272
- );
273
- if (!alreadyAdded) {
274
- uiEdges.push(edge);
275
- }
276
- }
277
- }
278
- return { nodes: uiNodes, edges: uiEdges };
279
- }
280
- };
281
- function createFlow(id) {
282
- return new FlowBuilder(id);
283
- }
284
-
285
- export { FlowBuilder, createFlow };
286
- //# sourceMappingURL=chunk-AKDL2ZX7.js.map
287
- //# sourceMappingURL=chunk-AKDL2ZX7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/flow.ts"],"names":[],"mappings":";;;AAMA,IAAI,WAAA,GAAc,CAAA;AAClB,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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A,CAAI,IAAA,CAAK,MAAM,CAAA,EAAG;AACzE,QAAA,MAAM,eAAe,OAAA,CAAQ,IAAA;AAAA,UAC5B,CAAC,CAAA,KAAM,CAAA,CAAE,MAAA,KAAW,IAAA,CAAK,MAAA,IAAU,CAAA,CAAE,MAAA,KAAW,IAAA,CAAK,MAAA,IAAU,CAAA,CAAE,MAAA,KAAW,IAAA,CAAK;AAAA,SAClF;AACA,QAAA,IAAI,CAAC,YAAA,EAAc;AAClB,UAAA,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,QAClB;AAAA,MACD;AAAA,IACD;AAEA,IAAA,OAAO,EAAE,KAAA,EAAO,OAAA,EAAS,KAAA,EAAO,OAAA,EAAQ;AAAA,EACzC;AACD;AAKO,SAAS,WAGd,EAAA,EAAkD;AACnD,EAAA,OAAO,IAAI,YAAY,EAAE,CAAA;AAC1B","file":"chunk-AKDL2ZX7.js","sourcesContent":["import { isNodeClass } from './node'\nimport type { EdgeDefinition, NodeClass, NodeDefinition, NodeFunction, UIGraph, WorkflowBlueprint } from './types'\n\n/**\n * Generates a deterministic hash for a function based on its source code and a unique counter.\n */\nlet hashCounter = 0\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\t// Add counter to ensure uniqueness even for identical functions\n\treturn (Math.abs(hash) + hashCounter++).toString(16)\n}\n\n/**\n * A fluent API for programmatically constructing a WorkflowBlueprint.\n */\nexport class FlowBuilder<\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\tcondition: string\n\t}>\n\tprivate batchDefinitions: Array<{\n\t\tid: string\n\t\tscatterId: string\n\t\tgatherId: string\n\t}>\n\tprivate cycleEntryPoints: Map<string, string>\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\tthis.batchDefinitions = []\n\t\tthis.cycleEntryPoints = new Map()\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 * This method augments the Flow's TContext with a new key for the output array.\n\t *\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 * @returns The Flow instance with an updated context type for chaining.\n\t */\n\tbatch<TWorkerInput, TWorkerOutput, TWorkerAction extends string, TOutputKey extends string>(\n\t\tid: string,\n\t\tworker:\n\t\t\t| NodeFunction<TContext, TDependencies, TWorkerInput, TWorkerOutput, TWorkerAction>\n\t\t\t| NodeClass<TContext, TDependencies, TWorkerInput, TWorkerOutput, TWorkerAction>,\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: TOutputKey\n\t\t\t/** The number of items to process in each chunk to limit memory usage. */\n\t\t\tchunkSize?: number\n\t\t},\n\t): FlowBuilder<TContext & { [K in TOutputKey]: TWorkerOutput[] }, TDependencies> {\n\t\tconst { inputKey, outputKey } = options\n\t\tconst scatterId = `${id}_scatter`\n\t\tconst gatherId = `${id}_gather`\n\n\t\tthis.batchDefinitions.push({ id, scatterId, gatherId })\n\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\tthis.blueprint.nodes?.push({\n\t\t\tid: scatterId,\n\t\t\tuses: 'batch-scatter',\n\t\t\tinputs: inputKey as string,\n\t\t\tparams: { workerUsesKey, outputKey: outputKey as string, gatherNodeId: gatherId, chunkSize: options.chunkSize },\n\t\t})\n\n\t\tthis.blueprint.nodes?.push({\n\t\t\tid: gatherId,\n\t\t\tuses: 'batch-gather',\n\t\t\tparams: { outputKey, gatherNodeId: gatherId },\n\t\t\tconfig: { joinStrategy: 'all' },\n\t\t})\n\n\t\tthis.edge(scatterId, gatherId)\n\n\t\treturn this as unknown as FlowBuilder<TContext & { [K in TOutputKey]: TWorkerOutput[] }, TDependencies>\n\t}\n\n\t/**\n\t * Creates a sleep node that pauses workflow execution for a specified duration.\n\t * @param id A unique identifier for the sleep node.\n\t * @param options Configuration for the sleep duration.\n\t */\n\tsleep(\n\t\tid: string,\n\t\toptions: {\n\t\t\t/** The duration to sleep in milliseconds or a string like '5s', '1m', '2h', '1d'. */\n\t\t\tduration: number | string\n\t\t},\n\t): this {\n\t\tconst nodeDef: NodeDefinition = {\n\t\t\tid,\n\t\t\tuses: 'sleep',\n\t\t\tparams: { duration: options.duration },\n\t\t}\n\t\tthis.blueprint.nodes?.push(nodeDef)\n\t\treturn this\n\t}\n\n\t/**\n\t * Creates a wait node that pauses workflow execution for external input.\n\t * @param id A unique identifier for the wait node.\n\t * @param options Optional configuration for the wait node.\n\t */\n\twait(id: string, options?: Omit<NodeDefinition, 'id' | 'uses'>): this {\n\t\tconst nodeDef: NodeDefinition = { id, uses: 'wait', ...options }\n\t\tthis.blueprint.nodes?.push(nodeDef)\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, condition })\n\n\t\tthis.blueprint.nodes?.push({\n\t\t\tid: controllerId,\n\t\t\tuses: 'loop-controller',\n\t\t\tparams: { condition },\n\t\t\tconfig: { joinStrategy: 'any' },\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}`,\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\t/**\n\t * Sets the preferred entry point for a cycle in non-DAG workflows.\n\t * This helps remove ambiguity when the runtime needs to choose a starting node for cycles.\n\t * @param nodeId The ID of the node to use as the entry point for cycles containing this node.\n\t */\n\tsetCycleEntryPoint(nodeId: string): this {\n\t\tthis.cycleEntryPoints.set(nodeId, nodeId)\n\t\treturn this\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\t\tconst finalEdges: EdgeDefinition[] = []\n\t\tconst processedOriginalEdges = new Set<EdgeDefinition>()\n\t\tconst allOriginalEdges = this.blueprint.edges || []\n\n\t\t// loop edge re-wiring\n\t\tfor (const loopDef of this.loopDefinitions) {\n\t\t\tconst controllerId = this.getLoopControllerId(loopDef.id)\n\t\t\tconst edgesToRewire = allOriginalEdges.filter((e) => e.source === loopDef.endNodeId && e.target !== controllerId)\n\t\t\tfor (const edge of edgesToRewire) {\n\t\t\t\tfinalEdges.push({ ...edge, source: controllerId, action: edge.action || 'break' })\n\t\t\t\tprocessedOriginalEdges.add(edge)\n\t\t\t}\n\t\t}\n\n\t\t// batch edge re-wiring\n\t\tfor (const batchDef of this.batchDefinitions) {\n\t\t\tconst incomingEdges = allOriginalEdges.filter((e) => e.target === batchDef.id)\n\t\t\tfor (const edge of incomingEdges) {\n\t\t\t\tfinalEdges.push({ ...edge, target: batchDef.scatterId })\n\t\t\t\tprocessedOriginalEdges.add(edge)\n\t\t\t}\n\n\t\t\tconst outgoingEdges = allOriginalEdges.filter((e) => e.source === batchDef.id)\n\t\t\tfor (const edge of outgoingEdges) {\n\t\t\t\tfinalEdges.push({ ...edge, source: batchDef.gatherId })\n\t\t\t\tprocessedOriginalEdges.add(edge)\n\t\t\t}\n\t\t}\n\n\t\t// all remaining edges\n\t\tfor (const edge of allOriginalEdges) {\n\t\t\tif (!processedOriginalEdges.has(edge)) {\n\t\t\t\tfinalEdges.push(edge)\n\t\t\t}\n\t\t}\n\t\tthis.blueprint.edges = finalEdges\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\tif (this.cycleEntryPoints.size > 0) {\n\t\t\tthis.blueprint.metadata = {\n\t\t\t\t...this.blueprint.metadata,\n\t\t\t\tcycleEntryPoints: Array.from(this.cycleEntryPoints.keys()),\n\t\t\t}\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\ttoGraphRepresentation(): UIGraph {\n\t\tconst blueprint = this.toBlueprint()\n\t\tconst uiNodes: UIGraph['nodes'] = []\n\t\tconst uiEdges: UIGraph['edges'] = []\n\n\t\tconst ignoredNodeIds = new Set<string>()\n\n\t\t// replace loop-controllers with direct, cyclical edges\n\t\tfor (const loopDef of this.loopDefinitions) {\n\t\t\tconst controllerId = this.loopControllerIds.get(loopDef.id)\n\t\t\tif (!controllerId) continue\n\n\t\t\tignoredNodeIds.add(controllerId)\n\n\t\t\t// direct edge from the end of loop to start\n\t\t\tuiEdges.push({\n\t\t\t\tsource: loopDef.endNodeId,\n\t\t\t\ttarget: loopDef.startNodeId,\n\t\t\t\tdata: {\n\t\t\t\t\tisLoopback: true,\n\t\t\t\t\tcondition: loopDef.condition,\n\t\t\t\t\tlabel: `continue if: ${loopDef.condition}`,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\t// re-wire any 'break' edges\n\t\t\tconst breakEdges = blueprint.edges.filter((edge) => edge.source === controllerId && edge.action === 'break')\n\t\t\tfor (const breakEdge of breakEdges) {\n\t\t\t\tuiEdges.push({\n\t\t\t\t\t...breakEdge,\n\t\t\t\t\tsource: loopDef.endNodeId,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// replace scatter/gather pairs with a single representative worker node\n\t\tconst scatterNodes = blueprint.nodes.filter((n) => n.uses === 'batch-scatter')\n\t\tfor (const scatterNode of scatterNodes) {\n\t\t\tconst gatherNodeId = scatterNode.params?.gatherNodeId\n\t\t\tif (!gatherNodeId) continue\n\n\t\t\tignoredNodeIds.add(scatterNode.id)\n\t\t\tignoredNodeIds.add(gatherNodeId)\n\n\t\t\t// single node to represent parallel work\n\t\t\tconst batchId = scatterNode.id.replace('_scatter', '')\n\t\t\tconst gatherNode = blueprint.nodes.find((n) => n.id === gatherNodeId)\n\n\t\t\tuiNodes.push({\n\t\t\t\tid: batchId,\n\t\t\t\tuses: scatterNode.params?.workerUsesKey,\n\t\t\t\ttype: 'batch-worker',\n\t\t\t\tdata: {\n\t\t\t\t\tlabel: `Batch: ${batchId}`,\n\t\t\t\t\tisBatchPlaceholder: true,\n\t\t\t\t\tworkerUsesKey: scatterNode.params?.workerUsesKey,\n\t\t\t\t\tinputKey: scatterNode.inputs,\n\t\t\t\t\toutputKey: gatherNode?.params?.outputKey,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\t// re-wire incoming edges\n\t\t\tconst incomingEdges = blueprint.edges.filter((e) => e.target === scatterNode.id)\n\t\t\tfor (const edge of incomingEdges) {\n\t\t\t\tuiEdges.push({ ...edge, target: batchId })\n\t\t\t}\n\n\t\t\t// re-wire outgoing edges\n\t\t\tconst outgoingEdges = blueprint.edges.filter((e) => e.source === gatherNodeId)\n\t\t\tfor (const edge of outgoingEdges) {\n\t\t\t\tuiEdges.push({ ...edge, source: batchId })\n\t\t\t}\n\t\t}\n\n\t\tfor (const node of blueprint.nodes) {\n\t\t\tif (!ignoredNodeIds.has(node.id)) {\n\t\t\t\tuiNodes.push(node)\n\t\t\t}\n\t\t}\n\n\t\tfor (const edge of blueprint.edges) {\n\t\t\tif (!ignoredNodeIds.has(edge.source) && !ignoredNodeIds.has(edge.target)) {\n\t\t\t\tconst alreadyAdded = uiEdges.some(\n\t\t\t\t\t(e) => e.source === edge.source && e.target === edge.target && e.action === edge.action,\n\t\t\t\t)\n\t\t\t\tif (!alreadyAdded) {\n\t\t\t\t\tuiEdges.push(edge)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { nodes: uiNodes, edges: uiEdges }\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): FlowBuilder<TContext, TDependencies> {\n\treturn new FlowBuilder(id)\n}\n"]}
@@ -1,42 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,76 +0,0 @@
1
- import { StepByStepOrchestrator } from './chunk-RAZWRNAJ.js';
2
- import { GraphTraverser } from './chunk-H4JTZYIT.js';
3
- import { ExecutionContext } from './chunk-L3MX5MTA.js';
4
- import { WorkflowState } from './chunk-L46TQXCV.js';
5
-
6
- // src/testing/stepper.ts
7
- async function createStepper(runtime, blueprint, functionRegistry, initialState = {}) {
8
- const _initialBlueprint = structuredClone(blueprint);
9
- const _initialState = structuredClone(initialState);
10
- let state;
11
- let traverser;
12
- const history = [];
13
- const orchestrator = new StepByStepOrchestrator();
14
- const executionId = globalThis.crypto?.randomUUID();
15
- const nodeRegistry = new Map([...runtime.registry, ...functionRegistry]);
16
- const initialize = () => {
17
- state = new WorkflowState(_initialState);
18
- traverser = new GraphTraverser(_initialBlueprint);
19
- history.length = 0;
20
- };
21
- initialize();
22
- const stepper = {
23
- get state() {
24
- return state;
25
- },
26
- get traverser() {
27
- return traverser;
28
- },
29
- isDone() {
30
- return !traverser.hasMoreWork() && !state.isAwaiting();
31
- },
32
- reset() {
33
- initialize();
34
- },
35
- async prev() {
36
- const previousStateJson = history.pop();
37
- if (!previousStateJson) {
38
- return null;
39
- }
40
- const previousStateData = runtime.serializer.deserialize(previousStateJson);
41
- state = new WorkflowState(previousStateData);
42
- traverser = GraphTraverser.fromState(_initialBlueprint, state);
43
- return state.toResult(runtime.serializer, void 0);
44
- },
45
- async next(options = {}) {
46
- if (stepper.isDone()) {
47
- return null;
48
- }
49
- const serializedContext = (await state.toResult(runtime.serializer, void 0)).serializedContext;
50
- history.push(serializedContext);
51
- const executionContext = new ExecutionContext(
52
- _initialBlueprint,
53
- state,
54
- nodeRegistry,
55
- executionId,
56
- runtime,
57
- {
58
- logger: runtime.logger,
59
- eventBus: runtime.eventBus,
60
- serializer: runtime.serializer,
61
- evaluator: runtime.evaluator,
62
- middleware: runtime.middleware,
63
- dependencies: runtime.dependencies
64
- },
65
- options.signal,
66
- options.concurrency
67
- );
68
- return orchestrator.run(executionContext, traverser);
69
- }
70
- };
71
- return stepper;
72
- }
73
-
74
- export { createStepper };
75
- //# sourceMappingURL=chunk-BCMR7Y4U.js.map
76
- //# sourceMappingURL=chunk-BCMR7Y4U.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/testing/stepper.ts"],"names":[],"mappings":";;;;;;AAkFA,eAAsB,cACrB,OAAA,EACA,SAAA,EACA,gBAAA,EACA,YAAA,GAAkC,EAAC,EACG;AACtC,EAAA,MAAM,iBAAA,GAAoB,gBAAgB,SAAS,CAAA;AACnD,EAAA,MAAM,a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cAAA,CAAe,SAAA,CAAU,iBAAA,EAAmB,KAAK,CAAA;AAE7D,MAAA,OAAO,KAAA,CAAM,QAAA,CAAS,OAAA,CAAQ,UAAA,EAAY,MAAS,CAAA;AAAA,IACpD,CAAA;AAAA,IACA,MAAM,IAAA,CAAK,OAAA,GAA0D,EAAC,EAAG;AACxE,MAAA,IAAI,OAAA,CAAQ,QAAO,EAAG;AACrB,QAAA,OAAO,IAAA;AAAA,MACR;AAEA,MAAA,MAAM,qBAAqB,MAAM,KAAA,CAAM,SAAS,OAAA,CAAQ,UAAA,EAAY,MAAS,CAAA,EAAG,iBAAA;AAChF,MAAA,OAAA,CAAQ,KAAK,iBAAiB,CAAA;AAE9B,MAAA,MAAM,mBAAmB,IAAI,gBAAA;AAAA,QAC5B,iBAAA;AAAA,QACA,KAAA;AAAA,QACA,YAAA;AAAA,QACA,WAAA;AAAA,QACA,OAAA;AAAA,QACA;AAAA,UACC,QAAQ,OAAA,CAAQ,MAAA;AAAA,UAChB,UAAU,OAAA,CAAQ,QAAA;AAAA,UAClB,YAAY,OAAA,CAAQ,UAAA;AAAA,UACpB,WAAW,OAAA,CAAQ,SAAA;AAAA,UACnB,YAAY,OAAA,CAAQ,UAAA;AAAA,UACpB,cAAc,OAAA,CAAQ;AAAA,SACvB;AAAA,QACA,OAAA,CAAQ,MAAA;AAAA,QACR,OAAA,CAAQ;AAAA,OACT;AACA,MAAA,OAAO,YAAA,CAAa,GAAA,CAAI,gBAAA,EAAkB,SAAS,CAAA;AAAA,IACpD;AAAA,GACD;AAEA,EAAA,OAAO,OAAA;AACR","file":"chunk-BCMR7Y4U.js","sourcesContent":["import type { FlowRuntime } from '../runtime'\nimport { ExecutionContext } from '../runtime/execution-context'\nimport { StepByStepOrchestrator } from '../runtime/orchestrators/step-by-step'\nimport { WorkflowState } from '../runtime/state'\nimport { GraphTraverser } from '../runtime/traverser'\nimport type { NodeClass, NodeFunction, WorkflowBlueprint, WorkflowResult } from '../types'\n\n/**\n * Represents the controlled, step-by-step execution of a workflow.\n * Returned by the `createStepper` utility.\n */\nexport interface IWorkflowStepper<TContext extends Record<string, any>> {\n\t/** The current state of the workflow. Can be inspected after each step. */\n\treadonly state: WorkflowState<TContext>\n\n\t/** The graph traverser instance. Can be used to inspect the frontier or completed nodes. */\n\treadonly traverser: GraphTraverser\n\n\t/**\n\t * Executes the next \"turn\" or batch of ready nodes in the workflow.\n\t * @param options Optional configuration for this specific step, like a cancellation signal.\n\t * @returns A `WorkflowResult` representing the state after the step, or `null` if the workflow has already completed.\n\t */\n\tnext(options?: { signal?: AbortSignal; concurrency?: number }): Promise<WorkflowResult<TContext> | null>\n\n\t/**\n\t * Reverts the workflow to its previous state.\n\t * @returns The `WorkflowResult` of the previous state, or `null` if there is no history to revert to.\n\t */\n\tprev(): Promise<WorkflowResult<TContext> | null>\n\n\t/**\n\t * Resets the stepper to its initial state, clearing all progress and history.\n\t */\n\treset(): void\n\n\t/**\n\t * A convenience method to check if the workflow has any more steps to run.\n\t * @returns `true` if the workflow is complete or stalled, `false` otherwise.\n\t */\n\tisDone(): boolean\n}\n\n/**\n * A test utility that creates a stepper to execute a workflow one \"turn\" at a time.\n * This is invaluable for debugging and writing fine-grained tests where you need to\n * assert the state of the workflow after each logical step.\n *\n * @example\n * // In your test file\n * it('should correctly execute step-by-step', async () => {\n * const runtime = new FlowRuntime({ ... });\n * const flow = createFlow('test')\n * .node('a', async () => ({ output: 10 }))\n * .node('b', async ({ input }) => ({ output: input * 2 }))\n * .edge('a', 'b');\n *\n * const stepper = await createStepper(runtime, flow.toBlueprint(), flow.getFunctionRegistry());\n *\n * // First step (executes node 'a')\n * const result1 = await stepper.next();\n * expect(stepper.isDone()).toBe(false);\n * expect(result1.status).toBe('stalled');\n * expect(result1.context._outputs.a).toBe(10);\n *\n * // Second step (executes node 'b')\n * const result2 = await stepper.next();\n * expect(stepper.isDone()).toBe(true);\n * expect(result2.status).toBe('completed');\n * expect(result2.context._outputs.b).toBe(20);\n *\n * // Final step (no more work)\n * const result3 = await stepper.next();\n * expect(result3).toBeNull();\n * });\n *\n * @param runtime The `FlowRuntime` instance, used for its configuration.\n * @param blueprint The `WorkflowBlueprint` to execute.\n * @param functionRegistry The function registry from createFlow, containing the node implementations.\n * @param initialState The initial state for the workflow run.\n * @returns A Promise that resolves to an `IWorkflowStepper` instance.\n */\nexport async function createStepper<TContext extends Record<string, any>, TDependencies extends Record<string, any>>(\n\truntime: FlowRuntime<TContext, TDependencies>,\n\tblueprint: WorkflowBlueprint,\n\tfunctionRegistry: Map<string, NodeFunction | NodeClass>,\n\tinitialState: Partial<TContext> = {},\n): Promise<IWorkflowStepper<TContext>> {\n\tconst _initialBlueprint = structuredClone(blueprint)\n\tconst _initialState = structuredClone(initialState)\n\n\tlet state: WorkflowState<TContext>\n\tlet traverser: GraphTraverser\n\tconst history: string[] = []\n\n\tconst orchestrator = new StepByStepOrchestrator()\n\tconst executionId = globalThis.crypto?.randomUUID()\n\tconst nodeRegistry = new Map([...runtime.registry, ...functionRegistry])\n\n\tconst initialize = () => {\n\t\tstate = new WorkflowState<TContext>(_initialState)\n\t\ttraverser = new GraphTraverser(_initialBlueprint)\n\t\thistory.length = 0\n\t}\n\n\tinitialize()\n\n\tconst stepper: IWorkflowStepper<TContext> = {\n\t\tget state() {\n\t\t\treturn state\n\t\t},\n\t\tget traverser() {\n\t\t\treturn traverser\n\t\t},\n\t\tisDone() {\n\t\t\treturn !traverser.hasMoreWork() && !state.isAwaiting()\n\t\t},\n\t\treset() {\n\t\t\tinitialize()\n\t\t},\n\t\tasync prev() {\n\t\t\tconst previousStateJson = history.pop()\n\t\t\tif (!previousStateJson) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst previousStateData = runtime.serializer.deserialize(previousStateJson) as Partial<TContext>\n\n\t\t\tstate = new WorkflowState(previousStateData)\n\t\t\ttraverser = GraphTraverser.fromState(_initialBlueprint, state)\n\n\t\t\treturn state.toResult(runtime.serializer, undefined)\n\t\t},\n\t\tasync next(options: { signal?: AbortSignal; concurrency?: number } = {}) {\n\t\t\tif (stepper.isDone()) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst serializedContext = (await state.toResult(runtime.serializer, undefined)).serializedContext\n\t\t\thistory.push(serializedContext)\n\n\t\t\tconst executionContext = new ExecutionContext(\n\t\t\t\t_initialBlueprint,\n\t\t\t\tstate,\n\t\t\t\tnodeRegistry,\n\t\t\t\texecutionId,\n\t\t\t\truntime,\n\t\t\t\t{\n\t\t\t\t\tlogger: runtime.logger,\n\t\t\t\t\teventBus: runtime.eventBus,\n\t\t\t\t\tserializer: runtime.serializer,\n\t\t\t\t\tevaluator: runtime.evaluator,\n\t\t\t\t\tmiddleware: runtime.middleware,\n\t\t\t\t\tdependencies: runtime.dependencies,\n\t\t\t\t},\n\t\t\t\toptions.signal,\n\t\t\t\toptions.concurrency,\n\t\t\t)\n\t\t\treturn orchestrator.run(executionContext, traverser)\n\t\t},\n\t}\n\n\treturn stepper\n}\n"]}
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
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"]}