@langchain/langgraph-sdk 0.1.10 → 1.0.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 (234) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/auth/error.cjs +76 -86
  4. package/dist/auth/error.cjs.map +1 -0
  5. package/dist/auth/error.d.cts +13 -0
  6. package/dist/auth/error.d.cts.map +1 -0
  7. package/dist/auth/error.d.ts +12 -8
  8. package/dist/auth/error.d.ts.map +1 -0
  9. package/dist/auth/error.js +76 -83
  10. package/dist/auth/error.js.map +1 -0
  11. package/dist/auth/index.cjs +36 -44
  12. package/dist/auth/index.cjs.map +1 -0
  13. package/dist/auth/index.d.cts +31 -0
  14. package/dist/auth/index.d.cts.map +1 -0
  15. package/dist/auth/index.d.ts +20 -15
  16. package/dist/auth/index.d.ts.map +1 -0
  17. package/dist/auth/index.js +35 -39
  18. package/dist/auth/index.js.map +1 -0
  19. package/dist/auth/types.d.cts +294 -0
  20. package/dist/auth/types.d.cts.map +1 -0
  21. package/dist/auth/types.d.ts +162 -165
  22. package/dist/auth/types.d.ts.map +1 -0
  23. package/dist/client.cjs +1108 -1294
  24. package/dist/client.cjs.map +1 -0
  25. package/dist/client.d.cts +688 -0
  26. package/dist/client.d.cts.map +1 -0
  27. package/dist/client.d.ts +647 -639
  28. package/dist/client.d.ts.map +1 -0
  29. package/dist/client.js +1099 -1281
  30. package/dist/client.js.map +1 -0
  31. package/dist/index.cjs +6 -8
  32. package/dist/index.d.cts +7 -0
  33. package/dist/index.d.ts +7 -7
  34. package/dist/index.js +4 -2
  35. package/dist/logging/index.cjs +30 -31
  36. package/dist/logging/index.cjs.map +1 -0
  37. package/dist/logging/index.d.cts +47 -0
  38. package/dist/logging/index.d.cts.map +1 -0
  39. package/dist/logging/index.d.ts +20 -16
  40. package/dist/logging/index.d.ts.map +1 -0
  41. package/dist/logging/index.js +31 -29
  42. package/dist/logging/index.js.map +1 -0
  43. package/dist/react/index.cjs +5 -7
  44. package/dist/react/index.d.cts +4 -0
  45. package/dist/react/index.d.ts +4 -3
  46. package/dist/react/index.js +4 -2
  47. package/dist/react/stream.cjs +14 -15
  48. package/dist/react/stream.cjs.map +1 -0
  49. package/dist/react/stream.custom.cjs +126 -145
  50. package/dist/react/stream.custom.cjs.map +1 -0
  51. package/dist/react/stream.custom.d.cts +39 -0
  52. package/dist/react/stream.custom.d.cts.map +1 -0
  53. package/dist/react/stream.custom.d.ts +35 -37
  54. package/dist/react/stream.custom.d.ts.map +1 -0
  55. package/dist/react/stream.custom.js +122 -137
  56. package/dist/react/stream.custom.js.map +1 -0
  57. package/dist/react/stream.d.cts +73 -0
  58. package/dist/react/stream.d.cts.map +1 -0
  59. package/dist/react/stream.d.ts +21 -15
  60. package/dist/react/stream.d.ts.map +1 -0
  61. package/dist/react/stream.js +12 -11
  62. package/dist/react/stream.js.map +1 -0
  63. package/dist/react/stream.lgp.cjs +438 -498
  64. package/dist/react/stream.lgp.cjs.map +1 -0
  65. package/dist/react/stream.lgp.js +433 -490
  66. package/dist/react/stream.lgp.js.map +1 -0
  67. package/dist/react/thread.cjs +18 -15
  68. package/dist/react/thread.cjs.map +1 -0
  69. package/dist/react/thread.js +19 -13
  70. package/dist/react/thread.js.map +1 -0
  71. package/dist/react/types.d.cts +355 -0
  72. package/dist/react/types.d.cts.map +1 -0
  73. package/dist/react/types.d.ts +333 -329
  74. package/dist/react/types.d.ts.map +1 -0
  75. package/dist/react-ui/client.cjs +123 -184
  76. package/dist/react-ui/client.cjs.map +1 -0
  77. package/dist/react-ui/client.d.cts +90 -0
  78. package/dist/react-ui/client.d.cts.map +1 -0
  79. package/dist/react-ui/client.d.ts +67 -51
  80. package/dist/react-ui/client.d.ts.map +1 -0
  81. package/dist/react-ui/client.js +118 -143
  82. package/dist/react-ui/client.js.map +1 -0
  83. package/dist/react-ui/index.cjs +14 -13
  84. package/dist/react-ui/index.cjs.map +1 -0
  85. package/dist/react-ui/index.d.cts +3 -0
  86. package/dist/react-ui/index.d.ts +3 -2
  87. package/dist/react-ui/index.js +8 -3
  88. package/dist/react-ui/index.js.map +1 -0
  89. package/dist/react-ui/server/index.cjs +5 -7
  90. package/dist/react-ui/server/index.d.cts +3 -0
  91. package/dist/react-ui/server/index.d.ts +3 -2
  92. package/dist/react-ui/server/index.js +4 -2
  93. package/dist/react-ui/server/server.cjs +53 -44
  94. package/dist/react-ui/server/server.cjs.map +1 -0
  95. package/dist/react-ui/server/server.d.cts +55 -0
  96. package/dist/react-ui/server/server.d.cts.map +1 -0
  97. package/dist/react-ui/server/server.d.ts +43 -39
  98. package/dist/react-ui/server/server.d.ts.map +1 -0
  99. package/dist/react-ui/server/server.js +54 -42
  100. package/dist/react-ui/server/server.js.map +1 -0
  101. package/dist/react-ui/types.cjs +32 -36
  102. package/dist/react-ui/types.cjs.map +1 -0
  103. package/dist/react-ui/types.d.cts +25 -0
  104. package/dist/react-ui/types.d.cts.map +1 -0
  105. package/dist/react-ui/types.d.ts +23 -19
  106. package/dist/react-ui/types.d.ts.map +1 -0
  107. package/dist/react-ui/types.js +32 -34
  108. package/dist/react-ui/types.js.map +1 -0
  109. package/dist/schema.d.cts +277 -0
  110. package/dist/schema.d.cts.map +1 -0
  111. package/dist/schema.d.ts +249 -242
  112. package/dist/schema.d.ts.map +1 -0
  113. package/dist/singletons/fetch.cjs +16 -20
  114. package/dist/singletons/fetch.cjs.map +1 -0
  115. package/dist/singletons/fetch.d.cts +14 -0
  116. package/dist/singletons/fetch.d.cts.map +1 -0
  117. package/dist/singletons/fetch.d.ts +5 -2
  118. package/dist/singletons/fetch.d.ts.map +1 -0
  119. package/dist/singletons/fetch.js +16 -17
  120. package/dist/singletons/fetch.js.map +1 -0
  121. package/dist/types.d.cts +187 -0
  122. package/dist/types.d.cts.map +1 -0
  123. package/dist/types.d.ts +178 -173
  124. package/dist/types.d.ts.map +1 -0
  125. package/dist/types.messages.d.cts +91 -0
  126. package/dist/types.messages.d.cts.map +1 -0
  127. package/dist/types.messages.d.ts +71 -66
  128. package/dist/types.messages.d.ts.map +1 -0
  129. package/dist/types.stream.d.cts +235 -0
  130. package/dist/types.stream.d.cts.map +1 -0
  131. package/dist/types.stream.d.ts +149 -142
  132. package/dist/types.stream.d.ts.map +1 -0
  133. package/dist/ui/branching.cjs +145 -141
  134. package/dist/ui/branching.cjs.map +1 -0
  135. package/dist/ui/branching.d.cts +22 -0
  136. package/dist/ui/branching.d.cts.map +1 -0
  137. package/dist/ui/branching.d.ts +17 -30
  138. package/dist/ui/branching.d.ts.map +1 -0
  139. package/dist/ui/branching.js +147 -139
  140. package/dist/ui/branching.js.map +1 -0
  141. package/dist/ui/errors.cjs +14 -12
  142. package/dist/ui/errors.cjs.map +1 -0
  143. package/dist/ui/errors.js +14 -9
  144. package/dist/ui/errors.js.map +1 -0
  145. package/dist/ui/manager.cjs +156 -232
  146. package/dist/ui/manager.cjs.map +1 -0
  147. package/dist/ui/manager.js +156 -228
  148. package/dist/ui/manager.js.map +1 -0
  149. package/dist/ui/messages.cjs +55 -69
  150. package/dist/ui/messages.cjs.map +1 -0
  151. package/dist/ui/messages.js +55 -66
  152. package/dist/ui/messages.js.map +1 -0
  153. package/dist/ui/utils.cjs +10 -10
  154. package/dist/ui/utils.cjs.map +1 -0
  155. package/dist/ui/utils.js +10 -8
  156. package/dist/ui/utils.js.map +1 -0
  157. package/dist/utils/async_caller.cjs +103 -185
  158. package/dist/utils/async_caller.cjs.map +1 -0
  159. package/dist/utils/async_caller.d.cts +53 -0
  160. package/dist/utils/async_caller.d.cts.map +1 -0
  161. package/dist/utils/async_caller.d.ts +36 -31
  162. package/dist/utils/async_caller.d.ts.map +1 -0
  163. package/dist/utils/async_caller.js +101 -177
  164. package/dist/utils/async_caller.js.map +1 -0
  165. package/dist/utils/env.cjs +11 -13
  166. package/dist/utils/env.cjs.map +1 -0
  167. package/dist/utils/env.js +11 -11
  168. package/dist/utils/env.js.map +1 -0
  169. package/dist/utils/signals.cjs +18 -19
  170. package/dist/utils/signals.cjs.map +1 -0
  171. package/dist/utils/signals.js +18 -17
  172. package/dist/utils/signals.js.map +1 -0
  173. package/dist/utils/sse.cjs +110 -140
  174. package/dist/utils/sse.cjs.map +1 -0
  175. package/dist/utils/sse.js +110 -138
  176. package/dist/utils/sse.js.map +1 -0
  177. package/dist/utils/stream.cjs +90 -114
  178. package/dist/utils/stream.cjs.map +1 -0
  179. package/dist/utils/stream.js +90 -111
  180. package/dist/utils/stream.js.map +1 -0
  181. package/package.json +72 -80
  182. package/auth.cjs +0 -1
  183. package/auth.d.cts +0 -1
  184. package/auth.d.ts +0 -1
  185. package/auth.js +0 -1
  186. package/client.cjs +0 -1
  187. package/client.d.cts +0 -1
  188. package/client.d.ts +0 -1
  189. package/client.js +0 -1
  190. package/dist/auth/types.cjs +0 -2
  191. package/dist/auth/types.js +0 -1
  192. package/dist/react/stream.lgp.d.ts +0 -7
  193. package/dist/react/thread.d.ts +0 -4
  194. package/dist/react/types.cjs +0 -2
  195. package/dist/react/types.js +0 -1
  196. package/dist/schema.cjs +0 -2
  197. package/dist/schema.js +0 -1
  198. package/dist/types.cjs +0 -2
  199. package/dist/types.js +0 -1
  200. package/dist/types.messages.cjs +0 -2
  201. package/dist/types.messages.js +0 -1
  202. package/dist/types.stream.cjs +0 -2
  203. package/dist/types.stream.js +0 -1
  204. package/dist/ui/branching.test.cjs +0 -370
  205. package/dist/ui/branching.test.d.ts +0 -1
  206. package/dist/ui/branching.test.js +0 -368
  207. package/dist/ui/errors.d.ts +0 -12
  208. package/dist/ui/manager.d.ts +0 -87
  209. package/dist/ui/messages.d.ts +0 -18
  210. package/dist/ui/utils.d.ts +0 -2
  211. package/dist/utils/env.d.ts +0 -1
  212. package/dist/utils/signals.d.ts +0 -1
  213. package/dist/utils/sse.d.ts +0 -8
  214. package/dist/utils/stream.d.ts +0 -13
  215. package/index.cjs +0 -1
  216. package/index.d.cts +0 -1
  217. package/index.d.ts +0 -1
  218. package/index.js +0 -1
  219. package/logging.cjs +0 -1
  220. package/logging.d.cts +0 -1
  221. package/logging.d.ts +0 -1
  222. package/logging.js +0 -1
  223. package/react-ui/server.cjs +0 -1
  224. package/react-ui/server.d.cts +0 -1
  225. package/react-ui/server.d.ts +0 -1
  226. package/react-ui/server.js +0 -1
  227. package/react-ui.cjs +0 -1
  228. package/react-ui.d.cts +0 -1
  229. package/react-ui.d.ts +0 -1
  230. package/react-ui.js +0 -1
  231. package/react.cjs +0 -1
  232. package/react.d.cts +0 -1
  233. package/react.d.ts +0 -1
  234. package/react.js +0 -1
