@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.
Files changed (57) hide show
  1. package/README.md +842 -0
  2. package/dist/checkpointing.d.ts +265 -0
  3. package/dist/checkpointing.d.ts.map +1 -0
  4. package/dist/checkpointing.js +577 -0
  5. package/dist/checkpointing.js.map +1 -0
  6. package/dist/edges/conditional-edge.d.ts +230 -0
  7. package/dist/edges/conditional-edge.d.ts.map +1 -0
  8. package/dist/edges/conditional-edge.js +439 -0
  9. package/dist/edges/conditional-edge.js.map +1 -0
  10. package/dist/edges/loop-edge.d.ts +290 -0
  11. package/dist/edges/loop-edge.d.ts.map +1 -0
  12. package/dist/edges/loop-edge.js +503 -0
  13. package/dist/edges/loop-edge.js.map +1 -0
  14. package/dist/index.d.ts +125 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +269 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/nodes/decision-node.d.ts +276 -0
  19. package/dist/nodes/decision-node.d.ts.map +1 -0
  20. package/dist/nodes/decision-node.js +403 -0
  21. package/dist/nodes/decision-node.js.map +1 -0
  22. package/dist/nodes/human-node.d.ts +272 -0
  23. package/dist/nodes/human-node.d.ts.map +1 -0
  24. package/dist/nodes/human-node.js +394 -0
  25. package/dist/nodes/human-node.js.map +1 -0
  26. package/dist/nodes/llm-node.d.ts +173 -0
  27. package/dist/nodes/llm-node.d.ts.map +1 -0
  28. package/dist/nodes/llm-node.js +325 -0
  29. package/dist/nodes/llm-node.js.map +1 -0
  30. package/dist/nodes/tool-node.d.ts +151 -0
  31. package/dist/nodes/tool-node.d.ts.map +1 -0
  32. package/dist/nodes/tool-node.js +373 -0
  33. package/dist/nodes/tool-node.js.map +1 -0
  34. package/dist/prebuilt-graphs/plan-execute-refine.d.ts +149 -0
  35. package/dist/prebuilt-graphs/plan-execute-refine.d.ts.map +1 -0
  36. package/dist/prebuilt-graphs/plan-execute-refine.js +600 -0
  37. package/dist/prebuilt-graphs/plan-execute-refine.js.map +1 -0
  38. package/dist/state-graph.d.ts +158 -0
  39. package/dist/state-graph.d.ts.map +1 -0
  40. package/dist/state-graph.js +756 -0
  41. package/dist/state-graph.js.map +1 -0
  42. package/dist/types.d.ts +762 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/types.js +73 -0
  45. package/dist/types.js.map +1 -0
  46. package/package.json +57 -0
  47. package/src/checkpointing.ts +702 -0
  48. package/src/edges/conditional-edge.ts +518 -0
  49. package/src/edges/loop-edge.ts +623 -0
  50. package/src/index.ts +416 -0
  51. package/src/nodes/decision-node.ts +538 -0
  52. package/src/nodes/human-node.ts +572 -0
  53. package/src/nodes/llm-node.ts +448 -0
  54. package/src/nodes/tool-node.ts +525 -0
  55. package/src/prebuilt-graphs/plan-execute-refine.ts +769 -0
  56. package/src/state-graph.ts +990 -0
  57. package/src/types.ts +729 -0
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Loop Edge - Cyclic edges for iterative workflows
3
+ * @module @wundr.io/langgraph-orchestrator
4
+ */
5
+ import { z } from 'zod';
6
+ import type { AgentState, EdgeDefinition, EdgeCondition, EdgeConditionEvaluator } from '../types';
7
+ /**
8
+ * Configuration for loop behavior
9
+ */
10
+ export interface LoopConfig {
11
+ /** Maximum number of iterations */
12
+ readonly maxIterations?: number;
13
+ /** Counter field in state.data */
14
+ readonly counterField?: string;
15
+ /** Condition to continue looping */
16
+ readonly condition: EdgeCondition;
17
+ /** What to do when max iterations reached */
18
+ readonly onMaxIterations?: 'error' | 'exit' | 'force-exit';
19
+ /** Exit node when loop completes */
20
+ readonly exitNode?: string;
21
+ }
22
+ /**
23
+ * Builder for loop edges with fluent API
24
+ */
25
+ export declare class LoopEdgeBuilder<TState extends AgentState = AgentState> {
26
+ private readonly from;
27
+ private readonly to;
28
+ private maxIterations;
29
+ private counterField;
30
+ private condition?;
31
+ private exitNode?;
32
+ private onMaxIterations;
33
+ /**
34
+ * Create a new loop edge builder
35
+ * @param from - Source node name
36
+ * @param to - Target node name (can be same as from for self-loop)
37
+ */
38
+ constructor(from: string, to?: string);
39
+ /**
40
+ * Set maximum iterations
41
+ * @param max - Maximum number of loop iterations
42
+ * @returns this for chaining
43
+ */
44
+ maxIter(max: number): this;
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: string): this;
51
+ /**
52
+ * Set condition to continue looping
53
+ * @param condition - Condition that must be true to continue
54
+ * @returns this for chaining
55
+ */
56
+ while(condition: EdgeCondition): this;
57
+ /**
58
+ * Continue while field equals value
59
+ * @param field - Field to check
60
+ * @param value - Expected value
61
+ * @returns this for chaining
62
+ */
63
+ whileEquals(field: string, value: unknown): this;
64
+ /**
65
+ * Continue while field is less than value
66
+ * @param field - Field to check
67
+ * @param value - Maximum value
68
+ * @returns this for chaining
69
+ */
70
+ whileLessThan(field: string, value: number): this;
71
+ /**
72
+ * Continue while custom condition is true
73
+ * @param evaluate - Custom evaluator function
74
+ * @returns this for chaining
75
+ */
76
+ whileCustom(evaluate: EdgeConditionEvaluator<TState>): this;
77
+ /**
78
+ * Set the exit node when loop completes
79
+ * @param node - Node to transition to after loop
80
+ * @returns this for chaining
81
+ */
82
+ exitTo(node: string): this;
83
+ /**
84
+ * Set behavior when max iterations reached
85
+ * @param behavior - What to do on max iterations
86
+ * @returns this for chaining
87
+ */
88
+ onMax(behavior: 'error' | 'exit' | 'force-exit'): this;
89
+ /**
90
+ * Build the loop edge configuration
91
+ * @returns LoopConfig object
92
+ */
93
+ build(): LoopConfig;
94
+ /**
95
+ * Build as EdgeDefinition
96
+ * @returns EdgeDefinition for the loop
97
+ */
98
+ buildEdge(): EdgeDefinition;
99
+ /**
100
+ * Create the composite loop condition
101
+ */
102
+ private createLoopCondition;
103
+ }
104
+ /**
105
+ * Create a loop edge builder
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const loopEdge = loopEdge('process')
110
+ * .maxIter(10)
111
+ * .whileLessThan('data.retryCount', 3)
112
+ * .exitTo('success')
113
+ * .onMax('exit')
114
+ * .buildEdge();
115
+ *
116
+ * graph.addLoopEdge(loopEdge.from, loopEdge.to, loopEdge.condition!);
117
+ * ```
118
+ *
119
+ * @param from - Source node name
120
+ * @param to - Optional target node (defaults to from for self-loop)
121
+ * @returns LoopEdgeBuilder
122
+ */
123
+ export declare function loopEdge<TState extends AgentState = AgentState>(from: string, to?: string): LoopEdgeBuilder<TState>;
124
+ /**
125
+ * Create a for-loop style edge
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const forLoop = createForLoop({
130
+ * from: 'process-item',
131
+ * iterations: 5,
132
+ * counterField: 'data.itemIndex',
133
+ * exitNode: 'complete'
134
+ * });
135
+ * ```
136
+ *
137
+ * @param options - For loop configuration
138
+ * @returns EdgeDefinition for the loop
139
+ */
140
+ export declare function createForLoop(options: {
141
+ from: string;
142
+ to?: string;
143
+ iterations: number;
144
+ counterField?: string;
145
+ exitNode?: string;
146
+ }): EdgeDefinition;
147
+ /**
148
+ * Create a while-loop style edge
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const whileLoop = createWhileLoop({
153
+ * from: 'check',
154
+ * to: 'process',
155
+ * condition: conditions.lessThan('data.errorCount', 5),
156
+ * exitNode: 'done',
157
+ * maxIterations: 100
158
+ * });
159
+ * ```
160
+ *
161
+ * @param options - While loop configuration
162
+ * @returns EdgeDefinition for the loop
163
+ */
164
+ export declare function createWhileLoop(options: {
165
+ from: string;
166
+ to?: string;
167
+ condition: EdgeCondition;
168
+ exitNode?: string;
169
+ maxIterations?: number;
170
+ }): EdgeDefinition;
171
+ /**
172
+ * Create a do-while loop (executes at least once)
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const doWhileLoop = createDoWhileLoop({
177
+ * from: 'retry',
178
+ * condition: conditions.equals('data.success', false),
179
+ * exitNode: 'complete',
180
+ * maxIterations: 5
181
+ * });
182
+ * ```
183
+ *
184
+ * @param options - Do-while loop configuration
185
+ * @returns EdgeDefinition for the loop
186
+ */
187
+ export declare function createDoWhileLoop(options: {
188
+ from: string;
189
+ to?: string;
190
+ condition: EdgeCondition;
191
+ exitNode?: string;
192
+ maxIterations?: number;
193
+ }): EdgeDefinition;
194
+ /**
195
+ * Create a retry loop with exponential backoff
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const retryLoop = createRetryLoop({
200
+ * from: 'api-call',
201
+ * maxRetries: 3,
202
+ * exitOnSuccess: 'process-result',
203
+ * exitOnFailure: 'handle-error',
204
+ * successCondition: conditions.equals('data.success', true)
205
+ * });
206
+ * ```
207
+ *
208
+ * @param options - Retry loop configuration
209
+ * @returns EdgeDefinition for the loop
210
+ */
211
+ export declare function createRetryLoop(options: {
212
+ from: string;
213
+ to?: string;
214
+ maxRetries: number;
215
+ retryCountField?: string;
216
+ successCondition: EdgeCondition;
217
+ exitOnSuccess?: string;
218
+ exitOnFailure?: string;
219
+ }): EdgeDefinition;
220
+ /**
221
+ * Create a pagination loop for iterating through paged data
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const paginationLoop = createPaginationLoop({
226
+ * from: 'fetch-page',
227
+ * pageField: 'data.currentPage',
228
+ * hasMoreField: 'data.hasMore',
229
+ * exitNode: 'process-all'
230
+ * });
231
+ * ```
232
+ *
233
+ * @param options - Pagination loop configuration
234
+ * @returns EdgeDefinition for the loop
235
+ */
236
+ export declare function createPaginationLoop(options: {
237
+ from: string;
238
+ to?: string;
239
+ pageField?: string;
240
+ hasMoreField: string;
241
+ maxPages?: number;
242
+ exitNode?: string;
243
+ }): EdgeDefinition;
244
+ /**
245
+ * Schema for loop configuration validation
246
+ */
247
+ export declare const LoopConfigSchema: z.ZodObject<{
248
+ maxIterations: z.ZodOptional<z.ZodNumber>;
249
+ counterField: z.ZodOptional<z.ZodString>;
250
+ condition: z.ZodObject<{
251
+ type: z.ZodEnum<["equals", "not_equals", "contains", "greater_than", "less_than", "exists", "not_exists", "custom"]>;
252
+ field: z.ZodOptional<z.ZodString>;
253
+ value: z.ZodOptional<z.ZodUnknown>;
254
+ }, "strip", z.ZodTypeAny, {
255
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
256
+ value?: unknown;
257
+ field?: string | undefined;
258
+ }, {
259
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
260
+ value?: unknown;
261
+ field?: string | undefined;
262
+ }>;
263
+ onMaxIterations: z.ZodOptional<z.ZodEnum<["error", "exit", "force-exit"]>>;
264
+ exitNode: z.ZodOptional<z.ZodString>;
265
+ }, "strip", z.ZodTypeAny, {
266
+ condition: {
267
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
268
+ value?: unknown;
269
+ field?: string | undefined;
270
+ };
271
+ maxIterations?: number | undefined;
272
+ counterField?: string | undefined;
273
+ onMaxIterations?: "error" | "exit" | "force-exit" | undefined;
274
+ exitNode?: string | undefined;
275
+ }, {
276
+ condition: {
277
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
278
+ value?: unknown;
279
+ field?: string | undefined;
280
+ };
281
+ maxIterations?: number | undefined;
282
+ counterField?: string | undefined;
283
+ onMaxIterations?: "error" | "exit" | "force-exit" | undefined;
284
+ exitNode?: string | undefined;
285
+ }>;
286
+ /**
287
+ * Validate a loop configuration
288
+ */
289
+ export declare function validateLoopConfig(config: LoopConfig): boolean;
290
+ //# sourceMappingURL=loop-edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop-edge.d.ts","sourceRoot":"","sources":["../../src/edges/loop-edge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,aAAa,EACb,sBAAsB,EAEvB,MAAM,UAAU,CAAC;AAElB;;GAEG;A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