@langchain/langgraph-sdk 0.0.107 → 0.0.109

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,12 @@
1
1
  # @langchain/langgraph-sdk
2
2
 
3
+ ## 0.0.109
4
+
5
+ ### Patch Changes
6
+
7
+ - e8b4540: Add support for select statements in the search endpoints
8
+ - 9c57526: fix(sdk): expose subgraph events in useStream callbacks
9
+
3
10
  ## 0.0.107
4
11
 
5
12
  ### Patch Changes
package/dist/client.cjs CHANGED
@@ -300,6 +300,7 @@ class CronsClient extends BaseClient {
300
300
  offset: query?.offset ?? 0,
301
301
  sort_by: query?.sortBy ?? undefined,
302
302
  sort_order: query?.sortOrder ?? undefined,
303
+ select: query?.select ?? undefined,
303
304
  },
304
305
  });
305
306
  }
@@ -413,6 +414,7 @@ class AssistantsClient extends BaseClient {
413
414
  offset: query?.offset ?? 0,
414
415
  sort_by: query?.sortBy ?? undefined,
415
416
  sort_order: query?.sortOrder ?? undefined,
417
+ select: query?.select ?? undefined,
416
418
  },
417
419
  });
418
420
  }
@@ -532,6 +534,7 @@ class ThreadsClient extends BaseClient {
532
534
  status: query?.status,
533
535
  sort_by: query?.sortBy,
534
536
  sort_order: query?.sortOrder,
537
+ select: query?.select ?? undefined,
535
538
  },
536
539
  });
537
540
  }
@@ -795,6 +798,7 @@ class RunsClient extends BaseClient {
795
798
  limit: options?.limit ?? 10,
796
799
  offset: options?.offset ?? 0,
797
800
  status: options?.status ?? undefined,
801
+ select: options?.select ?? undefined,
798
802
  },
799
803
  });
800
804
  }
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Assistant, AssistantGraph, AssistantSortBy, AssistantVersion, CancelAction, Checkpoint, Config, Cron, CronCreateForThreadResponse, CronCreateResponse, CronSortBy, DefaultValues, GraphSchema, Item, ListNamespaceResponse, Metadata, Run, RunStatus, SearchItemsResponse, SortOrder, Subgraphs, Thread, ThreadSortBy, ThreadState, ThreadStatus } from "./schema.js";
1
+ import { Assistant, AssistantGraph, AssistantSortBy, AssistantSelectField, AssistantVersion, CancelAction, Checkpoint, Config, Cron, CronSelectField, CronCreateForThreadResponse, CronCreateResponse, CronSortBy, DefaultValues, GraphSchema, Item, ListNamespaceResponse, Metadata, Run, RunSelectField, RunStatus, SearchItemsResponse, SortOrder, Subgraphs, Thread, ThreadSelectField, ThreadSortBy, ThreadState, ThreadStatus } from "./schema.js";
2
2
  import type { Command, CronsCreatePayload, OnConflictBehavior, RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent } from "./types.js";
3
3
  import type { StreamMode, TypedAsyncGenerator } from "./types.stream.js";
4
4
  import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
@@ -85,6 +85,7 @@ export declare class CronsClient extends BaseClient {
85
85
  offset?: number;
86
86
  sortBy?: CronSortBy;
87
87
  sortOrder?: SortOrder;
88
+ select?: CronSelectField[];
88
89
  }): Promise<Cron[]>;
89
90
  }
90
91
  export declare class AssistantsClient extends BaseClient {
@@ -168,6 +169,7 @@ export declare class AssistantsClient extends BaseClient {
168
169
  offset?: number;
169
170
  sortBy?: AssistantSortBy;
170
171
  sortOrder?: SortOrder;
172
+ select?: AssistantSelectField[];
171
173
  }): Promise<Assistant[]>;
172
174
  /**
173
175
  * List all versions of an assistant.
@@ -295,6 +297,7 @@ export declare class ThreadsClient<TStateType = DefaultValues, TUpdateType = TSt
295
297
  * Must be one of 'asc' or 'desc'.
296
298
  */
297
299
  sortOrder?: SortOrder;
300
+ select?: ThreadSelectField[];
298
301
  }): Promise<Thread<ValuesType>[]>;
299
302
  /**
300
303
  * Get state for a thread.
@@ -383,6 +386,7 @@ export declare class RunsClient<TStateType = DefaultValues, TUpdateType = TState
383
386
  * Status of the run to filter by.
384
387
  */
385
388
  status?: RunStatus;
389
+ select?: RunSelectField[];
386
390
  }): Promise<Run[]>;
