@langchain/langgraph 1.1.0 → 1.1.2
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/dist/errors.d.cts.map +1 -1
- package/dist/graph/annotation.cjs +3 -0
- package/dist/graph/annotation.cjs.map +1 -1
- package/dist/graph/annotation.d.cts +1 -0
- package/dist/graph/annotation.d.cts.map +1 -1
- package/dist/graph/annotation.d.ts +1 -0
- package/dist/graph/annotation.d.ts.map +1 -1
- package/dist/graph/annotation.js +3 -0
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +3 -3
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.js +3 -3
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/message.d.cts +2 -2
- package/dist/graph/message.d.cts.map +1 -1
- package/dist/graph/message.d.ts +2 -2
- package/dist/graph/message.d.ts.map +1 -1
- package/dist/graph/messages_annotation.d.cts +5 -5
- package/dist/graph/messages_annotation.d.cts.map +1 -1
- package/dist/graph/messages_annotation.d.ts +5 -5
- package/dist/graph/messages_annotation.d.ts.map +1 -1
- package/dist/graph/state.cjs +98 -78
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +68 -35
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +68 -35
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +99 -79
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/types.cjs +41 -0
- package/dist/graph/types.cjs.map +1 -0
- package/dist/graph/types.d.cts +247 -18
- package/dist/graph/types.d.cts.map +1 -1
- package/dist/graph/types.d.ts +247 -18
- package/dist/graph/types.d.ts.map +1 -1
- package/dist/graph/types.js +40 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/graph/zod/meta.cjs +4 -4
- package/dist/graph/zod/meta.cjs.map +1 -1
- package/dist/graph/zod/meta.js +4 -4
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/zod-registry.d.cts.map +1 -1
- package/dist/graph/zod/zod-registry.d.ts.map +1 -1
- package/dist/hash.cjs +1 -1
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.js +1 -1
- package/dist/hash.js.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/prebuilt/agent_executor.d.cts +5 -5
- package/dist/prebuilt/agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/agent_executor.d.ts +5 -5
- package/dist/prebuilt/agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.cjs +12 -12
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +3 -3
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.ts +3 -3
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.js +12 -12
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +1 -1
- package/dist/prebuilt/tool_node.cjs.map +1 -1
- package/dist/prebuilt/tool_node.js +1 -1
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/debug.cjs +9 -9
- package/dist/pregel/debug.cjs.map +1 -1
- package/dist/pregel/debug.js +9 -9
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +44 -44
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.js +44 -44
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +1 -1
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +1 -1
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/utils/subgraph.cjs +2 -2
- package/dist/pregel/utils/subgraph.cjs.map +1 -1
- package/dist/pregel/utils/subgraph.js +2 -2
- package/dist/pregel/utils/subgraph.js.map +1 -1
- package/dist/state/schema.cjs +8 -9
- package/dist/state/schema.cjs.map +1 -1
- package/dist/state/schema.d.cts +18 -22
- package/dist/state/schema.d.cts.map +1 -1
- package/dist/state/schema.d.ts +18 -22
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +8 -9
- package/dist/state/schema.js.map +1 -1
- package/dist/state/values/reduced.cjs.map +1 -1
- package/dist/state/values/reduced.d.cts +1 -1
- package/dist/state/values/reduced.d.cts.map +1 -1
- package/dist/state/values/reduced.d.ts +1 -1
- package/dist/state/values/reduced.d.ts.map +1 -1
- package/dist/state/values/reduced.js.map +1 -1
- package/dist/state/values/untracked.cjs.map +1 -1
- package/dist/state/values/untracked.d.cts +4 -0
- package/dist/state/values/untracked.d.cts.map +1 -1
- package/dist/state/values/untracked.d.ts +4 -0
- package/dist/state/values/untracked.d.ts.map +1 -1
- package/dist/state/values/untracked.js.map +1 -1
- package/dist/web.d.cts +3 -3
- package/dist/web.d.ts +3 -3
- package/package.json +6 -6
package/dist/graph/types.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { InteropZodToStateDefinition } from "./zod/meta.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { LangGraphRunnableConfig } from "../pregel/runnable_types.cjs";
|
|
3
3
|
import { AnnotationRoot, StateDefinition, StateType, UpdateType } from "./annotation.cjs";
|
|
4
4
|
import { CommandInstance, END, Send } from "../constants.cjs";
|
|
5
5
|
import { AnyStateSchema, StateSchema, StateSchemaFieldsToStateDefinition } from "../state/schema.cjs";
|
|
6
6
|
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
7
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
8
|
|
|
8
9
|
//#region src/graph/types.d.ts
|
|
9
10
|
|
|
@@ -12,13 +13,72 @@ import { InteropZodObject } from "@langchain/core/utils/types";
|
|
|
12
13
|
*
|
|
13
14
|
* @internal
|
|
14
15
|
*/
|
|
15
|
-
type ToStateDefinition<T> = T extends StateSchema<infer TInit> ? StateSchemaFieldsToStateDefinition<TInit> : T extends InteropZodObject ? InteropZodToStateDefinition<T> : T extends StateDefinition ? T : never;
|
|
16
|
+
type ToStateDefinition<T> = T extends StateSchema<infer TInit> ? StateSchemaFieldsToStateDefinition<TInit> : T extends AnnotationRoot<infer SD> ? SD : T extends InteropZodObject ? InteropZodToStateDefinition<T> : T extends StateDefinition ? T : never;
|
|
16
17
|
/**
|
|
17
18
|
* Type for schema types that can be used to initialize state.
|
|
19
|
+
* Supports all valid schema types: StateDefinition, Zod objects, StateSchema, and AnnotationRoot.
|
|
18
20
|
*
|
|
19
21
|
* @internal
|
|
20
22
|
*/
|
|
21
|
-
type StateDefinitionInit = StateDefinition | InteropZodObject | AnyStateSchema
|
|
23
|
+
type StateDefinitionInit = StateDefinition | InteropZodObject | AnyStateSchema | AnnotationRoot<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a value is a valid StateDefinitionInit type.
|
|
26
|
+
* Supports: StateSchema, InteropZodObject (Zod), AnnotationRoot, StateDefinition
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Valid types for context schema.
|
|
33
|
+
* Context doesn't have channels/reducers, so StateSchema is NOT supported.
|
|
34
|
+
* Supports StandardSchemaV1 (Zod, Valibot, etc.) and AnnotationRoot (backward compat).
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
type ContextSchemaInit = StandardSchemaV1 | AnnotationRoot<StateDefinition>;
|
|
39
|
+
/**
|
|
40
|
+
* Initialization options for StateGraph.
|
|
41
|
+
* Accepts any combination of schema types for state/input/output.
|
|
42
|
+
*
|
|
43
|
+
* Supports both `state` and `stateSchema` as aliases for backward compatibility.
|
|
44
|
+
* If only `input` is provided (no state/stateSchema), `input` is used as the state schema.
|
|
45
|
+
*
|
|
46
|
+
* @template SD - State definition type
|
|
47
|
+
* @template I - Input definition type (defaults to undefined)
|
|
48
|
+
* @template O - Output definition type (defaults to undefined)
|
|
49
|
+
* @template C - Context schema type (defaults to undefined)
|
|
50
|
+
* @template N - Node name union type (defaults to string)
|
|
51
|
+
* @template InterruptType - Interrupt type (defaults to unknown)
|
|
52
|
+
* @template WriterType - Writer type (defaults to unknown)
|
|
53
|
+
*/
|
|
54
|
+
type StateGraphInit<SD extends StateDefinitionInit = StateDefinitionInit, I extends StateDefinitionInit | undefined = undefined, O extends StateDefinitionInit | undefined = undefined, C extends StateDefinitionInit | undefined = undefined, N extends string = string, InterruptType = unknown, WriterType = unknown> = {
|
|
55
|
+
/** Primary key for state schema */
|
|
56
|
+
state?: SD;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use `state` instead. Will be removed in a future version.
|
|
59
|
+
*/
|
|
60
|
+
stateSchema?: SD;
|
|
61
|
+
input?: I;
|
|
62
|
+
output?: O;
|
|
63
|
+
/** Context schema for runtime configuration validation. Does not support StateSchema. */
|
|
64
|
+
context?: C;
|
|
65
|
+
interrupt?: InterruptType;
|
|
66
|
+
writer?: WriterType;
|
|
67
|
+
nodes?: N[];
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Options for the second argument when passing a direct schema.
|
|
71
|
+
* Excludes `state` and `stateSchema` since those come from the first arg.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
type StateGraphOptions<I extends StateDefinitionInit | undefined = undefined, O extends StateDefinitionInit | undefined = undefined, C extends StateDefinitionInit | undefined = undefined, N extends string = string, InterruptType = unknown, WriterType = unknown> = Omit<StateGraphInit<StateDefinitionInit, I, O, C, N, InterruptType, WriterType>, "state" | "stateSchema">;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a value is a StateGraphInit object (has state, stateSchema, or input with valid schema).
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
|
|
22
82
|
/**
|
|
23
83
|
* Extract the State type from any supported schema type.
|
|
24
84
|
*
|
|
@@ -48,9 +108,88 @@ type ExtractStateType<Schema, Fallback = Schema> = Schema extends AnnotationRoot
|
|
|
48
108
|
* @template FallbackBase - Base type for fallback (will be partialized), defaults to Schema
|
|
49
109
|
*/
|
|
50
110
|
type ExtractUpdateType<Schema, FallbackBase = Schema> = Schema extends AnnotationRoot<infer SD> ? UpdateType<SD> : UpdateType<ToStateDefinition<Schema>> extends infer U ? [U] extends [never] ? Partial<FallbackBase> : U : Partial<FallbackBase>;
|
|
111
|
+
/**
|
|
112
|
+
* Extract the input type from a type bag, using ExtractStateType on the InputSchema.
|
|
113
|
+
* Falls back to Default if InputSchema is not provided.
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
type ExtractBagInput<Bag, Default> = Bag extends {
|
|
117
|
+
InputSchema: infer I;
|
|
118
|
+
} ? ExtractStateType<I> : Default;
|
|
119
|
+
/**
|
|
120
|
+
* Extract the output type from a type bag, using ExtractUpdateType on the OutputSchema.
|
|
121
|
+
* Falls back to Default if OutputSchema is not provided.
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
type ExtractBagOutput<Bag, Default> = Bag extends {
|
|
125
|
+
OutputSchema: infer O;
|
|
126
|
+
} ? ExtractUpdateType<O> : Default;
|
|
127
|
+
/**
|
|
128
|
+
* Extract the context type from a type bag, using ExtractStateType on the ContextSchema.
|
|
129
|
+
* Falls back to Default if ContextSchema is not provided.
|
|
130
|
+
* Ensures result extends Record<string, unknown> for LangGraphRunnableConfig compatibility.
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
type ExtractBagContext<Bag, Default extends Record<string, unknown>> = Bag extends {
|
|
134
|
+
ContextSchema: infer C;
|
|
135
|
+
} ? ExtractStateType<C> extends infer Ctx ? Ctx extends Record<string, unknown> ? Ctx : Default : Default : Default;
|
|
136
|
+
/**
|
|
137
|
+
* Extract the Nodes type from a type bag.
|
|
138
|
+
* Falls back to Default if Nodes is not provided.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
type ExtractBagNodes<Bag, Default extends string> = Bag extends {
|
|
142
|
+
Nodes: infer N extends string;
|
|
143
|
+
} ? N : Default;
|
|
144
|
+
/**
|
|
145
|
+
* Type bag for GraphNode that accepts schema types.
|
|
146
|
+
* All fields are optional - unspecified fields use defaults.
|
|
147
|
+
*
|
|
148
|
+
* This enables separate input/output schemas for nodes, which is useful when
|
|
149
|
+
* a node receives a subset of state fields and returns different fields.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const node: GraphNode<{
|
|
154
|
+
* InputSchema: typeof NodeInputSchema;
|
|
155
|
+
* OutputSchema: typeof NodeOutputSchema;
|
|
156
|
+
* ContextSchema: typeof ContextSchema;
|
|
157
|
+
* Nodes: "agent" | "tool";
|
|
158
|
+
* }> = (state, runtime) => {
|
|
159
|
+
* return { answer: `Response to: ${state.query}` };
|
|
160
|
+
* };
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
interface GraphNodeTypes<InputSchema = unknown, OutputSchema = unknown, ContextSchema = unknown, Nodes extends string = string> {
|
|
164
|
+
/** Schema for node input state (uses ExtractStateType) */
|
|
165
|
+
InputSchema?: InputSchema;
|
|
166
|
+
/** Schema for node output/update (uses ExtractUpdateType) */
|
|
167
|
+
OutputSchema?: OutputSchema;
|
|
168
|
+
/** Schema for runtime context (uses ExtractStateType) */
|
|
169
|
+
ContextSchema?: ContextSchema;
|
|
170
|
+
/** Union of valid node names for Command.goto */
|
|
171
|
+
Nodes?: Nodes;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Detect if T is a type bag (has InputSchema or OutputSchema) or a direct schema.
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
type IsGraphNodeTypeBag<T> = T extends {
|
|
178
|
+
InputSchema: unknown;
|
|
179
|
+
} ? true : T extends {
|
|
180
|
+
OutputSchema: unknown;
|
|
181
|
+
} ? true : false;
|
|
182
|
+
/**
|
|
183
|
+
* Return value type for GraphNode functions.
|
|
184
|
+
* Nodes can return an update object, a Command, or a Promise of either.
|
|
185
|
+
*
|
|
186
|
+
* @template Update - The update type (what fields can be returned)
|
|
187
|
+
* @template Nodes - Union of valid node names for Command.goto
|
|
188
|
+
*/
|
|
189
|
+
type GraphNodeReturnValue<Update, Nodes extends string = string> = Update | CommandInstance<unknown, Update, Nodes> | Promise<Update | CommandInstance<unknown, Update, Nodes>>;
|
|
51
190
|
/**
|
|
52
191
|
* Strongly-typed utility for authoring graph nodes outside of the StateGraph builder,
|
|
53
|
-
* supporting inference for both state (from Schema) and
|
|
192
|
+
* supporting inference for both state (from Schema) and config context (from Context type).
|
|
54
193
|
*
|
|
55
194
|
* This type enables you to define graph node functions with full type safety—both
|
|
56
195
|
* for the evolving state and for additional context that may be passed in at runtime.
|
|
@@ -59,11 +198,19 @@ type ExtractUpdateType<Schema, FallbackBase = Schema> = Schema extends Annotatio
|
|
|
59
198
|
* Works with StateSchema, AnnotationRoot, and Zod object schemas for state, and
|
|
60
199
|
* with a user-defined object shape for context.
|
|
61
200
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
201
|
+
* **Supports two patterns:**
|
|
202
|
+
*
|
|
203
|
+
* 1. **Single schema usage** - Single schema for both input and output:
|
|
204
|
+
* `GraphNode<Schema, Context, Nodes>`
|
|
205
|
+
*
|
|
206
|
+
* 2. **Type bag pattern** - Separate schemas for input, output, context:
|
|
207
|
+
* `GraphNode<{ InputSchema; OutputSchema; ContextSchema; Nodes }>`
|
|
208
|
+
*
|
|
209
|
+
* @template Schema - The state schema type (StateSchema, AnnotationRoot, InteropZodObject) OR a type bag
|
|
210
|
+
* @template Context - The type of the context passed into this node (default: Record<string, unknown>)
|
|
64
211
|
* @template Nodes - An optional union of valid node names for Command.goto, used for type-safe routing (default: string)
|
|
65
212
|
*
|
|
66
|
-
* @example
|
|
213
|
+
* @example Single schema usage
|
|
67
214
|
* ```typescript
|
|
68
215
|
* import { StateSchema, GraphNode } from "@langchain/langgraph";
|
|
69
216
|
* import { z } from "zod/v4";
|
|
@@ -76,14 +223,14 @@ type ExtractUpdateType<Schema, FallbackBase = Schema> = Schema extends Annotatio
|
|
|
76
223
|
* // Context shape for custom node logic (optional)
|
|
77
224
|
* type MyContext = { userId: string };
|
|
78
225
|
*
|
|
79
|
-
* // Node receiving state and
|
|
80
|
-
* const processNode: GraphNode<typeof AgentState, MyContext> = (state,
|
|
81
|
-
* const
|
|
226
|
+
* // Node receiving state and config
|
|
227
|
+
* const processNode: GraphNode<typeof AgentState, MyContext> = (state, config) => {
|
|
228
|
+
* const userId = config.configurable?.userId; // type-safe context access
|
|
82
229
|
* return { step: state.step + 1 };
|
|
83
230
|
* };
|
|
84
231
|
*
|
|
85
232
|
* // Node with type-safe graph routing
|
|
86
|
-
* const routerNode: GraphNode<typeof AgentState, MyContext, "agent" | "tool"> = (state,
|
|
233
|
+
* const routerNode: GraphNode<typeof AgentState, MyContext, "agent" | "tool"> = (state, config) => {
|
|
87
234
|
* if (state.needsTool) {
|
|
88
235
|
* return new Command({ goto: "tool", update: { step: state.step + 1 } });
|
|
89
236
|
* }
|
|
@@ -96,32 +243,114 @@ type ExtractUpdateType<Schema, FallbackBase = Schema> = Schema extends Annotatio
|
|
|
96
243
|
* .addNode("router", routerNode)
|
|
97
244
|
* .compile();
|
|
98
245
|
* ```
|
|
246
|
+
*
|
|
247
|
+
* @example Type bag pattern - separate input/output schemas
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const InputSchema = new StateSchema({
|
|
250
|
+
* messages: z.array(z.string()),
|
|
251
|
+
* query: z.string(),
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* const OutputSchema = new StateSchema({
|
|
255
|
+
* answer: z.string(),
|
|
256
|
+
* });
|
|
257
|
+
*
|
|
258
|
+
* const ContextSchema = z.object({ userId: z.string() });
|
|
259
|
+
*
|
|
260
|
+
* const node: GraphNode<{
|
|
261
|
+
* InputSchema: typeof InputSchema;
|
|
262
|
+
* OutputSchema: typeof OutputSchema;
|
|
263
|
+
* ContextSchema: typeof ContextSchema;
|
|
264
|
+
* Nodes: "agent" | "tool";
|
|
265
|
+
* }> = (state, config) => {
|
|
266
|
+
* // state is { messages: string[]; query: string }
|
|
267
|
+
* // config.configurable is { userId: string } | undefined
|
|
268
|
+
* return { answer: `Response to: ${state.query}` };
|
|
269
|
+
* };
|
|
270
|
+
* ```
|
|
99
271
|
*/
|
|
100
|
-
type GraphNode<Schema, Context = Record<string,
|
|
272
|
+
type GraphNode<Schema, Context extends Record<string, any> = Record<string, any>, Nodes extends string = string> = IsGraphNodeTypeBag<Schema> extends true ? (state: ExtractBagInput<Schema, unknown>, config: LangGraphRunnableConfig<ExtractBagContext<Schema, Record<string, unknown>>>) => GraphNodeReturnValue<ExtractBagOutput<Schema, Partial<ExtractBagInput<Schema, unknown>>>, ExtractBagNodes<Schema, string>> : (state: ExtractStateType<Schema>, config: LangGraphRunnableConfig<Context>) => GraphNodeReturnValue<ExtractUpdateType<Schema>, Nodes>;
|
|
273
|
+
/**
|
|
274
|
+
* Type bag for ConditionalEdgeRouter that accepts schema types.
|
|
275
|
+
* Unlike GraphNodeTypes, conditional edges don't have separate input/output -
|
|
276
|
+
* they just read state and return routing decisions.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const router: ConditionalEdgeRouter<{
|
|
281
|
+
* Schema: typeof StateSchema;
|
|
282
|
+
* ContextSchema: typeof ContextSchema;
|
|
283
|
+
* Nodes: "agent" | "tool";
|
|
284
|
+
* }> = (state, config) => {
|
|
285
|
+
* return state.done ? END : "agent";
|
|
286
|
+
* };
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
interface ConditionalEdgeRouterTypes<InputSchema = unknown, ContextSchema = unknown, Nodes extends string = string> {
|
|
290
|
+
/** Schema for router state (uses ExtractStateType) */
|
|
291
|
+
InputSchema?: InputSchema;
|
|
292
|
+
/** Schema for runtime context (uses ExtractStateType) */
|
|
293
|
+
ContextSchema?: ContextSchema;
|
|
294
|
+
/** Union of valid node names that can be routed to */
|
|
295
|
+
Nodes?: Nodes;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Detect if T is a ConditionalEdgeRouterTypes bag.
|
|
299
|
+
* @internal
|
|
300
|
+
*/
|
|
301
|
+
type IsConditionalEdgeRouterTypeBag<T> = T extends {
|
|
302
|
+
InputSchema: unknown;
|
|
303
|
+
} ? true : T extends {
|
|
304
|
+
ContextSchema: unknown;
|
|
305
|
+
} ? true : false;
|
|
306
|
+
/**
|
|
307
|
+
* Return type for conditional edge routing functions.
|
|
308
|
+
*/
|
|
309
|
+
type ConditionalEdgeRouterReturnValue<Nodes extends string, State> = Nodes | typeof END | Send<Nodes, State> | Array<Nodes | Send<Nodes, State>>;
|
|
101
310
|
/**
|
|
102
311
|
* Type for conditional edge routing functions.
|
|
103
312
|
*
|
|
104
313
|
* Use this to type functions passed to `addConditionalEdges` for
|
|
105
314
|
* full type safety on state, runtime context, and return values.
|
|
106
315
|
*
|
|
107
|
-
*
|
|
316
|
+
* **Supports two patterns:**
|
|
317
|
+
*
|
|
318
|
+
* 1. **Single schema pattern** - Single schema:
|
|
319
|
+
* `ConditionalEdgeRouter<Schema, Context, Nodes>`
|
|
320
|
+
*
|
|
321
|
+
* 2. **Type bag pattern** - Separate schemas for state, context:
|
|
322
|
+
* `ConditionalEdgeRouter<{ Schema; ContextSchema; Nodes }>`
|
|
323
|
+
*
|
|
324
|
+
* @template Schema - The state schema type OR a type bag
|
|
108
325
|
* @template Context - The runtime context type available to node logic
|
|
109
326
|
* @template Nodes - Union of valid node names that can be routed to
|
|
110
327
|
*
|
|
111
|
-
* @example
|
|
328
|
+
* @example Single schema pattern
|
|
112
329
|
* ```typescript
|
|
113
330
|
* type MyContext = { userId: string };
|
|
114
331
|
* const router: ConditionalEdgeRouter<typeof AgentState, MyContext, "agent" | "tool"> =
|
|
115
|
-
* (state,
|
|
116
|
-
*
|
|
332
|
+
* (state, config) => {
|
|
333
|
+
* const userId = config.context?.userId;
|
|
117
334
|
* if (state.done) return END;
|
|
118
335
|
* return state.needsTool ? "tool" : "agent";
|
|
119
336
|
* };
|
|
120
337
|
*
|
|
121
338
|
* graph.addConditionalEdges("router", router, ["agent", "tool"]);
|
|
122
339
|
* ```
|
|
340
|
+
*
|
|
341
|
+
* @example Type bag pattern
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const router: ConditionalEdgeRouter<{
|
|
344
|
+
* Schema: typeof StateSchema;
|
|
345
|
+
* ContextSchema: typeof ContextSchema;
|
|
346
|
+
* Nodes: "agent" | "tool";
|
|
347
|
+
* }> = (state, config) => {
|
|
348
|
+
* if (state.done) return END;
|
|
349
|
+
* return "agent";
|
|
350
|
+
* };
|
|
351
|
+
* ```
|
|
123
352
|
*/
|
|
124
|
-
type ConditionalEdgeRouter<Schema, Context = Record<string,
|
|
353
|
+
type ConditionalEdgeRouter<Schema, Context extends Record<string, any> = Record<string, any>, Nodes extends string = string> = IsConditionalEdgeRouterTypeBag<Schema> extends true ? (state: ExtractBagInput<Schema, unknown>, config: LangGraphRunnableConfig<ExtractBagContext<Schema, Record<string, unknown>>>) => ConditionalEdgeRouterReturnValue<ExtractBagNodes<Schema, string>, ExtractBagInput<Schema, unknown>> | Promise<ConditionalEdgeRouterReturnValue<ExtractBagNodes<Schema, string>, ExtractBagInput<Schema, unknown>>> : (state: ExtractStateType<Schema>, config: LangGraphRunnableConfig<Context>) => ConditionalEdgeRouterReturnValue<Nodes, ExtractStateType<Schema>> | Promise<ConditionalEdgeRouterReturnValue<Nodes, ExtractStateType<Schema>>>;
|
|
125
354
|
//#endregion
|
|
126
|
-
export { ConditionalEdgeRouter, ExtractStateType, ExtractUpdateType, GraphNode, StateDefinitionInit, ToStateDefinition };
|
|
355
|
+
export { ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ExtractStateType, ExtractUpdateType, GraphNode, GraphNodeReturnValue, GraphNodeTypes, StateDefinitionInit, StateGraphInit, StateGraphOptions, ToStateDefinition };
|
|
127
356
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":["InteropZodObject","Runtime","CommandInstance","Send","END","AnnotationRoot","StateDefinition","StateType","UpdateType","AnnotationUpdateType","AnyStateSchema","StateSchema","StateSchemaFieldsToStateDefinition","InteropZodToStateDefinition","ToStateDefinition","T","TInit","StateDefinitionInit","ExtractStateType","Schema","SD","S","Fallback","ExtractUpdateType","U","FallbackBase","Partial","GraphNode","Record","Context","Nodes","Promise","ConditionalEdgeRouter","Array"],"sources":["../../src/graph/types.d.ts"],"sourcesContent":["import type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport type { Runtime } from \"../pregel/runnable_types.js\";\nimport type { CommandInstance, Send } from \"../constants.js\";\nimport { END } from \"../constants.js\";\nimport type { AnnotationRoot, StateDefinition, StateType, UpdateType as AnnotationUpdateType } from \"./annotation.js\";\nimport type { AnyStateSchema, StateSchema, StateSchemaFieldsToStateDefinition } from \"../state/schema.js\";\nimport type { InteropZodToStateDefinition } from \"./zod/meta.js\";\nexport { END };\n/**\n * Convert any supported schema type to a StateDefinition.\n *\n * @internal\n */\nexport type ToStateDefinition<T> = T extends StateSchema<infer TInit> ? StateSchemaFieldsToStateDefinition<TInit> : T extends InteropZodObject ? InteropZodToStateDefinition<T> : T extends StateDefinition ? T : never;\n/**\n * Type for schema types that can be used to initialize state.\n *\n * @internal\n */\nexport type StateDefinitionInit = StateDefinition | InteropZodObject | AnyStateSchema;\n/**\n * Extract the State type from any supported schema type.\n *\n * Supports:\n * - StateSchema\n * - AnnotationRoot\n * - StateDefinition (internal channel definitions)\n * - InteropZodObject (Zod v3/v4 object schemas)\n *\n * @template Schema - The schema type to extract state from\n * @template Fallback - Type to return if schema doesn't match (default: never)\n */\nexport type ExtractStateType<Schema, Fallback = Schema> = Schema extends AnnotationRoot<infer SD> ? StateType<SD> : StateType<ToStateDefinition<Schema>> extends infer S ? [S] extends [never] ? Fallback : S : Fallback;\n/**\n * Extract the Update type from any supported schema type.\n *\n * The Update type represents what a node can return to update the state.\n * All fields are optional since nodes only need to return the fields they modify.\n *\n * Supports:\n * - StateSchema\n * - AnnotationRoot\n * - StateDefinition (internal channel definitions)\n * - InteropZodObject (Zod v3/v4 object schemas)\n *\n * @template Schema - The schema type to extract update type from\n * @template FallbackBase - Base type for fallback (will be partialized), defaults to Schema\n */\nexport type ExtractUpdateType<Schema, FallbackBase = Schema> = Schema extends AnnotationRoot<infer SD> ? AnnotationUpdateType<SD> : AnnotationUpdateType<ToStateDefinition<Schema>> extends infer U ? [U] extends [never] ? Partial<FallbackBase> : U : Partial<FallbackBase>;\n/**\n * Strongly-typed utility for authoring graph nodes outside of the StateGraph builder,\n * supporting inference for both state (from Schema) and runtime context (from ContextType).\n *\n * This type enables you to define graph node functions with full type safety—both\n * for the evolving state and for additional context that may be passed in at runtime.\n * Typing the context parameter allows for better code organization and precise editor support.\n *\n * Works with StateSchema, AnnotationRoot, and Zod object schemas for state, and\n * with a user-defined object shape for context.\n *\n * @template Schema - The state schema type (StateSchema, AnnotationRoot, or InteropZodObject)\n * @template Context - The type of the runtime context injected into this node (default: Record<string, unknown>)\n * @template Nodes - An optional union of valid node names for Command.goto, used for type-safe routing (default: string)\n *\n * @example\n * ```typescript\n * import { StateSchema, GraphNode } from \"@langchain/langgraph\";\n * import { z } from \"zod/v4\";\n *\n * const AgentState = new StateSchema({\n * messages: MessagesValue,\n * step: z.number().default(0),\n * });\n *\n * // Context shape for custom node logic (optional)\n * type MyContext = { userId: string };\n *\n * // Node receiving state and context\n * const processNode: GraphNode<typeof AgentState, MyContext> = (state, runtime) => {\n * const { userId } = runtime; // type-safe context access\n * return { step: state.step + 1 };\n * };\n *\n * // Node with type-safe graph routing\n * const routerNode: GraphNode<typeof AgentState, MyContext, \"agent\" | \"tool\"> = (state, runtime) => {\n * if (state.needsTool) {\n * return new Command({ goto: \"tool\", update: { step: state.step + 1 } });\n * }\n * return new Command({ goto: \"agent\" });\n * };\n *\n * // Use in graph\n * const graph = new StateGraph(AgentState)\n * .addNode(\"process\", processNode)\n * .addNode(\"router\", routerNode)\n * .compile();\n * ```\n */\nexport type GraphNode<Schema, Context = Record<string, unknown>, Nodes extends string = string> = (state: ExtractStateType<Schema>, runtime: Runtime<Context>) => ExtractUpdateType<Schema> | CommandInstance<unknown, ExtractUpdateType<Schema>, Nodes> | Promise<ExtractUpdateType<Schema> | CommandInstance<unknown, ExtractUpdateType<Schema>, Nodes>>;\n/**\n * Type for conditional edge routing functions.\n *\n * Use this to type functions passed to `addConditionalEdges` for\n * full type safety on state, runtime context, and return values.\n *\n * @template Schema - The state schema type\n * @template Context - The runtime context type available to node logic\n * @template Nodes - Union of valid node names that can be routed to\n *\n * @example\n * ```typescript\n * type MyContext = { userId: string };\n * const router: ConditionalEdgeRouter<typeof AgentState, MyContext, \"agent\" | \"tool\"> =\n * (state, runtime) => {\n * // Access runtime context as type-safe: runtime.userId\n * if (state.done) return END;\n * return state.needsTool ? \"tool\" : \"agent\";\n * };\n *\n * graph.addConditionalEdges(\"router\", router, [\"agent\", \"tool\"]);\n * ```\n */\nexport type ConditionalEdgeRouter<Schema, Context = Record<string, unknown>, Nodes extends string = string> = (state: ExtractStateType<Schema>, runtime: Runtime<Context>) => Nodes | typeof END | Send<Nodes, ExtractStateType<Schema>> | Array<Nodes | Send<Nodes, ExtractStateType<Schema>>>;\n"],"mappings":";;;;;;;;;AAaA;;;;;AAAwEY,KAA5DE,iBAA4DF,CAAAA,CAAAA,CAAAA,GAArCG,CAAqCH,SAA3BD,WAA2BC,CAAAA,KAAAA,MAAAA,CAAAA,GAAAA,kCAAAA,CAAmCI,KAAnCJ,CAAAA,GAA4CG,CAA5CH,SAAsDZ,gBAAtDY,GAAyEC,2BAAzED,CAAqGG,CAArGH,CAAAA,GAA0GG,CAA1GH,SAAoHN,eAApHM,GAAsIG,CAAtIH,GAAAA,KAAAA;;;;;;AAAoHN,KAMhLW,mBAAAA,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OAwBoG1B,CAAAA,EAAAA,GAxBvFoB,iBAwBuFpB,CAxBrEgB,MAwBqEhB,CAAAA,GAxB3DD,eAwB2DC,CAAAA,OAAAA,EAxBlCoB,iBAwBkCpB,CAxBhBgB,MAwBgBhB,CAAAA,EAxBP2B,KAwBO3B,CAAAA,GAxBE4B,OAwBF5B,CAxBUoB,iBAwBVpB,CAxB4BgB,MAwB5BhB,CAAAA,GAxBsCD,eAwBtCC,CAAAA,OAAAA,EAxB+DoB,iBAwB/DpB,CAxBiFgB,MAwBjFhB,CAAAA,EAxB0F2B,KAwB1F3B,CAAAA,CAAAA;;;;;;;;;;;;;;;;;;;;;;;;KAA7O6B,wCAAwCJ,kEAAkEV,iBAAiBC,kBAAkBlB,QAAQ4B,aAAaC,eAAe1B,MAAMD,KAAK2B,OAAOZ,iBAAiBC,WAAWc,MAAMH,QAAQ3B,KAAK2B,OAAOZ,iBAAiBC"}
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":["InteropZodObject","StandardSchemaV1","LangGraphRunnableConfig","CommandInstance","Send","END","AnnotationRoot","StateDefinition","StateType","UpdateType","AnnotationUpdateType","AnyStateSchema","StateSchema","StateSchemaFieldsToStateDefinition","InteropZodToStateDefinition","ToStateDefinition","T","TInit","SD","StateDefinitionInit","isStateDefinitionInit","ContextSchemaInit","StateGraphInit","I","O","C","InterruptType","WriterType","N","StateGraphOptions","Omit","isStateGraphInit","ExtractStateType","Schema","S","Fallback","ExtractUpdateType","U","FallbackBase","Partial","ExtractBagInput","Bag","Default","ExtractBagOutput","ExtractBagContext","Record","Ctx","ExtractBagNodes","GraphNodeTypes","InputSchema","OutputSchema","ContextSchema","Nodes","IsGraphNodeTypeBag","GraphNodeReturnValue","Update","Promise","GraphNode","Context","ConditionalEdgeRouterTypes","IsConditionalEdgeRouterTypeBag","ConditionalEdgeRouterReturnValue","State","Array","ConditionalEdgeRouter"],"sources":["../../src/graph/types.d.ts"],"sourcesContent":["import { type InteropZodObject } from \"@langchain/core/utils/types\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { LangGraphRunnableConfig } from \"../pregel/runnable_types.js\";\nimport type { CommandInstance, Send } from \"../constants.js\";\nimport { END } from \"../constants.js\";\nimport type { AnnotationRoot, StateDefinition, StateType, UpdateType as AnnotationUpdateType } from \"./annotation.js\";\nimport { AnyStateSchema, StateSchema, StateSchemaFieldsToStateDefinition } from \"../state/schema.js\";\nimport type { InteropZodToStateDefinition } from \"./zod/meta.js\";\nexport { END };\n/**\n * Convert any supported schema type to a StateDefinition.\n *\n * @internal\n */\nexport type ToStateDefinition<T> = T extends StateSchema<infer TInit> ? StateSchemaFieldsToStateDefinition<TInit> : T extends AnnotationRoot<infer SD> ? SD : T extends InteropZodObject ? InteropZodToStateDefinition<T> : T extends StateDefinition ? T : never;\n/**\n * Type for schema types that can be used to initialize state.\n * Supports all valid schema types: StateDefinition, Zod objects, StateSchema, and AnnotationRoot.\n *\n * @internal\n */\nexport type StateDefinitionInit = StateDefinition | InteropZodObject | AnyStateSchema | AnnotationRoot<any>;\n/**\n * Check if a value is a valid StateDefinitionInit type.\n * Supports: StateSchema, InteropZodObject (Zod), AnnotationRoot, StateDefinition\n *\n * @internal\n */\nexport declare function isStateDefinitionInit(value: unknown): value is StateDefinitionInit;\n/**\n * Valid types for context schema.\n * Context doesn't have channels/reducers, so StateSchema is NOT supported.\n * Supports StandardSchemaV1 (Zod, Valibot, etc.) and AnnotationRoot (backward compat).\n *\n * @internal\n */\nexport type ContextSchemaInit = StandardSchemaV1 | AnnotationRoot<StateDefinition>;\n/**\n * Initialization options for StateGraph.\n * Accepts any combination of schema types for state/input/output.\n *\n * Supports both `state` and `stateSchema` as aliases for backward compatibility.\n * If only `input` is provided (no state/stateSchema), `input` is used as the state schema.\n *\n * @template SD - State definition type\n * @template I - Input definition type (defaults to undefined)\n * @template O - Output definition type (defaults to undefined)\n * @template C - Context schema type (defaults to undefined)\n * @template N - Node name union type (defaults to string)\n * @template InterruptType - Interrupt type (defaults to unknown)\n * @template WriterType - Writer type (defaults to unknown)\n */\nexport type StateGraphInit<SD extends StateDefinitionInit = StateDefinitionInit, I extends StateDefinitionInit | undefined = undefined, O extends StateDefinitionInit | undefined = undefined, C extends StateDefinitionInit | undefined = undefined, N extends string = string, InterruptType = unknown, WriterType = unknown> = {\n /** Primary key for state schema */\n state?: SD;\n /**\n * @deprecated Use `state` instead. Will be removed in a future version.\n */\n stateSchema?: SD;\n input?: I;\n output?: O;\n /** Context schema for runtime configuration validation. Does not support StateSchema. */\n context?: C;\n interrupt?: InterruptType;\n writer?: WriterType;\n nodes?: N[];\n};\n/**\n * Options for the second argument when passing a direct schema.\n * Excludes `state` and `stateSchema` since those come from the first arg.\n *\n * @internal\n */\nexport type StateGraphOptions<I extends StateDefinitionInit | undefined = undefined, O extends StateDefinitionInit | undefined = undefined, C extends StateDefinitionInit | undefined = undefined, N extends string = string, InterruptType = unknown, WriterType = unknown> = Omit<StateGraphInit<StateDefinitionInit, I, O, C, N, InterruptType, WriterType>, \"state\" | \"stateSchema\">;\n/**\n * Check if a value is a StateGraphInit object (has state, stateSchema, or input with valid schema).\n *\n * @internal\n */\nexport declare function isStateGraphInit(value: unknown): value is StateGraphInit<StateDefinitionInit>;\n/**\n * Extract the State type from any supported schema type.\n *\n * Supports:\n * - StateSchema\n * - AnnotationRoot\n * - StateDefinition (internal channel definitions)\n * - InteropZodObject (Zod v3/v4 object schemas)\n *\n * @template Schema - The schema type to extract state from\n * @template Fallback - Type to return if schema doesn't match (default: never)\n */\nexport type ExtractStateType<Schema, Fallback = Schema> = Schema extends AnnotationRoot<infer SD> ? StateType<SD> : StateType<ToStateDefinition<Schema>> extends infer S ? [S] extends [never] ? Fallback : S : Fallback;\n/**\n * Extract the Update type from any supported schema type.\n *\n * The Update type represents what a node can return to update the state.\n * All fields are optional since nodes only need to return the fields they modify.\n *\n * Supports:\n * - StateSchema\n * - AnnotationRoot\n * - StateDefinition (internal channel definitions)\n * - InteropZodObject (Zod v3/v4 object schemas)\n *\n * @template Schema - The schema type to extract update type from\n * @template FallbackBase - Base type for fallback (will be partialized), defaults to Schema\n */\nexport type ExtractUpdateType<Schema, FallbackBase = Schema> = Schema extends AnnotationRoot<infer SD> ? AnnotationUpdateType<SD> : AnnotationUpdateType<ToStateDefinition<Schema>> extends infer U ? [U] extends [never] ? Partial<FallbackBase> : U : Partial<FallbackBase>;\n/**\n * Extract the input type from a type bag, using ExtractStateType on the InputSchema.\n * Falls back to Default if InputSchema is not provided.\n * @internal\n */\ntype ExtractBagInput<Bag, Default> = Bag extends {\n InputSchema: infer I;\n} ? ExtractStateType<I> : Default;\n/**\n * Extract the output type from a type bag, using ExtractUpdateType on the OutputSchema.\n * Falls back to Default if OutputSchema is not provided.\n * @internal\n */\ntype ExtractBagOutput<Bag, Default> = Bag extends {\n OutputSchema: infer O;\n} ? ExtractUpdateType<O> : Default;\n/**\n * Extract the context type from a type bag, using ExtractStateType on the ContextSchema.\n * Falls back to Default if ContextSchema is not provided.\n * Ensures result extends Record<string, unknown> for LangGraphRunnableConfig compatibility.\n * @internal\n */\ntype ExtractBagContext<Bag, Default extends Record<string, unknown>> = Bag extends {\n ContextSchema: infer C;\n} ? ExtractStateType<C> extends infer Ctx ? Ctx extends Record<string, unknown> ? Ctx : Default : Default : Default;\n/**\n * Extract the Nodes type from a type bag.\n * Falls back to Default if Nodes is not provided.\n * @internal\n */\ntype ExtractBagNodes<Bag, Default extends string> = Bag extends {\n Nodes: infer N extends string;\n} ? N : Default;\n/**\n * Type bag for GraphNode that accepts schema types.\n * All fields are optional - unspecified fields use defaults.\n *\n * This enables separate input/output schemas for nodes, which is useful when\n * a node receives a subset of state fields and returns different fields.\n *\n * @example\n * ```typescript\n * const node: GraphNode<{\n * InputSchema: typeof NodeInputSchema;\n * OutputSchema: typeof NodeOutputSchema;\n * ContextSchema: typeof ContextSchema;\n * Nodes: \"agent\" | \"tool\";\n * }> = (state, runtime) => {\n * return { answer: `Response to: ${state.query}` };\n * };\n * ```\n */\nexport interface GraphNodeTypes<InputSchema = unknown, OutputSchema = unknown, ContextSchema = unknown, Nodes extends string = string> {\n /** Schema for node input state (uses ExtractStateType) */\n InputSchema?: InputSchema;\n /** Schema for node output/update (uses ExtractUpdateType) */\n OutputSchema?: OutputSchema;\n /** Schema for runtime context (uses ExtractStateType) */\n ContextSchema?: ContextSchema;\n /** Union of valid node names for Command.goto */\n Nodes?: Nodes;\n}\n/**\n * Detect if T is a type bag (has InputSchema or OutputSchema) or a direct schema.\n * @internal\n */\ntype IsGraphNodeTypeBag<T> = T extends {\n InputSchema: unknown;\n} ? true : T extends {\n OutputSchema: unknown;\n} ? true : false;\n/**\n * Return value type for GraphNode functions.\n * Nodes can return an update object, a Command, or a Promise of either.\n *\n * @template Update - The update type (what fields can be returned)\n * @template Nodes - Union of valid node names for Command.goto\n */\nexport type GraphNodeReturnValue<Update, Nodes extends string = string> = Update | CommandInstance<unknown, Update, Nodes> | Promise<Update | CommandInstance<unknown, Update, Nodes>>;\n/**\n * Strongly-typed utility for authoring graph nodes outside of the StateGraph builder,\n * supporting inference for both state (from Schema) and config context (from Context type).\n *\n * This type enables you to define graph node functions with full type safety—both\n * for the evolving state and for additional context that may be passed in at runtime.\n * Typing the context parameter allows for better code organization and precise editor support.\n *\n * Works with StateSchema, AnnotationRoot, and Zod object schemas for state, and\n * with a user-defined object shape for context.\n *\n * **Supports two patterns:**\n *\n * 1. **Single schema usage** - Single schema for both input and output:\n * `GraphNode<Schema, Context, Nodes>`\n *\n * 2. **Type bag pattern** - Separate schemas for input, output, context:\n * `GraphNode<{ InputSchema; OutputSchema; ContextSchema; Nodes }>`\n *\n * @template Schema - The state schema type (StateSchema, AnnotationRoot, InteropZodObject) OR a type bag\n * @template Context - The type of the context passed into this node (default: Record<string, unknown>)\n * @template Nodes - An optional union of valid node names for Command.goto, used for type-safe routing (default: string)\n *\n * @example Single schema usage\n * ```typescript\n * import { StateSchema, GraphNode } from \"@langchain/langgraph\";\n * import { z } from \"zod/v4\";\n *\n * const AgentState = new StateSchema({\n * messages: MessagesValue,\n * step: z.number().default(0),\n * });\n *\n * // Context shape for custom node logic (optional)\n * type MyContext = { userId: string };\n *\n * // Node receiving state and config\n * const processNode: GraphNode<typeof AgentState, MyContext> = (state, config) => {\n * const userId = config.configurable?.userId; // type-safe context access\n * return { step: state.step + 1 };\n * };\n *\n * // Node with type-safe graph routing\n * const routerNode: GraphNode<typeof AgentState, MyContext, \"agent\" | \"tool\"> = (state, config) => {\n * if (state.needsTool) {\n * return new Command({ goto: \"tool\", update: { step: state.step + 1 } });\n * }\n * return new Command({ goto: \"agent\" });\n * };\n *\n * // Use in graph\n * const graph = new StateGraph(AgentState)\n * .addNode(\"process\", processNode)\n * .addNode(\"router\", routerNode)\n * .compile();\n * ```\n *\n * @example Type bag pattern - separate input/output schemas\n * ```typescript\n * const InputSchema = new StateSchema({\n * messages: z.array(z.string()),\n * query: z.string(),\n * });\n *\n * const OutputSchema = new StateSchema({\n * answer: z.string(),\n * });\n *\n * const ContextSchema = z.object({ userId: z.string() });\n *\n * const node: GraphNode<{\n * InputSchema: typeof InputSchema;\n * OutputSchema: typeof OutputSchema;\n * ContextSchema: typeof ContextSchema;\n * Nodes: \"agent\" | \"tool\";\n * }> = (state, config) => {\n * // state is { messages: string[]; query: string }\n * // config.configurable is { userId: string } | undefined\n * return { answer: `Response to: ${state.query}` };\n * };\n * ```\n */\nexport type GraphNode<Schema, Context extends Record<string, any> = Record<string, any>, Nodes extends string = string> = IsGraphNodeTypeBag<Schema> extends true ? (state: ExtractBagInput<Schema, unknown>, config: LangGraphRunnableConfig<ExtractBagContext<Schema, Record<string, unknown>>>) => GraphNodeReturnValue<ExtractBagOutput<Schema, Partial<ExtractBagInput<Schema, unknown>>>, ExtractBagNodes<Schema, string>> : (state: ExtractStateType<Schema>, config: LangGraphRunnableConfig<Context>) => GraphNodeReturnValue<ExtractUpdateType<Schema>, Nodes>;\n/**\n * Type bag for ConditionalEdgeRouter that accepts schema types.\n * Unlike GraphNodeTypes, conditional edges don't have separate input/output -\n * they just read state and return routing decisions.\n *\n * @example\n * ```typescript\n * const router: ConditionalEdgeRouter<{\n * Schema: typeof StateSchema;\n * ContextSchema: typeof ContextSchema;\n * Nodes: \"agent\" | \"tool\";\n * }> = (state, config) => {\n * return state.done ? END : \"agent\";\n * };\n * ```\n */\nexport interface ConditionalEdgeRouterTypes<InputSchema = unknown, ContextSchema = unknown, Nodes extends string = string> {\n /** Schema for router state (uses ExtractStateType) */\n InputSchema?: InputSchema;\n /** Schema for runtime context (uses ExtractStateType) */\n ContextSchema?: ContextSchema;\n /** Union of valid node names that can be routed to */\n Nodes?: Nodes;\n}\n/**\n * Detect if T is a ConditionalEdgeRouterTypes bag.\n * @internal\n */\ntype IsConditionalEdgeRouterTypeBag<T> = T extends {\n InputSchema: unknown;\n} ? true : T extends {\n ContextSchema: unknown;\n} ? true : false;\n/**\n * Return type for conditional edge routing functions.\n */\ntype ConditionalEdgeRouterReturnValue<Nodes extends string, State> = Nodes | typeof END | Send<Nodes, State> | Array<Nodes | Send<Nodes, State>>;\n/**\n * Type for conditional edge routing functions.\n *\n * Use this to type functions passed to `addConditionalEdges` for\n * full type safety on state, runtime context, and return values.\n *\n * **Supports two patterns:**\n *\n * 1. **Single schema pattern** - Single schema:\n * `ConditionalEdgeRouter<Schema, Context, Nodes>`\n *\n * 2. **Type bag pattern** - Separate schemas for state, context:\n * `ConditionalEdgeRouter<{ Schema; ContextSchema; Nodes }>`\n *\n * @template Schema - The state schema type OR a type bag\n * @template Context - The runtime context type available to node logic\n * @template Nodes - Union of valid node names that can be routed to\n *\n * @example Single schema pattern\n * ```typescript\n * type MyContext = { userId: string };\n * const router: ConditionalEdgeRouter<typeof AgentState, MyContext, \"agent\" | \"tool\"> =\n * (state, config) => {\n * const userId = config.context?.userId;\n * if (state.done) return END;\n * return state.needsTool ? \"tool\" : \"agent\";\n * };\n *\n * graph.addConditionalEdges(\"router\", router, [\"agent\", \"tool\"]);\n * ```\n *\n * @example Type bag pattern\n * ```typescript\n * const router: ConditionalEdgeRouter<{\n * Schema: typeof StateSchema;\n * ContextSchema: typeof ContextSchema;\n * Nodes: \"agent\" | \"tool\";\n * }> = (state, config) => {\n * if (state.done) return END;\n * return \"agent\";\n * };\n * ```\n */\nexport type ConditionalEdgeRouter<Schema, Context extends Record<string, any> = Record<string, any>, Nodes extends string = string> = IsConditionalEdgeRouterTypeBag<Schema> extends true ? (state: ExtractBagInput<Schema, unknown>, config: LangGraphRunnableConfig<ExtractBagContext<Schema, Record<string, unknown>>>) => ConditionalEdgeRouterReturnValue<ExtractBagNodes<Schema, string>, ExtractBagInput<Schema, unknown>> | Promise<ConditionalEdgeRouterReturnValue<ExtractBagNodes<Schema, string>, ExtractBagInput<Schema, unknown>>> : (state: ExtractStateType<Schema>, config: LangGraphRunnableConfig<Context>) => ConditionalEdgeRouterReturnValue<Nodes, ExtractStateType<Schema>> | Promise<ConditionalEdgeRouterReturnValue<Nodes, ExtractStateType<Schema>>>;\n"],"mappings":";;;;;;;;;;AAcA;;;;;AAAwEa,KAA5DE,iBAA4DF,CAAAA,CAAAA,CAAAA,GAArCG,CAAqCH,SAA3BD,WAA2BC,CAAAA,KAAAA,MAAAA,CAAAA,GAAAA,kCAAAA,CAAmCI,KAAnCJ,CAAAA,GAA4CG,CAA5CH,SAAsDP,cAAtDO,CAAAA,KAAAA,GAAAA,CAAAA,GAAiFK,EAAjFL,GAAsFG,CAAtFH,SAAgGb,gBAAhGa,GAAmHC,2BAAnHD,CAA+IG,CAA/IH,CAAAA,GAAoJG,CAApJH,SAA8JN,eAA9JM,GAAgLG,CAAhLH,GAAAA,KAAAA;;;;;;;AAAmHC,KAO/KK,mBAAAA,GAAsBZ,eAPyJO,GAOvId,gBAPuIc,GAOpHH,cAPoHG,GAOnGR,cAPmGQ,CAAAA,GAAAA,CAAAA;;;;;AAO3L;;;;;;;AAeA;;;AAAkEP,KAAtDc,iBAAAA,GAAoBpB,gBAAkCM,GAAfD,cAAeC,C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