@wundr.io/langgraph-orchestrator 1.0.3
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 +842 -0
- package/dist/checkpointing.d.ts +265 -0
- package/dist/checkpointing.d.ts.map +1 -0
- package/dist/checkpointing.js +577 -0
- package/dist/checkpointing.js.map +1 -0
- package/dist/edges/conditional-edge.d.ts +230 -0
- package/dist/edges/conditional-edge.d.ts.map +1 -0
- package/dist/edges/conditional-edge.js +439 -0
- package/dist/edges/conditional-edge.js.map +1 -0
- package/dist/edges/loop-edge.d.ts +290 -0
- package/dist/edges/loop-edge.d.ts.map +1 -0
- package/dist/edges/loop-edge.js +503 -0
- package/dist/edges/loop-edge.js.map +1 -0
- package/dist/index.d.ts +125 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +269 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/decision-node.d.ts +276 -0
- package/dist/nodes/decision-node.d.ts.map +1 -0
- package/dist/nodes/decision-node.js +403 -0
- package/dist/nodes/decision-node.js.map +1 -0
- package/dist/nodes/human-node.d.ts +272 -0
- package/dist/nodes/human-node.d.ts.map +1 -0
- package/dist/nodes/human-node.js +394 -0
- package/dist/nodes/human-node.js.map +1 -0
- package/dist/nodes/llm-node.d.ts +173 -0
- package/dist/nodes/llm-node.d.ts.map +1 -0
- package/dist/nodes/llm-node.js +325 -0
- package/dist/nodes/llm-node.js.map +1 -0
- package/dist/nodes/tool-node.d.ts +151 -0
- package/dist/nodes/tool-node.d.ts.map +1 -0
- package/dist/nodes/tool-node.js +373 -0
- package/dist/nodes/tool-node.js.map +1 -0
- package/dist/prebuilt-graphs/plan-execute-refine.d.ts +149 -0
- package/dist/prebuilt-graphs/plan-execute-refine.d.ts.map +1 -0
- package/dist/prebuilt-graphs/plan-execute-refine.js +600 -0
- package/dist/prebuilt-graphs/plan-execute-refine.js.map +1 -0
- package/dist/state-graph.d.ts +158 -0
- package/dist/state-graph.d.ts.map +1 -0
- package/dist/state-graph.js +756 -0
- package/dist/state-graph.js.map +1 -0
- package/dist/types.d.ts +762 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +73 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/src/checkpointing.ts +702 -0
- package/src/edges/conditional-edge.ts +518 -0
- package/src/edges/loop-edge.ts +623 -0
- package/src/index.ts +416 -0
- package/src/nodes/decision-node.ts +538 -0
- package/src/nodes/human-node.ts +572 -0
- package/src/nodes/llm-node.ts +448 -0
- package/src/nodes/tool-node.ts +525 -0
- package/src/prebuilt-graphs/plan-execute-refine.ts +769 -0
- package/src/state-graph.ts +990 -0
- package/src/types.ts +729 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StateGraph - Core class for defining workflow graphs with nodes and edges
|
|
3
|
+
* @module @wundr.io/langgraph-orchestrator
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'eventemitter3';
|
|
6
|
+
import type { AgentState, GraphConfig, GraphGlobalConfig, NodeDefinition, EdgeCondition, ExecutionOptions, ExecutionResult, NodeResult, NodeServices, Checkpoint, WorkflowError, GraphCheckpointer } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Events emitted by StateGraph
|
|
9
|
+
*/
|
|
10
|
+
export interface StateGraphEvents {
|
|
11
|
+
'execution:start': (state: AgentState) => void;
|
|
12
|
+
'execution:complete': (result: ExecutionResult) => void;
|
|
13
|
+
'execution:error': (error: WorkflowError) => void;
|
|
14
|
+
'node:enter': (nodeName: string, state: AgentState) => void;
|
|
15
|
+
'node:exit': (nodeName: string, result: NodeResult) => void;
|
|
16
|
+
'checkpoint:created': (checkpoint: Checkpoint) => void;
|
|
17
|
+
'state:updated': (state: AgentState) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* StateGraph class for defining and executing workflow graphs
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const graph = new StateGraph('my-workflow')
|
|
25
|
+
* .addNode('start', {
|
|
26
|
+
* id: 'start',
|
|
27
|
+
* name: 'Start Node',
|
|
28
|
+
* type: 'start',
|
|
29
|
+
* config: {},
|
|
30
|
+
* execute: async (state) => ({ state, next: 'process' })
|
|
31
|
+
* })
|
|
32
|
+
* .addNode('process', {
|
|
33
|
+
* id: 'process',
|
|
34
|
+
* name: 'Process Node',
|
|
35
|
+
* type: 'transform',
|
|
36
|
+
* config: {},
|
|
37
|
+
* execute: async (state) => ({ state, next: 'end' })
|
|
38
|
+
* })
|
|
39
|
+
* .addEdge('start', 'process')
|
|
40
|
+
* .setEntryPoint('start');
|
|
41
|
+
*
|
|
42
|
+
* const result = await graph.execute();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class StateGraph<TState extends AgentState = AgentState> extends EventEmitter<StateGraphEvents> {
|
|
46
|
+
private readonly id;
|
|
47
|
+
private readonly name;
|
|
48
|
+
private readonly description?;
|
|
49
|
+
private readonly nodes;
|
|
50
|
+
private readonly edges;
|
|
51
|
+
private entryPoint?;
|
|
52
|
+
private config;
|
|
53
|
+
private _checkpointer?;
|
|
54
|
+
private services;
|
|
55
|
+
private logger;
|
|
56
|
+
/** Get the checkpointer */
|
|
57
|
+
get checkpointer(): GraphCheckpointer | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new StateGraph
|
|
60
|
+
* @param name - Human-readable name for the graph
|
|
61
|
+
* @param config - Optional configuration overrides
|
|
62
|
+
*/
|
|
63
|
+
constructor(name: string, config?: Partial<GraphGlobalConfig>);
|
|
64
|
+
/**
|
|
65
|
+
* Add a node to the graph
|
|
66
|
+
* @param name - Unique name for the node
|
|
67
|
+
* @param definition - Node definition
|
|
68
|
+
* @returns this for chaining
|
|
69
|
+
*/
|
|
70
|
+
addNode(name: string, definition: NodeDefinition<TState>): this;
|
|
71
|
+
/**
|
|
72
|
+
* Add a direct edge between nodes
|
|
73
|
+
* @param from - Source node name
|
|
74
|
+
* @param to - Target node name
|
|
75
|
+
* @returns this for chaining
|
|
76
|
+
*/
|
|
77
|
+
addEdge(from: string, to: string): this;
|
|
78
|
+
/**
|
|
79
|
+
* Add a conditional edge
|
|
80
|
+
* @param from - Source node name
|
|
81
|
+
* @param to - Target node name
|
|
82
|
+
* @param condition - Condition for traversal
|
|
83
|
+
* @returns this for chaining
|
|
84
|
+
*/
|
|
85
|
+
addConditionalEdge(from: string, to: string, condition: EdgeCondition): this;
|
|
86
|
+
/**
|
|
87
|
+
* Add a loop edge that can cycle back
|
|
88
|
+
* @param from - Source node name
|
|
89
|
+
* @param to - Target node name (can be same as from)
|
|
90
|
+
* @param condition - Condition to continue looping
|
|
91
|
+
* @returns this for chaining
|
|
92
|
+
*/
|
|
93
|
+
addLoopEdge(from: string, to: string, condition: EdgeCondition): this;
|
|
94
|
+
/**
|
|
95
|
+
* Add parallel edges to multiple targets
|
|
96
|
+
* @param from - Source node name
|
|
97
|
+
* @param targets - Target node names
|
|
98
|
+
* @returns this for chaining
|
|
99
|
+
*/
|
|
100
|
+
addParallelEdges(from: string, targets: string[]): this;
|
|
101
|
+
/**
|
|
102
|
+
* Set the entry point node
|
|
103
|
+
* @param nodeName - Name of the entry point node
|
|
104
|
+
* @returns this for chaining
|
|
105
|
+
*/
|
|
106
|
+
setEntryPoint(nodeName: string): this;
|
|
107
|
+
/**
|
|
108
|
+
* Set the checkpointer for state persistence
|
|
109
|
+
* @param checkpointer - Checkpointer implementation
|
|
110
|
+
* @returns this for chaining
|
|
111
|
+
*/
|
|
112
|
+
setCheckpointer(checkpointer: GraphCheckpointer): this;
|
|
113
|
+
/**
|
|
114
|
+
* Set services available to nodes
|
|
115
|
+
* @param services - Services to provide
|
|
116
|
+
* @returns this for chaining
|
|
117
|
+
*/
|
|
118
|
+
setServices(services: Partial<NodeServices>): this;
|
|
119
|
+
/**
|
|
120
|
+
* Get the graph configuration
|
|
121
|
+
* @returns GraphConfig object
|
|
122
|
+
*/
|
|
123
|
+
getConfig(): GraphConfig;
|
|
124
|
+
/**
|
|
125
|
+
* Execute the graph
|
|
126
|
+
* @param options - Execution options
|
|
127
|
+
* @returns Execution result
|
|
128
|
+
*/
|
|
129
|
+
execute(options?: ExecutionOptions): Promise<ExecutionResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Compile the graph into an executable form
|
|
132
|
+
* @returns Compiled graph configuration
|
|
133
|
+
*/
|
|
134
|
+
compile(): GraphConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Create a subgraph from a subset of nodes
|
|
137
|
+
* @param nodeNames - Names of nodes to include
|
|
138
|
+
* @returns New StateGraph containing the subgraph
|
|
139
|
+
*/
|
|
140
|
+
subgraph(nodeNames: string[]): StateGraph<TState>;
|
|
141
|
+
private validateNodeExists;
|
|
142
|
+
private validateGraph;
|
|
143
|
+
private initializeState;
|
|
144
|
+
private getNodeFromCheckpoint;
|
|
145
|
+
private executeNodeWithRetry;
|
|
146
|
+
private updateStateWithHistory;
|
|
147
|
+
private computeStateChanges;
|
|
148
|
+
private determineNextNode;
|
|
149
|
+
private evaluateEdgeCondition;
|
|
150
|
+
private getFieldValue;
|
|
151
|
+
private createCheckpoint;
|
|
152
|
+
private createError;
|
|
153
|
+
private normalizeError;
|
|
154
|
+
private isWorkflowError;
|
|
155
|
+
private getRecoveryHints;
|
|
156
|
+
private sleep;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=state-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-graph.d.ts","sourceRoot":"","sources":["../src/state-graph.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EAEd,aAAa,EACb,gBAAgB,EAChB,eAAe,EAGf,UAAU,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EAKb,iBAAiB,EAClB,MAAM,SAAS,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