@@ -1,142 +1,127 @@
1
- /* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
2
1
  "use client";
3
- import { useEffect, useRef, useState, useSyncExternalStore } from "react";
4
- import { StreamManager } from "../ui/manager.js";
5
- import { MessageTupleManager } from "../ui/messages.js";
2
+
3
+
6
4
  import { BytesLineDecoder, SSEDecoder } from "../utils/sse.js";
7
5
  import { IterableReadableStream } from "../utils/stream.js";
6
+ import { MessageTupleManager } from "../ui/messages.js";
7
+ import { StreamManager } from "../ui/manager.js";
8
8
  import { useControllableThreadId } from "./thread.js";
9
- export class FetchStreamTransport {
10
- constructor(options) {
11
- Object.defineProperty(this, "options", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: options
16
- });
17
- }
18
- async stream(payload) {
19
- const { signal, ...body } = payload;
20
- let requestInit = {
21
- method: "POST",
22
- headers: {
23
- "Content-Type": "application/json",
24
- ...this.options.defaultHeaders,
25
- },
26
- body: JSON.stringify(body),
27
- signal,
28
- };
29
- if (this.options.onRequest) {
30
- requestInit = await this.options.onRequest(this.options.apiUrl, requestInit);
31
- }
32
- const fetchFn = this.options.fetch ?? fetch;
33
- const response = await fetchFn(this.options.apiUrl, requestInit);
34
- if (!response.ok) {
35
- throw new Error(`Failed to stream: ${response.statusText}`);
36
- }
37
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
38
- .pipeThrough(BytesLineDecoder())
39
- .pipeThrough(SSEDecoder());
40
- return IterableReadableStream.fromReadableStream(stream);
41
- }
42
- }
43
- export function useStreamCustom(options) {
44
- const [messageManager] = useState(() => new MessageTupleManager());
45
- const [stream] = useState(() => new StreamManager(messageManager));
46
- useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getSnapshot);
47
- const [threadId, onThreadId] = useControllableThreadId(options);
48
- const threadIdRef = useRef(threadId);
49
- // Cancel the stream if thread ID has changed
50
- useEffect(() => {
51
- if (threadIdRef.current !== threadId) {
52
- threadIdRef.current = threadId;
53
- stream.clear();
54
- }
55
- }, [threadId, stream]);
56
- const getMessages = (value) => {
57
- const messagesKey = options.messagesKey ?? "messages";
58
- return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];
59
- };
60
- const setMessages = (current, messages) => {
61
- const messagesKey = options.messagesKey ?? "messages";
62
- return { ...current, [messagesKey]: messages };
63
- };
64
- const historyValues = options.initialValues ?? {};
65
- const stop = () => stream.stop(historyValues, { onStop: options.onStop });
66
- const submit = async (values, submitOptions) => {
67
- let callbackMeta;
68
- let usableThreadId = threadId;
69
- stream.setStreamValues(() => {
70
- if (submitOptions?.optimisticValues != null) {
71
- return {
72
- ...historyValues,
73
- ...(typeof submitOptions.optimisticValues === "function"
74
- ? submitOptions.optimisticValues(historyValues)
75
- : submitOptions.optimisticValues),
76
- };
77
- }
78
- return { ...historyValues };
79
- });
80
- await stream.start(async (signal) => {
81
- if (!usableThreadId) {
82
- // generate random thread id
83
- usableThreadId = crypto.randomUUID();
84
- threadIdRef.current = usableThreadId;
85
- onThreadId(usableThreadId);
86
- }
87
- if (!usableThreadId) {
88
- throw new Error("Failed to obtain valid thread ID.");
89
- }
90
- return options.transport.stream({
91
- input: values,
92
- context: submitOptions?.context,
93
- command: submitOptions?.command,
94
- signal,
95
- config: {
96
- ...submitOptions?.config,
97
- configurable: {
98
- thread_id: usableThreadId,
99
- ...submitOptions?.config?.configurable,
100
- },
101
- },
102
- });
103
- }, {
104
- getMessages,
105
- setMessages,
106
- initialValues: {},
107
- callbacks: options,
108
- onSuccess: () => undefined,
109
- onError(error) {
110
- options.onError?.(error, callbackMeta);
111
- },
112
- });
113
- };
114
- return {
115
- get values() {
116
- return stream.values ?? {};
117
- },
118
- error: stream.error,
119
- isLoading: stream.isLoading,
120
- stop,
121
- submit,
122
- get interrupt() {
123
- if (stream.values != null &&
124
- "__interrupt__" in stream.values &&
125
- Array.isArray(stream.values.__interrupt__)) {
126
- const valueInterrupts = stream.values.__interrupt__;
127
- if (valueInterrupts.length === 0)
128
- return { when: "breakpoint" };
129
- if (valueInterrupts.length === 1)
130
- return valueInterrupts[0];
131
- // TODO: fix the typing of interrupts if multiple interrupts are returned
132
- return valueInterrupts;
133
- }
134
- return undefined;
135
- },
136
- get messages() {
137
- if (!stream.values)
138
- return [];
139
- return getMessages(stream.values);
140
- },
141
- };
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 fetchFn = this.options.fetch ?? fetch;
29
+ const response = await fetchFn(this.options.apiUrl, requestInit);
30
+ if (!response.ok) throw new Error(`Failed to stream: ${response.statusText}`);
31
+ const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(BytesLineDecoder()).pipeThrough(SSEDecoder());
32
+ return IterableReadableStream.fromReadableStream(stream);
33
+ }
34
+ };
35
+ function useStreamCustom(options) {
36
+ const [messageManager] = useState(() => new MessageTupleManager());
37
+ const [stream] = useState(() => new StreamManager(messageManager));
38
+ useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getSnapshot);
39
+ const [threadId, onThreadId] = useControllableThreadId(options);
40
+ const threadIdRef = useRef(threadId);
41
+ useEffect(() => {
42
+ if (threadIdRef.current !== threadId) {
43
+ threadIdRef.current = threadId;
44
+ stream.clear();
45
+ }
46
+ }, [threadId, stream]);
47
+ const getMessages = (value) => {
48
+ const messagesKey = options.messagesKey ?? "messages";
49
+ return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];
50
+ };
51
+ const setMessages = (current, messages) => {
52
+ const messagesKey = options.messagesKey ?? "messages";
53
+ return {
54
+ ...current,
55
+ [messagesKey]: messages
56
+ };
57
+ };
58
+ const historyValues = options.initialValues ?? {};
59
+ const stop = () => stream.stop(historyValues, { onStop: options.onStop });
60
+ const submit = async (values, submitOptions) => {
61
+ let callbackMeta;
62
+ let usableThreadId = threadId;
63
+ stream.setStreamValues(() => {
64
+ if (submitOptions?.optimisticValues != null) return {
65
+ ...historyValues,
66
+ ...typeof submitOptions.optimisticValues === "function" ? submitOptions.optimisticValues(historyValues) : submitOptions.optimisticValues
67
+ };
68
+ return { ...historyValues };
69
+ });
70
+ await stream.start(async (signal) => {
71
+ if (!usableThreadId) {
72
+ usableThreadId = crypto.randomUUID();
73
+ threadIdRef.current = usableThreadId;
74
+ onThreadId(usableThreadId);
75
+ }
76
+ if (!usableThreadId) throw new Error("Failed to obtain valid thread ID.");
77
+ return options.transport.stream({
78
+ input: values,
79
+ context: submitOptions?.context,
80
+ command: submitOptions?.command,
81
+ signal,
82
+ config: {
83
+ ...submitOptions?.config,
84
+ configurable: {
85
+ thread_id: usableThreadId,
86
+ ...submitOptions?.config?.configurable
87
+ }
88
+ }
89
+ });
90
+ }, {
91
+ getMessages,
92
+ setMessages,
93
+ initialValues: {},
94
+ callbacks: options,
95
+ onSuccess: () => void 0,
96
+ onError(error) {
97
+ options.onError?.(error, callbackMeta);
98
+ }
99
+ });
100
+ };
101
+ return {
102
+ get values() {
103
+ return stream.values ?? {};
104
+ },
105
+ error: stream.error,
106
+ isLoading: stream.isLoading,
107
+ stop,
108
+ submit,
109
+ get interrupt() {
110
+ if (stream.values != null && "__interrupt__" in stream.values && Array.isArray(stream.values.__interrupt__)) {
111
+ const valueInterrupts = stream.values.__interrupt__;
112
+ if (valueInterrupts.length === 0) return { when: "breakpoint" };
113
+ if (valueInterrupts.length === 1) return valueInterrupts[0];
114
+ return valueInterrupts;
115
+ }
116
+ return void 0;
117
+ },
118
+ get messages() {
119
+ if (!stream.values) return [];
120
+ return getMessages(stream.values);
121
+ }
122
+ };
142
123
  }
124
+
125
+ //#endregion
126
+ export { FetchStreamTransport, useStreamCustom };
127
+ //# sourceMappingURL=stream.custom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.custom.js","names":["options: FetchStreamTransportOptions","requestInit: RequestInit","callbackMeta: RunCallbackMeta | undefined"],"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 BagTemplate,\n GetUpdateType,\n GetCustomEventType,\n GetInterruptType,\n RunCallbackMeta,\n GetConfigurableType,\n UseStreamCustomOptions,\n UseStreamCustom,\n UseStreamTransport,\n CustomSubmitOptions,\n} from \"./types.js\";\nimport type { Message } from \"../types.messages.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\";\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 {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options: UseStreamCustomOptions<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\n const [messageManager] = useState(() => new MessageTupleManager());\n const [stream] = useState(\n () => new StreamManager<StateType, Bag>(messageManager)\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]) ? value[messagesKey] : [];\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 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 callbackMeta: RunCallbackMeta | undefined;\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, callbackMeta);\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 interrupt(): Interrupt<InterruptType> | undefined {\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 if (valueInterrupts.length === 1) return valueInterrupts[0];\n\n // TODO: fix the typing of interrupts if multiple interrupts are returned\n return valueInterrupts as Interrupt<InterruptType>;\n }\n\n return undefined;\n },\n\n get messages() {\n if (!stream.values) return [];\n return getMessages(stream.values);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAmDA,IAAa,uBAAb,MAIA;CACE,YAAY,AAAiBA,SAAsC;EAAtC;;CAE7B,MAAM,OAAO,SAK8D;EACzE,MAAM,EAAE,OAAQ,GAAG,SAAS;EAE5B,IAAIC,cAA2B;GAC7B,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,GAAG,KAAK,QAAQ;;GAElB,MAAM,KAAK,UAAU;GACrB;;AAGF,MAAI,KAAK,QAAQ,UACf,eAAc,MAAM,KAAK,QAAQ,UAC/B,KAAK,QAAQ,QACb;EAGJ,MAAM,UAAU,KAAK,QAAQ,SAAS;EAEtC,MAAM,WAAW,MAAM,QAAQ,KAAK,QAAQ,QAAQ;AACpD,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,qBAAqB,SAAS;EAGhD,MAAM,UACJ,SAAS,QAAQ,IAAI,eAAe,EAAE,QAAQ,SAAS,KAAK,YAE3D,YAAY,oBACZ,YAAY;AAEf,SAAO,uBAAuB,mBAAmB;;;AAIrD,SAAgB,gBASd,SACiC;CAMjC,MAAM,CAAC,kBAAkB,eAAe,IAAI;CAC5C,MAAM,CAAC,UAAU,eACT,IAAI,cAA8B;AAG1C,sBACE,OAAO,WACP,OAAO,aACP,OAAO;CAGT,MAAM,CAAC,UAAU,cAAc,wBAAwB;CACvD,MAAM,cAAc,OAAsB;AAG1C,iBAAgB;AACd,MAAI,YAAY,YAAY,UAAU;AACpC,eAAY,UAAU;AACtB,UAAO;;IAER,CAAC,UAAU;CAEd,MAAM,eAAe,UAAgC;EACnD,MAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO,MAAM,QAAQ,MAAM,gBAAgB,MAAM,eAAe;;CAGlE,MAAM,eAAe,SAAoB,aAAmC;EAC1E,MAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO;GAAE,GAAG;IAAU,cAAc;;;CAGtC,MAAM,gBAAgB,QAAQ,iBAAkB;CAEhD,MAAM,aAAa,OAAO,KAAK,eAAe,EAAE,QAAQ,QAAQ;CAEhE,MAAM,SAAS,OACb,QACA,kBACG;EACH,IAAIC;EACJ,IAAI,iBAAiB;AAErB,SAAO,sBAAsB;AAC3B,OAAI,eAAe,oBAAoB,KACrC,QAAO;IACL,GAAG;IACH,GAAI,OAAO,cAAc,qBAAqB,aAC1C,cAAc,iBAAiB,iBAC/B,cAAc;;AAItB,UAAO,EAAE,GAAG;;AAGd,QAAM,OAAO,MACX,OAAO,WAAwB;AAC7B,OAAI,CAAC,gBAAgB;AAEnB,qBAAiB,OAAO;AACxB,gBAAY,UAAU;AACtB,eAAW;;AAGb,OAAI,CAAC,eACH,OAAM,IAAI,MAAM;AAGlB,UAAO,QAAQ,UAAU,OAAO;IAC9B,OAAO;IACP,SAAS,eAAe;IACxB,SAAS,eAAe;IACxB;IACA,QAAQ;KACN,GAAG,eAAe;KAClB,cAAc;MACZ,WAAW;MACX,GAAG,eAAe,QAAQ;;;;KAOlC;GACE;GACA;GAEA,eAAe;GACf,WAAW;GAEX,iBAAiB;GACjB,QAAQ,OAAO;AACb,YAAQ,UAAU,OAAO;;;;AAMjC,QAAO;EACL,IAAI,SAAS;AACX,UAAO,OAAO,UAAW;;EAG3B,OAAO,OAAO;EACd,WAAW,OAAO;EAElB;EACA;EAEA,IAAI,YAAkD;AACpD,OACE,OAAO,UAAU,QACjB,mBAAmB,OAAO,UAC1B,MAAM,QAAQ,OAAO,OAAO,gBAC5B;IACA,MAAM,kBAAkB,OAAO,OAAO;AACtC,QAAI,gBAAgB,WAAW,EAAG,QAAO,EAAE,MAAM;AACjD,QAAI,gBAAgB,WAAW,EAAG,QAAO,gBAAgB;AAGzD,WAAO;;AAGT,UAAO;;EAGT,IAAI,WAAW;AACb,OAAI,CAAC,OAAO,OAAQ,QAAO;AAC3B,UAAO,YAAY,OAAO"}
@@ -0,0 +1,73 @@
1
+ import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from "./types.cjs";
2
+
3
+ //#region src/react/stream.d.ts
4
+
5
+ /**
6
+ * A React hook that provides seamless integration with LangGraph streaming capabilities.
7
+ *
8
+ * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
9
+ * letting you focus on building great chat experiences. It provides automatic state management for
10
+ * messages, interrupts, loading states, and errors.
11
+ *
12
+ * @template StateType The type of the thread state (default: `Record<string, unknown>`)
13
+ * @template Bag Type configuration bag containing:
14
+ * - `ConfigurableType`: Type for the `config.configurable` property
15
+ * - `InterruptType`: Type for interrupt values
16
+ * - `CustomEventType`: Type for custom events
17
+ * - `UpdateType`: Type for the submit function updates
18
+ *
19
+ * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
20
+ */
21
+ declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
22
+ ConfigurableType?: Record<string, unknown>;
23
+ InterruptType?: unknown;
24
+ CustomEventType?: unknown;
25
+ UpdateType?: unknown;
26
+ } = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
27
+ /**
28
+ * A React hook that provides seamless integration with LangGraph streaming capabilities.
29
+ *
30
+ * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
31
+ * letting you focus on building great chat experiences. It provides automatic state management for
32
+ * messages, interrupts, loading states, and errors.
33
+ *
34
+ * @template StateType The type of the thread state (default: `Record<string, unknown>`)
35
+ * @template Bag Type configuration bag containing:
36
+ * - `ConfigurableType`: Type for the `config.configurable` property
37
+ * - `InterruptType`: Type for interrupt values
38
+ * - `CustomEventType`: Type for custom events
39
+ * - `UpdateType`: Type for the submit function updates
40
+ *
41
+ * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
42
+ */
43
+ declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
44
+ ConfigurableType?: Record<string, unknown>;
45
+ InterruptType?: unknown;
46
+ CustomEventType?: unknown;
47
+ UpdateType?: unknown;
48
+ } = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;
49
+ /**
50
+ * A React hook that provides seamless integration with LangGraph streaming capabilities.
51
+ *
52
+ * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
53
+ * letting you focus on building great chat experiences. It provides automatic state management for
54
+ * messages, interrupts, loading states, and errors.
55
+ *
56
+ * @template StateType The type of the thread state (default: `Record<string, unknown>`)
57
+ * @template Bag Type configuration bag containing:
58
+ * - `ConfigurableType`: Type for the `config.configurable` property
59
+ * - `InterruptType`: Type for interrupt values
60
+ * - `CustomEventType`: Type for custom events
61
+ * - `UpdateType`: Type for the submit function updates
62
+ *
63
+ * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
64
+ */
65
+ declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
66
+ ConfigurableType?: Record<string, unknown>;
67
+ InterruptType?: unknown;
68
+ CustomEventType?: unknown;
69
+ UpdateType?: unknown;
70
+ } = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
71
+ //#endregion
72
+ export { useStream };
73
+ //# sourceMappingURL=stream.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.cts","names":["BagTemplate","UseStream","UseStreamCustom","UseStreamCustomOptions","UseStreamOptions","useStream","Record","StateType","Bag"],"sources":["../../src/react/stream.d.ts"],"sourcesContent":["import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from \"./types.js\";\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 StateType The type of the thread state (default: `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 declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\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 StateType The type of the thread state (default: `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 declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;\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 StateType The type of the thread state (default: `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 declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n"],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;AAsBA;AAAiC,iBAtBTK,SAsBS,CAAA,kBAtBmBC,MAsBnB,CAAA,MAAA,EAAA,OAAA,CAAA,GAtB6CA,MAsB7C,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,YAAA;kBAAmBA,CAAAA,EArB7BA,MAqB6BA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;eAA0BA,CAAAA,EAAAA,OAAAA;iBACvDA,CAAAA,EAAAA,OAAAA;YAInBN,CAAAA,EAAAA,OAAAA;IAtBAA,WAsB6CO,CAAAA,CAAAA,OAAAA,EAtBvBH,gBAsBuBG,CAtBNA,SAsBMA,EAtBKC,GAsBLD,CAAAA,CAAAA,EAtBYN,SAsBZM,CAtBsBA,SAsBtBA,EAtBiCC,GAsBjCD,CAAAA;;;;;;;AAiBjD;;;;;;;;;;AAKkFC,iBA3B1DH,SA2B0DG,CAAAA,kBA3B9BF,MA2B8BE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GA3BJF,MA2BIE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAAAA;kBAArBP,CAAAA,EA1BtCK,MA0BsCL,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;IAtBzDD,sBAAsBG,uBAAuBI,WAAWC,OAAON,gBAAgBK,WAAWC;;;;;;;;;;;;;;;;;iBAiBtEH,4BAA4BC,0BAA0BA;qBACvDA;;;;IAInBN,sBAAsBI,iBAAiBG,WAAWC,OAAOP,UAAUM,WAAWC"}
@@ -1,4 +1,7 @@
1
1
  import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from "./types.js";
