@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.
Files changed (45) hide show
  1. package/README.md +29 -0
  2. package/dist/History.d.ts +115 -0
  3. package/dist/History.js +226 -0
  4. package/dist/LangGraphClient.d.ts +23 -2
  5. package/dist/LangGraphClient.js +118 -80
  6. package/dist/MessageProcessor.js +18 -24
  7. package/dist/SpendTime.js +4 -9
  8. package/dist/TestKit.d.ts +1 -1
  9. package/dist/TestKit.js +16 -15
  10. package/dist/ToolManager.js +4 -7
  11. package/dist/artifacts/index.js +1 -1
  12. package/dist/client/LanggraphServer.js +1 -1
  13. package/dist/client/LowJSServer.d.ts +3 -0
  14. package/dist/client/LowJSServer.js +80 -0
  15. package/dist/client/index.d.ts +2 -0
  16. package/dist/client/index.js +2 -0
  17. package/dist/client/utils/sse.d.ts +8 -0
  18. package/dist/client/utils/sse.js +151 -0
  19. package/dist/client/utils/stream.d.ts +15 -0
  20. package/dist/client/utils/stream.js +104 -0
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.js +2 -0
  23. package/dist/react/ChatContext.d.ts +31 -20
  24. package/dist/react/ChatContext.js +10 -4
  25. package/dist/tool/ToolUI.js +3 -2
  26. package/dist/tool/createTool.js +3 -6
  27. package/dist/tool/utils.js +3 -4
  28. package/dist/ui-store/createChatStore.d.ts +33 -66
  29. package/dist/ui-store/createChatStore.js +261 -247
  30. package/dist/vue/ChatContext.d.ts +41 -21
  31. package/dist/vue/ChatContext.js +8 -2
  32. package/package.json +3 -1
  33. package/src/History.ts +294 -0
  34. package/src/LangGraphClient.ts +98 -48
  35. package/src/client/LanggraphServer.ts +1 -2
  36. package/src/client/LowJSServer.ts +80 -0
  37. package/src/client/index.ts +2 -0
  38. package/src/client/utils/sse.ts +176 -0
  39. package/src/client/utils/stream.ts +114 -0
  40. package/src/index.ts +2 -0
  41. package/src/react/ChatContext.ts +25 -16
  42. package/src/ui-store/createChatStore.ts +310 -236
  43. package/src/vue/ChatContext.ts +12 -0
  44. package/test/TestKit.test.ts +10 -2
  45. package/tsconfig.json +1 -1
@@ -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
- return createChatStore(
57
- defaultAgent,
58
- {
59
- apiUrl,
60
- defaultHeaders: stableHeaders,
61
- callerOptions: {
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
- showHistory,
68
- showGraph,
69
- fallbackToAvailableAssistants,
70
- }
71
- );
72
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, showHistory, showGraph, fallbackToAvailableAssistants]);
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