@langgraph-js/sdk 4.6.2 → 4.6.3

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.
@@ -85,6 +85,8 @@ interface ChatProviderProps {
85
85
  onInitError?: (error: any, currentAgent: string) => void;
86
86
  client?: ILangGraphClient;
87
87
  legacyMode?: boolean;
88
+ /** 历史记录筛选的默认参数 */
89
+ historyFilter?: import("../ui-store/createChatStore.js").HistoryFilter;
88
90
  }
89
91
  export declare const ChatProvider: React.FC<ChatProviderProps>;
90
92
  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, }) => {
13
13
  // 使用 useMemo 稳定 defaultHeaders 的引用
14
14
  const stableHeaders = useMemo(() => defaultHeaders || {}, [defaultHeaders]);
15
15
  // 使用 useRef 保存 onInitError 的最新引用
@@ -42,8 +42,9 @@ export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://loc
42
42
  showGraph,
43
43
  fallbackToAvailableAssistants,
44
44
  autoRestoreLastSession,
45
+ historyFilter,
45
46
  });
46
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
47
+ }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession, client, legacyMode, historyFilter]);
47
48
  const unionStore = useUnionStore(store, useStore);
48
49
  // 使用 ref 标记是否已初始化
49
50
  const initializedRef = useRef(false);
@@ -85,6 +85,8 @@ interface ChatProviderProps {
85
85
  onInitError?: (error: any, currentAgent: string) => void;
86
86
  client?: ILangGraphClient;
87
87
  legacyMode?: boolean;
88
+ /** 历史记录筛选的默认参数 */
89
+ historyFilter?: import("../ui-store/createChatStore.js").HistoryFilter;
88
90
  }
89
91
  /**
90
92
  * @zh UnionStore 类型用于合并 store 的 data 和 mutations,使其可以直接访问。
@@ -53,6 +53,7 @@ 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,
56
57
  });
57
58
  });
58
59
  const unionStore = useUnionStoreSolid(store(), useStore);
@@ -16,6 +16,8 @@ interface ChatStoreContext {
16
16
  onInit?: (client: LangGraphClient) => void;
17
17
  /** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
18
18
  autoRestoreLastSession?: boolean;
19
+ /** 历史记录筛选的默认参数 */
20
+ historyFilter?: Partial<HistoryFilter>;
19
21
  }
20
22
  export interface HistoryPagination {
21
23
  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
  // ============ 计算属性 ============
@@ -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(),
@@ -39,6 +39,8 @@ export interface ChatProviderProps {
39
39
  onInitError?: (error: any, currentAgent: string) => void;
40
40
  client?: ILangGraphClient;
41
41
  legacyMode?: boolean;
42
+ /** 历史记录筛选的默认参数 */
43
+ historyFilter?: import("../ui-store/createChatStore.js").HistoryFilter;
42
44
  }
43
45
  /**
44
46
  * @zh Chat Provider Hook,用于在 setup 中直接使用
@@ -156,6 +158,10 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
156
158
  type: PropType<(error: any, currentAgent: string) => void>;
157
159
  default: undefined;
158
160
  };
161
+ historyFilter: {
162
+ type: PropType<any>;
163
+ default: undefined;
164
+ };
159
165
  }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
160
166
  [key: string]: any;
161
167
  }>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
@@ -195,11 +201,16 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
195
201
  type: PropType<(error: any, currentAgent: string) => void>;
196
202
  default: undefined;
197
203
  };
204
+ historyFilter: {
205
+ type: PropType<any>;
206
+ default: undefined;
207
+ };
198
208
  }>> & Readonly<{}>, {
199
209
  apiUrl: string;
200
210
  defaultHeaders: Record<string, string>;
201
211
  showGraph: boolean;
202
212
  showHistory: boolean;
213
+ historyFilter: any;
203
214
  defaultAgent: string;
204
215
  withCredentials: boolean;
205
216
  fetch: typeof fetch;
@@ -53,6 +53,7 @@ export const useChatProvider = (props) => {
53
53
  showGraph: props.showGraph,
54
54
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants,
55
55
  autoRestoreLastSession: props.autoRestoreLastSession,
56
+ historyFilter: props.historyFilter,
56
57
  });
57
58
  const unionStore = useUnionStoreVue(store, useStore);
58
59
  // 提供 store 给子组件
@@ -113,6 +114,10 @@ export const ChatProvider = defineComponent({
113
114
  type: Function,
114
115
  default: undefined,
115
116
  },
117
+ historyFilter: {
118
+ type: Object,
119
+ default: undefined,
120
+ },
116
121
  },
117
122
  setup(props, { slots }) {
118
123
  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.3",
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",
@@ -29,6 +29,8 @@ interface ChatProviderProps {
29
29
  onInitError?: (error: any, currentAgent: string) => void;
30
30
  client?: ILangGraphClient;
31
31
  legacyMode?: boolean;
32
+ /** 历史记录筛选的默认参数 */
33
+ historyFilter?: import("../ui-store/createChatStore.js").HistoryFilter;
32
34
  }