2
+
3
+ //#region src/react/stream.d.ts
4
+
2
5
  /**
3
6
  * A React hook that provides seamless integration with LangGraph streaming capabilities.
4
7
  *
@@ -15,11 +18,11 @@ import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStr
15
18
  *
16
19
  * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
17
20
  */
18
- export declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
19
- ConfigurableType?: Record<string, unknown>;
20
- InterruptType?: unknown;
21
- CustomEventType?: unknown;
22
- UpdateType?: unknown;
21
+ declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
22
+ ConfigurableType?: Record<string, unknown>;
23
+ InterruptType?: unknown;
24
+ CustomEventType?: unknown;
25
+ UpdateType?: unknown;
23
26
  } = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
24
27
  /**
25
28
  * A React hook that provides seamless integration with LangGraph streaming capabilities.
@@ -37,11 +40,11 @@ export declare function useStream<StateType extends Record<string, unknown> = Re
37
40
  *
38
41
  * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
39
42
  */
40
- export declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
41
- ConfigurableType?: Record<string, unknown>;
42
- InterruptType?: unknown;
43
- CustomEventType?: unknown;
44
- UpdateType?: unknown;
43
+ declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
44
+ ConfigurableType?: Record<string, unknown>;
45
+ InterruptType?: unknown;
46
+ CustomEventType?: unknown;
47
+ UpdateType?: unknown;
45
48
  } = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;
