@langgraph-js/sdk 4.6.2 → 4.6.4

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.
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
- import { UnionStore } from "../ui-store/index.js";
2
+ import { HistoryFilter, UnionStore } from "../ui-store/index.js";
3
3
  import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
4
4
  export declare const useChat: () => UnionStore<{
5
5
  data: {
@@ -28,7 +28,7 @@ export declare const useChat: () => UnionStore<{
28
28
  messages: import("@langchain/langgraph-sdk").Message[];
29
29
  }, unknown>[]> & object;
30
30
  historyPagination: import("nanostores").PreinitializedWritableAtom<import("../ui-store/createChatStore.js").HistoryPagination> & object;
31
- historyFilter: import("nanostores").PreinitializedWritableAtom<import("../ui-store/createChatStore.js").HistoryFilter> & object;
31
+ historyFilter: import("nanostores").PreinitializedWritableAtom<HistoryFilter> & object;
32
32
  };
33
33
  mutations: {
34
34
  setCurrentArtifactById: (id: string, tool_id: string) => void;
@@ -66,7 +66,7 @@ export declare const useChat: () => UnionStore<{
66
66
  }>): Promise<void>;
67
67
  setHistoryPage(page: number): void;
68
68
  setHistoryPageSize(pageSize: number): void;
69
- setHistoryFilter(filter: Partial<import("../ui-store/createChatStore.js").HistoryFilter>): void;
69
+ setHistoryFilter(filter: Partial<HistoryFilter>): void;
70
70
  resetHistoryFilter(): void;
71
71
  };
72
72
  }>;
@@ -85,6 +85,10 @@ interface ChatProviderProps {
85
85
  onInitError?: (error: any, currentAgent: string) => void;
86
86
  client?: ILangGraphClient;
87
87
  legacyMode?: boolean;
88
+ /** 历史记录筛选的默认参数 */
89
+ historyFilter?: HistoryFilter;
90
+ /** UI 更新的防抖时间(毫秒,默认 10) */
91
+ debounceTime?: number;
88
92
  }
89
93
  export declare const ChatProvider: React.FC<ChatProviderProps>;
90
94
  export {};
@@ -9,7 +9,7 @@ export const useChat = () => {
9
9
  }
10
10
  return context;
11
11
  };
12
- export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://localhost:8123", defaultHeaders, withCredentials = false, fetch, showHistory = false, showGraph = false, fallbackToAvailableAssistants = false, autoRestoreLastSession = false, onInitError, client, legacyMode = false, }) => {
12
+ export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://localhost:8123", defaultHeaders, withCredentials = false, fetch, showHistory = false, showGraph = false, fallbackToAvailableAssistants = false, autoRestoreLastSession = false, onInitError, client, legacyMode = false, historyFilter, debounceTime, }) => {
13
13
  // 使用 useMemo 稳定 defaultHeaders 的引用
14
14
  const stableHeaders = useMemo(() => defaultHeaders || {}, [defaultHeaders]);
15
15
  // 使用 useRef 保存 onInitError 的最新引用
@@ -42,8 +42,10 @@ export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://loc
42
42
  showGraph,
43
43
  fallbackToAvailableAssistants,
44
44
  autoRestoreLastSession,
45
+ historyFilter,
46
+ debounceTime,
45
47
  });
46
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
48
+ }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession, client, legacyMode, historyFilter, debounceTime]);
47
49
  const unionStore = useUnionStore(store, useStore);
48
50
  // 使用 ref 标记是否已初始化
49
51
  const initializedRef = useRef(false);
@@ -1,4 +1,5 @@
1
1
  import { type JSX, Accessor } from "solid-js";
2
+ import { HistoryFilter } from "../ui-store/index.js";
2
3
  import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
3
4
  import { PreinitializedWritableAtom, StoreValue } from "nanostores";
