flowcraft 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -134
- package/dist/analysis.d.ts +43 -0
- package/dist/analysis.js +3 -0
- package/dist/chunk-55J6XMHW.js +3 -0
- package/dist/{chunk-7XUN3OQT.js.map → chunk-55J6XMHW.js.map} +1 -1
- package/dist/chunk-6DNEDIIT.js +123 -0
- package/dist/chunk-6DNEDIIT.js.map +1 -0
- package/dist/chunk-734J4PTM.js +100 -0
- package/dist/chunk-734J4PTM.js.map +1 -0
- package/dist/chunk-DSZSR7UE.js +40 -0
- package/dist/chunk-DSZSR7UE.js.map +1 -0
- package/dist/chunk-GTZC6PQI.js +22 -0
- package/dist/chunk-GTZC6PQI.js.map +1 -0
- package/dist/chunk-HMR2GEGE.js +3 -0
- package/dist/{chunk-F2RSES6P.js.map → chunk-HMR2GEGE.js.map} +1 -1
- package/dist/chunk-J3RNCPED.js +27 -0
- package/dist/chunk-J3RNCPED.js.map +1 -0
- package/dist/chunk-M23P46ZL.js +105 -0
- package/dist/chunk-M23P46ZL.js.map +1 -0
- package/dist/chunk-MICPMOTW.js +49 -0
- package/dist/chunk-MICPMOTW.js.map +1 -0
- package/dist/chunk-NPAJNLXQ.js +106 -0
- package/dist/chunk-NPAJNLXQ.js.map +1 -0
- package/dist/chunk-RAZXOMZC.js +64 -0
- package/dist/chunk-RAZXOMZC.js.map +1 -0
- package/dist/chunk-REH55ZXV.js +13 -0
- package/dist/chunk-REH55ZXV.js.map +1 -0
- package/dist/chunk-RW4FH7IL.js +135 -0
- package/dist/chunk-RW4FH7IL.js.map +1 -0
- package/dist/chunk-RYTIQZIB.js +303 -0
- package/dist/chunk-RYTIQZIB.js.map +1 -0
- package/dist/chunk-UYPIWXZG.js +62 -0
- package/dist/chunk-UYPIWXZG.js.map +1 -0
- package/dist/chunk-VFC342WL.js +29 -0
- package/dist/chunk-VFC342WL.js.map +1 -0
- package/dist/chunk-WXT3YEWU.js +28 -0
- package/dist/chunk-WXT3YEWU.js.map +1 -0
- package/dist/context.d.ts +23 -105
- package/dist/context.js +1 -1
- package/dist/errors.d.ts +15 -31
- package/dist/errors.js +1 -1
- package/dist/evaluator.d.ts +22 -0
- package/dist/evaluator.js +3 -0
- package/dist/evaluator.js.map +1 -0
- package/dist/flow.d.ts +54 -0
- package/dist/flow.js +4 -0
- package/dist/flow.js.map +1 -0
- package/dist/index.d.ts +14 -16
- package/dist/index.js +17 -25
- package/dist/linter.d.ts +24 -0
- package/dist/linter.js +4 -0
- package/dist/linter.js.map +1 -0
- package/dist/logger.d.ts +11 -36
- package/dist/logger.js +1 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/runtime/adapter.d.ts +78 -0
- package/dist/runtime/adapter.js +15 -0
- package/dist/runtime/adapter.js.map +1 -0
- package/dist/runtime/executors.d.ts +26 -0
- package/dist/runtime/executors.js +4 -0
- package/dist/runtime/executors.js.map +1 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.js +16 -0
- package/dist/runtime/runtime.d.ts +33 -0
- package/dist/runtime/runtime.js +14 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/state.d.ts +21 -0
- package/dist/runtime/state.js +4 -0
- package/dist/runtime/state.js.map +1 -0
- package/dist/runtime/traverser.d.ts +24 -0
- package/dist/runtime/traverser.js +5 -0
- package/dist/runtime/traverser.js.map +1 -0
- package/dist/runtime/types.d.ts +15 -0
- package/dist/runtime/types.js +3 -0
- package/dist/sanitizer.d.ts +10 -0
- package/dist/sanitizer.js +3 -0
- package/dist/{utils/sanitize.js.map → sanitizer.js.map} +1 -1
- package/dist/serializer.d.ts +15 -0
- package/dist/serializer.js +3 -0
- package/dist/serializer.js.map +1 -0
- package/dist/types-CZN_FcB6.d.ts +201 -0
- package/dist/types.d.ts +1 -3
- package/dist/types.js +1 -1
- package/package.json +9 -20
- package/LICENSE +0 -21
- package/dist/builder/graph/graph.d.ts +0 -57
- package/dist/builder/graph/graph.js +0 -21
- package/dist/builder/graph/graph.js.map +0 -1
- package/dist/builder/graph/index.d.ts +0 -8
- package/dist/builder/graph/index.js +0 -23
- package/dist/builder/graph/internal-nodes.d.ts +0 -59
- package/dist/builder/graph/internal-nodes.js +0 -20
- package/dist/builder/graph/internal-nodes.js.map +0 -1
- package/dist/builder/graph/runner.d.ts +0 -51
- package/dist/builder/graph/runner.js +0 -21
- package/dist/builder/graph/runner.js.map +0 -1
- package/dist/builder/graph/types.d.ts +0 -3
- package/dist/builder/graph/types.js +0 -3
- package/dist/builder/index.d.ts +0 -8
- package/dist/builder/index.js +0 -24
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/patterns.d.ts +0 -136
- package/dist/builder/patterns.js +0 -19
- package/dist/builder/patterns.js.map +0 -1
- package/dist/chunk-3YMBNZ77.js +0 -441
- package/dist/chunk-3YMBNZ77.js.map +0 -1
- package/dist/chunk-64DNBF5W.js +0 -36
- package/dist/chunk-64DNBF5W.js.map +0 -1
- package/dist/chunk-6QCXIRLA.js +0 -18
- package/dist/chunk-6QCXIRLA.js.map +0 -1
- package/dist/chunk-7XUN3OQT.js +0 -3
- package/dist/chunk-AOHBHYF6.js +0 -7
- package/dist/chunk-AOHBHYF6.js.map +0 -1
- package/dist/chunk-BRFMFLR6.js +0 -85
- package/dist/chunk-BRFMFLR6.js.map +0 -1
- package/dist/chunk-ELEHMJPM.js +0 -13
- package/dist/chunk-ELEHMJPM.js.map +0 -1
- package/dist/chunk-F2RSES6P.js +0 -3
- package/dist/chunk-F6C6J7HK.js +0 -3
- package/dist/chunk-F6C6J7HK.js.map +0 -1
- package/dist/chunk-GMKJ34T2.js +0 -3
- package/dist/chunk-GMKJ34T2.js.map +0 -1
- package/dist/chunk-HEO3XL4Z.js +0 -328
- package/dist/chunk-HEO3XL4Z.js.map +0 -1
- package/dist/chunk-IIKTTIW5.js +0 -56
- package/dist/chunk-IIKTTIW5.js.map +0 -1
- package/dist/chunk-KOBEU2EM.js +0 -3
- package/dist/chunk-KOBEU2EM.js.map +0 -1
- package/dist/chunk-L5PK5VL2.js +0 -178
- package/dist/chunk-L5PK5VL2.js.map +0 -1
- package/dist/chunk-P3RPDZHO.js +0 -36
- package/dist/chunk-P3RPDZHO.js.map +0 -1
- package/dist/chunk-PNWOW52F.js +0 -19
- package/dist/chunk-PNWOW52F.js.map +0 -1
- package/dist/chunk-R27FIYR5.js +0 -62
- package/dist/chunk-R27FIYR5.js.map +0 -1
- package/dist/chunk-S4WFNGQG.js +0 -17
- package/dist/chunk-S4WFNGQG.js.map +0 -1
- package/dist/chunk-TS3M7MWA.js +0 -3
- package/dist/chunk-TS3M7MWA.js.map +0 -1
- package/dist/chunk-UY4PNPBX.js +0 -156
- package/dist/chunk-UY4PNPBX.js.map +0 -1
- package/dist/chunk-VMH2LRM6.js +0 -114
- package/dist/chunk-VMH2LRM6.js.map +0 -1
- package/dist/chunk-VZDHIOCH.js +0 -76
- package/dist/chunk-VZDHIOCH.js.map +0 -1
- package/dist/chunk-WGVHM7DU.js +0 -66
- package/dist/chunk-WGVHM7DU.js.map +0 -1
- package/dist/chunk-WR5PDOPP.js +0 -91
- package/dist/chunk-WR5PDOPP.js.map +0 -1
- package/dist/chunk-YR433ZDA.js +0 -20
- package/dist/chunk-YR433ZDA.js.map +0 -1
- package/dist/executors/in-memory.d.ts +0 -39
- package/dist/executors/in-memory.js +0 -6
- package/dist/executors/in-memory.js.map +0 -1
- package/dist/executors/types.d.ts +0 -3
- package/dist/executors/types.js +0 -3
- package/dist/executors/types.js.map +0 -1
- package/dist/functions.d.ts +0 -88
- package/dist/functions.js +0 -21
- package/dist/functions.js.map +0 -1
- package/dist/types-U76Ukj96.d.ts +0 -609
- package/dist/utils/analysis.d.ts +0 -75
- package/dist/utils/analysis.js +0 -3
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -10
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/mermaid.d.ts +0 -46
- package/dist/utils/mermaid.js +0 -4
- package/dist/utils/mermaid.js.map +0 -1
- package/dist/utils/middleware.d.ts +0 -11
- package/dist/utils/middleware.js +0 -3
- package/dist/utils/middleware.js.map +0 -1
- package/dist/utils/sanitize.d.ts +0 -19
- package/dist/utils/sanitize.js +0 -3
- package/dist/utils/sleep.d.ts +0 -9
- package/dist/utils/sleep.js +0 -4
- package/dist/utils/sleep.js.map +0 -1
- package/dist/workflow/AbstractNode.d.ts +0 -3
- package/dist/workflow/AbstractNode.js +0 -4
- package/dist/workflow/AbstractNode.js.map +0 -1
- package/dist/workflow/Flow.d.ts +0 -3
- package/dist/workflow/Flow.js +0 -16
- package/dist/workflow/Flow.js.map +0 -1
- package/dist/workflow/Node.d.ts +0 -3
- package/dist/workflow/Node.js +0 -15
- package/dist/workflow/Node.js.map +0 -1
- package/dist/workflow/index.d.ts +0 -4
- package/dist/workflow/index.js +0 -18
- package/dist/workflow/index.js.map +0 -1
- package/dist/workflow/node-patterns.d.ts +0 -55
- package/dist/workflow/node-patterns.js +0 -16
- package/dist/workflow/node-patterns.js.map +0 -1
- package/dist/workflow/registry.d.ts +0 -17
- package/dist/workflow/registry.js +0 -3
- package/dist/workflow/registry.js.map +0 -1
- /package/dist/{utils/analysis.js.map → analysis.js.map} +0 -0
- /package/dist/{builder/graph → runtime}/index.js.map +0 -0
- /package/dist/{builder/graph → runtime}/types.js.map +0 -0
package/dist/types-U76Ukj96.d.ts
DELETED
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
import { Context, ContextKey, ContextLens } from './context.js';
|
|
2
|
-
import { Logger } from './logger.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Defines the schema for all custom node types within a specific workflow application.
|
|
6
|
-
*
|
|
7
|
-
* It is a map where each key is a string identifier for a node `type`
|
|
8
|
-
* (e.g., `'llm-process'`), and the value is an object defining the expected
|
|
9
|
-
* shape of that node's `data` payload.
|
|
10
|
-
*
|
|
11
|
-
* By creating an application-specific interface that extends `NodeTypeMap`,
|
|
12
|
-
* you enable compile-time validation and autocompletion for your declarative
|
|
13
|
-
* graph definitions. This type is the central generic constraint used by
|
|
14
|
-
* `TypedWorkflowGraph`, `TypedNodeRegistry`, and `GraphBuilder` to provide a
|
|
15
|
-
* fully type-safe development experience.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* // 1. Define the data payloads for your application's nodes.
|
|
19
|
-
* interface MyAppNodeTypeMap extends NodeTypeMap {
|
|
20
|
-
* 'api-call': { url: string; retries: number };
|
|
21
|
-
* 'data-transform': { mode: 'uppercase' | 'lowercase' };
|
|
22
|
-
* 'output': { destination: string };
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* // 2. Use it to create a type-safe graph definition.
|
|
26
|
-
* const myGraph: TypedWorkflowGraph<MyAppNodeTypeMap> = {
|
|
27
|
-
* nodes: [
|
|
28
|
-
* // TypeScript will validate that `data` matches the 'api-call' schema.
|
|
29
|
-
* { id: 'fetch', type: 'api-call', data: { url: '/users', retries: 3 } },
|
|
30
|
-
* // TypeScript would throw an error on the following line:
|
|
31
|
-
* { id: 'bad', type: 'api-call', data: { path: '/users' } } // Missing 'url' and 'retries'
|
|
32
|
-
* ],
|
|
33
|
-
* edges: [],
|
|
34
|
-
* };
|
|
35
|
-
*/
|
|
36
|
-
interface NodeTypeMap {
|
|
37
|
-
[key: string]: Record<string, any>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* The standard options object passed to a Node's constructor by the `GraphBuilder`.
|
|
41
|
-
* @template TData The type of the `data` payload for this specific node.
|
|
42
|
-
* @template TContext The type of the dependency injection context.
|
|
43
|
-
*/
|
|
44
|
-
interface NodeConstructorOptions<TData, _TContext = object> extends NodeOptions {
|
|
45
|
-
/** The `data` payload from the graph definition, with `nodeId` injected for logging/debugging. */
|
|
46
|
-
data: TData & {
|
|
47
|
-
nodeId: string;
|
|
48
|
-
};
|
|
49
|
-
/** A context object containing any dependencies injected into the `GraphBuilder` constructor. */
|
|
50
|
-
[key: string]: any;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Represents a single, type-safe node within a declarative workflow graph.
|
|
54
|
-
* This is a discriminated union based on the `type` property, ensuring that
|
|
55
|
-
* the `data` payload matches the node's type as defined in the `TypedNodeRegistry`.
|
|
56
|
-
* @template T The `NodeTypeMap` that defines all possible node types and their data schemas.
|
|
57
|
-
*/
|
|
58
|
-
type TypedGraphNode<T extends {
|
|
59
|
-
[K in keyof T]: Record<string, any>;
|
|
60
|
-
}> = {
|
|
61
|
-
[K in keyof T]: {
|
|
62
|
-
/** A unique identifier for the node within the graph. */
|
|
63
|
-
id: string;
|
|
64
|
-
/** The type of the node, used to look up the corresponding Node class in the registry. */
|
|
65
|
-
type: K;
|
|
66
|
-
/** A flexible data object that must match the schema defined in the `NodeTypeMap` for this type. */
|
|
67
|
-
data: T[K];
|
|
68
|
-
/** A config object to configure the node's behavior. */
|
|
69
|
-
config?: NodeOptions;
|
|
70
|
-
};
|
|
71
|
-
}[keyof T];
|
|
72
|
-
/**
|
|
73
|
-
* Represents a directed edge connecting two nodes in a workflow graph.
|
|
74
|
-
*/
|
|
75
|
-
interface GraphEdge {
|
|
76
|
-
/** The `id` of the source node. */
|
|
77
|
-
source: string;
|
|
78
|
-
/** The `id` of the target node. */
|
|
79
|
-
target: string;
|
|
80
|
-
/** The action from the source node that triggers this edge. Defaults to `DEFAULT_ACTION`. */
|
|
81
|
-
action?: string;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Defines the structure of a type-safe, declarative workflow graph.
|
|
85
|
-
* @template T The `NodeTypeMap` that validates the graph's node definitions.
|
|
86
|
-
*/
|
|
87
|
-
interface TypedWorkflowGraph<T extends {
|
|
88
|
-
[K in keyof T]: Record<string, any>;
|
|
89
|
-
}> {
|
|
90
|
-
/** An array of node definitions. */
|
|
91
|
-
nodes: TypedGraphNode<T>[];
|
|
92
|
-
/** An array of edge definitions that connect the nodes. */
|
|
93
|
-
edges: GraphEdge[];
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* A type-safe registry that maps a node type string to its corresponding `Node` constructor.
|
|
97
|
-
* @template TNodeMap The `NodeTypeMap` that defines all possible node types and their data schemas.
|
|
98
|
-
* @template TContext The type of the dependency injection context passed to each constructor.
|
|
99
|
-
*/
|
|
100
|
-
type TypedNodeRegistry<TNodeMap extends NodeTypeMap, TContext = object> = {
|
|
101
|
-
[K in keyof TNodeMap as string extends K ? never : number extends K ? never : K]: new (options: NodeConstructorOptions<TNodeMap[K], TContext> & TContext) => AbstractNode;
|
|
102
|
-
};
|
|
103
|
-
type PredecessorIdMap = Map<string, string[]>;
|
|
104
|
-
type OriginalPredecessorIdMap = Map<string, string[]>;
|
|
105
|
-
/**
|
|
106
|
-
* A serializable, static representation of a compiled workflow graph.
|
|
107
|
-
* This is the "blueprint" that can be stored and shared across distributed workers.
|
|
108
|
-
*/
|
|
109
|
-
interface WorkflowBlueprint {
|
|
110
|
-
/** The final, flattened list of node definitions. */
|
|
111
|
-
nodes: GraphNode[];
|
|
112
|
-
/** The final, flattened list of edge definitions. */
|
|
113
|
-
edges: GraphEdge[];
|
|
114
|
-
/** A map of all node IDs to their direct predecessor count. */
|
|
115
|
-
predecessorCountMap: Record<string, number>;
|
|
116
|
-
/** A map of all node IDs to their logical data-producing predecessors. */
|
|
117
|
-
originalPredecessorIdMap: Record<string, string[]>;
|
|
118
|
-
/** The ID of the node where the flow should start. */
|
|
119
|
-
startNodeId: string;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* The result of a `GraphBuilder.buildBlueprint()` call, containing the serializable blueprint.
|
|
123
|
-
*/
|
|
124
|
-
interface BlueprintBuildResult {
|
|
125
|
-
/** The serializable blueprint of the workflow. */
|
|
126
|
-
blueprint: WorkflowBlueprint;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* The result of a successful `GraphBuilder.build()` call.
|
|
130
|
-
*/
|
|
131
|
-
interface BuildResult {
|
|
132
|
-
/** The fully wired, executable `Flow` instance. */
|
|
133
|
-
flow: Flow;
|
|
134
|
-
/** A map of all created node instances, keyed by their `id` from the graph definition. */
|
|
135
|
-
nodeMap: Map<string, AbstractNode>;
|
|
136
|
-
/** A map of all node `id`s to their predecessor count. */
|
|
137
|
-
predecessorCountMap: Map<string, number>;
|
|
138
|
-
/** A map of all node `id`s to an array of their predecessor `id`s. */
|
|
139
|
-
predecessorIdMap: PredecessorIdMap;
|
|
140
|
-
/**
|
|
141
|
-
* A map of all node `id`s to an array of their original (un-namespaced) predecessor `id`s.
|
|
142
|
-
* This represents the logical dependencies of the graph before flattening.
|
|
143
|
-
* Note: For sub-workflow nodes, their direct predecessors will be the logical terminal nodes
|
|
144
|
-
* from *within* that sub-workflow, reflecting the data flow.
|
|
145
|
-
*/
|
|
146
|
-
originalPredecessorIdMap: OriginalPredecessorIdMap;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Represents a node within the workflow graph.
|
|
150
|
-
* This is a simpler (UNTYPED) version of the `TypedGraphNode` type
|
|
151
|
-
*/
|
|
152
|
-
interface GraphNode {
|
|
153
|
-
/** A unique identifier for the node within the graph. */
|
|
154
|
-
id: string;
|
|
155
|
-
/** The type of the node, used to look up the corresponding Node class in the registry. */
|
|
156
|
-
type: string;
|
|
157
|
-
/** A flexible data object that must match the schema defined in the `NodeTypeMap` for this type. */
|
|
158
|
-
data?: Record<string, any>;
|
|
159
|
-
/** A config object to configure the node's behavior. */
|
|
160
|
-
config?: NodeOptions;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Defines the structure of a workflow graph.
|
|
164
|
-
* This is a simpler (UNTYPED) version of the `TypedWorkflowGraph` type
|
|
165
|
-
*/
|
|
166
|
-
interface WorkflowGraph {
|
|
167
|
-
nodes: GraphNode[];
|
|
168
|
-
edges: GraphEdge[];
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* A permissive (UNTYPED) registry that maps a node type string to a constructor.
|
|
172
|
-
* This is a simpler (UNTYPED) version of the `TypedNodeRegistry` type
|
|
173
|
-
*/
|
|
174
|
-
type NodeRegistry = Map<string, new (...args: any[]) => AbstractNode>;
|
|
175
|
-
/**
|
|
176
|
-
* An interface for an object that can resolve a sub-workflow definition by its ID.
|
|
177
|
-
*/
|
|
178
|
-
interface SubWorkflowResolver {
|
|
179
|
-
getGraph: (id: number | string) => WorkflowGraph | undefined;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Options for configuring the `GraphBuilder`.
|
|
183
|
-
*/
|
|
184
|
-
interface GraphBuilderOptions {
|
|
185
|
-
/**
|
|
186
|
-
* An array of node type names that should be treated as sub-workflows.
|
|
187
|
-
* When the builder encounters a node whose type is in this list, it will
|
|
188
|
-
* attempt to use the `subWorkflowResolver` to fetch and inline the corresponding graph.
|
|
189
|
-
* @example ['sub-flow', 'reusable-task-group']
|
|
190
|
-
*/
|
|
191
|
-
subWorkflowNodeTypes?: string[];
|
|
192
|
-
/**
|
|
193
|
-
* An object that provides the logic for retrieving a sub-workflow's graph definition.
|
|
194
|
-
* This is required if the graph contains any nodes whose types are listed in `subWorkflowNodeTypes`.
|
|
195
|
-
* The `getGraph` method will be called with the `workflowId` from the node's data payload.
|
|
196
|
-
*/
|
|
197
|
-
subWorkflowResolver?: SubWorkflowResolver;
|
|
198
|
-
/**
|
|
199
|
-
* An array of node `type` strings whose outgoing edges represent mutually
|
|
200
|
-
* exclusive conditional paths, not parallel branches.
|
|
201
|
-
*/
|
|
202
|
-
conditionalNodeTypes?: string[];
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* The abstract base class for all executable units in a workflow.
|
|
207
|
-
* It provides the core structure for connecting nodes into a graph.
|
|
208
|
-
*
|
|
209
|
-
* @template TPostRes The type for the action returned by the node's `post` method.
|
|
210
|
-
* @template TParams The type for the node's static parameters.
|
|
211
|
-
*/
|
|
212
|
-
declare abstract class AbstractNode<TPostRes = any, TParams extends Params = Params, TContext extends Context = Context> {
|
|
213
|
-
/** A unique identifier for this node instance, often set by the GraphBuilder. */
|
|
214
|
-
id?: number | string;
|
|
215
|
-
/** A key-value store for static parameters that configure the node's behavior. */
|
|
216
|
-
params: TParams;
|
|
217
|
-
/** A map of successor nodes, keyed by the action that triggers the transition. */
|
|
218
|
-
successors: Map<string | TPostRes | typeof DEFAULT_ACTION | typeof FILTER_FAILED, AbstractNode<any, any, TContext>[]>;
|
|
219
|
-
/** The original graph definition for this node, if created by a GraphBuilder. */
|
|
220
|
-
graphData?: GraphNode;
|
|
221
|
-
/** A flag indicating that this node is a container and should be passed through by distributed executors. */
|
|
222
|
-
isPassthrough: boolean;
|
|
223
|
-
/**
|
|
224
|
-
* Gets the original, un-prefixed ID of the node from its graph definition.
|
|
225
|
-
* This is useful for sub-workflow nodes where the runtime ID might be namespaced (e.g., 'parent:child').
|
|
226
|
-
*/
|
|
227
|
-
get originalId(): string;
|
|
228
|
-
/**
|
|
229
|
-
* Sets a unique identifier for this node instance.
|
|
230
|
-
* Primarily used by the GraphBuilder for wiring and debugging.
|
|
231
|
-
* @param id The unique ID for the node.
|
|
232
|
-
* @returns The node instance for chaining.
|
|
233
|
-
*/
|
|
234
|
-
withId(id: number | string): this;
|
|
235
|
-
/**
|
|
236
|
-
* Attaches the original graph definition data to the node instance.
|
|
237
|
-
* @internal
|
|
238
|
-
* @param data The graph node definition.
|
|
239
|
-
* @returns The node instance for chaining.
|
|
240
|
-
*/
|
|
241
|
-
withGraphData(data: GraphNode): this;
|
|
242
|
-
/**
|
|
243
|
-
* Sets or merges static parameters for the node. These parameters are available
|
|
244
|
-
* via `args.params` in the node's lifecycle methods.
|
|
245
|
-
* @param params The parameters to merge into the node's existing parameters.
|
|
246
|
-
* @returns The node instance for chaining.
|
|
247
|
-
*/
|
|
248
|
-
withParams(params: Partial<TParams>): this;
|
|
249
|
-
/**
|
|
250
|
-
* Defines the next node in the sequence for a given action.
|
|
251
|
-
* This is the primary method for constructing a workflow graph.
|
|
252
|
-
*
|
|
253
|
-
* @param node The successor node or nodes to execute next.
|
|
254
|
-
* @param action The action from this node's `post` method that triggers
|
|
255
|
-
* the transition. Defaults to `DEFAULT_ACTION` for linear flows.
|
|
256
|
-
* @returns The successor node instance, allowing for further chaining. If multiple nodes are provided, it returns the first one.
|
|
257
|
-
*/
|
|
258
|
-
next<NextNode extends AbstractNode<any, any>>(node: NextNode | NextNode[], action?: TPostRes | string | typeof DEFAULT_ACTION | typeof FILTER_FAILED): NextNode;
|
|
259
|
-
/**
|
|
260
|
-
* The internal method that executes the node's full lifecycle.
|
|
261
|
-
* It is called by an `IExecutor`.
|
|
262
|
-
* @internal
|
|
263
|
-
*/
|
|
264
|
-
abstract _run(ctx: NodeRunContext<TContext>): Promise<TPostRes>;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* The fundamental building block of a workflow, representing a single unit of work.
|
|
269
|
-
* It features a three-phase lifecycle, retry logic, and a fluent API for creating
|
|
270
|
-
* data processing pipelines.
|
|
271
|
-
*
|
|
272
|
-
* @template PrepRes The type of data returned by the `prep` phase.
|
|
273
|
-
* @template ExecRes The type of data returned by the `exec` phase.
|
|
274
|
-
* @template PostRes The type of the action returned by the `post` phase.
|
|
275
|
-
* @template TParams The type for the node's static parameters.
|
|
276
|
-
*/
|
|
277
|
-
declare class Node<PrepRes = any, ExecRes = any, PostRes = any, TParams extends Params = Params, TContext extends Context = Context> extends AbstractNode<PostRes, TParams, TContext> {
|
|
278
|
-
/** The total number of times the `exec` phase will be attempted. */
|
|
279
|
-
maxRetries: number;
|
|
280
|
-
/** The time in milliseconds to wait between failed `exec` attempts. */
|
|
281
|
-
wait: number;
|
|
282
|
-
/**
|
|
283
|
-
* @param options Configuration options for the node's behavior.
|
|
284
|
-
* @param options.maxRetries Total number of `exec` attempts. Defaults to `1`.
|
|
285
|
-
* @param options.wait Milliseconds to wait between failed `exec` attempts. Defaults to `0`.
|
|
286
|
-
*/
|
|
287
|
-
constructor(options?: NodeOptions);
|
|
288
|
-
protected _wrapError(e: any, phase: 'prep' | 'exec' | 'post'): Error;
|
|
289
|
-
/**
|
|
290
|
-
* (Lifecycle) Prepares data for execution. Runs once before `exec`.
|
|
291
|
-
* This is the ideal place to read data from the `Context`.
|
|
292
|
-
* @param args The arguments for the node, including `ctx` and `params`.
|
|
293
|
-
* @returns The data required by the `exec` phase.
|
|
294
|
-
*/
|
|
295
|
-
prep(args: NodeArgs<void, void, TParams, TContext>): Promise<PrepRes>;
|
|
296
|
-
/**
|
|
297
|
-
* (Lifecycle) Performs the core, isolated logic of the node.
|
|
298
|
-
* This is the only phase that is retried on failure. It should not access the `Context` directly.
|
|
299
|
-
* @param args The arguments for the node, including `prepRes`.
|
|
300
|
-
* @returns The result of the execution.
|
|
301
|
-
*/
|
|
302
|
-
exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes>;
|
|
303
|
-
/**
|
|
304
|
-
* (Lifecycle) Processes results and determines the next step. Runs once after `exec` succeeds.
|
|
305
|
-
* This is the ideal place to write data to the `Context`.
|
|
306
|
-
* @param args The arguments for the node, including `execRes`.
|
|
307
|
-
* @returns An "action" string to determine which successor to execute next. Defaults to `DEFAULT_ACTION`.
|
|
308
|
-
*/
|
|
309
|
-
post(args: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<PostRes>;
|
|
310
|
-
/**
|
|
311
|
-
* (Lifecycle) A fallback that runs if all `exec` retries fail.
|
|
312
|
-
* If not implemented, the final error will be re-thrown, halting the workflow.
|
|
313
|
-
* @param args The arguments for the node, including the final `error` that caused the failure.
|
|
314
|
-
* @returns A fallback result of type `ExecRes`, allowing the workflow to recover and continue.
|
|
315
|
-
*/
|
|
316
|
-
execFallback(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes>;
|
|
317
|
-
/**
|
|
318
|
-
* The internal retry-aware execution logic for the `exec` phase.
|
|
319
|
-
* @internal
|
|
320
|
-
*/
|
|
321
|
-
_exec(args: NodeArgs<PrepRes, void, TParams, TContext>): Promise<ExecRes>;
|
|
322
|
-
/**
|
|
323
|
-
* The internal method that executes the node's full lifecycle.
|
|
324
|
-
* @internal
|
|
325
|
-
*/
|
|
326
|
-
_run({ ctx, params, signal, logger, executor, visitedInParallel }: NodeRunContext<TContext>): Promise<PostRes>;
|
|
327
|
-
/**
|
|
328
|
-
* Runs the node as a standalone unit, independent of a larger flow.
|
|
329
|
-
* This is useful for testing individual nodes in isolation.
|
|
330
|
-
*
|
|
331
|
-
* @param ctx The shared workflow context.
|
|
332
|
-
* @param options Runtime options like a logger or abort controller.
|
|
333
|
-
* @returns The result of the node's `post` method (its action).
|
|
334
|
-
*/
|
|
335
|
-
run(ctx: TContext, options?: RunOptions): Promise<PostRes>;
|
|
336
|
-
/**
|
|
337
|
-
* Creates a new node that transforms the result of this node's `exec` phase.
|
|
338
|
-
*
|
|
339
|
-
* @remarks
|
|
340
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
341
|
-
* The new node inherits the original's `prep` method. The original `post` method
|
|
342
|
-
* is discarded as it is incompatible with the new result type.
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* const fetchUserNode = new FetchUserNode() // returns { id: 1, name: 'Alice' }
|
|
346
|
-
* const getUserNameNode = fetchUserNode.map(user => user.name) // returns 'Alice'
|
|
347
|
-
*
|
|
348
|
-
* @param fn A sync or async function to transform the execution result from `ExecRes` to `NewRes`.
|
|
349
|
-
* @returns A new `Node` instance with the transformed output type.
|
|
350
|
-
*/
|
|
351
|
-
map<NewRes>(fn: (result: ExecRes) => NewRes | Promise<NewRes>): Node<PrepRes, NewRes, any, TParams, TContext>;
|
|
352
|
-
/**
|
|
353
|
-
* Creates a new node that stores the result of this node's `exec` phase in the `Context`.
|
|
354
|
-
* This is a common terminal operation for a data processing chain.
|
|
355
|
-
*
|
|
356
|
-
* @remarks
|
|
357
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* const USER_NAME = contextKey<string>('user_name')
|
|
361
|
-
* const workflow = new FetchUserNode()
|
|
362
|
-
* .map(user => user.name)
|
|
363
|
-
* .toContext(USER_NAME)
|
|
364
|
-
*
|
|
365
|
-
* @param key The type-safe `ContextKey` to use for storing the result.
|
|
366
|
-
* @returns A new `Node` instance that performs the context update in its `post` phase.
|
|
367
|
-
*/
|
|
368
|
-
toContext(key: ContextKey<ExecRes>): Node<PrepRes, ExecRes, any, TParams, TContext>;
|
|
369
|
-
/**
|
|
370
|
-
* Creates a new node that acts as a conditional gate based on the `exec` result.
|
|
371
|
-
* If the predicate returns `true`, the node returns `DEFAULT_ACTION`.
|
|
372
|
-
* If it returns `false`, the node returns `FILTER_FAILED`, enabling branching.
|
|
373
|
-
*
|
|
374
|
-
* @remarks
|
|
375
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* const checkAdminNode = new FetchUserNode().filter(user => user.isAdmin)
|
|
379
|
-
*
|
|
380
|
-
* checkAdminNode.next(adminOnlyNode, DEFAULT_ACTION)
|
|
381
|
-
* checkAdminNode.next(accessDeniedNode, FILTER_FAILED)
|
|
382
|
-
*
|
|
383
|
-
* @param predicate A sync or async function that returns `true` or `false`.
|
|
384
|
-
* @returns A new `Node` instance that implements the filter logic.
|
|
385
|
-
*/
|
|
386
|
-
filter(predicate: (result: ExecRes) => boolean | Promise<boolean>): Node<PrepRes, ExecRes, any, TParams, TContext>;
|
|
387
|
-
/**
|
|
388
|
-
* Creates a new node that performs a side effect with the `exec` result,
|
|
389
|
-
* but passes the original result through unmodified. Ideal for logging or debugging.
|
|
390
|
-
*
|
|
391
|
-
* @remarks
|
|
392
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
393
|
-
*
|
|
394
|
-
* @example
|
|
395
|
-
* const workflow = new FetchUserNode()
|
|
396
|
-
* .tap(user => console.log('Fetched User:', user))
|
|
397
|
-
* .map(user => user.id)
|
|
398
|
-
*
|
|
399
|
-
* @param fn A function to call with the execution result for its side effect.
|
|
400
|
-
* @returns A new `Node` instance that wraps the original.
|
|
401
|
-
*/
|
|
402
|
-
tap(fn: (result: ExecRes) => void | Promise<void>): Node<PrepRes, ExecRes, PostRes, TParams, TContext>;
|
|
403
|
-
/**
|
|
404
|
-
* Creates a new node that applies a context mutation using a lens before executing.
|
|
405
|
-
* This allows for declaratively setting or updating context as part of a fluent chain.
|
|
406
|
-
*
|
|
407
|
-
* @remarks
|
|
408
|
-
* This method returns a **new** `Node` instance and does not modify the original.
|
|
409
|
-
*
|
|
410
|
-
* @example
|
|
411
|
-
* const VALUE = contextKey<number>('value')
|
|
412
|
-
* const valueLens = lens(VALUE)
|
|
413
|
-
*
|
|
414
|
-
* const nodeWithLens = new SomeNode().withLens(valueLens, 42) // Sets VALUE to 42 before SomeNode runs
|
|
415
|
-
*
|
|
416
|
-
* @param lens The `ContextLens` to use for the operation.
|
|
417
|
-
* @param value The value to set in the context via the lens.
|
|
418
|
-
* @returns A new `Node` instance that applies the context change.
|
|
419
|
-
*/
|
|
420
|
-
withLens<T>(lens: ContextLens<T>, value: T): Node<PrepRes, ExecRes, PostRes, TParams, TContext>;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* A special type of `Node` that orchestrates a graph of other nodes.
|
|
425
|
-
* It can contain its own middleware and can be composed within other flows.
|
|
426
|
-
*
|
|
427
|
-
* @template PrepRes The type of data returned by the `prep` phase.
|
|
428
|
-
* @template ExecRes The type of data returned by the `exec` phase (the final action).
|
|
429
|
-
* @template TParams The type for the flow's static parameters.
|
|
430
|
-
*/
|
|
431
|
-
declare class Flow<PrepRes = any, ExecRes = any, TParams extends Params = Params, TContext extends Context = Context> extends Node<PrepRes, ExecRes, ExecRes, TParams, TContext> {
|
|
432
|
-
/** The first node to be executed in this flow's graph. */
|
|
433
|
-
startNode?: AbstractNode<any, any>;
|
|
434
|
-
/** An array of middleware functions to be applied to every node within this flow. */
|
|
435
|
-
middleware: Middleware[];
|
|
436
|
-
/**
|
|
437
|
-
* @param start An optional node to start the flow with.
|
|
438
|
-
*/
|
|
439
|
-
constructor(start?: AbstractNode<any, any, TContext>);
|
|
440
|
-
protected _wrapError(e: any, phase: 'prep' | 'exec' | 'post'): Error;
|
|
441
|
-
/**
|
|
442
|
-
* Adds a middleware function to this flow. Middleware will be executed in the
|
|
443
|
-
* order it is added, wrapping the execution of every node within this flow.
|
|
444
|
-
* @param fn The middleware function to add.
|
|
445
|
-
* @returns The `Flow` instance for chaining.
|
|
446
|
-
*/
|
|
447
|
-
use(fn: Middleware): this;
|
|
448
|
-
/**
|
|
449
|
-
* Sets the starting node of the flow's graph.
|
|
450
|
-
* @param start The node to start with.
|
|
451
|
-
* @returns The start node instance, allowing for further chaining (`.next()`).
|
|
452
|
-
*/
|
|
453
|
-
start<StartNode extends AbstractNode<any, any, TContext>>(start: StartNode): StartNode;
|
|
454
|
-
/**
|
|
455
|
-
* (Lifecycle) Executes this flow's internal graph when it is used as a sub-flow
|
|
456
|
-
* (a node within a larger flow).
|
|
457
|
-
* @internal
|
|
458
|
-
* @param args The arguments for the node, passed down from the parent executor.
|
|
459
|
-
* @returns The final action returned by the last node in this flow's graph.
|
|
460
|
-
*/
|
|
461
|
-
exec(args: NodeArgs<any, any, TParams, TContext>): Promise<ExecRes>;
|
|
462
|
-
/**
|
|
463
|
-
* (Lifecycle) The post-execution step for a `Flow` node. It simply passes through
|
|
464
|
-
* the final action from its internal graph execution (`execRes`).
|
|
465
|
-
* @internal
|
|
466
|
-
*/
|
|
467
|
-
post({ execRes }: NodeArgs<PrepRes, ExecRes, TParams, TContext>): Promise<ExecRes>;
|
|
468
|
-
/**
|
|
469
|
-
* Runs the entire flow as a top-level entry point.
|
|
470
|
-
* @param ctx The shared workflow context.
|
|
471
|
-
* @param options Runtime options like a logger, abort controller, or a custom executor.
|
|
472
|
-
* @returns The final action returned by the last node in the flow.
|
|
473
|
-
*/
|
|
474
|
-
run(ctx: TContext, options?: RunOptions): Promise<ExecRes>;
|
|
475
|
-
/**
|
|
476
|
-
* Finds a node within the flow's graph by its unique ID.
|
|
477
|
-
*
|
|
478
|
-
* This method performs a breadth-first search starting from the `startNode`.
|
|
479
|
-
* It is a convenient way to get a reference to a specific node instance
|
|
480
|
-
* for debugging or dynamic modifications.
|
|
481
|
-
*
|
|
482
|
-
* @remarks
|
|
483
|
-
* This performs a graph traversal on each call, which has a time complexity
|
|
484
|
-
* proportional to the number of nodes and edges in the graph (O(V+E)). For
|
|
485
|
-
* performance-critical applications or flows built with `GraphBuilder`,
|
|
486
|
-
* it is more efficient to use the `nodeMap` returned by `GraphBuilder.build()`.
|
|
487
|
-
*
|
|
488
|
-
* @param id The unique ID of the node to find (set via `.withId()` or by the `GraphBuilder`).
|
|
489
|
-
* @returns The `AbstractNode` instance if found, otherwise `undefined`.
|
|
490
|
-
*/
|
|
491
|
-
getNodeById(id: string | number): AbstractNode<any, any, TContext> | undefined;
|
|
492
|
-
/**
|
|
493
|
-
* Retrieves all unique nodes within the flow's graph.
|
|
494
|
-
* @internal
|
|
495
|
-
*/
|
|
496
|
-
getAllNodes(): Set<AbstractNode>;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Defines the contract for a workflow execution engine.
|
|
501
|
-
* An executor is responsible for taking a `Flow` definition and running it,
|
|
502
|
-
* orchestrating the traversal of the node graph.
|
|
503
|
-
*/
|
|
504
|
-
interface IExecutor {
|
|
505
|
-
/**
|
|
506
|
-
* Executes a given flow with a specific context and options.
|
|
507
|
-
* @param flow The `Flow` instance to execute.
|
|
508
|
-
* @param context The shared `Context` for the workflow run.
|
|
509
|
-
* @param options Runtime options, which can include a logger, abort controller, or initial params.
|
|
510
|
-
* @returns A promise that resolves with the final action of the workflow, or another result
|
|
511
|
-
* depending on the executor's implementation (e.g., a job ID for a distributed executor).
|
|
512
|
-
*/
|
|
513
|
-
run: <T>(flow: Flow<any, T>, context: Context, options?: RunOptions) => Promise<T>;
|
|
514
|
-
/**
|
|
515
|
-
* Determines the next node to execute based on the action returned by the current node.
|
|
516
|
-
* @param curr The current node.
|
|
517
|
-
* @param action The action returned by the current node.
|
|
518
|
-
* @returns The next node to execute, or undefined if no further action is required.
|
|
519
|
-
*/
|
|
520
|
-
getNextNode: (curr: AbstractNode, action: any) => AbstractNode | undefined;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Internal, normalized run options used by executors.
|
|
524
|
-
* @internal
|
|
525
|
-
*/
|
|
526
|
-
interface InternalRunOptions {
|
|
527
|
-
logger: Logger;
|
|
528
|
-
signal?: AbortSignal;
|
|
529
|
-
params: Params;
|
|
530
|
-
executor: IExecutor;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/** A generic type for key-value parameters. */
|
|
534
|
-
type Params = Record<string, any>;
|
|
535
|
-
/** The default action returned by a node for linear progression. */
|
|
536
|
-
declare const DEFAULT_ACTION: unique symbol;
|
|
537
|
-
/** The action returned by a `.filter()` node when the predicate fails. */
|
|
538
|
-
declare const FILTER_FAILED: unique symbol;
|
|
539
|
-
/**
|
|
540
|
-
* The standard arguments object passed to a node's lifecycle methods.
|
|
541
|
-
* @template PrepRes The type of the `prepRes` property.
|
|
542
|
-
* @template ExecRes The type of the `execRes` property.
|
|
543
|
-
* @template TParams The type for the node's static parameters.
|
|
544
|
-
*/
|
|
545
|
-
interface NodeArgs<PrepRes = any, ExecRes = any, TParams extends Params = Params, TContext extends Context = Context> {
|
|
546
|
-
/** The shared, mutable context for the workflow run. */
|
|
547
|
-
ctx: TContext;
|
|
548
|
-
/** The static parameters for the node, merged from the node and flow's `withParams`. */
|
|
549
|
-
params: TParams;
|
|
550
|
-
/** An `AbortController` to gracefully cancel the workflow. */
|
|
551
|
-
controller?: AbortController;
|
|
552
|
-
/** An `AbortSignal` for handling cancellation. */
|
|
553
|
-
signal?: AbortSignal;
|
|
554
|
-
/** The logger instance for the workflow run. */
|
|
555
|
-
logger: Logger;
|
|
556
|
-
/** The result of the `prep` phase. */
|
|
557
|
-
prepRes: PrepRes;
|
|
558
|
-
/** The result of the `exec` phase. */
|
|
559
|
-
execRes: ExecRes;
|
|
560
|
-
/** The final error object, available only in `execFallback`. */
|
|
561
|
-
error?: Error;
|
|
562
|
-
/** The name of the Node's constructor, for logging. */
|
|
563
|
-
name?: string;
|
|
564
|
-
/** A reference to the current `IExecutor` running the flow. */
|
|
565
|
-
executor?: IExecutor;
|
|
566
|
-
/** The actual node instance being executed. */
|
|
567
|
-
node?: AbstractNode;
|
|
568
|
-
/** A shared set to track visited nodes within a parallel block, preventing race conditions. @internal */
|
|
569
|
-
visitedInParallel?: Set<AbstractNode>;
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* The context object passed to a node's internal `_run` method.
|
|
573
|
-
* @internal
|
|
574
|
-
*/
|
|
575
|
-
interface NodeRunContext<TContext extends Context = Context> {
|
|
576
|
-
ctx: TContext;
|
|
577
|
-
params: Params;
|
|
578
|
-
signal?: AbortSignal;
|
|
579
|
-
logger: Logger;
|
|
580
|
-
executor?: IExecutor;
|
|
581
|
-
/** A shared set to track visited nodes within a parallel block. @internal */
|
|
582
|
-
visitedInParallel?: Set<AbstractNode>;
|
|
583
|
-
}
|
|
584
|
-
/** Options for configuring a `Node` instance. */
|
|
585
|
-
interface NodeOptions {
|
|
586
|
-
/** The total number of times the `exec` phase will be attempted. Defaults to `1`. */
|
|
587
|
-
maxRetries?: number;
|
|
588
|
-
/** The time in milliseconds to wait between failed `exec` attempts. Defaults to `0`. */
|
|
589
|
-
wait?: number;
|
|
590
|
-
}
|
|
591
|
-
/** Options for running a top-level `Flow`. */
|
|
592
|
-
interface RunOptions {
|
|
593
|
-
/** An `AbortController` to gracefully cancel the workflow. */
|
|
594
|
-
controller?: AbortController;
|
|
595
|
-
/** An `AbortSignal` for handling cancellation. */
|
|
596
|
-
signal?: AbortSignal;
|
|
597
|
-
/** A `Logger` instance to receive logs from the execution engine. */
|
|
598
|
-
logger?: Logger;
|
|
599
|
-
/** Top-level parameters to be merged into the context for the entire run. */
|
|
600
|
-
params?: Params;
|
|
601
|
-
/** A custom `IExecutor` instance to run the workflow. Defaults to `InMemoryExecutor`. */
|
|
602
|
-
executor?: IExecutor;
|
|
603
|
-
}
|
|
604
|
-
/** The function signature for the `next` function passed to middleware. */
|
|
605
|
-
type MiddlewareNext<T = any> = (args: NodeArgs) => Promise<T>;
|
|
606
|
-
/** The function signature for a middleware function. */
|
|
607
|
-
type Middleware<T = any> = (args: NodeArgs, next: MiddlewareNext<T>) => Promise<T>;
|
|
608
|
-
|
|
609
|
-
export { AbstractNode as A, type BlueprintBuildResult as B, DEFAULT_ACTION as D, Flow as F, type GraphEdge as G, type IExecutor as I, type MiddlewareNext as M, Node as N, type OriginalPredecessorIdMap as O, type Params as P, type RunOptions as R, type SubWorkflowResolver as S, type TypedGraphNode as T, type WorkflowBlueprint as W, FILTER_FAILED as a, type NodeArgs as b, type NodeRunContext as c, type NodeOptions as d, type Middleware as e, type NodeTypeMap as f, type NodeConstructorOptions as g, type TypedWorkflowGraph as h, type TypedNodeRegistry as i, type PredecessorIdMap as j, type BuildResult as k, type GraphNode as l, type WorkflowGraph as m, type NodeRegistry as n, type GraphBuilderOptions as o, type InternalRunOptions as p };
|
package/dist/utils/analysis.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { f as NodeTypeMap, T as TypedGraphNode, h as TypedWorkflowGraph, m as WorkflowGraph, l as GraphNode } from '../types-U76Ukj96.js';
|
|
2
|
-
import '../context.js';
|
|
3
|
-
import '../logger.js';
|
|
4
|
-
|
|
5
|
-
/** The rich metadata object returned by the analyzeGraph function. */
|
|
6
|
-
interface GraphAnalysis<T extends NodeTypeMap = any> {
|
|
7
|
-
/** A map of all nodes, keyed by ID, augmented with their connection degrees. */
|
|
8
|
-
nodes: Map<string, TypedGraphNode<T> & {
|
|
9
|
-
inDegree: number;
|
|
10
|
-
outDegree: number;
|
|
11
|
-
}>;
|
|
12
|
-
/** An array of all node IDs in the graph. */
|
|
13
|
-
allNodeIds: string[];
|
|
14
|
-
/** An array of node IDs that have no incoming edges. */
|
|
15
|
-
startNodeIds: string[];
|
|
16
|
-
/** A list of cycles found in the graph. Each cycle is an array of node IDs. */
|
|
17
|
-
cycles: string[][];
|
|
18
|
-
}
|
|
19
|
-
/** A standard structure for reporting a single validation error. */
|
|
20
|
-
interface ValidationError {
|
|
21
|
-
/** The ID of the node where the error occurred, if applicable. */
|
|
22
|
-
nodeId?: string;
|
|
23
|
-
/** A category for the error, e.g., 'CycleDetected', 'ConnectionRuleViolation'. */
|
|
24
|
-
type: string;
|
|
25
|
-
/** A human-readable message explaining the validation failure. */
|
|
26
|
-
message: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A function that takes a graph analysis and the original graph,
|
|
30
|
-
* and returns an array of validation errors.
|
|
31
|
-
*/
|
|
32
|
-
type Validator<T extends NodeTypeMap = any> = (analysis: GraphAnalysis<T>, graph: TypedWorkflowGraph<T>) => ValidationError[];
|
|
33
|
-
/**
|
|
34
|
-
* A helper function that creates a type guard for filtering nodes by their type.
|
|
35
|
-
* This simplifies writing type-safe validation rules by removing the need for
|
|
36
|
-
* verbose, explicit type guard syntax.
|
|
37
|
-
*
|
|
38
|
-
* @param type The literal string of the node type to check for.
|
|
39
|
-
* @returns A type guard function that narrows the node to its specific type.
|
|
40
|
-
*/
|
|
41
|
-
declare function isNodeType<T extends NodeTypeMap, K extends keyof T>(type: K): (node: TypedGraphNode<T>) => node is TypedGraphNode<T> & {
|
|
42
|
-
type: K;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Analyzes a declarative workflow graph definition to extract structural metadata.
|
|
46
|
-
* This is a lightweight, static utility that does not instantiate any nodes.
|
|
47
|
-
*
|
|
48
|
-
* @param graph The WorkflowGraph object containing nodes and edges.
|
|
49
|
-
* @returns A GraphAnalysis object containing nodes with degree counts, start nodes, and any cycles.
|
|
50
|
-
*/
|
|
51
|
-
declare function analyzeGraph<T extends NodeTypeMap>(graph: TypedWorkflowGraph<T>): GraphAnalysis<T>;
|
|
52
|
-
declare function analyzeGraph(graph: WorkflowGraph): GraphAnalysis;
|
|
53
|
-
/**
|
|
54
|
-
* Factory for creating a generic, reusable validator that checks node properties.
|
|
55
|
-
* A single rule can now return multiple errors for a single node.
|
|
56
|
-
*
|
|
57
|
-
* @param filter A predicate to select which nodes this rule applies to.
|
|
58
|
-
* @param check A function that validates a selected node. It can return a single
|
|
59
|
-
* ValidationError, an array of them, or null if the node is valid.
|
|
60
|
-
* @returns A Validator function.
|
|
61
|
-
*/
|
|
62
|
-
declare function createNodeRule<T extends NodeTypeMap>(filter: (node: TypedGraphNode<T>) => boolean, check: (node: TypedGraphNode<T> & {
|
|
63
|
-
inDegree: number;
|
|
64
|
-
outDegree: number;
|
|
65
|
-
}) => ValidationError | ValidationError[] | null | undefined): Validator<T>;
|
|
66
|
-
declare function createNodeRule(filter: (node: GraphNode) => boolean, check: (node: GraphNode & {
|
|
67
|
-
inDegree: number;
|
|
68
|
-
outDegree: number;
|
|
69
|
-
}) => ValidationError | ValidationError[] | null | undefined): Validator;
|
|
70
|
-
/**
|
|
71
|
-
* A built-in validator that reports any cycles found in the graph.
|
|
72
|
-
*/
|
|
73
|
-
declare const checkForCycles: Validator;
|
|
74
|
-
|
|
75
|
-
export { type GraphAnalysis, type ValidationError, type Validator, analyzeGraph, checkForCycles, createNodeRule, isNodeType };
|