flowcraft 2.10.0 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +3 -3
  2. package/dist/adapter-DzeZVjSE.d.mts +133 -0
  3. package/dist/adapters/index.d.mts +2 -0
  4. package/dist/adapters/index.mjs +3 -0
  5. package/dist/adapters/persistent-event-bus.d.mts +2 -0
  6. package/dist/adapters/persistent-event-bus.mjs +59 -0
  7. package/dist/analysis-B5Twr7sD.d.mts +52 -0
  8. package/dist/analysis.d.mts +2 -0
  9. package/dist/analysis.mjs +164 -0
  10. package/dist/batch-gather-BhF-IzQR.d.mts +8 -0
  11. package/dist/batch-scatter-DD8TU0Wm.d.mts +8 -0
  12. package/dist/container-BKdd-9wf.d.mts +24 -0
  13. package/dist/container-factory-fDY2kkxt.d.mts +17 -0
  14. package/dist/container-factory.d.mts +2 -0
  15. package/dist/container-factory.mjs +23 -0
  16. package/dist/container.d.mts +2 -0
  17. package/dist/container.mjs +43 -0
  18. package/dist/context-ZVtzXuZu.d.mts +64 -0
  19. package/dist/context.d.mts +2 -0
  20. package/dist/context.mjs +145 -0
  21. package/dist/error-mapper-BAv_YQMQ.d.mts +14 -0
  22. package/dist/error-mapper.d.mts +2 -0
  23. package/dist/error-mapper.mjs +37 -0
  24. package/dist/errors-CyyIj3OO.d.mts +21 -0
  25. package/dist/errors.d.mts +2 -0
  26. package/dist/errors.mjs +24 -0
  27. package/dist/evaluator-Dnj5qJ92.d.mts +31 -0
  28. package/dist/evaluator.d.mts +2 -0
  29. package/dist/evaluator.mjs +80 -0
  30. package/dist/flow-CZGpYpl-.d.mts +94 -0
  31. package/dist/flow.d.mts +2 -0
  32. package/dist/flow.mjs +328 -0
  33. package/dist/index-9iG2qHLe.d.mts +1 -0
  34. package/dist/index-Bk0eNZmQ.d.mts +1 -0
  35. package/dist/index-CNgSR_kt.d.mts +1 -0
  36. package/dist/index-CW2WHUXP.d.mts +1 -0
  37. package/dist/index.d.mts +24 -1
  38. package/dist/index.mjs +31 -791
  39. package/dist/linter-B8KALEae.d.mts +25 -0
  40. package/dist/linter.d.mts +2 -0
  41. package/dist/linter.mjs +74 -0
  42. package/dist/logger-BvDgvNHQ.d.mts +19 -0
  43. package/dist/logger.d.mts +2 -0
  44. package/dist/logger.mjs +26 -0
  45. package/dist/node.d.mts +2 -0
  46. package/dist/node.mjs +55 -0
  47. package/dist/nodes/batch-gather.d.mts +2 -0
  48. package/dist/nodes/batch-gather.mjs +47 -0
  49. package/dist/nodes/batch-scatter.d.mts +2 -0
  50. package/dist/nodes/batch-scatter.mjs +52 -0
  51. package/dist/nodes/index.d.mts +7 -0
  52. package/dist/nodes/index.mjs +8 -0
  53. package/dist/nodes/sleep.d.mts +2 -0
  54. package/dist/nodes/sleep.mjs +41 -0
  55. package/dist/nodes/subflow.d.mts +2 -0
  56. package/dist/nodes/subflow.mjs +64 -0
  57. package/dist/nodes/wait.d.mts +2 -0
  58. package/dist/nodes/wait.mjs +12 -0
  59. package/dist/nodes/webhook.d.mts +2 -0
  60. package/dist/nodes/webhook.mjs +24 -0
  61. package/dist/orchestrator-DwMIJRFI.d.mts +8 -0
  62. package/dist/persistent-event-bus-COiQOpWh.d.mts +68 -0
  63. package/dist/replay-CVOy6d_L.d.mts +44 -0
  64. package/dist/runtime/adapter.d.mts +2 -0
  65. package/dist/runtime/adapter.mjs +349 -0
  66. package/dist/runtime/builtin-keys.d.mts +37 -0
  67. package/dist/runtime/builtin-keys.mjs +12 -0
  68. package/dist/runtime/execution-context.d.mts +2 -0
  69. package/dist/runtime/execution-context.mjs +26 -0
  70. package/dist/runtime/executors.d.mts +2 -0
  71. package/dist/runtime/executors.mjs +259 -0
  72. package/dist/runtime/index.d.mts +6 -0
  73. package/dist/runtime/index.mjs +10 -0
  74. package/dist/runtime/node-executor-factory.d.mts +11 -0
  75. package/dist/runtime/node-executor-factory.mjs +41 -0
  76. package/dist/runtime/orchestrator.d.mts +2 -0
  77. package/dist/runtime/orchestrator.mjs +41 -0
  78. package/dist/runtime/orchestrators/replay.d.mts +2 -0
  79. package/dist/{replay-BB11M6K1.mjs → runtime/orchestrators/replay.mjs} +1 -20
  80. package/dist/runtime/orchestrators/step-by-step.d.mts +15 -0
  81. package/dist/runtime/orchestrators/step-by-step.mjs +41 -0
  82. package/dist/runtime/orchestrators/utils.d.mts +2 -0
  83. package/dist/runtime/orchestrators/utils.mjs +79 -0
  84. package/dist/runtime/runtime.d.mts +2 -0
  85. package/dist/runtime/runtime.mjs +425 -0
  86. package/dist/runtime/scheduler.d.mts +2 -0
  87. package/dist/runtime/scheduler.mjs +64 -0
  88. package/dist/runtime/state.d.mts +2 -0
  89. package/dist/runtime/state.mjs +127 -0
  90. package/dist/runtime/traverser.d.mts +2 -0
  91. package/dist/runtime/traverser.mjs +213 -0
  92. package/dist/runtime/types.d.mts +2 -0
  93. package/dist/runtime/types.mjs +1 -0
  94. package/dist/runtime/workflow-logic-handler.d.mts +16 -0
  95. package/dist/runtime/workflow-logic-handler.mjs +159 -0
  96. package/dist/sanitizer-Bi00YjvO.d.mts +11 -0
  97. package/dist/sanitizer.d.mts +2 -0
  98. package/dist/sanitizer.mjs +37 -0
  99. package/dist/sdk.d.mts +1 -2
  100. package/dist/sdk.mjs +1 -2
  101. package/dist/serializer-BnmJr13R.d.mts +17 -0
  102. package/dist/serializer.d.mts +2 -0
  103. package/dist/serializer.mjs +34 -0
  104. package/dist/sleep-DpwYaY5b.d.mts +8 -0
  105. package/dist/subflow-n2IMsRe2.d.mts +8 -0
  106. package/dist/testing/event-logger.d.mts +62 -0
  107. package/dist/testing/event-logger.mjs +98 -0
  108. package/dist/testing/index.d.mts +5 -172
  109. package/dist/testing/index.mjs +6 -276
  110. package/dist/testing/run-with-trace.d.mts +37 -0
  111. package/dist/testing/run-with-trace.mjs +49 -0
  112. package/dist/testing/stepper.d.mts +78 -0
  113. package/dist/testing/stepper.mjs +100 -0
  114. package/dist/types-BcrXJEPI.d.mts +687 -0
  115. package/dist/types.d.mts +2 -0
  116. package/dist/types.mjs +1 -0
  117. package/dist/utils-BUEgr9V2.d.mts +34 -0
  118. package/dist/wait-2Q-LA7V7.d.mts +8 -0
  119. package/dist/webhook-BiCm-HLx.d.mts +12 -0
  120. package/package.json +4 -4
  121. package/dist/index-BXRN44Qf.d.mts +0 -1347
  122. package/dist/index.mjs.map +0 -1
  123. package/dist/replay-BB11M6K1.mjs.map +0 -1
  124. package/dist/runtime-ChsWirQN.mjs +0 -2256
  125. package/dist/runtime-ChsWirQN.mjs.map +0 -1
  126. package/dist/sdk.mjs.map +0 -1
  127. package/dist/testing/index.mjs.map +0 -1
