flowcraft 1.0.0 → 2.1.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-4PELJWF7.js +29 -0
  5. package/dist/chunk-4PELJWF7.js.map +1 -0
  6. package/dist/chunk-55J6XMHW.js +3 -0
  7. package/dist/{chunk-7XUN3OQT.js.map → chunk-55J6XMHW.js.map} +1 -1
  8. package/dist/chunk-5EHIPX23.js +202 -0
  9. package/dist/chunk-5EHIPX23.js.map +1 -0
  10. package/dist/chunk-5QMPFUKA.js +40 -0
  11. package/dist/chunk-5QMPFUKA.js.map +1 -0
  12. package/dist/chunk-5ZWYSKMH.js +147 -0
  13. package/dist/chunk-5ZWYSKMH.js.map +1 -0
  14. package/dist/chunk-5ZXV3R5D.js +28 -0
  15. package/dist/chunk-5ZXV3R5D.js.map +1 -0
  16. package/dist/chunk-CO5BTPKI.js +410 -0
  17. package/dist/chunk-CO5BTPKI.js.map +1 -0
  18. package/dist/chunk-CSZ6EOWG.js +61 -0
  19. package/dist/chunk-CSZ6EOWG.js.map +1 -0
  20. package/dist/chunk-CYHZ2YVH.js +24 -0
  21. package/dist/chunk-CYHZ2YVH.js.map +1 -0
  22. package/dist/chunk-DSYAC4WB.js +27 -0
  23. package/dist/chunk-DSYAC4WB.js.map +1 -0
  24. package/dist/chunk-HMR2GEGE.js +3 -0
  25. package/dist/{chunk-F2RSES6P.js.map → chunk-HMR2GEGE.js.map} +1 -1
  26. package/dist/chunk-HN72TZY5.js +110 -0
  27. package/dist/chunk-HN72TZY5.js.map +1 -0
  28. package/dist/chunk-KWQHFT7E.js +49 -0
  29. package/dist/chunk-KWQHFT7E.js.map +1 -0
  30. package/dist/chunk-PH2IYZHV.js +48 -0
  31. package/dist/chunk-PH2IYZHV.js.map +1 -0
  32. package/dist/chunk-QRMUKDSP.js +141 -0
  33. package/dist/chunk-QRMUKDSP.js.map +1 -0
  34. package/dist/chunk-UETC63DP.js +65 -0
  35. package/dist/chunk-UETC63DP.js.map +1 -0
  36. package/dist/chunk-UMXW3TCY.js +165 -0
  37. package/dist/chunk-UMXW3TCY.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 +30 -0
  43. package/dist/evaluator.js +3 -0
  44. package/dist/evaluator.js.map +1 -0
  45. package/dist/flow.d.ts +55 -0
  46. package/dist/flow.js +4 -0
  47. package/dist/flow.js.map +1 -0
  48. package/dist/index.d.ts +15 -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 +15 -40
  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 +94 -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 +34 -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 +25 -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 +16 -0
  81. package/dist/serializer.js +3 -0
  82. package/dist/serializer.js.map +1 -0
  83. package/dist/types-lG3xCzp_.d.ts +206 -0
  84. package/dist/types.d.ts +1 -3
  85. package/dist/types.js +1 -1
  86. package/package.json +10 -21
  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,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;AA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AA,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;AA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AAA,CAAI,SAAS,CAAA,EAAG;AAC5B,YAAA,OAAA,CAAQ,IAAI,SAAS,CAAA;AACrB,YAAA,KAAA,CAAM,KAAK,SAAS,CAAA;AAAA,UACrB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,IAAA,OAAO,MAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,WAAA,GAAiC;AACvC,IAAA,MAAM,QAAA,uBAAe,GAAA,EAAkB;AACvC,IAAA,IAAI,CAAC,IAAA,CAAK,SAAA;AACT,MAAA,OAAO,QAAA;AAER,IAAA,MAAM,KAAA,GAAwB,CAAC,IAAA,CAAK,SAAS,CAAA;AAC7C,IAAA,MAAM,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"]}