46
49
  /**
47
50
  * A React hook that provides seamless integration with LangGraph streaming capabilities.
@@ -59,9 +62,12 @@ export declare function useStream<StateType extends Record<string, unknown> = Re
59
62
  *
60
63
  * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
61
64
  */
62
- export declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
63
- ConfigurableType?: Record<string, unknown>;
64
- InterruptType?: unknown;
65
- CustomEventType?: unknown;
66
- UpdateType?: unknown;
65
+ declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
66
+ ConfigurableType?: Record<string, unknown>;
67
+ InterruptType?: unknown;
68
+ CustomEventType?: unknown;
69
+ UpdateType?: unknown;
67
70
  } = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
71
+ //#endregion
72
+ export { useStream };
73
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","names":["BagTemplate","UseStream","UseStreamCustom","UseStreamCustomOptions","UseStreamOptions","useStream","Record","StateType","Bag"],"sources":["../../src/react/stream.d.ts"],"sourcesContent":["import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from \"./types.js\";\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 StateType The type of the thread state (default: `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 declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\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 StateType The type of the thread state (default: `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 declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;\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 StateType The type of the thread state (default: `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 declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n"],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;AAsBA;AAAiC,iBAtBTK,SAsBS,CAAA,kBAtBmBC,MAsBnB,CAAA,MAAA,EAAA,OAAA,CAAA,GAtB6CA,MAsB7C,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,YAAA;kBAAmBA,CAAAA,EArB7BA,MAqB6BA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;eAA0BA,CAAAA,EAAAA,OAAAA;iBACvDA,CAAAA,EAAAA,OAAAA;YAInBN,CAAAA,EAAAA,OAAAA;IAtBAA,WAsB6CO,CAAAA,CAAAA,OAAAA,EAtBvBH,gBAsBuBG,CAtBNA,SAsBMA,EAtBKC,GAsBLD,CAAAA,CAAAA,EAtBYN,SAsBZM,CAtBsBA,SAsBtBA,EAtBiCC,GAsBjCD,CAAAA;;;;;;;AAiBjD;;;;;;;;;;AAKkFC,iBA3B1DH,SA2B0DG,CAAAA,kBA3B9BF,MA2B8BE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GA3BJF,MA2BIE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAAAA;kBAArBP,CAAAA,EA1BtCK,MA0BsCL,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;IAtBzDD,sBAAsBG,uBAAuBI,WAAWC,OAAON,gBAAgBK,WAAWC;;;;;;;;;;;;;;;;;iBAiBtEH,4BAA4BC,0BAA0BA;qBACvDA;;;;IAInBN,sBAAsBI,iBAAiBG,WAAWC,OAAOP,UAAUM,WAAWC"}
@@ -1,16 +1,17 @@
1
- import { useState } from "react";
2
1
  import { useStreamLGP } from "./stream.lgp.js";
