@langchain/langgraph-sdk 0.0.52 → 0.0.54

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.
@@ -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,18 +110,12 @@ 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
- return React.createElement(clientComponent, message.content);
115
+ return React.createElement(clientComponent, message.props);
121
116
  }
122
117
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { id: shadowRootId, ref: ref, ...props }), (0, jsx_runtime_1.jsx)(UseStreamContext.Provider, { value: { stream, meta }, children: state?.target != null
123
- ? ReactDOM.createPortal(React.createElement(state.comp, message.content), state.target)
118
+ ? ReactDOM.createPortal(React.createElement(state.comp, message.props), state.target)
124
119
  : fallback })] }));
125
120
  }
126
121
  exports.LoadExternalComponent = LoadExternalComponent;
@@ -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,18 +83,12 @@ 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
- return React.createElement(clientComponent, message.content);
88
+ return React.createElement(clientComponent, message.props);
94
89
  }
95
90
  return (_jsxs(_Fragment, { children: [_jsx("div", { id: shadowRootId, ref: ref, ...props }), _jsx(UseStreamContext.Provider, { value: { stream, meta }, children: state?.target != null
96
- ? ReactDOM.createPortal(React.createElement(state.comp, message.content), state.target)
91
+ ? ReactDOM.createPortal(React.createElement(state.comp, message.props), state.target)
97
92
  : fallback })] }));
98
93
  }
99
94
  export function bootstrapUiContext() {
@@ -18,10 +18,10 @@ const typedUi = (config) => {
18
18
  type: "ui",
19
19
  id: message?.id ?? (0, uuid_1.v4)(),
20
20
  name: message?.name,
21
- content: message?.content,
22
- additional_kwargs: {
21
+ props: message?.props,
22
+ metadata: {
23
23
  ...metadata,
24
- ...message?.additional_kwargs,
24
+ ...message?.metadata,
25
25
  ...(options?.message ? { message_id: options.message.id } : null),
26
26
  },
27
27
  };
@@ -13,8 +13,8 @@ export declare const typedUi: <Decl extends Record<string, ElementType>>(config:
13
13
  push: <K extends keyof Decl & string>(message: {
14
14
  id?: string | undefined;
15
15
  name: K;
16
- content: { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K];
17
- additional_kwargs?: Record<string, unknown> | undefined;
16
+ props: { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K];
17
+ metadata?: Record<string, unknown> | undefined;
18
18
  }, options?: {
19
19
  message?: MessageLike;
20
20
  }) => UIMessage;
@@ -15,10 +15,10 @@ export const typedUi = (config) => {
15
15
  type: "ui",
16
16
  id: message?.id ?? uuidv4(),
17
17
  name: message?.name,
18
- content: message?.content,
19
- additional_kwargs: {
18
+ props: message?.props,
19
+ metadata: {
20
20
  ...metadata,
21
- ...message?.additional_kwargs,
21
+ ...message?.metadata,
22
22
  ...(options?.message ? { message_id: options.message.id } : null),
23
23
  },
24
24
  };
@@ -2,8 +2,8 @@ export interface UIMessage {
2
2
  type: "ui";
3
3
  id: string;
4
4
  name: string;
5
- content: Record<string, unknown>;
6
- additional_kwargs: {
5
+ props: Record<string, unknown>;
6
+ metadata: {
7
7
  run_id: string;
8
8
  message_id?: string;
9
9
  [key: string]: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",