@langchain/langgraph-sdk 0.0.53 → 0.0.56

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())
@@ -87,7 +87,7 @@ class ComponentStore {
87
87
  const COMPONENT_STORE = new ComponentStore();
88
88
  const EXT_STORE_SYMBOL = Symbol.for("LGUI_EXT_STORE");
89
89
  const REQUIRE_SYMBOL = Symbol.for("LGUI_REQUIRE");
90
- function LoadExternalComponent({ stream, message, meta, fallback, components, ...props }) {
90
+ function LoadExternalComponent({ stream, namespace, message, meta, fallback, components, ...props }) {
91
91
  const ref = React.useRef(null);
92
92
  const id = React.useId();
93
93
  const shadowRootId = `child-shadow-${id}`;
@@ -95,11 +95,12 @@ function LoadExternalComponent({ stream, message, meta, fallback, components, ..
95
95
  const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
96
96
  const clientComponent = components?.[message.name];
97
97
  const hasClientComponent = clientComponent != null;
98
+ const uiNamespace = namespace ?? stream.assistantId;
98
99
  const uiClient = stream.client["~ui"];
99
100
  React.useEffect(() => {
100
101
  if (hasClientComponent)
101
102
  return;
102
- uiClient.getComponent(stream.assistantId, message.name).then((html) => {
103
+ uiClient.getComponent(uiNamespace, message.name).then((html) => {
103
104
  const dom = ref.current;
104
105
  if (!dom)
105
106
  return;
@@ -109,13 +110,7 @@ function LoadExternalComponent({ stream, message, meta, fallback, components, ..
109
110
  .createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
110
111
  root.appendChild(fragment);
111
112
  });
112
- }, [
113
- uiClient,
114
- stream.assistantId,
115
- message.name,
116
- shadowRootId,
117
- hasClientComponent,
118
- ]);
113
+ }, [uiClient, uiNamespace, message.name, shadowRootId, hasClientComponent]);
119
114
  if (hasClientComponent) {
120
115
  return React.createElement(clientComponent, message.props);
121
116
  }
@@ -51,6 +51,8 @@ declare const REQUIRE_SYMBOL: unique symbol;
51
51
  interface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivElement>, "style" | "className"> {
52
52
  /** Stream of the assistant */
53
53
  stream: ReturnType<typeof useStream>;
54
+ /** Namespace of UI components. Defaults to assistant ID. */
55
+ namespace?: string;
54
56
  /** UI message to be rendered */
55
57
  message: UIMessage;
56
58
  /** Additional context to be passed to the child component */
@@ -63,7 +65,7 @@ interface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivEl
63
65
  */
64
66
  components?: Record<string, React.FunctionComponent | React.ComponentClass>;
65
67
  }
66
- export declare function LoadExternalComponent({ stream, message, meta, fallback, components, ...props }: LoadExternalComponentProps): JsxRuntime.JSX.Element;
68
+ export declare function LoadExternalComponent({ stream, namespace, message, meta, fallback, components, ...props }: LoadExternalComponentProps): JsxRuntime.JSX.Element;
67
69
  declare global {
68
70
  interface Window {
69
71
  [EXT_STORE_SYMBOL]: ComponentStore;
@@ -60,7 +60,7 @@ class ComponentStore {
60
60
  const COMPONENT_STORE = new ComponentStore();
61
61
  const EXT_STORE_SYMBOL = Symbol.for("LGUI_EXT_STORE");
62
62
  const REQUIRE_SYMBOL = Symbol.for("LGUI_REQUIRE");
63
- export function LoadExternalComponent({ stream, message, meta, fallback, components, ...props }) {
63
+ export function LoadExternalComponent({ stream, namespace, message, meta, fallback, components, ...props }) {
64
64
  const ref = React.useRef(null);
65
65
  const id = React.useId();
66
66
  const shadowRootId = `child-shadow-${id}`;
@@ -68,11 +68,12 @@ export function LoadExternalComponent({ stream, message, meta, fallback, compone
68
68
  const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
69
69
  const clientComponent = components?.[message.name];
70
70
  const hasClientComponent = clientComponent != null;
71
+ const uiNamespace = namespace ?? stream.assistantId;
71
72
  const uiClient = stream.client["~ui"];
72
73
  React.useEffect(() => {
73
74
  if (hasClientComponent)
74
75
  return;
75
- uiClient.getComponent(stream.assistantId, message.name).then((html) => {
76
+ uiClient.getComponent(uiNamespace, message.name).then((html) => {
76
77
  const dom = ref.current;
77
78
  if (!dom)
78
79
  return;
@@ -82,13 +83,7 @@ export function LoadExternalComponent({ stream, message, meta, fallback, compone
82
83
  .createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
83
84
  root.appendChild(fragment);
84
85
  });
85
- }, [
86
- uiClient,
87
- stream.assistantId,
88
- message.name,
89
- shadowRootId,
90
- hasClientComponent,
91
- ]);
86
+ }, [uiClient, uiNamespace, message.name, shadowRootId, hasClientComponent]);
92
87
  if (hasClientComponent) {
93
88
  return React.createElement(clientComponent, message.props);
94
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.53",
3
+ "version": "0.0.56",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",