@langchain/langgraph-sdk 1.6.5 → 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 (177) hide show
  1. package/dist/client.cjs +2 -1
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.d.cts.map +1 -1
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +2 -1
  6. package/dist/client.js.map +1 -1
  7. package/dist/index.d.cts +4 -4
  8. package/dist/index.d.ts +4 -4
  9. package/dist/react/index.cjs +46 -10
  10. package/dist/react/index.cjs.map +1 -0
  11. package/dist/react/index.d.cts +14 -11
  12. package/dist/react/index.d.cts.map +1 -0
  13. package/dist/react/index.d.ts +14 -11
  14. package/dist/react/index.d.ts.map +1 -0
  15. package/dist/react/index.js +14 -4
  16. package/dist/react/index.js.map +1 -0
  17. package/dist/react-ui/index.cjs +38 -13
  18. package/dist/react-ui/index.d.cts +1 -2
  19. package/dist/react-ui/index.d.ts +1 -2
  20. package/dist/react-ui/index.js +2 -8
  21. package/dist/react-ui/server/index.cjs +14 -4
  22. package/dist/react-ui/server/index.d.cts +1 -2
  23. package/dist/react-ui/server/index.d.ts +1 -2
  24. package/dist/react-ui/server/index.js +1 -2
  25. package/dist/types.messages.d.cts +5 -3
  26. package/dist/types.messages.d.cts.map +1 -1
  27. package/dist/types.messages.d.ts +5 -3
  28. package/dist/types.messages.d.ts.map +1 -1
  29. package/dist/ui/branching.cjs +24 -0
  30. package/dist/ui/branching.cjs.map +1 -1
  31. package/dist/ui/branching.d.cts +26 -1
  32. package/dist/ui/branching.d.cts.map +1 -1
  33. package/dist/ui/branching.d.ts +26 -1
  34. package/dist/ui/branching.d.ts.map +1 -1
  35. package/dist/ui/branching.js +25 -1
  36. package/dist/ui/branching.js.map +1 -1
  37. package/dist/ui/index.cjs +30 -0
  38. package/dist/ui/index.d.cts +15 -0
  39. package/dist/ui/index.d.ts +15 -0
  40. package/dist/ui/index.js +11 -0
  41. package/dist/ui/interrupts.cjs +21 -0
  42. package/dist/ui/interrupts.cjs.map +1 -0
  43. package/dist/ui/interrupts.d.cts +11 -0
  44. package/dist/ui/interrupts.d.cts.map +1 -0
  45. package/dist/ui/interrupts.d.ts +11 -0
  46. package/dist/ui/interrupts.d.ts.map +1 -0
  47. package/dist/ui/interrupts.js +20 -0
  48. package/dist/ui/interrupts.js.map +1 -0
  49. package/dist/ui/manager.cjs +8 -3
  50. package/dist/ui/manager.cjs.map +1 -1
  51. package/dist/ui/manager.d.cts +224 -0
  52. package/dist/ui/manager.d.cts.map +1 -0
  53. package/dist/ui/manager.d.ts +224 -0
  54. package/dist/ui/manager.d.ts.map +1 -0
  55. package/dist/ui/manager.js +8 -3
  56. package/dist/ui/manager.js.map +1 -1
  57. package/dist/ui/messages.cjs +19 -0
  58. package/dist/ui/messages.cjs.map +1 -1
  59. package/dist/ui/messages.d.cts +36 -0
  60. package/dist/ui/messages.d.cts.map +1 -0
  61. package/dist/ui/messages.d.ts +36 -0
  62. package/dist/ui/messages.d.ts.map +1 -0
  63. package/dist/ui/messages.js +18 -1
  64. package/dist/ui/messages.js.map +1 -1
  65. package/dist/ui/queue.cjs +75 -0
  66. package/dist/ui/queue.cjs.map +1 -0
  67. package/dist/ui/queue.d.cts +72 -0
  68. package/dist/ui/queue.d.cts.map +1 -0
  69. package/dist/ui/queue.d.ts +72 -0
  70. package/dist/ui/queue.d.ts.map +1 -0
  71. package/dist/ui/queue.js +74 -0
  72. package/dist/ui/queue.js.map +1 -0
  73. package/dist/ui/stream/base.d.cts +11 -0
  74. package/dist/ui/stream/base.d.cts.map +1 -1
  75. package/dist/ui/stream/base.d.ts +11 -0
  76. package/dist/ui/stream/base.d.ts.map +1 -1
  77. package/dist/ui/stream/index.d.cts +4 -4
  78. package/dist/ui/stream/index.d.cts.map +1 -1
  79. package/dist/ui/stream/index.d.ts +4 -4
  80. package/dist/ui/stream/index.d.ts.map +1 -1
  81. package/dist/ui/subagents.cjs +4 -1
  82. package/dist/ui/subagents.cjs.map +1 -1
  83. package/dist/ui/subagents.d.cts +7 -0
  84. package/dist/ui/subagents.d.cts.map +1 -1
  85. package/dist/ui/subagents.d.ts +7 -0
  86. package/dist/ui/subagents.d.ts.map +1 -1
  87. package/dist/ui/subagents.js +4 -1
  88. package/dist/ui/subagents.js.map +1 -1
  89. package/dist/ui/transport.cjs +31 -0
  90. package/dist/ui/transport.cjs.map +1 -0
  91. package/dist/{react/stream.custom.d.cts → ui/transport.d.cts} +3 -3
  92. package/dist/ui/transport.d.cts.map +1 -0
  93. package/dist/{react/stream.custom.d.ts → ui/transport.d.ts} +3 -3
  94. package/dist/ui/transport.d.ts.map +1 -0
  95. package/dist/ui/transport.js +31 -0
  96. package/dist/ui/transport.js.map +1 -0
  97. package/dist/ui/types.d.cts +125 -16
  98. package/dist/ui/types.d.cts.map +1 -1
  99. package/dist/ui/types.d.ts +125 -16
  100. package/dist/ui/types.d.ts.map +1 -1
  101. package/dist/ui/utils.d.cts +7 -0
  102. package/dist/ui/utils.d.cts.map +1 -0
  103. package/dist/ui/utils.d.ts +7 -0
  104. package/dist/ui/utils.d.ts.map +1 -0
  105. package/dist/utils/index.cjs +9 -0
  106. package/dist/utils/index.d.cts +4 -0
  107. package/dist/utils/index.d.ts +4 -0
  108. package/dist/utils/index.js +5 -0
  109. package/dist/utils/sse.d.cts +11 -0
  110. package/dist/utils/sse.d.cts.map +1 -0
  111. package/dist/utils/sse.d.ts +11 -0
  112. package/dist/utils/sse.d.ts.map +1 -0
  113. package/dist/utils/stream.d.cts +19 -0
  114. package/dist/utils/stream.d.cts.map +1 -0
  115. package/dist/utils/stream.d.ts +19 -0
  116. package/dist/utils/stream.d.ts.map +1 -0
  117. package/dist/utils/tools.cjs +26 -17
  118. package/dist/utils/tools.cjs.map +1 -1
  119. package/dist/utils/tools.d.cts +7 -0
  120. package/dist/utils/tools.d.cts.map +1 -0
  121. package/dist/utils/tools.d.ts +7 -0
  122. package/dist/utils/tools.d.ts.map +1 -0
  123. package/dist/utils/tools.js +26 -17
  124. package/dist/utils/tools.js.map +1 -1
  125. package/package.json +41 -12
  126. package/dist/react/stream.cjs +0 -18
  127. package/dist/react/stream.cjs.map +0 -1
  128. package/dist/react/stream.custom.cjs +0 -164
  129. package/dist/react/stream.custom.cjs.map +0 -1
  130. package/dist/react/stream.custom.d.cts.map +0 -1
  131. package/dist/react/stream.custom.d.ts.map +0 -1
  132. package/dist/react/stream.custom.js +0 -162
  133. package/dist/react/stream.custom.js.map +0 -1
  134. package/dist/react/stream.d.cts +0 -174
  135. package/dist/react/stream.d.cts.map +0 -1
  136. package/dist/react/stream.d.ts +0 -174
  137. package/dist/react/stream.d.ts.map +0 -1
  138. package/dist/react/stream.js +0 -17
  139. package/dist/react/stream.js.map +0 -1
  140. package/dist/react/stream.lgp.cjs +0 -544
  141. package/dist/react/stream.lgp.cjs.map +0 -1
  142. package/dist/react/stream.lgp.js +0 -543
  143. package/dist/react/stream.lgp.js.map +0 -1
  144. package/dist/react/thread.cjs +0 -21
  145. package/dist/react/thread.cjs.map +0 -1
  146. package/dist/react/thread.js +0 -20
  147. package/dist/react/thread.js.map +0 -1
  148. package/dist/react/types.d.cts +0 -79
  149. package/dist/react/types.d.cts.map +0 -1
  150. package/dist/react/types.d.ts +0 -79
  151. package/dist/react/types.d.ts.map +0 -1
  152. package/dist/react-ui/client.cjs +0 -138
  153. package/dist/react-ui/client.cjs.map +0 -1
  154. package/dist/react-ui/client.d.cts +0 -76
  155. package/dist/react-ui/client.d.cts.map +0 -1
  156. package/dist/react-ui/client.d.ts +0 -76
  157. package/dist/react-ui/client.d.ts.map +0 -1
  158. package/dist/react-ui/client.js +0 -132
  159. package/dist/react-ui/client.js.map +0 -1
  160. package/dist/react-ui/index.cjs.map +0 -1
  161. package/dist/react-ui/index.js.map +0 -1
  162. package/dist/react-ui/server/server.cjs +0 -57
  163. package/dist/react-ui/server/server.cjs.map +0 -1
  164. package/dist/react-ui/server/server.d.cts +0 -54
  165. package/dist/react-ui/server/server.d.cts.map +0 -1
  166. package/dist/react-ui/server/server.d.ts +0 -54
  167. package/dist/react-ui/server/server.d.ts.map +0 -1
  168. package/dist/react-ui/server/server.js +0 -56
  169. package/dist/react-ui/server/server.js.map +0 -1
  170. package/dist/react-ui/types.cjs +0 -38
  171. package/dist/react-ui/types.cjs.map +0 -1
  172. package/dist/react-ui/types.d.cts +0 -25
  173. package/dist/react-ui/types.d.cts.map +0 -1
  174. package/dist/react-ui/types.d.ts +0 -25
  175. package/dist/react-ui/types.d.ts.map +0 -1
  176. package/dist/react-ui/types.js +0 -35
  177. package/dist/react-ui/types.js.map +0 -1