@@ -1,114 +0,0 @@
1
- import { DEFAULT_ACTION, FILTER_FAILED } from './chunk-AOHBHYF6.js';
2
-
3
- // src/utils/mermaid.ts
4
- function getActionLabel(action) {
5
- if (action === DEFAULT_ACTION)
6
- return "";
7
- if (action === FILTER_FAILED)
8
- return '"filter failed"';
9
- const sanitizedAction = action.toString().replace(/"/g, "");
10
- return `"${sanitizedAction}"`;
11
- }
12
- function getNodeLabel(node, uniqueId) {
13
- if (node.isParallelContainer)
14
- return ` ${uniqueId}{Parallel Block}`;
15
- if (node.constructor.name === "InputMappingNode")
16
- return ` ${uniqueId}(("Inputs"))`;
17
- if (node.constructor.name === "OutputMappingNode")
18
- return ` ${uniqueId}(("Outputs"))`;
19
- if (node.graphData) {
20
- const type = node.graphData.type;
21
- const id = node.graphData.id.split(":").pop();
22
- return ` ${uniqueId}["${id} (${type})"]`;
23
- }
24
- return ` ${uniqueId}[${node.constructor.name}]`;
25
- }
26
- function getUniqueNodeId(node, nameCounts, idMap) {
27
- if (idMap.has(node))
28
- return idMap.get(node);
29
- let baseName;
30
- if (node.isParallelContainer) {
31
- baseName = "ParallelBlock";
32
- } else if (node.graphData) {
33
- baseName = node.graphData.id;
34
- } else if (node.id) {
35
- baseName = String(node.id);
36
- } else {
37
- baseName = node.constructor.name;
38
- }
39
- const sanitizedBaseName = baseName.replace(/:/g, "_").replace(/\W/g, "");
40
- const count = nameCounts.get(sanitizedBaseName) || 0;
41
- const uniqueId = `${sanitizedBaseName}_${count}`;
42
- nameCounts.set(sanitizedBaseName, count + 1);
43
- idMap.set(node, uniqueId);
44
- return uniqueId;
45
- }
46
- function generateMermaidGraph(flow) {
47
- if (!flow.startNode)
48
- return "graph TD\n %% Empty Flow";
49
- const nodes = /* @__PURE__ */ new Set();
50
- const edges = /* @__PURE__ */ new Set();
51
- const visited = /* @__PURE__ */ new Set();
52
- const queue = [flow.startNode];
53
- const idMap = /* @__PURE__ */ new Map();
54
- const nameCounts = /* @__PURE__ */ new Map();
55
- visited.add(flow.startNode);
56
- getUniqueNodeId(flow.startNode, nameCounts, idMap);
57
- while (queue.length > 0) {
58
- const currentNode = queue.shift();
59
- const sourceId = getUniqueNodeId(currentNode, nameCounts, idMap);
60
- nodes.add(getNodeLabel(currentNode, sourceId));
61
- if (currentNode.isParallelContainer) {
62
- const container = currentNode;
63
- for (const internalNode of container.nodesToRun) {
64
- const targetId = getUniqueNodeId(internalNode, nameCounts, idMap);
65
- edges.add(` ${sourceId} --> ${targetId}`);
66
- if (!visited.has(internalNode)) {
67
- visited.add(internalNode);
68
- queue.push(internalNode);
69
- }
70
- }
71
- }
72
- for (const [action, successorNodes] of currentNode.successors.entries()) {
73
- for (const successorNode of successorNodes) {
74
- const targetId = getUniqueNodeId(successorNode, nameCounts, idMap);
75
- const label = getActionLabel(action);
76
- const edge = label ? ` ${sourceId} -- ${label} --> ${targetId}` : ` ${sourceId} --> ${targetId}`;
77
- edges.add(edge);
78
- if (!visited.has(successorNode)) {
79
- visited.add(successorNode);
80
- queue.push(successorNode);
81
- }
82
- }
83
- }
84
- }
85
- const mermaidLines = [
86
- "graph TD",
87
- ...Array.from(nodes),
88
- ...Array.from(edges)
89
- ];
90
- return mermaidLines.join("\n");
91
- }
92
- function generateMermaidFromBlueprint(blueprint) {
93
- let mermaidString = "graph TD\n";
94
- for (const node of blueprint.nodes) {
95
- const label = `${node.id.replace(/"/g, "#quot;")} (${node.type})`;
96
- mermaidString += ` ${node.id}["${label}"]
97
- `;
98
- }
99
- mermaidString += "\n";
100
- for (const edge of blueprint.edges) {
101
- if (edge.action) {
102
- mermaidString += ` ${edge.source} -->|${String(edge.action)}| ${edge.target}
103
- `;
104
- } else {
105
- mermaidString += ` ${edge.source} --> ${edge.target}
106
- `;
107
- }
108
- }
109
- return mermaidString;
110
- }
111
-
112
- export { generateMermaidFromBlueprint, generateMermaidGraph };
113
- //# sourceMappingURL=chunk-VMH2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CAAA,KAAA,EAAQ,MAAA,CAAO,KAAK,MAAM,CAAC,CAAA,EAAA,EAAK,IAAA,CAAK,MAAM;AAAA,CAAA;AAAA,IAC/E,CAAA,MACK;AACJ,MAAA,aAAA,IAAiB,CAAA,IAAA,EAAO,IAAA,CAAK,MAAM,CAAA,KAAA,EAAQ,KAAK,MAAM;AAAA,CAAA;AAAA,IACvD;AAAA,EACD;AAEA,EAAA,OAAO,aAAA;AACR","file":"chunk-VMH2LRM6.js","sourcesContent":["import type { WorkflowBlueprint } from '../builder/graph/types'\nimport type { AbstractNode, Flow } from '../workflow/index'\nimport { DEFAULT_ACTION, FILTER_FAILED } from '../types'\n\n/**\n * Converts a special action symbol to a user-friendly string for the graph label.\n * @param action The action symbol or string.\n * @returns A string label for the Mermaid edge.\n */\nfunction getActionLabel(action: string | symbol): string {\n\tif (action === DEFAULT_ACTION)\n\t\treturn ''\n\n\tif (action === FILTER_FAILED)\n\t\treturn '\"filter failed\"'\n\n\t// Sanitize labels to prevent breaking Mermaid syntax\n\tconst sanitizedAction = action.toString().replace(/\"/g, '')\n\treturn `\"${sanitizedAction}\"`\n}\n\n/**\n * Generates a descriptive label for a node to be used in the Mermaid graph.\n * @param node The node to generate a label for.\n * @param uniqueId The unique ID assigned to this node instance in the graph.\n * @returns A formatted string for the Mermaid node definition.\n */\nfunction getNodeLabel(node: AbstractNode, uniqueId: string): string {\n\tif ((node as any).isParallelContainer)\n\t\treturn ` ${uniqueId}{Parallel Block}`\n\n\tif (node.constructor.name === 'InputMappingNode')\n\t\treturn ` ${uniqueId}((\"Inputs\"))`\n\n\tif (node.constructor.name === 'OutputMappingNode')\n\t\treturn ` ${uniqueId}((\"Outputs\"))`\n\n\tif (node.graphData) {\n\t\tconst type = node.graphData.type\n\t\tconst id = node.graphData.id.split(':').pop()\n\t\treturn ` ${uniqueId}[\"${id} (${type})\"]`\n\t}\n\n\treturn ` ${uniqueId}[${node.constructor.name}]`\n}\n\n/**\n * Generates a unique, readable ID for a node instance.\n * @param node The node instance.\n * @returns A unique string ID.\n */\nfunction getUniqueNodeId(node: AbstractNode, nameCounts: Map<string, number>, idMap: Map<AbstractNode, string>): string {\n\tif (idMap.has(node))\n\t\treturn idMap.get(node)!\n\n\tlet baseName: string\n\tif ((node as any).isParallelContainer) {\n\t\tbaseName = 'ParallelBlock'\n\t}\n\telse if (node.graphData) {\n\t\tbaseName = node.graphData.id\n\t}\n\telse if (node.id) {\n\t\tbaseName = String(node.id)\n\t}\n\telse {\n\t\tbaseName = node.constructor.name\n\t}\n\n\t// Sanitize the name for Mermaid ID\n\tconst sanitizedBaseName = baseName.replace(/:/g, '_').replace(/\\W/g, '')\n\tconst count = nameCounts.get(sanitizedBaseName) || 0\n\tconst uniqueId = `${sanitizedBaseName}_${count}`\n\tnameCounts.set(sanitizedBaseName, count + 1)\n\tidMap.set(node, uniqueId)\n\treturn uniqueId\n}\n\n/**\n * Generates a Mermaid graph definition from a `Flow` instance.\n *\n * This utility traverses the workflow's node structure and outputs a string\n * that can be rendered by Mermaid.js to visualize the flow's logic,\n * including branching and cycles.\n *\n * @param flow The `Flow` instance to visualize.\n * @returns A string containing the Mermaid `graph TD` definition.\n *\n * @example\n * const startNode = new Node('start')\n * const processNode = new Node('process')\n * const endNode = new Node('end')\n *\n * startNode.next(processNode)\n * processNode.next(endNode)\n *\n * const myFlow = new Flow(startNode)\n * const mermaidSyntax = generateMermaidGraph(myFlow)\n * console.log(mermaidSyntax)\n * // Outputs:\n * // graph TD\n * // Node_0[Node]\n * // Node_1[Node]\n * // Node_2[Node]\n * // Node_0 --> Node_1\n * // Node_1 --> Node_2\n */\nexport function generateMermaidGraph(flow: Flow): string {\n\tif (!flow.startNode)\n\t\treturn 'graph TD\\n %% Empty Flow'\n\n\tconst nodes = new Set<string>()\n\tconst edges = new Set<string>()\n\tconst visited = new Set<AbstractNode>()\n\tconst queue: AbstractNode[] = [flow.startNode]\n\tconst idMap = new Map<AbstractNode, string>()\n\tconst nameCounts = new Map<string, number>()\n\n\tvisited.add(flow.startNode)\n\tgetUniqueNodeId(flow.startNode, nameCounts, idMap)\n\n\twhile (queue.length > 0) {\n\t\tconst currentNode = queue.shift()!\n\t\tconst sourceId = getUniqueNodeId(currentNode, nameCounts, idMap)\n\n\t\tnodes.add(getNodeLabel(currentNode, sourceId))\n\n\t\tif ((currentNode as any).isParallelContainer) {\n\t\t\tconst container = currentNode as any as { nodesToRun: AbstractNode[] }\n\t\t\tfor (const internalNode of container.nodesToRun) {\n\t\t\t\tconst targetId = getUniqueNodeId(internalNode, nameCounts, idMap)\n\t\t\t\tedges.add(` ${sourceId} --> ${targetId}`)\n\t\t\t\tif (!visited.has(internalNode)) {\n\t\t\t\t\tvisited.add(internalNode)\n\t\t\t\t\tqueue.push(internalNode)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const [action, successorNodes] of currentNode.successors.entries()) {\n\t\t\tfor (const successorNode of successorNodes) {\n\t\t\t\tconst targetId = getUniqueNodeId(successorNode, nameCounts, idMap)\n\t\t\t\tconst label = getActionLabel(action)\n\t\t\t\tconst edge = label\n\t\t\t\t\t? ` ${sourceId} -- ${label} --> ${targetId}`\n\t\t\t\t\t: ` ${sourceId} --> ${targetId}`\n\t\t\t\tedges.add(edge)\n\n\t\t\t\tif (!visited.has(successorNode)) {\n\t\t\t\t\tvisited.add(successorNode)\n\t\t\t\t\tqueue.push(successorNode)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst mermaidLines = [\n\t\t'graph TD',\n\t\t...Array.from(nodes),\n\t\t...Array.from(edges),\n\t]\n\n\treturn mermaidLines.join('\\n')\n}\n\n/**\n * Generates a Mermaid graph definition from a static `WorkflowBlueprint`.\n *\n * This utility iterates over the blueprint's nodes and edges to output a string\n * that can be rendered by Mermaid.js to visualize the entire workflow structure.\n *\n * @param blueprint The `WorkflowBlueprint` instance to visualize.\n * @returns A string containing the Mermaid `graph TD` definition.\n */\nexport function generateMermaidFromBlueprint(blueprint: WorkflowBlueprint): string {\n\tlet mermaidString = 'graph TD\\n'\n\n\t// Define nodes, quoting the ID to handle special characters and adding the type as a label\n\tfor (const node of blueprint.nodes) {\n\t\tconst label = `${node.id.replace(/\"/g, '#quot;')} (${node.type})`\n\t\tmermaidString += ` ${node.id}[\"${label}\"]\\n`\n\t}\n\n\tmermaidString += '\\n'\n\n\t// Define edges, adding the action as a label if it exists\n\tfor (const edge of blueprint.edges) {\n\t\tif (edge.action) {\n\t\t\tmermaidString += ` ${edge.source} -->|${String(edge.action)}| ${edge.target}\\n`\n\t\t}\n\t\telse {\n\t\t\tmermaidString += ` ${edge.source} --> ${edge.target}\\n`\n\t\t}\n\t}\n\n\treturn mermaidString\n}\n"]}
@@ -1,76 +0,0 @@
1
- import { DEFAULT_ACTION } from './chunk-AOHBHYF6.js';
2
-
3
- // src/workflow/AbstractNode.ts
4
- var AbstractNode = class {
5
- /** A unique identifier for this node instance, often set by the GraphBuilder. */
6
- id;
7
- /** A key-value store for static parameters that configure the node's behavior. */
8
- params = {};
9
- /** A map of successor nodes, keyed by the action that triggers the transition. */
10
- successors = /* @__PURE__ */ new Map();
11
- /** The original graph definition for this node, if created by a GraphBuilder. */
12
- graphData;
13
- /** A flag indicating that this node is a container and should be passed through by distributed executors. */
14
- isPassthrough = false;
15
- /**
16
- * Gets the original, un-prefixed ID of the node from its graph definition.
17
- * This is useful for sub-workflow nodes where the runtime ID might be namespaced (e.g., 'parent:child').
18
- */
19
- get originalId() {
20
- return this.graphData?.data?.originalId ?? this.id?.toString() ?? "";
21
- }
22
- /**
23
- * Sets a unique identifier for this node instance.
24
- * Primarily used by the GraphBuilder for wiring and debugging.
25
- * @param id The unique ID for the node.
26
- * @returns The node instance for chaining.
27
- */
28
- withId(id) {
29
- this.id = id;
30
- return this;
31
- }
32
- /**
33
- * Attaches the original graph definition data to the node instance.
34
- * @internal
35
- * @param data The graph node definition.
36
- * @returns The node instance for chaining.
37
- */
38
- withGraphData(data) {
39
- this.graphData = data;
40
- return this;
41
- }
42
- /**
43
- * Sets or merges static parameters for the node. These parameters are available
44
- * via `args.params` in the node's lifecycle methods.
45
- * @param params The parameters to merge into the node's existing parameters.
46
- * @returns The node instance for chaining.
47
- */
48
- withParams(params) {
49
- this.params = { ...this.params, ...params };
50
- return this;
51
- }
52
- /**
53
- * Defines the next node in the sequence for a given action.
54
- * This is the primary method for constructing a workflow graph.
55
- *
56
- * @param node The successor node or nodes to execute next.
57
- * @param action The action from this node's `post` method that triggers
58
- * the transition. Defaults to `DEFAULT_ACTION` for linear flows.
59
- * @returns The successor node instance, allowing for further chaining. If multiple nodes are provided, it returns the first one.
60
- */
61
- next(node, action = DEFAULT_ACTION) {
62
- const existing = this.successors.get(action) ?? [];
63
- const newSuccessors = Array.isArray(node) ? node : [node];
64
- for (const successor of newSuccessors) {
65
- if (!existing.includes(successor)) {
66
- existing.push(successor);
67
- }
68
- }
69
- this.successors.set(action, existing);
70
- return Array.isArray(node) ? node[0] : node;
71
- }
72
- };
73
-
74
- export { AbstractNode };
75
- //# sourceMappingURL=chunk-VZDHIOCH.js.map
76
- //# sourceMappingURL=chunk-VZDHIOCH.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/workflow/AbstractNode.ts"],"names":[],"mappings":";;;AAYO,IAAe,eAAf,MAIL;AAAA;AAAA,EAEM,EAAA;AAAA;AAAA,EAEA,SAAkB,EAAC;AAAA;AAAA,EAEnB,UAAA,uBAAiB,GAAA,EAA0G;AAAA;AAAA,EAE3H,SAAA;AAAA;AAAA,EAEA,aAAA,GAAgB,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,IAAW,UAAA,GAAqB;AAI/B,IAAA,OAAO,KAAK,SAAA,EAAW,IAAA,EAAM,cAAc,IAAA,CAAK,EAAA,EAAI,UAAS,IAAK,EAAA;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,EAAA,EAA2B;AACjC,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AACV,IAAA,OAAO,IAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,cAAc,IAAA,EAAuB;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,IAAA;AACjB,IAAA,OAAO,IAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,MAAA,EAAgC;AAC1C,IAAA,IAAA,CAAK,SAAS,EAAE,GAAG,IAAA,CAAK,MAAA,EAAQ,GAAG,MAAA,EAAO;AAC1C,IAAA,OAAO,IAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,IAAA,CACC,IAAA,EACA,MAAA,GAA2E,cAAA,EAChE;AACX,IAAA,MAAM,WAAW,IAAA,CAAK,UAAA,CAAW,GAAA,CAAI,MAAM,KAAK,EAAC;AACjD,IAAA,MAAM,gBAAgB,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA,GAAO,CAAC,IAAI,CAAA;AAExD,IAAA,KAAA,MAAW,aAAa,aAAA,EAAe;AACtC,MAAA,IAAI,CAAC,QAAA,CAAS,QAAA,CAAS,SAAS,CAAA,EAAG;AAClC,QAAA,QAAA,CAAS,KAAK,SAAS,CAAA;AAAA,MACxB;AAAA,IACD;AAEA,IAAA,IAAA,CAAK,UAAA,CAAW,GAAA,CAAI,MAAA,EAAQ,QAAQ,CAAA;AACpC,IAAA,OAAO,MAAM,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA,CAAK,CAAC,CAAA,GAAI,IAAA;AAAA,EACxC;AAQD","file":"chunk-VZDHIOCH.js","sourcesContent":["import type { GraphNode } from '../builder/graph/types'\nimport type { Context } from '../context'\nimport type { FILTER_FAILED, NodeRunContext, Params } from '../types'\nimport { DEFAULT_ACTION } from '../types'\n\n/**\n * The abstract base class for all executable units in a workflow.\n * It provides the core structure for connecting nodes into a graph.\n *\n * @template TPostRes The type for the action returned by the node's `post` method.\n * @template TParams The type for the node's static parameters.\n */\nexport abstract class AbstractNode<\n\tTPostRes = any,\n\tTParams extends Params = Params,\n\tTContext extends Context = Context,\n> {\n\t/** A unique identifier for this node instance, often set by the GraphBuilder. */\n\tpublic id?: number | string\n\t/** A key-value store for static parameters that configure the node's behavior. */\n\tpublic params: TParams = {} as TParams\n\t/** A map of successor nodes, keyed by the action that triggers the transition. */\n\tpublic successors = new Map<TPostRes | string | typeof DEFAULT_ACTION | typeof FILTER_FAILED, AbstractNode<any, any, TContext>[]>()\n\t/** The original graph definition for this node, if created by a GraphBuilder. */\n\tpublic graphData?: GraphNode\n\t/** A flag indicating that this node is a container and should be passed through by distributed executors. */\n\tpublic isPassthrough = false\n\n\t/**\n\t * Gets the original, un-prefixed ID of the node from its graph definition.\n\t * This is useful for sub-workflow nodes where the runtime ID might be namespaced (e.g., 'parent:child').\n\t */\n\tpublic get originalId(): string {\n\t\t// 1. Prefer the logical `originalId` injected by the GraphBuilder.\n\t\t// 2. Fall back to the primary runtime `id` property on the node instance.\n\t\t// 3. An uninitialized node with no id.\n\t\treturn this.graphData?.data?.originalId ?? this.id?.toString() ?? ''\n\t}\n\n\t/**\n\t * Sets a unique identifier for this node instance.\n\t * Primarily used by the GraphBuilder for wiring and debugging.\n\t * @param id The unique ID for the node.\n\t * @returns The node instance for chaining.\n\t */\n\twithId(id: number | string): this {\n\t\tthis.id = id\n\t\treturn this\n\t}\n\n\t/**\n\t * Attaches the original graph definition data to the node instance.\n\t * @internal\n\t * @param data The graph node definition.\n\t * @returns The node instance for chaining.\n\t */\n\twithGraphData(data: GraphNode): this {\n\t\tthis.graphData = data\n\t\treturn this\n\t}\n\n\t/**\n\t * Sets or merges static parameters for the node. These parameters are available\n\t * via `args.params` in the node's lifecycle methods.\n\t * @param params The parameters to merge into the node's existing parameters.\n\t * @returns The node instance for chaining.\n\t */\n\twithParams(params: Partial<TParams>): this {\n\t\tthis.params = { ...this.params, ...params }\n\t\treturn this\n\t}\n\n\t/**\n\t * Defines the next node in the sequence for a given action.\n\t * This is the primary method for constructing a workflow graph.\n\t *\n\t * @param node The successor node or nodes to execute next.\n\t * @param action The action from this node's `post` method that triggers\n\t * the transition. Defaults to `DEFAULT_ACTION` for linear flows.\n\t * @returns The successor node instance, allowing for further chaining. If multiple nodes are provided, it returns the first one.\n\t */\n\tnext<NextNode extends AbstractNode<any, any>>(\n\t\tnode: NextNode | NextNode[],\n\t\taction: TPostRes | string | typeof DEFAULT_ACTION | typeof FILTER_FAILED = DEFAULT_ACTION as any,\n\t): NextNode {\n\t\tconst existing = this.successors.get(action) ?? []\n\t\tconst newSuccessors = Array.isArray(node) ? node : [node]\n\n\t\tfor (const successor of newSuccessors) {\n\t\t\tif (!existing.includes(successor)) {\n\t\t\t\texisting.push(successor)\n\t\t\t}\n\t\t}\n\n\t\tthis.successors.set(action, existing)\n\t\treturn Array.isArray(node) ? node[0] : node\n\t}\n\n\t/**\n\t * The internal method that executes the node's full lifecycle.\n\t * It is called by an `IExecutor`.\n\t * @internal\n\t */\n\tabstract _run(ctx: NodeRunContext<TContext>): Promise<TPostRes>\n}\n"]}