@langchain/langgraph-sdk 0.0.46 → 0.0.47-experimental.0
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/react/stream.d.ts +1 -1
- package/dist/react-ui/client.cjs +153 -0
- package/dist/react-ui/client.d.ts +73 -0
- package/dist/react-ui/client.js +124 -0
- package/dist/react-ui/index.cjs +8 -0
- package/dist/react-ui/index.d.ts +2 -0
- package/dist/react-ui/index.js +3 -0
- package/dist/react-ui/server/index.cjs +7 -0
- package/dist/react-ui/server/index.d.ts +2 -0
- package/dist/react-ui/server/index.js +2 -0
- package/dist/react-ui/server/server.cjs +35 -0
- package/dist/react-ui/server/server.d.ts +14 -0
- package/dist/react-ui/server/server.js +31 -0
- package/dist/react-ui/types.cjs +22 -0
- package/dist/react-ui/types.d.ts +15 -0
- package/dist/react-ui/types.js +18 -0
- package/package.json +33 -5
- package/react-ui/client.cjs +1 -0
- package/react-ui/client.d.cts +1 -0
- package/react-ui/client.d.ts +1 -0
- package/react-ui/client.js +1 -0
- package/react-ui/server.cjs +1 -0
- package/react-ui/server.d.cts +1 -0
- package/react-ui/server.d.ts +1 -0
- package/react-ui/server.js +1 -0
- package/react-ui.cjs +1 -0
- package/react-ui.d.cts +1 -0
- package/react-ui.d.ts +1 -0
- package/react-ui.js +1 -0
package/dist/react/stream.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ interface UseStreamOptions<StateType extends Record<string, unknown> = Record<st
|
|
|
110
110
|
*/
|
|
111
111
|
onThreadId?: (threadId: string) => void;
|
|
112
112
|
}
|
|
113
|
-
interface UseStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
|
|
113
|
+
export interface UseStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
|
|
114
114
|
/**
|
|
115
115
|
* The current values of the thread.
|
|
116
116
|
*/
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.bootstrapUiContext = exports.LoadExternalComponent = exports.useStreamContext = void 0;
|
|
27
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
+
const index_js_1 = require("../react/index.cjs");
|
|
29
|
+
const React = __importStar(require("react"));
|
|
30
|
+
const ReactDOM = __importStar(require("react-dom"));
|
|
31
|
+
const JsxRuntime = __importStar(require("react/jsx-runtime"));
|
|
32
|
+
const UseStreamContext = React.createContext(null);
|
|
33
|
+
function useStreamContext() {
|
|
34
|
+
const ctx = React.useContext(UseStreamContext);
|
|
35
|
+
if (!ctx) {
|
|
36
|
+
throw new Error("useStreamContext must be used within a LoadExternalComponent");
|
|
37
|
+
}
|
|
38
|
+
return new Proxy(ctx, {
|
|
39
|
+
get(target, prop) {
|
|
40
|
+
if (prop === "meta")
|
|
41
|
+
return target.meta;
|
|
42
|
+
return target.stream[prop];
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.useStreamContext = useStreamContext;
|
|
47
|
+
class ComponentStore {
|
|
48
|
+
constructor() {
|
|
49
|
+
Object.defineProperty(this, "cache", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: {}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, "boundCache", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: {}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, "callbacks", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: {}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
respond(shadowRootId, comp, targetElement) {
|
|
69
|
+
this.cache[shadowRootId] = { comp, target: targetElement };
|
|
70
|
+
this.callbacks[shadowRootId]?.forEach((c) => c(comp, targetElement));
|
|
71
|
+
}
|
|
72
|
+
getBoundStore(shadowRootId) {
|
|
73
|
+
this.boundCache[shadowRootId] ??= {
|
|
74
|
+
subscribe: (onStoreChange) => {
|
|
75
|
+
this.callbacks[shadowRootId] ??= [];
|
|
76
|
+
this.callbacks[shadowRootId].push(onStoreChange);
|
|
77
|
+
return () => {
|
|
78
|
+
this.callbacks[shadowRootId] = this.callbacks[shadowRootId].filter((c) => c !== onStoreChange);
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
getSnapshot: () => this.cache[shadowRootId],
|
|
82
|
+
};
|
|
83
|
+
return this.boundCache[shadowRootId];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const COMPONENT_STORE = new ComponentStore();
|
|
87
|
+
const COMPONENT_PROMISE_CACHE = {};
|
|
88
|
+
const EXT_STORE_SYMBOL = Symbol.for("LGUI_EXT_STORE");
|
|
89
|
+
const REQUIRE_SYMBOL = Symbol.for("LGUI_REQUIRE");
|
|
90
|
+
function fetchComponent(apiUrl, assistantId, agentName) {
|
|
91
|
+
const cacheKey = `${apiUrl}-${assistantId}-${agentName}`;
|
|
92
|
+
if (COMPONENT_PROMISE_CACHE[cacheKey] != null) {
|
|
93
|
+
return COMPONENT_PROMISE_CACHE[cacheKey];
|
|
94
|
+
}
|
|
95
|
+
const request = fetch(`${apiUrl}/ui/${assistantId}`, {
|
|
96
|
+
headers: { Accept: "text/html", "Content-Type": "application/json" },
|
|
97
|
+
method: "POST",
|
|
98
|
+
body: JSON.stringify({ name: agentName }),
|
|
99
|
+
}).then((a) => a.text());
|
|
100
|
+
COMPONENT_PROMISE_CACHE[cacheKey] = request;
|
|
101
|
+
return request;
|
|
102
|
+
}
|
|
103
|
+
function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId, stream, message, meta, fallback, ...props }) {
|
|
104
|
+
const ref = React.useRef(null);
|
|
105
|
+
const id = React.useId();
|
|
106
|
+
const shadowRootId = `child-shadow-${id}`;
|
|
107
|
+
const store = React.useMemo(() => COMPONENT_STORE.getBoundStore(shadowRootId), [shadowRootId]);
|
|
108
|
+
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
109
|
+
React.useEffect(() => {
|
|
110
|
+
fetchComponent(apiUrl, assistantId, message.name).then((html) => {
|
|
111
|
+
const dom = ref.current;
|
|
112
|
+
if (!dom)
|
|
113
|
+
return;
|
|
114
|
+
const root = dom.shadowRoot ?? dom.attachShadow({ mode: "open" });
|
|
115
|
+
const fragment = document
|
|
116
|
+
.createRange()
|
|
117
|
+
.createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
|
|
118
|
+
root.appendChild(fragment);
|
|
119
|
+
});
|
|
120
|
+
}, [apiUrl, assistantId, message.name, shadowRootId]);
|
|
121
|
+
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
|
+
? ReactDOM.createPortal(React.createElement(state.comp, message.content), state.target)
|
|
123
|
+
: fallback })] }));
|
|
124
|
+
}
|
|
125
|
+
exports.LoadExternalComponent = LoadExternalComponent;
|
|
126
|
+
function bootstrapUiContext() {
|
|
127
|
+
if (typeof window === "undefined") {
|
|
128
|
+
console.warn("Attempting to bootstrap UI context outside of browser environment. " +
|
|
129
|
+
"Avoid importing from `@langchain/langgraph-sdk/react-ui` in server context.");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
window[EXT_STORE_SYMBOL] = COMPONENT_STORE;
|
|
133
|
+
window[REQUIRE_SYMBOL] = (name) => {
|
|
134
|
+
if (name === "react")
|
|
135
|
+
return React;
|
|
136
|
+
if (name === "react-dom")
|
|
137
|
+
return ReactDOM;
|
|
138
|
+
if (name === "react/jsx-runtime")
|
|
139
|
+
return JsxRuntime;
|
|
140
|
+
if (name === "@langchain/langgraph-sdk/react")
|
|
141
|
+
return { useStream: index_js_1.useStream };
|
|
142
|
+
if (name === "@langchain/langgraph-sdk/react-ui") {
|
|
143
|
+
return {
|
|
144
|
+
useStreamContext,
|
|
145
|
+
LoadExternalComponent: () => {
|
|
146
|
+
throw new Error("Nesting LoadExternalComponent is not supported");
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
throw new Error(`Unknown module...: ${name}`);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
exports.bootstrapUiContext = bootstrapUiContext;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useStream } from "../react/index.js";
|
|
2
|
+
import type { UIMessage } from "./types.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as JsxRuntime from "react/jsx-runtime";
|
|
5
|
+
import type { UseStream } from "../react/stream.js";
|
|
6
|
+
declare const UseStreamContext: React.Context<{
|
|
7
|
+
stream: UseStream<Record<string, unknown>, {
|
|
8
|
+
ConfigurableType?: Record<string, unknown> | undefined;
|
|
9
|
+
InterruptType?: unknown;
|
|
10
|
+
CustomEventType?: unknown;
|
|
11
|
+
UpdateType?: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
meta: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
type BagTemplate = {
|
|
16
|
+
ConfigurableType?: Record<string, unknown>;
|
|
17
|
+
InterruptType?: unknown;
|
|
18
|
+
CustomEventType?: unknown;
|
|
19
|
+
UpdateType?: unknown;
|
|
20
|
+
MetaType?: unknown;
|
|
21
|
+
};
|
|
22
|
+
type GetMetaType<Bag extends BagTemplate> = Bag extends {
|
|
23
|
+
MetaType: unknown;
|
|
24
|
+
} ? Bag["MetaType"] : unknown;
|
|
25
|
+
interface UseStreamContext<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> extends UseStream<StateType, Bag> {
|
|
26
|
+
meta?: GetMetaType<Bag>;
|
|
27
|
+
}
|
|
28
|
+
export declare function useStreamContext<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
29
|
+
ConfigurableType?: Record<string, unknown>;
|
|
30
|
+
InterruptType?: unknown;
|
|
31
|
+
CustomEventType?: unknown;
|
|
32
|
+
UpdateType?: unknown;
|
|
33
|
+
MetaType?: unknown;
|
|
34
|
+
} = BagTemplate>(): UseStreamContext<StateType, Bag>;
|
|
35
|
+
interface ComponentTarget {
|
|
36
|
+
comp: React.FunctionComponent | React.ComponentClass;
|
|
37
|
+
target: HTMLElement;
|
|
38
|
+
}
|
|
39
|
+
declare class ComponentStore {
|
|
40
|
+
private cache;
|
|
41
|
+
private boundCache;
|
|
42
|
+
private callbacks;
|
|
43
|
+
respond(shadowRootId: string, comp: React.FunctionComponent | React.ComponentClass, targetElement: HTMLElement): void;
|
|
44
|
+
getBoundStore(shadowRootId: string): {
|
|
45
|
+
subscribe: (onStoreChange: () => void) => () => void;
|
|
46
|
+
getSnapshot: () => ComponentTarget | undefined;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
declare const EXT_STORE_SYMBOL: unique symbol;
|
|
50
|
+
declare const REQUIRE_SYMBOL: unique symbol;
|
|
51
|
+
interface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivElement>, "style" | "className"> {
|
|
52
|
+
/** API URL of the LangGraph Platform */
|
|
53
|
+
apiUrl?: string;
|
|
54
|
+
/** ID of the assistant */
|
|
55
|
+
assistantId: string;
|
|
56
|
+
/** Stream of the assistant */
|
|
57
|
+
stream: ReturnType<typeof useStream>;
|
|
58
|
+
/** UI message to be rendered */
|
|
59
|
+
message: UIMessage;
|
|
60
|
+
/** Additional context to be passed to the child component */
|
|
61
|
+
meta?: unknown;
|
|
62
|
+
/** Fallback to be rendered when the component is loading */
|
|
63
|
+
fallback?: React.ReactNode;
|
|
64
|
+
}
|
|
65
|
+
export declare function LoadExternalComponent({ apiUrl, assistantId, stream, message, meta, fallback, ...props }: LoadExternalComponentProps): JsxRuntime.JSX.Element;
|
|
66
|
+
declare global {
|
|
67
|
+
interface Window {
|
|
68
|
+
[EXT_STORE_SYMBOL]: ComponentStore;
|
|
69
|
+
[REQUIRE_SYMBOL]: (name: string) => unknown;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export declare function bootstrapUiContext(): void;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useStream } from "../react/index.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as ReactDOM from "react-dom";
|
|
5
|
+
import * as JsxRuntime from "react/jsx-runtime";
|
|
6
|
+
const UseStreamContext = React.createContext(null);
|
|
7
|
+
export function useStreamContext() {
|
|
8
|
+
const ctx = React.useContext(UseStreamContext);
|
|
9
|
+
if (!ctx) {
|
|
10
|
+
throw new Error("useStreamContext must be used within a LoadExternalComponent");
|
|
11
|
+
}
|
|
12
|
+
return new Proxy(ctx, {
|
|
13
|
+
get(target, prop) {
|
|
14
|
+
if (prop === "meta")
|
|
15
|
+
return target.meta;
|
|
16
|
+
return target.stream[prop];
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
class ComponentStore {
|
|
21
|
+
constructor() {
|
|
22
|
+
Object.defineProperty(this, "cache", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: {}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "boundCache", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: {}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "callbacks", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: {}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
respond(shadowRootId, comp, targetElement) {
|
|
42
|
+
this.cache[shadowRootId] = { comp, target: targetElement };
|
|
43
|
+
this.callbacks[shadowRootId]?.forEach((c) => c(comp, targetElement));
|
|
44
|
+
}
|
|
45
|
+
getBoundStore(shadowRootId) {
|
|
46
|
+
this.boundCache[shadowRootId] ??= {
|
|
47
|
+
subscribe: (onStoreChange) => {
|
|
48
|
+
this.callbacks[shadowRootId] ??= [];
|
|
49
|
+
this.callbacks[shadowRootId].push(onStoreChange);
|
|
50
|
+
return () => {
|
|
51
|
+
this.callbacks[shadowRootId] = this.callbacks[shadowRootId].filter((c) => c !== onStoreChange);
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
getSnapshot: () => this.cache[shadowRootId],
|
|
55
|
+
};
|
|
56
|
+
return this.boundCache[shadowRootId];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const COMPONENT_STORE = new ComponentStore();
|
|
60
|
+
const COMPONENT_PROMISE_CACHE = {};
|
|
61
|
+
const EXT_STORE_SYMBOL = Symbol.for("LGUI_EXT_STORE");
|
|
62
|
+
const REQUIRE_SYMBOL = Symbol.for("LGUI_REQUIRE");
|
|
63
|
+
function fetchComponent(apiUrl, assistantId, agentName) {
|
|
64
|
+
const cacheKey = `${apiUrl}-${assistantId}-${agentName}`;
|
|
65
|
+
if (COMPONENT_PROMISE_CACHE[cacheKey] != null) {
|
|
66
|
+
return COMPONENT_PROMISE_CACHE[cacheKey];
|
|
67
|
+
}
|
|
68
|
+
const request = fetch(`${apiUrl}/ui/${assistantId}`, {
|
|
69
|
+
headers: { Accept: "text/html", "Content-Type": "application/json" },
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: JSON.stringify({ name: agentName }),
|
|
72
|
+
}).then((a) => a.text());
|
|
73
|
+
COMPONENT_PROMISE_CACHE[cacheKey] = request;
|
|
74
|
+
return request;
|
|
75
|
+
}
|
|
76
|
+
export function LoadExternalComponent({ apiUrl = "http://localhost:2024", assistantId, stream, message, meta, fallback, ...props }) {
|
|
77
|
+
const ref = React.useRef(null);
|
|
78
|
+
const id = React.useId();
|
|
79
|
+
const shadowRootId = `child-shadow-${id}`;
|
|
80
|
+
const store = React.useMemo(() => COMPONENT_STORE.getBoundStore(shadowRootId), [shadowRootId]);
|
|
81
|
+
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
fetchComponent(apiUrl, assistantId, message.name).then((html) => {
|
|
84
|
+
const dom = ref.current;
|
|
85
|
+
if (!dom)
|
|
86
|
+
return;
|
|
87
|
+
const root = dom.shadowRoot ?? dom.attachShadow({ mode: "open" });
|
|
88
|
+
const fragment = document
|
|
89
|
+
.createRange()
|
|
90
|
+
.createContextualFragment(html.replace("{{shadowRootId}}", shadowRootId));
|
|
91
|
+
root.appendChild(fragment);
|
|
92
|
+
});
|
|
93
|
+
}, [apiUrl, assistantId, message.name, shadowRootId]);
|
|
94
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { id: shadowRootId, ref: ref, ...props }), _jsx(UseStreamContext.Provider, { value: { stream, meta }, children: state?.target != null
|
|
95
|
+
? ReactDOM.createPortal(React.createElement(state.comp, message.content), state.target)
|
|
96
|
+
: fallback })] }));
|
|
97
|
+
}
|
|
98
|
+
export function bootstrapUiContext() {
|
|
99
|
+
if (typeof window === "undefined") {
|
|
100
|
+
console.warn("Attempting to bootstrap UI context outside of browser environment. " +
|
|
101
|
+
"Avoid importing from `@langchain/langgraph-sdk/react-ui` in server context.");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
window[EXT_STORE_SYMBOL] = COMPONENT_STORE;
|
|
105
|
+
window[REQUIRE_SYMBOL] = (name) => {
|
|
106
|
+
if (name === "react")
|
|
107
|
+
return React;
|
|
108
|
+
if (name === "react-dom")
|
|
109
|
+
return ReactDOM;
|
|
110
|
+
if (name === "react/jsx-runtime")
|
|
111
|
+
return JsxRuntime;
|
|
112
|
+
if (name === "@langchain/langgraph-sdk/react")
|
|
113
|
+
return { useStream };
|
|
114
|
+
if (name === "@langchain/langgraph-sdk/react-ui") {
|
|
115
|
+
return {
|
|
116
|
+
useStreamContext,
|
|
117
|
+
LoadExternalComponent: () => {
|
|
118
|
+
throw new Error("Nesting LoadExternalComponent is not supported");
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
throw new Error(`Unknown module...: ${name}`);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoadExternalComponent = exports.useStreamContext = void 0;
|
|
4
|
+
const client_js_1 = require("./client.cjs");
|
|
5
|
+
(0, client_js_1.bootstrapUiContext)();
|
|
6
|
+
var client_js_2 = require("./client.cjs");
|
|
7
|
+
Object.defineProperty(exports, "useStreamContext", { enumerable: true, get: function () { return client_js_2.useStreamContext; } });
|
|
8
|
+
Object.defineProperty(exports, "LoadExternalComponent", { enumerable: true, get: function () { return client_js_2.LoadExternalComponent; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uiMessageReducer = exports.typedUi = void 0;
|
|
4
|
+
var server_js_1 = require("./server.cjs");
|
|
5
|
+
Object.defineProperty(exports, "typedUi", { enumerable: true, get: function () { return server_js_1.typedUi; } });
|
|
6
|
+
var types_js_1 = require("../types.cjs");
|
|
7
|
+
Object.defineProperty(exports, "uiMessageReducer", { enumerable: true, get: function () { return types_js_1.uiMessageReducer; } });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typedUi = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const typedUi = (config) => {
|
|
6
|
+
let collect = [];
|
|
7
|
+
const runId = config.metadata?.run_id ?? config.runId;
|
|
8
|
+
if (!runId)
|
|
9
|
+
throw new Error("run_id is required");
|
|
10
|
+
const metadata = {
|
|
11
|
+
...config.metadata,
|
|
12
|
+
tags: config.tags,
|
|
13
|
+
name: config.runName,
|
|
14
|
+
run_id: runId,
|
|
15
|
+
};
|
|
16
|
+
const create = (name, props) => ({
|
|
17
|
+
type: "ui",
|
|
18
|
+
id: (0, uuid_1.v4)(),
|
|
19
|
+
name,
|
|
20
|
+
content: props,
|
|
21
|
+
additional_kwargs: metadata,
|
|
22
|
+
});
|
|
23
|
+
const remove = (id) => ({ type: "remove-ui", id });
|
|
24
|
+
return {
|
|
25
|
+
create,
|
|
26
|
+
remove,
|
|
27
|
+
collect,
|
|
28
|
+
write: (name, props) => {
|
|
29
|
+
const evt = create(name, props);
|
|
30
|
+
collect.push(evt);
|
|
31
|
+
config.writer?.(evt);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.typedUi = typedUi;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ElementType } from "react";
|
|
2
|
+
import type { RemoveUIMessage, UIMessage } from "../types.js";
|
|
3
|
+
export declare const typedUi: <Decl extends Record<string, ElementType>>(config: {
|
|
4
|
+
writer?: (chunk: unknown) => void;
|
|
5
|
+
runId?: string;
|
|
6
|
+
metadata?: Record<string, unknown>;
|
|
7
|
+
tags?: string[];
|
|
8
|
+
runName?: string;
|
|
9
|
+
}) => {
|
|
10
|
+
create: <K extends keyof Decl & string>(name: K, props: { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K]) => UIMessage;
|
|
11
|
+
remove: (id: string) => RemoveUIMessage;
|
|
12
|
+
collect: (UIMessage | RemoveUIMessage)[];
|
|
13
|
+
write: <K_2 extends keyof Decl & string>(name: K_2, props: { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K_2]) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
export const typedUi = (config) => {
|
|
3
|
+
let collect = [];
|
|
4
|
+
const runId = config.metadata?.run_id ?? config.runId;
|
|
5
|
+
if (!runId)
|
|
6
|
+
throw new Error("run_id is required");
|
|
7
|
+
const metadata = {
|
|
8
|
+
...config.metadata,
|
|
9
|
+
tags: config.tags,
|
|
10
|
+
name: config.runName,
|
|
11
|
+
run_id: runId,
|
|
12
|
+
};
|
|
13
|
+
const create = (name, props) => ({
|
|
14
|
+
type: "ui",
|
|
15
|
+
id: uuidv4(),
|
|
16
|
+
name,
|
|
17
|
+
content: props,
|
|
18
|
+
additional_kwargs: metadata,
|
|
19
|
+
});
|
|
20
|
+
const remove = (id) => ({ type: "remove-ui", id });
|
|
21
|
+
return {
|
|
22
|
+
create,
|
|
23
|
+
remove,
|
|
24
|
+
collect,
|
|
25
|
+
write: (name, props) => {
|
|
26
|
+
const evt = create(name, props);
|
|
27
|
+
collect.push(evt);
|
|
28
|
+
config.writer?.(evt);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uiMessageReducer = void 0;
|
|
4
|
+
function uiMessageReducer(state, update) {
|
|
5
|
+
const events = Array.isArray(update) ? update : [update];
|
|
6
|
+
let newState = state.slice();
|
|
7
|
+
for (const event of events) {
|
|
8
|
+
if (event.type === "remove-ui") {
|
|
9
|
+
newState = newState.filter((ui) => ui.id !== event.id);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const index = state.findIndex((ui) => ui.id === event.id);
|
|
13
|
+
if (index !== -1) {
|
|
14
|
+
newState[index] = event;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
newState.push(event);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return newState;
|
|
21
|
+
}
|
|
22
|
+
exports.uiMessageReducer = uiMessageReducer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface UIMessage {
|
|
2
|
+
type: "ui";
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
content: Record<string, unknown>;
|
|
6
|
+
additional_kwargs: {
|
|
7
|
+
run_id: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface RemoveUIMessage {
|
|
12
|
+
type: "remove-ui";
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function uiMessageReducer(state: UIMessage[], update: UIMessage | RemoveUIMessage | (UIMessage | RemoveUIMessage)[]): UIMessage[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function uiMessageReducer(state, update) {
|
|
2
|
+
const events = Array.isArray(update) ? update : [update];
|
|
3
|
+
let newState = state.slice();
|
|
4
|
+
for (const event of events) {
|
|
5
|
+
if (event.type === "remove-ui") {
|
|
6
|
+
newState = newState.filter((ui) => ui.id !== event.id);
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
const index = state.findIndex((ui) => ui.id === event.id);
|
|
10
|
+
if (index !== -1) {
|
|
11
|
+
newState[index] = event;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
newState.push(event);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return newState;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47-experimental.0",
|
|
4
4
|
"description": "Client library for interacting with the LangGraph API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "yarn@1.22.19",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clean": "rm -rf dist/ dist-cjs/",
|
|
9
9
|
"build": "yarn clean && yarn lc_build --create-entrypoints --pre --tree-shaking",
|
|
10
|
-
"
|
|
10
|
+
"prepack": "yarn run build",
|
|
11
11
|
"format": "prettier --write src",
|
|
12
12
|
"lint": "prettier --check src && tsc --noEmit",
|
|
13
13
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"@types/jest": "^29.5.12",
|
|
30
30
|
"@types/node": "^20.12.12",
|
|
31
31
|
"@types/uuid": "^9.0.1",
|
|
32
|
-
"@types/react": "
|
|
32
|
+
"@types/react": "^19.0.8",
|
|
33
|
+
"@types/react-dom": "^19.0.3",
|
|
33
34
|
"concat-md": "^0.5.1",
|
|
34
35
|
"jest": "^29.7.0",
|
|
35
36
|
"prettier": "^3.2.5",
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
"typedoc": "^0.27.7",
|
|
38
39
|
"typedoc-plugin-markdown": "^4.4.2",
|
|
39
40
|
"typescript": "^5.4.5",
|
|
40
|
-
"react": "^
|
|
41
|
+
"react": "^19.0.0",
|
|
42
|
+
"react-dom": "^19.0.0"
|
|
41
43
|
},
|
|
42
44
|
"peerDependencies": {
|
|
43
45
|
"react": "^18 || ^19",
|
|
@@ -79,6 +81,24 @@
|
|
|
79
81
|
"import": "./react.js",
|
|
80
82
|
"require": "./react.cjs"
|
|
81
83
|
},
|
|
84
|
+
"./react-ui": {
|
|
85
|
+
"types": {
|
|
86
|
+
"import": "./react-ui.d.ts",
|
|
87
|
+
"require": "./react-ui.d.cts",
|
|
88
|
+
"default": "./react-ui.d.ts"
|
|
89
|
+
},
|
|
90
|
+
"import": "./react-ui.js",
|
|
91
|
+
"require": "./react-ui.cjs"
|
|
92
|
+
},
|
|
93
|
+
"./react-ui/server": {
|
|
94
|
+
"types": {
|
|
95
|
+
"import": "./react-ui/server.d.ts",
|
|
96
|
+
"require": "./react-ui/server.d.cts",
|
|
97
|
+
"default": "./react-ui/server.d.ts"
|
|
98
|
+
},
|
|
99
|
+
"import": "./react-ui/server.js",
|
|
100
|
+
"require": "./react-ui/server.cjs"
|
|
101
|
+
},
|
|
82
102
|
"./package.json": "./package.json"
|
|
83
103
|
},
|
|
84
104
|
"files": [
|
|
@@ -94,6 +114,14 @@
|
|
|
94
114
|
"react.cjs",
|
|
95
115
|
"react.js",
|
|
96
116
|
"react.d.ts",
|
|
97
|
-
"react.d.cts"
|
|
117
|
+
"react.d.cts",
|
|
118
|
+
"react-ui.cjs",
|
|
119
|
+
"react-ui.js",
|
|
120
|
+
"react-ui.d.ts",
|
|
121
|
+
"react-ui.d.cts",
|
|
122
|
+
"react-ui/server.cjs",
|
|
123
|
+
"react-ui/server.js",
|
|
124
|
+
"react-ui/server.d.ts",
|
|
125
|
+
"react-ui/server.d.cts"
|
|
98
126
|
]
|
|
99
127
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/react-ui/client.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/react-ui/client.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/react-ui/client.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/react-ui/client.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/react-ui/server/index.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/react-ui/server/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/react-ui/server/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/react-ui/server/index.js'
|
package/react-ui.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/react-ui/index.cjs');
|
package/react-ui.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/react-ui/index.js'
|
package/react-ui.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/react-ui/index.js'
|
package/react-ui.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/react-ui/index.js'
|