@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,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Decision Node - Conditional branching node for workflow control flow
|
|
4
|
+
* @module @wundr.io/langgraph-orchestrator
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DecisionNodeConfigSchema = void 0;
|
|
8
|
+
exports.createDecisionNode = createDecisionNode;
|
|
9
|
+
exports.createSwitchNode = createSwitchNode;
|
|
10
|
+
exports.createThresholdNode = createThresholdNode;
|
|
11
|
+
exports.createIfElseNode = createIfElseNode;
|
|
12
|
+
exports.createMultiConditionNode = createMultiConditionNode;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
/**
|
|
15
|
+
* Schema for decision node configuration validation
|
|
16
|
+
*/
|
|
17
|
+
exports.DecisionNodeConfigSchema = zod_1.z.object({
|
|
18
|
+
branches: zod_1.z.array(zod_1.z.object({
|
|
19
|
+
name: zod_1.z.string(),
|
|
20
|
+
target: zod_1.z.string(),
|
|
21
|
+
condition: zod_1.z.object({
|
|
22
|
+
type: zod_1.z.enum([
|
|
23
|
+
'equals',
|
|
24
|
+
'not_equals',
|
|
25
|
+
'contains',
|
|
26
|
+
'greater_than',
|
|
27
|
+
'less_than',
|
|
28
|
+
'exists',
|
|
29
|
+
'not_exists',
|
|
30
|
+
'custom',
|
|
31
|
+
]),
|
|
32
|
+
field: zod_1.z.string().optional(),
|
|
33
|
+
value: zod_1.z.unknown().optional(),
|
|
34
|
+
}),
|
|
35
|
+
priority: zod_1.z.number().optional(),
|
|
36
|
+
})),
|
|
37
|
+
defaultBranch: zod_1.z.string().optional(),
|
|
38
|
+
throwOnNoMatch: zod_1.z.boolean().optional(),
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Create a decision node for conditional branching
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const decisionNode = createDecisionNode({
|
|
46
|
+
* id: 'router',
|
|
47
|
+
* name: 'Task Router',
|
|
48
|
+
* config: {
|
|
49
|
+
* branches: [
|
|
50
|
+
* {
|
|
51
|
+
* name: 'search',
|
|
52
|
+
* target: 'search-node',
|
|
53
|
+
* condition: { type: 'equals', field: 'data.action', value: 'search' }
|
|
54
|
+
* },
|
|
55
|
+
* {
|
|
56
|
+
* name: 'answer',
|
|
57
|
+
* target: 'answer-node',
|
|
58
|
+
* condition: { type: 'equals', field: 'data.action', value: 'answer' }
|
|
59
|
+
* }
|
|
60
|
+
* ],
|
|
61
|
+
* defaultBranch: 'fallback-node'
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* graph.addNode('router', decisionNode);
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param options - Node creation options
|
|
69
|
+
* @returns NodeDefinition for use in StateGraph
|
|
70
|
+
*/
|
|
71
|
+
function createDecisionNode(options) {
|
|
72
|
+
const { id, name, config, nodeConfig = {} } = options;
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
name,
|
|
76
|
+
type: 'decision',
|
|
77
|
+
config: nodeConfig,
|
|
78
|
+
execute: async (state, context) => {
|
|
79
|
+
context.services.logger.debug('Evaluating decision branches', {
|
|
80
|
+
branchCount: config.branches.length,
|
|
81
|
+
});
|
|
82
|
+
// If custom decision function provided, use it
|
|
83
|
+
if (config.decide) {
|
|
84
|
+
const target = await config.decide(state);
|
|
85
|
+
context.services.logger.debug('Custom decision made', { target });
|
|
86
|
+
return {
|
|
87
|
+
state,
|
|
88
|
+
next: target,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Sort branches by priority
|
|
92
|
+
const sortedBranches = [...config.branches].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
93
|
+
// Evaluate branches in order
|
|
94
|
+
for (const branch of sortedBranches) {
|
|
95
|
+
const matches = await evaluateCondition(branch.condition, state);
|
|
96
|
+
if (matches) {
|
|
97
|
+
context.services.logger.debug('Branch matched', {
|
|
98
|
+
branch: branch.name,
|
|
99
|
+
target: branch.target,
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
state,
|
|
103
|
+
next: branch.target,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// No branch matched
|
|
108
|
+
if (config.defaultBranch) {
|
|
109
|
+
context.services.logger.debug('Using default branch', {
|
|
110
|
+
target: config.defaultBranch,
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
state,
|
|
114
|
+
next: config.defaultBranch,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (config.throwOnNoMatch) {
|
|
118
|
+
throw new Error('No decision branch matched and no default configured');
|
|
119
|
+
}
|
|
120
|
+
context.services.logger.warn('No decision branch matched, workflow may terminate');
|
|
121
|
+
return { state };
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Evaluate a condition against state
|
|
127
|
+
*/
|
|
128
|
+
async function evaluateCondition(condition, state) {
|
|
129
|
+
const fieldValue = condition.field
|
|
130
|
+
? getFieldValue(state, condition.field)
|
|
131
|
+
: undefined;
|
|
132
|
+
switch (condition.type) {
|
|
133
|
+
case 'equals':
|
|
134
|
+
return fieldValue === condition.value;
|
|
135
|
+
case 'not_equals':
|
|
136
|
+
return fieldValue !== condition.value;
|
|
137
|
+
case 'contains':
|
|
138
|
+
if (Array.isArray(fieldValue)) {
|
|
139
|
+
return fieldValue.includes(condition.value);
|
|
140
|
+
}
|
|
141
|
+
if (typeof fieldValue === 'string') {
|
|
142
|
+
return fieldValue.includes(String(condition.value));
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
case 'greater_than':
|
|
146
|
+
return (typeof fieldValue === 'number' &&
|
|
147
|
+
typeof condition.value === 'number' &&
|
|
148
|
+
fieldValue > condition.value);
|
|
149
|
+
case 'less_than':
|
|
150
|
+
return (typeof fieldValue === 'number' &&
|
|
151
|
+
typeof condition.value === 'number' &&
|
|
152
|
+
fieldValue < condition.value);
|
|
153
|
+
case 'exists':
|
|
154
|
+
return fieldValue !== undefined && fieldValue !== null;
|
|
155
|
+
case 'not_exists':
|
|
156
|
+
return fieldValue === undefined || fieldValue === null;
|
|
157
|
+
case 'custom':
|
|
158
|
+
if (condition.evaluate) {
|
|
159
|
+
return await condition.evaluate(state, {
|
|
160
|
+
edge: { from: '', to: '', type: 'conditional', condition },
|
|
161
|
+
sourceResult: { state },
|
|
162
|
+
graph: {
|
|
163
|
+
id: '',
|
|
164
|
+
name: '',
|
|
165
|
+
entryPoint: '',
|
|
166
|
+
nodes: new Map(),
|
|
167
|
+
edges: new Map(),
|
|
168
|
+
config: {
|
|
169
|
+
maxIterations: 100,
|
|
170
|
+
timeout: 300000,
|
|
171
|
+
checkpointEnabled: false,
|
|
172
|
+
checkpointInterval: 1,
|
|
173
|
+
parallelExecution: false,
|
|
174
|
+
retry: {
|
|
175
|
+
maxRetries: 0,
|
|
176
|
+
initialDelay: 0,
|
|
177
|
+
backoffMultiplier: 1,
|
|
178
|
+
maxDelay: 0,
|
|
179
|
+
retryableErrors: [],
|
|
180
|
+
},
|
|
181
|
+
logLevel: 'silent',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
default:
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get a nested field value from state
|
|
193
|
+
*/
|
|
194
|
+
function getFieldValue(state, field) {
|
|
195
|
+
const parts = field.split('.');
|
|
196
|
+
let current = state;
|
|
197
|
+
for (const part of parts) {
|
|
198
|
+
if (current === null || current === undefined) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
current = current[part];
|
|
202
|
+
}
|
|
203
|
+
return current;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Create a switch-case style decision node
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const switchNode = createSwitchNode({
|
|
211
|
+
* id: 'type-switch',
|
|
212
|
+
* name: 'Type Switch',
|
|
213
|
+
* field: 'data.messageType',
|
|
214
|
+
* cases: {
|
|
215
|
+
* 'question': 'question-handler',
|
|
216
|
+
* 'command': 'command-handler',
|
|
217
|
+
* 'feedback': 'feedback-handler'
|
|
218
|
+
* },
|
|
219
|
+
* default: 'unknown-handler'
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @param options - Switch node options
|
|
224
|
+
* @returns NodeDefinition for use in StateGraph
|
|
225
|
+
*/
|
|
226
|
+
function createSwitchNode(options) {
|
|
227
|
+
const branches = Object.entries(options.cases).map(([value, target]) => ({
|
|
228
|
+
name: `case-${value}`,
|
|
229
|
+
target,
|
|
230
|
+
condition: {
|
|
231
|
+
type: 'equals',
|
|
232
|
+
field: options.field,
|
|
233
|
+
value,
|
|
234
|
+
},
|
|
235
|
+
}));
|
|
236
|
+
return createDecisionNode({
|
|
237
|
+
id: options.id,
|
|
238
|
+
name: options.name,
|
|
239
|
+
config: {
|
|
240
|
+
branches,
|
|
241
|
+
defaultBranch: options.default,
|
|
242
|
+
throwOnNoMatch: !options.default,
|
|
243
|
+
},
|
|
244
|
+
nodeConfig: options.nodeConfig,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create a threshold-based decision node
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* const confidenceRouter = createThresholdNode({
|
|
253
|
+
* id: 'confidence-router',
|
|
254
|
+
* name: 'Confidence Router',
|
|
255
|
+
* field: 'data.confidence',
|
|
256
|
+
* thresholds: [
|
|
257
|
+
* { value: 0.9, target: 'high-confidence' },
|
|
258
|
+
* { value: 0.7, target: 'medium-confidence' },
|
|
259
|
+
* { value: 0.5, target: 'low-confidence' }
|
|
260
|
+
* ],
|
|
261
|
+
* default: 'very-low-confidence'
|
|
262
|
+
* });
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @param options - Threshold node options
|
|
266
|
+
* @returns NodeDefinition for use in StateGraph
|
|
267
|
+
*/
|
|
268
|
+
function createThresholdNode(options) {
|
|
269
|
+
// Sort thresholds in descending order
|
|
270
|
+
const sortedThresholds = [...options.thresholds].sort((a, b) => b.value - a.value);
|
|
271
|
+
const branches = sortedThresholds.map((threshold, index) => ({
|
|
272
|
+
name: `threshold-${threshold.value}`,
|
|
273
|
+
target: threshold.target,
|
|
274
|
+
condition: {
|
|
275
|
+
type: 'custom',
|
|
276
|
+
evaluate: async (state) => {
|
|
277
|
+
const value = getFieldValue(state, options.field);
|
|
278
|
+
if (typeof value !== 'number') {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
// Check if value is >= this threshold but < the next higher threshold
|
|
282
|
+
const isAboveThreshold = value >= threshold.value;
|
|
283
|
+
const nextHigherThreshold = sortedThresholds[index - 1];
|
|
284
|
+
const isBelowNextThreshold = !nextHigherThreshold || value < nextHigherThreshold.value;
|
|
285
|
+
return isAboveThreshold && isBelowNextThreshold;
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
priority: sortedThresholds.length - index,
|
|
289
|
+
}));
|
|
290
|
+
return createDecisionNode({
|
|
291
|
+
id: options.id,
|
|
292
|
+
name: options.name,
|
|
293
|
+
config: {
|
|
294
|
+
branches,
|
|
295
|
+
defaultBranch: options.default,
|
|
296
|
+
throwOnNoMatch: !options.default,
|
|
297
|
+
},
|
|
298
|
+
nodeConfig: options.nodeConfig,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create a boolean decision node (if-else)
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const ifElseNode = createIfElseNode({
|
|
307
|
+
* id: 'has-error',
|
|
308
|
+
* name: 'Error Check',
|
|
309
|
+
* condition: {
|
|
310
|
+
* type: 'exists',
|
|
311
|
+
* field: 'error'
|
|
312
|
+
* },
|
|
313
|
+
* ifTrue: 'error-handler',
|
|
314
|
+
* ifFalse: 'success-handler'
|
|
315
|
+
* });
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @param options - If-else node options
|
|
319
|
+
* @returns NodeDefinition for use in StateGraph
|
|
320
|
+
*/
|
|
321
|
+
function createIfElseNode(options) {
|
|
322
|
+
return createDecisionNode({
|
|
323
|
+
id: options.id,
|
|
324
|
+
name: options.name,
|
|
325
|
+
config: {
|
|
326
|
+
branches: [
|
|
327
|
+
{
|
|
328
|
+
name: 'if-true',
|
|
329
|
+
target: options.ifTrue,
|
|
330
|
+
condition: options.condition,
|
|
331
|
+
priority: 1,
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
defaultBranch: options.ifFalse,
|
|
335
|
+
},
|
|
336
|
+
nodeConfig: options.nodeConfig,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Create a multi-condition decision node (AND/OR logic)
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const multiConditionNode = createMultiConditionNode({
|
|
345
|
+
* id: 'complex-router',
|
|
346
|
+
* name: 'Complex Router',
|
|
347
|
+
* branches: [
|
|
348
|
+
* {
|
|
349
|
+
* name: 'premium-user',
|
|
350
|
+
* target: 'premium-flow',
|
|
351
|
+
* conditions: [
|
|
352
|
+
* { type: 'equals', field: 'data.userType', value: 'premium' },
|
|
353
|
+
* { type: 'greater_than', field: 'data.credits', value: 0 }
|
|
354
|
+
* ],
|
|
355
|
+
* logic: 'AND'
|
|
356
|
+
* },
|
|
357
|
+
* {
|
|
358
|
+
* name: 'needs-upgrade',
|
|
359
|
+
* target: 'upgrade-flow',
|
|
360
|
+
* conditions: [
|
|
361
|
+
* { type: 'equals', field: 'data.userType', value: 'free' },
|
|
362
|
+
* { type: 'less_than', field: 'data.credits', value: 1 }
|
|
363
|
+
* ],
|
|
364
|
+
* logic: 'OR'
|
|
365
|
+
* }
|
|
366
|
+
* ],
|
|
367
|
+
* default: 'standard-flow'
|
|
368
|
+
* });
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @param options - Multi-condition node options
|
|
372
|
+
* @returns NodeDefinition for use in StateGraph
|
|
373
|
+
*/
|
|
374
|
+
function createMultiConditionNode(options) {
|
|
375
|
+
const branches = options.branches.map(branch => ({
|
|
376
|
+
name: branch.name,
|
|
377
|
+
target: branch.target,
|
|
378
|
+
priority: branch.priority,
|
|
379
|
+
condition: {
|
|
380
|
+
type: 'custom',
|
|
381
|
+
evaluate: async (state) => {
|
|
382
|
+
const results = await Promise.all(branch.conditions.map(cond => evaluateCondition(cond, state)));
|
|
383
|
+
if (branch.logic === 'AND') {
|
|
384
|
+
return results.every(r => r);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
return results.some(r => r);
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
}));
|
|
392
|
+
return createDecisionNode({
|
|
393
|
+
id: options.id,
|
|
394
|
+
name: options.name,
|
|
395
|
+
config: {
|
|
396
|
+
branches,
|
|
397
|
+
defaultBranch: options.default,
|
|
398
|
+
throwOnNoMatch: !options.default,
|
|
399
|
+
},
|
|
400
|
+
nodeConfig: options.nodeConfig,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
//# sourceMappingURL=decision-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision-node.js","sourceRoot":"","sources":["../../src/nodes/decision-node.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAqGH,gDA2EC;AA2HD,4CAgCC;AAuBD,kDAkDC;AAsBD,4CA0BC;AAqCD,4DA6CC;AAphBD,6BAAwB;AAuCxB;;GAEG;AACU,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;QAChB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;QAClB,SAAS,EAAE,OAAC,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC;gBACX,QAAQ;gBACR,YAAY;gBACZ,UAAU;gBACV,cAAc;gBACd,WAAW;gBACX,QAAQ;gBACR,YAAY;gBACZ,QAAQ;aACT,CAAC;YACF,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC5B,KAAK,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;SAC9B,CAAC;QACF,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAChC,CAAC,CACH;IACD,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACpC,cAAc,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACvC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,kBAAkB,CAEhC,OAKD;IACC,MAAM,EAAE,EAAE,EAAE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K,KAAK,EAAE,CAAC;oBAC3B,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC/B,CAAC;qBAAM,CAAC;oBACN,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;SACF;KACF,CAAC,CAAC,CAAC;IAEJ,OAAO,kBAAkB,CAAS;QAChC,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,EAAE;YACN,QAAQ;YACR,aAAa,EAAE,OAAO,CAAC,OAAO;YAC9B,cAAc,EAAE,CAAC,OAAO,CAAC,OAAO;SACjC;QACD,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human Node - Human-in-the-loop interaction node
|
|
3
|
+
* @module @wundr.io/langgraph-orchestrator
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { AgentState, NodeDefinition } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for human node
|
|
9
|
+
*/
|
|
10
|
+
export interface HumanNodeConfig {
|
|
11
|
+
/** Prompt to display to the human */
|
|
12
|
+
readonly prompt?: string | ((state: AgentState) => string);
|
|
13
|
+
/** Input handler to collect human response */
|
|
14
|
+
readonly inputHandler: HumanInputHandler;
|
|
15
|
+
/** Validation for human input */
|
|
16
|
+
readonly validation?: z.ZodSchema;
|
|
17
|
+
/** Timeout for human response in milliseconds */
|
|
18
|
+
readonly timeout?: number;
|
|
19
|
+
/** What to do on timeout */
|
|
20
|
+
readonly onTimeout?: 'error' | 'skip' | 'default';
|
|
21
|
+
/** Default value to use on timeout */
|
|
22
|
+
readonly defaultValue?: unknown;
|
|
23
|
+
/** Pre-defined choices for the human */
|
|
24
|
+
readonly choices?: HumanChoice[];
|
|
25
|
+
/** Whether to require confirmation */
|
|
26
|
+
readonly requireConfirmation?: boolean;
|
|
27
|
+
/** Custom response processor */
|
|
28
|
+
readonly processResponse?: (response: HumanResponse, state: AgentState) => Partial<AgentState['data']>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Handler for collecting human input
|
|
32
|
+
*/
|
|
33
|
+
export interface HumanInputHandler {
|
|
34
|
+
/** Request input from human */
|
|
35
|
+
request(context: HumanInputContext): Promise<HumanResponse>;
|
|
36
|
+
/** Cancel a pending request */
|
|
37
|
+
cancel?(requestId: string): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Context provided to human input handler
|
|
41
|
+
*/
|
|
42
|
+
export interface HumanInputContext {
|
|
43
|
+
/** Unique request ID */
|
|
44
|
+
readonly requestId: string;
|
|
45
|
+
/** Prompt to display */
|
|
46
|
+
readonly prompt: string;
|
|
47
|
+
/** Available choices */
|
|
48
|
+
readonly choices?: HumanChoice[];
|
|
49
|
+
/** Current workflow state (sanitized) */
|
|
50
|
+
readonly state: Partial<AgentState>;
|
|
51
|
+
/** Timeout in milliseconds */
|
|
52
|
+
readonly timeout?: number;
|
|
53
|
+
/** Additional metadata */
|
|
54
|
+
readonly metadata?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Human choice option
|
|
58
|
+
*/
|
|
59
|
+
export interface HumanChoice {
|
|
60
|
+
/** Choice value */
|
|
61
|
+
readonly value: string;
|
|
62
|
+
/** Display label */
|
|
63
|
+
readonly label: string;
|
|
64
|
+
/** Description */
|
|
65
|
+
readonly description?: string;
|
|
66
|
+
/** Whether this is the default choice */
|
|
67
|
+
readonly default?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Response from human input
|
|
71
|
+
*/
|
|
72
|
+
export interface HumanResponse {
|
|
73
|
+
/** The response value */
|
|
74
|
+
readonly value: unknown;
|
|
75
|
+
/** Response type */
|
|
76
|
+
readonly type: 'input' | 'choice' | 'confirmation' | 'cancel' | 'timeout';
|
|
77
|
+
/** Timestamp of response */
|
|
78
|
+
readonly timestamp: Date;
|
|
79
|
+
/** Additional metadata */
|
|
80
|
+
readonly metadata?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Schema for human node configuration validation
|
|
84
|
+
*/
|
|
85
|
+
export declare const HumanNodeConfigSchema: z.ZodObject<{
|
|
86
|
+
prompt: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
|
|
87
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
onTimeout: z.ZodOptional<z.ZodEnum<["error", "skip", "default"]>>;
|
|
89
|
+
choices: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
90
|
+
value: z.ZodString;
|
|
91
|
+
label: z.ZodString;
|
|
92
|
+
description: z.ZodOptional<z.ZodString>;
|
|
93
|
+
default: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
value: string;
|
|
96
|
+
label: string;
|
|
97
|
+
description?: string | undefined;
|
|
98
|
+
default?: boolean | undefined;
|
|
99
|
+
}, {
|
|
100
|
+
value: string;
|
|
101
|
+
label: string;
|
|
102
|
+
description?: string | undefined;
|
|
103
|
+
default?: boolean | undefined;
|
|
104
|
+
}>, "many">>;
|
|
105
|
+
requireConfirmation: z.ZodOptional<z.ZodBoolean>;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
timeout?: number | undefined;
|
|
108
|
+
prompt?: string | ((...args: unknown[]) => unknown) | undefined;
|
|
109
|
+
onTimeout?: "error" | "default" | "skip" | undefined;
|
|
110
|
+
choices?: {
|
|
111
|
+
value: string;
|
|
112
|
+
label: string;
|
|
113
|
+
description?: string | undefined;
|
|
114
|
+
default?: boolean | undefined;
|
|
115
|
+
}[] | undefined;
|
|
116
|
+
requireConfirmation?: boolean | undefined;
|
|
117
|
+
}, {
|
|
118
|
+
timeout?: number | undefined;
|
|
119
|
+
prompt?: string | ((...args: unknown[]) => unknown) | undefined;
|
|
120
|
+
onTimeout?: "error" | "default" | "skip" | undefined;
|
|
121
|
+
choices?: {
|
|
122
|
+
value: string;
|
|
123
|
+
label: string;
|
|
124
|
+
description?: string | undefined;
|
|
125
|
+
default?: boolean | undefined;
|
|
126
|
+
}[] | undefined;
|
|
127
|
+
requireConfirmation?: boolean | undefined;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Create a human-in-the-loop node
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const humanNode = createHumanNode({
|
|
135
|
+
* id: 'approval',
|
|
136
|
+
* name: 'Human Approval',
|
|
137
|
+
* config: {
|
|
138
|
+
* prompt: 'Please review and approve the generated content.',
|
|
139
|
+
* inputHandler: myInputHandler,
|
|
140
|
+
* choices: [
|
|
141
|
+
* { value: 'approve', label: 'Approve' },
|
|
142
|
+
* { value: 'reject', label: 'Reject' },
|
|
143
|
+
* { value: 'modify', label: 'Request Modifications' }
|
|
144
|
+
* ],
|
|
145
|
+
* timeout: 300000 // 5 minutes
|
|
146
|
+
* }
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* graph.addNode('approval', humanNode);
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @param options - Node creation options
|
|
153
|
+
* @returns NodeDefinition for use in StateGraph
|
|
154
|
+
*/
|
|
155
|
+
export declare function createHumanNode<TState extends AgentState = AgentState>(options: {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
config: HumanNodeConfig;
|
|
159
|
+
nodeConfig?: NodeDefinition<TState>['config'];
|
|
160
|
+
}): NodeDefinition<TState>;
|
|
161
|
+
/**
|
|
162
|
+
* Create a console-based human input handler
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const handler = createConsoleInputHandler();
|
|
167
|
+
*
|
|
168
|
+
* const humanNode = createHumanNode({
|
|
169
|
+
* id: 'input',
|
|
170
|
+
* name: 'User Input',
|
|
171
|
+
* config: {
|
|
172
|
+
* inputHandler: handler,
|
|
173
|
+
* prompt: 'Enter your response:'
|
|
174
|
+
* }
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @returns HumanInputHandler for console input
|
|
179
|
+
*/
|
|
180
|
+
export declare function createConsoleInputHandler(): HumanInputHandler;
|
|
181
|
+
/**
|
|
182
|
+
* Create a callback-based human input handler
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const pendingRequests = new Map();
|
|
187
|
+
*
|
|
188
|
+
* const handler = createCallbackInputHandler({
|
|
189
|
+
* onRequest: (context) => {
|
|
190
|
+
* pendingRequests.set(context.requestId, context);
|
|
191
|
+
* // Notify UI or external system
|
|
192
|
+
* },
|
|
193
|
+
* onResolve: (requestId) => pendingRequests.delete(requestId)
|
|
194
|
+
* });
|
|
195
|
+
*
|
|
196
|
+
* // External system resolves:
|
|
197
|
+
* handler.resolve(requestId, { value: 'user input', type: 'input', timestamp: new Date() });
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @param options - Handler options
|
|
201
|
+
* @returns HumanInputHandler with resolve capability
|
|
202
|
+
*/
|
|
203
|
+
export declare function createCallbackInputHandler(options: {
|
|
204
|
+
onRequest?: (context: HumanInputContext) => void;
|
|
205
|
+
onResolve?: (requestId: string) => void;
|
|
206
|
+
onCancel?: (requestId: string) => void;
|
|
207
|
+
}): HumanInputHandler & {
|
|
208
|
+
resolve: (requestId: string, response: HumanResponse) => void;
|
|
209
|
+
reject: (requestId: string, error: Error) => void;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Create a confirmation node for human approval
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const confirmNode = createConfirmationNode({
|
|
217
|
+
* id: 'confirm-action',
|
|
218
|
+
* name: 'Confirm Action',
|
|
219
|
+
* inputHandler: myHandler,
|
|
220
|
+
* message: (state) => `Are you sure you want to ${state.data.action}?`,
|
|
221
|
+
* onConfirm: 'execute-action',
|
|
222
|
+
* onReject: 'cancel-action'
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @param options - Confirmation node options
|
|
227
|
+
* @returns NodeDefinition for use in StateGraph
|
|
228
|
+
*/
|
|
229
|
+
export declare function createConfirmationNode<TState extends AgentState = AgentState>(options: {
|
|
230
|
+
id: string;
|
|
231
|
+
name: string;
|
|
232
|
+
inputHandler: HumanInputHandler;
|
|
233
|
+
message: string | ((state: TState) => string);
|
|
234
|
+
onConfirm: string;
|
|
235
|
+
onReject: string;
|
|
236
|
+
timeout?: number;
|
|
237
|
+
nodeConfig?: NodeDefinition<TState>['config'];
|
|
238
|
+
}): NodeDefinition<TState>;
|
|
239
|
+
/**
|
|
240
|
+
* Create a feedback collection node
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const feedbackNode = createFeedbackNode({
|
|
245
|
+
* id: 'collect-feedback',
|
|
246
|
+
* name: 'Collect Feedback',
|
|
247
|
+
* inputHandler: myHandler,
|
|
248
|
+
* questions: [
|
|
249
|
+
* { id: 'rating', prompt: 'Rate this response (1-5):', type: 'number' },
|
|
250
|
+
* { id: 'comments', prompt: 'Any additional comments?', type: 'text' }
|
|
251
|
+
* ]
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @param options - Feedback node options
|
|
256
|
+
* @returns NodeDefinition for use in StateGraph
|
|
257
|
+
*/
|
|
258
|
+
export declare function createFeedbackNode<TState extends AgentState = AgentState>(options: {
|
|
259
|
+
id: string;
|
|
260
|
+
name: string;
|
|
261
|
+
inputHandler: HumanInputHandler;
|
|
262
|
+
questions: Array<{
|
|
263
|
+
id: string;
|
|
264
|
+
prompt: string;
|
|
265
|
+
type: 'text' | 'number' | 'choice';
|
|
266
|
+
choices?: string[];
|
|
267
|
+
required?: boolean;
|
|
268
|
+
}>;
|
|
269
|
+
timeout?: number;
|
|
270
|
+
nodeConfig?: NodeDefinition<TState>['config'];
|
|
271
|
+
}): NodeDefinition<TState>;
|
|
272
|
+
//# sourceMappingURL=human-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-node.d.ts","sourceRoot":"","sources":["../../src/nodes/human-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EAIf,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC,CAAC;IAC3D,8CAA8C;IAC9C,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IACzC,iCAAiC;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;IAClC,iDAAiD;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAClD,sCAAsC;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,wCAAwC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACjC,sCAAsC;IACtC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IACvC,gCAAgC;IAChC,QAAQ,CAAC,eAAe,CAAC,EAA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