@langgraph-js/sdk 1.10.0 → 1.10.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { atom } from "nanostores";
|
|
2
2
|
import { LangGraphClient } from "../LangGraphClient.js";
|
|
3
|
-
import {
|
|
3
|
+
import { debounce } from "ts-debounce";
|
|
4
4
|
import { ToolRenderData } from "../tool/ToolUI.js";
|
|
5
5
|
/**
|
|
6
6
|
* @zh 格式化日期对象为时间字符串。
|
|
@@ -91,12 +91,12 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
91
91
|
if (showGraph.get())
|
|
92
92
|
graphVisualize.set((await ((_a = client.get()) === null || _a === void 0 ? void 0 : _a.graphVisualize())) || null);
|
|
93
93
|
};
|
|
94
|
-
const updateUI =
|
|
94
|
+
const updateUI = debounce((newClient) => {
|
|
95
95
|
const messages = newClient.renderMessage;
|
|
96
96
|
const lastMessage = messages[messages.length - 1];
|
|
97
97
|
currentNodeName.set((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.node_name) || (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.name) || "__start__");
|
|
98
98
|
renderMessages.set(messages);
|
|
99
|
-
});
|
|
99
|
+
}, 10);
|
|
100
100
|
/**
|
|
101
101
|
* @zh 初始化 LangGraph 客户端。
|
|
102
102
|
* @en Initializes the LangGraph client.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langgraph-js/sdk",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@langchain/langgraph-sdk": "^0.0.77",
|
|
33
33
|
"jsonrepair": "^3.12.0",
|
|
34
34
|
"nanostores": "^1.0.1",
|
|
35
|
+
"ts-debounce": "^4.0.0",
|
|
35
36
|
"zod": "^3.25.17",
|
|
36
37
|
"zod-to-json-schema": "^3.24.5"
|
|
37
38
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { atom, computed } from "nanostores";
|
|
2
2
|
import { LangGraphClient, LangGraphClientConfig, RenderMessage, SendMessageOptions } from "../LangGraphClient.js";
|
|
3
3
|
import { AssistantGraph, Message, Thread } from "@langchain/langgraph-sdk";
|
|
4
|
-
import {
|
|
4
|
+
import { debounce } from "ts-debounce";
|
|
5
5
|
import { ToolRenderData } from "../tool/ToolUI.js";
|
|
6
6
|
import { UnionTool } from "../tool/createTool.js";
|
|
7
7
|
|
|
@@ -97,14 +97,14 @@ export const createChatStore = (
|
|
|
97
97
|
const refreshGraph = async () => {
|
|
98
98
|
if (showGraph.get()) graphVisualize.set((await client.get()?.graphVisualize()) || null);
|
|
99
99
|
};
|
|
100
|
-
const updateUI =
|
|
100
|
+
const updateUI = debounce((newClient: LangGraphClient) => {
|
|
101
101
|
const messages = newClient.renderMessage;
|
|
102
102
|
const lastMessage = messages[messages.length - 1];
|
|
103
103
|
|
|
104
104
|
currentNodeName.set(lastMessage?.node_name || lastMessage?.name || "__start__");
|
|
105
105
|
|
|
106
106
|
renderMessages.set(messages);
|
|
107
|
-
});
|
|
107
|
+
}, 10);
|
|
108
108
|
/**
|
|
109
109
|
* @zh 初始化 LangGraph 客户端。
|
|
110
110
|
* @en Initializes the LangGraph client.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a debounced function that executes once per animation frame
|
|
3
|
-
* @param callback - The function to debounce
|
|
4
|
-
* @returns A function that executes the callback on the next animation frame
|
|
5
|
-
*/
|
|
6
|
-
export function rafDebounce<T extends (...args: any[]) => any>(callback: T): (...args: Parameters<T>) => void {
|
|
7
|
-
let rafId: number | null = null;
|
|
8
|
-
let lastArgs: Parameters<T> | null = null;
|
|
9
|
-
|
|
10
|
-
// Return the debounced function
|
|
11
|
-
return function (...args: Parameters<T>): void {
|
|
12
|
-
// Store the most recent arguments
|
|
13
|
-
lastArgs = args;
|
|
14
|
-
|
|
15
|
-
// Cancel any pending animation frame
|
|
16
|
-
if (rafId !== null) {
|
|
17
|
-
cancelAnimationFrame(rafId);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Schedule execution on the next animation frame
|
|
21
|
-
rafId = requestAnimationFrame(() => {
|
|
22
|
-
if (lastArgs !== null) {
|
|
23
|
-
callback(...lastArgs);
|
|
24
|
-
lastArgs = null;
|
|
25
|
-
}
|
|
26
|
-
rafId = null;
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|