@langchain/langgraph-sdk 0.0.70 → 0.0.72
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.cjs +24 -7
- package/dist/react/stream.d.ts +16 -2
- package/dist/react/stream.js +24 -7
- package/dist/react-ui/client.cjs +28 -3
- package/dist/react-ui/client.d.ts +1 -1
- package/dist/react-ui/client.js +28 -3
- package/dist/react-ui/index.cjs +3 -1
- package/dist/react-ui/index.d.ts +1 -1
- package/dist/react-ui/index.js +1 -1
- package/dist/react-ui/server/server.cjs +6 -9
- package/dist/react-ui/server/server.d.ts +21 -9
- package/dist/react-ui/server/server.js +6 -9
- package/dist/react-ui/types.cjs +20 -2
- package/dist/react-ui/types.d.ts +10 -5
- package/dist/react-ui/types.js +17 -1
- package/dist/types.stream.d.ts +9 -1
- package/package.json +1 -1
package/dist/react/stream.cjs
CHANGED
|
@@ -211,12 +211,14 @@ const useControllableThreadId = (options) => {
|
|
|
211
211
|
function useStream(options) {
|
|
212
212
|
let { assistantId, messagesKey, onError, onFinish } = options;
|
|
213
213
|
messagesKey ??= "messages";
|
|
214
|
-
const client = (0, react_1.useMemo)(() =>
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
214
|
+
const client = (0, react_1.useMemo)(() => options.client ??
|
|
215
|
+
new client_js_1.Client({
|
|
216
|
+
apiUrl: options.apiUrl,
|
|
217
|
+
apiKey: options.apiKey,
|
|
218
|
+
callerOptions: options.callerOptions,
|
|
219
|
+
defaultHeaders: options.defaultHeaders,
|
|
220
|
+
}), [
|
|
221
|
+
options.client,
|
|
220
222
|
options.apiKey,
|
|
221
223
|
options.apiUrl,
|
|
222
224
|
options.callerOptions,
|
|
@@ -240,14 +242,25 @@ function useStream(options) {
|
|
|
240
242
|
}, []);
|
|
241
243
|
const hasUpdateListener = options.onUpdateEvent != null;
|
|
242
244
|
const hasCustomListener = options.onCustomEvent != null;
|
|
245
|
+
const hasLangChainListener = options.onLangChainEvent != null;
|
|
246
|
+
const hasDebugListener = options.onDebugEvent != null;
|
|
243
247
|
const callbackStreamMode = (0, react_1.useMemo)(() => {
|
|
244
248
|
const modes = [];
|
|
245
249
|
if (hasUpdateListener)
|
|
246
250
|
modes.push("updates");
|
|
247
251
|
if (hasCustomListener)
|
|
248
252
|
modes.push("custom");
|
|
253
|
+
if (hasLangChainListener)
|
|
254
|
+
modes.push("events");
|
|
255
|
+
if (hasDebugListener)
|
|
256
|
+
modes.push("debug");
|
|
249
257
|
return modes;
|
|
250
|
-
}, [
|
|
258
|
+
}, [
|
|
259
|
+
hasUpdateListener,
|
|
260
|
+
hasCustomListener,
|
|
261
|
+
hasLangChainListener,
|
|
262
|
+
hasDebugListener,
|
|
263
|
+
]);
|
|
251
264
|
const clearCallbackRef = (0, react_1.useRef)(null);
|
|
252
265
|
clearCallbackRef.current = () => {
|
|
253
266
|
setStreamError(undefined);
|
|
@@ -391,6 +404,10 @@ function useStream(options) {
|
|
|
391
404
|
});
|
|
392
405
|
if (event === "metadata")
|
|
393
406
|
options.onMetadataEvent?.(data);
|
|
407
|
+
if (event === "events")
|
|
408
|
+
options.onLangChainEvent?.(data);
|
|
409
|
+
if (event === "debug")
|
|
410
|
+
options.onDebugEvent?.(data);
|
|
394
411
|
if (event === "values")
|
|
395
412
|
setStreamValues(data);
|
|
396
413
|
if (event === "messages") {
|
package/dist/react/stream.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Client, type ClientConfig } from "../client.js";
|
|
|
2
2
|
import type { Command, DisconnectMode, MultitaskStrategy, OnCompletionBehavior } from "../types.js";
|
|
3
3
|
import type { Message } from "../types.messages.js";
|
|
4
4
|
import type { Checkpoint, Config, Interrupt, Metadata, ThreadState } from "../schema.js";
|
|
5
|
-
import type { CustomStreamEvent, MetadataStreamEvent, StreamMode, UpdatesStreamEvent } from "../types.stream.js";
|
|
5
|
+
import type { CustomStreamEvent, DebugStreamEvent, EventsStreamEvent, MetadataStreamEvent, StreamMode, UpdatesStreamEvent } from "../types.stream.js";
|
|
6
6
|
interface Node<StateType = any> {
|
|
7
7
|
type: "node";
|
|
8
8
|
value: ThreadState<StateType>;
|
|
@@ -58,10 +58,14 @@ export interface UseStreamOptions<StateType extends Record<string, unknown> = Re
|
|
|
58
58
|
* The ID of the assistant to use.
|
|
59
59
|
*/
|
|
60
60
|
assistantId: string;
|
|
61
|
+
/**
|
|
62
|
+
* Client used to send requests.
|
|
63
|
+
*/
|
|
64
|
+
client?: Client;
|
|
61
65
|
/**
|
|
62
66
|
* The URL of the API to use.
|
|
63
67
|
*/
|
|
64
|
-
apiUrl
|
|
68
|
+
apiUrl?: ClientConfig["apiUrl"];
|
|
65
69
|
/**
|
|
66
70
|
* The API key to use.
|
|
67
71
|
*/
|
|
@@ -103,6 +107,16 @@ export interface UseStreamOptions<StateType extends Record<string, unknown> = Re
|
|
|
103
107
|
* Callback that is called when a metadata event is received.
|
|
104
108
|
*/
|
|
105
109
|
onMetadataEvent?: (data: MetadataStreamEvent["data"]) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Callback that is called when a LangChain event is received.
|
|
112
|
+
* @see https://langchain-ai.github.io/langgraph/cloud/how-tos/stream_events/#stream-graph-in-events-mode for more details.
|
|
113
|
+
*/
|
|
114
|
+
onLangChainEvent?: (data: EventsStreamEvent["data"]) => void;
|
|
115
|
+
/**
|
|
116
|
+
* Callback that is called when a debug event is received.
|
|
117
|
+
* @internal This API is experimental and subject to change.
|
|
118
|
+
*/
|
|
119
|
+
onDebugEvent?: (data: DebugStreamEvent["data"]) => void;
|
|
106
120
|
/**
|
|
107
121
|
* The ID of the thread to fetch history and current values from.
|
|
108
122
|
*/
|
package/dist/react/stream.js
CHANGED
|
@@ -208,12 +208,14 @@ const useControllableThreadId = (options) => {
|
|
|
208
208
|
export function useStream(options) {
|
|
209
209
|
let { assistantId, messagesKey, onError, onFinish } = options;
|
|
210
210
|
messagesKey ??= "messages";
|
|
211
|
-
const client = useMemo(() =>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
const client = useMemo(() => options.client ??
|
|
212
|
+
new Client({
|
|
213
|
+
apiUrl: options.apiUrl,
|
|
214
|
+
apiKey: options.apiKey,
|
|
215
|
+
callerOptions: options.callerOptions,
|
|
216
|
+
defaultHeaders: options.defaultHeaders,
|
|
217
|
+
}), [
|
|
218
|
+
options.client,
|
|
217
219
|
options.apiKey,
|
|
218
220
|
options.apiUrl,
|
|
219
221
|
options.callerOptions,
|
|
@@ -237,14 +239,25 @@ export function useStream(options) {
|
|
|
237
239
|
}, []);
|
|
238
240
|
const hasUpdateListener = options.onUpdateEvent != null;
|
|
239
241
|
const hasCustomListener = options.onCustomEvent != null;
|
|
242
|
+
const hasLangChainListener = options.onLangChainEvent != null;
|
|
243
|
+
const hasDebugListener = options.onDebugEvent != null;
|
|
240
244
|
const callbackStreamMode = useMemo(() => {
|
|
241
245
|
const modes = [];
|
|
242
246
|
if (hasUpdateListener)
|
|
243
247
|
modes.push("updates");
|
|
244
248
|
if (hasCustomListener)
|
|
245
249
|
modes.push("custom");
|
|
250
|
+
if (hasLangChainListener)
|
|
251
|
+
modes.push("events");
|
|
252
|
+
if (hasDebugListener)
|
|
253
|
+
modes.push("debug");
|
|
246
254
|
return modes;
|
|
247
|
-
}, [
|
|
255
|
+
}, [
|
|
256
|
+
hasUpdateListener,
|
|
257
|
+
hasCustomListener,
|
|
258
|
+
hasLangChainListener,
|
|
259
|
+
hasDebugListener,
|
|
260
|
+
]);
|
|
248
261
|
const clearCallbackRef = useRef(null);
|
|
249
262
|
clearCallbackRef.current = () => {
|
|
250
263
|
setStreamError(undefined);
|
|
@@ -388,6 +401,10 @@ export function useStream(options) {
|
|
|
388
401
|
});
|
|
389
402
|
if (event === "metadata")
|
|
390
403
|
options.onMetadataEvent?.(data);
|
|
404
|
+
if (event === "events")
|
|
405
|
+
options.onLangChainEvent?.(data);
|
|
406
|
+
if (event === "debug")
|
|
407
|
+
options.onDebugEvent?.(data);
|
|
391
408
|
if (event === "values")
|
|
392
409
|
setStreamValues(data);
|
|
393
410
|
if (event === "messages") {
|
package/dist/react-ui/client.cjs
CHANGED
|
@@ -88,6 +88,28 @@ 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
90
|
const REQUIRE_EXTRA_SYMBOL = Symbol.for("LGUI_REQUIRE_EXTRA");
|
|
91
|
+
const isIterable = (value) => value != null && typeof value === "object" && Symbol.iterator in value;
|
|
92
|
+
const isPromise = (value) => value != null &&
|
|
93
|
+
typeof value === "object" &&
|
|
94
|
+
"then" in value &&
|
|
95
|
+
typeof value.then === "function";
|
|
96
|
+
const isReactNode = (value) => {
|
|
97
|
+
if (React.isValidElement(value))
|
|
98
|
+
return true;
|
|
99
|
+
if (value == null)
|
|
100
|
+
return true;
|
|
101
|
+
if (typeof value === "string" ||
|
|
102
|
+
typeof value === "number" ||
|
|
103
|
+
typeof value === "bigint" ||
|
|
104
|
+
typeof value === "boolean") {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if (isIterable(value))
|
|
108
|
+
return true;
|
|
109
|
+
if (isPromise(value))
|
|
110
|
+
return true;
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
91
113
|
function LoadExternalComponent({ stream, namespace, message, meta, fallback, components, ...props }) {
|
|
92
114
|
const ref = React.useRef(null);
|
|
93
115
|
const id = React.useId();
|
|
@@ -96,6 +118,11 @@ function LoadExternalComponent({ stream, namespace, message, meta, fallback, com
|
|
|
96
118
|
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
97
119
|
const clientComponent = components?.[message.name];
|
|
98
120
|
const hasClientComponent = clientComponent != null;
|
|
121
|
+
const fallbackComponent = isReactNode(fallback)
|
|
122
|
+
? fallback
|
|
123
|
+
: typeof fallback === "object" && fallback != null
|
|
124
|
+
? fallback?.[message.name]
|
|
125
|
+
: null;
|
|
99
126
|
const uiNamespace = namespace ?? stream.assistantId;
|
|
100
127
|
const uiClient = stream.client["~ui"];
|
|
101
128
|
React.useEffect(() => {
|
|
@@ -117,7 +144,7 @@ function LoadExternalComponent({ stream, namespace, message, meta, fallback, com
|
|
|
117
144
|
}
|
|
118
145
|
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
|
|
119
146
|
? ReactDOM.createPortal(React.createElement(state.comp, message.props), state.target)
|
|
120
|
-
:
|
|
147
|
+
: fallbackComponent })] }));
|
|
121
148
|
}
|
|
122
149
|
exports.LoadExternalComponent = LoadExternalComponent;
|
|
123
150
|
function experimental_loadShare(name, module) {
|
|
@@ -129,8 +156,6 @@ function experimental_loadShare(name, module) {
|
|
|
129
156
|
exports.experimental_loadShare = experimental_loadShare;
|
|
130
157
|
function bootstrapUiContext() {
|
|
131
158
|
if (typeof window === "undefined") {
|
|
132
|
-
console.warn("Attempting to bootstrap UI context outside of browser environment. " +
|
|
133
|
-
"Avoid importing from `@langchain/langgraph-sdk/react-ui` in server context.");
|
|
134
159
|
return;
|
|
135
160
|
}
|
|
136
161
|
window[EXT_STORE_SYMBOL] = COMPONENT_STORE;
|
|
@@ -59,7 +59,7 @@ interface LoadExternalComponentProps extends Pick<React.HTMLAttributes<HTMLDivEl
|
|
|
59
59
|
/** Additional context to be passed to the child component */
|
|
60
60
|
meta?: unknown;
|
|
61
61
|
/** Fallback to be rendered when the component is loading */
|
|
62
|
-
fallback?: React.ReactNode
|
|
62
|
+
fallback?: React.ReactNode | Record<string, React.ReactNode>;
|
|
63
63
|
/**
|
|
64
64
|
* Map of components that can be rendered directly without fetching the UI code
|
|
65
65
|
* from the server.
|
package/dist/react-ui/client.js
CHANGED
|
@@ -61,6 +61,28 @@ 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
63
|
const REQUIRE_EXTRA_SYMBOL = Symbol.for("LGUI_REQUIRE_EXTRA");
|
|
64
|
+
const isIterable = (value) => value != null && typeof value === "object" && Symbol.iterator in value;
|
|
65
|
+
const isPromise = (value) => value != null &&
|
|
66
|
+
typeof value === "object" &&
|
|
67
|
+
"then" in value &&
|
|
68
|
+
typeof value.then === "function";
|
|
69
|
+
const isReactNode = (value) => {
|
|
70
|
+
if (React.isValidElement(value))
|
|
71
|
+
return true;
|
|
72
|
+
if (value == null)
|
|
73
|
+
return true;
|
|
74
|
+
if (typeof value === "string" ||
|
|
75
|
+
typeof value === "number" ||
|
|
76
|
+
typeof value === "bigint" ||
|
|
77
|
+
typeof value === "boolean") {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (isIterable(value))
|
|
81
|
+
return true;
|
|
82
|
+
if (isPromise(value))
|
|
83
|
+
return true;
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
64
86
|
export function LoadExternalComponent({ stream, namespace, message, meta, fallback, components, ...props }) {
|
|
65
87
|
const ref = React.useRef(null);
|
|
66
88
|
const id = React.useId();
|
|
@@ -69,6 +91,11 @@ export function LoadExternalComponent({ stream, namespace, message, meta, fallba
|
|
|
69
91
|
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
70
92
|
const clientComponent = components?.[message.name];
|
|
71
93
|
const hasClientComponent = clientComponent != null;
|
|
94
|
+
const fallbackComponent = isReactNode(fallback)
|
|
95
|
+
? fallback
|
|
96
|
+
: typeof fallback === "object" && fallback != null
|
|
97
|
+
? fallback?.[message.name]
|
|
98
|
+
: null;
|
|
72
99
|
const uiNamespace = namespace ?? stream.assistantId;
|
|
73
100
|
const uiClient = stream.client["~ui"];
|
|
74
101
|
React.useEffect(() => {
|
|
@@ -90,7 +117,7 @@ export function LoadExternalComponent({ stream, namespace, message, meta, fallba
|
|
|
90
117
|
}
|
|
91
118
|
return (_jsxs(_Fragment, { children: [_jsx("div", { id: shadowRootId, ref: ref, ...props }), _jsx(UseStreamContext.Provider, { value: { stream, meta }, children: state?.target != null
|
|
92
119
|
? ReactDOM.createPortal(React.createElement(state.comp, message.props), state.target)
|
|
93
|
-
:
|
|
120
|
+
: fallbackComponent })] }));
|
|
94
121
|
}
|
|
95
122
|
export function experimental_loadShare(name, module) {
|
|
96
123
|
if (typeof window === "undefined")
|
|
@@ -100,8 +127,6 @@ export function experimental_loadShare(name, module) {
|
|
|
100
127
|
}
|
|
101
128
|
export function bootstrapUiContext() {
|
|
102
129
|
if (typeof window === "undefined") {
|
|
103
|
-
console.warn("Attempting to bootstrap UI context outside of browser environment. " +
|
|
104
|
-
"Avoid importing from `@langchain/langgraph-sdk/react-ui` in server context.");
|
|
105
130
|
return;
|
|
106
131
|
}
|
|
107
132
|
window[EXT_STORE_SYMBOL] = COMPONENT_STORE;
|
package/dist/react-ui/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uiMessageReducer = exports.experimental_loadShare = exports.LoadExternalComponent = exports.useStreamContext = void 0;
|
|
3
|
+
exports.isRemoveUIMessage = exports.isUIMessage = exports.uiMessageReducer = exports.experimental_loadShare = exports.LoadExternalComponent = exports.useStreamContext = void 0;
|
|
4
4
|
const client_js_1 = require("./client.cjs");
|
|
5
5
|
(0, client_js_1.bootstrapUiContext)();
|
|
6
6
|
var client_js_2 = require("./client.cjs");
|
|
@@ -9,3 +9,5 @@ Object.defineProperty(exports, "LoadExternalComponent", { enumerable: true, get:
|
|
|
9
9
|
Object.defineProperty(exports, "experimental_loadShare", { enumerable: true, get: function () { return client_js_2.experimental_loadShare; } });
|
|
10
10
|
var types_js_1 = require("./types.cjs");
|
|
11
11
|
Object.defineProperty(exports, "uiMessageReducer", { enumerable: true, get: function () { return types_js_1.uiMessageReducer; } });
|
|
12
|
+
Object.defineProperty(exports, "isUIMessage", { enumerable: true, get: function () { return types_js_1.isUIMessage; } });
|
|
13
|
+
Object.defineProperty(exports, "isRemoveUIMessage", { enumerable: true, get: function () { return types_js_1.isRemoveUIMessage; } });
|
package/dist/react-ui/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { useStreamContext, LoadExternalComponent, experimental_loadShare, } from "./client.js";
|
|
2
|
-
export { uiMessageReducer, type UIMessage, type RemoveUIMessage, } from "./types.js";
|
|
2
|
+
export { uiMessageReducer, isUIMessage, isRemoveUIMessage, type UIMessage, type RemoveUIMessage, } from "./types.js";
|
package/dist/react-ui/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { bootstrapUiContext } from "./client.js";
|
|
2
2
|
bootstrapUiContext();
|
|
3
3
|
export { useStreamContext, LoadExternalComponent, experimental_loadShare, } from "./client.js";
|
|
4
|
-
export { uiMessageReducer, } from "./types.js";
|
|
4
|
+
export { uiMessageReducer, isUIMessage, isRemoveUIMessage, } from "./types.js";
|
|
@@ -16,20 +16,17 @@ const typedUi = (config, options) => {
|
|
|
16
16
|
const runId = config.metadata?.run_id ?? config.runId;
|
|
17
17
|
if (!runId)
|
|
18
18
|
throw new Error("run_id is required");
|
|
19
|
-
|
|
20
|
-
...config.metadata,
|
|
21
|
-
tags: config.tags,
|
|
22
|
-
name: config.runName,
|
|
23
|
-
run_id: runId,
|
|
24
|
-
};
|
|
25
|
-
const handlePush = (message, options) => {
|
|
19
|
+
function handlePush(message, options) {
|
|
26
20
|
const evt = {
|
|
27
21
|
type: "ui",
|
|
28
22
|
id: message?.id ?? (0, uuid_1.v4)(),
|
|
29
23
|
name: message?.name,
|
|
30
24
|
props: message?.props,
|
|
31
25
|
metadata: {
|
|
32
|
-
|
|
26
|
+
merge: options?.merge || undefined,
|
|
27
|
+
run_id: runId,
|
|
28
|
+
tags: config.tags,
|
|
29
|
+
name: config.runName,
|
|
33
30
|
...message?.metadata,
|
|
34
31
|
...(options?.message ? { message_id: options.message.id } : null),
|
|
35
32
|
},
|
|
@@ -38,7 +35,7 @@ const typedUi = (config, options) => {
|
|
|
38
35
|
config.writer?.(evt);
|
|
39
36
|
config.configurable?.__pregel_send?.([[stateKey, evt]]);
|
|
40
37
|
return evt;
|
|
41
|
-
}
|
|
38
|
+
}
|
|
42
39
|
const handleDelete = (id) => {
|
|
43
40
|
const evt = { type: "remove-ui", id };
|
|
44
41
|
items.push(evt);
|
|
@@ -25,15 +25,27 @@ export declare const typedUi: <Decl extends Record<string, ElementType>>(config:
|
|
|
25
25
|
/** The key to write the UI messages to. Defaults to `ui`. */
|
|
26
26
|
stateKey?: string;
|
|
27
27
|
}) => {
|
|
28
|
-
push:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
push: {
|
|
29
|
+
<K extends keyof Decl & string>(message: {
|
|
30
|
+
id?: string | undefined;
|
|
31
|
+
name: K;
|
|
32
|
+
props: { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K];
|
|
33
|
+
metadata?: Record<string, unknown> | undefined;
|
|
34
|
+
}, options?: {
|
|
35
|
+
message?: MessageLike;
|
|
36
|
+
merge?: boolean;
|
|
37
|
+
}): UIMessage<K, { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K]>;
|
|
38
|
+
<K_2 extends keyof Decl & string>(message: {
|
|
39
|
+
id?: string | undefined;
|
|
40
|
+
name: K_2;
|
|
41
|
+
props: Partial<{ [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K_2]>;
|
|
42
|
+
metadata?: Record<string, unknown> | undefined;
|
|
43
|
+
}, options: {
|
|
44
|
+
message?: MessageLike;
|
|
45
|
+
merge: true;
|
|
46
|
+
}): UIMessage<K_2, Partial<{ [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K_2]>>;
|
|
47
|
+
};
|
|
36
48
|
delete: (id: string) => RemoveUIMessage;
|
|
37
|
-
items: (
|
|
49
|
+
items: (RemoveUIMessage | UIMessage<string, Record<string, unknown>>)[];
|
|
38
50
|
};
|
|
39
51
|
export {};
|
|
@@ -13,20 +13,17 @@ export const typedUi = (config, options) => {
|
|
|
13
13
|
const runId = config.metadata?.run_id ?? config.runId;
|
|
14
14
|
if (!runId)
|
|
15
15
|
throw new Error("run_id is required");
|
|
16
|
-
|
|
17
|
-
...config.metadata,
|
|
18
|
-
tags: config.tags,
|
|
19
|
-
name: config.runName,
|
|
20
|
-
run_id: runId,
|
|
21
|
-
};
|
|
22
|
-
const handlePush = (message, options) => {
|
|
16
|
+
function handlePush(message, options) {
|
|
23
17
|
const evt = {
|
|
24
18
|
type: "ui",
|
|
25
19
|
id: message?.id ?? uuidv4(),
|
|
26
20
|
name: message?.name,
|
|
27
21
|
props: message?.props,
|
|
28
22
|
metadata: {
|
|
29
|
-
|
|
23
|
+
merge: options?.merge || undefined,
|
|
24
|
+
run_id: runId,
|
|
25
|
+
tags: config.tags,
|
|
26
|
+
name: config.runName,
|
|
30
27
|
...message?.metadata,
|
|
31
28
|
...(options?.message ? { message_id: options.message.id } : null),
|
|
32
29
|
},
|
|
@@ -35,7 +32,7 @@ export const typedUi = (config, options) => {
|
|
|
35
32
|
config.writer?.(evt);
|
|
36
33
|
config.configurable?.__pregel_send?.([[stateKey, evt]]);
|
|
37
34
|
return evt;
|
|
38
|
-
}
|
|
35
|
+
}
|
|
39
36
|
const handleDelete = (id) => {
|
|
40
37
|
const evt = { type: "remove-ui", id };
|
|
41
38
|
items.push(evt);
|
package/dist/react-ui/types.cjs
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uiMessageReducer = void 0;
|
|
3
|
+
exports.uiMessageReducer = exports.isRemoveUIMessage = exports.isUIMessage = void 0;
|
|
4
|
+
function isUIMessage(message) {
|
|
5
|
+
if (typeof message !== "object" || message == null)
|
|
6
|
+
return false;
|
|
7
|
+
if (!("type" in message))
|
|
8
|
+
return false;
|
|
9
|
+
return message.type === "ui";
|
|
10
|
+
}
|
|
11
|
+
exports.isUIMessage = isUIMessage;
|
|
12
|
+
function isRemoveUIMessage(message) {
|
|
13
|
+
if (typeof message !== "object" || message == null)
|
|
14
|
+
return false;
|
|
15
|
+
if (!("type" in message))
|
|
16
|
+
return false;
|
|
17
|
+
return message.type === "remove-ui";
|
|
18
|
+
}
|
|
19
|
+
exports.isRemoveUIMessage = isRemoveUIMessage;
|
|
4
20
|
function uiMessageReducer(state, update) {
|
|
5
21
|
const events = Array.isArray(update) ? update : [update];
|
|
6
22
|
let newState = state.slice();
|
|
@@ -11,7 +27,9 @@ function uiMessageReducer(state, update) {
|
|
|
11
27
|
}
|
|
12
28
|
const index = state.findIndex((ui) => ui.id === event.id);
|
|
13
29
|
if (index !== -1) {
|
|
14
|
-
newState[index] = event
|
|
30
|
+
newState[index] = event.metadata.merge
|
|
31
|
+
? { ...event, props: { ...state[index].props, ...event.props } }
|
|
32
|
+
: event;
|
|
15
33
|
}
|
|
16
34
|
else {
|
|
17
35
|
newState.push(event);
|
package/dist/react-ui/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export interface UIMessage {
|
|
1
|
+
export interface UIMessage<TName extends string = string, TProps extends Record<string, unknown> = Record<string, unknown>> {
|
|
2
2
|
type: "ui";
|
|
3
3
|
id: string;
|
|
4
|
-
name:
|
|
5
|
-
props:
|
|
4
|
+
name: TName;
|
|
5
|
+
props: TProps;
|
|
6
6
|
metadata: {
|
|
7
|
-
|
|
7
|
+
merge?: boolean;
|
|
8
|
+
run_id?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
tags?: string[];
|
|
8
11
|
message_id?: string;
|
|
9
12
|
[key: string]: unknown;
|
|
10
13
|
};
|
|
@@ -13,4 +16,6 @@ export interface RemoveUIMessage {
|
|
|
13
16
|
type: "remove-ui";
|
|
14
17
|
id: string;
|
|
15
18
|
}
|
|
16
|
-
export declare function
|
|
19
|
+
export declare function isUIMessage(message: unknown): message is UIMessage;
|
|
20
|
+
export declare function isRemoveUIMessage(message: unknown): message is RemoveUIMessage;
|
|
21
|
+
export declare function uiMessageReducer(state: UIMessage[], update: UIMessage | RemoveUIMessage | (UIMessage | RemoveUIMessage)[]): UIMessage<string, Record<string, unknown>>[];
|
package/dist/react-ui/types.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
export function isUIMessage(message) {
|
|
2
|
+
if (typeof message !== "object" || message == null)
|
|
3
|
+
return false;
|
|
4
|
+
if (!("type" in message))
|
|
5
|
+
return false;
|
|
6
|
+
return message.type === "ui";
|
|
7
|
+
}
|
|
8
|
+
export function isRemoveUIMessage(message) {
|
|
9
|
+
if (typeof message !== "object" || message == null)
|
|
10
|
+
return false;
|
|
11
|
+
if (!("type" in message))
|
|
12
|
+
return false;
|
|
13
|
+
return message.type === "remove-ui";
|
|
14
|
+
}
|
|
1
15
|
export function uiMessageReducer(state, update) {
|
|
2
16
|
const events = Array.isArray(update) ? update : [update];
|
|
3
17
|
let newState = state.slice();
|
|
@@ -8,7 +22,9 @@ export function uiMessageReducer(state, update) {
|
|
|
8
22
|
}
|
|
9
23
|
const index = state.findIndex((ui) => ui.id === event.id);
|
|
10
24
|
if (index !== -1) {
|
|
11
|
-
newState[index] = event
|
|
25
|
+
newState[index] = event.metadata.merge
|
|
26
|
+
? { ...event, props: { ...state[index].props, ...event.props } }
|
|
27
|
+
: event;
|
|
12
28
|
}
|
|
13
29
|
else {
|
|
14
30
|
newState.push(event);
|
package/dist/types.stream.d.ts
CHANGED
|
@@ -120,7 +120,15 @@ export type SubgraphDebugStreamEvent = AsSubgraph<DebugStreamEvent>;
|
|
|
120
120
|
*/
|
|
121
121
|
export type EventsStreamEvent = {
|
|
122
122
|
event: "events";
|
|
123
|
-
data:
|
|
123
|
+
data: {
|
|
124
|
+
event: `on_${"chat_model" | "llm" | "chain" | "tool" | "retriever" | "prompt"}_${"start" | "stream" | "end"}` | (string & {});
|
|
125
|
+
name: string;
|
|
126
|
+
tags: string[];
|
|
127
|
+
run_id: string;
|
|
128
|
+
metadata: Record<string, unknown>;
|
|
129
|
+
parent_ids: string[];
|
|
130
|
+
data: unknown;
|
|
131
|
+
};
|
|
124
132
|
};
|
|
125
133
|
/** @internal */
|
|
126
134
|
export type SubgraphEventsStreamEvent = AsSubgraph<EventsStreamEvent>;
|