|
14 | 14 | - Deprecate `stateSchema` property in favor of `state` |
15 | 15 | - Simplify constructor overloads with unified `StateGraphInit` type |
16 | 16 |
|
| 17 | +- [#1918](https://github.com/langchain-ai/langgraphjs/pull/1918) [`cc12263`](https://github.com/langchain-ai/langgraphjs/commit/cc12263ad26804ef53760cabf1bd2fda0be575d6) Thanks [@hntrl](https://github.com/hntrl)! - Add type bag pattern for `GraphNode` and `ConditionalEdgeRouter` type utilities. |
| 18 | + |
| 19 | + **New types:** |
| 20 | + |
| 21 | + - `GraphNodeTypes<InputSchema, OutputSchema, ContextSchema, Nodes>` - Type bag interface for GraphNode |
| 22 | + - `GraphNodeReturnValue<Update, Nodes>` - Return type helper for node functions |
| 23 | + - `ConditionalEdgeRouterTypes<InputSchema, ContextSchema, Nodes>` - Type bag interface for ConditionalEdgeRouter |
| 24 | + |
| 25 | + **Usage:** |
| 26 | + |
| 27 | + Both `GraphNode` and `ConditionalEdgeRouter` now support two patterns: |
| 28 | + |
| 29 | + 1. **Single schema** (backward compatible): |
| 30 | + |
| 31 | + ```typescript |
| 32 | + const node: GraphNode<typeof AgentState, MyContext, "agent" | "tool"> = ... |
| 33 | + ``` |
| 34 | + |
| 35 | + 2. **Type bag pattern** (new): |
| 36 | + ```typescript |
| 37 | + const node: GraphNode<{ |
| 38 | + InputSchema: typeof InputSchema; |
| 39 | + OutputSchema: typeof OutputSchema; |
| 40 | + ContextSchema: typeof ContextSchema; |
| 41 | + Nodes: "agent" | "tool"; |
| 42 | + }> = (state, runtime) => { |
| 43 | + // state type inferred from InputSchema |
| 44 | + // return type validated against OutputSchema |
| 45 | + // runtime.configurable type inferred from ContextSchema |
| 46 | + return { answer: "response" }; |
| 47 | + }; |
| 48 | + ``` |
| 49 | + |
| 50 | + The type bag pattern enables nodes that receive a subset of state fields and return different fields, with full type safety. |
| 51 | + |
17 | 52 | ## 1.1.1 |
18 | 53 |
|
19 | 54 | ### Patch Changes |
|
0 commit comments