@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
package/dist/index.js ADDED
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ /**
3
+ * LangGraph Orchestrator - LangGraph-style cyclic, state-driven workflows
4
+ * @module @wundr.io/langgraph-orchestrator
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import {
9
+ * StateGraph,
10
+ * createLLMNode,
11
+ * createToolNode,
12
+ * createDecisionNode,
13
+ * MemoryCheckpointer
14
+ * } from '@wundr.io/langgraph-orchestrator';
15
+ *
16
+ * // Create a workflow graph
17
+ * const graph = new StateGraph('my-workflow')
18
+ * .addNode('agent', createLLMNode({
19
+ * id: 'agent',
20
+ * name: 'Agent',
21
+ * config: { model: 'claude-3-sonnet-20240229' }
22
+ * }))
23
+ * .addNode('tools', createToolNode({
24
+ * id: 'tools',
25
+ * name: 'Tools'
26
+ * }))
27
+ * .addEdge('agent', 'tools')
28
+ * .addConditionalEdge('tools', 'agent', {
29
+ * type: 'exists',
30
+ * field: 'data.pendingToolCalls'
31
+ * })
32
+ * .setEntryPoint('agent')
33
+ * .setCheckpointer(new MemoryCheckpointer());
34
+ *
35
+ * // Execute the workflow
36
+ * const result = await graph.execute({
37
+ * initialState: {
38
+ * data: { task: 'Research AI developments' }
39
+ * }
40
+ * });
41
+ * ```
42
+ */
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.createSimpleTaskGraph = exports.createPlanExecuteRefineGraph = exports.CheckpointValidationSchema = exports.validateCheckpoint = exports.applyRetentionPolicy = exports.createCheckpoint = exports.TimeTravelDebugger = exports.FileCheckpointer = exports.MemoryCheckpointer = exports.validateLoopConfig = exports.LoopConfigSchema = exports.createPaginationLoop = exports.createRetryLoop = exports.createDoWhileLoop = exports.createWhileLoop = exports.createForLoop = exports.loopEdge = exports.LoopEdgeBuilder = exports.validateCondition = exports.EdgeConditionSchema = exports.conditions = exports.createRouter = exports.conditionalEdge = exports.ConditionalEdgeBuilder = exports.HumanNodeConfigSchema = exports.createFeedbackNode = exports.createConfirmationNode = exports.createCallbackInputHandler = exports.createConsoleInputHandler = exports.createHumanNode = exports.DecisionNodeConfigSchema = exports.createMultiConditionNode = exports.createIfElseNode = exports.createThresholdNode = exports.createSwitchNode = exports.createDecisionNode = exports.ToolNodeConfigSchema = exports.createBatchToolNode = exports.createTool = exports.createToolRegistry = exports.createToolNode = exports.LLMNodeConfigSchema = exports.createConversationalLLMNode = exports.createStructuredLLMNode = exports.createLLMRouter = exports.createLLMNode = exports.StateGraph = exports.CheckpointSchema = exports.GraphConfigSchema = exports.MessageSchema = void 0;
45
+ exports.VERSION = exports.PlanSchema = void 0;
46
+ exports.createAgentWorkflow = createAgentWorkflow;
47
+ exports.createChatWorkflow = createChatWorkflow;
48
+ exports.createDecisionTree = createDecisionTree;
49
+ // ============================================================================
50
+ // Core Types
51
+ // ============================================================================
52
+ // ============================================================================
53
+ // Utility Functions
54
+ // ============================================================================
55
+ // Import for internal use in utility functions
56
+ const decision_node_1 = require("./nodes/decision-node");
57
+ const llm_node_1 = require("./nodes/llm-node");
58
+ const tool_node_1 = require("./nodes/tool-node");
59
+ const state_graph_1 = require("./state-graph");
60
+ // Zod schemas
61
+ var types_1 = require("./types");
62
+ Object.defineProperty(exports, "MessageSchema", { enumerable: true, get: function () { return types_1.MessageSchema; } });
63
+ Object.defineProperty(exports, "GraphConfigSchema", { enumerable: true, get: function () { return types_1.GraphConfigSchema; } });
64
+ Object.defineProperty(exports, "CheckpointSchema", { enumerable: true, get: function () { return types_1.CheckpointSchema; } });
65
+ // ============================================================================
66
+ // Core Classes
67
+ // ============================================================================
68
+ var state_graph_2 = require("./state-graph");
69
+ Object.defineProperty(exports, "StateGraph", { enumerable: true, get: function () { return state_graph_2.StateGraph; } });
70
+ // ============================================================================
71
+ // Nodes
72
+ // ============================================================================
73
+ // LLM Node
74
+ var llm_node_2 = require("./nodes/llm-node");
75
+ Object.defineProperty(exports, "createLLMNode", { enumerable: true, get: function () { return llm_node_2.createLLMNode; } });
76
+ Object.defineProperty(exports, "createLLMRouter", { enumerable: true, get: function () { return llm_node_2.createLLMRouter; } });
77
+ Object.defineProperty(exports, "createStructuredLLMNode", { enumerable: true, get: function () { return llm_node_2.createStructuredLLMNode; } });
78
+ Object.defineProperty(exports, "createConversationalLLMNode", { enumerable: true, get: function () { return llm_node_2.createConversationalLLMNode; } });
79
+ Object.defineProperty(exports, "LLMNodeConfigSchema", { enumerable: true, get: function () { return llm_node_2.LLMNodeConfigSchema; } });
80
+ // Tool Node
81
+ var tool_node_2 = require("./nodes/tool-node");
82
+ Object.defineProperty(exports, "createToolNode", { enumerable: true, get: function () { return tool_node_2.createToolNode; } });
83
+ Object.defineProperty(exports, "createToolRegistry", { enumerable: true, get: function () { return tool_node_2.createToolRegistry; } });
84
+ Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return tool_node_2.createTool; } });
85
+ Object.defineProperty(exports, "createBatchToolNode", { enumerable: true, get: function () { return tool_node_2.createBatchToolNode; } });
86
+ Object.defineProperty(exports, "ToolNodeConfigSchema", { enumerable: true, get: function () { return tool_node_2.ToolNodeConfigSchema; } });
87
+ // Decision Node
88
+ var decision_node_2 = require("./nodes/decision-node");
89
+ Object.defineProperty(exports, "createDecisionNode", { enumerable: true, get: function () { return decision_node_2.createDecisionNode; } });
90
+ Object.defineProperty(exports, "createSwitchNode", { enumerable: true, get: function () { return decision_node_2.createSwitchNode; } });
91
+ Object.defineProperty(exports, "createThresholdNode", { enumerable: true, get: function () { return decision_node_2.createThresholdNode; } });
92
+ Object.defineProperty(exports, "createIfElseNode", { enumerable: true, get: function () { return decision_node_2.createIfElseNode; } });
93
+ Object.defineProperty(exports, "createMultiConditionNode", { enumerable: true, get: function () { return decision_node_2.createMultiConditionNode; } });
94
+ Object.defineProperty(exports, "DecisionNodeConfigSchema", { enumerable: true, get: function () { return decision_node_2.DecisionNodeConfigSchema; } });
95
+ // Human Node
96
+ var human_node_1 = require("./nodes/human-node");
97
+ Object.defineProperty(exports, "createHumanNode", { enumerable: true, get: function () { return human_node_1.createHumanNode; } });
98
+ Object.defineProperty(exports, "createConsoleInputHandler", { enumerable: true, get: function () { return human_node_1.createConsoleInputHandler; } });
99
+ Object.defineProperty(exports, "createCallbackInputHandler", { enumerable: true, get: function () { return human_node_1.createCallbackInputHandler; } });
100
+ Object.defineProperty(exports, "createConfirmationNode", { enumerable: true, get: function () { return human_node_1.createConfirmationNode; } });
101
+ Object.defineProperty(exports, "createFeedbackNode", { enumerable: true, get: function () { return human_node_1.createFeedbackNode; } });
102
+ Object.defineProperty(exports, "HumanNodeConfigSchema", { enumerable: true, get: function () { return human_node_1.HumanNodeConfigSchema; } });
103
+ // ============================================================================
104
+ // Edges
105
+ // ============================================================================
106
+ // Conditional Edge
107
+ var conditional_edge_1 = require("./edges/conditional-edge");
108
+ Object.defineProperty(exports, "ConditionalEdgeBuilder", { enumerable: true, get: function () { return conditional_edge_1.ConditionalEdgeBuilder; } });
109
+ Object.defineProperty(exports, "conditionalEdge", { enumerable: true, get: function () { return conditional_edge_1.conditionalEdge; } });
110
+ Object.defineProperty(exports, "createRouter", { enumerable: true, get: function () { return conditional_edge_1.createRouter; } });
111
+ Object.defineProperty(exports, "conditions", { enumerable: true, get: function () { return conditional_edge_1.conditions; } });
112
+ Object.defineProperty(exports, "EdgeConditionSchema", { enumerable: true, get: function () { return conditional_edge_1.EdgeConditionSchema; } });
113
+ Object.defineProperty(exports, "validateCondition", { enumerable: true, get: function () { return conditional_edge_1.validateCondition; } });
114
+ // Loop Edge
115
+ var loop_edge_1 = require("./edges/loop-edge");
116
+ Object.defineProperty(exports, "LoopEdgeBuilder", { enumerable: true, get: function () { return loop_edge_1.LoopEdgeBuilder; } });
117
+ Object.defineProperty(exports, "loopEdge", { enumerable: true, get: function () { return loop_edge_1.loopEdge; } });
118
+ Object.defineProperty(exports, "createForLoop", { enumerable: true, get: function () { return loop_edge_1.createForLoop; } });
119
+ Object.defineProperty(exports, "createWhileLoop", { enumerable: true, get: function () { return loop_edge_1.createWhileLoop; } });
120
+ Object.defineProperty(exports, "createDoWhileLoop", { enumerable: true, get: function () { return loop_edge_1.createDoWhileLoop; } });
121
+ Object.defineProperty(exports, "createRetryLoop", { enumerable: true, get: function () { return loop_edge_1.createRetryLoop; } });
122
+ Object.defineProperty(exports, "createPaginationLoop", { enumerable: true, get: function () { return loop_edge_1.createPaginationLoop; } });
123
+ Object.defineProperty(exports, "LoopConfigSchema", { enumerable: true, get: function () { return loop_edge_1.LoopConfigSchema; } });
124
+ Object.defineProperty(exports, "validateLoopConfig", { enumerable: true, get: function () { return loop_edge_1.validateLoopConfig; } });
125
+ // ============================================================================
126
+ // Checkpointing
127
+ // ============================================================================
128
+ var checkpointing_1 = require("./checkpointing");
129
+ Object.defineProperty(exports, "MemoryCheckpointer", { enumerable: true, get: function () { return checkpointing_1.MemoryCheckpointer; } });
130
+ Object.defineProperty(exports, "FileCheckpointer", { enumerable: true, get: function () { return checkpointing_1.FileCheckpointer; } });
131
+ Object.defineProperty(exports, "TimeTravelDebugger", { enumerable: true, get: function () { return checkpointing_1.TimeTravelDebugger; } });
132
+ Object.defineProperty(exports, "createCheckpoint", { enumerable: true, get: function () { return checkpointing_1.createCheckpoint; } });
133
+ Object.defineProperty(exports, "applyRetentionPolicy", { enumerable: true, get: function () { return checkpointing_1.applyRetentionPolicy; } });
134
+ Object.defineProperty(exports, "validateCheckpoint", { enumerable: true, get: function () { return checkpointing_1.validateCheckpoint; } });
135
+ Object.defineProperty(exports, "CheckpointValidationSchema", { enumerable: true, get: function () { return checkpointing_1.CheckpointSchema; } });
136
+ // ============================================================================
137
+ // Prebuilt Graphs
138
+ // ============================================================================
139
+ var plan_execute_refine_1 = require("./prebuilt-graphs/plan-execute-refine");
140
+ Object.defineProperty(exports, "createPlanExecuteRefineGraph", { enumerable: true, get: function () { return plan_execute_refine_1.createPlanExecuteRefineGraph; } });
141
+ Object.defineProperty(exports, "createSimpleTaskGraph", { enumerable: true, get: function () { return plan_execute_refine_1.createSimpleTaskGraph; } });
142
+ Object.defineProperty(exports, "PlanSchema", { enumerable: true, get: function () { return plan_execute_refine_1.PlanSchema; } });
143
+ /**
144
+ * Create a simple agent workflow
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const graph = createAgentWorkflow({
149
+ * name: 'research-agent',
150
+ * llmProvider: myProvider,
151
+ * tools: [searchTool, writeTool],
152
+ * systemPrompt: 'You are a helpful research assistant.'
153
+ * });
154
+ * ```
155
+ */
156
+ function createAgentWorkflow(options) {
157
+ const graph = new state_graph_1.StateGraph(options.name, {
158
+ maxIterations: options.maxIterations ?? 50,
159
+ });
160
+ const registry = (0, tool_node_1.createToolRegistry)();
161
+ options.tools?.forEach(tool => registry.register(tool));
162
+ graph.setServices({
163
+ llmProvider: options.llmProvider,
164
+ toolRegistry: registry,
165
+ });
166
+ // Add agent node
167
+ graph.addNode('agent', (0, llm_node_1.createLLMNode)({
168
+ id: 'agent',
169
+ name: 'Agent',
170
+ config: {
171
+ systemPrompt: options.systemPrompt,
172
+ tools: options.tools,
173
+ },
174
+ }));
175
+ // Add tool node if tools provided
176
+ if (options.tools?.length) {
177
+ graph.addNode('tools', (0, tool_node_1.createToolNode)({
178
+ id: 'tools',
179
+ name: 'Tool Executor',
180
+ config: {
181
+ tools: options.tools,
182
+ parallel: true,
183
+ },
184
+ }));
185
+ // Add edges
186
+ graph.addConditionalEdge('agent', 'tools', {
187
+ type: 'exists',
188
+ field: 'data.pendingToolCalls',
189
+ });
190
+ graph.addEdge('tools', 'agent');
191
+ }
192
+ graph.setEntryPoint('agent');
193
+ return graph;
194
+ }
195
+ /**
196
+ * Create a chat workflow with conversation history
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * const chat = createChatWorkflow({
201
+ * name: 'chat-assistant',
202
+ * llmProvider: myProvider,
203
+ * systemPrompt: 'You are a friendly assistant.',
204
+ * maxHistory: 20
205
+ * });
206
+ * ```
207
+ */
208
+ function createChatWorkflow(options) {
209
+ const graph = new state_graph_1.StateGraph(options.name);
210
+ graph.setServices({
211
+ llmProvider: options.llmProvider,
212
+ });
213
+ graph.addNode('chat', (0, llm_node_1.createConversationalLLMNode)({
214
+ id: 'chat',
215
+ name: 'Chat',
216
+ config: {
217
+ systemPrompt: options.systemPrompt,
218
+ },
219
+ maxHistoryLength: options.maxHistory ?? 50,
220
+ }));
221
+ graph.setEntryPoint('chat');
222
+ return graph;
223
+ }
224
+ /**
225
+ * Create a decision tree workflow
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * const tree = createDecisionTree({
230
+ * name: 'support-router',
231
+ * decisions: [
232
+ * {
233
+ * field: 'data.category',
234
+ * branches: {
235
+ * 'billing': 'billing-handler',
236
+ * 'technical': 'tech-handler',
237
+ * 'general': 'general-handler'
238
+ * },
239
+ * default: 'general-handler'
240
+ * }
241
+ * ]
242
+ * });
243
+ * ```
244
+ */
245
+ function createDecisionTree(options) {
246
+ const graph = new state_graph_1.StateGraph(options.name);
247
+ options.decisions.forEach((decision, index) => {
248
+ const nodeId = decision.id ?? `decision-${index}`;
249
+ graph.addNode(nodeId, (0, decision_node_1.createSwitchNode)({
250
+ id: nodeId,
251
+ name: nodeId,
252
+ field: decision.field,
253
+ cases: decision.branches,
254
+ default: decision.default,
255
+ }));
256
+ });
257
+ if (options.decisions.length > 0) {
258
+ const firstDecision = options.decisions[0];
259
+ if (firstDecision) {
260
+ graph.setEntryPoint(firstDecision.id ?? 'decision-0');
261
+ }
262
+ }
263
+ return graph;
264
+ }
265
+ // ============================================================================
266
+ // Version
267
+ // ============================================================================
268
+ exports.VERSION = '1.0.3';
269
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;;;;AAuNH,kDAyDC;AAeD,gDA2BC;AAuBD,gDAiCC;AAhXD,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAC/E,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,+CAA+C;AAC/C,yDAA+E;AAC/E,+CAG0B;AAC1B,iDAG2B;AAC3B,+CAA8D;AAkE9D,cAAc;AACd,iCAA6E;AAApE,sGAAA,aAAa,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAE3D,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAC/E,6CAA6D;AAApD,yGAAA,UAAU,OAAA;AAEnB,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E,WAAW;AACX,6CAO0B;AANxB,yGAAA,aAAa,OAAA;AACb,2GAAA,eAAe,OAAA;AACf,mHAAA,uBAAuB,OAAA;AACvB,uHAAA,2BAA2B,OAAA;AAE3B,+GAAA,mBAAmB,OAAA;AAGrB,YAAY;AACZ,+CAO2B;AANzB,2GAAA,cAAc,OAAA;AACd,+GAAA,kBAAkB,OAAA;AAClB,uGAAA,UAAU,OAAA;AACV,gHAAA,mBAAmB,OAAA;AAEnB,iHAAA,oBAAoB,OAAA;AAGtB,gBAAgB;AACh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M,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC3C,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,IAAI,YAAY,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAClE,QAAA,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,276 @@
1
+ /**
2
+ * Decision Node - Conditional branching node for workflow control flow
3
+ * @module @wundr.io/langgraph-orchestrator
4
+ */
5
+ import { z } from 'zod';
6
+ import type { AgentState, NodeDefinition, EdgeCondition } from '../types';
7
+ /**
8
+ * Configuration for decision node
9
+ */
10
+ export interface DecisionNodeConfig {
11
+ /** Decision branches */
12
+ readonly branches: DecisionBranch[];
13
+ /** Default branch if no conditions match */
14
+ readonly defaultBranch?: string;
15
+ /** Whether to throw error if no branch matches and no default */
16
+ readonly throwOnNoMatch?: boolean;
17
+ /** Custom decision function */
18
+ readonly decide?: (state: AgentState) => string | Promise<string>;
19
+ }
20
+ /**
21
+ * Decision branch definition
22
+ */
23
+ export interface DecisionBranch {
24
+ /** Name/ID of this branch */
25
+ readonly name: string;
26
+ /** Target node for this branch */
27
+ readonly target: string;
28
+ /** Condition for taking this branch */
29
+ readonly condition: EdgeCondition;
30
+ /** Priority (higher = checked first) */
31
+ readonly priority?: number;
32
+ }
33
+ /**
34
+ * Schema for decision node configuration validation
35
+ */
36
+ export declare const DecisionNodeConfigSchema: z.ZodObject<{
37
+ branches: z.ZodArray<z.ZodObject<{
38
+ name: z.ZodString;
39
+ target: z.ZodString;
40
+ condition: z.ZodObject<{
41
+ type: z.ZodEnum<["equals", "not_equals", "contains", "greater_than", "less_than", "exists", "not_exists", "custom"]>;
42
+ field: z.ZodOptional<z.ZodString>;
43
+ value: z.ZodOptional<z.ZodUnknown>;
44
+ }, "strip", z.ZodTypeAny, {
45
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
46
+ value?: unknown;
47
+ field?: string | undefined;
48
+ }, {
49
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
50
+ value?: unknown;
51
+ field?: string | undefined;
52
+ }>;
53
+ priority: z.ZodOptional<z.ZodNumber>;
54
+ }, "strip", z.ZodTypeAny, {
55
+ name: string;
56
+ target: string;
57
+ condition: {
58
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
59
+ value?: unknown;
60
+ field?: string | undefined;
61
+ };
62
+ priority?: number | undefined;
63
+ }, {
64
+ name: string;
65
+ target: string;
66
+ condition: {
67
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
68
+ value?: unknown;
69
+ field?: string | undefined;
70
+ };
71
+ priority?: number | undefined;
72
+ }>, "many">;
73
+ defaultBranch: z.ZodOptional<z.ZodString>;
74
+ throwOnNoMatch: z.ZodOptional<z.ZodBoolean>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ branches: {
77
+ name: string;
78
+ target: string;
79
+ condition: {
80
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
81
+ value?: unknown;
82
+ field?: string | undefined;
83
+ };
84
+ priority?: number | undefined;
85
+ }[];
86
+ defaultBranch?: string | undefined;
87
+ throwOnNoMatch?: boolean | undefined;
88
+ }, {
89
+ branches: {
90
+ name: string;
91
+ target: string;
92
+ condition: {
93
+ type: "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "exists" | "not_exists" | "custom";
94
+ value?: unknown;
95
+ field?: string | undefined;
96
+ };
97
+ priority?: number | undefined;
98
+ }[];
99
+ defaultBranch?: string | undefined;
100
+ throwOnNoMatch?: boolean | undefined;
101
+ }>;
102
+ /**
103
+ * Create a decision node for conditional branching
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const decisionNode = createDecisionNode({
108
+ * id: 'router',
109
+ * name: 'Task Router',
110
+ * config: {
111
+ * branches: [
112
+ * {
113
+ * name: 'search',
114
+ * target: 'search-node',
115
+ * condition: { type: 'equals', field: 'data.action', value: 'search' }
116
+ * },
117
+ * {
118
+ * name: 'answer',
119
+ * target: 'answer-node',
120
+ * condition: { type: 'equals', field: 'data.action', value: 'answer' }
121
+ * }
122
+ * ],
123
+ * defaultBranch: 'fallback-node'
124
+ * }
125
+ * });
126
+ *
127
+ * graph.addNode('router', decisionNode);
128
+ * ```
129
+ *
130
+ * @param options - Node creation options
131
+ * @returns NodeDefinition for use in StateGraph
132
+ */
133
+ export declare function createDecisionNode<TState extends AgentState = AgentState>(options: {
134
+ id: string;
135
+ name: string;
136
+ config: DecisionNodeConfig;
137
+ nodeConfig?: NodeDefinition<TState>['config'];
138
+ }): NodeDefinition<TState>;
139
+ /**
140
+ * Create a switch-case style decision node
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const switchNode = createSwitchNode({
145
+ * id: 'type-switch',
146
+ * name: 'Type Switch',
147
+ * field: 'data.messageType',
148
+ * cases: {
149
+ * 'question': 'question-handler',
150
+ * 'command': 'command-handler',
151
+ * 'feedback': 'feedback-handler'
152
+ * },
153
+ * default: 'unknown-handler'
154
+ * });
155
+ * ```
156
+ *
157
+ * @param options - Switch node options
158
+ * @returns NodeDefinition for use in StateGraph
159
+ */
160
+ export declare function createSwitchNode<TState extends AgentState = AgentState>(options: {
161
+ id: string;
162
+ name: string;
163
+ field: string;
164
+ cases: Record<string, string>;
165
+ default?: string;
166
+ nodeConfig?: NodeDefinition<TState>['config'];
167
+ }): NodeDefinition<TState>;
168
+ /**
169
+ * Create a threshold-based decision node
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * const confidenceRouter = createThresholdNode({
174
+ * id: 'confidence-router',
175
+ * name: 'Confidence Router',
176
+ * field: 'data.confidence',
177
+ * thresholds: [
178
+ * { value: 0.9, target: 'high-confidence' },
179
+ * { value: 0.7, target: 'medium-confidence' },
180
+ * { value: 0.5, target: 'low-confidence' }
181
+ * ],
182
+ * default: 'very-low-confidence'
183
+ * });
184
+ * ```
185
+ *
186
+ * @param options - Threshold node options
187
+ * @returns NodeDefinition for use in StateGraph
188
+ */
189
+ export declare function createThresholdNode<TState extends AgentState = AgentState>(options: {
190
+ id: string;
191
+ name: string;
192
+ field: string;
193
+ thresholds: Array<{
194
+ value: number;
195
+ target: string;
196
+ }>;
197
+ default?: string;
198
+ nodeConfig?: NodeDefinition<TState>['config'];
199
+ }): NodeDefinition<TState>;
200
+ /**
201
+ * Create a boolean decision node (if-else)
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const ifElseNode = createIfElseNode({
206
+ * id: 'has-error',
207
+ * name: 'Error Check',
208
+ * condition: {
209
+ * type: 'exists',
210
+ * field: 'error'
211
+ * },
212
+ * ifTrue: 'error-handler',
213
+ * ifFalse: 'success-handler'
214
+ * });
215
+ * ```
216
+ *
217
+ * @param options - If-else node options
218
+ * @returns NodeDefinition for use in StateGraph
219
+ */
220
+ export declare function createIfElseNode<TState extends AgentState = AgentState>(options: {
221
+ id: string;
222
+ name: string;
223
+ condition: EdgeCondition;
224
+ ifTrue: string;
225
+ ifFalse: string;
226
+ nodeConfig?: NodeDefinition<TState>['config'];
227
+ }): NodeDefinition<TState>;
228
+ /**
229
+ * Create a multi-condition decision node (AND/OR logic)
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const multiConditionNode = createMultiConditionNode({
234
+ * id: 'complex-router',
235
+ * name: 'Complex Router',
236
+ * branches: [
237
+ * {
238
+ * name: 'premium-user',
239
+ * target: 'premium-flow',
240
+ * conditions: [
241
+ * { type: 'equals', field: 'data.userType', value: 'premium' },
242
+ * { type: 'greater_than', field: 'data.credits', value: 0 }
243
+ * ],
244
+ * logic: 'AND'
245
+ * },
246
+ * {
247
+ * name: 'needs-upgrade',
248
+ * target: 'upgrade-flow',
249
+ * conditions: [
250
+ * { type: 'equals', field: 'data.userType', value: 'free' },
251
+ * { type: 'less_than', field: 'data.credits', value: 1 }
252
+ * ],
253
+ * logic: 'OR'
254
+ * }
255
+ * ],
256
+ * default: 'standard-flow'
257
+ * });
258
+ * ```
259
+ *
260
+ * @param options - Multi-condition node options
261
+ * @returns NodeDefinition for use in StateGraph
262
+ */
263
+ export declare function createMultiConditionNode<TState extends AgentState = AgentState>(options: {
264
+ id: string;
265
+ name: string;
266
+ branches: Array<{
267
+ name: string;
268
+ target: string;
269
+ conditions: EdgeCondition[];
270
+ logic: 'AND' | 'OR';
271
+ priority?: number;
272
+ }>;
273
+ default?: string;
274
+ nodeConfig?: NodeDefinition<TState>['config'];
275
+ }): NodeDefinition<TState>;
276
+ //# sourceMappingURL=decision-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision-node.d.ts","sourceRoot":"","sources":["../../src/nodes/decision-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EAGd,aAAa,EAEd,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wBAAwB;IACxB,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,4CAA4C;IAC5C,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,iEAAiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACnE;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kCAAkC;IAClC,QAAQ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