4
5
  export declare const useChat: () => UnionStoreSolid<{
@@ -28,7 +29,7 @@ export declare const useChat: () => UnionStoreSolid<{
28
29
  messages: import("@langchain/langgraph-sdk").Message[];
29
30
  }, unknown>[]> & object;
30
31
  historyPagination: PreinitializedWritableAtom<import("../ui-store/createChatStore.js").HistoryPagination> & object;
31
- historyFilter: PreinitializedWritableAtom<import("../ui-store/createChatStore.js").HistoryFilter> & object;
32
+ historyFilter: PreinitializedWritableAtom<HistoryFilter> & object;
32
33
  };
33
34
  mutations: {
34
35
  setCurrentArtifactById: (id: string, tool_id: string) => void;
@@ -66,7 +67,7 @@ export declare const useChat: () => UnionStoreSolid<{
66
67
  }>): Promise<void>;
67
68
  setHistoryPage(page: number): void;
68
69
  setHistoryPageSize(pageSize: number): void;
69
- setHistoryFilter(filter: Partial<import("../ui-store/createChatStore.js").HistoryFilter>): void;
70
+ setHistoryFilter(filter: Partial<HistoryFilter>): void;
70
71
  resetHistoryFilter(): void;
71
72
  };
72
73
  }>;
@@ -85,6 +86,10 @@ interface ChatProviderProps {
85
86
  onInitError?: (error: any, currentAgent: string) => void;
86
87
  client?: ILangGraphClient;
87
88
  legacyMode?: boolean;
89
+ /** 历史记录筛选的默认参数 */
90
+ historyFilter?: HistoryFilter;
91
+ /** UI 更新的防抖时间(毫秒,默认 10) */
92
+ debounceTime?: number;
88
93
  }
89
94
  /**
90
95
  * @zh UnionStore 类型用于合并 store 的 data 和 mutations,使其可以直接访问。
@@ -53,6 +53,8 @@ export const ChatProvider = (props) => {
53
53
  showGraph: props.showGraph || false,
54
54
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants || false,
55
55
  autoRestoreLastSession: props.autoRestoreLastSession || false,
56
+ historyFilter: props.historyFilter,
57
+ debounceTime: props.debounceTime,
56
58
  });
57
59
  });
58
60
  const unionStore = useUnionStoreSolid(store(), useStore);
@@ -16,6 +16,10 @@ interface ChatStoreContext {
16
16
  onInit?: (client: LangGraphClient) => void;
17
17
  /** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
18
18
  autoRestoreLastSession?: boolean;
19
+ /** 历史记录筛选的默认参数 */
20
+ historyFilter?: Partial<HistoryFilter>;
21
+ /** UI 更新的防抖时间(毫秒,默认 10) */
22
+ debounceTime?: number;
19
23
  }
20
24
  export interface HistoryPagination {
21
25
  page: number;
@@ -76,13 +76,14 @@ export const createChatStore = (initClientName, config, context = {}) => {
76
76
  pageSize: 10,
77
77
  total: 0,
78
78
  });
79
- // 历史记录筛选状态
80
- const historyFilter = atom({
81
- metadata: null,
82
- status: null,
83
- sortBy: "updated_at",
84
- sortOrder: "desc",
85
- });
79
+ // 历史记录筛选状态 - 使用 context 中的默认值
80
+ const defaultHistoryFilter = {
81
+ metadata: context.historyFilter?.metadata ?? null,
82
+ status: context.historyFilter?.status ?? null,
83
+ sortBy: context.historyFilter?.sortBy ?? "updated_at",
84
+ sortOrder: context.historyFilter?.sortOrder ?? "desc",
85
+ };
86
+ const historyFilter = atom(defaultHistoryFilter);
86
87
  // ============ 内部状态 ============
87
88
  let cleanupCurrentClient = null;
88
89
  // ============ 计算属性 ============
@@ -104,7 +105,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
104
105
  currentNodeName.set(lastMessage?.node_name || lastMessage?.name || "__start__");
105
106
  renderMessages.set(messages);
106
107
  currentStatus.set(newClient.status);
107
- }, 10);
108
+ }, context.debounceTime ?? 10);
108
109
  // ============ 工具和图表辅助函数 ============
109
110
  const refreshTools = async () => {
110
111
  const c = client.get();
@@ -513,10 +514,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
513
514
  },
