@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,503 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Loop Edge - Cyclic edges for iterative workflows
|
|
4
|
+
* @module @wundr.io/langgraph-orchestrator
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LoopConfigSchema = exports.LoopEdgeBuilder = void 0;
|
|
8
|
+
exports.loopEdge = loopEdge;
|
|
9
|
+
exports.createForLoop = createForLoop;
|
|
10
|
+
exports.createWhileLoop = createWhileLoop;
|
|
11
|
+
exports.createDoWhileLoop = createDoWhileLoop;
|
|
12
|
+
exports.createRetryLoop = createRetryLoop;
|
|
13
|
+
exports.createPaginationLoop = createPaginationLoop;
|
|
14
|
+
exports.validateLoopConfig = validateLoopConfig;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
/**
|
|
17
|
+
* Builder for loop edges with fluent API
|
|
18
|
+
*/
|
|
19
|
+
class LoopEdgeBuilder {
|
|
20
|
+
from;
|
|
21
|
+
to;
|
|
22
|
+
maxIterations = 100;
|
|
23
|
+
counterField = '__loopCounter';
|
|
24
|
+
condition;
|
|
25
|
+
exitNode;
|
|
26
|
+
onMaxIterations = 'exit';
|
|
27
|
+
/**
|
|
28
|
+
* Create a new loop edge builder
|
|
29
|
+
* @param from - Source node name
|
|
30
|
+
* @param to - Target node name (can be same as from for self-loop)
|
|
31
|
+
*/
|
|
32
|
+
constructor(from, to) {
|
|
33
|
+
this.from = from;
|
|
34
|
+
this.to = to ?? from; // Default to self-loop
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Set maximum iterations
|
|
38
|
+
* @param max - Maximum number of loop iterations
|
|
39
|
+
* @returns this for chaining
|
|
40
|
+
*/
|
|
41
|
+
maxIter(max) {
|
|
42
|
+
this.maxIterations = max;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set the counter field name in state
|
|
47
|
+
* @param field - Field name for storing iteration count
|
|
48
|
+
* @returns this for chaining
|
|
49
|
+
*/
|
|
50
|
+
counter(field) {
|
|
51
|
+
this.counterField = field;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Set condition to continue looping
|
|
56
|
+
* @param condition - Condition that must be true to continue
|
|
57
|
+
* @returns this for chaining
|
|
58
|
+
*/
|
|
59
|
+
while(condition) {
|
|
60
|
+
this.condition = condition;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Continue while field equals value
|
|
65
|
+
* @param field - Field to check
|
|
66
|
+
* @param value - Expected value
|
|
67
|
+
* @returns this for chaining
|
|
68
|
+
*/
|
|
69
|
+
whileEquals(field, value) {
|
|
70
|
+
return this.while({ type: 'equals', field, value });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Continue while field is less than value
|
|
74
|
+
* @param field - Field to check
|
|
75
|
+
* @param value - Maximum value
|
|
76
|
+
* @returns this for chaining
|
|
77
|
+
*/
|
|
78
|
+
whileLessThan(field, value) {
|
|
79
|
+
return this.while({ type: 'less_than', field, value });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Continue while custom condition is true
|
|
83
|
+
* @param evaluate - Custom evaluator function
|
|
84
|
+
* @returns this for chaining
|
|
85
|
+
*/
|
|
86
|
+
whileCustom(evaluate) {
|
|
87
|
+
return this.while({
|
|
88
|
+
type: 'custom',
|
|
89
|
+
evaluate: evaluate,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Set the exit node when loop completes
|
|
94
|
+
* @param node - Node to transition to after loop
|
|
95
|
+
* @returns this for chaining
|
|
96
|
+
*/
|
|
97
|
+
exitTo(node) {
|
|
98
|
+
this.exitNode = node;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Set behavior when max iterations reached
|
|
103
|
+
* @param behavior - What to do on max iterations
|
|
104
|
+
* @returns this for chaining
|
|
105
|
+
*/
|
|
106
|
+
onMax(behavior) {
|
|
107
|
+
this.onMaxIterations = behavior;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Build the loop edge configuration
|
|
112
|
+
* @returns LoopConfig object
|
|
113
|
+
*/
|
|
114
|
+
build() {
|
|
115
|
+
if (!this.condition) {
|
|
116
|
+
throw new Error('Loop condition is required. Call while() before build()');
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
maxIterations: this.maxIterations,
|
|
120
|
+
counterField: this.counterField,
|
|
121
|
+
condition: this.condition,
|
|
122
|
+
onMaxIterations: this.onMaxIterations,
|
|
123
|
+
exitNode: this.exitNode,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Build as EdgeDefinition
|
|
128
|
+
* @returns EdgeDefinition for the loop
|
|
129
|
+
*/
|
|
130
|
+
buildEdge() {
|
|
131
|
+
if (!this.condition) {
|
|
132
|
+
throw new Error('Loop condition is required. Call while() before buildEdge()');
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
from: this.from,
|
|
136
|
+
to: this.to,
|
|
137
|
+
type: 'loop',
|
|
138
|
+
condition: this.createLoopCondition(),
|
|
139
|
+
metadata: {
|
|
140
|
+
maxIterations: this.maxIterations,
|
|
141
|
+
counterField: this.counterField,
|
|
142
|
+
onMaxIterations: this.onMaxIterations,
|
|
143
|
+
exitNode: this.exitNode,
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create the composite loop condition
|
|
149
|
+
*/
|
|
150
|
+
createLoopCondition() {
|
|
151
|
+
const originalCondition = this.condition;
|
|
152
|
+
const maxIterations = this.maxIterations;
|
|
153
|
+
const counterField = this.counterField;
|
|
154
|
+
const onMaxIterations = this.onMaxIterations;
|
|
155
|
+
return {
|
|
156
|
+
type: 'custom',
|
|
157
|
+
evaluate: async (state, context) => {
|
|
158
|
+
// Get current iteration count
|
|
159
|
+
const currentCount = state.data[counterField] ?? 0;
|
|
160
|
+
// Check max iterations
|
|
161
|
+
if (currentCount >= maxIterations) {
|
|
162
|
+
if (onMaxIterations === 'error') {
|
|
163
|
+
throw new Error(`Loop exceeded maximum iterations (${maxIterations})`);
|
|
164
|
+
}
|
|
165
|
+
return false; // Exit loop
|
|
166
|
+
}
|
|
167
|
+
// Evaluate the actual condition
|
|
168
|
+
return await evaluateCondition(originalCondition, state, context);
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.LoopEdgeBuilder = LoopEdgeBuilder;
|
|
174
|
+
/**
|
|
175
|
+
* Create a loop edge builder
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const loopEdge = loopEdge('process')
|
|
180
|
+
* .maxIter(10)
|
|
181
|
+
* .whileLessThan('data.retryCount', 3)
|
|
182
|
+
* .exitTo('success')
|
|
183
|
+
* .onMax('exit')
|
|
184
|
+
* .buildEdge();
|
|
185
|
+
*
|
|
186
|
+
* graph.addLoopEdge(loopEdge.from, loopEdge.to, loopEdge.condition!);
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @param from - Source node name
|
|
190
|
+
* @param to - Optional target node (defaults to from for self-loop)
|
|
191
|
+
* @returns LoopEdgeBuilder
|
|
192
|
+
*/
|
|
193
|
+
function loopEdge(from, to) {
|
|
194
|
+
return new LoopEdgeBuilder(from, to);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Create a for-loop style edge
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const forLoop = createForLoop({
|
|
202
|
+
* from: 'process-item',
|
|
203
|
+
* iterations: 5,
|
|
204
|
+
* counterField: 'data.itemIndex',
|
|
205
|
+
* exitNode: 'complete'
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @param options - For loop configuration
|
|
210
|
+
* @returns EdgeDefinition for the loop
|
|
211
|
+
*/
|
|
212
|
+
function createForLoop(options) {
|
|
213
|
+
const counterField = options.counterField ?? '__forLoopCounter';
|
|
214
|
+
return {
|
|
215
|
+
from: options.from,
|
|
216
|
+
to: options.to ?? options.from,
|
|
217
|
+
type: 'loop',
|
|
218
|
+
condition: {
|
|
219
|
+
type: 'custom',
|
|
220
|
+
evaluate: async (state) => {
|
|
221
|
+
const current = state.data[counterField] ?? 0;
|
|
222
|
+
return current < options.iterations;
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
metadata: {
|
|
226
|
+
loopType: 'for',
|
|
227
|
+
iterations: options.iterations,
|
|
228
|
+
counterField,
|
|
229
|
+
exitNode: options.exitNode,
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Create a while-loop style edge
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const whileLoop = createWhileLoop({
|
|
239
|
+
* from: 'check',
|
|
240
|
+
* to: 'process',
|
|
241
|
+
* condition: conditions.lessThan('data.errorCount', 5),
|
|
242
|
+
* exitNode: 'done',
|
|
243
|
+
* maxIterations: 100
|
|
244
|
+
* });
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @param options - While loop configuration
|
|
248
|
+
* @returns EdgeDefinition for the loop
|
|
249
|
+
*/
|
|
250
|
+
function createWhileLoop(options) {
|
|
251
|
+
const maxIterations = options.maxIterations ?? 1000;
|
|
252
|
+
return {
|
|
253
|
+
from: options.from,
|
|
254
|
+
to: options.to ?? options.from,
|
|
255
|
+
type: 'loop',
|
|
256
|
+
condition: {
|
|
257
|
+
type: 'custom',
|
|
258
|
+
evaluate: async (state, context) => {
|
|
259
|
+
// Check iteration guard
|
|
260
|
+
const iterations = context.graph?.config?.maxIterations ?? maxIterations;
|
|
261
|
+
if (state.metadata.stepCount >= iterations) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
return await evaluateCondition(options.condition, state, context);
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
metadata: {
|
|
268
|
+
loopType: 'while',
|
|
269
|
+
exitNode: options.exitNode,
|
|
270
|
+
maxIterations,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Create a do-while loop (executes at least once)
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const doWhileLoop = createDoWhileLoop({
|
|
280
|
+
* from: 'retry',
|
|
281
|
+
* condition: conditions.equals('data.success', false),
|
|
282
|
+
* exitNode: 'complete',
|
|
283
|
+
* maxIterations: 5
|
|
284
|
+
* });
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @param options - Do-while loop configuration
|
|
288
|
+
* @returns EdgeDefinition for the loop
|
|
289
|
+
*/
|
|
290
|
+
function createDoWhileLoop(options) {
|
|
291
|
+
const maxIterations = options.maxIterations ?? 1000;
|
|
292
|
+
return {
|
|
293
|
+
from: options.from,
|
|
294
|
+
to: options.to ?? options.from,
|
|
295
|
+
type: 'loop',
|
|
296
|
+
condition: {
|
|
297
|
+
type: 'custom',
|
|
298
|
+
evaluate: async (state, context) => {
|
|
299
|
+
// Check iteration guard
|
|
300
|
+
const iterations = context.graph?.config?.maxIterations ?? maxIterations;
|
|
301
|
+
if (state.metadata.stepCount >= iterations) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
// First iteration always executes (check if this is first time through)
|
|
305
|
+
const loopCount = state.data['__doWhileCount'] ?? 0;
|
|
306
|
+
if (loopCount === 0) {
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
return await evaluateCondition(options.condition, state, context);
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
metadata: {
|
|
313
|
+
loopType: 'do-while',
|
|
314
|
+
exitNode: options.exitNode,
|
|
315
|
+
maxIterations,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Create a retry loop with exponential backoff
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* const retryLoop = createRetryLoop({
|
|
325
|
+
* from: 'api-call',
|
|
326
|
+
* maxRetries: 3,
|
|
327
|
+
* exitOnSuccess: 'process-result',
|
|
328
|
+
* exitOnFailure: 'handle-error',
|
|
329
|
+
* successCondition: conditions.equals('data.success', true)
|
|
330
|
+
* });
|
|
331
|
+
* ```
|
|
332
|
+
*
|
|
333
|
+
* @param options - Retry loop configuration
|
|
334
|
+
* @returns EdgeDefinition for the loop
|
|
335
|
+
*/
|
|
336
|
+
function createRetryLoop(options) {
|
|
337
|
+
const retryCountField = options.retryCountField ?? '__retryCount';
|
|
338
|
+
return {
|
|
339
|
+
from: options.from,
|
|
340
|
+
to: options.to ?? options.from,
|
|
341
|
+
type: 'loop',
|
|
342
|
+
condition: {
|
|
343
|
+
type: 'custom',
|
|
344
|
+
evaluate: async (state, context) => {
|
|
345
|
+
const retryCount = state.data[retryCountField] ?? 0;
|
|
346
|
+
// Check if we've succeeded
|
|
347
|
+
const succeeded = await evaluateCondition(options.successCondition, state, context);
|
|
348
|
+
if (succeeded) {
|
|
349
|
+
return false; // Exit loop to success node
|
|
350
|
+
}
|
|
351
|
+
// Check if we've exhausted retries
|
|
352
|
+
if (retryCount >= options.maxRetries) {
|
|
353
|
+
return false; // Exit loop to failure node
|
|
354
|
+
}
|
|
355
|
+
// Continue retrying
|
|
356
|
+
return true;
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
metadata: {
|
|
360
|
+
loopType: 'retry',
|
|
361
|
+
maxRetries: options.maxRetries,
|
|
362
|
+
retryCountField,
|
|
363
|
+
exitOnSuccess: options.exitOnSuccess,
|
|
364
|
+
exitOnFailure: options.exitOnFailure,
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Create a pagination loop for iterating through paged data
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* const paginationLoop = createPaginationLoop({
|
|
374
|
+
* from: 'fetch-page',
|
|
375
|
+
* pageField: 'data.currentPage',
|
|
376
|
+
* hasMoreField: 'data.hasMore',
|
|
377
|
+
* exitNode: 'process-all'
|
|
378
|
+
* });
|
|
379
|
+
* ```
|
|
380
|
+
*
|
|
381
|
+
* @param options - Pagination loop configuration
|
|
382
|
+
* @returns EdgeDefinition for the loop
|
|
383
|
+
*/
|
|
384
|
+
function createPaginationLoop(options) {
|
|
385
|
+
const pageField = options.pageField ?? '__currentPage';
|
|
386
|
+
const maxPages = options.maxPages ?? 1000;
|
|
387
|
+
return {
|
|
388
|
+
from: options.from,
|
|
389
|
+
to: options.to ?? options.from,
|
|
390
|
+
type: 'loop',
|
|
391
|
+
condition: {
|
|
392
|
+
type: 'custom',
|
|
393
|
+
evaluate: async (state) => {
|
|
394
|
+
const currentPage = state.data[pageField] ?? 0;
|
|
395
|
+
// Check page limit
|
|
396
|
+
if (currentPage >= maxPages) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
// Check if there are more pages
|
|
400
|
+
const hasMore = getFieldValue(state, options.hasMoreField);
|
|
401
|
+
return hasMore === true;
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
metadata: {
|
|
405
|
+
loopType: 'pagination',
|
|
406
|
+
pageField,
|
|
407
|
+
hasMoreField: options.hasMoreField,
|
|
408
|
+
maxPages,
|
|
409
|
+
exitNode: options.exitNode,
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Evaluate a condition against state
|
|
415
|
+
*/
|
|
416
|
+
async function evaluateCondition(condition, state, context) {
|
|
417
|
+
const fieldValue = condition.field
|
|
418
|
+
? getFieldValue(state, condition.field)
|
|
419
|
+
: undefined;
|
|
420
|
+
switch (condition.type) {
|
|
421
|
+
case 'equals':
|
|
422
|
+
return fieldValue === condition.value;
|
|
423
|
+
case 'not_equals':
|
|
424
|
+
return fieldValue !== condition.value;
|
|
425
|
+
case 'contains':
|
|
426
|
+
if (Array.isArray(fieldValue)) {
|
|
427
|
+
return fieldValue.includes(condition.value);
|
|
428
|
+
}
|
|
429
|
+
if (typeof fieldValue === 'string') {
|
|
430
|
+
return fieldValue.includes(String(condition.value));
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
433
|
+
case 'greater_than':
|
|
434
|
+
return (typeof fieldValue === 'number' &&
|
|
435
|
+
typeof condition.value === 'number' &&
|
|
436
|
+
fieldValue > condition.value);
|
|
437
|
+
case 'less_than':
|
|
438
|
+
return (typeof fieldValue === 'number' &&
|
|
439
|
+
typeof condition.value === 'number' &&
|
|
440
|
+
fieldValue < condition.value);
|
|
441
|
+
case 'exists':
|
|
442
|
+
return fieldValue !== undefined && fieldValue !== null;
|
|
443
|
+
case 'not_exists':
|
|
444
|
+
return fieldValue === undefined || fieldValue === null;
|
|
445
|
+
case 'custom':
|
|
446
|
+
if (condition.evaluate) {
|
|
447
|
+
return await condition.evaluate(state, context);
|
|
448
|
+
}
|
|
449
|
+
return false;
|
|
450
|
+
default:
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get a nested field value from state
|
|
456
|
+
*/
|
|
457
|
+
function getFieldValue(state, field) {
|
|
458
|
+
const parts = field.split('.');
|
|
459
|
+
let current = state;
|
|
460
|
+
for (const part of parts) {
|
|
461
|
+
if (current === null || current === undefined) {
|
|
462
|
+
return undefined;
|
|
463
|
+
}
|
|
464
|
+
current = current[part];
|
|
465
|
+
}
|
|
466
|
+
return current;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Schema for loop configuration validation
|
|
470
|
+
*/
|
|
471
|
+
exports.LoopConfigSchema = zod_1.z.object({
|
|
472
|
+
maxIterations: zod_1.z.number().min(1).optional(),
|
|
473
|
+
counterField: zod_1.z.string().optional(),
|
|
474
|
+
condition: zod_1.z.object({
|
|
475
|
+
type: zod_1.z.enum([
|
|
476
|
+
'equals',
|
|
477
|
+
'not_equals',
|
|
478
|
+
'contains',
|
|
479
|
+
'greater_than',
|
|
480
|
+
'less_than',
|
|
481
|
+
'exists',
|
|
482
|
+
'not_exists',
|
|
483
|
+
'custom',
|
|
484
|
+
]),
|
|
485
|
+
field: zod_1.z.string().optional(),
|
|
486
|
+
value: zod_1.z.unknown().optional(),
|
|
487
|
+
}),
|
|
488
|
+
onMaxIterations: zod_1.z.enum(['error', 'exit', 'force-exit']).optional(),
|
|
489
|
+
exitNode: zod_1.z.string().optional(),
|
|
490
|
+
});
|
|
491
|
+
/**
|
|
492
|
+
* Validate a loop configuration
|
|
493
|
+
*/
|
|
494
|
+
function validateLoopConfig(config) {
|
|
495
|
+
try {
|
|
496
|
+
exports.LoopConfigSchema.parse(config);
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
catch {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
//# sourceMappingURL=loop-edge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AAC,IAAI,CAAC;YACX,QAAQ;YACR,YAAY;YACZ,UAAU;YACV,cAAc;YACd,WAAW;YACX,QAAQ;YACR,YAAY;YACZ,QAAQ;SACT,CAAC;QACF,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC5B,KAAK,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;KAC9B,CAAC;IACF,eAAe,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE;IACnE,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEH;;GAEG;AACH,SAAgB,kBAAkB,CAAC,MAAkB;IACnD,IAAI,CAAC;QACH,wBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangGraph Orchestrator - LangGraph-style cyclic, state-driven workflows
|
|
3
|
+
* @module @wundr.io/langgraph-orchestrator
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import {
|
|
8
|
+
* StateGraph,
|
|
9
|
+
* createLLMNode,
|
|
10
|
+
* createToolNode,
|
|
11
|
+
* createDecisionNode,
|
|
12
|
+
* MemoryCheckpointer
|
|
13
|
+
* } from '@wundr.io/langgraph-orchestrator';
|
|
14
|
+
*
|
|
15
|
+
* // Create a workflow graph
|
|
16
|
+
* const graph = new StateGraph('my-workflow')
|
|
17
|
+
* .addNode('agent', createLLMNode({
|
|
18
|
+
* id: 'agent',
|
|
19
|
+
* name: 'Agent',
|
|
20
|
+
* config: { model: 'claude-3-sonnet-20240229' }
|
|
21
|
+
* }))
|
|
22
|
+
* .addNode('tools', createToolNode({
|
|
23
|
+
* id: 'tools',
|
|
24
|
+
* name: 'Tools'
|
|
25
|
+
* }))
|
|
26
|
+
* .addEdge('agent', 'tools')
|
|
27
|
+
* .addConditionalEdge('tools', 'agent', {
|
|
28
|
+
* type: 'exists',
|
|
29
|
+
* field: 'data.pendingToolCalls'
|
|
30
|
+
* })
|
|
31
|
+
* .setEntryPoint('agent')
|
|
32
|
+
* .setCheckpointer(new MemoryCheckpointer());
|
|
33
|
+
*
|
|
34
|
+
* // Execute the workflow
|
|
35
|
+
* const result = await graph.execute({
|
|
36
|
+
* initialState: {
|
|
37
|
+
* data: { task: 'Research AI developments' }
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
import { StateGraph as StateGraphClass } from './state-graph';
|
|
43
|
+
import type { LLMProvider, Tool } from './types';
|
|
44
|
+
export type { AgentState, Message, MessageRole, ToolCall, ToolResult, StateHistoryEntry, StateChange, WorkflowError, StateMetadata, GraphConfig, GraphGlobalConfig, RetryConfig, LogLevel, NodeDefinition, NodeType, NodeConfig, NodeExecutor, NodeContext, NodeServices, NodeResult, NodeExecutionMetadata, NodeHook, Logger, Tool, ToolRegistry, LLMProvider, LLMRequest, LLMResponse, TokenUsage, FinishReason, LLMStreamChunk, EdgeDefinition, EdgeType, EdgeCondition, ConditionType, EdgeConditionEvaluator, EdgeContext, GraphCheckpointer, Checkpoint, CheckpointSummary, ExecutionOptions, ExecutionHandlers, ExecutionResult, ExecutionStats, } from './types';
|
|
45
|
+
export { MessageSchema, GraphConfigSchema, CheckpointSchema } from './types';
|
|
46
|
+
export { StateGraph, StateGraphEvents } from './state-graph';
|
|
47
|
+
export { createLLMNode, createLLMRouter, createStructuredLLMNode, createConversationalLLMNode, LLMNodeConfig, LLMNodeConfigSchema, } from './nodes/llm-node';
|
|
48
|
+
export { createToolNode, createToolRegistry, createTool, createBatchToolNode, ToolNodeConfig, ToolNodeConfigSchema, } from './nodes/tool-node';
|
|
49
|
+
export { createDecisionNode, createSwitchNode, createThresholdNode, createIfElseNode, createMultiConditionNode, DecisionNodeConfig, DecisionBranch, DecisionNodeConfigSchema, } from './nodes/decision-node';
|
|
50
|
+
export { createHumanNode, createConsoleInputHandler, createCallbackInputHandler, createConfirmationNode, createFeedbackNode, HumanNodeConfig, HumanInputHandler, HumanInputContext, HumanChoice, HumanResponse, HumanNodeConfigSchema, } from './nodes/human-node';
|
|
51
|
+
export { ConditionalEdgeBuilder, conditionalEdge, createRouter, conditions, EdgeConditionSchema, validateCondition, } from './edges/conditional-edge';
|
|
52
|
+
export { LoopEdgeBuilder, loopEdge, createForLoop, createWhileLoop, createDoWhileLoop, createRetryLoop, createPaginationLoop, LoopConfig, LoopConfigSchema, validateLoopConfig, } from './edges/loop-edge';
|
|
53
|
+
export { MemoryCheckpointer, FileCheckpointer, TimeTravelDebugger, createCheckpoint, applyRetentionPolicy, validateCheckpoint, FileSystem, StateDiff, StateHistoryItem, RetentionPolicy, CheckpointSchema as CheckpointValidationSchema, } from './checkpointing';
|
|
54
|
+
export { createPlanExecuteRefineGraph, createSimpleTaskGraph, PlanExecuteState, PlanStep, StepResult, PlanExecuteRefineConfig, PlanSchema, } from './prebuilt-graphs/plan-execute-refine';
|
|
55
|
+
/**
|
|
56
|
+
* Create a simple agent workflow
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const graph = createAgentWorkflow({
|
|
61
|
+
* name: 'research-agent',
|
|
62
|
+
* llmProvider: myProvider,
|
|
63
|
+
* tools: [searchTool, writeTool],
|
|
64
|
+
* systemPrompt: 'You are a helpful research assistant.'
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function createAgentWorkflow(options: {
|
|
69
|
+
name: string;
|
|
70
|
+
llmProvider: LLMProvider;
|
|
71
|
+
tools?: Tool[];
|
|
72
|
+
systemPrompt?: string;
|
|
73
|
+
maxIterations?: number;
|
|
74
|
+
}): StateGraphClass;
|
|
75
|
+
/**
|
|
76
|
+
* Create a chat workflow with conversation history
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const chat = createChatWorkflow({
|
|
81
|
+
* name: 'chat-assistant',
|
|
82
|
+
* llmProvider: myProvider,
|
|
83
|
+
* systemPrompt: 'You are a friendly assistant.',
|
|
84
|
+
* maxHistory: 20
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function createChatWorkflow(options: {
|
|
89
|
+
name: string;
|
|
90
|
+
llmProvider: LLMProvider;
|
|
91
|
+
systemPrompt?: string;
|
|
92
|
+
maxHistory?: number;
|
|
93
|
+
}): StateGraphClass;
|
|
94
|
+
/**
|
|
95
|
+
* Create a decision tree workflow
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const tree = createDecisionTree({
|
|
100
|
+
* name: 'support-router',
|
|
101
|
+
* decisions: [
|
|
102
|
+
* {
|
|
103
|
+
* field: 'data.category',
|
|
104
|
+
* branches: {
|
|
105
|
+
* 'billing': 'billing-handler',
|
|
106
|
+
* 'technical': 'tech-handler',
|
|
107
|
+
* 'general': 'general-handler'
|
|
108
|
+
* },
|
|
109
|
+
* default: 'general-handler'
|
|
110
|
+
* }
|
|
111
|
+
* ]
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function createDecisionTree(options: {
|
|
116
|
+
name: string;
|
|
117
|
+
decisions: Array<{
|
|
118
|
+
id?: string;
|
|
119
|
+
field: string;
|
|
120
|
+
branches: Record<string, string>;
|
|
121
|
+
default?: string;
|
|
122
|
+
}>;
|
|
123
|
+
}): StateGraphClass;
|
|
124
|
+
export declare const VERSION = "1.0.3";
|
|
125
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
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