flowcraft 1.0.0 → 2.0.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 (201) hide show
  1. package/README.md +37 -134
  2. package/dist/analysis.d.ts +43 -0
  3. package/dist/analysis.js +3 -0
  4. package/dist/chunk-55J6XMHW.js +3 -0
  5. package/dist/{chunk-7XUN3OQT.js.map → chunk-55J6XMHW.js.map} +1 -1
  6. package/dist/chunk-6DNEDIIT.js +123 -0
  7. package/dist/chunk-6DNEDIIT.js.map +1 -0
  8. package/dist/chunk-734J4PTM.js +100 -0
  9. package/dist/chunk-734J4PTM.js.map +1 -0
  10. package/dist/chunk-DSZSR7UE.js +40 -0
  11. package/dist/chunk-DSZSR7UE.js.map +1 -0
  12. package/dist/chunk-GTZC6PQI.js +22 -0
  13. package/dist/chunk-GTZC6PQI.js.map +1 -0
  14. package/dist/chunk-HMR2GEGE.js +3 -0
  15. package/dist/{chunk-F2RSES6P.js.map → chunk-HMR2GEGE.js.map} +1 -1
  16. package/dist/chunk-J3RNCPED.js +27 -0
  17. package/dist/chunk-J3RNCPED.js.map +1 -0
  18. package/dist/chunk-M23P46ZL.js +105 -0
  19. package/dist/chunk-M23P46ZL.js.map +1 -0
  20. package/dist/chunk-MICPMOTW.js +49 -0
  21. package/dist/chunk-MICPMOTW.js.map +1 -0
  22. package/dist/chunk-NPAJNLXQ.js +106 -0
  23. package/dist/chunk-NPAJNLXQ.js.map +1 -0
  24. package/dist/chunk-RAZXOMZC.js +64 -0
  25. package/dist/chunk-RAZXOMZC.js.map +1 -0
  26. package/dist/chunk-REH55ZXV.js +13 -0
  27. package/dist/chunk-REH55ZXV.js.map +1 -0
  28. package/dist/chunk-RW4FH7IL.js +135 -0
  29. package/dist/chunk-RW4FH7IL.js.map +1 -0
  30. package/dist/chunk-RYTIQZIB.js +303 -0
  31. package/dist/chunk-RYTIQZIB.js.map +1 -0
  32. package/dist/chunk-UYPIWXZG.js +62 -0
  33. package/dist/chunk-UYPIWXZG.js.map +1 -0
  34. package/dist/chunk-VFC342WL.js +29 -0
  35. package/dist/chunk-VFC342WL.js.map +1 -0
  36. package/dist/chunk-WXT3YEWU.js +28 -0
  37. package/dist/chunk-WXT3YEWU.js.map +1 -0
  38. package/dist/context.d.ts +23 -105
  39. package/dist/context.js +1 -1
  40. package/dist/errors.d.ts +15 -31
  41. package/dist/errors.js +1 -1
  42. package/dist/evaluator.d.ts +22 -0
  43. package/dist/evaluator.js +3 -0
  44. package/dist/evaluator.js.map +1 -0
  45. package/dist/flow.d.ts +54 -0
  46. package/dist/flow.js +4 -0
  47. package/dist/flow.js.map +1 -0
  48. package/dist/index.d.ts +14 -16
  49. package/dist/index.js +17 -25
  50. package/dist/linter.d.ts +24 -0
  51. package/dist/linter.js +4 -0
  52. package/dist/linter.js.map +1 -0
  53. package/dist/logger.d.ts +11 -36
  54. package/dist/logger.js +1 -1
  55. package/dist/node.d.ts +1 -0
  56. package/dist/node.js +3 -0
  57. package/dist/node.js.map +1 -0
  58. package/dist/runtime/adapter.d.ts +78 -0
  59. package/dist/runtime/adapter.js +15 -0
  60. package/dist/runtime/adapter.js.map +1 -0
  61. package/dist/runtime/executors.d.ts +26 -0
  62. package/dist/runtime/executors.js +4 -0
  63. package/dist/runtime/executors.js.map +1 -0
  64. package/dist/runtime/index.d.ts +7 -0
  65. package/dist/runtime/index.js +16 -0
  66. package/dist/runtime/runtime.d.ts +33 -0
  67. package/dist/runtime/runtime.js +14 -0
  68. package/dist/runtime/runtime.js.map +1 -0
  69. package/dist/runtime/state.d.ts +21 -0
  70. package/dist/runtime/state.js +4 -0
  71. package/dist/runtime/state.js.map +1 -0
  72. package/dist/runtime/traverser.d.ts +24 -0
  73. package/dist/runtime/traverser.js +5 -0
  74. package/dist/runtime/traverser.js.map +1 -0
  75. package/dist/runtime/types.d.ts +15 -0
  76. package/dist/runtime/types.js +3 -0
  77. package/dist/sanitizer.d.ts +10 -0
  78. package/dist/sanitizer.js +3 -0
  79. package/dist/{utils/sanitize.js.map → sanitizer.js.map} +1 -1
  80. package/dist/serializer.d.ts +15 -0
  81. package/dist/serializer.js +3 -0
  82. package/dist/serializer.js.map +1 -0
  83. package/dist/types-CZN_FcB6.d.ts +201 -0
  84. package/dist/types.d.ts +1 -3
  85. package/dist/types.js +1 -1
  86. package/package.json +9 -20
  87. package/LICENSE +0 -21
  88. package/dist/builder/graph/graph.d.ts +0 -57
  89. package/dist/builder/graph/graph.js +0 -21
  90. package/dist/builder/graph/graph.js.map +0 -1
  91. package/dist/builder/graph/index.d.ts +0 -8
  92. package/dist/builder/graph/index.js +0 -23
  93. package/dist/builder/graph/internal-nodes.d.ts +0 -59
  94. package/dist/builder/graph/internal-nodes.js +0 -20
  95. package/dist/builder/graph/internal-nodes.js.map +0 -1
  96. package/dist/builder/graph/runner.d.ts +0 -51
  97. package/dist/builder/graph/runner.js +0 -21
  98. package/dist/builder/graph/runner.js.map +0 -1
  99. package/dist/builder/graph/types.d.ts +0 -3
  100. package/dist/builder/graph/types.js +0 -3
  101. package/dist/builder/index.d.ts +0 -8
  102. package/dist/builder/index.js +0 -24
  103. package/dist/builder/index.js.map +0 -1
  104. package/dist/builder/patterns.d.ts +0 -136
  105. package/dist/builder/patterns.js +0 -19
  106. package/dist/builder/patterns.js.map +0 -1
  107. package/dist/chunk-3YMBNZ77.js +0 -441
  108. package/dist/chunk-3YMBNZ77.js.map +0 -1
  109. package/dist/chunk-64DNBF5W.js +0 -36
  110. package/dist/chunk-64DNBF5W.js.map +0 -1
  111. package/dist/chunk-6QCXIRLA.js +0 -18
  112. package/dist/chunk-6QCXIRLA.js.map +0 -1
  113. package/dist/chunk-7XUN3OQT.js +0 -3
  114. package/dist/chunk-AOHBHYF6.js +0 -7
  115. package/dist/chunk-AOHBHYF6.js.map +0 -1
  116. package/dist/chunk-BRFMFLR6.js +0 -85
  117. package/dist/chunk-BRFMFLR6.js.map +0 -1
  118. package/dist/chunk-ELEHMJPM.js +0 -13
  119. package/dist/chunk-ELEHMJPM.js.map +0 -1
  120. package/dist/chunk-F2RSES6P.js +0 -3
  121. package/dist/chunk-F6C6J7HK.js +0 -3
  122. package/dist/chunk-F6C6J7HK.js.map +0 -1
  123. package/dist/chunk-GMKJ34T2.js +0 -3
  124. package/dist/chunk-GMKJ34T2.js.map +0 -1
  125. package/dist/chunk-HEO3XL4Z.js +0 -328
  126. package/dist/chunk-HEO3XL4Z.js.map +0 -1
  127. package/dist/chunk-IIKTTIW5.js +0 -56
  128. package/dist/chunk-IIKTTIW5.js.map +0 -1
  129. package/dist/chunk-KOBEU2EM.js +0 -3
  130. package/dist/chunk-KOBEU2EM.js.map +0 -1
  131. package/dist/chunk-L5PK5VL2.js +0 -178
  132. package/dist/chunk-L5PK5VL2.js.map +0 -1
  133. package/dist/chunk-P3RPDZHO.js +0 -36
  134. package/dist/chunk-P3RPDZHO.js.map +0 -1
  135. package/dist/chunk-PNWOW52F.js +0 -19
  136. package/dist/chunk-PNWOW52F.js.map +0 -1
  137. package/dist/chunk-R27FIYR5.js +0 -62
  138. package/dist/chunk-R27FIYR5.js.map +0 -1
  139. package/dist/chunk-S4WFNGQG.js +0 -17
  140. package/dist/chunk-S4WFNGQG.js.map +0 -1
  141. package/dist/chunk-TS3M7MWA.js +0 -3
  142. package/dist/chunk-TS3M7MWA.js.map +0 -1
  143. package/dist/chunk-UY4PNPBX.js +0 -156
  144. package/dist/chunk-UY4PNPBX.js.map +0 -1
  145. package/dist/chunk-VMH2LRM6.js +0 -114
  146. package/dist/chunk-VMH2LRM6.js.map +0 -1
  147. package/dist/chunk-VZDHIOCH.js +0 -76
  148. package/dist/chunk-VZDHIOCH.js.map +0 -1
  149. package/dist/chunk-WGVHM7DU.js +0 -66
  150. package/dist/chunk-WGVHM7DU.js.map +0 -1
  151. package/dist/chunk-WR5PDOPP.js +0 -91
  152. package/dist/chunk-WR5PDOPP.js.map +0 -1
  153. package/dist/chunk-YR433ZDA.js +0 -20
  154. package/dist/chunk-YR433ZDA.js.map +0 -1
  155. package/dist/executors/in-memory.d.ts +0 -39
  156. package/dist/executors/in-memory.js +0 -6
  157. package/dist/executors/in-memory.js.map +0 -1
  158. package/dist/executors/types.d.ts +0 -3
  159. package/dist/executors/types.js +0 -3
  160. package/dist/executors/types.js.map +0 -1
  161. package/dist/functions.d.ts +0 -88
  162. package/dist/functions.js +0 -21
  163. package/dist/functions.js.map +0 -1
  164. package/dist/types-U76Ukj96.d.ts +0 -609
  165. package/dist/utils/analysis.d.ts +0 -75
  166. package/dist/utils/analysis.js +0 -3
  167. package/dist/utils/index.d.ts +0 -8
  168. package/dist/utils/index.js +0 -10
  169. package/dist/utils/index.js.map +0 -1
  170. package/dist/utils/mermaid.d.ts +0 -46
  171. package/dist/utils/mermaid.js +0 -4
  172. package/dist/utils/mermaid.js.map +0 -1
  173. package/dist/utils/middleware.d.ts +0 -11
  174. package/dist/utils/middleware.js +0 -3
  175. package/dist/utils/middleware.js.map +0 -1
  176. package/dist/utils/sanitize.d.ts +0 -19
  177. package/dist/utils/sanitize.js +0 -3
  178. package/dist/utils/sleep.d.ts +0 -9
  179. package/dist/utils/sleep.js +0 -4
  180. package/dist/utils/sleep.js.map +0 -1
  181. package/dist/workflow/AbstractNode.d.ts +0 -3
  182. package/dist/workflow/AbstractNode.js +0 -4
  183. package/dist/workflow/AbstractNode.js.map +0 -1
  184. package/dist/workflow/Flow.d.ts +0 -3
  185. package/dist/workflow/Flow.js +0 -16
  186. package/dist/workflow/Flow.js.map +0 -1
  187. package/dist/workflow/Node.d.ts +0 -3
  188. package/dist/workflow/Node.js +0 -15
  189. package/dist/workflow/Node.js.map +0 -1
  190. package/dist/workflow/index.d.ts +0 -4
  191. package/dist/workflow/index.js +0 -18
  192. package/dist/workflow/index.js.map +0 -1
  193. package/dist/workflow/node-patterns.d.ts +0 -55
  194. package/dist/workflow/node-patterns.js +0 -16
  195. package/dist/workflow/node-patterns.js.map +0 -1
  196. package/dist/workflow/registry.d.ts +0 -17
  197. package/dist/workflow/registry.js +0 -3
  198. package/dist/workflow/registry.js.map +0 -1
  199. /package/dist/{utils/analysis.js.map → analysis.js.map} +0 -0
  200. /package/dist/{builder/graph → runtime}/index.js.map +0 -0
  201. /package/dist/{builder/graph → runtime}/types.js.map +0 -0
