@langchain/langgraph-sdk 0.0.47-experimental.0 → 0.0.48

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Client } from "./client.js";
2
- export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, ListNamespaceResponse, Item, SearchItem, SearchItemsResponse, CronCreateResponse, CronCreateForThreadResponse, } from "./schema.js";
2
+ export type { AssistantBase, Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, ListNamespaceResponse, Item, SearchItem, SearchItemsResponse, CronCreateResponse, CronCreateForThreadResponse, } from "./schema.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  export type { OnConflictBehavior, Command } from "./types.js";
5
5
  export type { StreamMode } from "./types.stream.js";
@@ -100,13 +100,17 @@ function fetchComponent(apiUrl, assistantId, agentName) {
100
100
  COMPONENT_PROMISE_CACHE[cacheKey] = request;
101
101
  return request;
102
102
  }
103
- function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId, stream, message, meta, fallback, ...props }) {
103
+ function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId, stream, message, meta, fallback, components, ...props }) {
104
104
  const ref = React.useRef(null);
105
105
  const id = React.useId();
106
106
  const shadowRootId = `child-shadow-${id}`;
107
107
  const store = React.useMemo(() => COMPONENT_STORE.getBoundStore(shadowRootId), [shadowRootId]);
108
108
  const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
109
+ const clientComponent = components?.[message.name];
110
+ const hasClientComponent = clientComponent != null;
109
111
  React.useEffect(() => {
112
+ if (hasClientComponent)
113
+ return;
110
114
  fetchComponent(apiUrl, assistantId, message.name).then((html) => {
111
115
  const dom = ref.current;
112
116
  if (!dom)
@@ -117,7 +121,10 @@ function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId,
117
121
  .createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
118
122
  root.appendChild(fragment);
119
123
  });
120
- }, [apiUrl, assistantId, message.name, shadowRootId]);
124
+ }, [apiUrl, assistantId, message.name, shadowRootId, hasClientComponent]);
125
+ if (hasClientComponent) {
126
+ return React.createElement(clientComponent, message.content);
127
+ }
121
128
  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
122
129
  ? ReactDOM.createPortal(React.createElement(state.comp, message.content), state.target)
123
130
  : fallback })] }));
@@ -61,8 +61,13 @@ interface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivEl
61
61
  meta?: unknown;
62
62
  /** Fallback to be rendered when the component is loading */
63
63
  fallback?: React.ReactNode;
64
+ /**
65
+ * Map of components that can be rendered directly without fetching the UI code
66
+ * from the server.
67
+ */
68
+ components?: Record<string, React.FunctionComponent | React.ComponentClass>;
64
69
  }
65
- export declare function LoadExternalComponent({ apiUrl, assistantId, stream, message, meta, fallback, ...props }: LoadExternalComponentProps): JsxRuntime.JSX.Element;
70
+ export declare function LoadExternalComponent({ apiUrl, assistantId, stream, message, meta, fallback, components, ...props }: LoadExternalComponentProps): JsxRuntime.JSX.Element;
66
71
  declare global {
67
72
  interface Window {
68
73
  [EXT_STORE_SYMBOL]: ComponentStore;
@@ -73,13 +73,17 @@ function fetchComponent(apiUrl, assistantId, agentName) {
73
73
  COMPONENT_PROMISE_CACHE[cacheKey] = request;
74
74
  return request;
75
75
  }
76
- export function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId, stream, message, meta, fallback, ...props }) {
76
+ export function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId, stream, message, meta, fallback, components, ...props }) {
77
77
  const ref = React.useRef(null);
78
78
  const id = React.useId();
79
79
  const shadowRootId = `child-shadow-${id}`;
80
80
  const store = React.useMemo(() => COMPONENT_STORE.getBoundStore(shadowRootId), [shadowRootId]);
81
81
  const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
82
+ const clientComponent = components?.[message.name];
83
+ const hasClientComponent = clientComponent != null;
82
84
  React.useEffect(() => {
85
+ if (hasClientComponent)
86
+ return;
83
87
  fetchComponent(apiUrl, assistantId, message.name).then((html) => {
84
88
  const dom = ref.current;
85
89
  if (!dom)
@@ -90,7 +94,10 @@ export function LoadExternalComponent({ apiUrl = "http://localhost:2024", assist
90
94
  .createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
91
95
  root.appendChild(fragment);
92
96
  });
93
- }, [apiUrl, assistantId, message.name, shadowRootId]);
97
+ }, [apiUrl, assistantId, message.name, shadowRootId, hasClientComponent]);
98
+ if (hasClientComponent) {
99
+ return React.createElement(clientComponent, message.content);
100
+ }
94
101
  return (_jsxs(_Fragment, { children: [_jsx("div", { id: shadowRootId, ref: ref, ...props }), _jsx(UseStreamContext.Provider, { value: { stream, meta }, children: state?.target != null
95
102
  ? ReactDOM.createPortal(React.createElement(state.comp, message.content), state.target)
96
103
  : fallback })] }));
package/dist/schema.d.ts CHANGED
@@ -77,14 +77,14 @@ export interface AssistantBase {
77
77
  metadata: Metadata;
78
78
  /** The version of the assistant. */
79
79
  version: number;
80
+ /** The name of the assistant */
81
+ name: string;
80
82
  }
81
83
  export interface AssistantVersion extends AssistantBase {
82
84
  }
83
85
  export interface Assistant extends AssistantBase {
84
86
  /** The last time the assistant was updated. */
85
87
  updated_at: string;
86
- /** The name of the assistant */
87
- name: string;
88
88
  }
89
89
  export interface AssistantGraph {
90
90
  nodes: Array<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.47-experimental.0",
3
+ "version": "0.0.48",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",
@@ -1 +0,0 @@
1
- module.exports = require('../dist/react-ui/client.cjs');
@@ -1 +0,0 @@
1
- export * from '../dist/react-ui/client.js'
@@ -1 +0,0 @@
1
- export * from '../dist/react-ui/client.js'
@@ -1 +0,0 @@
1
- export * from '../dist/react-ui/client.js'