@langchain/langgraph-sdk 0.1.10 → 1.0.1

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 (235) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +11 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/auth/error.cjs +76 -86
  5. package/dist/auth/error.cjs.map +1 -0
  6. package/dist/auth/error.d.cts +13 -0
  7. package/dist/auth/error.d.cts.map +1 -0
  8. package/dist/auth/error.d.ts +12 -8
  9. package/dist/auth/error.d.ts.map +1 -0
  10. package/dist/auth/error.js +76 -83
  11. package/dist/auth/error.js.map +1 -0
  12. package/dist/auth/index.cjs +36 -44
  13. package/dist/auth/index.cjs.map +1 -0
  14. package/dist/auth/index.d.cts +31 -0
  15. package/dist/auth/index.d.cts.map +1 -0
  16. package/dist/auth/index.d.ts +20 -15
  17. package/dist/auth/index.d.ts.map +1 -0
  18. package/dist/auth/index.js +35 -39
  19. package/dist/auth/index.js.map +1 -0
  20. package/dist/auth/types.d.cts +294 -0
  21. package/dist/auth/types.d.cts.map +1 -0
  22. package/dist/auth/types.d.ts +162 -165
  23. package/dist/auth/types.d.ts.map +1 -0
  24. package/dist/client.cjs +1110 -1294
  25. package/dist/client.cjs.map +1 -0
  26. package/dist/client.d.cts +697 -0
  27. package/dist/client.d.cts.map +1 -0
  28. package/dist/client.d.ts +656 -639
  29. package/dist/client.d.ts.map +1 -0
  30. package/dist/client.js +1101 -1281
  31. package/dist/client.js.map +1 -0
  32. package/dist/index.cjs +6 -8
  33. package/dist/index.d.cts +7 -0
  34. package/dist/index.d.ts +7 -7
  35. package/dist/index.js +4 -2
  36. package/dist/logging/index.cjs +30 -31
  37. package/dist/logging/index.cjs.map +1 -0
  38. package/dist/logging/index.d.cts +47 -0
  39. package/dist/logging/index.d.cts.map +1 -0
  40. package/dist/logging/index.d.ts +20 -16
  41. package/dist/logging/index.d.ts.map +1 -0
  42. package/dist/logging/index.js +31 -29
  43. package/dist/logging/index.js.map +1 -0
  44. package/dist/react/index.cjs +5 -7
  45. package/dist/react/index.d.cts +4 -0
  46. package/dist/react/index.d.ts +4 -3
  47. package/dist/react/index.js +4 -2
  48. package/dist/react/stream.cjs +14 -15
  49. package/dist/react/stream.cjs.map +1 -0
  50. package/dist/react/stream.custom.cjs +126 -145
  51. package/dist/react/stream.custom.cjs.map +1 -0
  52. package/dist/react/stream.custom.d.cts +39 -0
  53. package/dist/react/stream.custom.d.cts.map +1 -0
  54. package/dist/react/stream.custom.d.ts +35 -37
  55. package/dist/react/stream.custom.d.ts.map +1 -0
  56. package/dist/react/stream.custom.js +122 -137
  57. package/dist/react/stream.custom.js.map +1 -0
  58. package/dist/react/stream.d.cts +73 -0
  59. package/dist/react/stream.d.cts.map +1 -0
  60. package/dist/react/stream.d.ts +21 -15
  61. package/dist/react/stream.d.ts.map +1 -0
  62. package/dist/react/stream.js +12 -11
  63. package/dist/react/stream.js.map +1 -0
  64. package/dist/react/stream.lgp.cjs +438 -498
  65. package/dist/react/stream.lgp.cjs.map +1 -0
  66. package/dist/react/stream.lgp.js +433 -490
  67. package/dist/react/stream.lgp.js.map +1 -0
  68. package/dist/react/thread.cjs +18 -15
  69. package/dist/react/thread.cjs.map +1 -0
  70. package/dist/react/thread.js +19 -13
  71. package/dist/react/thread.js.map +1 -0
  72. package/dist/react/types.d.cts +356 -0
  73. package/dist/react/types.d.cts.map +1 -0
  74. package/dist/react/types.d.ts +334 -329
  75. package/dist/react/types.d.ts.map +1 -0
  76. package/dist/react-ui/client.cjs +123 -184
  77. package/dist/react-ui/client.cjs.map +1 -0
  78. package/dist/react-ui/client.d.cts +90 -0
  79. package/dist/react-ui/client.d.cts.map +1 -0
  80. package/dist/react-ui/client.d.ts +67 -51
  81. package/dist/react-ui/client.d.ts.map +1 -0
  82. package/dist/react-ui/client.js +118 -143
  83. package/dist/react-ui/client.js.map +1 -0
  84. package/dist/react-ui/index.cjs +14 -13
  85. package/dist/react-ui/index.cjs.map +1 -0
  86. package/dist/react-ui/index.d.cts +3 -0
  87. package/dist/react-ui/index.d.ts +3 -2
  88. package/dist/react-ui/index.js +8 -3
  89. package/dist/react-ui/index.js.map +1 -0
  90. package/dist/react-ui/server/index.cjs +5 -7
  91. package/dist/react-ui/server/index.d.cts +3 -0
  92. package/dist/react-ui/server/index.d.ts +3 -2
  93. package/dist/react-ui/server/index.js +4 -2
  94. package/dist/react-ui/server/server.cjs +53 -44
  95. package/dist/react-ui/server/server.cjs.map +1 -0
  96. package/dist/react-ui/server/server.d.cts +55 -0
  97. package/dist/react-ui/server/server.d.cts.map +1 -0
  98. package/dist/react-ui/server/server.d.ts +43 -39
  99. package/dist/react-ui/server/server.d.ts.map +1 -0
  100. package/dist/react-ui/server/server.js +54 -42
  101. package/dist/react-ui/server/server.js.map +1 -0
  102. package/dist/react-ui/types.cjs +32 -36
  103. package/dist/react-ui/types.cjs.map +1 -0
  104. package/dist/react-ui/types.d.cts +25 -0
  105. package/dist/react-ui/types.d.cts.map +1 -0
  106. package/dist/react-ui/types.d.ts +23 -19
  107. package/dist/react-ui/types.d.ts.map +1 -0
  108. package/dist/react-ui/types.js +32 -34
  109. package/dist/react-ui/types.js.map +1 -0
  110. package/dist/schema.d.cts +278 -0
  111. package/dist/schema.d.cts.map +1 -0
  112. package/dist/schema.d.ts +250 -242
  113. package/dist/schema.d.ts.map +1 -0
  114. package/dist/singletons/fetch.cjs +16 -20
  115. package/dist/singletons/fetch.cjs.map +1 -0
  116. package/dist/singletons/fetch.d.cts +14 -0
  117. package/dist/singletons/fetch.d.cts.map +1 -0
  118. package/dist/singletons/fetch.d.ts +5 -2
  119. package/dist/singletons/fetch.d.ts.map +1 -0
  120. package/dist/singletons/fetch.js +16 -17
  121. package/dist/singletons/fetch.js.map +1 -0
  122. package/dist/types.d.cts +187 -0
  123. package/dist/types.d.cts.map +1 -0
  124. package/dist/types.d.ts +178 -173
  125. package/dist/types.d.ts.map +1 -0
  126. package/dist/types.messages.d.cts +91 -0
  127. package/dist/types.messages.d.cts.map +1 -0
  128. package/dist/types.messages.d.ts +71 -66
  129. package/dist/types.messages.d.ts.map +1 -0
  130. package/dist/types.stream.d.cts +235 -0
  131. package/dist/types.stream.d.cts.map +1 -0
  132. package/dist/types.stream.d.ts +149 -142
  133. package/dist/types.stream.d.ts.map +1 -0
  134. package/dist/ui/branching.cjs +145 -141
  135. package/dist/ui/branching.cjs.map +1 -0
  136. package/dist/ui/branching.d.cts +22 -0
  137. package/dist/ui/branching.d.cts.map +1 -0
  138. package/dist/ui/branching.d.ts +17 -30
  139. package/dist/ui/branching.d.ts.map +1 -0
  140. package/dist/ui/branching.js +147 -139
  141. package/dist/ui/branching.js.map +1 -0
  142. package/dist/ui/errors.cjs +14 -12
  143. package/dist/ui/errors.cjs.map +1 -0
  144. package/dist/ui/errors.js +14 -9
  145. package/dist/ui/errors.js.map +1 -0
  146. package/dist/ui/manager.cjs +156 -232
  147. package/dist/ui/manager.cjs.map +1 -0
  148. package/dist/ui/manager.js +156 -228
  149. package/dist/ui/manager.js.map +1 -0
  150. package/dist/ui/messages.cjs +55 -69
  151. package/dist/ui/messages.cjs.map +1 -0
  152. package/dist/ui/messages.js +55 -66
  153. package/dist/ui/messages.js.map +1 -0
  154. package/dist/ui/utils.cjs +10 -10
  155. package/dist/ui/utils.cjs.map +1 -0
  156. package/dist/ui/utils.js +10 -8
  157. package/dist/ui/utils.js.map +1 -0
  158. package/dist/utils/async_caller.cjs +103 -185
  159. package/dist/utils/async_caller.cjs.map +1 -0
  160. package/dist/utils/async_caller.d.cts +53 -0
  161. package/dist/utils/async_caller.d.cts.map +1 -0
  162. package/dist/utils/async_caller.d.ts +36 -31
  163. package/dist/utils/async_caller.d.ts.map +1 -0
  164. package/dist/utils/async_caller.js +101 -177
  165. package/dist/utils/async_caller.js.map +1 -0
  166. package/dist/utils/env.cjs +11 -13
  167. package/dist/utils/env.cjs.map +1 -0
  168. package/dist/utils/env.js +11 -11
  169. package/dist/utils/env.js.map +1 -0
  170. package/dist/utils/signals.cjs +18 -19
  171. package/dist/utils/signals.cjs.map +1 -0
  172. package/dist/utils/signals.js +18 -17
  173. package/dist/utils/signals.js.map +1 -0
  174. package/dist/utils/sse.cjs +110 -140
  175. package/dist/utils/sse.cjs.map +1 -0
  176. package/dist/utils/sse.js +110 -138
  177. package/dist/utils/sse.js.map +1 -0
  178. package/dist/utils/stream.cjs +90 -114
  179. package/dist/utils/stream.cjs.map +1 -0
  180. package/dist/utils/stream.js +90 -111
  181. package/dist/utils/stream.js.map +1 -0
  182. package/package.json +73 -81
  183. package/auth.cjs +0 -1
  184. package/auth.d.cts +0 -1
  185. package/auth.d.ts +0 -1
  186. package/auth.js +0 -1
  187. package/client.cjs +0 -1
  188. package/client.d.cts +0 -1
  189. package/client.d.ts +0 -1
  190. package/client.js +0 -1
  191. package/dist/auth/types.cjs +0 -2
  192. package/dist/auth/types.js +0 -1
  193. package/dist/react/stream.lgp.d.ts +0 -7
  194. package/dist/react/thread.d.ts +0 -4
  195. package/dist/react/types.cjs +0 -2
  196. package/dist/react/types.js +0 -1
  197. package/dist/schema.cjs +0 -2
  198. package/dist/schema.js +0 -1
  199. package/dist/types.cjs +0 -2
  200. package/dist/types.js +0 -1
  201. package/dist/types.messages.cjs +0 -2
  202. package/dist/types.messages.js +0 -1
  203. package/dist/types.stream.cjs +0 -2
  204. package/dist/types.stream.js +0 -1
  205. package/dist/ui/branching.test.cjs +0 -370
  206. package/dist/ui/branching.test.d.ts +0 -1
  207. package/dist/ui/branching.test.js +0 -368
  208. package/dist/ui/errors.d.ts +0 -12
  209. package/dist/ui/manager.d.ts +0 -87
  210. package/dist/ui/messages.d.ts +0 -18
  211. package/dist/ui/utils.d.ts +0 -2
  212. package/dist/utils/env.d.ts +0 -1
  213. package/dist/utils/signals.d.ts +0 -1
  214. package/dist/utils/sse.d.ts +0 -8
  215. package/dist/utils/stream.d.ts +0 -13
  216. package/index.cjs +0 -1
  217. package/index.d.cts +0 -1
  218. package/index.d.ts +0 -1
  219. package/index.js +0 -1
  220. package/logging.cjs +0 -1
  221. package/logging.d.cts +0 -1
  222. package/logging.d.ts +0 -1
  223. package/logging.js +0 -1
  224. package/react-ui/server.cjs +0 -1
  225. package/react-ui/server.d.cts +0 -1
  226. package/react-ui/server.d.ts +0 -1
  227. package/react-ui/server.js +0 -1
  228. package/react-ui.cjs +0 -1
  229. package/react-ui.d.cts +0 -1
  230. package/react-ui.d.ts +0 -1
  231. package/react-ui.js +0 -1
  232. package/react.cjs +0 -1
  233. package/react.d.cts +0 -1
  234. package/react.d.ts +0 -1
  235. package/react.js +0 -1