33
35
 
34
36
  export const ChatProvider: React.FC<ChatProviderProps> = ({
@@ -45,6 +47,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
45
47
  onInitError,
46
48
  client,
47
49
  legacyMode = false,
50
+ historyFilter,
48
51
  }) => {
49
52
  // 使用 useMemo 稳定 defaultHeaders 的引用
50
53
  const stableHeaders = useMemo(() => defaultHeaders || {}, [defaultHeaders]);
@@ -80,8 +83,9 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
80
83
  showGraph,
81
84
  fallbackToAvailableAssistants,
82
85
  autoRestoreLastSession,
86
+ historyFilter,
83
87
  });
84
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
88
+ }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession, client, legacyMode, historyFilter]);
85
89
 
86
90
  const unionStore = useUnionStore(store, useStore);
87
91
 
@@ -29,6 +29,8 @@ interface ChatProviderProps {
29
29
  onInitError?: (error: any, currentAgent: string) => void;
30
30
  client?: ILangGraphClient;
31
31
  legacyMode?: boolean;
32
+ /** 历史记录筛选的默认参数 */
33
+ historyFilter?: import("../ui-store/createChatStore.js").HistoryFilter;
32
34
  }
33
35
  /**
34
36
  * @zh UnionStore 类型用于合并 store 的 data 和 mutations,使其可以直接访问。
@@ -90,6 +92,7 @@ export const ChatProvider = (props: ChatProviderProps) => {
90
92
  showGraph: props.showGraph || false,
91
93
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants || false,
92
94
  autoRestoreLastSession: props.autoRestoreLastSession || false,
95
+ historyFilter: props.historyFilter,
93
96
  });
94
97
  });
95
98
 
@@ -59,6 +59,8 @@ interface ChatStoreContext {
59
59
  onInit?: (client: LangGraphClient) => void;
60
60
  /** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
61
61
  autoRestoreLastSession?: boolean;
62
+ /** 历史记录筛选的默认参数 */
63
+ historyFilter?: Partial<HistoryFilter>;
62
64
  }
63
65
 
64
66
  // 分页状态类型
@@ -113,13 +115,15 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
113
115
  total: 0,
114
116
  });
115
117
 
116
- // 历史记录筛选状态
117
- const historyFilter = atom<HistoryFilter>({
118
- metadata: null,
119
- status: null,
120
- sortBy: "updated_at",
121
- sortOrder: "desc",
122
- });
118
+ // 历史记录筛选状态 - 使用 context 中的默认值
119
+ const defaultHistoryFilter: HistoryFilter = {
120
+ metadata: context.historyFilter?.metadata ?? null,
121
+ status: context.historyFilter?.status ?? null,
122
+ sortBy: context.historyFilter?.sortBy ?? "updated_at",
123
+ sortOrder: context.historyFilter?.sortOrder ?? "desc",
124
+ };
125
+
126
+ const historyFilter = atom<HistoryFilter>(defaultHistoryFilter);
123
127
 
124
128
  // ============ 内部状态 ============
125
129
 
@@ -611,10 +615,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
611
615
  },
612
616
  resetHistoryFilter() {
613
617
  historyFilter.set({
614
- metadata: null,
615
- status: null,
616
- sortBy: "updated_at",
617
- sortOrder: "desc",
618
+ ...defaultHistoryFilter,
618
619
  });
619
620
  historyPagination.set({
620
621
  ...historyPagination.get(),
@@ -61,6 +61,8 @@ export interface ChatProviderProps {
61
61
  onInitError?: (error: any, currentAgent: string) => void;
62
62
  client?: ILangGraphClient;
63
63
  legacyMode?: boolean;
64
+ /** 历史记录筛选的默认参数 */
65
+ historyFilter?: import("../ui-store/createChatStore.js").HistoryFilter;
64
66
  }
65
67
 
66
68
  /**
@@ -93,6 +95,7 @@ export const useChatProvider = (props: ChatProviderProps) => {
93
95
  showGraph: props.showGraph,
94
96
  fallbackToAvailableAssistants: props.fallbackToAvailableAssistants,
95
97
  autoRestoreLastSession: props.autoRestoreLastSession,
98
+ historyFilter: props.historyFilter,
96
99
  }
97
100
  );
98
101
 
@@ -159,6 +162,10 @@ export const ChatProvider = defineComponent({
159
162
  type: Function as PropType<(error: any, currentAgent: string) => void>,
160
163
  default: undefined,
161
164
  },
165
+ historyFilter: {
166
+ type: Object as PropType<any>,
167
+ default: undefined,
168
+ },
162
169
  },
163
170
  setup(props, { slots }) {
164
171
  const { unionStore } = useChatProvider(props);