@langgraph-js/sdk 4.3.4 → 4.3.5
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/History.d.ts +1 -1
- package/dist/History.js +6 -6
- package/dist/react/ChatContext.d.ts +1 -1
- package/dist/solid/ChatContext.d.ts +1 -1
- package/dist/ui-store/createChatStore.d.ts +1 -1
- package/dist/ui-store/createChatStore.js +3 -3
- package/dist/vue/ChatContext.d.ts +1 -1
- package/package.json +1 -1
- package/src/History.ts +6 -6
- package/src/ui-store/createChatStore.ts +3 -3
package/dist/History.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class History {
|
|
|
43
43
|
* @zh 激活指定会话(懒加载创建 Client)
|
|
44
44
|
* @en Activates the specified session (lazy load client)
|
|
45
45
|
*/
|
|
46
|
-
activateSession(sessionId: string): Promise<SessionInfo>;
|
|
46
|
+
activateSession(sessionId: string, mustResetStream?: boolean): Promise<SessionInfo>;
|
|
47
47
|
/**
|
|
48
48
|
* @zh 获取当前活跃的会话
|
|
49
49
|
* @en Gets the current active session
|
package/dist/History.js
CHANGED
|
@@ -45,18 +45,18 @@ export class History {
|
|
|
45
45
|
* @zh 激活指定会话(懒加载创建 Client)
|
|
46
46
|
* @en Activates the specified session (lazy load client)
|
|
47
47
|
*/
|
|
48
|
-
async activateSession(sessionId) {
|
|
49
|
-
const session = this.sessions.get(sessionId)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
48
|
+
async activateSession(sessionId, mustResetStream = false) {
|
|
49
|
+
const session = this.sessions.get(sessionId) || {
|
|
50
|
+
sessionId,
|
|
51
|
+
agentName: this.virtualClient.getCurrentAssistant()?.graph_id,
|
|
52
|
+
};
|
|
53
53
|
// 懒加载:只在激活时创建 Client
|
|
54
54
|
if (!session.client) {
|
|
55
55
|
const client = new LangGraphClient(this.clientConfig);
|
|
56
56
|
await client.initAssistant(session.agentName);
|
|
57
57
|
// 只有在有 thread 的情况下才重置(恢复已有会话)
|
|
58
58
|
// 新会话的 thread 会在发送第一条消息时自动创建
|
|
59
|
-
if (session.thread) {
|
|
59
|
+
if (session.thread || mustResetStream) {
|
|
60
60
|
await client.resetThread(session.agentName, sessionId);
|
|
61
61
|
}
|
|
62
62
|
session.client = client;
|
|
@@ -34,7 +34,7 @@ export declare const useChat: () => UnionStore<{
|
|
|
34
34
|
initClient: () => Promise<import("../History.js").History>;
|
|
35
35
|
getClient: () => import("../LangGraphClient.js").LangGraphClient<unknown> | null;
|
|
36
36
|
getHistory: () => import("../History.js").History | null;
|
|
37
|
-
activateSession: (sessionId: string) => Promise<void>;
|
|
37
|
+
activateSession: (sessionId: string, mustResetStream?: boolean) => Promise<void>;
|
|
38
38
|
createNewSession: () => Promise<void>;
|
|
39
39
|
refreshSessionList: () => Promise<void>;
|
|
40
40
|
refreshHistoryList: () => Promise<void>;
|
|
@@ -34,7 +34,7 @@ export declare const useChat: () => UnionStoreSolid<{
|
|
|
34
34
|
initClient: () => Promise<import("../History.js").History>;
|
|
35
35
|
getClient: () => import("../LangGraphClient.js").LangGraphClient<unknown> | null;
|
|
36
36
|
getHistory: () => import("../History.js").History | null;
|
|
37
|
-
activateSession: (sessionId: string) => Promise<void>;
|
|
37
|
+
activateSession: (sessionId: string, mustResetStream?: boolean) => Promise<void>;
|
|
38
38
|
createNewSession: () => Promise<void>;
|
|
39
39
|
refreshSessionList: () => Promise<void>;
|
|
40
40
|
refreshHistoryList: () => Promise<void>;
|
|
@@ -50,7 +50,7 @@ export declare const createChatStore: (initClientName: string, config: Partial<L
|
|
|
50
50
|
initClient: () => Promise<History>;
|
|
51
51
|
getClient: () => LangGraphClient<unknown> | null;
|
|
52
52
|
getHistory: () => History | null;
|
|
53
|
-
activateSession: (sessionId: string) => Promise<void>;
|
|
53
|
+
activateSession: (sessionId: string, mustResetStream?: boolean) => Promise<void>;
|
|
54
54
|
createNewSession: () => Promise<void>;
|
|
55
55
|
refreshSessionList: () => Promise<void>;
|
|
56
56
|
refreshHistoryList: () => Promise<void>;
|
|
@@ -234,7 +234,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
// ============ 会话激活逻辑 ============
|
|
237
|
-
async function activateSession(sessionId) {
|
|
237
|
+
async function activateSession(sessionId, mustResetStream = false) {
|
|
238
238
|
const historyManager = history.get();
|
|
239
239
|
if (!historyManager)
|
|
240
240
|
return;
|
|
@@ -246,7 +246,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
246
246
|
inChatError.set(null);
|
|
247
247
|
interruptData.set(null);
|
|
248
248
|
isInterrupted.set(false);
|
|
249
|
-
const session = await historyManager.activateSession(sessionId);
|
|
249
|
+
const session = await historyManager.activateSession(sessionId, mustResetStream);
|
|
250
250
|
const activeClient = session.client;
|
|
251
251
|
if (activeClient) {
|
|
252
252
|
cleanupCurrentClient = setupClientListeners(activeClient);
|
|
@@ -416,7 +416,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
|
|
|
416
416
|
// 历史记录(兼容旧 API)
|
|
417
417
|
addToHistory,
|
|
418
418
|
createNewChat: createNewSession,
|
|
419
|
-
toHistoryChat: (thread) => activateSession(thread.thread_id),
|
|
419
|
+
toHistoryChat: (thread) => activateSession(thread.thread_id, true),
|
|
420
420
|
async deleteHistoryChat(thread) {
|
|
421
421
|
const historyManager = history.get();
|
|
422
422
|
if (historyManager) {
|
|
@@ -77,7 +77,7 @@ export declare const useChatProvider: (props: ChatProviderProps) => {
|
|
|
77
77
|
initClient: () => Promise<import("../History.js").History>;
|
|
78
78
|
getClient: () => import("../LangGraphClient.js").LangGraphClient<unknown> | null;
|
|
79
79
|
getHistory: () => import("../History.js").History | null;
|
|
80
|
-
activateSession: (sessionId: string) => Promise<void>;
|
|
80
|
+
activateSession: (sessionId: string, mustResetStream?: boolean) => Promise<void>;
|
|
81
81
|
createNewSession: () => Promise<void>;
|
|
82
82
|
refreshSessionList: () => Promise<void>;
|
|
83
83
|
refreshHistoryList: () => Promise<void>;
|
package/package.json
CHANGED
package/src/History.ts
CHANGED
|
@@ -78,11 +78,11 @@ export class History {
|
|
|
78
78
|
* @zh 激活指定会话(懒加载创建 Client)
|
|
79
79
|
* @en Activates the specified session (lazy load client)
|
|
80
80
|
*/
|
|
81
|
-
async activateSession(sessionId: string): Promise<SessionInfo> {
|
|
82
|
-
const session = this.sessions.get(sessionId)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
81
|
+
async activateSession(sessionId: string, mustResetStream = false): Promise<SessionInfo> {
|
|
82
|
+
const session: SessionInfo = this.sessions.get(sessionId) || {
|
|
83
|
+
sessionId,
|
|
84
|
+
agentName: this.virtualClient.getCurrentAssistant()?.graph_id!,
|
|
85
|
+
};
|
|
86
86
|
|
|
87
87
|
// 懒加载:只在激活时创建 Client
|
|
88
88
|
if (!session.client) {
|
|
@@ -91,7 +91,7 @@ export class History {
|
|
|
91
91
|
|
|
92
92
|
// 只有在有 thread 的情况下才重置(恢复已有会话)
|
|
93
93
|
// 新会话的 thread 会在发送第一条消息时自动创建
|
|
94
|
-
if (session.thread) {
|
|
94
|
+
if (session.thread || mustResetStream) {
|
|
95
95
|
await client.resetThread(session.agentName, sessionId);
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -281,7 +281,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
|
|
|
281
281
|
|
|
282
282
|
// ============ 会话激活逻辑 ============
|
|
283
283
|
|
|
284
|
-
async function activateSession(sessionId: string) {
|
|
284
|
+
async function activateSession(sessionId: string, mustResetStream = false) {
|
|
285
285
|
const historyManager = history.get();
|
|
286
286
|
if (!historyManager) return;
|
|
287
287
|
|
|
@@ -295,7 +295,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
|
|
|
295
295
|
interruptData.set(null);
|
|
296
296
|
isInterrupted.set(false);
|
|
297
297
|
|
|
298
|
-
const session = await historyManager.activateSession(sessionId);
|
|
298
|
+
const session = await historyManager.activateSession(sessionId, mustResetStream);
|
|
299
299
|
const activeClient = session.client;
|
|
300
300
|
|
|
301
301
|
if (activeClient) {
|
|
@@ -488,7 +488,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
|
|
|
488
488
|
// 历史记录(兼容旧 API)
|
|
489
489
|
addToHistory,
|
|
490
490
|
createNewChat: createNewSession,
|
|
491
|
-
toHistoryChat: (thread: Thread<{ messages: Message[] }>) => activateSession(thread.thread_id),
|
|
491
|
+
toHistoryChat: (thread: Thread<{ messages: Message[] }>) => activateSession(thread.thread_id, true),
|
|
492
492
|
async deleteHistoryChat(thread: Thread<{ messages: Message[] }>) {
|
|
493
493
|
const historyManager = history.get();
|
|
494
494
|
if (historyManager) {
|