@@ -1,351 +1,356 @@
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
+ runId?: string;
301
+ optimisticValues?: Partial<StateType> | ((prev: StateType) => Partial<StateType>);
302
+ /**
303
+ * Whether or not to stream the nodes of any subgraphs called
304
+ * by the assistant.
305
+ * @default false
306
+ */
307
+ streamSubgraphs?: boolean;
308
+ /**
309
+ * Mark the stream as resumable. All events emitted during the run will be temporarily persisted
310
+ * in order to be re-emitted if the stream is re-joined.
311
+ * @default false
312
+ */
313
+ streamResumable?: boolean;
314
+ /**
315
+ * Whether to checkpoint during the run (or only at the end/interruption).
316
+ * - `"async"`: Save checkpoint asynchronously while the next step executes (default).
317
+ * - `"sync"`: Save checkpoint synchronously before the next step starts.
318
+ * - `"exit"`: Save checkpoint only when the graph exits.
319
+ * @default "async"
320
+ */
321
+ durability?: Durability;
322
+ /**
323
+ * The ID to use when creating a new thread. When provided, this ID will be used
324
+ * for thread creation when threadId is `null` or `undefined`.
325
+ * This enables optimistic UI updates where you know the thread ID
326
+ * before the thread is actually created.
327
+ */
328
+ threadId?: string;
326
329
  }
