flowcraft 2.2.0 → 2.3.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.
- package/README.md +40 -34
- package/dist/analysis.d.ts +3 -1
- package/dist/chunk-33NO4PUJ.js +74 -0
- package/dist/chunk-33NO4PUJ.js.map +1 -0
- package/dist/chunk-BC4G7OM6.js +42 -0
- package/dist/chunk-BC4G7OM6.js.map +1 -0
- package/dist/chunk-BCRWXTWX.js +21 -0
- package/dist/chunk-BCRWXTWX.js.map +1 -0
- package/dist/chunk-BN4MV36K.js +25 -0
- package/dist/chunk-BN4MV36K.js.map +1 -0
- package/dist/{chunk-ZCHFZBGL.js → chunk-C4HYIJI3.js} +120 -5
- package/dist/chunk-C4HYIJI3.js.map +1 -0
- package/dist/chunk-CD3Q4N6V.js +13 -0
- package/dist/chunk-CD3Q4N6V.js.map +1 -0
- package/dist/chunk-CD4FUZOJ.js +114 -0
- package/dist/chunk-CD4FUZOJ.js.map +1 -0
- package/dist/chunk-DL7KVYZF.js +39 -0
- package/dist/chunk-DL7KVYZF.js.map +1 -0
- package/dist/chunk-FRKO3WX4.js +32 -0
- package/dist/chunk-FRKO3WX4.js.map +1 -0
- package/dist/chunk-G53CSLBF.js +54 -0
- package/dist/chunk-G53CSLBF.js.map +1 -0
- package/dist/chunk-G5BGBPFP.js +172 -0
- package/dist/chunk-G5BGBPFP.js.map +1 -0
- package/dist/chunk-HAZ26F3P.js +98 -0
- package/dist/chunk-HAZ26F3P.js.map +1 -0
- package/dist/chunk-HKX7WQLS.js +446 -0
- package/dist/chunk-HKX7WQLS.js.map +1 -0
- package/dist/{chunk-U5V5O5MN.js → chunk-LNK7LZER.js} +5 -3
- package/dist/chunk-LNK7LZER.js.map +1 -0
- package/dist/chunk-MCGK3FXQ.js +143 -0
- package/dist/chunk-MCGK3FXQ.js.map +1 -0
- package/dist/chunk-MKNZBKSR.js +90 -0
- package/dist/chunk-MKNZBKSR.js.map +1 -0
- package/dist/chunk-MUYLRTSR.js +82 -0
- package/dist/chunk-MUYLRTSR.js.map +1 -0
- package/dist/chunk-NVJ3ZO3P.js +3 -0
- package/dist/{chunk-HMR2GEGE.js.map → chunk-NVJ3ZO3P.js.map} +1 -1
- package/dist/chunk-NVLZFLYM.js +3 -0
- package/dist/chunk-NVLZFLYM.js.map +1 -0
- package/dist/chunk-ONH7PIJZ.js +300 -0
- package/dist/chunk-ONH7PIJZ.js.map +1 -0
- package/dist/chunk-QNYXQKFW.js +25 -0
- package/dist/chunk-QNYXQKFW.js.map +1 -0
- package/dist/chunk-RM677CNU.js +52 -0
- package/dist/chunk-RM677CNU.js.map +1 -0
- package/dist/chunk-WWGFIYKW.js +47 -0
- package/dist/chunk-WWGFIYKW.js.map +1 -0
- package/dist/chunk-XNRIM27H.js +76 -0
- package/dist/chunk-XNRIM27H.js.map +1 -0
- package/dist/{chunk-QLGJUDQF.js → chunk-ZNL7ZXPR.js} +26 -11
- package/dist/chunk-ZNL7ZXPR.js.map +1 -0
- package/dist/container-factory.d.ts +17 -0
- package/dist/container-factory.js +13 -0
- package/dist/container-factory.js.map +1 -0
- package/dist/container.d.ts +23 -0
- package/dist/container.js +3 -0
- package/dist/container.js.map +1 -0
- package/dist/context.d.ts +3 -1
- package/dist/errors.d.ts +18 -17
- package/dist/errors.js +1 -1
- package/dist/evaluator.d.ts +3 -1
- package/dist/flow.d.ts +12 -2
- package/dist/flow.js +2 -2
- package/dist/index.d.ts +7 -8
- package/dist/index.js +26 -14
- package/dist/linter.d.ts +3 -1
- package/dist/logger.d.ts +3 -1
- package/dist/node.d.ts +3 -1
- package/dist/node.js +1 -1
- package/dist/nodes/batch-gather.d.ts +9 -0
- package/dist/nodes/batch-gather.js +4 -0
- package/dist/nodes/batch-gather.js.map +1 -0
- package/dist/nodes/batch-scatter.d.ts +9 -0
- package/dist/nodes/batch-scatter.js +4 -0
- package/dist/nodes/batch-scatter.js.map +1 -0
- package/dist/nodes/subflow.d.ts +9 -0
- package/dist/nodes/subflow.js +10 -0
- package/dist/nodes/subflow.js.map +1 -0
- package/dist/nodes/wait.d.ts +9 -0
- package/dist/nodes/wait.js +4 -0
- package/dist/nodes/wait.js.map +1 -0
- package/dist/runtime/adapter.d.ts +3 -5
- package/dist/runtime/adapter.js +19 -9
- package/dist/runtime/execution-context.d.ts +3 -0
- package/dist/runtime/execution-context.js +6 -0
- package/dist/runtime/execution-context.js.map +1 -0
- package/dist/runtime/executors.d.ts +3 -26
- package/dist/runtime/executors.js +2 -2
- package/dist/runtime/index.d.ts +5 -7
- package/dist/runtime/index.js +21 -10
- package/dist/runtime/node-executor-factory.d.ts +12 -0
- package/dist/runtime/node-executor-factory.js +6 -0
- package/dist/runtime/node-executor-factory.js.map +1 -0
- package/dist/runtime/orchestrator.d.ts +9 -0
- package/dist/runtime/orchestrator.js +8 -0
- package/dist/runtime/orchestrator.js.map +1 -0
- package/dist/runtime/orchestrators/step-by-step.d.ts +16 -0
- package/dist/runtime/orchestrators/step-by-step.js +5 -0
- package/dist/runtime/orchestrators/step-by-step.js.map +1 -0
- package/dist/runtime/orchestrators/utils.d.ts +35 -0
- package/dist/runtime/orchestrators/utils.js +4 -0
- package/dist/runtime/orchestrators/utils.js.map +1 -0
- package/dist/runtime/runtime.d.ts +3 -41
- package/dist/runtime/runtime.js +18 -8
- package/dist/runtime/state.d.ts +3 -21
- package/dist/runtime/state.js +2 -1
- package/dist/runtime/traverser.d.ts +3 -26
- package/dist/runtime/traverser.js +1 -2
- package/dist/runtime/types.d.ts +3 -16
- package/dist/runtime/types.js +1 -1
- package/dist/runtime/workflow-logic-handler.d.ts +17 -0
- package/dist/runtime/workflow-logic-handler.js +5 -0
- package/dist/runtime/workflow-logic-handler.js.map +1 -0
- package/dist/sanitizer.d.ts +3 -1
- package/dist/serializer.d.ts +3 -1
- package/dist/testing/event-logger.d.ts +63 -0
- package/dist/testing/event-logger.js +3 -0
- package/dist/testing/event-logger.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.js +31 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/run-with-trace.d.ts +38 -0
- package/dist/testing/run-with-trace.js +29 -0
- package/dist/testing/run-with-trace.js.map +1 -0
- package/dist/testing/stepper.d.ts +79 -0
- package/dist/testing/stepper.js +11 -0
- package/dist/testing/stepper.js.map +1 -0
- package/dist/types-ezHUBdpL.d.ts +564 -0
- package/dist/types.d.ts +3 -1
- package/package.json +55 -51
- package/LICENSE +0 -21
- package/dist/chunk-5ZXV3R5D.js +0 -28
- package/dist/chunk-5ZXV3R5D.js.map +0 -1
- package/dist/chunk-GEKDR2SS.js +0 -201
- package/dist/chunk-GEKDR2SS.js.map +0 -1
- package/dist/chunk-HMR2GEGE.js +0 -3
- package/dist/chunk-M2FRTT2K.js +0 -144
- package/dist/chunk-M2FRTT2K.js.map +0 -1
- package/dist/chunk-OTS5YJ3S.js +0 -494
- package/dist/chunk-OTS5YJ3S.js.map +0 -1
- package/dist/chunk-QLGJUDQF.js.map +0 -1
- package/dist/chunk-U5V5O5MN.js.map +0 -1
- package/dist/chunk-VSGQDLBF.js +0 -61
- package/dist/chunk-VSGQDLBF.js.map +0 -1
- package/dist/chunk-ZCHFZBGL.js.map +0 -1
- package/dist/types-CsTeXTiA.d.ts +0 -222
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { W as WorkflowState, G as GraphTraverser, J as WorkflowResult, c as FlowRuntime, g as WorkflowBlueprint, n as NodeFunction, o as NodeClass } from '../types-ezHUBdpL.js';
|
|
2
|
+
import '../errors.js';
|
|
3
|
+
import '../container.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents the controlled, step-by-step execution of a workflow.
|
|
7
|
+
* Returned by the `createStepper` utility.
|
|
8
|
+
*/
|
|
9
|
+
interface IWorkflowStepper<TContext extends Record<string, any>> {
|
|
10
|
+
/** The current state of the workflow. Can be inspected after each step. */
|
|
11
|
+
readonly state: WorkflowState<TContext>;
|
|
12
|
+
/** The graph traverser instance. Can be used to inspect the frontier or completed nodes. */
|
|
13
|
+
readonly traverser: GraphTraverser;
|
|
14
|
+
/**
|
|
15
|
+
* Executes the next "turn" or batch of ready nodes in the workflow.
|
|
16
|
+
* @param options Optional configuration for this specific step, like a cancellation signal.
|
|
17
|
+
* @returns A `WorkflowResult` representing the state after the step, or `null` if the workflow has already completed.
|
|
18
|
+
*/
|
|
19
|
+
next(options?: {
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
concurrency?: number;
|
|
22
|
+
}): Promise<WorkflowResult<TContext> | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Reverts the workflow to its previous state.
|
|
25
|
+
* @returns The `WorkflowResult` of the previous state, or `null` if there is no history to revert to.
|
|
26
|
+
*/
|
|
27
|
+
prev(): Promise<WorkflowResult<TContext> | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Resets the stepper to its initial state, clearing all progress and history.
|
|
30
|
+
*/
|
|
31
|
+
reset(): void;
|
|
32
|
+
/**
|
|
33
|
+
* A convenience method to check if the workflow has any more steps to run.
|
|
34
|
+
* @returns `true` if the workflow is complete or stalled, `false` otherwise.
|
|
35
|
+
*/
|
|
36
|
+
isDone(): boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A test utility that creates a stepper to execute a workflow one "turn" at a time.
|
|
40
|
+
* This is invaluable for debugging and writing fine-grained tests where you need to
|
|
41
|
+
* assert the state of the workflow after each logical step.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // In your test file
|
|
45
|
+
* it('should correctly execute step-by-step', async () => {
|
|
46
|
+
* const runtime = new FlowRuntime({ ... });
|
|
47
|
+
* const flow = createFlow('test')
|
|
48
|
+
* .node('a', async () => ({ output: 10 }))
|
|
49
|
+
* .node('b', async ({ input }) => ({ output: input * 2 }))
|
|
50
|
+
* .edge('a', 'b');
|
|
51
|
+
*
|
|
52
|
+
* const stepper = await createStepper(runtime, flow.toBlueprint(), flow.getFunctionRegistry());
|
|
53
|
+
*
|
|
54
|
+
* // First step (executes node 'a')
|
|
55
|
+
* const result1 = await stepper.next();
|
|
56
|
+
* expect(stepper.isDone()).toBe(false);
|
|
57
|
+
* expect(result1.status).toBe('stalled');
|
|
58
|
+
* expect(result1.context._outputs.a).toBe(10);
|
|
59
|
+
*
|
|
60
|
+
* // Second step (executes node 'b')
|
|
61
|
+
* const result2 = await stepper.next();
|
|
62
|
+
* expect(stepper.isDone()).toBe(true);
|
|
63
|
+
* expect(result2.status).toBe('completed');
|
|
64
|
+
* expect(result2.context._outputs.b).toBe(20);
|
|
65
|
+
*
|
|
66
|
+
* // Final step (no more work)
|
|
67
|
+
* const result3 = await stepper.next();
|
|
68
|
+
* expect(result3).toBeNull();
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* @param runtime The `FlowRuntime` instance, used for its configuration.
|
|
72
|
+
* @param blueprint The `WorkflowBlueprint` to execute.
|
|
73
|
+
* @param functionRegistry The function registry from createFlow, containing the node implementations.
|
|
74
|
+
* @param initialState The initial state for the workflow run.
|
|
75
|
+
* @returns A Promise that resolves to an `IWorkflowStepper` instance.
|
|
76
|
+
*/
|
|
77
|
+
declare function createStepper<TContext extends Record<string, any>, TDependencies extends Record<string, any>>(runtime: FlowRuntime<TContext, TDependencies>, blueprint: WorkflowBlueprint, functionRegistry: Map<string, NodeFunction | NodeClass>, initialState?: Partial<TContext>): Promise<IWorkflowStepper<TContext>>;
|
|
78
|
+
|
|
79
|
+
export { type IWorkflowStepper, createStepper };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { createStepper } from '../chunk-XNRIM27H.js';
|
|
2
|
+
import '../chunk-G53CSLBF.js';
|
|
3
|
+
import '../chunk-G5BGBPFP.js';
|
|
4
|
+
import '../chunk-233SESC2.js';
|
|
5
|
+
import '../chunk-HAZ26F3P.js';
|
|
6
|
+
import '../chunk-FRKO3WX4.js';
|
|
7
|
+
import '../chunk-CD4FUZOJ.js';
|
|
8
|
+
import '../chunk-R3HQXIEL.js';
|
|
9
|
+
import '../chunk-BCRWXTWX.js';
|
|
10
|
+
//# sourceMappingURL=stepper.js.map
|
|
11
|
+
//# sourceMappingURL=stepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"stepper.js"}
|
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import { FlowcraftError } from './errors.js';
|
|
2
|
+
import { DIContainer } from './container.js';
|
|
3
|
+
|
|
4
|
+
/** A type guard to reliably distinguish a NodeClass from a NodeFunction. */
|
|
5
|
+
declare function isNodeClass(impl: any): impl is NodeClass;
|
|
6
|
+
/**
|
|
7
|
+
* A structured, class-based node for complex logic with a safe, granular lifecycle.
|
|
8
|
+
* This class is generic, allowing implementations to specify the exact context
|
|
9
|
+
* and dependency types they expect.
|
|
10
|
+
*/
|
|
11
|
+
declare abstract class BaseNode<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any, TOutput = any, TAction extends string = string> {
|
|
12
|
+
protected params?: Record<string, any> | undefined;
|
|
13
|
+
protected nodeId?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @param params Static parameters for this node instance, passed from the blueprint.
|
|
16
|
+
* @param nodeId The ID of the node in the blueprint.
|
|
17
|
+
*/
|
|
18
|
+
constructor(params?: Record<string, any> | undefined, nodeId?: string | undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Phase 1: Gathers and prepares data for execution. This phase is NOT retried on failure.
|
|
21
|
+
* @param context The node's execution context.
|
|
22
|
+
* @returns The data needed for the `exec` phase.
|
|
23
|
+
*/
|
|
24
|
+
prep(context: NodeContext<TContext, TDependencies, TInput>): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Phase 2: Performs the core, isolated logic. This is the ONLY phase that is retried.
|
|
27
|
+
* @param prepResult The data returned from the `prep` phase.
|
|
28
|
+
* @param context The node's execution context.
|
|
29
|
+
*/
|
|
30
|
+
abstract exec(prepResult: any, context: NodeContext<TContext, TDependencies, TInput>): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>;
|
|
31
|
+
/**
|
|
32
|
+
* Phase 3: Processes the result and saves state. This phase is NOT retried.
|
|
33
|
+
* @param execResult The successful result from the `exec` or `fallback` phase.
|
|
34
|
+
* @param _context The node's execution context.
|
|
35
|
+
*/
|
|
36
|
+
post(execResult: Omit<NodeResult<TOutput, TAction>, 'error'>, _context: NodeContext<TContext, TDependencies, TInput>): Promise<NodeResult<TOutput, TAction>>;
|
|
37
|
+
/**
|
|
38
|
+
* An optional safety net that runs if all `exec` retries fail.
|
|
39
|
+
* @param error The final error from the last `exec` attempt.
|
|
40
|
+
* @param _context The node's execution context.
|
|
41
|
+
*/
|
|
42
|
+
fallback(error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>;
|
|
43
|
+
/**
|
|
44
|
+
* An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.
|
|
45
|
+
* This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.
|
|
46
|
+
* Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.
|
|
47
|
+
* @param _error The error that caused the failure.
|
|
48
|
+
* @param _context The node's execution context.
|
|
49
|
+
*/
|
|
50
|
+
recover(_error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare class WorkflowState<TContext extends Record<string, any>> {
|
|
54
|
+
private _completedNodes;
|
|
55
|
+
private errors;
|
|
56
|
+
private anyFallbackExecuted;
|
|
57
|
+
private context;
|
|
58
|
+
private _isAwaiting;
|
|
59
|
+
private _awaitingNodeIds;
|
|
60
|
+
constructor(initialData: Partial<TContext>);
|
|
61
|
+
addCompletedNode(nodeId: string, output: any): Promise<void>;
|
|
62
|
+
addError(nodeId: string, error: Error): void;
|
|
63
|
+
clearError(nodeId: string): void;
|
|
64
|
+
markFallbackExecuted(): void;
|
|
65
|
+
getContext(): IAsyncContext<TContext>;
|
|
66
|
+
getCompletedNodes(): Set<string>;
|
|
67
|
+
getErrors(): WorkflowError[];
|
|
68
|
+
getAnyFallbackExecuted(): boolean;
|
|
69
|
+
markAsAwaiting(nodeId: string): void;
|
|
70
|
+
isAwaiting(): boolean;
|
|
71
|
+
getAwaitingNodeIds(): string[];
|
|
72
|
+
clearAwaiting(nodeId?: string): void;
|
|
73
|
+
getStatus(isTraversalComplete?: boolean): WorkflowResult['status'];
|
|
74
|
+
toResult(serializer: ISerializer): Promise<WorkflowResult<TContext>>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface ExecutionStrategy {
|
|
78
|
+
execute: (nodeDef: NodeDefinition, context: NodeContext<any, any, any>, executionId?: string, signal?: AbortSignal) => Promise<NodeResult<any, any>>;
|
|
79
|
+
}
|
|
80
|
+
declare class FunctionNodeExecutor implements ExecutionStrategy {
|
|
81
|
+
private implementation;
|
|
82
|
+
private maxRetries;
|
|
83
|
+
private eventBus;
|
|
84
|
+
constructor(implementation: NodeFunction, maxRetries: number, eventBus: IEventBus);
|
|
85
|
+
execute(nodeDef: NodeDefinition, context: NodeContext<any, any, any>, executionId?: string, signal?: AbortSignal): Promise<NodeResult<any, any>>;
|
|
86
|
+
}
|
|
87
|
+
declare class ClassNodeExecutor implements ExecutionStrategy {
|
|
88
|
+
private implementation;
|
|
89
|
+
private maxRetries;
|
|
90
|
+
private eventBus;
|
|
91
|
+
constructor(implementation: NodeClass, maxRetries: number, eventBus: IEventBus);
|
|
92
|
+
execute(nodeDef: NodeDefinition, context: NodeContext<any, any, any>, executionId?: string, signal?: AbortSignal): Promise<NodeResult<any, any>>;
|
|
93
|
+
}
|
|
94
|
+
type NodeExecutionResult = {
|
|
95
|
+
status: 'success';
|
|
96
|
+
result: NodeResult<any, any>;
|
|
97
|
+
} | {
|
|
98
|
+
status: 'failed_with_fallback';
|
|
99
|
+
fallbackNodeId: string;
|
|
100
|
+
error: FlowcraftError;
|
|
101
|
+
} | {
|
|
102
|
+
status: 'failed';
|
|
103
|
+
error: FlowcraftError;
|
|
104
|
+
};
|
|
105
|
+
interface NodeExecutorConfig<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {
|
|
106
|
+
context: ExecutionContext<TContext, TDependencies>;
|
|
107
|
+
nodeDef: NodeDefinition;
|
|
108
|
+
strategy: ExecutionStrategy;
|
|
109
|
+
}
|
|
110
|
+
declare class NodeExecutor<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {
|
|
111
|
+
private context;
|
|
112
|
+
private nodeDef;
|
|
113
|
+
private strategy;
|
|
114
|
+
constructor(config: NodeExecutorConfig<TContext, TDependencies>);
|
|
115
|
+
execute(input: any): Promise<NodeExecutionResult>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface ReadyNode {
|
|
119
|
+
nodeId: string;
|
|
120
|
+
nodeDef: NodeDefinition;
|
|
121
|
+
}
|
|
122
|
+
declare class GraphTraverser {
|
|
123
|
+
private frontier;
|
|
124
|
+
private allPredecessors;
|
|
125
|
+
private dynamicBlueprint;
|
|
126
|
+
private completedNodes;
|
|
127
|
+
constructor(blueprint: WorkflowBlueprint, isStrictMode?: boolean);
|
|
128
|
+
/**
|
|
129
|
+
* Clears all nodes from the execution frontier.
|
|
130
|
+
*/
|
|
131
|
+
clearFrontier(): void;
|
|
132
|
+
/**
|
|
133
|
+
* Creates and initializes a GraphTraverser from a saved workflow state.
|
|
134
|
+
* This is the correct way to prepare a traverser for a `resume` operation.
|
|
135
|
+
* @param blueprint The workflow blueprint.
|
|
136
|
+
* @param state The workflow state being resumed.
|
|
137
|
+
* @returns A configured GraphTraverser instance.
|
|
138
|
+
*/
|
|
139
|
+
static fromState(blueprint: WorkflowBlueprint, state: WorkflowState<any>): GraphTraverser;
|
|
140
|
+
private isFallbackNode;
|
|
141
|
+
private getEffectiveJoinStrategy;
|
|
142
|
+
getReadyNodes(): ReadyNode[];
|
|
143
|
+
hasMoreWork(): boolean;
|
|
144
|
+
markNodeCompleted(nodeId: string, result: NodeResult<any, any>, nextNodes: NodeDefinition[]): void;
|
|
145
|
+
getAllNodeIds(): Set<string>;
|
|
146
|
+
getFallbackNodeIds(): Set<string>;
|
|
147
|
+
getCompletedNodes(): Set<string>;
|
|
148
|
+
getDynamicBlueprint(): WorkflowBlueprint;
|
|
149
|
+
getAllPredecessors(): Map<string, Set<string>>;
|
|
150
|
+
addDynamicNode(_nodeId: string, dynamicNode: NodeDefinition, predecessorId: string, gatherNodeId?: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* Manually adds a node ID back to the execution frontier.
|
|
153
|
+
* Used by orchestrators that need fine-grained control over steps.
|
|
154
|
+
* @param nodeId The ID of the node to add to the frontier.
|
|
155
|
+
*/
|
|
156
|
+
addToFrontier(nodeId: string): void;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type NodeExecutorFactory = (context: ExecutionContext<any, any>) => (nodeId: string) => NodeExecutor<any, any>;
|
|
160
|
+
interface ExecutionServices {
|
|
161
|
+
determineNextNodes: (blueprint: WorkflowBlueprint, nodeId: string, result: NodeResult<any, any>, context: ContextImplementation<any>, executionId?: string) => Promise<{
|
|
162
|
+
node: NodeDefinition;
|
|
163
|
+
edge: EdgeDefinition;
|
|
164
|
+
}[]>;
|
|
165
|
+
applyEdgeTransform: (edge: EdgeDefinition, sourceResult: NodeResult<any, any>, targetNode: NodeDefinition, context: ContextImplementation<any>, allPredecessors?: Map<string, Set<string>>) => Promise<void>;
|
|
166
|
+
resolveNodeInput: (nodeId: string, blueprint: WorkflowBlueprint, context: any) => Promise<any>;
|
|
167
|
+
}
|
|
168
|
+
interface IOrchestrator {
|
|
169
|
+
run(context: ExecutionContext<any, any>, traverser: GraphTraverser): Promise<WorkflowResult<any>>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface IRuntime<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies> {
|
|
173
|
+
options: RuntimeOptions<TDependencies>;
|
|
174
|
+
registry: Map<string, NodeFunction | NodeClass>;
|
|
175
|
+
executeNode: (blueprint: WorkflowBlueprint, nodeId: string, state: WorkflowState<TContext>, allPredecessors?: Map<string, Set<string>>, functionRegistry?: Map<string, any>, executionId?: string, signal?: AbortSignal) => Promise<NodeResult>;
|
|
176
|
+
determineNextNodes: (blueprint: WorkflowBlueprint, nodeId: string, result: NodeResult, context: ContextImplementation<TContext>, executionId?: string) => Promise<{
|
|
177
|
+
node: NodeDefinition;
|
|
178
|
+
edge: EdgeDefinition;
|
|
179
|
+
}[]>;
|
|
180
|
+
applyEdgeTransform: (edge: EdgeDefinition, sourceResult: NodeResult, targetNode: NodeDefinition, context: ContextImplementation<TContext>, allPredecessors?: Map<string, Set<string>>) => Promise<void>;
|
|
181
|
+
createForSubflow: (subBlueprint: WorkflowBlueprint, initialSubState: Partial<TContext>, executionId: string, signal?: AbortSignal) => ExecutionContext<TContext, TDependencies>;
|
|
182
|
+
getExecutorForNode: (nodeId: string, context: ExecutionContext<TContext, TDependencies>) => NodeExecutor<TContext, TDependencies>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare class FlowRuntime<TContext extends Record<string, any>, TDependencies extends Record<string, any>> implements IRuntime<TContext, TDependencies> {
|
|
186
|
+
private container;
|
|
187
|
+
registry: Map<string, NodeFunction | NodeClass>;
|
|
188
|
+
private blueprints;
|
|
189
|
+
dependencies: TDependencies;
|
|
190
|
+
logger: ILogger;
|
|
191
|
+
eventBus: IEventBus;
|
|
192
|
+
serializer: ISerializer;
|
|
193
|
+
middleware: Middleware[];
|
|
194
|
+
evaluator: IEvaluator;
|
|
195
|
+
private analysisCache;
|
|
196
|
+
orchestrator: IOrchestrator;
|
|
197
|
+
options: RuntimeOptions<TDependencies>;
|
|
198
|
+
private readonly logicHandler;
|
|
199
|
+
private readonly executorFactory;
|
|
200
|
+
constructor(container: DIContainer, options?: RuntimeOptions<TDependencies>);
|
|
201
|
+
constructor(options: RuntimeOptions<TDependencies>);
|
|
202
|
+
private _setupExecutionContext;
|
|
203
|
+
run(blueprint: WorkflowBlueprint, initialState?: Partial<TContext> | string, options?: {
|
|
204
|
+
functionRegistry?: Map<string, any>;
|
|
205
|
+
strict?: boolean;
|
|
206
|
+
signal?: AbortSignal;
|
|
207
|
+
concurrency?: number;
|
|
208
|
+
}): Promise<WorkflowResult<TContext>>;
|
|
209
|
+
private _setupResumedExecutionContext;
|
|
210
|
+
resume(blueprint: WorkflowBlueprint, serializedContext: string, resumeData: {
|
|
211
|
+
output?: any;
|
|
212
|
+
action?: string;
|
|
213
|
+
}, nodeId?: string, options?: {
|
|
214
|
+
functionRegistry?: Map<string, any>;
|
|
215
|
+
strict?: boolean;
|
|
216
|
+
signal?: AbortSignal;
|
|
217
|
+
concurrency?: number;
|
|
218
|
+
}): Promise<WorkflowResult<TContext>>;
|
|
219
|
+
_createExecutionRegistry(dynamicRegistry?: Map<string, any>): Map<string, NodeFunction | NodeClass>;
|
|
220
|
+
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>>;
|
|
221
|
+
getExecutorForNode(nodeId: string, context: ExecutionContext<TContext, TDependencies>): any;
|
|
222
|
+
createForSubflow(subBlueprint: WorkflowBlueprint, initialSubState: Partial<TContext>, executionId: string, signal?: AbortSignal): ExecutionContext<TContext, TDependencies>;
|
|
223
|
+
determineNextNodes(blueprint: WorkflowBlueprint, nodeId: string, result: NodeResult<any, any>, context: ContextImplementation<TContext>, executionId?: string): Promise<{
|
|
224
|
+
node: NodeDefinition;
|
|
225
|
+
edge: EdgeDefinition;
|
|
226
|
+
}[]>;
|
|
227
|
+
applyEdgeTransform(edge: EdgeDefinition, sourceResult: NodeResult<any, any>, targetNode: NodeDefinition, context: ContextImplementation<TContext>, allPredecessors?: Map<string, Set<string>>): Promise<void>;
|
|
228
|
+
resolveNodeInput(nodeId: string, blueprint: WorkflowBlueprint, context: ContextImplementation<TContext>): Promise<any>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* A container for all state and dependencies of a single workflow execution.
|
|
233
|
+
* This object is created once per `run` and passed through the execution stack.
|
|
234
|
+
*/
|
|
235
|
+
declare class ExecutionContext<TContext extends Record<string, any>, TDependencies extends RuntimeDependencies> {
|
|
236
|
+
readonly blueprint: WorkflowBlueprint;
|
|
237
|
+
readonly state: WorkflowState<TContext>;
|
|
238
|
+
readonly nodeRegistry: Map<string, NodeFunction | NodeClass>;
|
|
239
|
+
readonly executionId: string;
|
|
240
|
+
readonly runtime: FlowRuntime<TContext, TDependencies>;
|
|
241
|
+
readonly services: {
|
|
242
|
+
logger: ILogger;
|
|
243
|
+
eventBus: IEventBus;
|
|
244
|
+
serializer: ISerializer;
|
|
245
|
+
evaluator: IEvaluator;
|
|
246
|
+
middleware: Middleware[];
|
|
247
|
+
dependencies: TDependencies;
|
|
248
|
+
};
|
|
249
|
+
readonly signal?: AbortSignal | undefined;
|
|
250
|
+
readonly concurrency?: number | undefined;
|
|
251
|
+
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
|
|
252
|
+
services: {
|
|
253
|
+
logger: ILogger;
|
|
254
|
+
eventBus: IEventBus;
|
|
255
|
+
serializer: ISerializer;
|
|
256
|
+
evaluator: IEvaluator;
|
|
257
|
+
middleware: Middleware[];
|
|
258
|
+
dependencies: TDependencies;
|
|
259
|
+
}, signal?: AbortSignal | undefined, concurrency?: number | undefined);
|
|
260
|
+
createForSubflow(subBlueprint: WorkflowBlueprint, initialSubState: Partial<TContext>): ExecutionContext<TContext, TDependencies>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The central, serializable representation of a workflow. */
|
|
264
|
+
interface WorkflowBlueprint {
|
|
265
|
+
id: string;
|
|
266
|
+
nodes: NodeDefinition[];
|
|
267
|
+
edges: EdgeDefinition[];
|
|
268
|
+
metadata?: Record<string, any>;
|
|
269
|
+
}
|
|
270
|
+
/** Defines a single step in the workflow. */
|
|
271
|
+
interface NodeDefinition {
|
|
272
|
+
id: string;
|
|
273
|
+
/** A key that resolves to an implementation in a registry. */
|
|
274
|
+
uses: string;
|
|
275
|
+
/** Static parameters for the node. */
|
|
276
|
+
params?: Record<string, any>;
|
|
277
|
+
/** Maps context data to this node's `input`. */
|
|
278
|
+
inputs?: string | Record<string, string>;
|
|
279
|
+
/** Configuration for retries, timeouts, etc. */
|
|
280
|
+
config?: NodeConfig;
|
|
281
|
+
}
|
|
282
|
+
/** Defines the connection and data flow between two nodes. */
|
|
283
|
+
interface EdgeDefinition {
|
|
284
|
+
source: string;
|
|
285
|
+
target: string;
|
|
286
|
+
/** An 'action' from the source node that triggers this edge. */
|
|
287
|
+
action?: string;
|
|
288
|
+
/** A condition that must be met for this edge to be taken. */
|
|
289
|
+
condition?: string;
|
|
290
|
+
/** A string expression to transform the data before passing it to the target node. */
|
|
291
|
+
transform?: string;
|
|
292
|
+
}
|
|
293
|
+
/** Configuration for a node's resiliency and behavior. */
|
|
294
|
+
interface NodeConfig {
|
|
295
|
+
maxRetries?: number;
|
|
296
|
+
retryDelay?: number;
|
|
297
|
+
timeout?: number;
|
|
298
|
+
/** The `uses` key of another node implementation for fallback. */
|
|
299
|
+
fallback?: string;
|
|
300
|
+
/** Determines how a node with multiple incoming edges should be triggered. */
|
|
301
|
+
joinStrategy?: 'all' | 'any';
|
|
302
|
+
}
|
|
303
|
+
/** The required return type for any node implementation. */
|
|
304
|
+
interface NodeResult<TOutput = any, TAction extends string = string> {
|
|
305
|
+
output?: TOutput;
|
|
306
|
+
action?: TAction;
|
|
307
|
+
error?: {
|
|
308
|
+
message: string;
|
|
309
|
+
[key: string]: any;
|
|
310
|
+
};
|
|
311
|
+
/** Allows a node to dynamically schedule new nodes for the orchestrator to execute. */
|
|
312
|
+
dynamicNodes?: NodeDefinition[];
|
|
313
|
+
/** Internal flag: Indicates that this result came from a fallback execution. */
|
|
314
|
+
_fallbackExecuted?: boolean;
|
|
315
|
+
}
|
|
316
|
+
/** The context object passed to every node's execution logic. */
|
|
317
|
+
interface NodeContext<TContext extends Record<string, any> = Record<string, any>, TDependencies extends RuntimeDependencies = RuntimeDependencies, TInput = any> {
|
|
318
|
+
/** The async-only interface for interacting with the workflow's state. */
|
|
319
|
+
context: IAsyncContext<TContext>;
|
|
320
|
+
/** The primary input data for this node, typically from its predecessor. */
|
|
321
|
+
input?: TInput;
|
|
322
|
+
/** Static parameters defined in the blueprint. */
|
|
323
|
+
params: Record<string, any>;
|
|
324
|
+
/** Shared, runtime-level dependencies (e.g., database clients, loggers). */
|
|
325
|
+
dependencies: TDependencies & {
|
|
326
|
+
runtime: ExecutionContext<TContext, TDependencies>;
|
|
327
|
+
workflowState: WorkflowState<TContext>;
|
|
328
|
+
};
|
|
329
|
+
/** A signal to gracefully cancel long-running node operations. */
|
|
330
|
+
signal?: AbortSignal;
|
|
331
|
+
}
|
|
332
|
+
/** A simple function-based node implementation. */
|
|
333
|
+
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>>;
|
|
334
|
+
/** Represents a constructor for any concrete class that extends the abstract BaseNode. */
|
|
335
|
+
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>;
|
|
336
|
+
/** A union of all possible node implementation types. */
|
|
337
|
+
type NodeImplementation = NodeFunction | NodeClass;
|
|
338
|
+
/** A registry mapping node types to their implementations. */
|
|
339
|
+
type NodeRegistry = Record<string, NodeImplementation>;
|
|
340
|
+
/** A discriminated union for all possible context implementations. */
|
|
341
|
+
type ContextImplementation<T extends Record<string, any>> = ISyncContext<T> | IAsyncContext<T>;
|
|
342
|
+
/** The synchronous context interface for high-performance, in-memory state. */
|
|
343
|
+
interface ISyncContext<TContext extends Record<string, any> = Record<string, any>> {
|
|
344
|
+
readonly type: 'sync';
|
|
345
|
+
get<K extends keyof TContext>(key: K): TContext[K] | undefined;
|
|
346
|
+
get(key: string): any | undefined;
|
|
347
|
+
set<K extends keyof TContext>(key: K, value: TContext[K]): void;
|
|
348
|
+
set(key: string, value: any): void;
|
|
349
|
+
has<K extends keyof TContext>(key: K): boolean;
|
|
350
|
+
has(key: string): boolean;
|
|
351
|
+
delete<K extends keyof TContext>(key: K): boolean;
|
|
352
|
+
delete(key: string): boolean;
|
|
353
|
+
toJSON: () => Record<string, any>;
|
|
354
|
+
}
|
|
355
|
+
/** The asynchronous context interface for remote or distributed state. */
|
|
356
|
+
interface IAsyncContext<TContext extends Record<string, any> = Record<string, any>> {
|
|
357
|
+
readonly type: 'async';
|
|
358
|
+
get<K extends keyof TContext>(key: K): Promise<TContext[K] | undefined>;
|
|
359
|
+
get(key: string): Promise<any | undefined>;
|
|
360
|
+
set<K extends keyof TContext>(key: K, value: TContext[K]): Promise<void>;
|
|
361
|
+
set(key: string, value: any): Promise<void>;
|
|
362
|
+
has<K extends keyof TContext>(key: K): Promise<boolean>;
|
|
363
|
+
has(key: string): Promise<boolean>;
|
|
364
|
+
delete<K extends keyof TContext>(key: K): Promise<boolean>;
|
|
365
|
+
delete(key: string): Promise<boolean>;
|
|
366
|
+
toJSON: () => Promise<Record<string, any>>;
|
|
367
|
+
}
|
|
368
|
+
/** Generic for any set of dependencies. */
|
|
369
|
+
interface RuntimeDependencies {
|
|
370
|
+
[key: string]: any;
|
|
371
|
+
}
|
|
372
|
+
/** Configuration options for the FlowRuntime. */
|
|
373
|
+
interface RuntimeOptions<TDependencies extends RuntimeDependencies = RuntimeDependencies> {
|
|
374
|
+
/** A registry of globally available node implementations. */
|
|
375
|
+
registry?: Record<string, NodeFunction | NodeClass | typeof BaseNode>;
|
|
376
|
+
/** A registry of all available workflow blueprints for subflow execution. */
|
|
377
|
+
blueprints?: Record<string, WorkflowBlueprint>;
|
|
378
|
+
/** Shared dependencies to be injected into every node. */
|
|
379
|
+
dependencies?: TDependencies;
|
|
380
|
+
/** A pluggable logger for consistent output. */
|
|
381
|
+
logger?: ILogger;
|
|
382
|
+
/** A pluggable event bus for observability. */
|
|
383
|
+
eventBus?: IEventBus;
|
|
384
|
+
/**
|
|
385
|
+
* A pluggable evaluator for edge conditions and transforms.
|
|
386
|
+
* @default new PropertyEvaluator() - A safe evaluator for simple property access.
|
|
387
|
+
* For complex logic, provide a custom implementation or use the `UnsafeEvaluator`
|
|
388
|
+
* (not recommended for production).
|
|
389
|
+
*/
|
|
390
|
+
evaluator?: IEvaluator;
|
|
391
|
+
/** An array of middleware to wrap node execution. */
|
|
392
|
+
middleware?: Middleware[];
|
|
393
|
+
/** A pluggable serializer for handling complex data types in the context. */
|
|
394
|
+
serializer?: ISerializer;
|
|
395
|
+
/** A flag to enforce strictness in the workflow. */
|
|
396
|
+
strict?: boolean;
|
|
397
|
+
}
|
|
398
|
+
/** Interface for a pluggable expression evaluator for conditions and transforms. */
|
|
399
|
+
interface IEvaluator {
|
|
400
|
+
evaluate: (expression: string, context: Record<string, any>) => any;
|
|
401
|
+
}
|
|
402
|
+
/** Interface for a pluggable logger. */
|
|
403
|
+
interface ILogger {
|
|
404
|
+
debug: (message: string, meta?: Record<string, any>) => void;
|
|
405
|
+
info: (message: string, meta?: Record<string, any>) => void;
|
|
406
|
+
warn: (message: string, meta?: Record<string, any>) => void;
|
|
407
|
+
error: (message: string, meta?: Record<string, any>) => void;
|
|
408
|
+
}
|
|
409
|
+
/** Structured event types for detailed execution tracing. */
|
|
410
|
+
type FlowcraftEvent = {
|
|
411
|
+
type: 'workflow:start';
|
|
412
|
+
payload: {
|
|
413
|
+
blueprintId: string;
|
|
414
|
+
executionId: string;
|
|
415
|
+
};
|
|
416
|
+
} | {
|
|
417
|
+
type: 'workflow:resume';
|
|
418
|
+
payload: {
|
|
419
|
+
blueprintId: string;
|
|
420
|
+
executionId: string;
|
|
421
|
+
};
|
|
422
|
+
} | {
|
|
423
|
+
type: 'workflow:stall';
|
|
424
|
+
payload: {
|
|
425
|
+
blueprintId: string;
|
|
426
|
+
executionId: string;
|
|
427
|
+
remainingNodes: number;
|
|
428
|
+
};
|
|
429
|
+
} | {
|
|
430
|
+
type: 'workflow:pause';
|
|
431
|
+
payload: {
|
|
432
|
+
blueprintId: string;
|
|
433
|
+
executionId: string;
|
|
434
|
+
};
|
|
435
|
+
} | {
|
|
436
|
+
type: 'workflow:finish';
|
|
437
|
+
payload: {
|
|
438
|
+
blueprintId: string;
|
|
439
|
+
executionId: string;
|
|
440
|
+
status: string;
|
|
441
|
+
errors?: WorkflowError[];
|
|
442
|
+
};
|
|
443
|
+
} | {
|
|
444
|
+
type: 'node:start';
|
|
445
|
+
payload: {
|
|
446
|
+
nodeId: string;
|
|
447
|
+
executionId: string;
|
|
448
|
+
input: any;
|
|
449
|
+
blueprintId: string;
|
|
450
|
+
};
|
|
451
|
+
} | {
|
|
452
|
+
type: 'node:finish';
|
|
453
|
+
payload: {
|
|
454
|
+
nodeId: string;
|
|
455
|
+
result: NodeResult;
|
|
456
|
+
executionId: string;
|
|
457
|
+
blueprintId: string;
|
|
458
|
+
};
|
|
459
|
+
} | {
|
|
460
|
+
type: 'node:error';
|
|
461
|
+
payload: {
|
|
462
|
+
nodeId: string;
|
|
463
|
+
error: FlowcraftError;
|
|
464
|
+
executionId: string;
|
|
465
|
+
blueprintId: string;
|
|
466
|
+
};
|
|
467
|
+
} | {
|
|
468
|
+
type: 'node:fallback';
|
|
469
|
+
payload: {
|
|
470
|
+
nodeId: string;
|
|
471
|
+
executionId: string;
|
|
472
|
+
fallback: string;
|
|
473
|
+
blueprintId: string;
|
|
474
|
+
};
|
|
475
|
+
} | {
|
|
476
|
+
type: 'node:retry';
|
|
477
|
+
payload: {
|
|
478
|
+
nodeId: string;
|
|
479
|
+
attempt: number;
|
|
480
|
+
executionId: string;
|
|
481
|
+
blueprintId: string;
|
|
482
|
+
};
|
|
483
|
+
} | {
|
|
484
|
+
type: 'node:skipped';
|
|
485
|
+
payload: {
|
|
486
|
+
nodeId: string;
|
|
487
|
+
edge: EdgeDefinition;
|
|
488
|
+
executionId: string;
|
|
489
|
+
blueprintId: string;
|
|
490
|
+
};
|
|
491
|
+
} | {
|
|
492
|
+
type: 'edge:evaluate';
|
|
493
|
+
payload: {
|
|
494
|
+
source: string;
|
|
495
|
+
target: string;
|
|
496
|
+
condition?: string;
|
|
497
|
+
result: boolean;
|
|
498
|
+
};
|
|
499
|
+
} | {
|
|
500
|
+
type: 'context:change';
|
|
501
|
+
payload: {
|
|
502
|
+
sourceNode: string;
|
|
503
|
+
key: string;
|
|
504
|
+
value: any;
|
|
505
|
+
};
|
|
506
|
+
} | {
|
|
507
|
+
type: 'batch:start';
|
|
508
|
+
payload: {
|
|
509
|
+
batchId: string;
|
|
510
|
+
scatterNodeId: string;
|
|
511
|
+
workerNodeIds: string[];
|
|
512
|
+
};
|
|
513
|
+
} | {
|
|
514
|
+
type: 'batch:finish';
|
|
515
|
+
payload: {
|
|
516
|
+
batchId: string;
|
|
517
|
+
gatherNodeId: string;
|
|
518
|
+
results: any[];
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
/** Interface for a pluggable event bus. */
|
|
522
|
+
interface IEventBus {
|
|
523
|
+
emit: (event: FlowcraftEvent) => void | Promise<void>;
|
|
524
|
+
}
|
|
525
|
+
/** Interface for a pluggable serializer. */
|
|
526
|
+
interface ISerializer {
|
|
527
|
+
serialize: (data: Record<string, any>) => string;
|
|
528
|
+
deserialize: (text: string) => Record<string, any>;
|
|
529
|
+
}
|
|
530
|
+
/** Interface for middleware to handle cross-cutting concerns. */
|
|
531
|
+
interface Middleware<TContext extends Record<string, any> = Record<string, any>> {
|
|
532
|
+
beforeNode?: (ctx: ContextImplementation<TContext>, nodeId: string) => void | Promise<void>;
|
|
533
|
+
afterNode?: (ctx: ContextImplementation<TContext>, nodeId: string, result: NodeResult | undefined, error: Error | undefined) => void | Promise<void>;
|
|
534
|
+
aroundNode?: (ctx: ContextImplementation<TContext>, nodeId: string, next: () => Promise<NodeResult>) => Promise<NodeResult>;
|
|
535
|
+
}
|
|
536
|
+
/** A structured error object returned from a failed workflow execution. */
|
|
537
|
+
interface WorkflowError extends FlowcraftError {
|
|
538
|
+
timestamp: string;
|
|
539
|
+
originalError?: any;
|
|
540
|
+
}
|
|
541
|
+
/** The status of a workflow execution. */
|
|
542
|
+
type WorkflowStatus = 'completed' | 'failed' | 'stalled' | 'cancelled' | 'awaiting';
|
|
543
|
+
/** The final result of a workflow execution. */
|
|
544
|
+
interface WorkflowResult<TContext = Record<string, any>> {
|
|
545
|
+
context: TContext;
|
|
546
|
+
serializedContext: string;
|
|
547
|
+
status: WorkflowStatus;
|
|
548
|
+
errors?: WorkflowError[];
|
|
549
|
+
}
|
|
550
|
+
/** A graph representation of a workflow blueprint. */
|
|
551
|
+
interface UIGraph {
|
|
552
|
+
nodes: Array<Partial<NodeDefinition> & {
|
|
553
|
+
id: string;
|
|
554
|
+
data?: Record<string, any>;
|
|
555
|
+
type?: string;
|
|
556
|
+
}>;
|
|
557
|
+
edges: Array<Partial<EdgeDefinition> & {
|
|
558
|
+
source: string;
|
|
559
|
+
target: string;
|
|
560
|
+
data?: Record<string, any>;
|
|
561
|
+
}>;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export { type ISerializer as A, BaseNode as B, ClassNodeExecutor as C, type WorkflowError as D, type ExecutionStrategy as E, FunctionNodeExecutor as F, GraphTraverser as G, type WorkflowStatus as H, type IOrchestrator as I, type WorkflowResult as J, ExecutionContext as K, type Middleware as M, type NodeExecutionResult as N, type ReadyNode as R, type UIGraph as U, WorkflowState as W, type NodeExecutorConfig as a, NodeExecutor as b, FlowRuntime as c, type NodeExecutorFactory as d, type ExecutionServices as e, type IRuntime as f, type WorkflowBlueprint as g, type NodeDefinition as h, isNodeClass as i, type EdgeDefinition as j, type NodeConfig as k, type NodeResult as l, type NodeContext as m, type NodeFunction as n, type NodeClass as o, type NodeImplementation as p, type NodeRegistry as q, type ContextImplementation as r, type ISyncContext as s, type IAsyncContext as t, type RuntimeDependencies as u, type RuntimeOptions as v, type IEvaluator as w, type ILogger as x, type FlowcraftEvent as y, type IEventBus as z };
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import './errors.js';
|
|
2
|
+
export { r as ContextImplementation, j as EdgeDefinition, y as FlowcraftEvent, t as IAsyncContext, w as IEvaluator, z as IEventBus, x as ILogger, A as ISerializer, s as ISyncContext, M as Middleware, o as NodeClass, k as NodeConfig, m as NodeContext, h as NodeDefinition, n as NodeFunction, p as NodeImplementation, q as NodeRegistry, l as NodeResult, u as RuntimeDependencies, v as RuntimeOptions, U as UIGraph, g as WorkflowBlueprint, D as WorkflowError, J as WorkflowResult, H as WorkflowStatus } from './types-ezHUBdpL.js';
|
|
3
|
+
import './container.js';
|