387
391
  /**
388
392
  * Get a run by ID.
package/dist/client.js CHANGED
@@ -295,6 +295,7 @@ export class CronsClient extends BaseClient {
295
295
  offset: query?.offset ?? 0,
296
296
  sort_by: query?.sortBy ?? undefined,
297
297
  sort_order: query?.sortOrder ?? undefined,
298
+ select: query?.select ?? undefined,
298
299
  },
299
300
  });
300
301
  }
@@ -407,6 +408,7 @@ export class AssistantsClient extends BaseClient {
407
408
  offset: query?.offset ?? 0,
408
409
  sort_by: query?.sortBy ?? undefined,
409
410
  sort_order: query?.sortOrder ?? undefined,
411
+ select: query?.select ?? undefined,
410
412
  },
411
413
  });
412
414
  }
@@ -525,6 +527,7 @@ export class ThreadsClient extends BaseClient {
525
527
  status: query?.status,
526
528
  sort_by: query?.sortBy,
527
529
  sort_order: query?.sortOrder,
530
+ select: query?.select ?? undefined,
528
531
  },
529
532
  });
530
533
  }
@@ -787,6 +790,7 @@ export class RunsClient extends BaseClient {
787
790
  limit: options?.limit ?? 10,
788
791
  offset: options?.offset ?? 0,
789
792
  status: options?.status ?? undefined,
793
+ select: options?.select ?? undefined,
790
794
  },
791
795
  });
792
796
  }
@@ -284,6 +284,9 @@ function useStreamValuesState() {
284
284
  return [values?.[0] ?? null, setStreamValues, mutate];
285
285
  }
286
286
  function useStream(options) {
287
+ const matchEventType = (expected, actual, _data) => {
288
+ return expected === actual || actual.startsWith(`${expected}|`);
289
+ };
287
290
  let { messagesKey } = options;
288
291
  const { assistantId, fetchStateHistory } = options;
289
292
  const { onCreated, onError, onFinish } = options;
@@ -454,36 +457,37 @@ function useStream(options) {
454
457
  streamError = new StreamError(data);
455
458
  break;
456
459
  }
457
- if (event === "updates")
458
- options.onUpdateEvent?.(data);
459
- if (event === "custom" ||
460
- // if `streamSubgraphs: true`, then we also want
461
- // to also receive custom events from subgraphs
462
- event.startsWith("custom|"))
463
- options.onCustomEvent?.(data, {
464
- mutate: getMutateFn("stream", historyValues),
465
- });
460
+ const namespace = event.includes("|")
461
+ ? event.split("|").slice(1)
462
+ : undefined;
463
+ const mutate = getMutateFn("stream", historyValues);
466
464
  if (event === "metadata")
467
465
  options.onMetadataEvent?.(data);
468
466
  if (event === "events")
469
467
  options.onLangChainEvent?.(data);
470
- if (event === "debug")
471
- options.onDebugEvent?.(data);
472
- if (event === "checkpoints")
473
- options.onCheckpointEvent?.(data);
474
- if (event === "tasks")
475
- options.onTaskEvent?.(data);
468
+ if (matchEventType("updates", event, data)) {
469
+ options.onUpdateEvent?.(data, { namespace, mutate });
470
+ }
471
+ if (matchEventType("custom", event, data)) {
472
+ options.onCustomEvent?.(data, { namespace, mutate });
473
+ }
474
+ if (matchEventType("checkpoints", event, data)) {
475
+ options.onCheckpointEvent?.(data, { namespace });
476
+ }
477
+ if (matchEventType("tasks", event, data)) {
478
+ options.onTaskEvent?.(data, { namespace });
479
+ }
480
+ if (matchEventType("debug", event, data)) {
481
+ options.onDebugEvent?.(data, { namespace });
482
+ }
476
483
  if (event === "values") {
477
- if ("__interrupt__" in data) {
478
- // don't update values on interrupt values event
484
+ // don't update values on interrupt values event
485
+ if ("__interrupt__" in data)
479
486
  continue;
480
- }
481
487
  setStreamValues(data);
482
488
  }
483
- if (event === "messages" ||
484
- // if `streamSubgraphs: true`, then we also want
485
- // to also receive messages from subgraphs
486
- event.startsWith("messages|")) {
489
+ // Consume subgraph messages as well
490
+ if (matchEventType("messages", event, data)) {
487
491
  const [serialized, metadata] = data;
488
492
  const messageId = messageManagerRef.current.add(serialized, metadata);
489
493
  if (!messageId) {
@@ -109,11 +109,15 @@ export interface UseStreamOptions<StateType extends Record<string, unknown> = Re
109
109
  /**
110
110
  * Callback that is called when an update event is received.
111
111
  */
112
- onUpdateEvent?: (data: UpdatesStreamEvent<GetUpdateType<Bag, StateType>>["data"]) => void;
112
+ onUpdateEvent?: (data: UpdatesStreamEvent<GetUpdateType<Bag, StateType>>["data"], options: {
113
+ namespace: string[] | undefined;
114
+ mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
115
+ }) => void;
113
116
  /**
114
117
  * Callback that is called when a custom event is received.
115
118
  */
116
119
  onCustomEvent?: (data: CustomStreamEvent<GetCustomEventType<Bag>>["data"], options: {
120
+ namespace: string[] | undefined;
117
121
  mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
118
122
  }) => void;
119
123
  /**
@@ -129,15 +133,21 @@ export interface UseStreamOptions<StateType extends Record<string, unknown> = Re
129
133
  * Callback that is called when a debug event is received.
130
134
  * @internal This API is experimental and subject to change.
131
135
  */