3
2
  import { useStreamCustom } from "./stream.custom.js";
3
+ import { useState } from "react";
4
+
5
+ //#region src/react/stream.tsx
4
6
  function isCustomOptions(options) {
5
- return "transport" in options;
7
+ return "transport" in options;
6
8
  }
7
- export function useStream(options) {
8
- // Store this in useState to make sure we're not changing the implementation in re-renders
9
- const [isCustom] = useState(isCustomOptions(options));
10
- if (isCustom) {
11
- // eslint-disable-next-line react-hooks/rules-of-hooks
12
- return useStreamCustom(options);
13
- }
14
- // eslint-disable-next-line react-hooks/rules-of-hooks
15
- return useStreamLGP(options);
9
+ function useStream(options) {
10
+ const [isCustom] = useState(isCustomOptions(options));
11
+ if (isCustom) return useStreamCustom(options);
12
+ return useStreamLGP(options);
16
13
  }
14
+
15
+ //#endregion
16
+ export { useStream };
17
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
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 {\n BagTemplate,\n UseStream,\n UseStreamCustom,\n UseStreamCustomOptions,\n UseStreamOptions,\n} from \"./types.js\";\n\nfunction isCustomOptions<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = 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, and errors.\n *\n * @template StateType The type of the thread state (default: `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 StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, 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 StateType The type of the thread state (default: `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 StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options: UseStreamCustomOptions<StateType, Bag>\n): UseStreamCustom<StateType, 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 StateType The type of the thread state (default: `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 StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n\nexport function useStream<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options:\n | UseStreamOptions<StateType, Bag>\n | UseStreamCustomOptions<StateType, Bag>\n): UseStream<StateType, Bag> | UseStreamCustom<StateType, Bag> {\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 as UseStreamCustomOptions<StateType, Bag>);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamLGP(options as UseStreamOptions<StateType, Bag>);\n}\n"],"mappings":";;;;;AAWA,SAAS,gBASP,SAGmD;AACnD,QAAO,eAAe;;AAmFxB,SAAgB,UASd,SAG6D;CAE7D,MAAM,CAAC,YAAY,SAAS,gBAAgB;AAE5C,KAAI,SAEF,QAAO,gBAAgB;AAIzB,QAAO,aAAa"}