@langchain/langgraph-sdk 1.6.4 → 1.7.0

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 (187) hide show
  1. package/dist/client.cjs +4 -2
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.d.cts +7 -0
  4. package/dist/client.d.cts.map +1 -1
  5. package/dist/client.d.ts +7 -0
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +4 -2
  8. package/dist/client.js.map +1 -1
  9. package/dist/index.d.cts +4 -4
  10. package/dist/index.d.ts +4 -4
  11. package/dist/react/index.cjs +46 -10
  12. package/dist/react/index.cjs.map +1 -0
  13. package/dist/react/index.d.cts +14 -11
  14. package/dist/react/index.d.cts.map +1 -0
  15. package/dist/react/index.d.ts +14 -11
  16. package/dist/react/index.d.ts.map +1 -0
  17. package/dist/react/index.js +14 -4
  18. package/dist/react/index.js.map +1 -0
  19. package/dist/react-ui/index.cjs +38 -13
  20. package/dist/react-ui/index.d.cts +1 -2
  21. package/dist/react-ui/index.d.ts +1 -2
  22. package/dist/react-ui/index.js +2 -8
  23. package/dist/react-ui/server/index.cjs +14 -4
  24. package/dist/react-ui/server/index.d.cts +1 -2
  25. package/dist/react-ui/server/index.d.ts +1 -2
  26. package/dist/react-ui/server/index.js +1 -2
  27. package/dist/schema.d.cts +2 -0
  28. package/dist/schema.d.cts.map +1 -1
  29. package/dist/schema.d.ts +2 -0
  30. package/dist/schema.d.ts.map +1 -1
  31. package/dist/types.messages.d.cts +5 -3
  32. package/dist/types.messages.d.cts.map +1 -1
  33. package/dist/types.messages.d.ts +5 -3
  34. package/dist/types.messages.d.ts.map +1 -1
  35. package/dist/types.stream.d.cts +40 -2
  36. package/dist/types.stream.d.cts.map +1 -1
  37. package/dist/types.stream.d.ts +40 -2
  38. package/dist/types.stream.d.ts.map +1 -1
  39. package/dist/ui/branching.cjs +24 -0
  40. package/dist/ui/branching.cjs.map +1 -1
  41. package/dist/ui/branching.d.cts +26 -1
  42. package/dist/ui/branching.d.cts.map +1 -1
  43. package/dist/ui/branching.d.ts +26 -1
  44. package/dist/ui/branching.d.ts.map +1 -1
  45. package/dist/ui/branching.js +25 -1
  46. package/dist/ui/branching.js.map +1 -1
  47. package/dist/ui/index.cjs +30 -0
  48. package/dist/ui/index.d.cts +15 -0
  49. package/dist/ui/index.d.ts +15 -0
  50. package/dist/ui/index.js +11 -0
  51. package/dist/ui/interrupts.cjs +21 -0
  52. package/dist/ui/interrupts.cjs.map +1 -0
  53. package/dist/ui/interrupts.d.cts +11 -0
  54. package/dist/ui/interrupts.d.cts.map +1 -0
  55. package/dist/ui/interrupts.d.ts +11 -0
  56. package/dist/ui/interrupts.d.ts.map +1 -0
  57. package/dist/ui/interrupts.js +20 -0
  58. package/dist/ui/interrupts.js.map +1 -0
  59. package/dist/ui/manager.cjs +12 -3
  60. package/dist/ui/manager.cjs.map +1 -1
  61. package/dist/ui/manager.d.cts +224 -0
  62. package/dist/ui/manager.d.cts.map +1 -0
  63. package/dist/ui/manager.d.ts +224 -0
  64. package/dist/ui/manager.d.ts.map +1 -0
  65. package/dist/ui/manager.js +12 -3
  66. package/dist/ui/manager.js.map +1 -1
  67. package/dist/ui/messages.cjs +19 -0
  68. package/dist/ui/messages.cjs.map +1 -1
  69. package/dist/ui/messages.d.cts +36 -0
  70. package/dist/ui/messages.d.cts.map +1 -0
  71. package/dist/ui/messages.d.ts +36 -0
  72. package/dist/ui/messages.d.ts.map +1 -0
  73. package/dist/ui/messages.js +18 -1
  74. package/dist/ui/messages.js.map +1 -1
  75. package/dist/ui/queue.cjs +75 -0
  76. package/dist/ui/queue.cjs.map +1 -0
  77. package/dist/ui/queue.d.cts +72 -0
  78. package/dist/ui/queue.d.cts.map +1 -0
  79. package/dist/ui/queue.d.ts +72 -0
  80. package/dist/ui/queue.d.ts.map +1 -0
  81. package/dist/ui/queue.js +74 -0
  82. package/dist/ui/queue.js.map +1 -0
  83. package/dist/ui/stream/base.d.cts +17 -1
  84. package/dist/ui/stream/base.d.cts.map +1 -1
  85. package/dist/ui/stream/base.d.ts +17 -1
  86. package/dist/ui/stream/base.d.ts.map +1 -1
  87. package/dist/ui/stream/index.d.cts +4 -4
  88. package/dist/ui/stream/index.d.cts.map +1 -1
  89. package/dist/ui/stream/index.d.ts +4 -4
  90. package/dist/ui/stream/index.d.ts.map +1 -1
  91. package/dist/ui/subagents.cjs +4 -1
  92. package/dist/ui/subagents.cjs.map +1 -1
  93. package/dist/ui/subagents.d.cts +7 -0
  94. package/dist/ui/subagents.d.cts.map +1 -1
  95. package/dist/ui/subagents.d.ts +7 -0
  96. package/dist/ui/subagents.d.ts.map +1 -1
  97. package/dist/ui/subagents.js +4 -1
  98. package/dist/ui/subagents.js.map +1 -1
  99. package/dist/ui/transport.cjs +31 -0
  100. package/dist/ui/transport.cjs.map +1 -0
  101. package/dist/{react/stream.custom.d.cts → ui/transport.d.cts} +3 -3
  102. package/dist/ui/transport.d.cts.map +1 -0
  103. package/dist/{react/stream.custom.d.ts → ui/transport.d.ts} +3 -3
  104. package/dist/ui/transport.d.ts.map +1 -0
  105. package/dist/ui/transport.js +31 -0
  106. package/dist/ui/transport.js.map +1 -0
  107. package/dist/ui/types.d.cts +134 -18
  108. package/dist/ui/types.d.cts.map +1 -1
  109. package/dist/ui/types.d.ts +134 -18
  110. package/dist/ui/types.d.ts.map +1 -1
  111. package/dist/ui/utils.d.cts +7 -0
  112. package/dist/ui/utils.d.cts.map +1 -0
  113. package/dist/ui/utils.d.ts +7 -0
  114. package/dist/ui/utils.d.ts.map +1 -0
  115. package/dist/utils/index.cjs +9 -0
  116. package/dist/utils/index.d.cts +4 -0
  117. package/dist/utils/index.d.ts +4 -0
  118. package/dist/utils/index.js +5 -0
  119. package/dist/utils/sse.d.cts +11 -0
  120. package/dist/utils/sse.d.cts.map +1 -0
  121. package/dist/utils/sse.d.ts +11 -0
  122. package/dist/utils/sse.d.ts.map +1 -0
  123. package/dist/utils/stream.d.cts +19 -0
  124. package/dist/utils/stream.d.cts.map +1 -0
  125. package/dist/utils/stream.d.ts +19 -0
  126. package/dist/utils/stream.d.ts.map +1 -0
  127. package/dist/utils/tools.cjs +26 -17
  128. package/dist/utils/tools.cjs.map +1 -1
  129. package/dist/utils/tools.d.cts +7 -0
  130. package/dist/utils/tools.d.cts.map +1 -0
  131. package/dist/utils/tools.d.ts +7 -0
  132. package/dist/utils/tools.d.ts.map +1 -0
  133. package/dist/utils/tools.js +26 -17
  134. package/dist/utils/tools.js.map +1 -1
  135. package/package.json +42 -13
  136. package/dist/react/stream.cjs +0 -18
  137. package/dist/react/stream.cjs.map +0 -1
  138. package/dist/react/stream.custom.cjs +0 -164
  139. package/dist/react/stream.custom.cjs.map +0 -1
  140. package/dist/react/stream.custom.d.cts.map +0 -1
  141. package/dist/react/stream.custom.d.ts.map +0 -1
  142. package/dist/react/stream.custom.js +0 -162
  143. package/dist/react/stream.custom.js.map +0 -1
  144. package/dist/react/stream.d.cts +0 -174
  145. package/dist/react/stream.d.cts.map +0 -1
  146. package/dist/react/stream.d.ts +0 -174
  147. package/dist/react/stream.d.ts.map +0 -1
  148. package/dist/react/stream.js +0 -17
  149. package/dist/react/stream.js.map +0 -1
  150. package/dist/react/stream.lgp.cjs +0 -482
  151. package/dist/react/stream.lgp.cjs.map +0 -1
  152. package/dist/react/stream.lgp.js +0 -481
  153. package/dist/react/stream.lgp.js.map +0 -1
  154. package/dist/react/thread.cjs +0 -21
  155. package/dist/react/thread.cjs.map +0 -1
  156. package/dist/react/thread.js +0 -20
  157. package/dist/react/thread.js.map +0 -1
  158. package/dist/react/types.d.cts +0 -75
  159. package/dist/react/types.d.cts.map +0 -1
  160. package/dist/react/types.d.ts +0 -75
  161. package/dist/react/types.d.ts.map +0 -1
  162. package/dist/react-ui/client.cjs +0 -138
  163. package/dist/react-ui/client.cjs.map +0 -1
  164. package/dist/react-ui/client.d.cts +0 -76
  165. package/dist/react-ui/client.d.cts.map +0 -1
  166. package/dist/react-ui/client.d.ts +0 -76
  167. package/dist/react-ui/client.d.ts.map +0 -1
  168. package/dist/react-ui/client.js +0 -132
  169. package/dist/react-ui/client.js.map +0 -1
  170. package/dist/react-ui/index.cjs.map +0 -1
  171. package/dist/react-ui/index.js.map +0 -1
  172. package/dist/react-ui/server/server.cjs +0 -57
  173. package/dist/react-ui/server/server.cjs.map +0 -1
  174. package/dist/react-ui/server/server.d.cts +0 -54
  175. package/dist/react-ui/server/server.d.cts.map +0 -1
  176. package/dist/react-ui/server/server.d.ts +0 -54
  177. package/dist/react-ui/server/server.d.ts.map +0 -1
  178. package/dist/react-ui/server/server.js +0 -56
  179. package/dist/react-ui/server/server.js.map +0 -1
  180. package/dist/react-ui/types.cjs +0 -38
  181. package/dist/react-ui/types.cjs.map +0 -1
  182. package/dist/react-ui/types.d.cts +0 -25
  183. package/dist/react-ui/types.d.cts.map +0 -1
  184. package/dist/react-ui/types.d.ts +0 -25
  185. package/dist/react-ui/types.d.ts.map +0 -1
  186. package/dist/react-ui/types.js +0 -35
  187. package/dist/react-ui/types.js.map +0 -1
