@langchain/langgraph-sdk 0.0.97 → 0.0.98

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @langchain/langgraph-sdk
2
2
 
3
+ ## 0.0.98
4
+
5
+ ### Patch Changes
6
+
7
+ - ee1defa: feat(sdk): add typing for "tasks" and "checkpoints" stream mode
8
+
3
9
  ## 0.0.97
4
10
 
5
11
  ### Patch Changes
@@ -315,6 +315,8 @@ function useStream(options) {
315
315
  const hasCustomListener = options.onCustomEvent != null;
316
316
  const hasLangChainListener = options.onLangChainEvent != null;
317
317
  const hasDebugListener = options.onDebugEvent != null;
318
+ const hasCheckpointListener = options.onCheckpointEvent != null;
319
+ const hasTaskListener = options.onTaskEvent != null;
318
320
  const callbackStreamMode = (0, react_1.useMemo)(() => {
319
321
  const modes = [];
320
322
  if (hasUpdateListener)
@@ -325,12 +327,18 @@ function useStream(options) {
325
327
  modes.push("events");
326
328
  if (hasDebugListener)
327
329
  modes.push("debug");
330
+ if (hasCheckpointListener)
331
+ modes.push("checkpoints");
332
+ if (hasTaskListener)
333
+ modes.push("tasks");
328
334
  return modes;
329
335
  }, [
330
336
  hasUpdateListener,
331
337
  hasCustomListener,
332
338
  hasLangChainListener,
333
339
  hasDebugListener,
340
+ hasCheckpointListener,
341
+ hasTaskListener,
334
342
  ]);
335
343
  const clearCallbackRef = (0, react_1.useRef)(null);
336
344
  clearCallbackRef.current = () => {
@@ -435,6 +443,10 @@ function useStream(options) {
435
443
  options.onLangChainEvent?.(data);
436
444
  if (event === "debug")
437
445
  options.onDebugEvent?.(data);
446
+ if (event === "checkpoints")
447
+ options.onCheckpointEvent?.(data);
448
+ if (event === "tasks")
449
+ options.onTaskEvent?.(data);
438
450
  if (event === "values") {
439
451
  if ("__interrupt__" in data) {
440
452
  // don't update values on interrupt values event
@@ -2,7 +2,7 @@ import { Client, type ClientConfig } from "../client.js";
2
2
  import type { Command, DisconnectMode, MultitaskStrategy, OnCompletionBehavior } from "../types.js";
3
3
  import type { Message } from "../types.messages.js";
4
4
  import type { Checkpoint, Config, Interrupt, Metadata, ThreadState } from "../schema.js";
5
- import type { CustomStreamEvent, DebugStreamEvent, EventsStreamEvent, MetadataStreamEvent, StreamMode, UpdatesStreamEvent } from "../types.stream.js";
5
+ import type { CheckpointsStreamEvent, CustomStreamEvent, DebugStreamEvent, EventsStreamEvent, MetadataStreamEvent, StreamMode, TasksStreamEvent, UpdatesStreamEvent } from "../types.stream.js";
6
6
  interface Node<StateType = any> {
7
7
  type: "node";
8
8
  value: ThreadState<StateType>;
@@ -125,6 +125,14 @@ export interface UseStreamOptions<StateType extends Record<string, unknown> = Re
125
125
  * @internal This API is experimental and subject to change.
126
126
  */
127
127
  onDebugEvent?: (data: DebugStreamEvent["data"]) => void;
128
+ /**
129
+ * Callback that is called when a checkpoints event is received.
130
+ */
131
+ onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>["data"]) => void;
132
+ /**
133
+ * Callback that is called when a tasks event is received.
134
+ */
135
+ onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>["data"]) => void;
128
136
  /**
129
137
  * Callback that is called when the stream is stopped by the user.
130
138
  * Provides a mutate function to update the stream state immediately
@@ -311,6 +311,8 @@ export function useStream(options) {
311
311
  const hasCustomListener = options.onCustomEvent != null;
312
312
  const hasLangChainListener = options.onLangChainEvent != null;
313
313
  const hasDebugListener = options.onDebugEvent != null;
314
+ const hasCheckpointListener = options.onCheckpointEvent != null;
315
+ const hasTaskListener = options.onTaskEvent != null;
314
316
  const callbackStreamMode = useMemo(() => {
315
317
  const modes = [];
316
318
  if (hasUpdateListener)
@@ -321,12 +323,18 @@ export function useStream(options) {
321
323
  modes.push("events");
322
324
  if (hasDebugListener)
323
325
  modes.push("debug");
326
+ if (hasCheckpointListener)
327
+ modes.push("checkpoints");
328
+ if (hasTaskListener)
329
+ modes.push("tasks");
324
330
  return modes;
325
331
  }, [
326
332
  hasUpdateListener,
327
333
  hasCustomListener,
328
334
  hasLangChainListener,
329
335
  hasDebugListener,
336
+ hasCheckpointListener,
337
+ hasTaskListener,
330
338
  ]);
331
339
  const clearCallbackRef = useRef(null);
332
340
  clearCallbackRef.current = () => {
@@ -431,6 +439,10 @@ export function useStream(options) {
431
439
  options.onLangChainEvent?.(data);
432
440
  if (event === "debug")
433
441
  options.onDebugEvent?.(data);
442
+ if (event === "checkpoints")
443
+ options.onCheckpointEvent?.(data);
444
+ if (event === "tasks")
445
+ options.onTaskEvent?.(data);
434
446
  if (event === "values") {
435
447
  if ("__interrupt__" in data) {
436
448
  // don't update values on interrupt values event
@@ -1,5 +1,7 @@
1
1
  import type { Message } from "./types.messages.js";
2
+ import type { Interrupt, Metadata, Config, ThreadTask } from "./schema.js";
2
3
  /**
4
+ import type { SubgraphCheckpointsStreamEvent } from "./types.stream.subgraph.js";
3
5
  * Stream modes
4
6
  * - "values": Stream only the state values.
5
7
  * - "messages": Stream complete messages.
@@ -9,7 +11,7 @@ import type { Message } from "./types.messages.js";
9
11
  * - "debug": Stream detailed debug information.
10
12
  * - "custom": Stream custom events.
11
13
  */
12
- export type StreamMode = "values" | "messages" | "updates" | "events" | "debug" | "custom" | "messages-tuple";
14
+ export type StreamMode = "values" | "messages" | "updates" | "events" | "debug" | "tasks" | "checkpoints" | "custom" | "messages-tuple";
13
15
  type MessageTupleMetadata = {
14
16
  tags: string[];
15
17
  [key: string]: unknown;
@@ -108,6 +110,51 @@ type MessagesPartialStreamEvent = {
108
110
  event: "messages/partial";
109
111
  data: Message[];
110
112
  };
113
+ type TasksStreamCreateEvent<StateType> = {
114
+ id?: string;
115
+ event: "tasks";
116
+ data: {
117
+ id: string;
118
+ name: string;
119
+ interrupts: Interrupt[];
120
+ input: StateType;
121
+ triggers: string[];
122
+ };
123
+ };
124
+ type TasksStreamResultEvent<UpdateType> = {
125
+ id?: string;
126
+ event: "tasks";
127
+ data: {
128
+ id: string;
129
+ name: string;
130
+ interrupts: Interrupt[];
131
+ result: [string, UpdateType][];
132
+ };
133
+ };
134
+ type TasksStreamErrorEvent = {
135
+ id?: string;
136
+ event: "tasks";
137
+ data: {
138
+ id: string;
139
+ name: string;
140
+ interrupts: Interrupt[];
141
+ error: string;
142
+ };
143
+ };
144
+ export type TasksStreamEvent<StateType, UpdateType> = TasksStreamCreateEvent<StateType> | TasksStreamResultEvent<UpdateType> | TasksStreamErrorEvent;
145
+ type SubgraphTasksStreamEvent<StateType, UpdateType> = AsSubgraph<TasksStreamCreateEvent<StateType>> | AsSubgraph<TasksStreamResultEvent<UpdateType>> | AsSubgraph<TasksStreamErrorEvent>;
146
+ export type CheckpointsStreamEvent<StateType> = {
147
+ id?: string;
148
+ event: "checkpoints";
149
+ data: {
150
+ values: StateType;
151
+ next: string[];
152
+ config: Config;
153
+ metadata: Metadata;
154
+ tasks: ThreadTask[];
155
+ };
156
+ };
157
+ type SubgraphCheckpointsStreamEvent<StateType> = AsSubgraph<CheckpointsStreamEvent<StateType>>;
111
158
  /**
112
159
  * Message stream event specific to LangGraph Server.
113
160
  * @deprecated Use `streamMode: "messages-tuple"` instead.
@@ -161,6 +208,8 @@ type GetStreamModeMap<TStreamMode extends StreamMode | StreamMode[], TStateType
161
208
  debug: DebugStreamEvent;
162
209
  messages: MessagesStreamEvent;
163
210
  "messages-tuple": MessagesTupleStreamEvent;
211
+ tasks: TasksStreamEvent<TStateType, TUpdateType>;
212
+ checkpoints: CheckpointsStreamEvent<TStateType>;
164
213
  events: EventsStreamEvent;
165
214
  }[TStreamMode extends StreamMode[] ? TStreamMode[number] : TStreamMode] | ErrorStreamEvent | MetadataStreamEvent | FeedbackStreamEvent;
166
215
  type GetSubgraphsStreamModeMap<TStreamMode extends StreamMode | StreamMode[], TStateType = unknown, TUpdateType = TStateType, TCustomType = unknown> = {
@@ -171,6 +220,8 @@ type GetSubgraphsStreamModeMap<TStreamMode extends StreamMode | StreamMode[], TS
171
220
  messages: SubgraphMessagesStreamEvent;
172
221
  "messages-tuple": SubgraphMessagesTupleStreamEvent;
173
222
  events: SubgraphEventsStreamEvent;
223
+ tasks: SubgraphTasksStreamEvent<TStateType, TUpdateType>;
224
+ checkpoints: SubgraphCheckpointsStreamEvent<TStateType>;
174
225
  }[TStreamMode extends StreamMode[] ? TStreamMode[number] : TStreamMode] | SubgraphErrorStreamEvent | MetadataStreamEvent | FeedbackStreamEvent;
175
226
  export type TypedAsyncGenerator<TStreamMode extends StreamMode | StreamMode[] = [], TSubgraphs extends boolean = false, TStateType = unknown, TUpdateType = TStateType, TCustomType = unknown> = AsyncGenerator<TSubgraphs extends true ? GetSubgraphsStreamModeMap<TStreamMode, TStateType, TUpdateType, TCustomType> : GetStreamModeMap<TStreamMode, TStateType, TUpdateType, TCustomType>>;
176
227
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.97",
3
+ "version": "0.0.98",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "scripts": {