@@ -0,0 +1,687 @@
1
+ import { t as FlowcraftError } from "./errors-CyyIj3OO.mjs";
2
+ import { t as DIContainer } from "./container-BKdd-9wf.mjs";
3
+
4
+ //#region src/node.d.ts
5
+ /** A type guard to reliably distinguish a NodeClass from a NodeFunction. */
6
+ declare function isNodeClass(impl: any): impl is NodeClass;
7
+ /**
8
+ * A structured, class-based node for complex logic with a safe, granular lifecycle.
9
+ * This class is generic, allowing implementations to specify the exact context
10
+ * and dependency types they expect.
11
+ */
12
+ declare abstract class BaseNode<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any, TOutput = any, TAction extends string = string> {
13
+ protected params?: Record<string, any> | undefined;
14
+ protected nodeId?: string | undefined;
15
+ /**
16
+ * @param params Static parameters for this node instance, passed from the blueprint.
17
+ * @param nodeId The ID of the node in the blueprint.
18
+ */
19
+ constructor(params?: Record<string, any> | undefined, nodeId?: string | undefined);
20
+ /**
21
+ * Phase 1: Gathers and prepares data for execution. This phase is NOT retried on failure.
22
+ * @param context The node's execution context.
23
+ * @returns The data needed for the `exec` phase.
24
+ */
25
+ prep(context: NodeContext<TContext, TDependencies, TInput>): Promise<any>;
26
+ /**
27
+ * Phase 2: Performs the core, isolated logic. This is the ONLY phase that is retried.
28
+ * @param prepResult The data returned from the `prep` phase.
29
+ * @param context The node's execution context.
30
+ */
31
+ abstract exec(prepResult: any, context: NodeContext<TContext, TDependencies, TInput>): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>;
32
+ /**
33
+ * Phase 3: Processes the result and saves state. This phase is NOT retried.
34
+ * @param execResult The successful result from the `exec` or `fallback` phase.
35
+ * @param _context The node's execution context.
36
+ */
37
+ post(execResult: Omit<NodeResult<TOutput, TAction>, 'error'>, _context: NodeContext<TContext, TDependencies, TInput>): Promise<NodeResult<TOutput, TAction>>;
38
+ /**
39
+ * An optional safety net that runs if all `exec` retries fail.
40
+ * @param error The final error from the last `exec` attempt.
41
+ * @param _context The node's execution context.
42
+ */
43
+ fallback(error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>;
44
+ /**
45
+ * An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.
46
+ * This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.
47
+ * Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.
48
+ * @param _error The error that caused the failure.
49
+ * @param _context The node's execution context.
50
+ */
51
+ recover(_error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<void>;
52
+ }
53
+ //#endregion
54
+ //#region src/runtime/scheduler.d.ts
55
+ interface AwaitingWorkflow {
56
+ executionId: string;
57
+ blueprintId: string;
58
+ serializedContext: string;
59
+ awaitingNodeId: string;
60
+ wakeUpAt: string;
61
+ functionRegistry?: Map<string, any>;
62
+ }
63
+ declare class WorkflowScheduler {
64
+ private runtime;
65
+ private activeWorkflows;
66
+ private resumeResults;
67
+ private intervalId?;
68
+ private checkIntervalMs;
69
+ constructor(runtime: FlowRuntime<any, any>, checkIntervalMs?: number);
70
+ start(): void;
71
+ stop(): void;
72
+ registerAwaitingWorkflow(executionId: string, blueprintId: string, serializedContext: string, awaitingNodeId: string, wakeUpAt: string, functionRegistry?: Map<string, any>): void;
73
+ unregisterWorkflow(executionId: string): void;
74
+ private checkAndResumeWorkflows;
75
+ getActiveWorkflows(): AwaitingWorkflow[];
76
+ getResumeResult(executionId: string): WorkflowResult | undefined;
77
+ }
78
+ //#endregion
79
+ //#region src/runtime/state.d.ts
80
+ declare class WorkflowState<TContext extends Record<string, any>> {
81
+ private _completedNodes;
82
+ private errors;
83
+ private anyFallbackExecuted;
84
+ private context;
85
+ private _isAwaiting;
86
+ private _awaitingNodeIds;
87
+ private _awaitingDetails;
88
+ isLastAttempt?: boolean;
89
+ constructor(initialData: Partial<TContext>, context?: IAsyncContext<TContext>);
90
+ /**
91
+ * Configure the context to emit events when modified.
92
+ * This is called after the ExecutionContext is created.
93
+ */
94
+ setEventEmitter(eventBus: any, executionId: string, sourceNode?: string): void;
95
+ addCompletedNode(nodeId: string, output: any): Promise<void>;
96
+ addError(nodeId: string, error: Error): void;
97
+ clearError(nodeId: string): void;
98
+ markFallbackExecuted(): void;
99
+ getContext(): IAsyncContext<TContext>;
100
+ getCompletedNodes(): Set<string>;
101
+ getErrors(): WorkflowError[];
102
+ getAnyFallbackExecuted(): boolean;
103
+ markAsAwaiting(nodeId: string, details?: any): Promise<void>;
104
+ isAwaiting(): boolean;
105
+ getAwaitingNodeIds(): string[];
106
+ getAwaitingDetails(nodeId: string): any;
107
+ clearAwaiting(nodeId?: string): void;
108
+ getStatus(isTraversalComplete?: boolean): WorkflowResult['status'];
109
+ toResult(serializer: ISerializer, executionId?: string): Promise<WorkflowResult<TContext>>;
110
+ }
111
+ //#endregion
112
+ //#region src/runtime/executors.d.ts
113
+ interface ExecutionStrategy {
114
+ execute: (nodeDef: NodeDefinition, context: NodeContext<any, any, any>, executionId?: string, signal?: AbortSignal) => Promise<NodeResult<any, any>>;
115
+ }
116
+ declare class FunctionNodeExecutor implements ExecutionStrategy {
117
+ private implementation;
118
+ private maxRetries;
119
+ private eventBus;
120
+ constructor(implementation: NodeFunction, maxRetries: number, eventBus: IEventBus);
121
+ execute(nodeDef: NodeDefinition, context: NodeContext<any, any, any>, executionId?: string, signal?: AbortSignal): Promise<NodeResult<any, any>>;
122
+ }
123
+ declare class ClassNodeExecutor implements ExecutionStrategy {
124
+ private implementation;
125
+ private maxRetries;
126
+ private eventBus;
127
+ constructor(implementation: NodeClass, maxRetries: number, eventBus: IEventBus);
128
+ execute(nodeDef: NodeDefinition, context: NodeContext<any, any, any>, executionId?: string, signal?: AbortSignal): Promise<NodeResult<any, any>>;
129
+ }
130
+ type NodeExecutionResult = {
131
+ status: 'success';
132
+ result: NodeResult<any, any>;
133
+ } | {
134
+ status: 'failed_with_fallback';
135
+ fallbackNodeId: string;
136
+ error: FlowcraftError;
137
+ } | {
138
+ status: 'failed';
139
+ error: FlowcraftError;
140
+ };
141
+ interface NodeExecutorConfig<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {
142
+ context: ExecutionContext<TContext, TDependencies>;
143
+ nodeDef: NodeDefinition;
144
+ strategy: ExecutionStrategy;
145
+ }
146
+ declare class NodeExecutor<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {
147
+ private context;
148
+ private nodeDef;
149
+ private strategy;
150
+ constructor(config: NodeExecutorConfig<TContext, TDependencies>);
151
+ execute(input: any): Promise<NodeExecutionResult>;
152
+ }
153
+ //#endregion
154
+ //#region src/runtime/traverser.d.ts
155
+ interface ReadyNode {
156
+ nodeId: string;
157
+ nodeDef: NodeDefinition;
158
+ }
159
+ declare class GraphTraverser {
160
+ private frontier;
161
+ private allPredecessors;
162
+ private allSuccessors;
163
+ private dynamicBlueprint;
164
+ private completedNodes;
165
+ private nodesInLoops;
166
+ constructor(blueprint: WorkflowBlueprint, isStrictMode?: boolean);
167
+ /**
168
+ * Clears all nodes from the execution frontier.
169
+ */
170
+ clearFrontier(): void;
171
+ /**
172
+ * Creates and initializes a GraphTraverser from a saved workflow state.
173
+ * This is the correct way to prepare a traverser for a `resume` operation.
174
+ * @param blueprint The workflow blueprint.
175
+ * @param state The workflow state being resumed.
176
+ * @returns A configured GraphTraverser instance.
177
+ */
178
+ static fromState(blueprint: WorkflowBlueprint, state: WorkflowState<any>): GraphTraverser;
179
+ private isFallbackNode;
180
+ private getJoinStrategy;
181
+ private filterNodesInLoops;
182
+ private getAllLoopSuccessors;
183
+ getReadyNodes(): ReadyNode[];
184
+ hasMoreWork(): boolean;
185
+ markNodeCompleted(nodeId: string, result: NodeResult<any, any>, nextNodes: NodeDefinition[]): void;
186
+ getAllNodeIds(): Set<string>;
187
+ getFallbackNodeIds(): Set<string>;
188
+ getCompletedNodes(): Set<string>;
189
+ getDynamicBlueprint(): WorkflowBlueprint;
190
+ getAllPredecessors(): Map<string, Set<string>>;
191
+ getAllSuccessors(): Map<string, Set<string>>;
192
+ getPredecessors(nodeId: string): Set<string>;
193
+ getSuccessors(nodeId: string): Set<string>;
194
+ getNodesInLoop(id: string): Set<string>;
195
+ resetNodeCompletion(nodeId: string): void;
196
+ getNode(nodeId: string, blueprint: WorkflowBlueprint): NodeDefinition | undefined;
197
+ addDynamicNode(_nodeId: string, dynamicNode: NodeDefinition, predecessorId: string, gatherNodeId?: string): void;
198
+ /**
199
+ * Manually adds a node ID back to the execution frontier.
200
+ * Used by orchestrators that need fine-grained control over steps.
201
+ * @param nodeId The ID of the node to add to the frontier.
202
+ */
203
+ addToFrontier(nodeId: string): void;
204
+ }
205
+ //#endregion
206
+ //#region src/runtime/types.d.ts
207
+ type NodeExecutorFactory = (context: ExecutionContext<any, any>) => (nodeId: string) => NodeExecutor<any, any>;
208
+ interface ExecutionServices {
209
+ determineNextNodes: (blueprint: WorkflowBlueprint, nodeId: string, result: NodeResult<any, any>, context: ContextImplementation<any>, executionId?: string) => Promise<{
210
+ node: NodeDefinition;
211
+ edge: EdgeDefinition;
212
+ }[]>;
213
+ applyEdgeTransform: (edge: EdgeDefinition, sourceResult: NodeResult<any, any>, targetNode: NodeDefinition, context: ContextImplementation<any>, allPredecessors?: Map<string, Set<string>>, executionId?: string) => Promise<void>;
214
+ resolveNodeInput: (nodeId: string, blueprint: WorkflowBlueprint, context: any) => Promise<any>;
215
+ }
216
+ interface IOrchestrator {
217
+ run(context: ExecutionContext<any, any>, traverser: GraphTraverser): Promise<WorkflowResult<any>>;
218
+ }
219
+ interface IRuntime<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies> {
220
+ options: RuntimeOptions<TDependencies>;
221
+ registry: Map<string, NodeFunction | NodeClass>;
222
+ executeNode: (blueprint: WorkflowBlueprint, nodeId: string, state: WorkflowState<TContext>, allPredecessors?: Map<string, Set<string>>, functionRegistry?: Map<string, any>, executionId?: string, signal?: AbortSignal) => Promise<NodeResult>;
223
+ determineNextNodes: (blueprint: WorkflowBlueprint, nodeId: string, result: NodeResult, context: ContextImplementation<TContext>, executionId?: string) => Promise<{
224
+ node: NodeDefinition;
225
+ edge: EdgeDefinition;
226
+ }[]>;
227
+ applyEdgeTransform: (edge: EdgeDefinition, sourceResult: NodeResult, targetNode: NodeDefinition, context: ContextImplementation<TContext>, allPredecessors?: Map<string, Set<string>>, executionId?: string) => Promise<void>;
228
+ getExecutorForNode: (nodeId: string, context: ExecutionContext<TContext, TDependencies>) => NodeExecutor<TContext, TDependencies>;
229
+ }
230
+ //#endregion
231
+ //#region src/runtime/runtime.d.ts
232
+ declare class FlowRuntime<TContext extends Record<string, any>, TDependencies extends Record<string, any>> implements IRuntime<TContext, TDependencies> {
233
+ private container;
234
+ registry: Map<string, NodeFunction | NodeClass>;
235
+ private blueprints;
236
+ dependencies: TDependencies;
237
+ logger: ILogger;
238
+ eventBus: IEventBus;
239
+ serializer: ISerializer;
240
+ middleware: Middleware[];
241
+ evaluator: IEvaluator;
242
+ private analysisCache;
243
+ orchestrator: IOrchestrator;
244
+ options: RuntimeOptions<TDependencies>;
245
+ private readonly logicHandler;
246
+ private readonly executorFactory;
247
+ scheduler: WorkflowScheduler;
248
+ getBlueprint(id: string): WorkflowBlueprint | undefined;
249
+ constructor();
250
+ constructor(container: DIContainer, options?: RuntimeOptions<TDependencies>);
251
+ constructor(options: RuntimeOptions<TDependencies>);
252
+ private _setupExecutionContext;
253
+ run(blueprint: WorkflowBlueprint, initialState?: Partial<TContext> | string, options?: {
254
+ functionRegistry?: Map<string, any>;
255
+ strict?: boolean;
256
+ signal?: AbortSignal;
257
+ concurrency?: number;
258
+ }): Promise<WorkflowResult<TContext>>;
259
+ startScheduler(checkIntervalMs?: number): void;
260
+ stopScheduler(): void;
261
+ private _setupResumedExecutionContext;
262
+ resume(blueprint: WorkflowBlueprint, serializedContext: string, resumeData: {
263
+ output?: any;
264
+ action?: string;
265
+ }, nodeId?: string, options?: {
266
+ functionRegistry?: Map<string, any>;
267
+ strict?: boolean;
268
+ signal?: AbortSignal;
269
+ concurrency?: number;
270
+ }): Promise<WorkflowResult<TContext>>;
271
+ _createExecutionRegistry(dynamicRegistry?: Map<string, any>): Map<string, NodeFunction | NodeClass>;
272
+ executeNode(blueprint: WorkflowBlueprint, nodeId: string, state: WorkflowState<TContext>, _allPredecessors?: Map<string, Set<string>>, functionRegistry?: Map<string, any>, executionId?: string, signal?: AbortSignal): Promise<NodeResult<any, any>>;
273
+ getExecutorForNode(nodeId: string, context: ExecutionContext<TContext, TDependencies>): any;
274
+ determineNextNodes(blueprint: WorkflowBlueprint, nodeId: string, result: NodeResult<any, any>, context: ContextImplementation<TContext>, executionId?: string): Promise<{
275
+ node: NodeDefinition;
276
+ edge: EdgeDefinition;
277
+ }[]>;
278
+ applyEdgeTransform(edge: EdgeDefinition, sourceResult: NodeResult<any, any>, targetNode: NodeDefinition, context: ContextImplementation<TContext>, allPredecessors?: Map<string, Set<string>>, executionId?: string): Promise<void>;
279
+ resolveNodeInput(nodeId: string, blueprint: WorkflowBlueprint, context: ContextImplementation<TContext>): Promise<any>;
280
+ /**
281
+ * Replay a workflow execution from a pre-recorded event history.
282
+ * This reconstructs the final workflow state without executing any node logic,
283
+ * enabling time-travel debugging and post-mortem analysis.
284
+ *
285
+ * @param blueprint The workflow blueprint
286
+ * @param events The recorded event history for the execution
287
+ * @param executionId Optional execution ID to filter events (if events contain multiple executions)
288
+ * @returns The reconstructed workflow result
289
+ */
290
+ replay(blueprint: WorkflowBlueprint, events: FlowcraftEvent[], executionId?: string): Promise<WorkflowResult<TContext>>;
291
+ }
292
+ //#endregion
293
+ //#region src/runtime/execution-context.d.ts
294
+ /**
295
+ * A container for all state and dependencies of a single workflow execution.
296
+ * This object is created once per `run` and passed through the execution stack.
297
+ */
298
+ declare class ExecutionContext<TContext extends Record<string, any>, TDependencies extends RuntimeDependencies> {
299
+ readonly blueprint: WorkflowBlueprint;
300
+ readonly state: WorkflowState<TContext>;
301
+ readonly nodeRegistry: Map<string, NodeFunction | NodeClass>;
302
+ readonly executionId: string;
303
+ readonly runtime: FlowRuntime<TContext, TDependencies>;
304
+ readonly services: {
305
+ logger: ILogger;
306
+ eventBus: IEventBus;
307
+ serializer: ISerializer;
308
+ evaluator: IEvaluator;
309
+ middleware: Middleware[];
310
+ dependencies: TDependencies;
311
+ };
312
+ readonly signal?: AbortSignal | undefined;
313
+ readonly concurrency?: number | undefined;
314
+ constructor(blueprint: WorkflowBlueprint, state: WorkflowState<TContext>, nodeRegistry: Map<string, NodeFunction | NodeClass>, executionId: string, runtime: FlowRuntime<TContext, TDependencies>, // A reference back to the runtime for orchestrating subflows
315
+ services: {
316
+ logger: ILogger;
317
+ eventBus: IEventBus;
318
+ serializer: ISerializer;
319
+ evaluator: IEvaluator;
320
+ middleware: Middleware[];
321
+ dependencies: TDependencies;
322
+ }, signal?: AbortSignal | undefined, concurrency?: number | undefined);
323
+ createForSubflow(subBlueprint: WorkflowBlueprint, initialSubState: Partial<TContext>): ExecutionContext<TContext, TDependencies>;
324
+ }
325
+ //#endregion
326
+ //#region src/types.d.ts
327
+ /** Source location information for debugging and visualization. */
328
+ interface SourceLocation {
329
+ file: string;
330
+ line: number;
331
+ column: number;
332
+ }
333
+ /** Metadata associated with a workflow blueprint. */
334
+ interface WorkflowBlueprintMetadata {
335
+ /** Optional version identifier for the blueprint. Used in distributed systems to ensure version compatibility. */
336
+ version?: string;
337
+ /** Entry points for cycles in the workflow graph. */
338
+ cycleEntryPoints?: string[];
339
+ [key: string]: any;
340
+ }
341
+ /** The central, serializable representation of a workflow. */
342
+ interface WorkflowBlueprint {
343
+ id: string;
344
+ nodes: NodeDefinition[];
345
+ edges: EdgeDefinition[];
346
+ metadata?: WorkflowBlueprintMetadata;
347
+ }
348
+ /** Defines a single step in the workflow. */
349
+ interface NodeDefinition {
350
+ id: string;
351
+ /** A key that resolves to an implementation in a registry. */
352
+ uses: string;
353
+ /** Static parameters for the node. */
354
+ params?: Record<string, any>;
355
+ /** Maps context data to this node's `input`. */
356
+ inputs?: string | Record<string, string>;
357
+ /** Configuration for retries, timeouts, etc. */
358
+ config?: NodeConfig;
359
+ /** Source location for debugging and visualization. */
360
+ _sourceLocation?: SourceLocation;
361
+ }
362
+ /** Defines the connection and data flow between two nodes. */
363
+ interface EdgeDefinition {
364
+ source: string;
365
+ target: string;
366
+ /** An 'action' from the source node that triggers this edge. */
367
+ action?: string;
368
+ /** A condition that must be met for this edge to be taken. */
369
+ condition?: string;
370
+ /** A string expression to transform the data before passing it to the target node. */
371
+ transform?: string;
372
+ /** Source location for debugging and visualization. */
373
+ _sourceLocation?: SourceLocation;
374
+ }
375
+ /** Configuration for a node's resiliency and behavior. */
376
+ interface NodeConfig {
377
+ maxRetries?: number;
378
+ retryDelay?: number;
379
+ timeout?: number;
380
+ /** The `uses` key of another node implementation for fallback. */
381
+ fallback?: string;
382
+ /** Determines how a node with multiple incoming edges should be triggered. */
383
+ joinStrategy?: 'all' | 'any';
384
+ }
385
+ /** The required return type for any node implementation. */
386
+ interface NodeResult<TOutput = any, TAction extends string = string> {
387
+ output?: TOutput;
388
+ action?: TAction;
389
+ error?: {
390
+ message: string;
391
+ [key: string]: any;
392
+ };
393
+ /** Allows a node to dynamically schedule new nodes for the orchestrator to execute. */
394
+ dynamicNodes?: NodeDefinition[];
395
+ /** Internal flag: Indicates that this result came from a fallback execution. */
396
+ _fallbackExecuted?: boolean;
397
+ }
398
+ /** The context object passed to every node's execution logic. */
399
+ interface NodeContext<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any> {
400
+ /** The async-only interface for interacting with the workflow's state. */
401
+ context: IAsyncContext<TContext>;
402
+ /** The primary input data for this node, typically from its predecessor. */
403
+ input?: TInput;
404
+ /** Static parameters defined in the blueprint. */
405
+ params: Record<string, any>;
406
+ /** Shared, runtime-level dependencies (e.g., database clients, loggers). */
407
+ dependencies: TDependencies & {
408
+ runtime: ExecutionContext<TContext, TDependencies>;
409
+ workflowState: WorkflowState<TContext>;
410
+ };
411
+ /** A signal to gracefully cancel long-running node operations. */
412
+ signal?: AbortSignal;
413
+ }
414
+ /** A simple function-based node implementation. */
415
+ 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>>;
416
+ /** Represents a constructor for any concrete class that extends the abstract BaseNode. */
417
+ 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>, nodeId?: string) => BaseNode<TContext, TDependencies, TInput, TOutput, TAction>;
418
+ /** A union of all possible node implementation types. */
419
+ type NodeImplementation = NodeFunction | NodeClass;
420
+ /** A registry mapping node types to their implementations. */
421
+ type NodeRegistry = Record<string, NodeImplementation>;
422
+ /** A discriminated union for all possible context implementations. */
423
+ type ContextImplementation<T extends Record<string, any>> = ISyncContext<T> | IAsyncContext<T>;
424
+ /** The synchronous context interface for high-performance, in-memory state. */
425
+ interface ISyncContext<TContext extends Record<string, any> = Record<string, any>> {
426
+ readonly type: 'sync';
427
+ get<K extends keyof TContext>(key: K): TContext[K] | undefined;
428
+ get(key: string): any | undefined;
429
+ set<K extends keyof TContext>(key: K, value: TContext[K]): void;
430
+ set(key: string, value: any): void;
431
+ has<K extends keyof TContext>(key: K): boolean;
432
+ has(key: string): boolean;
433
+ delete<K extends keyof TContext>(key: K): boolean;
434
+ delete(key: string): boolean;
435
+ toJSON: () => Record<string, any>;
436
+ }
437
+ /** The asynchronous context interface for remote or distributed state. */
438
+ interface IAsyncContext<TContext extends Record<string, any> = Record<string, any>> {
439
+ readonly type: 'async';
440
+ get<K extends keyof TContext>(key: K): Promise<TContext[K] | undefined>;
441
+ get(key: string): Promise<any | undefined>;
442
+ set<K extends keyof TContext>(key: K, value: TContext[K]): Promise<void>;
443
+ set(key: string, value: any): Promise<void>;
444
+ has<K extends keyof TContext>(key: K): Promise<boolean>;
445
+ has(key: string): Promise<boolean>;
446
+ delete<K extends keyof TContext>(key: K): Promise<boolean>;
447
+ delete(key: string): Promise<boolean>;
448
+ toJSON: () => Promise<Record<string, any>>;
449
+ /**
450
+ * Applies a batch of patch operations atomically.
451
+ * More efficient than individual set/delete calls for bulk updates.
452
+ */
453
+ patch(operations: PatchOperation[]): Promise<void>;
454
+ }
455
+ /** Represents a single patch operation for delta-based state updates. */
456
+ type PatchOperation = {
457
+ op: 'set';
458
+ key: string;
459
+ value: any;
460
+ } | {
461
+ op: 'delete';
462
+ key: string;
463
+ };
464
+ /** Generic for any set of dependencies. */
465
+ interface RuntimeDependencies {
466
+ [key: string]: any;
467
+ }
468
+ /** Configuration options for the FlowRuntime. */
469
+ interface RuntimeOptions<TDependencies extends RuntimeDependencies = RuntimeDependencies> {
470
+ /** A registry of globally available node implementations. */
471
+ registry?: Record<string, NodeFunction | NodeClass | typeof BaseNode>;
472
+ /** A registry of all available workflow blueprints for subflow execution. */
473
+ blueprints?: Record<string, WorkflowBlueprint>;
474
+ /** Shared dependencies to be injected into every node. */
475
+ dependencies?: TDependencies;
476
+ /** A pluggable logger for consistent output. */
477
+ logger?: ILogger;
478
+ /** A pluggable event bus for observability. */
479
+ eventBus?: IEventBus;
480
+ /**
481
+ * A pluggable evaluator for edge conditions and transforms.
482
+ * @default new PropertyEvaluator() - A safe evaluator for simple property access.
483
+ * For complex logic, provide a custom implementation or use the `UnsafeEvaluator`
484
+ * (not recommended for production).
485
+ */
486
+ evaluator?: IEvaluator;
487
+ /** An array of middleware to wrap node execution. */
488
+ middleware?: Middleware[];
489
+ /** A pluggable serializer for handling complex data types in the context. */
490
+ serializer?: ISerializer;
491
+ /** A flag to enforce strictness in the workflow. */
492
+ strict?: boolean;
493
+ }
494
+ /** Interface for a pluggable expression evaluator for conditions and transforms. */
495
+ interface IEvaluator {
496
+ evaluate: (expression: string, context: Record<string, any>) => any;
497
+ }
498
+ /** Interface for a pluggable logger. */
499
+ interface ILogger {
500
+ debug: (message: string, meta?: Record<string, any>) => void;
501
+ info: (message: string, meta?: Record<string, any>) => void;
502
+ warn: (message: string, meta?: Record<string, any>) => void;
503
+ error: (message: string, meta?: Record<string, any>) => void;
504
+ }
505
+ /** Structured event types for detailed execution tracing. */
506
+ type FlowcraftEvent = {
507
+ type: 'workflow:start';
508
+ payload: {
509
+ blueprintId: string;
510
+ executionId: string;
511
+ };
512
+ } | {
513
+ type: 'workflow:resume';
514
+ payload: {
515
+ blueprintId: string;
516
+ executionId: string;
517
+ };
518
+ } | {
519
+ type: 'workflow:stall';
520
+ payload: {
521
+ blueprintId: string;
522
+ executionId: string;
523
+ remainingNodes: number;
524
+ };
525
+ } | {
526
+ type: 'workflow:pause';
527
+ payload: {
528
+ blueprintId: string;
529
+ executionId: string;
530
+ };
531
+ } | {
532
+ type: 'workflow:finish';
533
+ payload: {
534
+ blueprintId: string;
535
+ executionId: string;
536
+ status: string;
537
+ errors?: WorkflowError[];
538
+ };
539
+ } | {
540
+ type: 'node:start';
541
+ payload: {
542
+ nodeId: string;
543
+ executionId: string;
544
+ input: any;
545
+ blueprintId: string;
546
+ };
547
+ } | {
548
+ type: 'node:finish';
549
+ payload: {
550
+ nodeId: string;
551
+ result: NodeResult;
552
+ executionId: string;
553
+ blueprintId: string;
554
+ };
555
+ } | {
556
+ type: 'node:error';
557
+ payload: {
558
+ nodeId: string;
559
+ error: FlowcraftError;
560
+ executionId: string;
561
+ blueprintId: string;
562
+ };
563
+ } | {
564
+ type: 'node:fallback';
565
+ payload: {
566
+ nodeId: string;
567
+ executionId: string;
568
+ fallback: string;
569
+ blueprintId: string;
570
+ };
571
+ } | {
572
+ type: 'node:retry';
573
+ payload: {
574
+ nodeId: string;
575
+ attempt: number;
576
+ executionId: string;
577
+ blueprintId: string;
578
+ };
579
+ } | {
580
+ type: 'node:skipped';
581
+ payload: {
582
+ nodeId: string;
583
+ edge: EdgeDefinition;
584
+ executionId: string;
585
+ blueprintId: string;
586
+ };
587
+ } | {
588
+ type: 'edge:evaluate';
589
+ payload: {
590
+ source: string;
591
+ target: string;
592
+ condition?: string;
593
+ result: boolean;
594
+ };
595
+ } | {
596
+ type: 'context:change';
597
+ payload: {
598
+ sourceNode: string;
599
+ key: string;
600
+ op: 'set' | 'delete';
601
+ value?: any;
602
+ executionId: string;
603
+ };
604
+ } | {
605
+ type: 'job:enqueued';
606
+ payload: {
607
+ runId: string;
608
+ blueprintId: string;
609
+ nodeId: string;
610
+ queueName?: string;
611
+ };
612
+ } | {
613
+ type: 'job:processed';
614
+ payload: {
615
+ runId: string;
616
+ blueprintId: string;
617
+ nodeId: string;
618
+ duration: number;
619
+ success: boolean;
620
+ };
621
+ } | {
622
+ type: 'job:failed';
623
+ payload: {
624
+ runId: string;
625
+ blueprintId: string;
626
+ nodeId: string;
627
+ error: FlowcraftError;
628
+ };
629
+ } | {
630
+ type: 'batch:start';
631
+ payload: {
632
+ batchId: string;
633
+ scatterNodeId: string;
634
+ workerNodeIds: string[];
635
+ };
636
+ } | {
637
+ type: 'batch:finish';
638
+ payload: {
639
+ batchId: string;
640
+ gatherNodeId: string;
641
+ results: any[];
642
+ };
643
+ };
644
+ /** Interface for a pluggable event bus. */
645
+ interface IEventBus {
646
+ emit: (event: FlowcraftEvent) => void | Promise<void>;
647
+ }
648
+ /** Interface for a pluggable serializer. */
649
+ interface ISerializer {
650
+ serialize: (data: Record<string, any>) => string;
651
+ deserialize: (text: string) => Record<string, any>;
652
+ }
653
+ /** Interface for middleware to handle cross-cutting concerns. */
654
+ interface Middleware<TContext extends Record<string, any> = Record<string, any>> {
655
+ beforeNode?: (ctx: ContextImplementation<TContext>, nodeId: string) => void | Promise<void>;
656
+ afterNode?: (ctx: ContextImplementation<TContext>, nodeId: string, result: NodeResult | undefined, error: Error | undefined) => void | Promise<void>;
657
+ aroundNode?: (ctx: ContextImplementation<TContext>, nodeId: string, next: () => Promise<NodeResult>) => Promise<NodeResult>;
658
+ }
659
+ /** A structured error object returned from a failed workflow execution. */
660
+ interface WorkflowError extends FlowcraftError {
661
+ timestamp: string;
662
+ originalError?: any;
663
+ }
664
+ /** The status of a workflow execution. */
665
+ type WorkflowStatus = 'completed' | 'failed' | 'stalled' | 'cancelled' | 'awaiting';
666
+ /** The final result of a workflow execution. */
667
+ interface WorkflowResult<TContext = Record<string, any>> {
668
+ context: TContext;
669
+ serializedContext: string;
670
+ status: WorkflowStatus;
671
+ errors?: WorkflowError[];
672
+ }
673
+ /** A graph representation of a workflow blueprint. */
674
+ interface UIGraph {
675
+ nodes: Array<Partial<NodeDefinition> & {
676
+ id: string;
677
+ data?: Record<string, any>;
678
+ type?: string;
679
+ }>;
680
+ edges: Array<Partial<EdgeDefinition> & {
681
+ source: string;
682
+ target: string;
683
+ data?: Record<string, any>;
684
+ }>;
685
+ }
686
+ //#endregion
687
+ export { FlowRuntime as A, NodeExecutionResult as B, UIGraph as C, WorkflowResult as D, WorkflowError as E, GraphTraverser as F, WorkflowScheduler as G, NodeExecutorConfig as H, ReadyNode as I, BaseNode as K, ClassNodeExecutor as L, IOrchestrator as M, IRuntime as N, WorkflowStatus as O, NodeExecutorFactory as P, ExecutionStrategy as R, SourceLocation as S, WorkflowBlueprintMetadata as T, WorkflowState as U, NodeExecutor as V, AwaitingWorkflow as W, NodeRegistry as _, IEvaluator as a, RuntimeDependencies as b, ISerializer as c, NodeClass as d, NodeConfig as f, NodeImplementation as g, NodeFunction as h, IAsyncContext as i, ExecutionServices as j, ExecutionContext as k, ISyncContext as l, NodeDefinition as m, EdgeDefinition as n, IEventBus as o, NodeContext as p, isNodeClass as q, FlowcraftEvent as r, ILogger as s, ContextImplementation as t, Middleware as u, NodeResult as v, WorkflowBlueprint as w, RuntimeOptions as x, PatchOperation as y, FunctionNodeExecutor as z };
@@ -0,0 +1,2 @@
1
+ import { C as UIGraph, D as WorkflowResult, E as WorkflowError, O as WorkflowStatus, S as SourceLocation, T as WorkflowBlueprintMetadata, _ as NodeRegistry, a as IEvaluator, b as RuntimeDependencies, c as ISerializer, d as NodeClass, f as NodeConfig, g as NodeImplementation, h as NodeFunction, i as IAsyncContext, l as ISyncContext, m as NodeDefinition, n as EdgeDefinition, o as IEventBus, p as NodeContext, r as FlowcraftEvent, s as ILogger, t as ContextImplementation, u as Middleware, v as NodeResult, w as WorkflowBlueprint, x as RuntimeOptions, y as PatchOperation } from "./types-BcrXJEPI.mjs";
2
+ export { ContextImplementation, EdgeDefinition, FlowcraftEvent, IAsyncContext, IEvaluator, IEventBus, ILogger, ISerializer, ISyncContext, Middleware, NodeClass, NodeConfig, NodeContext, NodeDefinition, NodeFunction, NodeImplementation, NodeRegistry, NodeResult, PatchOperation, RuntimeDependencies, RuntimeOptions, SourceLocation, UIGraph, WorkflowBlueprint, WorkflowBlueprintMetadata, WorkflowError, WorkflowResult, WorkflowStatus };
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };