@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
package/src/react/ChatContext.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { createElement, createContext, useContext, useMemo, ReactNode, useEffect
|
|
|
2
2
|
|
|
3
3
|
import { createChatStore, UnionStore, useUnionStore } from "../ui-store/index.js";
|
|
4
4
|
import { useStore } from "@nanostores/react";
|
|
5
|
+
import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
|
|
5
6
|
|
|
6
7
|
const ChatContext = createContext<UnionStore<ReturnType<typeof createChatStore>> | undefined>(undefined);
|
|
7
8
|
|
|
@@ -22,7 +23,11 @@ interface ChatProviderProps {
|
|
|
22
23
|
showHistory?: boolean;
|
|
23
24
|
showGraph?: boolean;
|
|
24
25
|
fallbackToAvailableAssistants?: boolean;
|
|
26
|
+
/** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
|
|
27
|
+
autoRestoreLastSession?: boolean;
|
|
25
28
|
onInitError?: (error: any, currentAgent: string) => void;
|
|
29
|
+
client?: ILangGraphClient;
|
|
30
|
+
legacyMode?: boolean;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
@@ -34,7 +39,10 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
34
39
|
showHistory = false,
|
|
35
40
|
showGraph = false,
|
|
36
41
|
fallbackToAvailableAssistants = false,
|
|
42
|
+
autoRestoreLastSession = false,
|
|
37
43
|
onInitError,
|
|
44
|
+
client,
|
|
45
|
+
legacyMode = false,
|
|
38
46
|
}) => {
|
|
39
47
|
// 使用 useMemo 稳定 defaultHeaders 的引用
|
|
40
48
|
const stableHeaders = useMemo(() => defaultHeaders || {}, [defaultHeaders]);
|
|
@@ -53,23 +61,24 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
53
61
|
}
|
|
54
62
|
: fetch;
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
fetch: F,
|
|
63
|
-
maxRetries: 1,
|
|
64
|
-
},
|
|
64
|
+
const config = {
|
|
65
|
+
apiUrl,
|
|
66
|
+
defaultHeaders: stableHeaders,
|
|
67
|
+
callerOptions: {
|
|
68
|
+
fetch: F,
|
|
69
|
+
maxRetries: 1,
|
|
65
70
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
legacyMode,
|
|
72
|
+
};
|
|
73
|
+
/** @ts-ignore */
|
|
74
|
+
if (client) config.client = client;
|
|
75
|
+
return createChatStore(defaultAgent, config, {
|
|
76
|
+
showHistory,
|
|
77
|
+
showGraph,
|
|
78
|
+
fallbackToAvailableAssistants,
|
|
79
|
+
autoRestoreLastSession,
|
|
80
|
+
});
|
|
81
|
+
}, [defaultAgent, apiUrl, stableHeaders, withCredentials, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
|
|
73
82
|
|
|
74
83
|
const unionStore = useUnionStore(store, useStore);
|
|
75
84
|
|