@langchain/langgraph-sdk 0.0.107 → 0.0.111

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,18 @@
1
1
  # @langchain/langgraph-sdk
2
2
 
3
+ ## 0.0.111
4
+
5
+ ### Patch Changes
6
+
7
+ - b5f14d0: Add methods to connect with the /count endpoints
8
+
9
+ ## 0.0.109
10
+
11
+ ### Patch Changes
12
+
13
+ - e8b4540: Add support for select statements in the search endpoints
14
+ - 9c57526: fix(sdk): expose subgraph events in useStream callbacks
15
+
3
16
  ## 0.0.107
4
17
 
5
18
  ### Patch Changes
package/dist/client.cjs CHANGED
@@ -300,6 +300,23 @@ 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,
304
+ },
305
+ });
306
+ }
307
+ /**
308
+ * Count cron jobs matching filters.
309
+ *
310
+ * @param query.assistantId Assistant ID to filter by.
311
+ * @param query.threadId Thread ID to filter by.
312
+ * @returns Number of cron jobs matching the criteria.
313
+ */
314
+ async count(query) {
315
+ return this.fetch(`/runs/crons/count`, {
316
+ method: "POST",
317
+ json: {
318
+ assistant_id: query?.assistantId ?? undefined,
319
+ thread_id: query?.threadId ?? undefined,
303
320
  },
304
321
  });
305
322
  }
@@ -413,6 +430,23 @@ class AssistantsClient extends BaseClient {
413
430
  offset: query?.offset ?? 0,
414
431
  sort_by: query?.sortBy ?? undefined,
415
432
  sort_order: query?.sortOrder ?? undefined,
433
+ select: query?.select ?? undefined,
434
+ },
435
+ });
436
+ }
437
+ /**
438
+ * Count assistants matching filters.
439
+ *
440
+ * @param query.metadata Metadata to filter by. Exact match for each key/value.
441
+ * @param query.graphId Optional graph id to filter by.
442
+ * @returns Number of assistants matching the criteria.
443
+ */
444
+ async count(query) {
445
+ return this.fetch(`/assistants/count`, {
446
+ method: "POST",
447
+ json: {
448
+ metadata: query?.metadata ?? undefined,
449
+ graph_id: query?.graphId ?? undefined,
416
450
  },
417
451
  });
418
452
  }
@@ -532,6 +566,25 @@ class ThreadsClient extends BaseClient {
532
566
  status: query?.status,
533
567
  sort_by: query?.sortBy,
534
568
  sort_order: query?.sortOrder,
569
+ select: query?.select ?? undefined,
570
+ },
571
+ });
572
+ }
573
+ /**
574
+ * Count threads matching filters.
575
+ *
576
+ * @param query.metadata Thread metadata to filter on.
577
+ * @param query.values State values to filter on.
578
+ * @param query.status Thread status to filter on.
579
+ * @returns Number of threads matching the criteria.
580
+ */
581
+ async count(query) {
582
+ return this.fetch(`/threads/count`, {
583
+ method: "POST",
584
+ json: {
585
+ metadata: query?.metadata ?? undefined,
586
+ values: query?.values ?? undefined,
587
+ status: query?.status ?? undefined,
535
588
  },
536
589
  });
537
590
  }
@@ -795,6 +848,7 @@ class RunsClient extends BaseClient {
795
848
  limit: options?.limit ?? 10,
796
849
  offset: options?.offset ?? 0,
797
850
  status: options?.status ?? undefined,
851
+ select: options?.select ?? undefined,
798
852
  },
799
853
  });
800
854
  }
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,7 +85,19 @@ 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[]>;
90
+ /**
91
+ * Count cron jobs matching filters.
92
+ *
93
+ * @param query.assistantId Assistant ID to filter by.
94
+ * @param query.threadId Thread ID to filter by.
95
+ * @returns Number of cron jobs matching the criteria.
96
+ */
97
+ count(query?: {
98
+ assistantId?: string;
99
+ threadId?: string;
100
+ }): Promise<number>;
89
101
  }
