@langgraph-js/sdk 1.10.0 → 1.10.2

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/TestKit.d.ts CHANGED
@@ -66,11 +66,12 @@ export declare class TestLangGraphChat {
66
66
  checkAllTask(messages: readonly RenderMessage[], options?: {
67
67
  skipLengthCheck?: boolean;
68
68
  }): void;
69
+ private readited;
69
70
  /**
70
71
  * @zh 准备测试环境,初始化客户端连接
71
72
  * @en Prepare test environment, initialize client connection
72
73
  */
73
- ready(): Promise<import("./LangGraphClient.js").LangGraphClient>;
74
+ ready(): Promise<import("./LangGraphClient.js").LangGraphClient> | undefined;
74
75
  /**
75
76
  * @zh 模拟人类输入消息并等待测试任务完成,这是测试的核心方法
76
77
  * @en Simulate human input and wait for test tasks to complete, this is the core test method
package/dist/TestKit.js CHANGED
@@ -26,6 +26,7 @@ export class TestLangGraphChat {
26
26
  this.lastLength = 0;
27
27
  /** 待处理的测试任务列表 */
28
28
  this.processFunc = [];
29
+ this.readited = false;
29
30
  this.debug = (_a = options.debug) !== null && _a !== void 0 ? _a : false;
30
31
  options.tools && this.addTools(options.tools);
31
32
  const renderMessages = this.store.data.renderMessages;
@@ -92,6 +93,10 @@ export class TestLangGraphChat {
92
93
  * @en Prepare test environment, initialize client connection
93
94
  */
94
95
  ready() {
96
+ if (this.readited) {
97
+ return;
98
+ }
99
+ this.readited = true;
95
100
  return this.store.mutations.initClient();
96
101
  }
97
102
  /**
@@ -121,7 +126,9 @@ export class TestLangGraphChat {
121
126
  content: text,
122
127
  },
123
128
  ])
124
- .then(() => {
129
+ .then(async () => {
130
+ // messages 有 10 ms 的 debounce,我们需要稍等一下
131
+ await new Promise((resolve) => setTimeout(resolve, 20));
125
132
  this.checkAllTask(this.getMessages(), {
126
133
  skipLengthCheck: true,
127
134
  });
@@ -1,6 +1,6 @@
1
1
  import { atom } from "nanostores";
2
2
  import { LangGraphClient } from "../LangGraphClient.js";
3
- import { rafDebounce } from "./rafDebounce.js";
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 = rafDebounce((newClient) => {
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.0",
3
+ "version": "1.10.2",
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
  },
package/src/TestKit.ts CHANGED
@@ -117,11 +117,16 @@ export class TestLangGraphChat {
117
117
  }
118
118
  }
119
119
 
120
+ private readited = false
120
121
  /**
121
122
  * @zh 准备测试环境,初始化客户端连接
122
123
  * @en Prepare test environment, initialize client connection
123
124
  */
124
125
  ready() {
126
+ if (this.readited) {
127
+ return
128
+ }
129
+ this.readited = true
125
130
  return this.store.mutations.initClient();
126
131
  }
127
132
 
@@ -152,7 +157,9 @@ export class TestLangGraphChat {
152
157
  content: text,
153
158
  },
154
159
  ])
155
- .then(() => {
160
+ .then(async () => {
161
+ // messages 有 10 ms 的 debounce,我们需要稍等一下
162
+ await new Promise((resolve) => setTimeout(resolve, 20));
156
163
  this.checkAllTask(this.getMessages(), {
157
164
  skipLengthCheck: true,
158
165
  });
@@ -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 { rafDebounce } from "./rafDebounce.js";
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 = rafDebounce((newClient: LangGraphClient) => {
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
- }