@@ -1,162 +0,0 @@
1
- "use client";
2
-
3
- import { BytesLineDecoder, SSEDecoder } from "../utils/sse.js";
4
- import { IterableReadableStream } from "../utils/stream.js";
5
- import { MessageTupleManager } from "../ui/messages.js";
6
- import { getToolCallsWithResults } from "../utils/tools.js";
7
- import { StreamManager } from "../ui/manager.js";
8
- import { useControllableThreadId } from "./thread.js";
9
- import { useEffect, useRef, useState, useSyncExternalStore } from "react";
10
-
11
- //#region src/react/stream.custom.tsx
12
- var FetchStreamTransport = class {
13
- constructor(options) {
14
- this.options = options;
15
- }
16
- async stream(payload) {
17
- const { signal, ...body } = payload;
18
- let requestInit = {
19
- method: "POST",
20
- headers: {
21
- "Content-Type": "application/json",
22
- ...this.options.defaultHeaders
23
- },
24
- body: JSON.stringify(body),
25
- signal
26
- };
27
- if (this.options.onRequest) requestInit = await this.options.onRequest(this.options.apiUrl, requestInit);
28
- const response = await (this.options.fetch ?? fetch)(this.options.apiUrl, requestInit);
29
- if (!response.ok) throw new Error(`Failed to stream: ${response.statusText}`);
30
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(BytesLineDecoder()).pipeThrough(SSEDecoder());
31
- return IterableReadableStream.fromReadableStream(stream);
32
- }
33
- };
34
- function useStreamCustom(options) {
35
- const [messageManager] = useState(() => new MessageTupleManager());
36
- const [stream] = useState(() => new StreamManager(messageManager, {
37
- throttle: options.throttle ?? false,
38
- subagentToolNames: options.subagentToolNames,
39
- filterSubagentMessages: options.filterSubagentMessages
40
- }));
41
- useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getSnapshot);
42
- const [threadId, onThreadId] = useControllableThreadId(options);
43
- const threadIdRef = useRef(threadId);
44
- useEffect(() => {
45
- if (threadIdRef.current !== threadId) {
46
- threadIdRef.current = threadId;
47
- stream.clear();
48
- }
49
- }, [threadId, stream]);
50
- const getMessages = (value) => {
51
- const messagesKey = options.messagesKey ?? "messages";
52
- return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];
53
- };
54
- const setMessages = (current, messages) => {
55
- const messagesKey = options.messagesKey ?? "messages";
56
- return {
57
- ...current,
58
- [messagesKey]: messages
59
- };
60
- };
61
- const historyValues = options.initialValues ?? {};
62
- const historyMessages = getMessages(historyValues);
63
- const shouldReconstructSubagents = options.filterSubagentMessages && !stream.isLoading && historyMessages.length > 0;
64
- useEffect(() => {
65
- if (shouldReconstructSubagents) stream.reconstructSubagents(historyMessages, { skipIfPopulated: true });
66
- }, [shouldReconstructSubagents, historyMessages.length]);
67
- const stop = () => stream.stop(historyValues, { onStop: options.onStop });
68
- const submit = async (values, submitOptions) => {
69
- let usableThreadId = threadId;
70
- stream.setStreamValues(() => {
71
- if (submitOptions?.optimisticValues != null) return {
72
- ...historyValues,
73
- ...typeof submitOptions.optimisticValues === "function" ? submitOptions.optimisticValues(historyValues) : submitOptions.optimisticValues
74
- };
75
- return { ...historyValues };
76
- });
77
- await stream.start(async (signal) => {
78
- if (!usableThreadId) {
79
- usableThreadId = crypto.randomUUID();
80
- threadIdRef.current = usableThreadId;
81
- onThreadId(usableThreadId);
82
- }
83
- if (!usableThreadId) throw new Error("Failed to obtain valid thread ID.");
84
- return options.transport.stream({
85
- input: values,
86
- context: submitOptions?.context,
87
- command: submitOptions?.command,
88
- signal,
89
- config: {
90
- ...submitOptions?.config,
91
- configurable: {
92
- thread_id: usableThreadId,
93
- ...submitOptions?.config?.configurable
94
- }
95
- }
96
- });
97
- }, {
98
- getMessages,
99
- setMessages,
100
- initialValues: {},
101
- callbacks: options,
102
- onSuccess: () => void 0,
103
- onError(error) {
104
- options.onError?.(error, void 0);
105
- }
106
- });
107
- };
108
- return {
109
- get values() {
110
- return stream.values ?? {};
111
- },
112
- error: stream.error,
113
- isLoading: stream.isLoading,
114
- stop,
115
- submit,
116
- get interrupts() {
117
- if (stream.values != null && "__interrupt__" in stream.values && Array.isArray(stream.values.__interrupt__)) {
118
- const valueInterrupts = stream.values.__interrupt__;
119
- if (valueInterrupts.length === 0) return [{ when: "breakpoint" }];
120
- return valueInterrupts;
121
- }
122
- return [];
123
- },
124
- get interrupt() {
125
- const all = this.interrupts;
126
- if (all.length === 0) return void 0;
127
- if (all.length === 1) return all[0];
128
- return all;
129
- },
130
- get messages() {
131
- if (!stream.values) return [];
132
- return getMessages(stream.values);
133
- },
134
- get toolCalls() {
135
- if (!stream.values) return [];
136
- return getToolCallsWithResults(getMessages(stream.values));
137
- },
138
- getToolCalls(message) {
139
- if (!stream.values) return [];
140
- return getToolCallsWithResults(getMessages(stream.values)).filter((tc) => tc.aiMessage.id === message.id);
141
- },
142
- get subagents() {
143
- return stream.getSubagents();
144
- },
145
- get activeSubagents() {
146
- return stream.getActiveSubagents();
147
- },
148
- getSubagent(toolCallId) {
149
- return stream.getSubagent(toolCallId);
150
- },
151
- getSubagentsByType(type) {
152
- return stream.getSubagentsByType(type);
153
- },
154
- getSubagentsByMessage(messageId) {
155
- return stream.getSubagentsByMessage(messageId);
156
- }
157
- };
158
- }
159
-
160
- //#endregion
161
- export { FetchStreamTransport, useStreamCustom };
162
- //# sourceMappingURL=stream.custom.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.custom.js","names":[],"sources":["../../src/react/stream.custom.tsx"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport { EventStreamEvent, StreamManager } from \"../ui/manager.js\";\nimport type {\n GetUpdateType,\n GetCustomEventType,\n GetInterruptType,\n GetToolCallsType,\n GetConfigurableType,\n UseStreamTransport,\n AnyStreamCustomOptions,\n CustomSubmitOptions,\n} from \"../ui/types.js\";\nimport type { UseStreamCustom } from \"./types.js\";\nimport { type Message } from \"../types.messages.js\";\nimport { getToolCallsWithResults } from \"../utils/tools.js\";\nimport { MessageTupleManager } from \"../ui/messages.js\";\nimport { Interrupt } from \"../schema.js\";\nimport { BytesLineDecoder, SSEDecoder } from \"../utils/sse.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { useControllableThreadId } from \"./thread.js\";\nimport { Command } from \"../types.js\";\nimport type { BagTemplate } from \"../types.template.js\";\n\ninterface FetchStreamTransportOptions {\n /**\n * The URL of the API to use.\n */\n apiUrl: string;\n\n /**\n * Default headers to send with requests.\n */\n defaultHeaders?: HeadersInit;\n\n /**\n * Specify a custom fetch implementation.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Callback that is called before the request is made.\n */\n onRequest?: (\n url: string,\n init: RequestInit\n ) => Promise<RequestInit> | RequestInit;\n}\n\nexport class FetchStreamTransport<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n> implements UseStreamTransport<StateType, Bag>\n{\n constructor(private readonly options: FetchStreamTransportOptions) {}\n\n async stream(payload: {\n input: GetUpdateType<Bag, StateType> | null | undefined;\n context: GetConfigurableType<Bag> | undefined;\n command: Command | undefined;\n signal: AbortSignal;\n }): Promise<AsyncGenerator<{ id?: string; event: string; data: unknown }>> {\n const { signal, ...body } = payload;\n\n let requestInit: RequestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.options.defaultHeaders,\n },\n body: JSON.stringify(body),\n signal,\n };\n\n if (this.options.onRequest) {\n requestInit = await this.options.onRequest(\n this.options.apiUrl,\n requestInit\n );\n }\n const fetchFn = this.options.fetch ?? fetch;\n\n const response = await fetchFn(this.options.apiUrl, requestInit);\n if (!response.ok) {\n throw new Error(`Failed to stream: ${response.statusText}`);\n }\n\n const stream = (\n response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })\n )\n .pipeThrough(BytesLineDecoder())\n .pipeThrough(SSEDecoder());\n\n return IterableReadableStream.fromReadableStream(stream);\n }\n}\n\nexport function useStreamCustom<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: AnyStreamCustomOptions<StateType, Bag>\n): UseStreamCustom<StateType, Bag> {\n type UpdateType = GetUpdateType<Bag, StateType>;\n type CustomType = GetCustomEventType<Bag>;\n type InterruptType = GetInterruptType<Bag>;\n type ConfigurableType = GetConfigurableType<Bag>;\n type ToolCallType = GetToolCallsType<StateType>;\n\n const [messageManager] = useState(() => new MessageTupleManager());\n const [stream] = useState(\n () =>\n new StreamManager<StateType, Bag>(messageManager, {\n throttle: options.throttle ?? false,\n subagentToolNames: options.subagentToolNames,\n filterSubagentMessages: options.filterSubagentMessages,\n })\n );\n\n useSyncExternalStore(\n stream.subscribe,\n stream.getSnapshot,\n stream.getSnapshot\n );\n\n const [threadId, onThreadId] = useControllableThreadId(options);\n const threadIdRef = useRef<string | null>(threadId);\n\n // Cancel the stream if thread ID has changed\n useEffect(() => {\n if (threadIdRef.current !== threadId) {\n threadIdRef.current = threadId;\n stream.clear();\n }\n }, [threadId, stream]);\n\n const getMessages = (value: StateType): Message[] => {\n const messagesKey = options.messagesKey ?? \"messages\";\n return Array.isArray(value[messagesKey])\n ? (value[messagesKey] as Message[])\n : [];\n };\n\n const setMessages = (current: StateType, messages: Message[]): StateType => {\n const messagesKey = options.messagesKey ?? \"messages\";\n return { ...current, [messagesKey]: messages };\n };\n\n const historyValues = options.initialValues ?? ({} as StateType);\n\n // Reconstruct subagents from initialValues when:\n // 1. Subagent filtering is enabled\n // 2. Not currently streaming\n // 3. initialValues has messages\n // This ensures subagent visualization works with cached/persisted state\n const historyMessages = getMessages(historyValues);\n const shouldReconstructSubagents =\n options.filterSubagentMessages &&\n !stream.isLoading &&\n historyMessages.length > 0;\n\n useEffect(() => {\n if (shouldReconstructSubagents) {\n // skipIfPopulated: true ensures we don't overwrite subagents from active streaming\n stream.reconstructSubagents(historyMessages, { skipIfPopulated: true });\n }\n // We intentionally only run this when shouldReconstructSubagents changes\n // to avoid unnecessary reconstructions during streaming\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shouldReconstructSubagents, historyMessages.length]);\n\n const stop = () => stream.stop(historyValues, { onStop: options.onStop });\n\n const submit = async (\n values: UpdateType | null | undefined,\n submitOptions?: CustomSubmitOptions<StateType, ConfigurableType>\n ) => {\n let usableThreadId = threadId;\n\n stream.setStreamValues(() => {\n if (submitOptions?.optimisticValues != null) {\n return {\n ...historyValues,\n ...(typeof submitOptions.optimisticValues === \"function\"\n ? submitOptions.optimisticValues(historyValues)\n : submitOptions.optimisticValues),\n };\n }\n\n return { ...historyValues };\n });\n\n await stream.start(\n async (signal: AbortSignal) => {\n if (!usableThreadId) {\n // generate random thread id\n usableThreadId = crypto.randomUUID();\n threadIdRef.current = usableThreadId;\n onThreadId(usableThreadId);\n }\n\n if (!usableThreadId) {\n throw new Error(\"Failed to obtain valid thread ID.\");\n }\n\n return options.transport.stream({\n input: values,\n context: submitOptions?.context,\n command: submitOptions?.command,\n signal,\n config: {\n ...submitOptions?.config,\n configurable: {\n thread_id: usableThreadId,\n ...submitOptions?.config?.configurable,\n } as unknown as GetConfigurableType<Bag>,\n },\n }) as Promise<\n AsyncGenerator<EventStreamEvent<StateType, UpdateType, CustomType>>\n >;\n },\n {\n getMessages,\n setMessages,\n\n initialValues: {} as StateType,\n callbacks: options,\n\n onSuccess: () => undefined,\n onError(error) {\n options.onError?.(error, undefined);\n },\n }\n );\n };\n\n return {\n get values() {\n return stream.values ?? ({} as StateType);\n },\n\n error: stream.error,\n isLoading: stream.isLoading,\n\n stop,\n submit,\n\n get interrupts(): Interrupt<InterruptType>[] {\n if (\n stream.values != null &&\n \"__interrupt__\" in stream.values &&\n Array.isArray(stream.values.__interrupt__)\n ) {\n const valueInterrupts = stream.values.__interrupt__;\n if (valueInterrupts.length === 0) return [{ when: \"breakpoint\" }];\n return valueInterrupts;\n }\n\n return [];\n },\n\n get interrupt(): Interrupt<InterruptType> | undefined {\n const all = this.interrupts;\n if (all.length === 0) return undefined;\n if (all.length === 1) return all[0];\n\n // Multiple interrupts: return the array for backward compat\n return all as Interrupt<InterruptType>;\n },\n\n get messages(): Message<ToolCallType>[] {\n if (!stream.values) return [];\n return getMessages(stream.values);\n },\n\n get toolCalls() {\n if (!stream.values) return [];\n const msgs = getMessages(stream.values);\n return getToolCallsWithResults<ToolCallType>(msgs);\n },\n\n getToolCalls(message) {\n if (!stream.values) return [];\n const msgs = getMessages(stream.values);\n const allToolCalls = getToolCallsWithResults<ToolCallType>(msgs);\n return allToolCalls.filter((tc) => tc.aiMessage.id === message.id);\n },\n\n get subagents() {\n return stream.getSubagents();\n },\n\n get activeSubagents() {\n return stream.getActiveSubagents();\n },\n\n getSubagent(toolCallId: string) {\n return stream.getSubagent(toolCallId);\n },\n\n getSubagentsByType(type: string) {\n return stream.getSubagentsByType(type);\n },\n\n getSubagentsByMessage(messageId: string) {\n return stream.getSubagentsByMessage(messageId);\n },\n };\n}\n"],"mappings":"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"}
@@ -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"}