90
102
  export declare class AssistantsClient extends BaseClient {
91
103
  /**
@@ -168,7 +180,19 @@ export declare class AssistantsClient extends BaseClient {
168
180
  offset?: number;
169
181
  sortBy?: AssistantSortBy;
170
182
  sortOrder?: SortOrder;
183
+ select?: AssistantSelectField[];
171
184
  }): Promise<Assistant[]>;
185
+ /**
186
+ * Count assistants matching filters.
187
+ *
188
+ * @param query.metadata Metadata to filter by. Exact match for each key/value.
189
+ * @param query.graphId Optional graph id to filter by.
190
+ * @returns Number of assistants matching the criteria.
191
+ */
192
+ count(query?: {
193
+ metadata?: Metadata;
194
+ graphId?: string;
195
+ }): Promise<number>;
172
196
  /**
173
197
  * List all versions of an assistant.
174
198
  *
@@ -295,7 +319,21 @@ export declare class ThreadsClient<TStateType = DefaultValues, TUpdateType = TSt
295
319
  * Must be one of 'asc' or 'desc'.
296
320
  */
297
321
  sortOrder?: SortOrder;
322
+ select?: ThreadSelectField[];
298
323
  }): Promise<Thread<ValuesType>[]>;
324
+ /**
325
+ * Count threads matching filters.
326
+ *
327
+ * @param query.metadata Thread metadata to filter on.
328
+ * @param query.values State values to filter on.
329
+ * @param query.status Thread status to filter on.
330
+ * @returns Number of threads matching the criteria.
331
+ */
332
+ count<ValuesType = TStateType>(query?: {
333
+ metadata?: Metadata;
334
+ values?: ValuesType;
335
+ status?: ThreadStatus;
336
+ }): Promise<number>;
299
337
  /**
300
338
  * Get state for a thread.
301
339
  *
@@ -383,6 +421,7 @@ export declare class RunsClient<TStateType = DefaultValues, TUpdateType = TState
383
421
  * Status of the run to filter by.
384
422
  */
385
423
  status?: RunStatus;
424
+ select?: RunSelectField[];
386
425
  }): Promise<Run[]>;
387
426
  /**
388
427
  * Get a run by ID.
package/dist/client.js CHANGED
@@ -295,6 +295,23 @@ 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,
299
+ },
300
+ });
301
+ }
302
+ /**
303
+ * Count cron jobs matching filters.
304
+ *
305
+ * @param query.assistantId Assistant ID to filter by.
306
+ * @param query.threadId Thread ID to filter by.
307
+ * @returns Number of cron jobs matching the criteria.
308
+ */
309
+ async count(query) {
310
+ return this.fetch(`/runs/crons/count`, {
311
+ method: "POST",
312
+ json: {
313
+ assistant_id: query?.assistantId ?? undefined,
314
+ thread_id: query?.threadId ?? undefined,
298
315
  },
299
316
  });
300
317
  }
@@ -407,6 +424,23 @@ export class AssistantsClient extends BaseClient {
407
424
  offset: query?.offset ?? 0,
408
425
  sort_by: query?.sortBy ?? undefined,
409
426
  sort_order: query?.sortOrder ?? undefined,
427
+ select: query?.select ?? undefined,
428
+ },
429
+ });
430
+ }
431
+ /**
432
+ * Count assistants matching filters.
433
+ *
434
+ * @param query.metadata Metadata to filter by. Exact match for each key/value.
435
+ * @param query.graphId Optional graph id to filter by.
436
+ * @returns Number of assistants matching the criteria.
437
+ */
438
+ async count(query) {
439
+ return this.fetch(`/assistants/count`, {
440
+ method: "POST",
441
+ json: {
442
+ metadata: query?.metadata ?? undefined,
443
+ graph_id: query?.graphId ?? undefined,
410
444
  },
411
445
  });
412
446
  }
@@ -525,6 +559,25 @@ export class ThreadsClient extends BaseClient {
525
559
  status: query?.status,
526
560
  sort_by: query?.sortBy,
527
561
  sort_order: query?.sortOrder,
562
+ select: query?.select ?? undefined,
563
+ },
564
+ });
565
+ }
566
+ /**
567
+ * Count threads matching filters.
568
+ *
569
+ * @param query.metadata Thread metadata to filter on.
570
+ * @param query.values State values to filter on.
571
+ * @param query.status Thread status to filter on.
572
+ * @returns Number of threads matching the criteria.
573
+ */
574
+ async count(query) {
575
+ return this.fetch(`/threads/count`, {
576
+ method: "POST",
577
+ json: {
578
+ metadata: query?.metadata ?? undefined,
579
+ values: query?.values ?? undefined,
580
+ status: query?.status ?? undefined,
528
581
  },
529
582
  });
530
583
  }
@@ -787,6 +840,7 @@ export class RunsClient extends BaseClient {
787
840
  limit: options?.limit ?? 10,
788
841
  offset: options?.offset ?? 0,
789
842
  status: options?.status ?? undefined,
843
+ select: options?.select ?? undefined,
790
844
  },
791
845
  });
792
846
  }
@@ -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.111",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "scripts": {