514
515
  resetHistoryFilter() {
515
516
  historyFilter.set({
516
- metadata: null,
517
- status: null,
518
- sortBy: "updated_at",
519
- sortOrder: "desc",
517
+ ...defaultHistoryFilter,
520
518
  });
521
519
  historyPagination.set({
522
520
  ...historyPagination.get(),
@@ -1,5 +1,5 @@
1
1
  import { type PropType, Ref } from "vue";
2
- import { createChatStore } from "../ui-store/index.js";
2
+ import { createChatStore, HistoryFilter } from "../ui-store/index.js";
3
3
  import { PreinitializedWritableAtom, StoreValue } from "nanostores";
4
4
  import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
5
5
  /**
@@ -39,6 +39,10 @@ export interface ChatProviderProps {
39
39
  onInitError?: (error: any, currentAgent: string) => void;
40
40
  client?: ILangGraphClient;
41
41
  legacyMode?: boolean;
42
+ /** 历史记录筛选的默认参数 */
43
+ historyFilter?: HistoryFilter;
44
+ /** UI 更新的防抖时间(毫秒,默认 10) */
45
+ debounceTime?: number;
42
46
  }
43
47
  /**
44
48
  * @zh Chat Provider Hook,用于在 setup 中直接使用
@@ -72,7 +76,7 @@ export declare const useChatProvider: (props: ChatProviderProps) => {
72
76
  messages: import("@langchain/langgraph-sdk").Message[];
73
77
  }, unknown>[]> & object;
74
78
  historyPagination: PreinitializedWritableAtom<import("../ui-store/createChatStore.js").HistoryPagination> & object;
75
- historyFilter: PreinitializedWritableAtom<import("../ui-store/createChatStore.js").HistoryFilter> & object;
79
+ historyFilter: PreinitializedWritableAtom<HistoryFilter> & object;
76
80
  };
77
81
  mutations: {
78
82
  setCurrentArtifactById: (id: string, tool_id: string) => void;
@@ -110,7 +114,7 @@ export declare const useChatProvider: (props: ChatProviderProps) => {
110
114
  }>): Promise<void>;
111
115
  setHistoryPage(page: number): void;
112
116
  setHistoryPageSize(pageSize: number): void;
113
- setHistoryFilter(filter: Partial<import("../ui-store/createChatStore.js").HistoryFilter>): void;
117
+ setHistoryFilter(filter: Partial<HistoryFilter>): void;
114
118
  resetHistoryFilter(): void;
115
119
  };
116
120
  }>;
@@ -156,6 +160,14 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
156
160
  type: PropType<(error: any, currentAgent: string) => void>;
157
161
  default: undefined;
158
162
  };
163
+ historyFilter: {
164
+ type: PropType<any>;
165
+ default: undefined;
166
+ };
167
+ debounceTime: {
168
+ type: PropType<number>;
169
+ default: undefined;
170
+ };
159
171
  }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
160
172
  [key: string]: any;
161
173
  }>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
@@ -195,14 +207,24 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
195
207
  type: PropType<(error: any, currentAgent: string) => void>;
196
208
  default: undefined;
197
209
  };
210
+ historyFilter: {
211
+ type: PropType<any>;
212
+ default: undefined;
213
+ };
214
+ debounceTime: {
215
+ type: PropType<number>;
216
+ default: undefined;
217
+ };
198
218
  }>> & Readonly<{}>, {
199
219
  apiUrl: string;
200
220
  defaultHeaders: Record<string, string>;
201
221
  showGraph: boolean;
202
222
  showHistory: boolean;
223
+ historyFilter: any;
203
224
  defaultAgent: string;
204
225
  withCredentials: boolean;
205
226
  fetch: typeof fetch;
206
227
  autoRestoreLastSession: boolean;
207
228
  onInitError: (error: any, currentAgent: string) => void;
229
+ debounceTime: number;
208
230
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -53,6 +53,8 @@ export const useChatProvider = (props) => {
53
53
  showGraph: props.showGraph,
54
54
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants,
55
55
  autoRestoreLastSession: props.autoRestoreLastSession,
56
+ historyFilter: props.historyFilter,
57
+ debounceTime: props.debounceTime,
56
58
  });
57
59
  const unionStore = useUnionStoreVue(store, useStore);
58
60
  // 提供 store 给子组件
@@ -113,6 +115,14 @@ export const ChatProvider = defineComponent({
113
115
  type: Function,
114
116
  default: undefined,
115
117
  },
118
+ historyFilter: {
119
+ type: Object,
120
+ default: undefined,
121
+ },
122
+ debounceTime: {
123
+ type: Number,
124
+ default: undefined,
125
+ },
116
126
  },
117
127
  setup(props, { slots }) {
118
128
  const { unionStore } = useChatProvider(props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langgraph-js/sdk",
3
- "version": "4.6.2",
3
+ "version": "4.6.4",
4
4
  "description": "The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  import { createElement, createContext, useContext, useMemo, ReactNode, useEffect, useRef } from "react";
2
2
 
3
- import { createChatStore, UnionStore, useUnionStore } from "../ui-store/index.js";
3
+ import { createChatStore, HistoryFilter, UnionStore, useUnionStore } from "../ui-store/index.js";
4
4
  import { useStore } from "@nanostores/react";
5
5
  import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
6
6
 
@@ -29,6 +29,10 @@ interface ChatProviderProps {
29
29
  onInitError?: (error: any, currentAgent: string) => void;
30
30
  client?: ILangGraphClient;
31
31
  legacyMode?: boolean;
32
+ /** 历史记录筛选的默认参数 */
33
+ historyFilter?: HistoryFilter;
34
+ /** UI 更新的防抖时间(毫秒,默认 10) */
35
+ debounceTime?: number;
32
36
  }
33
37
 
34
38
  export const ChatProvider: React.FC<ChatProviderProps> = ({
@@ -45,6 +49,8 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
45
49
  onInitError,
46
50
  client,
47
51
  legacyMode = false,
52
+ historyFilter,
53
+ debounceTime,
48
54
  }) => {
49
55
  // 使用 useMemo 稳定 defaultHeaders 的引用
50
56
  const stableHeaders = useMemo(() => defaultHeaders || {}, [defaultHeaders]);
@@ -80,8 +86,10 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
80
86
  showGraph,
81
87
  fallbackToAvailableAssistants,
82
88
  autoRestoreLastSession,
89
+ historyFilter,
90
+ debounceTime,
83
91
  });