@@ -1,178 +0,0 @@
1
- import { Flow } from './chunk-UY4PNPBX.js';
2
- import { AbortError } from './chunk-64DNBF5W.js';
3
-
4
- // src/builder/patterns.ts
5
- var SequenceFlow = class extends Flow {
6
- /**
7
- * @param nodes A sequence of `Node` or `Flow` instances to be executed in order.
8
- */
9
- constructor(...nodes) {
10
- if (nodes.length === 0) {
11
- super();
12
- return;
13
- }
14
- super(nodes[0]);
15
- let current = nodes[0];
16
- for (let i = 1; i < nodes.length; i++)
17
- current = current.next(nodes[i]);
18
- }
19
- };
20
- var ParallelFlow = class extends Flow {
21
- /**
22
- * @param nodesToRun The array of nodes to execute concurrently.
23
- */
24
- constructor(nodesToRun = []) {
25
- super();
26
- this.nodesToRun = nodesToRun;
27
- }
28
- /** A tag to reliably identify this node type in the visualizer. */
29
- isParallelContainer = true;
30
- /**
31
- * Orchestrates the parallel execution of all nodes.
32
- * @internal
33
- */
34
- async exec({ ctx, params, signal, logger, executor, visitedInParallel }) {
35
- if (!visitedInParallel)
36
- throw new Error("ParallelFlow requires a visitedInParallel set from its executor.");
37
- const branches = this.nodesToRun.length > 0 ? this.nodesToRun : Array.from(this.successors.values()).flat();
38
- if (branches.length === 0) {
39
- logger.debug("[ParallelFlow] No branches to execute.");
40
- return;
41
- }
42
- const runBranch = async (startNode) => {
43
- let currentNode = startNode;
44
- while (currentNode) {
45
- if (signal?.aborted)
46
- throw new AbortError();
47
- if (visitedInParallel.has(currentNode))
48
- break;
49
- visitedInParallel.add(currentNode);
50
- const action = await currentNode._run({
51
- ctx,
52
- params: { ...params, ...currentNode.params },
53
- signal,
54
- logger,
55
- executor,
56
- visitedInParallel
57
- });
58
- currentNode = executor?.getNextNode(currentNode, action);
59
- }
60
- };
61
- const promises = branches.map(runBranch);
62
- await Promise.allSettled(promises);
63
- }
64
- };
65
- var BatchFlow = class extends Flow {
66
- constructor() {
67
- super();
68
- }
69
- /**
70
- * (Abstract) Prepares the list of items to be processed.
71
- * This method is called once before the batch processing begins.
72
- * @param _args The arguments for the node, including `ctx` and `params`.
73
- * @returns An array or iterable of parameter objects, one for each item.
74
- * The `nodeToRun` will be executed once for each of these objects.
75
- */
76
- async prep(_args) {
77
- return [];
78
- }
79
- /**
80
- * Orchestrates the sequential execution of `nodeToRun` for each item.
81
- * @internal
82
- */
83
- async exec(args) {
84
- if (!this.nodeToRun)
85
- return null;
86
- const combinedParams = { ...this.params, ...args.params };
87
- const batchParamsIterable = await this.prep(args) || [];
88
- const batchParamsList = Array.from(batchParamsIterable);
89
- for (const batchParams of batchParamsList) {
90
- if (args.signal?.aborted)
91
- throw new AbortError();
92
- await this.nodeToRun._run({
93
- ctx: args.ctx,
94
- params: { ...combinedParams, ...batchParams },
95
- signal: args.signal,
96
- logger: args.logger,
97
- executor: args.executor
98
- });
99
- }
100
- return null;
101
- }
102
- };
103
- var ParallelBatchFlow = class extends Flow {
104
- constructor() {
105
- super();
106
- }
107
- /**
108
- * (Abstract) Prepares the list of items to be processed.
109
- * This method is called once before the batch processing begins.
110
- * @param _args The arguments for the node, including `ctx` and `params`.
111
- * @returns An array or iterable of parameter objects, one for each item.
112
- * The `nodeToRun` will be executed concurrently for each of these objects.
113
- */
114
- async prep(_args) {
115
- return [];
116
- }
117
- /**
118
- * Orchestrates the parallel execution of `nodeToRun` for each item.
119
- * @internal
120
- */
121
- async exec(args) {
122
- if (!this.nodeToRun)
123
- return [];
124
- const combinedParams = { ...this.params, ...args.params };
125
- const batchParamsIterable = await this.prep(args) || [];
126
- const batchParamsList = Array.from(batchParamsIterable);
127
- const promises = batchParamsList.map((batchParams) => {
128
- return this.nodeToRun._run({
129
- ctx: args.ctx,
130
- params: { ...combinedParams, ...batchParams },
131
- signal: args.signal,
132
- logger: args.logger,
133
- executor: args.executor
134
- });
135
- });
136
- const results = await Promise.allSettled(promises);
137
- for (const result of results) {
138
- if (result.status === "rejected") {
139
- args.logger.error("A parallel batch item failed.", { error: result.reason });
140
- }
141
- }
142
- return results;
143
- }
144
- };
145
- function mapCollection(items, fn) {
146
- return new class extends Flow {
147
- async exec() {
148
- const promises = items.map((item) => fn(item));
149
- return Promise.all(promises);
150
- }
151
- }();
152
- }
153
- function filterCollection(items, predicate) {
154
- return new class extends Flow {
155
- async exec() {
156
- const results = await Promise.all(items.map((item) => predicate(item)));
157
- return items.filter((_, index) => results[index]);
158
- }
159
- }();
160
- }
161
- function reduceCollection(items, reducer, initialValue) {
162
- return new class extends Flow {
163
- async exec(_args) {
164
- let accumulator = initialValue;
165
- for (const item of items) {
166
- if (_args.signal?.aborted) {
167
- throw new AbortError();
168
- }
169
- accumulator = await reducer(accumulator, item);
170
- }
171
- return accumulator;
172
- }
173
- }();
174
- }
175
-
176
- export { BatchFlow, ParallelBatchFlow, ParallelFlow, SequenceFlow, filterCollection, mapCollection, reduceCollection };
177
- //# sourceMappingURL=chunk-L5PK5VL2.js.map
178
- //# sourceMappingURL=chunk-L5PK5VL2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/builder/patterns.ts"],"names":[],"mappings":";;;;AAWO,IAAM,YAAA,GAAN,cAKG,IAAA,CAA0C;AAAA;AAAA;AAAA;AAAA,EAInD,eAAe,KAAA,EAA2C;AACzD,IAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACvB,MAAA,KAAA,EAAM;AACN,MAAA;AAAA,IACD;AACA,IAAA,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA;AACd,IAAA,IAAI,OAAA,GAAU,MAAM,CAAC,CAAA;AACrB,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,MAAA,EAAQ,CAAA,EAAA;AACjC,MAAA,OAAA,GAAU,OAAA,CAAQ,IAAA,CAAK,KAAA,CAA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AAAA,IACR;AAAA,GACD,EAAE;AACH","file":"chunk-L5PK5VL2.js","sourcesContent":["import type { Context } from '../context'\nimport type { NodeFunction } from '../functions'\nimport type { NodeArgs, Params } from '../types'\nimport type { AbstractNode } from '../workflow/index'\nimport { AbortError } from '../errors'\nimport { Flow } from '../workflow/index'\n\n/**\n * A `Flow` that creates a linear workflow from a sequence of nodes,\n * automatically chaining them in order.\n */\nexport class SequenceFlow<\n\tPrepRes = any,\n\tExecRes = any,\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> extends Flow<PrepRes, ExecRes, TParams, TContext> {\n\t/**\n\t * @param nodes A sequence of `Node` or `Flow` instances to be executed in order.\n\t */\n\tconstructor(...nodes: AbstractNode<any, any, TContext>[]) {\n\t\tif (nodes.length === 0) {\n\t\t\tsuper()\n\t\t\treturn\n\t\t}\n\t\tsuper(nodes[0])\n\t\tlet current = nodes[0]\n\t\tfor (let i = 1; i < nodes.length; i++)\n\t\t\tcurrent = current.next(nodes[i])\n\t}\n}\n\n/**\n * A `Flow` that executes a collection of different nodes concurrently.\n * This is the core of the \"fan-out, fan-in\" pattern for structural parallelism.\n * After all parallel branches complete, the flow can proceed to a single successor.\n */\nexport class ParallelFlow<\n\tTContext extends Context = Context,\n> extends Flow<void, void, Params, TContext> {\n\t/** A tag to reliably identify this node type in the visualizer. */\n\tpublic readonly isParallelContainer = true\n\n\t/**\n\t * @param nodesToRun The array of nodes to execute concurrently.\n\t */\n\tconstructor(protected nodesToRun: AbstractNode<any, any, TContext>[] = []) {\n\t\tsuper()\n\t}\n\n\t/**\n\t * Orchestrates the parallel execution of all nodes.\n\t * @internal\n\t */\n\tasync exec({ ctx, params, signal, logger, executor, visitedInParallel }: NodeArgs<void, void, Params, TContext>): Promise<void> {\n\t\tif (!visitedInParallel)\n\t\t\tthrow new Error('ParallelFlow requires a visitedInParallel set from its executor.')\n\n\t\tconst branches = this.nodesToRun.length > 0\n\t\t\t? this.nodesToRun\n\t\t\t: Array.from(this.successors.values()).flat()\n\n\t\tif (branches.length === 0) {\n\t\t\tlogger.debug('[ParallelFlow] No branches to execute.')\n\t\t\treturn\n\t\t}\n\n\t\tconst runBranch = async (startNode: AbstractNode<any, any, TContext>) => {\n\t\t\tlet currentNode: AbstractNode<any, any, TContext> | undefined = startNode\n\t\t\twhile (currentNode) {\n\t\t\t\tif (signal?.aborted)\n\t\t\t\t\tthrow new AbortError()\n\n\t\t\t\tif (visitedInParallel.has(currentNode))\n\t\t\t\t\tbreak\n\t\t\t\tvisitedInParallel.add(currentNode)\n\n\t\t\t\tconst action = await currentNode._run({\n\t\t\t\t\tctx,\n\t\t\t\t\tparams: { ...params, ...currentNode.params },\n\t\t\t\t\tsignal,\n\t\t\t\t\tlogger,\n\t\t\t\t\texecutor,\n\t\t\t\t\tvisitedInParallel,\n\t\t\t\t})\n\n\t\t\t\tcurrentNode = executor?.getNextNode(currentNode, action)\n\t\t\t}\n\t\t}\n\n\t\tconst promises = branches.map(runBranch)\n\t\tawait Promise.allSettled(promises)\n\t}\n}\n\n/**\n * An abstract `Flow` that processes a collection of items sequentially, one by one.\n * Subclasses must implement the `prep` method to provide the items and the\n * `nodeToRun` property to define the processing logic for each item.\n */\nexport abstract class BatchFlow<\n\tT = any,\n\tTContext extends Context = Context,\n> extends Flow<Iterable<T>, null, Params, TContext> {\n\t/**\n\t * The `Node` instance that will be executed for each item in the batch.\n\t * This must be implemented by any subclass.\n\t */\n\tprotected abstract nodeToRun: AbstractNode<any, any, TContext>\n\n\tconstructor() {\n\t\tsuper()\n\t}\n\n\t/**\n\t * (Abstract) Prepares the list of items to be processed.\n\t * This method is called once before the batch processing begins.\n\t * @param _args The arguments for the node, including `ctx` and `params`.\n\t * @returns An array or iterable of parameter objects, one for each item.\n\t * The `nodeToRun` will be executed once for each of these objects.\n\t */\n\tasync prep(_args: NodeArgs<void, void, Params, TContext>): Promise<Iterable<any>> {\n\t\treturn []\n\t}\n\n\t/**\n\t * Orchestrates the sequential execution of `nodeToRun` for each item.\n\t * @internal\n\t */\n\tasync exec(args: NodeArgs<void, void, Params, TContext>): Promise<null> {\n\t\tif (!this.nodeToRun)\n\t\t\treturn null\n\n\t\tconst combinedParams = { ...this.params, ...args.params }\n\t\tconst batchParamsIterable = (await this.prep(args)) || []\n\t\tconst batchParamsList = Array.from(batchParamsIterable)\n\n\t\tfor (const batchParams of batchParamsList) {\n\t\t\tif (args.signal?.aborted)\n\t\t\t\tthrow new AbortError()\n\n\t\t\tawait this.nodeToRun._run({\n\t\t\t\tctx: args.ctx,\n\t\t\t\tparams: { ...combinedParams, ...batchParams },\n\t\t\t\tsignal: args.signal,\n\t\t\t\tlogger: args.logger,\n\t\t\t\texecutor: args.executor,\n\t\t\t})\n\t\t}\n\t\treturn null\n\t}\n}\n\n/**\n * An abstract `Flow` that processes a collection of items concurrently.\n * Subclasses must implement the `prep` method to provide the items and the\n * `nodeToRun` property to define the processing logic for each item.\n * This provides a significant performance boost for I/O-bound tasks.\n */\nexport abstract class ParallelBatchFlow<\n\tT = any,\n\tTContext extends Context = Context,\n> extends Flow<Iterable<T>, PromiseSettledResult<any>[], Params, TContext> {\n\t/**\n\t * The `Node` instance that will be executed concurrently for each item in the batch.\n\t * This must be implemented by any subclass.\n\t */\n\tprotected abstract nodeToRun: AbstractNode<any, any, TContext>\n\n\tconstructor() {\n\t\tsuper()\n\t}\n\n\t/**\n\t * (Abstract) Prepares the list of items to be processed.\n\t * This method is called once before the batch processing begins.\n\t * @param _args The arguments for the node, including `ctx` and `params`.\n\t * @returns An array or iterable of parameter objects, one for each item.\n\t * The `nodeToRun` will be executed concurrently for each of these objects.\n\t */\n\tasync prep(_args: NodeArgs<void, void, Params, TContext>): Promise<Iterable<any>> {\n\t\treturn []\n\t}\n\n\t/**\n\t * Orchestrates the parallel execution of `nodeToRun` for each item.\n\t * @internal\n\t */\n\tasync exec(args: NodeArgs<any, void, Params, TContext>): Promise<PromiseSettledResult<any>[]> {\n\t\tif (!this.nodeToRun)\n\t\t\treturn []\n\n\t\tconst combinedParams = { ...this.params, ...args.params }\n\t\tconst batchParamsIterable = (await this.prep(args)) || []\n\t\tconst batchParamsList = Array.from(batchParamsIterable)\n\n\t\tconst promises = batchParamsList.map((batchParams) => {\n\t\t\treturn this.nodeToRun._run({\n\t\t\t\tctx: args.ctx,\n\t\t\t\tparams: { ...combinedParams, ...batchParams },\n\t\t\t\tsignal: args.signal,\n\t\t\t\tlogger: args.logger,\n\t\t\t\texecutor: args.executor,\n\t\t\t})\n\t\t})\n\n\t\tconst results = await Promise.allSettled(promises)\n\n\t\tfor (const result of results) {\n\t\t\tif (result.status === 'rejected') {\n\t\t\t\targs.logger.error('A parallel batch item failed.', { error: result.reason })\n\t\t\t}\n\t\t}\n\n\t\treturn results\n\t}\n}\n\n/**\n * Creates a flow that applies a mapping function to each item in a collection in parallel\n * and returns a new array containing the results.\n *\n * @example\n * const numbers = [1, 2, 3];\n * const double = (n: number) => n * 2;\n * const processingFlow = mapCollection(numbers, double);\n * // When run, processingFlow's result will be [2, 4, 6]\n *\n * @param items The initial array of items of type `T`.\n * @param fn An async or sync function that transforms an item from type `T` to type `U`.\n * @returns A `Flow` instance that, when run, will output an array of type `U[]`.\n */\nexport function mapCollection<T, U, TContext extends Context = Context>(items: T[], fn: NodeFunction<T, U>): Flow<void, U[], Params, TContext> {\n\treturn new class extends Flow<void, U[], Params, TContext> {\n\t\tasync exec(): Promise<U[]> {\n\t\t\tconst promises = items.map(item => fn(item))\n\t\t\treturn Promise.all(promises)\n\t\t}\n\t}()\n}\n\n/**\n * Creates a flow that filters a collection based on a predicate function,\n * returning a new array containing only the items that pass the predicate.\n * The predicate is applied to all items concurrently.\n *\n * @example\n * const users = [{ id: 1, admin: true }, { id: 2, admin: false }];\n * const isAdmin = async (user: { admin: boolean }) => user.admin;\n * const adminFilterFlow = filterCollection(users, isAdmin);\n * // When run, the result will be [{ id: 1, admin: true }]\n *\n * @param items The initial array of items of type `T`.\n * @param predicate An async or sync function that returns `true` or `false` for an item.\n * @returns A `Flow` instance that, when run, will output a filtered array of type `T[]`.\n */\nexport function filterCollection<T, TContext extends Context = Context>(items: T[], predicate: (item: T) => boolean | Promise<boolean>): Flow<void, T[], Params, TContext> {\n\treturn new class extends Flow<void, T[], Params, TContext> {\n\t\tasync exec(): Promise<T[]> {\n\t\t\tconst results = await Promise.all(items.map(item => predicate(item)))\n\t\t\treturn items.filter((_, index) => results[index])\n\t\t}\n\t}()\n}\n\n/**\n * Creates a flow that reduces a collection to a single value by executing a\n * reducer function sequentially for each item, similar to `Array.prototype.reduce()`.\n *\n * @example\n * const numbers = [1, 2, 3, 4];\n * const sumReducer = (acc: number, val: number) => acc + val;\n * const sumFlow = reduceCollection(numbers, sumReducer, 0);\n * // When run, the result will be 10.\n *\n * @param items The array of items to be reduced.\n * @param reducer An async or sync function that processes the accumulator and the current item.\n * @param initialValue The initial value for the accumulator.\n * @returns A `Flow` instance that, when run, will output the final accumulated value of type `U`.\n */\nexport function reduceCollection<T, U, TContext extends Context = Context>(\n\titems: T[],\n\treducer: (accumulator: U, item: T) => U | Promise<U>,\n\tinitialValue: U,\n): Flow<void, U, Params, TContext> {\n\treturn new class extends Flow<void, U, Params, TContext> {\n\t\tasync exec(_args: NodeArgs<void, void, Params, TContext>): Promise<U> {\n\t\t\tlet accumulator = initialValue\n\t\t\tfor (const item of items) {\n\t\t\t\tif (_args.signal?.aborted) {\n\t\t\t\t\tthrow new AbortError()\n\t\t\t\t}\n\t\t\t\taccumulator = await reducer(accumulator, item)\n\t\t\t}\n\t\t\treturn accumulator\n\t\t}\n\t}()\n}\n"]}
@@ -1,36 +0,0 @@
1
- import { composeContext } from './chunk-R27FIYR5.js';
2
- import { SequenceFlow } from './chunk-L5PK5VL2.js';
3
- import { Node } from './chunk-HEO3XL4Z.js';
4
-
5
- // src/functions.ts
6
- function mapNode(fn) {
7
- return new class extends Node {
8
- async exec({ params }) {
9
- return fn(params);
10
- }
11
- }();
12
- }
13
- function contextNode(fn) {
14
- return new class extends Node {
15
- async exec({ ctx, params }) {
16
- return await fn(ctx, params);
17
- }
18
- }();
19
- }
20
- function transformNode(...transforms) {
21
- return new class extends Node {
22
- async prep({ ctx }) {
23
- await composeContext(...transforms)(ctx);
24
- }
25
- }();
26
- }
27
- function pipeline(...nodes) {
28
- return new SequenceFlow(...nodes);
29
- }
30
- function compose(f, g) {
31
- return async (input) => f(await g(input));
32
- }
33
-
34
- export { compose, contextNode, mapNode, pipeline, transformNode };
35
- //# sourceMappingURL=chunk-P3RPDZHO.js.map
36
- //# sourceMappingURL=chunk-P3RPDZHO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/functions.ts"],"names":[],"mappings":";;;;;AAkCO,SAAS,QAId,EAAA,EAAmE;AACpE,EAAA,OAAO,IAAI,cAAc,IAAA,CAAyC;AAAA,IACjE,MAAM,IAAA,CAAK,EAAE,MAAA,EAAO,EAAuD;AAC1E,MAAA,OAAO,GAAG,MAAa,CAAA;AAAA,IACxB;AAAA,GACD,EAAE;AACH;AAeO,SAAS,YAId,EAAA,EAAgF;AACjF,EAAA,OAAO,IAAI,cAAc,IAAA,CAAyC;AAAA,IACjE,MAAM,IAAA,CAAK,EAAE,GAAA,EAAK,QAAO,EAAuD;AAC/E,MAAA,OAAO,MAAM,EAAA,CAAG,GAAA,EAAK,MAAa,CAAA;AAAA,IACnC;AAAA,GACD,EAAE;AACH;AAeO,SAAS,iBAAqD,UAAA,EAAyE;AAC7I,EAAA,OAAO,IAAI,cAAc,IAAA,CAA4C;AAAA,IACpE,MAAM,IAAA,CAAK,EAAE,GAAA,EAAI,EAA2C;AAE3D,MAAA,MAAM,cAAA,CAAe,GAAG,UAAU,CAAA,CAAE,GAAG,CAAA;AAAA,IACxC;AAAA,GACD,EAAE;AACH;AAYO,SAAS,YAAgD,KAAA,EAA+E;AAC9I,EAAA,OAAO,IAAI,YAAA,CAAyC,GAAG,KAAK,CAAA;AAC7D;AAkBO,SAAS,OAAA,CAAiB,GAAuB,CAAA,EAA2C;AAClG,EAAA,OAAO,OAAO,KAAA,KAAa,CAAA,CAAE,MAAM,CAAA,CAAE,KAAK,CAAC,CAAA;AAC5C","file":"chunk-P3RPDZHO.js","sourcesContent":["import type { Context, ContextTransform } from './context'\nimport type { NodeArgs, Params } from './types'\nimport type { Flow, Node } from './workflow/index'\nimport { SequenceFlow } from './builder/patterns'\nimport { composeContext } from './context'\nimport { Node as BaseNode } from './workflow/index'\n\n/**\n * A type for a pure function that can be executed within a `Node`,\n * typically taking the node's `params` as input.\n * @template TIn The input type, corresponding to `params`.\n * @template TOut The output type, which becomes the node's `execRes`.\n */\nexport type NodeFunction<TIn = any, TOut = any> = (input: TIn) => TOut | Promise<TOut>\n\n/**\n * A type for a function that operates on the shared `Context` in addition\n * to the node's `params`.\n * @template TIn The input type, corresponding to `params`.\n * @template TOut The output type, which becomes the node's `execRes`.\n */\nexport type ContextFunction<TIn = any, TOut = any, TContext extends Context = Context> = (ctx: TContext, input: TIn) => TOut | Promise<TOut>\n\n/**\n * Creates a `Node` from a simple, pure function that transforms an input to an output.\n * The node's `params` object is passed as the input to the function.\n *\n * @example\n * const add = (n: number) => mapNode<{ value: number }, number>(params => params.value + n)\n * const add5Node = add(5) // A reusable node that adds 5 to its input parameter.\n *\n * @param fn A function that takes an input object and returns a result.\n * @returns A new `Node` instance that wraps the function.\n */\nexport function mapNode<\n\tTIn extends Params,\n\tTOut,\n\tTContext extends Context = Context,\n>(fn: NodeFunction<TIn, TOut>): Node<void, TOut, any, TIn, TContext> {\n\treturn new class extends BaseNode<void, TOut, any, TIn, TContext> {\n\t\tasync exec({ params }: NodeArgs<void, void, TIn, TContext>): Promise<TOut> {\n\t\t\treturn fn(params as TIn)\n\t\t}\n\t}()\n}\n\n/**\n * Creates a `Node` from a function that requires access to the shared `Context`.\n * Both the `Context` and the node's `params` are passed as arguments to the function.\n *\n * @example\n * const greeter = contextNode(async (ctx, params: { name: string }) => {\n * const language = await ctx.get(LANGUAGE_KEY) || 'en'\n * return language === 'en' ? `Hello, ${params.name}` : `Hola, ${params.name}`\n * })\n *\n * @param fn A function that takes the context and an input object, and returns a result.\n * @returns A new `Node` instance that wraps the function.\n */\nexport function contextNode<\n\tTIn extends Params,\n\tTOut,\n\tTContext extends Context = Context,\n>(fn: ContextFunction<TIn, TOut, TContext>): Node<void, TOut, any, TIn, TContext> {\n\treturn new class extends BaseNode<void, TOut, any, TIn, TContext> {\n\t\tasync exec({ ctx, params }: NodeArgs<void, void, TIn, TContext>): Promise<TOut> {\n\t\t\treturn await fn(ctx, params as TIn)\n\t\t}\n\t}()\n}\n\n/**\n * Creates a `Node` that declaratively applies a series of transformations to the `Context`.\n * This is a \"side-effect\" node used purely for state management; its logic runs in the `prep` phase,\n * and it does not produce an `exec` output.\n *\n * @example\n * const USER_ID = contextKey<string>('user_id')\n * const userLens = lens(USER_ID)\n * const setupUserContext = (userId: string) => transformNode(userLens.set(userId))\n *\n * @param transforms A sequence of `ContextTransform` functions (e.g., from a lens) to apply.\n * @returns A new `Node` instance that will mutate the context when executed.\n */\nexport function transformNode<TContext extends Context = Context>(...transforms: ContextTransform[]): Node<void, void, any, Params, TContext> {\n\treturn new class extends BaseNode<void, void, any, Params, TContext> {\n\t\tasync prep({ ctx }: NodeArgs<void, void, Params, TContext>) {\n\t\t\t// Apply the composed transformations directly to the mutable context.\n\t\t\tawait composeContext(...transforms)(ctx)\n\t\t}\n\t}()\n}\n\n/**\n * A functional-style alias for `SequenceFlow`. It constructs a linear workflow\n * where each node executes in the order it is provided.\n *\n * @example\n * const mathPipeline = pipeline(addNode(5), multiplyNode(2))\n *\n * @param nodes A sequence of `Node` instances to chain together.\n * @returns A `Flow` instance representing the linear sequence.\n */\nexport function pipeline<TContext extends Context = Context>(...nodes: Node<any, any, any, any, TContext>[]): Flow<any, any, Params, TContext> {\n\treturn new SequenceFlow<any, any, Params, TContext>(...nodes)\n}\n\n/**\n * A classic functional composition utility. It takes two functions, `f` and `g`,\n * and returns a new function that computes `f(g(x))`.\n *\n * This is a general-purpose helper, not a `Node` builder itself, but it can be\n * used to create more complex `NodeFunction`s to pass to `mapNode`.\n *\n * @example\n * const add5 = (x: number) => x + 5\n * const multiply2 = (x: number) => x * 2\n * const add5ThenMultiply2 = compose(multiply2, add5) // equivalent to: x => (x + 5) * 2\n *\n * @param f The outer function, which receives the result of `g`.\n * @param g The inner function, which receives the initial input.\n * @returns A new `NodeFunction` that combines both operations.\n */\nexport function compose<A, B, C>(f: NodeFunction<B, C>, g: NodeFunction<A, B>): NodeFunction<A, C> {\n\treturn async (input: A) => f(await g(input))\n}\n"]}
@@ -1,19 +0,0 @@
1
- // src/utils/middleware.ts
2
- function applyMiddleware(middleware, nodeToRun) {
3
- const runNode = (args) => {
4
- return nodeToRun._run({
5
- ...args,
6
- params: { ...args.params, ...nodeToRun.params }
7
- });
8
- };
9
- if (!middleware || middleware.length === 0)
10
- return runNode;
11
- return middleware.reduceRight(
12
- (next, mw) => (args) => mw(args, next),
13
- runNode
14
- );
15
- }
16
-
17
- export { applyMiddleware };
18
- //# sourceMappingURL=chunk-PNWOW52F.js.map
19
- //# sourceMappingURL=chunk-PNWOW52F.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/middleware.ts"],"names":[],"mappings":";AAOO,SAAS,eAAA,CAAyB,YAA6B,SAAA,EAA4C;AACjH,EAAA,MAAM,OAAA,GAA6B,CAAC,IAAA,KAAmB;AACtD,IAAA,OAAO,UAAU,IAAA,CAAK;AAAA,MACrB,GAAG,IAAA;AAAA,MACH,QAAQ,EAAE,GAAG,KAAK,MAAA,EAAQ,GAAG,UAAU,MAAA;AAAO,KAC9C,CAAA;AAAA,EACF,CAAA;AAEA,EAAA,IAAI,CAAC,UAAA,IAAc,UAAA,CAAW,MAAA,KAAW,CAAA;AACxC,IAAA,OAAO,OAAA;AAGR,EAAA,OAAO,UAAA,CAAW,WAAA;AAAA,IACjB,CAAC,IAAA,EAAM,EAAA,KAAO,CAAC,IAAA,KAAmB,EAAA,CAAG,MAAM,IAAI,CAAA;AAAA,IAC/C;AAAA,GACD;AACD","file":"chunk-PNWOW52F.js","sourcesContent":["import type { Middleware, MiddlewareNext, NodeArgs } from '../types'\nimport type { AbstractNode } from '../workflow/index'\n\n/**\n * Composes a chain of middleware functions around a node's execution.\n * @internal\n */\nexport function applyMiddleware<T = any>(middleware: Middleware<T>[], nodeToRun: AbstractNode): MiddlewareNext<T> {\n\tconst runNode: MiddlewareNext<T> = (args: NodeArgs) => {\n\t\treturn nodeToRun._run({\n\t\t\t...args,\n\t\t\tparams: { ...args.params, ...nodeToRun.params },\n\t\t})\n\t}\n\n\tif (!middleware || middleware.length === 0)\n\t\treturn runNode\n\n\t// Build the chain backwards, so the first middleware in the array is the outermost.\n\treturn middleware.reduceRight<MiddlewareNext<T>>(\n\t\t(next, mw) => (args: NodeArgs) => mw(args, next),\n\t\trunNode,\n\t)\n}\n"]}
@@ -1,62 +0,0 @@
1
- // src/context.ts
2
- var contextKey = (description) => Symbol(description);
3
- var TypedContext = class {
4
- data;
5
- /**
6
- * @param initialData An optional iterable (like an array of `[key, value]` pairs)
7
- * to initialize the context with.
8
- */
9
- constructor(initialData) {
10
- this.data = new Map(initialData);
11
- }
12
- async get(key) {
13
- return this.data.get(key);
14
- }
15
- async set(key, value) {
16
- this.data.set(key, value);
17
- return this;
18
- }
19
- async has(key) {
20
- return this.data.has(key);
21
- }
22
- async delete(key) {
23
- return this.data.delete(key);
24
- }
25
- entries() {
26
- return this.data.entries();
27
- }
28
- keys() {
29
- return this.data.keys();
30
- }
31
- values() {
32
- return this.data.values();
33
- }
34
- };
35
- function lens(key) {
36
- return {
37
- get: async (ctx) => {
38
- return await ctx.get(key);
39
- },
40
- set: (value) => async (ctx) => {
41
- return await ctx.set(key, value);
42
- },
43
- update: (fn) => async (ctx) => {
44
- const currentValue = await ctx.get(key);
45
- const newValue = fn(currentValue);
46
- return await ctx.set(key, newValue);
47
- }
48
- };
49
- }
50
- function composeContext(...transforms) {
51
- return async (ctx) => {
52
- let currentContext = ctx;
53
- for (const transform of transforms) {
54
- currentContext = await transform(currentContext);
55
- }
56
- return currentContext;
57
- };
58
- }
59
-
60
- export { TypedContext, composeContext, contextKey, lens };
61
- //# sourceMappingURL=chunk-R27FIYR5.js.map
62
- //# sourceMappingURL=chunk-R27FIYR5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context.ts"],"names":[],"mappings":";AAeO,IAAM,UAAA,GAAa,CAAI,WAAA,KAAwC,MAAA,CAAO,WAAW;AA6CjF,IAAM,eAAN,MAAsC;AAAA,EACpC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,WAAA,EAAyE;AACpF,IAAA,IAAA,CAAK,IAAA,GAAO,IAAI,GAAA,CAAc,WAAW,CAAA;AAAA,EAC1C;AAAA,EACA,MAAM,IAAI,GAAA,EAA6C;AAAE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA;AAAA,EAAE;AAAA,EACnF,MAAM,GAAA,CAAI,GAAA,EAA+B,KAAA,EAA2B;AAAE,IAAA,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAG,IAAA,OAAO,IAAA;AAAA,EAAK;AAAA,EAC7G,MAAM,IAAI,GAAA,EAAiD;AAAE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA;AAAA,EAAE;AAAA,EACvF,MAAM,OAAO,GAAA,EAAiD;AAAE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,MAAA,CAAO,GAAG,CAAA;AAAA,EAAE;AAAA,EAC7F,OAAA,GAAwC;AAAE,IAAA,OAAO,IAAA,CAAK,KAAK,OAAA,EAAQ;AAAA,EAAE;AAAA,EACrE,IAAA,GAA8B;AAAE,IAAA,OAAO,IAAA,CAAK,KAAK,IAAA,EAAK;AAAA,EAAE;AAAA,EACxD,MAAA,GAAgC;AAAE,IAAA,OAAO,IAAA,CAAK,KAAK,MAAA,EAAO;AAAA,EAAE;AAC7D;AAsCO,SAAS,KAAQ,GAAA,EAAoC;AAC3D,EAAA,OAAO;AAAA,IACN,GAAA,EAAK,OAAO,GAAA,KAAyC;AACpD,MAAA,OAAO,MAAM,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA;AAAA,IACzB,CAAA;AAAA,IACA,GAAA,EAAK,CAAC,KAAA,KAA+B,OAAO,GAAA,KAAiB;AAC5D,MAAA,OAAO,MAAM,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAA,IAChC,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,EAAA,KAAwD,OAAO,GAAA,KAAiB;AACxF,MAAA,MAAM,YAAA,GAAe,MAAM,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA;AACtC,MAAA,MAAM,QAAA,GAAW,GAAG,YAAY,CAAA;AAChC,MAAA,OAAO,MAAM,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,QAAQ,CAAA;AAAA,IACnC;AAAA,GACD;AACD;AASO,SAAS,kBAAkB,UAAA,EAAkD;AACnF,EAAA,OAAO,OAAO,GAAA,KAAiB;AAC9B,IAAA,IAAI,cAAA,GAAiB,GAAA;AACrB,IAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AACnC,MAAA,cAAA,GAAiB,MAAM,UAAU,cAAc,CAAA;AAAA,IAChD;AACA,IAAA,OAAO,cAAA;AAAA,EACR,CAAA;AACD","file":"chunk-R27FIYR5.js","sourcesContent":["/* eslint-disable style/lines-between-class-members, style/max-statements-per-line */\n\n/**\n * A type-safe, opaque key for storing and retrieving values from the Context.\n * Using a `ContextKey` provides compile-time safety for your workflow's state.\n * @template T The type of the value this key refers to.\n */\nexport type ContextKey<T> = symbol & { __type: T }\n\n/**\n * Creates a new, unique `ContextKey` for type-safe access to the `Context`.\n * @template T The type of the value this key will hold.\n * @param description An optional description for debugging purposes (e.g., in logs or test snapshots).\n * @returns A unique `ContextKey<T>`.\n */\nexport const contextKey = <T>(description?: string): ContextKey<T> => Symbol(description) as ContextKey<T>\n\n/**\n * Defines the interface for the shared context object passed through the workflow.\n * This interface is \"async-aware\", allowing for both synchronous (Map-based)\n * and asynchronous (e.g., Redis-backed) implementations.\n */\nexport interface Context {\n\t/**\n\t * Asynchronously retrieves a value from the context.\n\t * Callers should ALWAYS `await` the result of this method.\n\t */\n\tget: (<T>(key: ContextKey<T>) => Promise<T | undefined>)\n\t\t& (<T = any>(key: string) => Promise<T | undefined>)\n\t/** Asynchronously stores a value in the context. */\n\tset: (<T>(key: ContextKey<T>, value: T) => Promise<this>)\n\t\t& ((key: string, value: any) => Promise<this>)\n\t/** Asynchronously checks if a key exists in the context. */\n\thas: ((key: ContextKey<any>) => Promise<boolean>)\n\t\t& ((key: string) => Promise<boolean>)\n\t/** Asynchronously deletes a key from the context. */\n\tdelete: ((key: ContextKey<any>) => Promise<boolean>)\n\t\t& ((key: string) => Promise<boolean>)\n\t/**\n\t * Returns an iterator of all [key, value] pairs in the context.\n\t * NOTE: This may not be supported or may be inefficient in some async implementations.\n\t */\n\tentries: () => IterableIterator<[any, any]>\n\t/**\n\t * Returns an iterator of all keys in the context.\n\t * NOTE: This may not be supported or may be inefficient in some async implementations.\n\t */\n\tkeys: () => IterableIterator<any>\n\t/**\n\t * Returns an iterator of all values in the context.\n\t * NOTE: This may not be supported or may be inefficient in some async implementations.\n\t */\n\tvalues: () => IterableIterator<any>\n}\n\n/**\n * The default, `Map`-based implementation of the `Context` interface.\n * Its methods are async to satisfy the `Context` interface, but they wrap\n * synchronous operations.\n */\nexport class TypedContext implements Context {\n\tprivate data: Map<any, any>\n\t/**\n\t * @param initialData An optional iterable (like an array of `[key, value]` pairs)\n\t * to initialize the context with.\n\t */\n\tconstructor(initialData?: Iterable<readonly [ContextKey<any> | string, any]> | null) {\n\t\tthis.data = new Map<any, any>(initialData)\n\t}\n\tasync get(key: ContextKey<any> | string): Promise<any> { return this.data.get(key) }\n\tasync set(key: ContextKey<any> | string, value: any): Promise<this> { this.data.set(key, value); return this }\n\tasync has(key: ContextKey<any> | string): Promise<boolean> { return this.data.has(key) }\n\tasync delete(key: ContextKey<any> | string): Promise<boolean> { return this.data.delete(key) }\n\tentries(): IterableIterator<[any, any]> { return this.data.entries() }\n\tkeys(): IterableIterator<any> { return this.data.keys() }\n\tvalues(): IterableIterator<any> { return this.data.values() }\n}\n\n/** A function that takes a `Context` and returns a (potentially new) `Context`. */\nexport type ContextTransform = (ctx: Context) => Context | Promise<Context>\n\n/**\n * A \"lens\" provides a way to \"focus\" on a single key in the `Context`,\n * creating reusable, type-safe async functions to get, set, or update its value.\n * @template T The type of the value the lens focuses on.\n */\nexport interface ContextLens<T> {\n\t/** Asynchronously retrieves the value for the key from the context. */\n\tget: (ctx: Context) => Promise<T | undefined>\n\t/** Returns an asynchronous `ContextTransform` function that will set the key to the provided value. */\n\tset: (value: T) => ContextTransform\n\t/** Returns an asynchronous `ContextTransform` function that updates the key's value based on its current value. */\n\tupdate: (fn: (current: T | undefined) => T) => ContextTransform\n}\n\n/**\n * Creates a `ContextLens` object for a specific `ContextKey`.\n * This is the entry point for functional context manipulation.\n * All operations that read from the context are now async.\n *\n * @example\n * const NAME = contextKey<string>('name')\n * const nameLens = lens(NAME)\n *\n * // Usage in an async function:\n * async function exampleUsage(ctx: Context) {\n * const currentName = await nameLens.get(ctx);\n * const setNameTransform = nameLens.set('Alice');\n * await setNameTransform(ctx);\n * }\n *\n * @param key The `ContextKey` to focus on.\n * @returns A `ContextLens<T>` object with async-aware methods.\n */\nexport function lens<T>(key: ContextKey<T>): ContextLens<T> {\n\treturn {\n\t\tget: async (ctx: Context): Promise<T | undefined> => {\n\t\t\treturn await ctx.get(key) as T | undefined\n\t\t},\n\t\tset: (value: T): ContextTransform => async (ctx: Context) => {\n\t\t\treturn await ctx.set(key, value)\n\t\t},\n\t\tupdate: (fn: (current: T | undefined) => T): ContextTransform => async (ctx: Context) => {\n\t\t\tconst currentValue = await ctx.get(key) as T | undefined\n\t\t\tconst newValue = fn(currentValue)\n\t\t\treturn await ctx.set(key, newValue)\n\t\t},\n\t}\n}\n\n/**\n * Composes multiple `ContextTransform` functions into a single `ContextTransform` function.\n * The transformations are applied in the order they are provided.\n *\n * @param transforms A sequence of `ContextTransform` functions.\n * @returns A single function that applies all transformations.\n */\nexport function composeContext(...transforms: ContextTransform[]): ContextTransform {\n\treturn async (ctx: Context) => {\n\t\tlet currentContext = ctx\n\t\tfor (const transform of transforms) {\n\t\t\tcurrentContext = await transform(currentContext)\n\t\t}\n\t\treturn currentContext\n\t}\n}\n"]}
@@ -1,17 +0,0 @@
1
- // src/workflow/registry.ts
2
- var flowConstructor;
3
- function registerFlow(constructor) {
4
- flowConstructor = constructor;
5
- }
6
- function getFlowConstructor() {
7
- if (!flowConstructor) {
8
- throw new Error(
9
- "Flow constructor has not been registered. This is an internal error in the framework, likely due to a module loading issue."
10
- );
11
- }
12
- return flowConstructor;
13
- }
14
-
15
- export { getFlowConstructor, registerFlow };
16
- //# sourceMappingURL=chunk-S4WFNGQG.js.map
17
- //# sourceMappingURL=chunk-S4WFNGQG.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/workflow/registry.ts"],"names":[],"mappings":";AAMA,IAAI,eAAA;AAMG,SAAS,aAAa,WAAA,EAAoC;AAChE,EAAA,eAAA,GAAkB,WAAA;AACnB;AAMO,SAAS,kBAAA,GAAsC;AACrD,EAAA,IAAI,CAAC,eAAA,EAAiB;AACrB,IAAA,MAAM,IAAI,KAAA;AAAA,MACT;AAAA,KACD;AAAA,EACD;AACA,EAAA,OAAO,eAAA;AACR","file":"chunk-S4WFNGQG.js","sourcesContent":["import type { AbstractNode } from './AbstractNode'\nimport type { Flow } from './Flow'\n\n// A type alias for the Flow class constructor.\ntype FlowConstructor = new (start?: AbstractNode) => Flow\n\nlet flowConstructor: FlowConstructor | undefined\n\n/**\n * For internal use by the Flow class to register itself, breaking the circular dependency.\n * @internal\n */\nexport function registerFlow(constructor: FlowConstructor): void {\n\tflowConstructor = constructor\n}\n\n/**\n * For internal use by the Node class to get the Flow constructor without a direct import.\n * @internal\n */\nexport function getFlowConstructor(): FlowConstructor {\n\tif (!flowConstructor) {\n\t\tthrow new Error(\n\t\t\t'Flow constructor has not been registered. This is an internal error in the framework, likely due to a module loading issue.',\n\t\t)\n\t}\n\treturn flowConstructor\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=chunk-TS3M7MWA.js.map
3
- //# sourceMappingURL=chunk-TS3M7MWA.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-TS3M7MWA.js"}
@@ -1,156 +0,0 @@
1
- import { Node } from './chunk-HEO3XL4Z.js';
2
- import { InMemoryExecutor } from './chunk-BRFMFLR6.js';
3
- import { registerFlow } from './chunk-S4WFNGQG.js';
4
-
5
- // src/workflow/Flow.ts
6
- var Flow = class extends Node {
7
- /** The first node to be executed in this flow's graph. */
8
- startNode;
9
- /** An array of middleware functions to be applied to every node within this flow. */
10
- middleware = [];
11
- /**
12
- * @param start An optional node to start the flow with.
13
- */
14
- constructor(start) {
15
- super();
16
- this.startNode = start;
17
- }
18
- _wrapError(e, phase) {
19
- if (phase === "exec") {
20
- return e;
21
- }
22
- return super._wrapError(e, phase);
23
- }
24
- /**
25
- * Adds a middleware function to this flow. Middleware will be executed in the
26
- * order it is added, wrapping the execution of every node within this flow.
27
- * @param fn The middleware function to add.
28
- * @returns The `Flow` instance for chaining.
29
- */
30
- use(fn) {
31
- this.middleware.push(fn);
32
- return this;
33
- }
34
- /**
35
- * Sets the starting node of the flow's graph.
36
- * @param start The node to start with.
37
- * @returns The start node instance, allowing for further chaining (`.next()`).
38
- */
39
- start(start) {
40
- this.startNode = start;
41
- return start;
42
- }
43
- /**
44
- * (Lifecycle) Executes this flow's internal graph when it is used as a sub-flow
45
- * (a node within a larger flow).
46
- * @internal
47
- * @param args The arguments for the node, passed down from the parent executor.
48
- * @returns The final action returned by the last node in this flow's graph.
49
- */
50
- async exec(args) {
51
- if (!(args.executor instanceof InMemoryExecutor)) {
52
- throw new TypeError("Programmatic sub-flow execution is only supported by the InMemoryExecutor. For other environments, use GraphBuilder to create a single, flattened workflow.");
53
- }
54
- if (!this.startNode) {
55
- return super.exec(args);
56
- }
57
- const combinedParams = { ...args.params, ...this.params };
58
- const internalOptions = {
59
- logger: args.logger,
60
- signal: args.signal,
61
- params: combinedParams,
62
- executor: args.executor
63
- };
64
- const finalAction = await args.executor._orch(
65
- this.startNode,
66
- this.middleware,
67
- args.ctx,
68
- internalOptions
69
- );
70
- return finalAction;
71
- }
72
- /**
73
- * (Lifecycle) The post-execution step for a `Flow` node. It simply passes through
74
- * the final action from its internal graph execution (`execRes`).
75
- * @internal
76
- */
77
- async post({ execRes }) {
78
- return execRes;
79
- }
80
- /**
81
- * Runs the entire flow as a top-level entry point.
82
- * @param ctx The shared workflow context.
83
- * @param options Runtime options like a logger, abort controller, or a custom executor.
84
- * @returns The final action returned by the last node in the flow.
85
- */
86
- async run(ctx, options) {
87
- const executor = options?.executor ?? new InMemoryExecutor();
88
- return executor.run(this, ctx, options);
89
- }
90
- /**
91
- * Finds a node within the flow's graph by its unique ID.
92
- *
93
- * This method performs a breadth-first search starting from the `startNode`.
94
- * It is a convenient way to get a reference to a specific node instance
95
- * for debugging or dynamic modifications.
96
- *
97
- * @remarks
98
- * This performs a graph traversal on each call, which has a time complexity
99
- * proportional to the number of nodes and edges in the graph (O(V+E)). For
100
- * performance-critical applications or flows built with `GraphBuilder`,
101
- * it is more efficient to use the `nodeMap` returned by `GraphBuilder.build()`.
102
- *
103
- * @param id The unique ID of the node to find (set via `.withId()` or by the `GraphBuilder`).
104
- * @returns The `AbstractNode` instance if found, otherwise `undefined`.
105
- */
106
- getNodeById(id) {
107
- if (!this.startNode)
108
- return void 0;
109
- const queue = [this.startNode];
110
- const visited = /* @__PURE__ */ new Set([this.startNode]);
111
- while (queue.length > 0) {
112
- const currentNode = queue.shift();
113
- if (currentNode.id === id)
114
- return currentNode;
115
- for (const successorArray of currentNode.successors.values()) {
116
- for (const successor of successorArray) {
117
- if (!visited.has(successor)) {
118
- visited.add(successor);
119
- queue.push(successor);
120
- }
121
- }
122
- }
123
- }
124
- return void 0;
125
- }
126
- /**
127
- * Retrieves all unique nodes within the flow's graph.
128
- * @internal
129
- */
130
- getAllNodes() {
131
- const allNodes = /* @__PURE__ */ new Set();
132
- if (!this.startNode)
133
- return allNodes;
134
- const queue = [this.startNode];
135
- const visited = /* @__PURE__ */ new Set([this.startNode]);
136
- allNodes.add(this.startNode);
137
- while (queue.length > 0) {
138
- const currentNode = queue.shift();
139
- for (const successorArray of currentNode.successors.values()) {
140
- for (const successor of successorArray) {
141
- if (!visited.has(successor)) {
142
- visited.add(successor);
143
- queue.push(successor);
144
- allNodes.add(successor);
145
- }
146
- }
147
- }
148
- }
149
- return allNodes;
150
- }
151
- };
152
- registerFlow(Flow);
153
-
154
- export { Flow };
155
- //# sourceMappingURL=chunk-UY4PNPBX.js.map
156
- //# sourceMappingURL=chunk-UY4PNPBX.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/workflow/Flow.ts"],"names":[],"mappings":";;;;;AAgBO,IAAM,IAAA,GAAN,cAKG,IAAA,CAAmD;AAAA;AAAA,EAErD,SAAA;AAAA;AAAA,EAEA,aAA2B,EAAC;AAAA;AAAA;AAAA;AAAA,EAKnC,YAAY,KAAA,EAA0C;AACrD,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,SAAA,GAAY,KAAA;AAAA,EAClB;AAAA,EAEU,UAAA,CAAW,GAAQ,KAAA,EAAwC;AACpE,IAAA,IAAI,UAAU,MAAA,EAAQ;AAErB,MAAA,OAAO,CAAA;AAAA,IACR;AACA,IAAA,OAAO,KAAA,CAAM,UAAA,CAAW,CAAA,EAAG,KAAK,CAAA;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,IAAI,EAAA,EAAsB;AAChC,IAAA,I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M,0BAAU,IAAI,GAAA,CAAkB,CAAC,IAAA,CAAK,SAAS,CAAC,CAAA;AACtD,IAAA,QAAA,CAAS,GAAA,CAAI,KAAK,SAAS,CAAA;AAE3B,IAAA,OAAO,KAAA,CAAM,SAAS,CAAA,EAAG;AACxB,MAAA,MAAM,WAAA,GAAc,MAAM,KAAA,EAAM;AAChC,MAAA,KAAA,MAAW,cAAA,IAAkB,WAAA,CAAY,UAAA,CAAW,MAAA,EAAO,EAAG;AAC7D,QAAA,KAAA,MAAW,aAAa,cAAA,EAAgB;AACvC,UAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA,EAAG;AAC5B,YAAA,OAAA,CAAQ,IAAI,SAAS,CAAA;AACrB,YAAA,KAAA,CAAM,KAAK,SAAS,CAAA;AACpB,YAAA,QAAA,CAAS,IAAI,SAAS,CAAA;AAAA,UACvB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACA,IAAA,OAAO,QAAA;AAAA,EACR;AACD;AAEA,YAAA,CAAa,IAAI,CAAA","file":"chunk-UY4PNPBX.js","sourcesContent":["import type { Context } from '../context'\nimport type { InternalRunOptions } from '../executors/types'\nimport type { Middleware, NodeArgs, Params, RunOptions } from '../types'\nimport type { AbstractNode } from './AbstractNode'\nimport { InMemoryExecutor } from '../executors/in-memory'\nimport { Node } from './Node'\nimport { registerFlow } from './registry'\n\n/**\n * A special type of `Node` that orchestrates a graph of other nodes.\n * It can contain its own middleware and can be composed within other flows.\n *\n * @template PrepRes The type of data returned by the `prep` phase.\n * @template ExecRes The type of data returned by the `exec` phase (the final action).\n * @template TParams The type for the flow's static parameters.\n */\nexport class Flow<\n\tPrepRes = any,\n\tExecRes = any,\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> extends Node<PrepRes, ExecRes, ExecRes, TParams, TContext> {\n\t/** The first node to be executed in this flow's graph. */\n\tpublic startNode?: AbstractNode<any, any>\n\t/** An array of middleware functions to be applied to every node within this flow. */\n\tpublic middleware: Middleware[] = []\n\n\t/**\n\t * @param start An optional node to start the flow with.\n\t */\n\tconstructor(start?: AbstractNode<any, any, TContext>) {\n\t\tsuper()\n\t\tthis.startNode = start\n\t}\n\n\tprotected _wrapError(e: any, phase: 'prep' | 'exec' | 'post'): Error {\n\t\tif (phase === 'exec') {\n\t\t\t// Errors from a sub-flow's orchestration are already wrapped, so we pass them through.\n\t\t\treturn e\n\t\t}\n\t\treturn super._wrapError(e, phase)\n\t}\n\n\t/**\n\t * Adds a middleware function to this flow. Middleware will be executed in the\n\t * order it is added, wrapping the execution of every node within this flow.\n\t * @param fn The middleware function to add.\n\t * @returns The `Flow` instance for chaining.\n\t */\n\tpublic use(fn: Middleware): this {\n\t\tthis.middleware.push(fn)\n\t\treturn this\n\t}\n\n\t/**\n\t * Sets the starting node of the flow's graph.\n\t * @param start The node to start with.\n\t * @returns The start node instance, allowing for further chaining (`.next()`).\n\t */\n\tstart<StartNode extends AbstractNode<any, any, TContext>>(start: StartNode): StartNode {\n\t\tthis.startNode = start\n\t\treturn start\n\t}\n\n\t/**\n\t * (Lifecycle) Executes this flow's internal graph when it is used as a sub-flow\n\t * (a node within a larger flow).\n\t * @internal\n\t * @param args The arguments for the node, passed down from the parent executor.\n\t * @returns The final action returned by the last node in this flow's graph.\n\t */\n\tasync exec(args: NodeArgs<any, any, TParams, TContext>): Promise<ExecRes> {\n\t\t// For programmatic composition, a Flow node orchestrates its own graph.\n\t\t// This is a feature of the InMemoryExecutor. Distributed systems should\n\t\t// rely on pre-flattened graphs produced by the GraphBuilder.\n\t\tif (!(args.executor instanceof InMemoryExecutor)) {\n\t\t\tthrow new TypeError('Programmatic sub-flow execution is only supported by the InMemoryExecutor. For other environments, use GraphBuilder to create a single, flattened workflow.')\n\t\t}\n\n\t\tif (!this.startNode) {\n\t\t\t// This handles logic-bearing flows like BatchFlow that override exec directly.\n\t\t\treturn super.exec(args)\n\t\t}\n\n\t\tconst combinedParams = { ...args.params, ...this.params }\n\t\tconst internalOptions: InternalRunOptions = {\n\t\t\tlogger: args.logger,\n\t\t\tsignal: args.signal,\n\t\t\tparams: combinedParams,\n\t\t\texecutor: args.executor,\n\t\t}\n\n\t\tconst finalAction = await args.executor._orch<ExecRes>(\n\t\t\tthis.startNode,\n\t\t\tthis.middleware,\n\t\t\targs.ctx,\n\t\t\tinternalOptions,\n\t\t)\n\n\t\treturn finalAction as ExecRes\n\t}\n\n\t/**\n\t * (Lifecycle) The post-execution step for a `Flow` node. It simply passes through\n\t * the final action from its internal graph execution (`execRes`).\n\t * @internal\n\t */\n\tasync post({ execRes }: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<ExecRes> {\n\t\treturn execRes\n\t}\n\n\t/**\n\t * Runs the entire flow as a top-level entry point.\n\t * @param ctx The shared workflow context.\n\t * @param options Runtime options like a logger, abort controller, or a custom executor.\n\t * @returns The final action returned by the last node in the flow.\n\t */\n\tasync run(ctx: TContext, options?: RunOptions): Promise<ExecRes> {\n\t\tconst executor = options?.executor ?? new InMemoryExecutor()\n\t\treturn executor.run(this, ctx, options)\n\t}\n\n\t/**\n\t * Finds a node within the flow's graph by its unique ID.\n\t *\n\t * This method performs a breadth-first search starting from the `startNode`.\n\t * It is a convenient way to get a reference to a specific node instance\n\t * for debugging or dynamic modifications.\n\t *\n\t * @remarks\n\t * This performs a graph traversal on each call, which has a time complexity\n\t * proportional to the number of nodes and edges in the graph (O(V+E)). For\n\t * performance-critical applications or flows built with `GraphBuilder`,\n\t * it is more efficient to use the `nodeMap` returned by `GraphBuilder.build()`.\n\t *\n\t * @param id The unique ID of the node to find (set via `.withId()` or by the `GraphBuilder`).\n\t * @returns The `AbstractNode` instance if found, otherwise `undefined`.\n\t */\n\tpublic getNodeById(id: string | number): AbstractNode<any, any, TContext> | undefined {\n\t\tif (!this.startNode)\n\t\t\treturn undefined\n\n\t\tconst queue: AbstractNode<any, any, TContext>[] = [this.startNode]\n\t\tconst visited = new Set<AbstractNode<any, any, TContext>>([this.startNode])\n\t\twhile (queue.length > 0) {\n\t\t\tconst currentNode = queue.shift()!\n\n\t\t\tif (currentNode.id === id)\n\t\t\t\treturn currentNode\n\n\t\t\tfor (const successorArray of currentNode.successors.values()) {\n\t\t\t\tfor (const successor of successorArray) {\n\t\t\t\t\tif (!visited.has(successor)) {\n\t\t\t\t\t\tvisited.add(successor)\n\t\t\t\t\t\tqueue.push(successor)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\t/**\n\t * Retrieves all unique nodes within the flow's graph.\n\t * @internal\n\t */\n\tpublic getAllNodes(): Set<AbstractNode> {\n\t\tconst allNodes = new Set<AbstractNode>()\n\t\tif (!this.startNode)\n\t\t\treturn allNodes\n\n\t\tconst queue: AbstractNode[] = [this.startNode]\n\t\tconst visited = new Set<AbstractNode>([this.startNode])\n\t\tallNodes.add(this.startNode)\n\n\t\twhile (queue.length > 0) {\n\t\t\tconst currentNode = queue.shift()!\n\t\t\tfor (const successorArray of currentNode.successors.values()) {\n\t\t\t\tfor (const successor of successorArray) {\n\t\t\t\t\tif (!visited.has(successor)) {\n\t\t\t\t\t\tvisited.add(successor)\n\t\t\t\t\t\tqueue.push(successor)\n\t\t\t\t\t\tallNodes.add(successor)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn allNodes\n\t}\n}\n\nregisterFlow(Flow)\n"]}