flowcraft 2.1.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +41 -35
  2. package/dist/analysis.d.ts +5 -2
  3. package/dist/analysis.js +1 -1
  4. package/dist/{chunk-HN72TZY5.js → chunk-233SESC2.js} +34 -23
  5. package/dist/chunk-233SESC2.js.map +1 -0
  6. package/dist/chunk-33NO4PUJ.js +74 -0
  7. package/dist/chunk-33NO4PUJ.js.map +1 -0
  8. package/dist/chunk-5KKSQWSC.js +90 -0
  9. package/dist/chunk-5KKSQWSC.js.map +1 -0
  10. package/dist/{chunk-O3XD45IL.js → chunk-6INWPSZT.js} +44 -17
  11. package/dist/chunk-6INWPSZT.js.map +1 -0
  12. package/dist/chunk-BC4G7OM6.js +42 -0
  13. package/dist/chunk-BC4G7OM6.js.map +1 -0
  14. package/dist/chunk-BCRWXTWX.js +21 -0
  15. package/dist/chunk-BCRWXTWX.js.map +1 -0
  16. package/dist/chunk-C4HYIJI3.js +279 -0
  17. package/dist/chunk-C4HYIJI3.js.map +1 -0
  18. package/dist/chunk-CD3Q4N6V.js +13 -0
  19. package/dist/chunk-CD3Q4N6V.js.map +1 -0
  20. package/dist/chunk-CD4FUZOJ.js +114 -0
  21. package/dist/chunk-CD4FUZOJ.js.map +1 -0
  22. package/dist/chunk-CY755I7I.js +25 -0
  23. package/dist/chunk-CY755I7I.js.map +1 -0
  24. package/dist/chunk-DL7KVYZF.js +39 -0
  25. package/dist/chunk-DL7KVYZF.js.map +1 -0
  26. package/dist/{chunk-UETC63DP.js → chunk-EUJWJWFA.js} +24 -4
  27. package/dist/chunk-EUJWJWFA.js.map +1 -0
  28. package/dist/chunk-FRKO3WX4.js +32 -0
  29. package/dist/chunk-FRKO3WX4.js.map +1 -0
  30. package/dist/chunk-G53CSLBF.js +54 -0
  31. package/dist/chunk-G53CSLBF.js.map +1 -0
  32. package/dist/chunk-G5BGBPFP.js +172 -0
  33. package/dist/chunk-G5BGBPFP.js.map +1 -0
  34. package/dist/chunk-HAZ26F3P.js +98 -0
  35. package/dist/chunk-HAZ26F3P.js.map +1 -0
  36. package/dist/chunk-IB2BISIC.js +446 -0
  37. package/dist/chunk-IB2BISIC.js.map +1 -0
  38. package/dist/{chunk-U5V5O5MN.js → chunk-LNK7LZER.js} +5 -3
  39. package/dist/chunk-LNK7LZER.js.map +1 -0
  40. package/dist/chunk-MCGK3FXQ.js +143 -0
  41. package/dist/chunk-MCGK3FXQ.js.map +1 -0
  42. package/dist/chunk-MUYLRTSR.js +82 -0
  43. package/dist/chunk-MUYLRTSR.js.map +1 -0
  44. package/dist/chunk-NVJ3ZO3P.js +3 -0
  45. package/dist/{chunk-HMR2GEGE.js.map → chunk-NVJ3ZO3P.js.map} +1 -1
  46. package/dist/chunk-NVLZFLYM.js +3 -0
  47. package/dist/chunk-NVLZFLYM.js.map +1 -0
  48. package/dist/chunk-ONH7PIJZ.js +300 -0
  49. package/dist/chunk-ONH7PIJZ.js.map +1 -0
  50. package/dist/chunk-QNYXQKFW.js +25 -0
  51. package/dist/chunk-QNYXQKFW.js.map +1 -0
  52. package/dist/{chunk-KWQHFT7E.js → chunk-R3HQXIEL.js} +6 -6
  53. package/dist/chunk-R3HQXIEL.js.map +1 -0
  54. package/dist/chunk-RM677CNU.js +52 -0
  55. package/dist/chunk-RM677CNU.js.map +1 -0
  56. package/dist/chunk-WWGFIYKW.js +47 -0
  57. package/dist/chunk-WWGFIYKW.js.map +1 -0
  58. package/dist/chunk-XNRIM27H.js +76 -0
  59. package/dist/chunk-XNRIM27H.js.map +1 -0
  60. package/dist/container-factory.d.ts +17 -0
  61. package/dist/container-factory.js +13 -0
  62. package/dist/container-factory.js.map +1 -0
  63. package/dist/container.d.ts +23 -0
  64. package/dist/container.js +3 -0
  65. package/dist/container.js.map +1 -0
  66. package/dist/context.d.ts +3 -1
  67. package/dist/context.js +1 -1
  68. package/dist/errors.d.ts +18 -17
  69. package/dist/errors.js +1 -1
  70. package/dist/evaluator.d.ts +3 -1
  71. package/dist/flow.d.ts +29 -8
  72. package/dist/flow.js +2 -2
  73. package/dist/index.d.ts +7 -7
  74. package/dist/index.js +27 -15
  75. package/dist/linter.d.ts +5 -3
  76. package/dist/linter.js +2 -2
  77. package/dist/logger.d.ts +3 -1
  78. package/dist/node.d.ts +3 -1
  79. package/dist/node.js +1 -1
  80. package/dist/nodes/batch-gather.d.ts +9 -0
  81. package/dist/nodes/batch-gather.js +4 -0
  82. package/dist/nodes/batch-gather.js.map +1 -0
  83. package/dist/nodes/batch-scatter.d.ts +9 -0
  84. package/dist/nodes/batch-scatter.js +4 -0
  85. package/dist/nodes/batch-scatter.js.map +1 -0
  86. package/dist/nodes/subflow.d.ts +9 -0
  87. package/dist/nodes/subflow.js +10 -0
  88. package/dist/nodes/subflow.js.map +1 -0
  89. package/dist/nodes/wait.d.ts +9 -0
  90. package/dist/nodes/wait.js +4 -0
  91. package/dist/nodes/wait.js.map +1 -0
  92. package/dist/runtime/adapter.d.ts +6 -5
  93. package/dist/runtime/adapter.js +20 -10
  94. package/dist/runtime/builtin-keys.d.ts +38 -0
  95. package/dist/runtime/builtin-keys.js +10 -0
  96. package/dist/runtime/builtin-keys.js.map +1 -0
  97. package/dist/runtime/execution-context.d.ts +3 -0
  98. package/dist/runtime/execution-context.js +6 -0
  99. package/dist/runtime/execution-context.js.map +1 -0
  100. package/dist/runtime/executors.d.ts +3 -26
  101. package/dist/runtime/executors.js +2 -2
  102. package/dist/runtime/index.d.ts +5 -6
  103. package/dist/runtime/index.js +22 -11
  104. package/dist/runtime/node-executor-factory.d.ts +12 -0
  105. package/dist/runtime/node-executor-factory.js +6 -0
  106. package/dist/runtime/node-executor-factory.js.map +1 -0
  107. package/dist/runtime/orchestrator.d.ts +9 -0
  108. package/dist/runtime/orchestrator.js +8 -0
  109. package/dist/runtime/orchestrator.js.map +1 -0
  110. package/dist/runtime/orchestrators/step-by-step.d.ts +16 -0
  111. package/dist/runtime/orchestrators/step-by-step.js +5 -0
  112. package/dist/runtime/orchestrators/step-by-step.js.map +1 -0
  113. package/dist/runtime/orchestrators/utils.d.ts +35 -0
  114. package/dist/runtime/orchestrators/utils.js +4 -0
  115. package/dist/runtime/orchestrators/utils.js.map +1 -0
  116. package/dist/runtime/runtime.d.ts +3 -35
  117. package/dist/runtime/runtime.js +19 -9
  118. package/dist/runtime/state.d.ts +3 -21
  119. package/dist/runtime/state.js +3 -2
  120. package/dist/runtime/traverser.d.ts +3 -26
  121. package/dist/runtime/traverser.js +2 -3
  122. package/dist/runtime/types.d.ts +3 -16
  123. package/dist/runtime/types.js +1 -1
  124. package/dist/runtime/workflow-logic-handler.d.ts +17 -0
  125. package/dist/runtime/workflow-logic-handler.js +5 -0
  126. package/dist/runtime/workflow-logic-handler.js.map +1 -0
  127. package/dist/sanitizer.d.ts +3 -1
  128. package/dist/serializer.d.ts +3 -1
  129. package/dist/testing/event-logger.d.ts +63 -0
  130. package/dist/testing/event-logger.js +3 -0
  131. package/dist/testing/event-logger.js.map +1 -0
  132. package/dist/testing/index.d.ts +6 -0
  133. package/dist/testing/index.js +31 -0
  134. package/dist/testing/index.js.map +1 -0
  135. package/dist/testing/run-with-trace.d.ts +38 -0
  136. package/dist/testing/run-with-trace.js +29 -0
  137. package/dist/testing/run-with-trace.js.map +1 -0
  138. package/dist/testing/stepper.d.ts +79 -0
  139. package/dist/testing/stepper.js +11 -0
  140. package/dist/testing/stepper.js.map +1 -0
  141. package/dist/types-ezHUBdpL.d.ts +564 -0
  142. package/dist/types.d.ts +3 -1
  143. package/package.json +6 -2
  144. package/dist/chunk-3XVVR2SR.js +0 -417
  145. package/dist/chunk-3XVVR2SR.js.map +0 -1
  146. package/dist/chunk-4A627Q6L.js +0 -147
  147. package/dist/chunk-4A627Q6L.js.map +0 -1
  148. package/dist/chunk-5ZXV3R5D.js +0 -28
  149. package/dist/chunk-5ZXV3R5D.js.map +0 -1
  150. package/dist/chunk-CSZ6EOWG.js +0 -61
  151. package/dist/chunk-CSZ6EOWG.js.map +0 -1
  152. package/dist/chunk-HMR2GEGE.js +0 -3
  153. package/dist/chunk-HN72TZY5.js.map +0 -1
  154. package/dist/chunk-KWQHFT7E.js.map +0 -1
  155. package/dist/chunk-M2FRTT2K.js +0 -144
  156. package/dist/chunk-M2FRTT2K.js.map +0 -1
  157. package/dist/chunk-NBIRTKZ7.js +0 -192
  158. package/dist/chunk-NBIRTKZ7.js.map +0 -1
  159. package/dist/chunk-O3XD45IL.js.map +0 -1
  160. package/dist/chunk-U5V5O5MN.js.map +0 -1
  161. package/dist/chunk-UETC63DP.js.map +0 -1
  162. package/dist/types-CQCe_nBM.d.ts +0 -214