84
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
92
+ }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession, client, legacyMode, historyFilter, debounceTime]);
85
93
 
86
94
  const unionStore = useUnionStore(store, useStore);
87
95
 
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext, createMemo, onMount, type JSX, type Component, createComponent, Accessor } from "solid-js";
2
- import { createChatStore, UnionStore } from "../ui-store/index.js";
2
+ import { createChatStore, HistoryFilter, UnionStore } from "../ui-store/index.js";
3
3
  import { useStore } from "@nanostores/solid";
4
4
  import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
5
5
  import { PreinitializedWritableAtom, StoreValue } from "nanostores";
@@ -29,6 +29,10 @@ interface ChatProviderProps {
29
29
  onInitError?: (error: any, currentAgent: string) => void;
30
30
  client?: ILangGraphClient;
31
31
  legacyMode?: boolean;
32
+ /** 历史记录筛选的默认参数 */
33
+ historyFilter?: HistoryFilter;
34
+ /** UI 更新的防抖时间(毫秒,默认 10) */
35
+ debounceTime?: number;
32
36
  }
33
37
  /**
34
38
  * @zh UnionStore 类型用于合并 store 的 data 和 mutations,使其可以直接访问。
@@ -90,6 +94,8 @@ export const ChatProvider = (props: ChatProviderProps) => {
90
94
  showGraph: props.showGraph || false,
91
95
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants || false,
92
96
  autoRestoreLastSession: props.autoRestoreLastSession || false,
97
+ historyFilter: props.historyFilter,
98
+ debounceTime: props.debounceTime,
93
99
  });
94
100
  });
95
101
 
@@ -59,6 +59,10 @@ interface ChatStoreContext {
59
59
  onInit?: (client: LangGraphClient) => void;
60
60
  /** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
61
61
  autoRestoreLastSession?: boolean;
62
+ /** 历史记录筛选的默认参数 */
63
+ historyFilter?: Partial<HistoryFilter>;
64
+ /** UI 更新的防抖时间(毫秒,默认 10) */
65
+ debounceTime?: number;
62
66
  }
