@langgraph-js/sdk 1.1.9 → 1.2.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.
|
@@ -100,6 +100,7 @@ export declare class LangGraphClient extends Client {
|
|
|
100
100
|
createThread({ threadId, }?: {
|
|
101
101
|
threadId?: string;
|
|
102
102
|
}): Promise<Thread<import("@langchain/langgraph-sdk").DefaultValues>>;
|
|
103
|
+
graphVisualize(): Promise<import("@langchain/langgraph-sdk").AssistantGraph>;
|
|
103
104
|
/**
|
|
104
105
|
* @zh 列出所有的 Thread。
|
|
105
106
|
* @en Lists all Threads.
|
package/dist/LangGraphClient.js
CHANGED
|
@@ -90,6 +90,12 @@ export class LangGraphClient extends Client {
|
|
|
90
90
|
throw error;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
graphVisualize() {
|
|
94
|
+
var _a;
|
|
95
|
+
return this.assistants.getGraph((_a = this.currentAssistant) === null || _a === void 0 ? void 0 : _a.assistant_id, {
|
|
96
|
+
xray: true,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
93
99
|
/**
|
|
94
100
|
* @zh 列出所有的 Thread。
|
|
95
101
|
* @en Lists all Threads.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LangGraphClient, LangGraphClientConfig, RenderMessage, SendMessageOptions } from "../LangGraphClient.js";
|
|
2
|
-
import { Message, Thread } from "@langchain/langgraph-sdk";
|
|
2
|
+
import { AssistantGraph, Message, Thread } from "@langchain/langgraph-sdk";
|
|
3
3
|
/**
|
|
4
4
|
* @zh 格式化日期对象为时间字符串。
|
|
5
5
|
* @en Formats a Date object into a time string.
|
|
@@ -25,6 +25,8 @@ export declare const getHistoryContent: (thread: Thread) => string | any[];
|
|
|
25
25
|
* @en Creates a state manager (store) for the chat interface.
|
|
26
26
|
*/
|
|
27
27
|
export declare const createChatStore: (initClientName: string, config: LangGraphClientConfig, context?: {
|
|
28
|
+
showHistory?: boolean;
|
|
29
|
+
showGraph?: boolean;
|
|
28
30
|
onInit?: (client: LangGraphClient) => void;
|
|
29
31
|
}) => {
|
|
30
32
|
data: {
|
|
@@ -40,9 +42,11 @@ export declare const createChatStore: (initClientName: string, config: LangGraph
|
|
|
40
42
|
messages: Message[];
|
|
41
43
|
}>[]> & object;
|
|
42
44
|
currentChatId: import("nanostores").PreinitializedWritableAtom<string | null> & object;
|
|
45
|
+
showGraph: import("nanostores").PreinitializedWritableAtom<boolean> & object;
|
|
46
|
+
graphVisualize: import("nanostores").PreinitializedWritableAtom<AssistantGraph | null> & object;
|
|
43
47
|
};
|
|
44
48
|
mutations: {
|
|
45
|
-
initClient: () => Promise<
|
|
49
|
+
initClient: () => Promise<LangGraphClient>;
|
|
46
50
|
sendMessage: (message?: Message[], extraData?: SendMessageOptions) => Promise<void>;
|
|
47
51
|
stopGeneration: () => void;
|
|
48
52
|
toggleToolCollapse: (toolId: string) => void;
|
|
@@ -61,6 +65,8 @@ export declare const createChatStore: (initClientName: string, config: LangGraph
|
|
|
61
65
|
* @en Sets the current Agent and reinitializes the client.
|
|
62
66
|
*/
|
|
63
67
|
setCurrentAgent(agent: string): Promise<void>;
|
|
68
|
+
toggleGraphVisible(): void;
|
|
69
|
+
refreshGraph: () => Promise<void>;
|
|
64
70
|
/**
|
|
65
71
|
* @zh 创建一个新的聊天会话。
|
|
66
72
|
* @en Creates a new chat session.
|
|
@@ -63,15 +63,24 @@ export const getHistoryContent = (thread) => {
|
|
|
63
63
|
* @en Creates a state manager (store) for the chat interface.
|
|
64
64
|
*/
|
|
65
65
|
export const createChatStore = (initClientName, config, context = {}) => {
|
|
66
|
+
var _a, _b;
|
|
66
67
|
const client = atom(null);
|
|
67
68
|
const renderMessages = atom([]);
|
|
68
69
|
const userInput = atom("");
|
|
69
70
|
const loading = atom(false);
|
|
70
71
|
const collapsedTools = atom([]);
|
|
71
72
|
const inChatError = atom(null);
|
|
72
|
-
const showHistory = atom(
|
|
73
|
+
const showHistory = atom((_a = context.showHistory) !== null && _a !== void 0 ? _a : false);
|
|
73
74
|
const currentAgent = atom(initClientName);
|
|
74
75
|
const currentChatId = atom(null);
|
|
76
|
+
// 显示 langgraph 可视化图
|
|
77
|
+
const showGraph = atom((_b = context.showGraph) !== null && _b !== void 0 ? _b : false);
|
|
78
|
+
const graphVisualize = atom(null);
|
|
79
|
+
const refreshGraph = async () => {
|
|
80
|
+
var _a;
|
|
81
|
+
if (showGraph.get())
|
|
82
|
+
graphVisualize.set((await ((_a = client.get()) === null || _a === void 0 ? void 0 : _a.graphVisualize())) || null);
|
|
83
|
+
};
|
|
75
84
|
const updateUI = rafDebounce((newClient) => {
|
|
76
85
|
renderMessages.set(newClient.renderMessage);
|
|
77
86
|
});
|
|
@@ -103,6 +112,9 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
103
112
|
(_a = context.onInit) === null || _a === void 0 ? void 0 : _a.call(context, newClient);
|
|
104
113
|
newClient.graphState = {};
|
|
105
114
|
client.set(newClient);
|
|
115
|
+
if (showGraph.get())
|
|
116
|
+
refreshGraph();
|
|
117
|
+
return newClient;
|
|
106
118
|
}
|
|
107
119
|
/**
|
|
108
120
|
* @zh 发送消息。
|
|
@@ -140,6 +152,9 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
140
152
|
*/
|
|
141
153
|
const toggleHistoryVisible = () => {
|
|
142
154
|
showHistory.set(!showHistory.get());
|
|
155
|
+
if (showHistory.get()) {
|
|
156
|
+
refreshHistoryList();
|
|
157
|
+
}
|
|
143
158
|
};
|
|
144
159
|
const historyList = atom([]);
|
|
145
160
|
/**
|
|
@@ -178,6 +193,8 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
178
193
|
showHistory,
|
|
179
194
|
historyList,
|
|
180
195
|
currentChatId,
|
|
196
|
+
showGraph,
|
|
197
|
+
graphVisualize,
|
|
181
198
|
},
|
|
182
199
|
mutations: {
|
|
183
200
|
initClient,
|
|
@@ -204,8 +221,18 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
204
221
|
if (showHistory.get()) {
|
|
205
222
|
refreshHistoryList();
|
|
206
223
|
}
|
|
224
|
+
if (showGraph.get()) {
|
|
225
|
+
refreshGraph();
|
|
226
|
+
}
|
|
207
227
|
});
|
|
208
228
|
},
|
|
229
|
+
toggleGraphVisible() {
|
|
230
|
+
showGraph.set(!showGraph.get());
|
|
231
|
+
if (showGraph.get()) {
|
|
232
|
+
refreshGraph();
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
refreshGraph,
|
|
209
236
|
/**
|
|
210
237
|
* @zh 创建一个新的聊天会话。
|
|
211
238
|
* @en Creates a new chat session.
|
package/package.json
CHANGED
package/src/LangGraphClient.ts
CHANGED
|
@@ -154,6 +154,12 @@ export class LangGraphClient extends Client {
|
|
|
154
154
|
throw error;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
graphVisualize() {
|
|
159
|
+
return this.assistants.getGraph(this.currentAssistant?.assistant_id!, {
|
|
160
|
+
xray: true,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
157
163
|
/**
|
|
158
164
|
* @zh 列出所有的 Thread。
|
|
159
165
|
* @en Lists all Threads.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { atom } from "nanostores";
|
|
2
2
|
import { LangGraphClient, LangGraphClientConfig, RenderMessage, SendMessageOptions } from "../LangGraphClient.js";
|
|
3
|
-
import { Message, Thread } from "@langchain/langgraph-sdk";
|
|
3
|
+
import { AssistantGraph, Message, Thread } from "@langchain/langgraph-sdk";
|
|
4
4
|
import { rafDebounce } from "./rafDebounce.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -65,6 +65,8 @@ export const createChatStore = (
|
|
|
65
65
|
initClientName: string,
|
|
66
66
|
config: LangGraphClientConfig,
|
|
67
67
|
context: {
|
|
68
|
+
showHistory?: boolean;
|
|
69
|
+
showGraph?: boolean;
|
|
68
70
|
onInit?: (client: LangGraphClient) => void;
|
|
69
71
|
} = {}
|
|
70
72
|
) => {
|
|
@@ -74,10 +76,16 @@ export const createChatStore = (
|
|
|
74
76
|
const loading = atom<boolean>(false);
|
|
75
77
|
const collapsedTools = atom<string[]>([]);
|
|
76
78
|
const inChatError = atom<string | null>(null);
|
|
77
|
-
const showHistory = atom<boolean>(
|
|
79
|
+
const showHistory = atom<boolean>(context.showHistory ?? false);
|
|
78
80
|
const currentAgent = atom<string>(initClientName);
|
|
79
81
|
const currentChatId = atom<string | null>(null);
|
|
80
82
|
|
|
83
|
+
// 显示 langgraph 可视化图
|
|
84
|
+
const showGraph = atom<boolean>(context.showGraph ?? false);
|
|
85
|
+
const graphVisualize = atom<AssistantGraph | null>(null);
|
|
86
|
+
const refreshGraph = async () => {
|
|
87
|
+
if (showGraph.get()) graphVisualize.set((await client.get()?.graphVisualize()) || null);
|
|
88
|
+
};
|
|
81
89
|
const updateUI = rafDebounce((newClient: LangGraphClient) => {
|
|
82
90
|
renderMessages.set(newClient.renderMessage);
|
|
83
91
|
});
|
|
@@ -109,6 +117,8 @@ export const createChatStore = (
|
|
|
109
117
|
context.onInit?.(newClient);
|
|
110
118
|
newClient.graphState = {};
|
|
111
119
|
client.set(newClient);
|
|
120
|
+
if (showGraph.get()) refreshGraph();
|
|
121
|
+
return newClient;
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
/**
|
|
@@ -150,6 +160,9 @@ export const createChatStore = (
|
|
|
150
160
|
*/
|
|
151
161
|
const toggleHistoryVisible = () => {
|
|
152
162
|
showHistory.set(!showHistory.get());
|
|
163
|
+
if (showHistory.get()) {
|
|
164
|
+
refreshHistoryList();
|
|
165
|
+
}
|
|
153
166
|
};
|
|
154
167
|
|
|
155
168
|
const historyList = atom<Thread<{ messages: Message[] }>[]>([]);
|
|
@@ -189,6 +202,8 @@ export const createChatStore = (
|
|
|
189
202
|
showHistory,
|
|
190
203
|
historyList,
|
|
191
204
|
currentChatId,
|
|
205
|
+
showGraph,
|
|
206
|
+
graphVisualize,
|
|
192
207
|
},
|
|
193
208
|
mutations: {
|
|
194
209
|
initClient,
|
|
@@ -215,8 +230,18 @@ export const createChatStore = (
|
|
|
215
230
|
if (showHistory.get()) {
|
|
216
231
|
refreshHistoryList();
|
|
217
232
|
}
|
|
233
|
+
if (showGraph.get()) {
|
|
234
|
+
refreshGraph();
|
|
235
|
+
}
|
|
218
236
|
});
|
|
219
237
|
},
|
|
238
|
+
toggleGraphVisible() {
|
|
239
|
+
showGraph.set(!showGraph.get());
|
|
240
|
+
if (showGraph.get()) {
|
|
241
|
+
refreshGraph();
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
refreshGraph,
|
|
220
245
|
/**
|
|
221
246
|
* @zh 创建一个新的聊天会话。
|
|
222
247
|
* @en Creates a new chat session.
|