@langgraph-js/sdk 3.7.0 → 3.8.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/README.md +29 -0
- package/dist/History.d.ts +115 -0
- package/dist/History.js +226 -0
- package/dist/LangGraphClient.d.ts +23 -2
- package/dist/LangGraphClient.js +118 -80
- package/dist/MessageProcessor.js +18 -24
- package/dist/SpendTime.js +4 -9
- package/dist/TestKit.d.ts +1 -1
- package/dist/TestKit.js +16 -15
- package/dist/ToolManager.js +4 -7
- package/dist/artifacts/index.js +1 -1
- package/dist/client/LanggraphServer.js +1 -1
- package/dist/client/LowJSServer.d.ts +3 -0
- package/dist/client/LowJSServer.js +80 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/utils/sse.d.ts +8 -0
- package/dist/client/utils/sse.js +151 -0
- package/dist/client/utils/stream.d.ts +15 -0
- package/dist/client/utils/stream.js +104 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/react/ChatContext.d.ts +31 -20
- package/dist/react/ChatContext.js +10 -4
- package/dist/tool/ToolUI.js +3 -2
- package/dist/tool/createTool.js +3 -6
- package/dist/tool/utils.js +3 -4
- package/dist/ui-store/createChatStore.d.ts +33 -66
- package/dist/ui-store/createChatStore.js +261 -247
- package/dist/vue/ChatContext.d.ts +41 -21
- package/dist/vue/ChatContext.js +8 -2
- package/package.json +3 -1
- package/src/History.ts +294 -0
- package/src/LangGraphClient.ts +98 -48
- package/src/client/LanggraphServer.ts +1 -2
- package/src/client/LowJSServer.ts +80 -0
- package/src/client/index.ts +2 -0
- package/src/client/utils/sse.ts +176 -0
- package/src/client/utils/stream.ts +114 -0
- package/src/index.ts +2 -0
- package/src/react/ChatContext.ts +25 -16
- package/src/ui-store/createChatStore.ts +310 -236
- package/src/vue/ChatContext.ts +12 -0
- package/test/TestKit.test.ts +10 -2
- package/tsconfig.json +1 -1
|
@@ -2,109 +2,76 @@ import { LangGraphClient, LangGraphClientConfig, RenderMessage, SendMessageOptio
|
|
|
2
2
|
import { AssistantGraph, Message, Thread } from "@langchain/langgraph-sdk";
|
|
3
3
|
import { UnionTool } from "../tool/createTool.js";
|
|
4
4
|
import { RevertChatToOptions } from "../time-travel/index.js";
|
|
5
|
-
|
|
6
|
-
* @zh 格式化日期对象为时间字符串。
|
|
7
|
-
* @en Formats a Date object into a time string.
|
|
8
|
-
*/
|
|
5
|
+
import { History, SessionInfo } from "../History.js";
|
|
9
6
|
export declare const formatTime: (date: Date) => string;
|
|
10
|
-
/**
|
|
11
|
-
* @zh 格式化数字为带千位分隔符的字符串。
|
|
12
|
-
* @en Formats a number into a string with thousand separators.
|
|
13
|
-
*/
|
|
14
7
|
export declare const formatTokens: (tokens: number) => string;
|
|
15
|
-
/**
|
|
16
|
-
* @zh 获取消息内容的文本表示,处理不同类型的消息内容。
|
|
17
|
-
* @en Gets the text representation of message content, handling different types of message content.
|
|
18
|
-
*/
|
|
19
8
|
export declare const getMessageContent: (content: any) => string;
|
|
20
|
-
/**
|
|
21
|
-
* @zh 获取历史记录中 Thread 内容的文本表示。
|
|
22
|
-
* @en Gets the text representation of Thread content in history.
|
|
23
|
-
*/
|
|
24
9
|
export declare const getHistoryContent: (thread: Thread) => string | any[];
|
|
25
|
-
|
|
26
|
-
* @zh 创建一个用于聊天界面的状态管理器 (store)。
|
|
27
|
-
* @en Creates a state manager (store) for the chat interface.
|
|
28
|
-
*/
|
|
29
|
-
export declare const createChatStore: (initClientName: string, config: Partial<LangGraphClientConfig>, context?: {
|
|
10
|
+
interface ChatStoreContext {
|
|
30
11
|
showHistory?: boolean;
|
|
31
12
|
showGraph?: boolean;
|
|
32
13
|
fallbackToAvailableAssistants?: boolean;
|
|
33
14
|
onInit?: (client: LangGraphClient) => void;
|
|
34
|
-
|
|
15
|
+
/** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
|
|
16
|
+
autoRestoreLastSession?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const createChatStore: (initClientName: string, config: Partial<LangGraphClientConfig>, context?: ChatStoreContext) => {
|
|
35
19
|
data: {
|
|
36
20
|
artifacts: import("nanostores").PreinitializedWritableAtom<import("../artifacts/index.js").ComposedArtifact[]> & object;
|
|
37
21
|
currentArtifactId: import("nanostores").PreinitializedWritableAtom<[string, string] | null> & object;
|
|
38
22
|
showArtifact: import("nanostores").PreinitializedWritableAtom<boolean> & object;
|
|
39
23
|
client: import("nanostores").PreinitializedWritableAtom<LangGraphClient<unknown> | null> & object;
|
|
24
|
+
history: import("nanostores").PreinitializedWritableAtom<History | null> & object;
|
|
25
|
+
sessions: import("nanostores").PreinitializedWritableAtom<SessionInfo[]> & object;
|
|
40
26
|
renderMessages: import("nanostores").PreinitializedWritableAtom<RenderMessage[]> & object;
|
|
41
27
|
userInput: import("nanostores").PreinitializedWritableAtom<string> & object;
|
|
42
28
|
loading: import("nanostores").PreinitializedWritableAtom<boolean> & object;
|
|
43
29
|
inChatError: import("nanostores").PreinitializedWritableAtom<string | null> & object;
|
|
44
30
|
currentAgent: import("nanostores").PreinitializedWritableAtom<string> & object;
|
|
31
|
+
currentChatId: import("nanostores").PreinitializedWritableAtom<string | null> & object;
|
|
32
|
+
currentNodeName: import("nanostores").PreinitializedWritableAtom<string> & object;
|
|
33
|
+
tools: import("nanostores").PreinitializedWritableAtom<UnionTool<any, Object, any>[]> & object;
|
|
45
34
|
collapsedTools: import("nanostores").PreinitializedWritableAtom<string[]> & object;
|
|
35
|
+
showGraph: import("nanostores").PreinitializedWritableAtom<boolean> & object;
|
|
36
|
+
graphVisualize: import("nanostores").PreinitializedWritableAtom<AssistantGraph | null> & object;
|
|
46
37
|
showHistory: import("nanostores").PreinitializedWritableAtom<boolean> & object;
|
|
47
38
|
historyList: import("nanostores").PreinitializedWritableAtom<Thread<{
|
|
48
39
|
messages: Message[];
|
|
49
40
|
}>[]> & object;
|
|
50
|
-
currentChatId: import("nanostores").PreinitializedWritableAtom<string | null> & object;
|
|
51
|
-
showGraph: import("nanostores").PreinitializedWritableAtom<boolean> & object;
|
|
52
|
-
graphVisualize: import("nanostores").PreinitializedWritableAtom<AssistantGraph | null> & object;
|
|
53
|
-
currentNodeName: import("nanostores").PreinitializedWritableAtom<string> & object;
|
|
54
|
-
tools: import("nanostores").PreinitializedWritableAtom<UnionTool<any, Object, any>[]> & object;
|
|
55
41
|
};
|
|
56
42
|
mutations: {
|
|
57
43
|
setCurrentArtifactById: (id: string, tool_id: string) => void;
|
|
58
44
|
setShowArtifact: (show: boolean) => void;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
initClient: () => Promise<History>;
|
|
46
|
+
getClient: () => LangGraphClient<unknown> | null;
|
|
47
|
+
getHistory: () => History | null;
|
|
48
|
+
activateSession: (sessionId: string) => Promise<void>;
|
|
49
|
+
createNewSession: () => Promise<void>;
|
|
50
|
+
refreshSessionList: () => Promise<void>;
|
|
51
|
+
refreshHistoryList: () => Promise<void>;
|
|
64
52
|
sendMessage: (message?: Message[], extraData?: SendMessageOptions, withoutCheck?: boolean) => Promise<void>;
|
|
65
53
|
stopGeneration: () => void;
|
|
54
|
+
setUserInput: (input: string) => void;
|
|
55
|
+
revertChatTo(messageId: string, resend?: boolean, sendOptions?: SendMessageOptions & RevertChatToOptions): Promise<void>;
|
|
56
|
+
refreshTools: () => Promise<void>;
|
|
57
|
+
setTools(new_tools: UnionTool<any>[]): void;
|
|
66
58
|
toggleToolCollapse: (toolId: string) => void;
|
|
59
|
+
getToolUIRender: (tool_name: string) => ((message: RenderMessage) => Object) | null;
|
|
60
|
+
isFELocking: () => boolean | undefined;
|
|
67
61
|
toggleHistoryVisible: () => void;
|
|
68
|
-
|
|
62
|
+
toggleGraphVisible(): void;
|
|
63
|
+
refreshGraph: () => Promise<void>;
|
|
64
|
+
setCurrentAgent(agent: string): Promise<History>;
|
|
69
65
|
addToHistory: (thread: Thread<{
|
|
70
66
|
messages: Message[];
|
|
71
67
|
}>) => void;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* @en Reverts to the specified message.
|
|
75
|
-
*/
|
|
76
|
-
revertChatTo(messageId: string, resend?: boolean, sendOptions?: SendMessageOptions & RevertChatToOptions): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
* @zh 设置用户输入内容。
|
|
79
|
-
* @en Sets the user input content.
|
|
80
|
-
*/
|
|
81
|
-
setUserInput(input: string): void;
|
|
82
|
-
/**
|
|
83
|
-
* @zh 设置当前的 Agent 并重新初始化客户端。
|
|
84
|
-
* @en Sets the current Agent and reinitializes the client.
|
|
85
|
-
*/
|
|
86
|
-
setCurrentAgent(agent: string): Promise<void>;
|
|
87
|
-
toggleGraphVisible(): void;
|
|
88
|
-
refreshGraph: () => Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* @zh 创建一个新的聊天会话。
|
|
91
|
-
* @en Creates a new chat session.
|
|
92
|
-
*/
|
|
93
|
-
createNewChat(): void;
|
|
94
|
-
/**
|
|
95
|
-
* @zh 切换到指定的历史聊天会话。
|
|
96
|
-
* @en Switches to the specified historical chat session.
|
|
97
|
-
*/
|
|
98
|
-
toHistoryChat(thread: Thread<{
|
|
68
|
+
createNewChat: () => Promise<void>;
|
|
69
|
+
toHistoryChat: (thread: Thread<{
|
|
99
70
|
messages: Message[];
|
|
100
|
-
}>)
|
|
101
|
-
/**
|
|
102
|
-
* @zh 删除指定的历史聊天会话。
|
|
103
|
-
* @en Deletes the specified historical chat session.
|
|
104
|
-
*/
|
|
71
|
+
}>) => Promise<void>;
|
|
105
72
|
deleteHistoryChat(thread: Thread<{
|
|
106
73
|
messages: Message[];
|
|
107
74
|
}>): Promise<void>;
|
|
108
|
-
getToolUIRender: (tool_name: string) => ((message: RenderMessage) => Object) | null;
|
|
109
75
|
};
|
|
110
76
|
};
|
|
77
|
+
export {};
|