@langgraph-js/sdk 3.5.2 → 3.7.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/LangGraphClient.d.ts +3 -5
- package/dist/LangGraphClient.js +2 -2
- package/dist/MessageProcessor.js +7 -10
- package/dist/react/ChatContext.d.ts +1 -1
- package/dist/time-travel/index.d.ts +4 -1
- package/dist/time-travel/index.js +4 -3
- package/dist/ui-store/createChatStore.d.ts +2 -1
- package/dist/ui-store/createChatStore.js +1 -1
- package/dist/vue/ChatContext.d.ts +1 -1
- package/package.json +1 -1
- package/src/LangGraphClient.ts +3 -3
- package/src/MessageProcessor.ts +7 -9
- package/src/time-travel/index.ts +8 -3
- package/src/ui-store/createChatStore.ts +3 -2
|
@@ -3,6 +3,7 @@ import { EventEmitter } from "eventemitter3";
|
|
|
3
3
|
import { ToolManager } from "./ToolManager.js";
|
|
4
4
|
import { CallToolResult } from "./tool/createTool.js";
|
|
5
5
|
import { type ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
|
|
6
|
+
import { RevertChatToOptions } from "./time-travel/index.js";
|
|
6
7
|
export type RenderMessage = Message & {
|
|
7
8
|
/** 对于 AIMessage 来说是节点名称,对于工具节点来说是工具名称 */
|
|
8
9
|
name?: string;
|
|
@@ -143,10 +144,7 @@ export declare class LangGraphClient<TStateType = unknown> extends EventEmitter<
|
|
|
143
144
|
metadata?: import("@langchain/langgraph-sdk").Metadata;
|
|
144
145
|
limit?: number;
|
|
145
146
|
offset?: number;
|
|
146
|
-
sortBy
|
|
147
|
-
* The maximum number of retries that can be made for a single call,
|
|
148
|
-
* with an exponential backoff between each attempt. Defaults to 6.
|
|
149
|
-
*/: import("@langgraph-js/pure-graph/dist/types.js").AssistantSortBy;
|
|
147
|
+
sortBy?: import("@langgraph-js/pure-graph/dist/types.js").AssistantSortBy;
|
|
150
148
|
sortOrder?: import("@langgraph-js/pure-graph/dist/types.js").SortOrder;
|
|
151
149
|
}): Promise<Assistant[]>;
|
|
152
150
|
getGraph(assistantId: string, options?: {
|
|
@@ -230,7 +228,7 @@ export declare class LangGraphClient<TStateType = unknown> extends EventEmitter<
|
|
|
230
228
|
* @zh 回滚到指定的消息。但是不会触发数据的重新更新
|
|
231
229
|
* @en Reverts to the specified message.
|
|
232
230
|
*/
|
|
233
|
-
revertChatTo(messageId: string): Promise<{
|
|
231
|
+
revertChatTo(messageId: string, options: RevertChatToOptions): Promise<{
|
|
234
232
|
messages: Message[];
|
|
235
233
|
}>;
|
|
236
234
|
messagesMetadata: {};
|
package/dist/LangGraphClient.js
CHANGED
|
@@ -197,8 +197,8 @@ export class LangGraphClient extends EventEmitter {
|
|
|
197
197
|
* @zh 回滚到指定的消息。但是不会触发数据的重新更新
|
|
198
198
|
* @en Reverts to the specified message.
|
|
199
199
|
*/
|
|
200
|
-
async revertChatTo(messageId) {
|
|
201
|
-
const { state, checkpoint } = await revertChatTo(this.client, this.currentThread.thread_id, messageId);
|
|
200
|
+
async revertChatTo(messageId, options) {
|
|
201
|
+
const { state, checkpoint } = await revertChatTo(this.client, this.currentThread.thread_id, messageId, options);
|
|
202
202
|
this.graphState = state;
|
|
203
203
|
this.messageProcessor.clearStreamingMessages();
|
|
204
204
|
this.messageProcessor.setGraphMessages(state.messages);
|
package/dist/MessageProcessor.js
CHANGED
|
@@ -145,16 +145,13 @@ export class MessageProcessor {
|
|
|
145
145
|
const parentMessage = toolParentMessage.get(message.tool_call_id);
|
|
146
146
|
if (assistantToolMessage) {
|
|
147
147
|
message.tool_input = typeof assistantToolMessage.args !== "string" ? JSON.stringify(assistantToolMessage.args) : assistantToolMessage.args;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
done: true,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
148
|
+
const isDone = !!message.content;
|
|
149
|
+
message.done = isDone;
|
|
150
|
+
message.additional_kwargs = {
|
|
151
|
+
...((parentMessage === null || parentMessage === void 0 ? void 0 : parentMessage.additional_kwargs) || {}),
|
|
152
|
+
...(message.additional_kwargs || {}),
|
|
153
|
+
done: isDone,
|
|
154
|
+
};
|
|
158
155
|
}
|
|
159
156
|
if (parentMessage) {
|
|
160
157
|
message.usage_metadata = parentMessage.usage_metadata;
|
|
@@ -38,7 +38,7 @@ export declare const useChat: () => UnionStore<{
|
|
|
38
38
|
addToHistory: (thread: import("@langchain/langgraph-sdk").Thread<{
|
|
39
39
|
messages: import("@langchain/langgraph-sdk").Message[];
|
|
40
40
|
}>) => void;
|
|
41
|
-
revertChatTo(messageId: string, resend?: boolean, sendOptions?: import("../LangGraphClient.js").SendMessageOptions): Promise<void>;
|
|
41
|
+
revertChatTo(messageId: string, resend?: boolean, sendOptions?: import("../LangGraphClient.js").SendMessageOptions & import("../time-travel/index.js").RevertChatToOptions): Promise<void>;
|
|
42
42
|
setUserInput(input: string): void;
|
|
43
43
|
setCurrentAgent(agent: string): Promise<void>;
|
|
44
44
|
toggleGraphVisible(): void;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Client, Message } from "@langchain/langgraph-sdk";
|
|
2
|
+
export interface RevertChatToOptions {
|
|
3
|
+
includeMessageId?: boolean;
|
|
4
|
+
}
|
|
2
5
|
export declare function revertChatTo(client: Client<{
|
|
3
6
|
messages: Message[];
|
|
4
7
|
}, {
|
|
5
8
|
messages: Message[];
|
|
6
|
-
}, unknown>, threadId: string, messageId: string): Promise<{
|
|
9
|
+
}, unknown>, threadId: string, messageId: string, options: RevertChatToOptions): Promise<{
|
|
7
10
|
state: {
|
|
8
11
|
messages: Message[];
|
|
9
12
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export async function revertChatTo(client, threadId, messageId) {
|
|
1
|
+
export async function revertChatTo(client, threadId, messageId, options) {
|
|
2
2
|
const thread = await client.threads.get(threadId);
|
|
3
3
|
const messages = thread.values.messages;
|
|
4
4
|
const idx = messages.findIndex((message) => message.id === messageId);
|
|
5
5
|
if (idx === -1) {
|
|
6
6
|
throw new Error(`Message id ${messageId} not found`);
|
|
7
7
|
}
|
|
8
|
-
const
|
|
8
|
+
const removeStartIdx = options.includeMessageId ? idx : idx + 1;
|
|
9
|
+
const removeMessages = messages.slice(removeStartIdx);
|
|
9
10
|
const state = {
|
|
10
11
|
...thread.values,
|
|
11
12
|
messages: removeMessages.map((i) => {
|
|
@@ -23,7 +24,7 @@ export async function revertChatTo(client, threadId, messageId) {
|
|
|
23
24
|
// client.runs.wait();
|
|
24
25
|
return {
|
|
25
26
|
state: {
|
|
26
|
-
messages: messages.slice(0,
|
|
27
|
+
messages: messages.slice(0, removeStartIdx),
|
|
27
28
|
},
|
|
28
29
|
checkpoint: res,
|
|
29
30
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LangGraphClient, LangGraphClientConfig, RenderMessage, SendMessageOptions } from "../LangGraphClient.js";
|
|
2
2
|
import { AssistantGraph, Message, Thread } from "@langchain/langgraph-sdk";
|
|
3
3
|
import { UnionTool } from "../tool/createTool.js";
|
|
4
|
+
import { RevertChatToOptions } from "../time-travel/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* @zh 格式化日期对象为时间字符串。
|
|
6
7
|
* @en Formats a Date object into a time string.
|
|
@@ -72,7 +73,7 @@ export declare const createChatStore: (initClientName: string, config: Partial<L
|
|
|
72
73
|
* @zh 回滚到指定的消息。
|
|
73
74
|
* @en Reverts to the specified message.
|
|
74
75
|
*/
|
|
75
|
-
revertChatTo(messageId: string, resend?: boolean, sendOptions?: SendMessageOptions): Promise<void>;
|
|
76
|
+
revertChatTo(messageId: string, resend?: boolean, sendOptions?: SendMessageOptions & RevertChatToOptions): Promise<void>;
|
|
76
77
|
/**
|
|
77
78
|
* @zh 设置用户输入内容。
|
|
78
79
|
* @en Sets the user input content.
|
|
@@ -285,7 +285,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
285
285
|
*/
|
|
286
286
|
async revertChatTo(messageId, resend = false, sendOptions) {
|
|
287
287
|
var _a;
|
|
288
|
-
await ((_a = client.get()) === null || _a === void 0 ? void 0 : _a.revertChatTo(messageId));
|
|
288
|
+
await ((_a = client.get()) === null || _a === void 0 ? void 0 : _a.revertChatTo(messageId, sendOptions || {}));
|
|
289
289
|
if (resend) {
|
|
290
290
|
return sendMessage([], sendOptions, true);
|
|
291
291
|
}
|
|
@@ -77,7 +77,7 @@ export declare const useChatProvider: (props: ChatProviderProps) => {
|
|
|
77
77
|
addToHistory: (thread: import("@langchain/langgraph-sdk").Thread<{
|
|
78
78
|
messages: import("@langchain/langgraph-sdk").Message[];
|
|
79
79
|
}>) => void;
|
|
80
|
-
revertChatTo(messageId: string, resend?: boolean, sendOptions?: import("../LangGraphClient.js").SendMessageOptions): Promise<void>;
|
|
80
|
+
revertChatTo(messageId: string, resend?: boolean, sendOptions?: import("../LangGraphClient.js").SendMessageOptions & import("../time-travel/index.js").RevertChatToOptions): Promise<void>;
|
|
81
81
|
setUserInput(input: string): void;
|
|
82
82
|
setCurrentAgent(agent: string): Promise<void>;
|
|
83
83
|
toggleGraphVisible(): void;
|
package/package.json
CHANGED
package/src/LangGraphClient.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ToolManager } from "./ToolManager.js";
|
|
|
4
4
|
import { CallToolResult } from "./tool/createTool.js";
|
|
5
5
|
import { type ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
|
|
6
6
|
import { MessageProcessor } from "./MessageProcessor.js";
|
|
7
|
-
import { revertChatTo } from "./time-travel/index.js";
|
|
7
|
+
import { revertChatTo, RevertChatToOptions } from "./time-travel/index.js";
|
|
8
8
|
|
|
9
9
|
export type RenderMessage = Message & {
|
|
10
10
|
/** 对于 AIMessage 来说是节点名称,对于工具节点来说是工具名称 */
|
|
@@ -310,8 +310,8 @@ export class LangGraphClient<TStateType = unknown> extends EventEmitter<LangGrap
|
|
|
310
310
|
* @zh 回滚到指定的消息。但是不会触发数据的重新更新
|
|
311
311
|
* @en Reverts to the specified message.
|
|
312
312
|
*/
|
|
313
|
-
async revertChatTo(messageId: string) {
|
|
314
|
-
const { state, checkpoint } = await revertChatTo(this.client as any, this.currentThread!.thread_id, messageId);
|
|
313
|
+
async revertChatTo(messageId: string, options: RevertChatToOptions) {
|
|
314
|
+
const { state, checkpoint } = await revertChatTo(this.client as any, this.currentThread!.thread_id, messageId, options);
|
|
315
315
|
this.graphState = state;
|
|
316
316
|
this.messageProcessor.clearStreamingMessages();
|
|
317
317
|
this.messageProcessor.setGraphMessages(state.messages! as RenderMessage[]);
|
package/src/MessageProcessor.ts
CHANGED
|
@@ -164,15 +164,13 @@ export class MessageProcessor {
|
|
|
164
164
|
const parentMessage = toolParentMessage.get(message.tool_call_id!);
|
|
165
165
|
if (assistantToolMessage) {
|
|
166
166
|
message.tool_input = typeof assistantToolMessage.args !== "string" ? JSON.stringify(assistantToolMessage.args) : assistantToolMessage.args;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
message.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
};
|
|
175
|
-
}
|
|
167
|
+
const isDone = !!message.content;
|
|
168
|
+
message.done = isDone;
|
|
169
|
+
message.additional_kwargs = {
|
|
170
|
+
...(parentMessage?.additional_kwargs || {}),
|
|
171
|
+
...(message.additional_kwargs || {}),
|
|
172
|
+
done: isDone,
|
|
173
|
+
};
|
|
176
174
|
}
|
|
177
175
|
if (parentMessage) {
|
|
178
176
|
message.usage_metadata = parentMessage.usage_metadata;
|
package/src/time-travel/index.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { Client, Message } from "@langchain/langgraph-sdk";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface RevertChatToOptions {
|
|
4
|
+
includeMessageId?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function revertChatTo(client: Client<{ messages: Message[] }, { messages: Message[] }, unknown>, threadId: string, messageId: string, options: RevertChatToOptions) {
|
|
4
8
|
const thread = await client.threads.get(threadId);
|
|
5
9
|
const messages = thread.values.messages;
|
|
6
10
|
const idx = messages.findIndex((message) => message.id === messageId);
|
|
7
11
|
if (idx === -1) {
|
|
8
12
|
throw new Error(`Message id ${messageId} not found`);
|
|
9
13
|
}
|
|
10
|
-
const
|
|
14
|
+
const removeStartIdx = options.includeMessageId ? idx : idx + 1;
|
|
15
|
+
const removeMessages = messages.slice(removeStartIdx);
|
|
11
16
|
const state = {
|
|
12
17
|
...thread.values,
|
|
13
18
|
messages: removeMessages.map((i) => {
|
|
@@ -25,7 +30,7 @@ export async function revertChatTo(client: Client<{ messages: Message[] }, { mes
|
|
|
25
30
|
// client.runs.wait();
|
|
26
31
|
return {
|
|
27
32
|
state: {
|
|
28
|
-
messages: messages.slice(0,
|
|
33
|
+
messages: messages.slice(0, removeStartIdx),
|
|
29
34
|
},
|
|
30
35
|
checkpoint: res,
|
|
31
36
|
};
|
|
@@ -6,6 +6,7 @@ import { ToolRenderData } from "../tool/ToolUI.js";
|
|
|
6
6
|
import { UnionTool } from "../tool/createTool.js";
|
|
7
7
|
import { createLangGraphServerClient } from "../client/LanggraphServer.js";
|
|
8
8
|
import { useArtifacts } from "../artifacts/index.js";
|
|
9
|
+
import { RevertChatToOptions } from "../time-travel/index.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @zh 格式化日期对象为时间字符串。
|
|
@@ -290,8 +291,8 @@ export const createChatStore = (
|
|
|
290
291
|
* @zh 回滚到指定的消息。
|
|
291
292
|
* @en Reverts to the specified message.
|
|
292
293
|
*/
|
|
293
|
-
async revertChatTo(messageId: string, resend = false, sendOptions?: SendMessageOptions) {
|
|
294
|
-
await client.get()?.revertChatTo(messageId);
|
|
294
|
+
async revertChatTo(messageId: string, resend = false, sendOptions?: SendMessageOptions & RevertChatToOptions) {
|
|
295
|
+
await client.get()?.revertChatTo(messageId, sendOptions || {});
|
|
295
296
|
if (resend) {
|
|
296
297
|
return sendMessage([], sendOptions, true);
|
|
297
298
|
} else {
|