63
67
 
64
68
  // 分页状态类型
@@ -113,13 +117,15 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
113
117
  total: 0,
114
118
  });
115
119
 
116
- // 历史记录筛选状态
117
- const historyFilter = atom<HistoryFilter>({
118
- metadata: null,
119
- status: null,
120
- sortBy: "updated_at",
121
- sortOrder: "desc",
122
- });
120
+ // 历史记录筛选状态 - 使用 context 中的默认值
121
+ const defaultHistoryFilter: HistoryFilter = {
122
+ metadata: context.historyFilter?.metadata ?? null,
123
+ status: context.historyFilter?.status ?? null,
124
+ sortBy: context.historyFilter?.sortBy ?? "updated_at",
125
+ sortOrder: context.historyFilter?.sortOrder ?? "desc",
126
+ };
127
+
128
+ const historyFilter = atom<HistoryFilter>(defaultHistoryFilter);
123
129
 
124
130
  // ============ 内部状态 ============
125
131
 
@@ -149,7 +155,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
149
155
  currentNodeName.set(lastMessage?.node_name || lastMessage?.name || "__start__");
150
156
  renderMessages.set(messages);
151
157
  currentStatus.set(newClient.status);
152
- }, 10);
158
+ }, context.debounceTime ?? 10);
153
159
  // ============ 工具和图表辅助函数 ============
154
160
 
155
161
  const refreshTools = async () => {
@@ -611,10 +617,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
611
617
  },
612
618
  resetHistoryFilter() {
613
619
  historyFilter.set({
614
- metadata: null,
615
- status: null,
616
- sortBy: "updated_at",
617
- sortOrder: "desc",
620
+ ...defaultHistoryFilter,
618
621
  });
619
622
  historyPagination.set({
620
623
  ...historyPagination.get(),
@@ -1,5 +1,5 @@
1
1
  import { defineComponent, inject, provide, onMounted, defineExpose, type InjectionKey, type PropType, Ref } from "vue";
2
- import { createChatStore } from "../ui-store/index.js";
2
+ import { createChatStore, HistoryFilter } from "../ui-store/index.js";
3
3
  import { useStore } from "@nanostores/vue";
4
4
  import { PreinitializedWritableAtom, StoreValue } from "nanostores";
5
5
  import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
@@ -61,6 +61,10 @@ export interface ChatProviderProps {
61
61
  onInitError?: (error: any, currentAgent: string) => void;
62
62
  client?: ILangGraphClient;
63
63
  legacyMode?: boolean;
64
+ /** 历史记录筛选的默认参数 */
65
+ historyFilter?: HistoryFilter;
66
+ /** UI 更新的防抖时间(毫秒,默认 10) */
67
+ debounceTime?: number;
64
68
  }
65
69
 
66
70
  /**
@@ -93,6 +97,8 @@ export const useChatProvider = (props: ChatProviderProps) => {
93
97
  showGraph: props.showGraph,
94
98
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants,
95
99
  autoRestoreLastSession: props.autoRestoreLastSession,
100
+ historyFilter: props.historyFilter,
101
+ debounceTime: props.debounceTime,
96
102
  }
97
103
  );
98
104
 
@@ -159,6 +165,14 @@ export const ChatProvider = defineComponent({
159
165
  type: Function as PropType<(error: any, currentAgent: string) => void>,
160
166
  default: undefined,
161
167
  },
168
+ historyFilter: {
169
+ type: Object as PropType<any>,
170
+ default: undefined,
171
+ },
172
+ debounceTime: {
173
+ type: Number as PropType<number>,
174
+ default: undefined,
175
+ },
162
176
  },
163
177
  setup(props, { slots }) {
164
178
  const { unionStore } = useChatProvider(props);