@@ -1,214 +0,0 @@
1
- /** A type guard to reliably distinguish a NodeClass from a NodeFunction. */
2
- declare function isNodeClass(impl: any): impl is NodeClass;
3
- /**
4
- * A structured, class-based node for complex logic with a safe, granular lifecycle.
5
- * This class is generic, allowing implementations to specify the exact context
6
- * and dependency types they expect.
7
- */
8
- declare abstract class BaseNode<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any, TOutput = any, TAction extends string = string> {
9
- protected params?: Record<string, any> | undefined;
10
- /**
11
- * @param params Static parameters for this node instance, passed from the blueprint.
12
- */
13
- constructor(params?: Record<string, any> | undefined);
14
- /**
15
- * Phase 1: Gathers and prepares data for execution. This phase is NOT retried on failure.
16
- * @param context The node's execution context.
17
- * @returns The data needed for the `exec` phase.
18
- */
19
- prep(context: NodeContext<TContext, TDependencies, TInput>): Promise<any>;
20
- /**
21
- * Phase 2: Performs the core, isolated logic. This is the ONLY phase that is retried.
22
- * @param prepResult The data returned from the `prep` phase.
23
- * @param context The node's execution context.
24
- */
25
- abstract exec(prepResult: any, context: NodeContext<TContext, TDependencies, TInput>): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>;
26
- /**
27
- * Phase 3: Processes the result and saves state. This phase is NOT retried.
28
- * @param execResult The successful result from the `exec` or `fallback` phase.
29
- * @param _context The node's execution context.
30
- */
31
- post(execResult: Omit<NodeResult<TOutput, TAction>, 'error'>, _context: NodeContext<TContext, TDependencies, TInput>): Promise<NodeResult<TOutput, TAction>>;
32
- /**
33
- * An optional safety net that runs if all `exec` retries fail.
34
- * @param error The final error from the last `exec` attempt.
35
- * @param _context The node's execution context.
36
- */
37
- fallback(error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>;
38
- /**
39
- * An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.
40
- * This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.
41
- * Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.
42
- * @param _error The error that caused the failure.
43
- * @param _context The node's execution context.
44
- */
45
- recover(_error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<void>;
46
- }
47
-
48
- /** The central, serializable representation of a workflow. */
49
- interface WorkflowBlueprint {
50
- id: string;
51
- nodes: NodeDefinition[];
52
- edges: EdgeDefinition[];
53
- metadata?: Record<string, any>;
54
- }
55
- /** Defines a single step in the workflow. */
56
- interface NodeDefinition {
57
- id: string;
58
- /** A key that resolves to an implementation in a registry. */
59
- uses: string;
60
- /** Static parameters for the node. */
61
- params?: Record<string, any>;
62
- /** Maps context data to this node's `input`. */
63
- inputs?: string | Record<string, string>;
64
- /** Configuration for retries, timeouts, etc. */
65
- config?: NodeConfig;
66
- }
67
- /** Defines the connection and data flow between two nodes. */
68
- interface EdgeDefinition {
69
- source: string;
70
- target: string;
71
- /** An 'action' from the source node that triggers this edge. */
72
- action?: string;
73
- /** A condition that must be met for this edge to be taken. */
74
- condition?: string;
75
- /** A string expression to transform the data before passing it to the target node. */
76
- transform?: string;
77
- }
78
- /** Configuration for a node's resiliency and behavior. */
79
- interface NodeConfig {
80
- maxRetries?: number;
81
- retryDelay?: number;
82
- timeout?: number;
83
- /** The `uses` key of another node implementation for fallback. */
84
- fallback?: string;
85
- /** Determines how a node with multiple incoming edges should be triggered. */
86
- joinStrategy?: 'all' | 'any';
87
- }
88
- /** The required return type for any node implementation. */
89
- interface NodeResult<TOutput = any, TAction extends string = string> {
90
- output?: TOutput;
91
- action?: TAction;
92
- error?: {
93
- message: string;
94
- [key: string]: any;
95
- };
96
- /** Allows a node to dynamically schedule new nodes for the orchestrator to execute. */
97
- dynamicNodes?: NodeDefinition[];
98
- /** Internal flag: Indicates that this result came from a fallback execution. */
99
- _fallbackExecuted?: boolean;
100
- }
101
- /** The context object passed to every node's execution logic. */
102
- interface NodeContext<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any> {
103
- /** The async-only interface for interacting with the workflow's state. */
104
- context: IAsyncContext<TContext>;
105
- /** The primary input data for this node, typically from its predecessor. */
106
- input?: TInput;
107
- /** Static parameters defined in the blueprint. */
108
- params: Record<string, any>;
109
- /** Shared, runtime-level dependencies (e.g., database clients, loggers). */
110
- dependencies: TDependencies;
111
- /** A signal to gracefully cancel long-running node operations. */
112
- signal?: AbortSignal;
113
- }
114
- /** A simple function-based node implementation. */
115
- type NodeFunction<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any, TOutput = any, TAction extends string = string> = (context: NodeContext<TContext, TDependencies, TInput>) => Promise<NodeResult<TOutput, TAction>>;
116
- /** Represents a constructor for any concrete class that extends the abstract BaseNode. */
117
- type NodeClass<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any, TOutput = any, TAction extends string = string> = new (params?: Record<string, any>) => BaseNode<TContext, TDependencies, TInput, TOutput, TAction>;
118
- /** A union of all possible node implementation types. */
119
- type NodeImplementation = NodeFunction | NodeClass;
120
- /** A registry mapping node types to their implementations. */
121
- type NodeRegistry = Record<string, NodeImplementation>;
122
- /** A discriminated union for all possible context implementations. */
123
- type ContextImplementation<T extends Record<string, any>> = ISyncContext<T> | IAsyncContext<T>;
124
- /** The synchronous context interface for high-performance, in-memory state. */
125
- interface ISyncContext<TContext extends Record<string, any> = Record<string, any>> {
126
- readonly type: 'sync';
127
- get: <K extends keyof TContext>(key: K) => TContext[K] | undefined;
128
- set: <K extends keyof TContext>(key: K, value: TContext[K]) => void;
129
- has: <K extends keyof TContext>(key: K) => boolean;
130
- delete: <K extends keyof TContext>(key: K) => boolean;
131
- toJSON: () => Record<string, any>;
132
- }
133
- /** The asynchronous context interface for remote or distributed state. */
134
- interface IAsyncContext<TContext extends Record<string, any> = Record<string, any>> {
135
- readonly type: 'async';
136
- get: <K extends keyof TContext>(key: K) => Promise<TContext[K] | undefined>;
137
- set: <K extends keyof TContext>(key: K, value: TContext[K]) => Promise<void>;
138
- has: <K extends keyof TContext>(key: K) => Promise<boolean>;
139
- delete: <K extends keyof TContext>(key: K) => Promise<boolean>;
140
- toJSON: () => Promise<Record<string, any>>;
141
- }
142
- /** Generic for any set of dependencies. */
143
- interface RuntimeDependencies {
144
- [key: string]: any;
145
- }
146
- /** Configuration options for the FlowRuntime. */
147
- interface RuntimeOptions<TDependencies extends RuntimeDependencies = RuntimeDependencies> {
148
- /** A registry of globally available node implementations. */
149
- registry?: Record<string, NodeFunction | NodeClass | typeof BaseNode>;
150
- /** A registry of all available workflow blueprints for subflow execution. */
151
- blueprints?: Record<string, WorkflowBlueprint>;
152
- /** Shared dependencies to be injected into every node. */
153
- dependencies?: TDependencies;
154
- /** A pluggable logger for consistent output. */
155
- logger?: ILogger;
156
- /** A pluggable event bus for observability. */
157
- eventBus?: IEventBus;
158
- /**
159
- * A pluggable evaluator for edge conditions and transforms.
160
- * @default new PropertyEvaluator() - A safe evaluator for simple property access.
161
- * For complex logic, provide a custom implementation or use the `UnsafeEvaluator`
162
- * (not recommended for production).
163
- */
164
- evaluator?: IEvaluator;
165
- /** An array of middleware to wrap node execution. */
166
- middleware?: Middleware[];
167
- /** A pluggable serializer for handling complex data types in the context. */
168
- serializer?: ISerializer;
169
- /** A flag to enforce strictness in the workflow. */
170
- strict?: boolean;
171
- }
172
- /** Interface for a pluggable expression evaluator for conditions and transforms. */
173
- interface IEvaluator {
174
- evaluate: (expression: string, context: Record<string, any>) => any;
175
- }
176
- /** Interface for a pluggable logger. */
177
- interface ILogger {
178
- debug: (message: string, meta?: Record<string, any>) => void;
179
- info: (message: string, meta?: Record<string, any>) => void;
180
- warn: (message: string, meta?: Record<string, any>) => void;
181
- error: (message: string, meta?: Record<string, any>) => void;
182
- }
183
- /** Interface for a pluggable event bus. */
184
- interface IEventBus {
185
- emit: (eventName: string, payload: Record<string, any>) => void | Promise<void>;
186
- }
187
- /** Interface for a pluggable serializer. */
188
- interface ISerializer {
189
- serialize: (data: Record<string, any>) => string;
190
- deserialize: (text: string) => Record<string, any>;
191
- }
192
- /** Interface for middleware to handle cross-cutting concerns. */
193
- interface Middleware<TContext extends Record<string, any> = Record<string, any>> {
194
- beforeNode?: (ctx: ContextImplementation<TContext>, nodeId: string) => void | Promise<void>;
195
- afterNode?: (ctx: ContextImplementation<TContext>, nodeId: string, result: NodeResult | undefined, error: Error | undefined) => void | Promise<void>;
196
- aroundNode?: (ctx: ContextImplementation<TContext>, nodeId: string, next: () => Promise<NodeResult>) => Promise<NodeResult>;
197
- }
198
- /** A structured error object returned from a failed workflow execution. */
199
- interface WorkflowError {
200
- nodeId: string;
201
- message: string;
202
- originalError?: any;
203
- timestamp: string;
204
- stack?: string;
205
- }
206
- /** The final result of a workflow execution. */
207
- interface WorkflowResult<TContext = Record<string, any>> {
208
- context: TContext;
209
- serializedContext: string;
210
- status: 'completed' | 'failed' | 'stalled' | 'cancelled';
211
- errors?: WorkflowError[];
212
- }
213
-
214
- export { BaseNode as B, type ContextImplementation as C, type EdgeDefinition as E, type ISyncContext as I, type Middleware as M, type NodeDefinition as N, type RuntimeDependencies as R, type WorkflowBlueprint as W, type NodeConfig as a, type NodeResult as b, type NodeContext as c, type NodeFunction as d, type NodeClass as e, type NodeImplementation as f, type NodeRegistry as g, type IAsyncContext as h, isNodeClass as i, type RuntimeOptions as j, type IEvaluator as k, type ILogger as l, type IEventBus as m, type ISerializer as n, type WorkflowError as o, type WorkflowResult as p };