@@ -1,174 +0,0 @@
1
- import { BagTemplate } from "../types.template.cjs";
2
- import { UseStreamCustomOptions } from "../ui/types.cjs";
3
- import { InferBag, InferStateType, ResolveStreamInterface, ResolveStreamOptions } from "../ui/stream/index.cjs";
4
-
5
- //#region src/react/stream.d.ts
6
- /**
7
- * A React hook that provides seamless integration with LangGraph streaming capabilities.
8
- *
9
- * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
10
- * letting you focus on building great chat experiences. It provides automatic state management for
11
- * messages, interrupts, loading states, subagent streams, and errors.
12
- *
13
- * ## Usage with ReactAgent (recommended for createAgent users)
14
- *
15
- * When using `createAgent` from `@langchain/langgraph`, you can pass `typeof agent` as the
16
- * type parameter to automatically infer tool call types:
17
- *
18
- * @example
19
- * ```typescript
20
- * // In your agent file (e.g., agent.ts)
21
- * import { createAgent, tool } from "langchain";
22
- * import { z } from "zod";
23
- *
24
- * const getWeather = tool(
25
- * async ({ location }) => `Weather in ${location}`,
26
- * { name: "get_weather", schema: z.object({ location: z.string() }) }
27
- * );
28
- *
29
- * export const agent = createAgent({
30
- * model: "openai:gpt-4o",
31
- * tools: [getWeather],
32
- * });
33
- *
34
- * // In your React component
35
- * import { agent } from "./agent";
36
- *
37
- * function Chat() {
38
- * // Tool calls are automatically typed from the agent's tools!
39
- * const stream = useStream<typeof agent>({
40
- * assistantId: "agent",
41
- * apiUrl: "http://localhost:2024",
42
- * });
43
- *
44
- * // stream.toolCalls[0].call.name is typed as "get_weather"
45
- * // stream.toolCalls[0].call.args is typed as { location: string }
46
- * }
47
- * ```
48
- *
49
- * ## Usage with StateGraph (for custom LangGraph applications)
50
- *
51
- * When building custom graphs with `StateGraph`, embed your tool call types directly
52
- * in your state's messages property using `Message<MyToolCalls>`:
53
- *
54
- * @example
55
- * ```typescript
56
- * import { Message } from "@langchain/langgraph-sdk";
57
- *
58
- * // Define your tool call types as a discriminated union
59
- * type MyToolCalls =
60
- * | { name: "search"; args: { query: string }; id?: string }
61
- * | { name: "calculate"; args: { expression: string }; id?: string };
62
- *
63
- * // Embed tool call types in your state's messages
64
- * interface MyGraphState {
65
- * messages: Message<MyToolCalls>[];
66
- * context?: string;
67
- * }
68
- *
69
- * function Chat() {
70
- * const stream = useStream<MyGraphState>({
71
- * assistantId: "my-graph",
72
- * apiUrl: "http://localhost:2024",
73
- * });
74
- *
75
- * // stream.values is typed as MyGraphState
76
- * // stream.toolCalls[0].call.name is typed as "search" | "calculate"
77
- * }
78
- * ```
79
- *
80
- * @example
81
- * ```typescript
82
- * // With additional type configuration (interrupts, configurable)
83
- * interface MyGraphState {
84
- * messages: Message<MyToolCalls>[];
85
- * }
86
- *
87
- * function Chat() {
88
- * const stream = useStream<MyGraphState, {
89
- * InterruptType: { question: string };
90
- * ConfigurableType: { userId: string };
91
- * }>({
92
- * assistantId: "my-graph",
93
- * apiUrl: "http://localhost:2024",
94
- * });
95
- *
96
- * // stream.interrupt is typed as { question: string } | undefined
97
- * }
98
- * ```
99
- *
100
- * ## Usage with Deep Agents (subagent streaming, experimental)
101
- *
102
- * For agents that spawn subagents (nested graphs), use `filterSubagentMessages`
103
- * to keep the main message stream clean while tracking subagent activity separately:
104
- *
105
- * @example
106
- * ```typescript
107
- * import { useStream, SubagentStream } from "@langchain/langgraph-sdk/react";
108
- * import type { agent } from "./agent";
109
- *
110
- * function DeepAgentChat() {
111
- * const stream = useStream<typeof agent>({
112
- * assistantId: "deepagent",
113
- * apiUrl: "http://localhost:2024",
114
- * // Filter subagent messages from main stream
115
- * filterSubagentMessages: true,
116
- * });
117
- *
118
- * const handleSubmit = (content: string) => {
119
- * stream.submit(
120
- * { messages: [{ content, type: "human" }] },
121
- * { streamSubgraphs: true } // Enable subgraph streaming
122
- * );
123
- * };
124
- *
125
- * // Access subagent streams via stream.subagents (Map<string, SubagentStream>)
126
- * const subagentList = [...stream.subagents.values()];
127
- *
128
- * return (
129
- * <div>
130
- * {stream.messages.map((msg) => <Message key={msg.id} message={msg} />)}
131
- *
132
- * {subagentList.map((subagent) => (
133
- * <SubagentCard
134
- * key={subagent.id}
135
- * status={subagent.status} // "pending" | "running" | "complete" | "error"
136
- * messages={subagent.messages}
137
- * toolCalls={subagent.toolCalls}
138
- * />
139
- * ))}
140
- * </div>
141
- * );
142
- * }
143
- * ```
144
- *
145
- * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
146
- * @template Bag Type configuration bag containing:
147
- * - `ConfigurableType`: Type for the `config.configurable` property
148
- * - `InterruptType`: Type for interrupt values
149
- * - `CustomEventType`: Type for custom events
150
- * - `UpdateType`: Type for the submit function updates
151
- *
152
- * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
153
- */
154
- declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
155
- /**
156
- * A React hook that provides seamless integration with LangGraph streaming capabilities.
157
- *
158
- * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
159
- * letting you focus on building great chat experiences. It provides automatic state management for
160
- * messages, interrupts, loading states, and errors.
161
- *
162
- * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
163
- * @template Bag Type configuration bag containing:
164
- * - `ConfigurableType`: Type for the `config.configurable` property
165
- * - `InterruptType`: Type for interrupt values
166
- * - `CustomEventType`: Type for custom events
167
- * - `UpdateType`: Type for the submit function updates
168
- *
169
- * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
170
- */
171
- declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
172
- //#endregion
173
- export { useStream };
174
- //# sourceMappingURL=stream.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.cts","names":[],"sources":["../../src/react/stream.tsx"],"mappings":";;;;;;;AA4KA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAvBgB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;iBAkBzB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA,KAC9D,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA"}
@@ -1,174 +0,0 @@
1
- import { BagTemplate } from "../types.template.js";
2
- import { UseStreamCustomOptions } from "../ui/types.js";
3
- import { InferBag, InferStateType, ResolveStreamInterface, ResolveStreamOptions } from "../ui/stream/index.js";
4
-
5
- //#region src/react/stream.d.ts
6
- /**
7
- * A React hook that provides seamless integration with LangGraph streaming capabilities.
8
- *
9
- * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
10
- * letting you focus on building great chat experiences. It provides automatic state management for
11
- * messages, interrupts, loading states, subagent streams, and errors.
12
- *
13
- * ## Usage with ReactAgent (recommended for createAgent users)
14
- *
15
- * When using `createAgent` from `@langchain/langgraph`, you can pass `typeof agent` as the
16
- * type parameter to automatically infer tool call types:
17
- *
18
- * @example
19
- * ```typescript
20
- * // In your agent file (e.g., agent.ts)
21
- * import { createAgent, tool } from "langchain";
22
- * import { z } from "zod";
23
- *
24
- * const getWeather = tool(
25
- * async ({ location }) => `Weather in ${location}`,
26
- * { name: "get_weather", schema: z.object({ location: z.string() }) }
27
- * );
28
- *
29
- * export const agent = createAgent({
30
- * model: "openai:gpt-4o",
31
- * tools: [getWeather],
32
- * });
33
- *
34
- * // In your React component
35
- * import { agent } from "./agent";
36
- *
37
- * function Chat() {
38
- * // Tool calls are automatically typed from the agent's tools!
39
- * const stream = useStream<typeof agent>({
40
- * assistantId: "agent",
41
- * apiUrl: "http://localhost:2024",
42
- * });
43
- *
44
- * // stream.toolCalls[0].call.name is typed as "get_weather"
45
- * // stream.toolCalls[0].call.args is typed as { location: string }
46
- * }
47
- * ```
48
- *
49
- * ## Usage with StateGraph (for custom LangGraph applications)
50
- *
51
- * When building custom graphs with `StateGraph`, embed your tool call types directly
52
- * in your state's messages property using `Message<MyToolCalls>`:
53
- *
54
- * @example
55
- * ```typescript
56
- * import { Message } from "@langchain/langgraph-sdk";
57
- *
58
- * // Define your tool call types as a discriminated union
59
- * type MyToolCalls =
60
- * | { name: "search"; args: { query: string }; id?: string }
61
- * | { name: "calculate"; args: { expression: string }; id?: string };
62
- *
63
- * // Embed tool call types in your state's messages
64
- * interface MyGraphState {
65
- * messages: Message<MyToolCalls>[];
66
- * context?: string;
67
- * }
68
- *
69
- * function Chat() {
70
- * const stream = useStream<MyGraphState>({
71
- * assistantId: "my-graph",
72
- * apiUrl: "http://localhost:2024",
73
- * });
74
- *
75
- * // stream.values is typed as MyGraphState
76
- * // stream.toolCalls[0].call.name is typed as "search" | "calculate"
77
- * }
78
- * ```
79
- *
80
- * @example
81
- * ```typescript
82
- * // With additional type configuration (interrupts, configurable)
83
- * interface MyGraphState {
84
- * messages: Message<MyToolCalls>[];
85
- * }
86
- *
87
- * function Chat() {
88
- * const stream = useStream<MyGraphState, {
89
- * InterruptType: { question: string };
90
- * ConfigurableType: { userId: string };
91
- * }>({
92
- * assistantId: "my-graph",
93
- * apiUrl: "http://localhost:2024",
94
- * });
95
- *
96
- * // stream.interrupt is typed as { question: string } | undefined
97
- * }
98
- * ```
99
- *
100
- * ## Usage with Deep Agents (subagent streaming, experimental)
101
- *
102
- * For agents that spawn subagents (nested graphs), use `filterSubagentMessages`
103
- * to keep the main message stream clean while tracking subagent activity separately:
104
- *
105
- * @example
106
- * ```typescript
107
- * import { useStream, SubagentStream } from "@langchain/langgraph-sdk/react";
108
- * import type { agent } from "./agent";
109
- *
110
- * function DeepAgentChat() {
111
- * const stream = useStream<typeof agent>({
112
- * assistantId: "deepagent",
113
- * apiUrl: "http://localhost:2024",
114
- * // Filter subagent messages from main stream
115
- * filterSubagentMessages: true,
116
- * });
117
- *
118
- * const handleSubmit = (content: string) => {
119
- * stream.submit(
120
- * { messages: [{ content, type: "human" }] },
121
- * { streamSubgraphs: true } // Enable subgraph streaming
122
- * );
123
- * };
124
- *
125
- * // Access subagent streams via stream.subagents (Map<string, SubagentStream>)
126
- * const subagentList = [...stream.subagents.values()];
127
- *
128
- * return (
129
- * <div>
130
- * {stream.messages.map((msg) => <Message key={msg.id} message={msg} />)}
131
- *
132
- * {subagentList.map((subagent) => (
133
- * <SubagentCard
134
- * key={subagent.id}
135
- * status={subagent.status} // "pending" | "running" | "complete" | "error"
136
- * messages={subagent.messages}
137
- * toolCalls={subagent.toolCalls}
138
- * />
139
- * ))}
140
- * </div>
141
- * );
142
- * }
143
- * ```
144
- *
145
- * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
146
- * @template Bag Type configuration bag containing:
147
- * - `ConfigurableType`: Type for the `config.configurable` property
148
- * - `InterruptType`: Type for interrupt values
149
- * - `CustomEventType`: Type for custom events
150
- * - `UpdateType`: Type for the submit function updates
151
- *
152
- * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
153
- */
154
- declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
155
- /**
156
- * A React hook that provides seamless integration with LangGraph streaming capabilities.
157
- *
158
- * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
159
- * letting you focus on building great chat experiences. It provides automatic state management for
160
- * messages, interrupts, loading states, and errors.
161
- *
162
- * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
163
- * @template Bag Type configuration bag containing:
164
- * - `ConfigurableType`: Type for the `config.configurable` property
165
- * - `InterruptType`: Type for interrupt values
166
- * - `CustomEventType`: Type for custom events
167
- * - `UpdateType`: Type for the submit function updates
168
- *
169
- * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
170
- */
171
- declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
172
- //#endregion
173
- export { useStream };
174
- //# sourceMappingURL=stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.ts","names":[],"sources":["../../src/react/stream.tsx"],"mappings":";;;;;;;AA4KA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAvBgB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;iBAkBzB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA,KAC9D,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA"}
@@ -1,17 +0,0 @@
1
- import { useStreamLGP } from "./stream.lgp.js";
2
- import { useStreamCustom } from "./stream.custom.js";
3
- import { useState } from "react";
4
-
5
- //#region src/react/stream.tsx
6
- function isCustomOptions(options) {
7
- return "transport" in options;
8
- }
9
- function useStream(options) {
10
- const [isCustom] = useState(isCustomOptions(options));
11
- if (isCustom) return useStreamCustom(options);
12
- return useStreamLGP(options);
13
- }
14
-
15
- //#endregion
16
- export { useStream };
17
- //# sourceMappingURL=stream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.js","names":[],"sources":["../../src/react/stream.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { useStreamLGP } from \"./stream.lgp.js\";\nimport { useStreamCustom } from \"./stream.custom.js\";\nimport type { UseStreamOptions } from \"../ui/types.js\";\nimport type { BagTemplate } from \"../types.template.js\";\nimport type { UseStreamCustomOptions } from \"./types.js\";\nimport type {\n ResolveStreamInterface,\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n} from \"../ui/stream/index.js\";\n\nfunction isCustomOptions<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options:\n | UseStreamOptions<StateType, Bag>\n | UseStreamCustomOptions<StateType, Bag>\n): options is UseStreamCustomOptions<StateType, Bag> {\n return \"transport\" in options;\n}\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, subagent streams, and errors.\n *\n * ## Usage with ReactAgent (recommended for createAgent users)\n *\n * When using `createAgent` from `@langchain/langgraph`, you can pass `typeof agent` as the\n * type parameter to automatically infer tool call types:\n *\n * @example\n * ```typescript\n * // In your agent file (e.g., agent.ts)\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool(\n * async ({ location }) => `Weather in ${location}`,\n * { name: \"get_weather\", schema: z.object({ location: z.string() }) }\n * );\n *\n * export const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [getWeather],\n * });\n *\n * // In your React component\n * import { agent } from \"./agent\";\n *\n * function Chat() {\n * // Tool calls are automatically typed from the agent's tools!\n * const stream = useStream<typeof agent>({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * // stream.toolCalls[0].call.name is typed as \"get_weather\"\n * // stream.toolCalls[0].call.args is typed as { location: string }\n * }\n * ```\n *\n * ## Usage with StateGraph (for custom LangGraph applications)\n *\n * When building custom graphs with `StateGraph`, embed your tool call types directly\n * in your state's messages property using `Message<MyToolCalls>`:\n *\n * @example\n * ```typescript\n * import { Message } from \"@langchain/langgraph-sdk\";\n *\n * // Define your tool call types as a discriminated union\n * type MyToolCalls =\n * | { name: \"search\"; args: { query: string }; id?: string }\n * | { name: \"calculate\"; args: { expression: string }; id?: string };\n *\n * // Embed tool call types in your state's messages\n * interface MyGraphState {\n * messages: Message<MyToolCalls>[];\n * context?: string;\n * }\n *\n * function Chat() {\n * const stream = useStream<MyGraphState>({\n * assistantId: \"my-graph\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * // stream.values is typed as MyGraphState\n * // stream.toolCalls[0].call.name is typed as \"search\" | \"calculate\"\n * }\n * ```\n *\n * @example\n * ```typescript\n * // With additional type configuration (interrupts, configurable)\n * interface MyGraphState {\n * messages: Message<MyToolCalls>[];\n * }\n *\n * function Chat() {\n * const stream = useStream<MyGraphState, {\n * InterruptType: { question: string };\n * ConfigurableType: { userId: string };\n * }>({\n * assistantId: \"my-graph\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * // stream.interrupt is typed as { question: string } | undefined\n * }\n * ```\n *\n * ## Usage with Deep Agents (subagent streaming, experimental)\n *\n * For agents that spawn subagents (nested graphs), use `filterSubagentMessages`\n * to keep the main message stream clean while tracking subagent activity separately:\n *\n * @example\n * ```typescript\n * import { useStream, SubagentStream } from \"@langchain/langgraph-sdk/react\";\n * import type { agent } from \"./agent\";\n *\n * function DeepAgentChat() {\n * const stream = useStream<typeof agent>({\n * assistantId: \"deepagent\",\n * apiUrl: \"http://localhost:2024\",\n * // Filter subagent messages from main stream\n * filterSubagentMessages: true,\n * });\n *\n * const handleSubmit = (content: string) => {\n * stream.submit(\n * { messages: [{ content, type: \"human\" }] },\n * { streamSubgraphs: true } // Enable subgraph streaming\n * );\n * };\n *\n * // Access subagent streams via stream.subagents (Map<string, SubagentStream>)\n * const subagentList = [...stream.subagents.values()];\n *\n * return (\n * <div>\n * {stream.messages.map((msg) => <Message key={msg.id} message={msg} />)}\n *\n * {subagentList.map((subagent) => (\n * <SubagentCard\n * key={subagent.id}\n * status={subagent.status} // \"pending\" | \"running\" | \"complete\" | \"error\"\n * messages={subagent.messages}\n * toolCalls={subagent.toolCalls}\n * />\n * ))}\n * </div>\n * );\n * }\n * ```\n *\n * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: ResolveStreamOptions<T, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useStream(options: any): any {\n // Store this in useState to make sure we're not changing the implementation in re-renders\n const [isCustom] = useState(isCustomOptions(options));\n\n if (isCustom) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamCustom(options);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamLGP(options);\n}\n"],"mappings":";;;;;AAaA,SAAS,gBAIP,SAGmD;AACnD,QAAO,eAAe;;AAsLxB,SAAgB,UAAU,SAAmB;CAE3C,MAAM,CAAC,YAAY,SAAS,gBAAgB,QAAQ,CAAC;AAErD,KAAI,SAEF,QAAO,gBAAgB,QAAQ;AAIjC,QAAO,aAAa,QAAQ"}