327
330
  /**
328
331
  * Transport used to stream the thread.
329
332
  * Only applicable for custom endpoints using `toLangGraphEventStream` or `toLangGraphEventStreamResponse`.
330
333
  */
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
- }>>;
334
+ interface UseStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
335
+ stream: (payload: {
336
+ input: GetUpdateType<Bag, StateType> | null | undefined;
337
+ context: GetConfigurableType<Bag> | undefined;
338
+ command: Command | undefined;
339
+ config: ConfigWithConfigurable<GetConfigurableType<Bag>> | undefined;
340
+ signal: AbortSignal;
341
+ }) => Promise<AsyncGenerator<{
342
+ id?: string;
343
+ event: string;
344
+ data: unknown;
345
+ }>>;
343
346
  }
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>;
347
+ 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"> & {
348
+ transport: UseStreamTransport<StateType, Bag>;
346
349
  };
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>;
350
+ type UseStreamCustom<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStream<StateType, Bag>, "values" | "error" | "isLoading" | "stop" | "interrupt" | "messages"> & {
351
+ submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: CustomSubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
349
352
  };
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 {};
353
+ 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">;
354
+ //#endregion
355
+ export { BagTemplate, GetConfigurableType, GetUpdateType, MessageMetadata, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport };
356
+ //# sourceMappingURL=types.d.ts.map