132
- onDebugEvent?: (data: DebugStreamEvent["data"]) => void;
136
+ onDebugEvent?: (data: DebugStreamEvent["data"], options: {
137
+ namespace: string[] | undefined;
138
+ }) => void;
133
139
  /**
134
140
  * Callback that is called when a checkpoints event is received.
135
141
  */
136
- onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>["data"]) => void;
142
+ onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>["data"], options: {
143
+ namespace: string[] | undefined;
144
+ }) => void;
137
145
  /**
138
146
  * Callback that is called when a tasks event is received.
139
147
  */
140
- onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>["data"]) => void;
148
+ onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>["data"], options: {
149
+ namespace: string[] | undefined;
150
+ }) => void;
141
151
  /**
142
152
  * Callback that is called when the stream is stopped by the user.
143
153
  * Provides a mutate function to update the stream state immediately
@@ -280,6 +280,9 @@ function useStreamValuesState() {
280
280
  return [values?.[0] ?? null, setStreamValues, mutate];
281
281
  }
282
282
  export function useStream(options) {
283
+ const matchEventType = (expected, actual, _data) => {
284
+ return expected === actual || actual.startsWith(`${expected}|`);
285
+ };
283
286
  let { messagesKey } = options;
284
287
  const { assistantId, fetchStateHistory } = options;
285
288
  const { onCreated, onError, onFinish } = options;
@@ -450,36 +453,37 @@ export function useStream(options) {
450
453
  streamError = new StreamError(data);
451
454
  break;
452
455
  }
453
- if (event === "updates")
454
- options.onUpdateEvent?.(data);
455
- if (event === "custom" ||
456
- // if `streamSubgraphs: true`, then we also want
457
- // to also receive custom events from subgraphs
458
- event.startsWith("custom|"))
459
- options.onCustomEvent?.(data, {
460
- mutate: getMutateFn("stream", historyValues),
461
- });
456
+ const namespace = event.includes("|")
457
+ ? event.split("|").slice(1)
458
+ : undefined;
459
+ const mutate = getMutateFn("stream", historyValues);
462
460
  if (event === "metadata")
463
461
  options.onMetadataEvent?.(data);
464
462
  if (event === "events")
465
463
  options.onLangChainEvent?.(data);
466
- if (event === "debug")
467
- options.onDebugEvent?.(data);
468
- if (event === "checkpoints")
469
- options.onCheckpointEvent?.(data);
470
- if (event === "tasks")
471
- options.onTaskEvent?.(data);
464
+ if (matchEventType("updates", event, data)) {
465
+ options.onUpdateEvent?.(data, { namespace, mutate });
466
+ }
467
+ if (matchEventType("custom", event, data)) {
468
+ options.onCustomEvent?.(data, { namespace, mutate });
469
+ }
470
+ if (matchEventType("checkpoints", event, data)) {
471
+ options.onCheckpointEvent?.(data, { namespace });
472
+ }
473
+ if (matchEventType("tasks", event, data)) {
474
+ options.onTaskEvent?.(data, { namespace });
475
+ }
476
+ if (matchEventType("debug", event, data)) {
477
+ options.onDebugEvent?.(data, { namespace });
478
+ }
472
479
  if (event === "values") {
473
- if ("__interrupt__" in data) {
474
- // don't update values on interrupt values event
480
+ // don't update values on interrupt values event
481
+ if ("__interrupt__" in data)
475
482
  continue;
476
- }
477
483
  setStreamValues(data);
478
484
  }
479
- if (event === "messages" ||
480
- // if `streamSubgraphs: true`, then we also want
481
- // to also receive messages from subgraphs
482
- event.startsWith("messages|")) {
485
+ // Consume subgraph messages as well
486
+ if (matchEventType("messages", event, data)) {
483
487
  const [serialized, metadata] = data;
484
488
  const messageId = messageManagerRef.current.add(serialized, metadata);
485
489
  if (!messageId) {
package/dist/schema.d.ts CHANGED
@@ -263,4 +263,8 @@ export type AssistantSortBy = "assistant_id" | "graph_id" | "name" | "created_at
263
263
  export type ThreadSortBy = "thread_id" | "status" | "created_at" | "updated_at";
264
264
  export type CronSortBy = "cron_id" | "assistant_id" | "thread_id" | "created_at" | "updated_at" | "next_run_date";
265
265
  export type SortOrder = "asc" | "desc";
266
+ export type AssistantSelectField = "assistant_id" | "graph_id" | "name" | "description" | "config" | "context" | "created_at" | "updated_at" | "metadata" | "version";
267
+ export type ThreadSelectField = "thread_id" | "created_at" | "updated_at" | "metadata" | "config" | "context" | "status" | "values" | "interrupts";
268
+ export type RunSelectField = "run_id" | "thread_id" | "assistant_id" | "created_at" | "updated_at" | "status" | "metadata" | "kwargs" | "multitask_strategy";
269
+ export type CronSelectField = "cron_id" | "assistant_id" | "thread_id" | "end_time" | "schedule" | "created_at" | "updated_at" | "user_id" | "payload" | "next_run_date" | "metadata" | "now";
266
270
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "scripts": {