@langchain/langgraph-sdk 0.0.54 → 0.0.57

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/dist/client.cjs CHANGED
@@ -686,6 +686,12 @@ class RunsClient extends BaseClient {
686
686
  *
687
687
  * @param threadId The ID of the thread.
688
688
  * @param runId The ID of the run.
689
+ * @param options Additional options for controlling the stream behavior:
690
+ * - signal: An AbortSignal that can be used to cancel the stream request
691
+ * - cancelOnDisconnect: When true, automatically cancels the run if the client disconnects from the stream
692
+ * - streamMode: Controls what types of events to receive from the stream (can be a single mode or array of modes)
693
+ * Must be a subset of the stream modes passed when creating the run. Background runs default to having the union of all
694
+ * stream modes enabled.
689
695
  * @returns An async generator yielding stream parts.
690
696
  */
691
697
  async *joinStream(threadId, runId, options) {
@@ -698,7 +704,10 @@ class RunsClient extends BaseClient {
698
704
  method: "GET",
699
705
  timeoutMs: null,
700
706
  signal: opts?.signal,
701
- params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
707
+ params: {
708
+ cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0",
709
+ stream_mode: opts?.streamMode,
710
+ },
702
711
  }));
703
712
  const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
704
713
  .pipeThrough(new sse_js_1.BytesLineDecoder())
package/dist/client.d.ts CHANGED
@@ -364,11 +364,18 @@ export declare class RunsClient<TStateType = DefaultValues, TUpdateType = TState
364
364
  *
365
365
  * @param threadId The ID of the thread.
366
366
  * @param runId The ID of the run.
367
+ * @param options Additional options for controlling the stream behavior:
368
+ * - signal: An AbortSignal that can be used to cancel the stream request
369
+ * - cancelOnDisconnect: When true, automatically cancels the run if the client disconnects from the stream
370
+ * - streamMode: Controls what types of events to receive from the stream (can be a single mode or array of modes)
371
+ * Must be a subset of the stream modes passed when creating the run. Background runs default to having the union of all
372
+ * stream modes enabled.
367
373
  * @returns An async generator yielding stream parts.
368
374
  */
369
375
  joinStream(threadId: string, runId: string, options?: {
370
376
  signal?: AbortSignal;
371
377
  cancelOnDisconnect?: boolean;
378
+ streamMode?: StreamMode | StreamMode[];
372
379
  } | AbortSignal): AsyncGenerator<{
373
380
  event: StreamEvent;
374
381
  data: any;
package/dist/client.js CHANGED
@@ -679,6 +679,12 @@ export class RunsClient extends BaseClient {
679
679
  *
680
680
  * @param threadId The ID of the thread.
681
681
  * @param runId The ID of the run.
682
+ * @param options Additional options for controlling the stream behavior:
683
+ * - signal: An AbortSignal that can be used to cancel the stream request
684
+ * - cancelOnDisconnect: When true, automatically cancels the run if the client disconnects from the stream
685
+ * - streamMode: Controls what types of events to receive from the stream (can be a single mode or array of modes)
686
+ * Must be a subset of the stream modes passed when creating the run. Background runs default to having the union of all
687
+ * stream modes enabled.
682
688
  * @returns An async generator yielding stream parts.
683
689
  */
684
690
  async *joinStream(threadId, runId, options) {
@@ -691,7 +697,10 @@ export class RunsClient extends BaseClient {
691
697
  method: "GET",
692
698
  timeoutMs: null,
693
699
  signal: opts?.signal,
694
- params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
700
+ params: {
701
+ cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0",
702
+ stream_mode: opts?.streamMode,
703
+ },
695
704
  }));
696
705
  const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
697
706
  .pipeThrough(new BytesLineDecoder())
@@ -2,8 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typedUi = void 0;
4
4
  const uuid_1 = require("uuid");
5
- const typedUi = (config) => {
5
+ /**
6
+ * Helper to send and persist UI messages. Accepts a map of component names to React components
7
+ * as type argument to provide type safety. Will also write to the `options?.stateKey` state.
8
+ *
9
+ * @param config LangGraphRunnableConfig
10
+ * @param options
11
+ * @returns
12
+ */
13
+ const typedUi = (config, options) => {
6
14
  let items = [];
15
+ const stateKey = options?.stateKey ?? "ui";
7
16
  const runId = config.metadata?.run_id ?? config.runId;
8
17
  if (!runId)
9
18
  throw new Error("run_id is required");
@@ -27,12 +36,14 @@ const typedUi = (config) => {
27
36
  };
28
37
  items.push(evt);
29
38
  config.writer?.(evt);
39
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
30
40
  return evt;
31
41
  };
32
42
  const handleDelete = (id) => {
33
43
  const evt = { type: "remove-ui", id };
34
44
  items.push(evt);
35
45
  config.writer?.(evt);
46
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
36
47
  return evt;
37
48
  };
38
49
  return { push: handlePush, delete: handleDelete, items };
@@ -3,12 +3,27 @@ import type { RemoveUIMessage, UIMessage } from "../types.js";
3
3
  interface MessageLike {
4
4
  id?: string;
5
5
  }
6
+ /**
7
+ * Helper to send and persist UI messages. Accepts a map of component names to React components
8
+ * as type argument to provide type safety. Will also write to the `options?.stateKey` state.
9
+ *
10
+ * @param config LangGraphRunnableConfig
11
+ * @param options
12
+ * @returns
13
+ */
6
14
  export declare const typedUi: <Decl extends Record<string, ElementType>>(config: {
7
15
  writer?: (chunk: unknown) => void;
8
16
  runId?: string;
9
17
  metadata?: Record<string, unknown>;
10
18
  tags?: string[];
11
19
  runName?: string;
20
+ configurable?: {
21
+ __pregel_send?: (writes_: [string, unknown][]) => void;
22
+ [key: string]: unknown;
23
+ };
24
+ }, options?: {
25
+ /** The key to write the UI messages to. Defaults to `ui`. */
26
+ stateKey?: string;
12
27
  }) => {
13
28
  push: <K extends keyof Decl & string>(message: {
14
29
  id?: string | undefined;
@@ -1,6 +1,15 @@
1
1
  import { v4 as uuidv4 } from "uuid";
2
- export const typedUi = (config) => {
2
+ /**
3
+ * Helper to send and persist UI messages. Accepts a map of component names to React components
4
+ * as type argument to provide type safety. Will also write to the `options?.stateKey` state.
5
+ *
6
+ * @param config LangGraphRunnableConfig
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export const typedUi = (config, options) => {
3
11
  let items = [];
12
+ const stateKey = options?.stateKey ?? "ui";
4
13
  const runId = config.metadata?.run_id ?? config.runId;
5
14
  if (!runId)
6
15
  throw new Error("run_id is required");
@@ -24,12 +33,14 @@ export const typedUi = (config) => {
24
33
  };
25
34
  items.push(evt);
26
35
  config.writer?.(evt);
36
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
27
37
  return evt;
28
38
  };
29
39
  const handleDelete = (id) => {
30
40
  const evt = { type: "remove-ui", id };
31
41
  items.push(evt);
32
42
  config.writer?.(evt);
43
+ config.configurable?.__pregel_send?.([[stateKey, evt]]);
33
44
  return evt;
34
45
  };
35
46
  return { push: handlePush, delete: handleDelete, items };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.54",
3
+ "version": "0.0.57",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",