@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,351 +1,355 @@
1
- import type { Client, ClientConfig } from "../client.js";
2
- import type { ThreadState, Interrupt, Config, Checkpoint, Metadata } from "../schema.js";
3
- import type { Command, MultitaskStrategy, OnCompletionBehavior, DisconnectMode, Durability } from "../types.js";
4
- import type { Message } from "../types.messages.js";
5
- import type { UpdatesStreamEvent, CustomStreamEvent, MetadataStreamEvent, EventsStreamEvent, DebugStreamEvent, CheckpointsStreamEvent, TasksStreamEvent, StreamMode } from "../types.stream.js";
6
- import type { Sequence } from "../ui/branching.js";
7
- export type MessageMetadata<StateType extends Record<string, unknown>> = {
8
- /**
9
- * The ID of the message used.
10
- */
11
- messageId: string;
12
- /**
13
- * The first thread state the message was seen in.
14
- */
15
- firstSeenState: ThreadState<StateType> | undefined;
16
- /**
17
- * The branch of the message.
18
- */
19
- branch: string | undefined;
20
- /**
21
- * The list of branches this message is part of.
22
- * This is useful for displaying branching controls.
23
- */
24
- branchOptions: string[] | undefined;
25
- /**
26
- * Metadata sent alongside the message during run streaming.
27
- * @remarks This metadata only exists temporarily in browser memory during streaming and is not persisted after completion.
28
- */
29
- streamMetadata: Record<string, unknown> | undefined;
1
+ import { Checkpoint, Config, Interrupt, Metadata, ThreadState } from "../schema.js";
2
+ import { Message } from "../types.messages.js";
3
+ import { CheckpointsStreamEvent, CustomStreamEvent, DebugStreamEvent, EventsStreamEvent, MetadataStreamEvent, StreamMode, TasksStreamEvent, UpdatesStreamEvent } from "../types.stream.js";
4
+ import { Command, DisconnectMode, Durability, MultitaskStrategy, OnCompletionBehavior } from "../types.js";
5
+ import { Client, ClientConfig } from "../client.js";
6
+ import { Sequence } from "../ui/branching.js";
7
+
8
+ //#region src/react/types.d.ts
9
+ type MessageMetadata<StateType extends Record<string, unknown>> = {
10
+ /**
11
+ * The ID of the message used.
12
+ */
13
+ messageId: string;
14
+ /**
15
+ * The first thread state the message was seen in.
16
+ */
17
+ firstSeenState: ThreadState<StateType> | undefined;
18
+ /**
19
+ * The branch of the message.
20
+ */
21
+ branch: string | undefined;
22
+ /**
23
+ * The list of branches this message is part of.
24
+ * This is useful for displaying branching controls.
25
+ */
26
+ branchOptions: string[] | undefined;
27
+ /**
28
+ * Metadata sent alongside the message during run streaming.
29
+ * @remarks This metadata only exists temporarily in browser memory during streaming and is not persisted after completion.
30
+ */
31
+ streamMetadata: Record<string, unknown> | undefined;
30
32
  };
31
- export type BagTemplate = {
32
- ConfigurableType?: Record<string, unknown>;
33
- InterruptType?: unknown;
34
- CustomEventType?: unknown;
35
- UpdateType?: unknown;
33
+ type BagTemplate = {
34
+ ConfigurableType?: Record<string, unknown>;
35
+ InterruptType?: unknown;
36
+ CustomEventType?: unknown;
37
+ UpdateType?: unknown;
36
38
  };
37
- export type GetUpdateType<Bag extends BagTemplate, StateType extends Record<string, unknown>> = Bag extends {
38
- UpdateType: unknown;
39
+ type GetUpdateType<Bag extends BagTemplate, StateType extends Record<string, unknown>> = Bag extends {
40
+ UpdateType: unknown;
39
41
  } ? Bag["UpdateType"] : Partial<StateType>;
40
- export type GetConfigurableType<Bag extends BagTemplate> = Bag extends {
41
- ConfigurableType: Record<string, unknown>;
42
+ type GetConfigurableType<Bag extends BagTemplate> = Bag extends {
43
+ ConfigurableType: Record<string, unknown>;
42
44
  } ? Bag["ConfigurableType"] : Record<string, unknown>;
43
- export type GetInterruptType<Bag extends BagTemplate> = Bag extends {
44
- InterruptType: unknown;
45
+ type GetInterruptType<Bag extends BagTemplate> = Bag extends {
46
+ InterruptType: unknown;
45
47
  } ? Bag["InterruptType"] : unknown;
46
- export type GetCustomEventType<Bag extends BagTemplate> = Bag extends {
47
- CustomEventType: unknown;
48
+ type GetCustomEventType<Bag extends BagTemplate> = Bag extends {
49
+ CustomEventType: unknown;
48
50
  } ? Bag["CustomEventType"] : unknown;
49
- export interface RunCallbackMeta {
50
- run_id: string;
51
- thread_id: string;
51
+ interface RunCallbackMeta {
52
+ run_id: string;
53
+ thread_id: string;
52
54
  }
53
- export interface UseStreamThread<StateType extends Record<string, unknown>> {
54
- data: ThreadState<StateType>[] | null | undefined;
55
- error: unknown;
56
- isLoading: boolean;
57
- mutate: (mutateId?: string) => Promise<ThreadState<StateType>[] | null | undefined>;
55
+ interface UseStreamThread<StateType extends Record<string, unknown>> {
56
+ data: ThreadState<StateType>[] | null | undefined;
57
+ error: unknown;
58
+ isLoading: boolean;
59
+ mutate: (mutateId?: string) => Promise<ThreadState<StateType>[] | null | undefined>;
58
60
  }
59
- export interface UseStreamOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
60
- /**
61
- * The ID of the assistant to use.
62
- */
63
- assistantId: string;
64
- /**
65
- * Client used to send requests.
66
- */
67
- client?: Client;
68
- /**
69
- * The URL of the API to use.
70
- */
71
- apiUrl?: ClientConfig["apiUrl"];
72
- /**
73
- * The API key to use.
74
- */
75
- apiKey?: ClientConfig["apiKey"];
76
- /**
77
- * Custom call options, such as custom fetch implementation.
78
- */
79
- callerOptions?: ClientConfig["callerOptions"];
80
- /**
81
- * Default headers to send with requests.
82
- */
83
- defaultHeaders?: ClientConfig["defaultHeaders"];
84
- /**
85
- * Specify the key within the state that contains messages.
86
- * Defaults to "messages".
87
- *
88
- * @default "messages"
89
- */
90
- messagesKey?: string;
91
- /**
92
- * Callback that is called when an error occurs.
93
- */
94
- onError?: (error: unknown, run: RunCallbackMeta | undefined) => void;
95
- /**
96
- * Callback that is called when the stream is finished.
97
- */
98
- onFinish?: (state: ThreadState<StateType>, run: RunCallbackMeta | undefined) => void;
99
- /**
100
- * Callback that is called when a new stream is created.
101
- */
102
- onCreated?: (run: RunCallbackMeta) => void;
103
- /**
104
- * Callback that is called when an update event is received.
105
- */
106
- onUpdateEvent?: (data: UpdatesStreamEvent<GetUpdateType<Bag, StateType>>["data"], options: {
107
- namespace: string[] | undefined;
108
- mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
109
- }) => void;
110
- /**
111
- * Callback that is called when a custom event is received.
112
- */
113
- onCustomEvent?: (data: CustomStreamEvent<GetCustomEventType<Bag>>["data"], options: {
114
- namespace: string[] | undefined;
115
- mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
116
- }) => void;
117
- /**
118
- * Callback that is called when a metadata event is received.
119
- */
120
- onMetadataEvent?: (data: MetadataStreamEvent["data"]) => void;
121
- /**
122
- * Callback that is called when a LangChain event is received.
123
- * @see https://langchain-ai.github.io/langgraph/cloud/how-tos/stream_events/#stream-graph-in-events-mode for more details.
124
- */
125
- onLangChainEvent?: (data: EventsStreamEvent["data"]) => void;
126
- /**
127
- * Callback that is called when a debug event is received.
128
- * @internal This API is experimental and subject to change.
129
- */
130
- onDebugEvent?: (data: DebugStreamEvent["data"], options: {
131
- namespace: string[] | undefined;
132
- }) => void;
133
- /**
134
- * Callback that is called when a checkpoints event is received.
135
- */
136
- onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>["data"], options: {
137
- namespace: string[] | undefined;
138
- }) => void;
139
- /**
140
- * Callback that is called when a tasks event is received.
141
- */
142
- onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>["data"], options: {
143
- namespace: string[] | undefined;
144
- }) => void;
145
- /**
146
- * Callback that is called when the stream is stopped by the user.
147
- * Provides a mutate function to update the stream state immediately
148
- * without requiring a server roundtrip.
149
- *
150
- * @example
151
- * ```typescript
152
- * onStop: ({ mutate }) => {
153
- * mutate((prev) => ({
154
- * ...prev,
155
- * ui: prev.ui?.map(component =>
156
- * component.props.isLoading
157
- * ? { ...component, props: { ...component.props, stopped: true, isLoading: false }}
158
- * : component
159
- * )
160
- * }));
161
- * }
162
- * ```
163
- */
164
- onStop?: (options: {
165
- mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
166
- }) => void;
167
- /**
168
- * The ID of the thread to fetch history and current values from.
169
- */
170
- threadId?: string | null;
171
- /**
172
- * Callback that is called when the thread ID is updated (ie when a new thread is created).
173
- */
174
- onThreadId?: (threadId: string) => void;
175
- /** Will reconnect the stream on mount */
176
- reconnectOnMount?: boolean | (() => RunMetadataStorage);
177
- /**
178
- * Initial values to display immediately when loading a thread.
179
- * Useful for displaying cached thread data while official history loads.
180
- * These values will be replaced when official thread data is fetched.
181
- *
182
- * Note: UI components from initialValues will render immediately if they're
183
- * predefined in LoadExternalComponent's components prop, providing instant
184
- * cached UI display without server fetches.
185
- */
186
- initialValues?: StateType | null;
187
- /**
188
- * Whether to fetch the history of the thread.
189
- * If true, the history will be fetched from the server. Defaults to 10 entries.
190
- * If false, only the last state will be fetched from the server.
191
- * @default true
192
- */
193
- fetchStateHistory?: boolean | {
194
- limit: number;
195
- };
196
- /**
197
- * Manage the thread state externally.
198
- * @experimental
199
- */
200
- experimental_thread?: UseStreamThread<StateType>;
61
+ interface UseStreamOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
62
+ /**
63
+ * The ID of the assistant to use.
64
+ */
65
+ assistantId: string;
66
+ /**
67
+ * Client used to send requests.
68
+ */
69
+ client?: Client;
70
+ /**
71
+ * The URL of the API to use.
72
+ */
73
+ apiUrl?: ClientConfig["apiUrl"];
74
+ /**
75
+ * The API key to use.
76
+ */
77
+ apiKey?: ClientConfig["apiKey"];
78
+ /**
79
+ * Custom call options, such as custom fetch implementation.
80
+ */
81
+ callerOptions?: ClientConfig["callerOptions"];
82
+ /**
83
+ * Default headers to send with requests.
84
+ */
85
+ defaultHeaders?: ClientConfig["defaultHeaders"];
86
+ /**
87
+ * Specify the key within the state that contains messages.
88
+ * Defaults to "messages".
89
+ *
90
+ * @default "messages"
91
+ */
92
+ messagesKey?: string;
93
+ /**
94
+ * Callback that is called when an error occurs.
95
+ */
96
+ onError?: (error: unknown, run: RunCallbackMeta | undefined) => void;
97
+ /**
98
+ * Callback that is called when the stream is finished.
99
+ */
100
+ onFinish?: (state: ThreadState<StateType>, run: RunCallbackMeta | undefined) => void;
101
+ /**
102
+ * Callback that is called when a new stream is created.
103
+ */
104
+ onCreated?: (run: RunCallbackMeta) => void;
105
+ /**
106
+ * Callback that is called when an update event is received.
107
+ */
108
+ onUpdateEvent?: (data: UpdatesStreamEvent<GetUpdateType<Bag, StateType>>["data"], options: {
109
+ namespace: string[] | undefined;
110
+ mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
111
+ }) => void;
112
+ /**
113
+ * Callback that is called when a custom event is received.
114
+ */
115
+ onCustomEvent?: (data: CustomStreamEvent<GetCustomEventType<Bag>>["data"], options: {
116
+ namespace: string[] | undefined;
117
+ mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
118
+ }) => void;
119
+ /**
120
+ * Callback that is called when a metadata event is received.
121
+ */
122
+ onMetadataEvent?: (data: MetadataStreamEvent["data"]) => void;
123
+ /**
124
+ * Callback that is called when a LangChain event is received.
125
+ * @see https://langchain-ai.github.io/langgraph/cloud/how-tos/stream_events/#stream-graph-in-events-mode for more details.
126
+ */
127
+ onLangChainEvent?: (data: EventsStreamEvent["data"]) => void;
128
+ /**
129
+ * Callback that is called when a debug event is received.
130
+ * @internal This API is experimental and subject to change.
131
+ */
132
+ onDebugEvent?: (data: DebugStreamEvent["data"], options: {
133
+ namespace: string[] | undefined;
134
+ }) => void;
135
+ /**
136
+ * Callback that is called when a checkpoints event is received.
137
+ */
138
+ onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>["data"], options: {
139
+ namespace: string[] | undefined;
140
+ }) => void;
141
+ /**
142
+ * Callback that is called when a tasks event is received.
143
+ */
144
+ onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>["data"], options: {
145
+ namespace: string[] | undefined;
146
+ }) => void;
147
+ /**
148
+ * Callback that is called when the stream is stopped by the user.
149
+ * Provides a mutate function to update the stream state immediately
150
+ * without requiring a server roundtrip.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * onStop: ({ mutate }) => {
155
+ * mutate((prev) => ({
156
+ * ...prev,
157
+ * ui: prev.ui?.map(component =>
158
+ * component.props.isLoading
159
+ * ? { ...component, props: { ...component.props, stopped: true, isLoading: false }}
160
+ * : component
161
+ * )
162
+ * }));
163
+ * }
164
+ * ```
165
+ */
166
+ onStop?: (options: {
167
+ mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
168
+ }) => void;
169
+ /**
170
+ * The ID of the thread to fetch history and current values from.
171
+ */
172
+ threadId?: string | null;
173
+ /**
174
+ * Callback that is called when the thread ID is updated (ie when a new thread is created).
175
+ */
176
+ onThreadId?: (threadId: string) => void;
177
+ /** Will reconnect the stream on mount */
178
+ reconnectOnMount?: boolean | (() => RunMetadataStorage);
179
+ /**
180
+ * Initial values to display immediately when loading a thread.
181
+ * Useful for displaying cached thread data while official history loads.
182
+ * These values will be replaced when official thread data is fetched.
183
+ *
184
+ * Note: UI components from initialValues will render immediately if they're
185
+ * predefined in LoadExternalComponent's components prop, providing instant
186
+ * cached UI display without server fetches.
187
+ */
188
+ initialValues?: StateType | null;
189
+ /**
190
+ * Whether to fetch the history of the thread.
191
+ * If true, the history will be fetched from the server. Defaults to 10 entries.
192
+ * If false, only the last state will be fetched from the server.
193
+ * @default true
194
+ */
195
+ fetchStateHistory?: boolean | {
196
+ limit: number;
197
+ };
198
+ /**
199
+ * Manage the thread state externally.
200
+ * @experimental
201
+ */
202
+ experimental_thread?: UseStreamThread<StateType>;
201
203
  }
202
204
  interface RunMetadataStorage {
203
- getItem(key: `lg:stream:${string}`): string | null;
204
- setItem(key: `lg:stream:${string}`, value: string): void;
205
- removeItem(key: `lg:stream:${string}`): void;
205
+ getItem(key: `lg:stream:${string}`): string | null;
206
+ setItem(key: `lg:stream:${string}`, value: string): void;
207
+ removeItem(key: `lg:stream:${string}`): void;
206
208
  }
207
- export interface UseStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
208
- /**
209
- * The current values of the thread.
210
- */
211
- values: StateType;
212
- /**
213
- * Last seen error from the thread or during streaming.
214
- */
215
- error: unknown;
216
- /**
217
- * Whether the stream is currently running.
218
- */
219
- isLoading: boolean;
220
- /**
221
- * Whether the thread is currently being loaded.
222
- */
223
- isThreadLoading: boolean;
224
- /**
225
- * Stops the stream.
226
- */
227
- stop: () => Promise<void>;
228
- /**
229
- * Create and stream a run to the thread.
230
- */
231
- submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
232
- /**
233
- * The current branch of the thread.
234
- */
235
- branch: string;
236
- /**
237
- * Set the branch of the thread.
238
- */
239
- setBranch: (branch: string) => void;
240
- /**
241
- * Flattened history of thread states of a thread.
242
- */
243
- history: ThreadState<StateType>[];
244
- /**
245
- * Tree of all branches for the thread.
246
- * @experimental
247
- */
248
- experimental_branchTree: Sequence<StateType>;
249
- /**
250
- * Get the interrupt value for the stream if interrupted.
251
- */
252
- interrupt: Interrupt<GetInterruptType<Bag>> | undefined;
253
- /**
254
- * Messages inferred from the thread.
255
- * Will automatically update with incoming message chunks.
256
- */
257
- messages: Message[];
258
- /**
259
- * Get the metadata for a message, such as first thread state the message
260
- * was seen in and branch information.
261
-
262
- * @param message - The message to get the metadata for.
263
- * @param index - The index of the message in the thread.
264
- * @returns The metadata for the message.
265
- */
266
- getMessagesMetadata: (message: Message, index?: number) => MessageMetadata<StateType> | undefined;
267
- /**
268
- * LangGraph SDK client used to send request and receive responses.
269
- */
270
- client: Client;
271
- /**
272
- * The ID of the assistant to use.
273
- */
274
- assistantId: string;
275
- /**
276
- * Join an active stream.
277
- */
278
- joinStream: (runId: string, lastEventId?: string, options?: {
279
- streamMode?: StreamMode | StreamMode[];
280
- }) => Promise<void>;
209
+ interface UseStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
210
+ /**
211
+ * The current values of the thread.
212
+ */
213
+ values: StateType;
214
+ /**
215
+ * Last seen error from the thread or during streaming.
216
+ */
217
+ error: unknown;
218
+ /**
219
+ * Whether the stream is currently running.
220
+ */
221
+ isLoading: boolean;
222
+ /**
223
+ * Whether the thread is currently being loaded.
224
+ */
225
+ isThreadLoading: boolean;
226
+ /**
227
+ * Stops the stream.
228
+ */
229
+ stop: () => Promise<void>;
230
+ /**
231
+ * Create and stream a run to the thread.
232
+ */
233
+ submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
234
+ /**
235
+ * The current branch of the thread.
236
+ */
237
+ branch: string;
238
+ /**
239
+ * Set the branch of the thread.
240
+ */
241
+ setBranch: (branch: string) => void;
242
+ /**
243
+ * Flattened history of thread states of a thread.
244
+ */
245
+ history: ThreadState<StateType>[];
246
+ /**
247
+ * Tree of all branches for the thread.
248
+ * @experimental
249
+ */
250
+ experimental_branchTree: Sequence<StateType>;
251
+ /**
252
+ * Get the interrupt value for the stream if interrupted.
253
+ */
254
+ interrupt: Interrupt<GetInterruptType<Bag>> | undefined;
255
+ /**
256
+ * Messages inferred from the thread.
257
+ * Will automatically update with incoming message chunks.
258
+ */
259
+ messages: Message[];
260
+ /**
261
+ * Get the metadata for a message, such as first thread state the message
262
+ * was seen in and branch information.
263
+
264
+ * @param message - The message to get the metadata for.
265
+ * @param index - The index of the message in the thread.
266
+ * @returns The metadata for the message.
267
+ */
268
+ getMessagesMetadata: (message: Message, index?: number) => MessageMetadata<StateType> | undefined;
269
+ /**
270
+ * LangGraph SDK client used to send request and receive responses.
271
+ */
272
+ client: Client;
273
+ /**
274
+ * The ID of the assistant to use.
275
+ */
276
+ assistantId: string;
277
+ /**
278
+ * Join an active stream.
279
+ */
280
+ joinStream: (runId: string, lastEventId?: string, options?: {
281
+ streamMode?: StreamMode | StreamMode[];
282
+ }) => Promise<void>;
281
283
  }
282
284
  type ConfigWithConfigurable<ConfigurableType extends Record<string, unknown>> = Config & {
283
- configurable?: ConfigurableType;
285
+ configurable?: ConfigurableType;
284
286
  };
285
- export interface SubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ContextType extends Record<string, unknown> = Record<string, unknown>> {
286
- config?: ConfigWithConfigurable<ContextType>;
287
- context?: ContextType;
288
- checkpoint?: Omit<Checkpoint, "thread_id"> | null;
289
- command?: Command;
290
- interruptBefore?: "*" | string[];
291
- interruptAfter?: "*" | string[];
292
- metadata?: Metadata;
293
- multitaskStrategy?: MultitaskStrategy;
294
- onCompletion?: OnCompletionBehavior;
295
- onDisconnect?: DisconnectMode;
296
- feedbackKeys?: string[];
297
- streamMode?: Array<StreamMode>;
298
- optimisticValues?: Partial<StateType> | ((prev: StateType) => Partial<StateType>);
299
- /**
300
- * Whether or not to stream the nodes of any subgraphs called
301
- * by the assistant.
302
- * @default false
303
- */
304
- streamSubgraphs?: boolean;
305
- /**
306
- * Mark the stream as resumable. All events emitted during the run will be temporarily persisted
307
- * in order to be re-emitted if the stream is re-joined.
308
- * @default false
309
- */
310
- streamResumable?: boolean;
311
- /**
312
- * Whether to checkpoint during the run (or only at the end/interruption).
313
- * - `"async"`: Save checkpoint asynchronously while the next step executes (default).
314
- * - `"sync"`: Save checkpoint synchronously before the next step starts.
315
- * - `"exit"`: Save checkpoint only when the graph exits.
316
- * @default "async"
317
- */
318
- durability?: Durability;
319
- /**
320
- * The ID to use when creating a new thread. When provided, this ID will be used
321
- * for thread creation when threadId is `null` or `undefined`.
322
- * This enables optimistic UI updates where you know the thread ID
323
- * before the thread is actually created.
324
- */
325
- threadId?: string;
287
+ interface SubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ContextType extends Record<string, unknown> = Record<string, unknown>> {
288
+ config?: ConfigWithConfigurable<ContextType>;
289
+ context?: ContextType;
290
+ checkpoint?: Omit<Checkpoint, "thread_id"> | null;
291
+ command?: Command;
292
+ interruptBefore?: "*" | string[];
293
+ interruptAfter?: "*" | string[];
294
+ metadata?: Metadata;
295
+ multitaskStrategy?: MultitaskStrategy;
296
+ onCompletion?: OnCompletionBehavior;
297
+ onDisconnect?: DisconnectMode;
298
+ feedbackKeys?: string[];
299
+ streamMode?: Array<StreamMode>;
300
+ optimisticValues?: Partial<StateType> | ((prev: StateType) => Partial<StateType>);
301
+ /**
302
+ * Whether or not to stream the nodes of any subgraphs called
303
+ * by the assistant.
304
+ * @default false
305
+ */
306
+ streamSubgraphs?: boolean;
307
+ /**
308
+ * Mark the stream as resumable. All events emitted during the run will be temporarily persisted
309
+ * in order to be re-emitted if the stream is re-joined.
310
+ * @default false
311
+ */
312
+ streamResumable?: boolean;
313
+ /**
314
+ * Whether to checkpoint during the run (or only at the end/interruption).
315
+ * - `"async"`: Save checkpoint asynchronously while the next step executes (default).
316
+ * - `"sync"`: Save checkpoint synchronously before the next step starts.
317
+ * - `"exit"`: Save checkpoint only when the graph exits.
318
+ * @default "async"
319
+ */
320
+ durability?: Durability;
321
+ /**
322
+ * The ID to use when creating a new thread. When provided, this ID will be used
323
+ * for thread creation when threadId is `null` or `undefined`.
324
+ * This enables optimistic UI updates where you know the thread ID
325
+ * before the thread is actually created.
326
+ */
327
+ threadId?: string;
326
328
  }
327
329
  /**
328
330
  * Transport used to stream the thread.
329
331
  * Only applicable for custom endpoints using `toLangGraphEventStream` or `toLangGraphEventStreamResponse`.
330
332
  */
331
- export interface UseStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
332
- stream: (payload: {
333
- input: GetUpdateType<Bag, StateType> | null | undefined;
334
- context: GetConfigurableType<Bag> | undefined;
335
- command: Command | undefined;
336
- config: ConfigWithConfigurable<GetConfigurableType<Bag>> | undefined;
337
- signal: AbortSignal;
338
- }) => Promise<AsyncGenerator<{
339
- id?: string;
340
- event: string;
341
- data: unknown;
342
- }>>;
333
+ interface UseStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
334
+ stream: (payload: {
335
+ input: GetUpdateType<Bag, StateType> | null | undefined;
336
+ context: GetConfigurableType<Bag> | undefined;
337
+ command: Command | undefined;
338
+ config: ConfigWithConfigurable<GetConfigurableType<Bag>> | undefined;
339
+ signal: AbortSignal;
340
+ }) => Promise<AsyncGenerator<{
341
+ id?: string;
342
+ event: string;
343
+ data: unknown;
344
+ }>>;
343
345
  }
344
- export type UseStreamCustomOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStreamOptions<StateType, Bag>, "messagesKey" | "threadId" | "onThreadId" | "onError" | "onCreated" | "onUpdateEvent" | "onCustomEvent" | "onMetadataEvent" | "onLangChainEvent" | "onDebugEvent" | "onCheckpointEvent" | "onTaskEvent" | "onStop" | "initialValues"> & {
345
- transport: UseStreamTransport<StateType, Bag>;
346
+ type UseStreamCustomOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStreamOptions<StateType, Bag>, "messagesKey" | "threadId" | "onThreadId" | "onError" | "onCreated" | "onUpdateEvent" | "onCustomEvent" | "onMetadataEvent" | "onLangChainEvent" | "onDebugEvent" | "onCheckpointEvent" | "onTaskEvent" | "onStop" | "initialValues"> & {
347
+ transport: UseStreamTransport<StateType, Bag>;
346
348
  };
347
- export type UseStreamCustom<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStream<StateType, Bag>, "values" | "error" | "isLoading" | "stop" | "interrupt" | "messages"> & {
348
- submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: CustomSubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
349
+ type UseStreamCustom<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStream<StateType, Bag>, "values" | "error" | "isLoading" | "stop" | "interrupt" | "messages"> & {
350
+ submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: CustomSubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
349
351
  };
350
- export type CustomSubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ConfigurableType extends Record<string, unknown> = Record<string, unknown>> = Pick<SubmitOptions<StateType, ConfigurableType>, "optimisticValues" | "context" | "command" | "config">;
351
- export {};
352
+ type CustomSubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ConfigurableType extends Record<string, unknown> = Record<string, unknown>> = Pick<SubmitOptions<StateType, ConfigurableType>, "optimisticValues" | "context" | "command" | "config">;
353
+ //#endregion
354
+ export { BagTemplate, GetConfigurableType, GetUpdateType, MessageMetadata, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport };
355
+ //# sourceMappingURL=types.d.ts.map