balibabu commited on
Commit
11e3284
·
1 Parent(s): 7e4abf1

feat: Fetch conversation list by @tanstack/react-query and displays error message that task_executor does not exist #2088 (#2112)

Browse files

### What problem does this PR solve?

feat: Fetch conversation list by @tanstack/react-query
feat: Displays error message that task_executor does not exist

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/components/file-icon/index.less CHANGED
@@ -1,3 +1,4 @@
1
  .thumbnailImg {
 
2
  max-width: 20px;
3
  }
 
1
  .thumbnailImg {
2
+ display: inline-block;
3
  max-width: 20px;
4
  }
web/src/constants/chat.ts CHANGED
@@ -15,3 +15,10 @@ export enum SharedFrom {
15
  Agent = 'agent',
16
  Chat = 'chat',
17
  }
 
 
 
 
 
 
 
 
15
  Agent = 'agent',
16
  Chat = 'chat',
17
  }
18
+
19
+ export enum ChatSearchParams {
20
+ DialogId = 'dialogId',
21
+ ConversationId = 'conversationId',
22
+ }
23
+
24
+ export const EmptyConversationId = 'empty';
web/src/hooks/chat-hooks.ts CHANGED
@@ -1,131 +1,255 @@
 
1
  import {
2
  IConversation,
3
  IDialog,
4
  IStats,
5
  IToken,
 
6
  } from '@/interfaces/database/chat';
 
 
7
  import chatService from '@/services/chat-service';
 
8
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
 
9
  import dayjs, { Dayjs } from 'dayjs';
10
- import { useCallback, useState } from 'react';
11
- import { useDispatch, useSelector } from 'umi';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- export const useFetchDialogList = () => {
14
- const dispatch = useDispatch();
15
 
16
- const fetchDialogList = useCallback(() => {
17
- return dispatch<any>({ type: 'chatModel/listDialog' });
18
- }, [dispatch]);
19
 
20
- return fetchDialogList;
 
 
 
 
21
  };
22
 
23
- export const useSelectDialogList = () => {
24
- const dialogList: IDialog[] = useSelector(
25
- (state: any) => state.chatModel.dialogList,
26
- );
27
 
28
- return dialogList;
29
- };
30
 
31
- export const useFetchConversationList = () => {
32
- const dispatch = useDispatch();
33
 
34
- const fetchConversationList = useCallback(
35
- async (dialogId: string) => {
36
- if (dialogId) {
37
- dispatch({
38
- type: 'chatModel/listConversation',
39
- payload: { dialog_id: dialogId },
40
- });
 
 
 
 
 
 
 
41
  }
 
 
42
  },
43
- [dispatch],
44
- );
45
 
46
- return fetchConversationList;
47
  };
48
 
49
- export const useSelectConversationList = () => {
50
- const conversationList: IConversation[] = useSelector(
51
- (state: any) => state.chatModel.conversationList,
52
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- return conversationList;
55
  };
56
 
57
- export const useFetchConversation = () => {
58
- const dispatch = useDispatch();
59
-
60
- const fetchConversation = useCallback(
61
- (conversationId: string, needToBeSaved = true) => {
62
- return dispatch<any>({
63
- type: 'chatModel/getConversation',
64
- payload: {
65
- needToBeSaved,
66
- conversation_id: conversationId,
67
- },
68
- });
 
69
  },
70
- [dispatch],
71
- );
72
 
73
- return fetchConversation;
74
  };
75
 
76
- export const useFetchDialog = () => {
77
- const dispatch = useDispatch();
 
 
 
 
 
 
 
 
78
 
79
- const fetchDialog = useCallback(
80
- (dialogId: string, needToBeSaved = true) => {
81
- if (dialogId) {
82
- return dispatch<any>({
83
- type: 'chatModel/getDialog',
84
- payload: { dialog_id: dialogId, needToBeSaved },
85
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
 
87
  },
88
- [dispatch],
89
- );
90
 
91
- return fetchDialog;
92
  };
93
 
94
- export const useRemoveDialog = () => {
95
- const dispatch = useDispatch();
 
96
 
97
- const removeDocument = useCallback(
98
- (dialogIds: Array<string>) => {
99
- return dispatch({
100
- type: 'chatModel/removeDialog',
101
- payload: {
102
- dialog_ids: dialogIds,
103
- },
104
- });
 
 
 
 
 
 
 
 
105
  },
106
- [dispatch],
107
- );
108
 
109
- return removeDocument;
110
  };
111
 
112
- export const useUpdateConversation = () => {
113
- const dispatch = useDispatch();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
- const updateConversation = useCallback(
116
- (payload: any) => {
117
- return dispatch<any>({
118
- type: 'chatModel/setConversation',
119
- payload,
120
- });
 
 
 
 
 
 
 
 
 
121
  },
122
- [dispatch],
123
- );
124
 
125
- return updateConversation;
126
  };
127
 
128
  export const useUpdateNextConversation = () => {
 
129
  const {
130
  data,
131
  isPending: loading,
@@ -134,7 +258,9 @@ export const useUpdateNextConversation = () => {
134
  mutationKey: ['updateConversation'],
135
  mutationFn: async (params: Record<string, any>) => {
136
  const { data } = await chatService.setConversation(params);
137
-
 
 
138
  return data;
139
  },
140
  });
@@ -142,72 +268,34 @@ export const useUpdateNextConversation = () => {
142
  return { data, loading, updateConversation: mutateAsync };
143
  };
144
 
145
- export const useSetDialog = () => {
146
- const dispatch = useDispatch();
147
-
148
- const setDialog = useCallback(
149
- (payload: IDialog) => {
150
- return dispatch<any>({ type: 'chatModel/setDialog', payload });
151
- },
152
- [dispatch],
153
- );
154
-
155
- return setDialog;
156
- };
157
-
158
- export const useRemoveConversation = () => {
159
- const dispatch = useDispatch();
160
-
161
- const removeConversation = useCallback(
162
- (conversationIds: Array<string>, dialogId: string) => {
163
- return dispatch<any>({
164
- type: 'chatModel/removeConversation',
165
- payload: {
166
- dialog_id: dialogId,
167
- conversation_ids: conversationIds,
168
- },
169
- });
170
- },
171
- [dispatch],
172
- );
173
-
174
- return removeConversation;
175
- };
176
 
177
- /*
178
- @deprecated
179
- */
180
- export const useCompleteConversation = () => {
181
- const dispatch = useDispatch();
182
-
183
- const completeConversation = useCallback(
184
- (payload: any) => {
185
- return dispatch<any>({
186
- type: 'chatModel/completeConversation',
187
- payload,
188
  });
 
 
 
 
189
  },
190
- [dispatch],
191
- );
192
 
193
- return completeConversation;
194
  };
 
195
 
196
  // #region API provided for external calls
197
 
198
- export const useCreateToken = (params: Record<string, any>) => {
199
- const dispatch = useDispatch();
200
-
201
- const createToken = useCallback(() => {
202
- return dispatch<any>({
203
- type: 'chatModel/createToken',
204
- payload: params,
205
- });
206
- }, [dispatch, params]);
207
-
208
- return createToken;
209
- };
210
-
211
  export const useCreateNextToken = () => {
212
  const queryClient = useQueryClient();
213
  const {
@@ -303,36 +391,41 @@ export const useFetchNextStats = () => {
303
 
304
  //#region shared chat
305
 
306
- export const useCreateSharedConversation = () => {
307
- const dispatch = useDispatch();
 
 
 
 
 
 
 
308
 
309
- const createSharedConversation = useCallback(
310
- (userId?: string) => {
311
- return dispatch<any>({
312
- type: 'chatModel/createExternalConversation',
313
- payload: { userId },
314
- });
315
  },
316
- [dispatch],
317
- );
318
 
319
- return createSharedConversation;
320
  };
321
 
322
- export const useFetchSharedConversation = () => {
323
- const dispatch = useDispatch();
 
 
 
 
 
 
 
 
 
 
324
 
325
- const fetchSharedConversation = useCallback(
326
- (conversationId: string) => {
327
- return dispatch<any>({
328
- type: 'chatModel/getExternalConversation',
329
- payload: conversationId,
330
- });
331
  },
332
- [dispatch],
333
- );
334
 
335
- return fetchSharedConversation;
336
  };
337
 
338
  //#endregion
 
1
+ import { ChatSearchParams } from '@/constants/chat';
2
  import {
3
  IConversation,
4
  IDialog,
5
  IStats,
6
  IToken,
7
+ Message,
8
  } from '@/interfaces/database/chat';
9
+ import i18n from '@/locales/config';
10
+ import { IClientConversation, IMessage } from '@/pages/chat/interface';
11
  import chatService from '@/services/chat-service';
12
+ import { isConversationIdExist } from '@/utils/chat';
13
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
14
+ import { message } from 'antd';
15
  import dayjs, { Dayjs } from 'dayjs';
16
+ import { useCallback, useMemo, useState } from 'react';
17
+ import { useSearchParams } from 'umi';
18
+ import { v4 as uuid } from 'uuid';
19
+
20
+ //#region logic
21
+
22
+ export const useClickDialogCard = () => {
23
+ const [, setSearchParams] = useSearchParams();
24
+
25
+ const newQueryParameters: URLSearchParams = useMemo(() => {
26
+ return new URLSearchParams();
27
+ }, []);
28
+
29
+ const handleClickDialog = useCallback(
30
+ (dialogId: string) => {
31
+ newQueryParameters.set(ChatSearchParams.DialogId, dialogId);
32
+ // newQueryParameters.set(
33
+ // ChatSearchParams.ConversationId,
34
+ // EmptyConversationId,
35
+ // );
36
+ setSearchParams(newQueryParameters);
37
+ },
38
+ [newQueryParameters, setSearchParams],
39
+ );
40
 
41
+ return { handleClickDialog };
42
+ };
43
 
44
+ export const useGetChatSearchParams = () => {
45
+ const [currentQueryParameters] = useSearchParams();
 
46
 
47
+ return {
48
+ dialogId: currentQueryParameters.get(ChatSearchParams.DialogId) || '',
49
+ conversationId:
50
+ currentQueryParameters.get(ChatSearchParams.ConversationId) || '',
51
+ };
52
  };
53
 
54
+ //#endregion
 
 
 
55
 
56
+ //#region dialog
 
57
 
58
+ export const useFetchNextDialogList = () => {
59
+ const { handleClickDialog } = useClickDialogCard();
60
 
61
+ const {
62
+ data,
63
+ isFetching: loading,
64
+ refetch,
65
+ } = useQuery<IDialog[]>({
66
+ queryKey: ['fetchDialogList'],
67
+ initialData: [],
68
+ gcTime: 0,
69
+ refetchOnWindowFocus: false,
70
+ queryFn: async () => {
71
+ const { data } = await chatService.listDialog();
72
+
73
+ if (data.retcode === 0 && data.data.length > 0) {
74
+ handleClickDialog(data.data[0].id);
75
  }
76
+
77
+ return data?.data ?? [];
78
  },
79
+ });
 
80
 
81
+ return { data, loading, refetch };
82
  };
83
 
84
+ export const useSetNextDialog = () => {
85
+ const queryClient = useQueryClient();
86
+ const {
87
+ data,
88
+ isPending: loading,
89
+ mutateAsync,
90
+ } = useMutation({
91
+ mutationKey: ['setDialog'],
92
+ mutationFn: async (params: IDialog) => {
93
+ const { data } = await chatService.setDialog(params);
94
+ if (data.retcode === 0) {
95
+ queryClient.invalidateQueries({ queryKey: ['fetchDialogList'] });
96
+ message.success(
97
+ i18n.t(`message.${params.id ? 'modified' : 'created'}`),
98
+ );
99
+ }
100
+ return data?.retcode;
101
+ },
102
+ });
103
 
104
+ return { data, loading, setDialog: mutateAsync };
105
  };
106
 
107
+ export const useFetchNextDialog = () => {
108
+ const { dialogId } = useGetChatSearchParams();
109
+
110
+ const { data, isFetching: loading } = useQuery<IDialog>({
111
+ queryKey: ['fetchDialog', dialogId],
112
+ gcTime: 0,
113
+ initialData: {} as IDialog,
114
+ enabled: !!dialogId,
115
+ refetchOnWindowFocus: false,
116
+ queryFn: async () => {
117
+ const { data } = await chatService.getDialog({ dialogId });
118
+
119
+ return data?.data ?? ({} as IDialog);
120
  },
121
+ });
 
122
 
123
+ return { data, loading };
124
  };
125
 
126
+ export const useFetchManualDialog = () => {
127
+ const {
128
+ data,
129
+ isPending: loading,
130
+ mutateAsync,
131
+ } = useMutation({
132
+ mutationKey: ['fetchManualDialog'],
133
+ gcTime: 0,
134
+ mutationFn: async (dialogId: string) => {
135
+ const { data } = await chatService.getDialog({ dialogId });
136
 
137
+ return data;
138
+ },
139
+ });
140
+
141
+ return { data, loading, fetchDialog: mutateAsync };
142
+ };
143
+
144
+ export const useRemoveNextDialog = () => {
145
+ const queryClient = useQueryClient();
146
+
147
+ const {
148
+ data,
149
+ isPending: loading,
150
+ mutateAsync,
151
+ } = useMutation({
152
+ mutationKey: ['removeDialog'],
153
+ mutationFn: async (dialogIds: string[]) => {
154
+ const { data } = await chatService.removeDialog({ dialogIds });
155
+ if (data.retcode === 0) {
156
+ queryClient.invalidateQueries({ queryKey: ['fetchDialogList'] });
157
+ message.success(i18n.t('message.deleted'));
158
  }
159
+ return data.retcode;
160
  },
161
+ });
 
162
 
163
+ return { data, loading, removeDialog: mutateAsync };
164
  };
165
 
166
+ //#endregion
167
+
168
+ //#region conversation
169
 
170
+ export const useFetchNextConversationList = () => {
171
+ const { dialogId } = useGetChatSearchParams();
172
+ const {
173
+ data,
174
+ isFetching: loading,
175
+ refetch,
176
+ } = useQuery<IConversation[]>({
177
+ queryKey: ['fetchConversationList', dialogId],
178
+ initialData: [],
179
+ gcTime: 0,
180
+ refetchOnWindowFocus: false,
181
+ enabled: !!dialogId,
182
+ queryFn: async () => {
183
+ const { data } = await chatService.listConversation({ dialogId });
184
+
185
+ return data?.data;
186
  },
187
+ });
 
188
 
189
+ return { data, loading, refetch };
190
  };
191
 
192
+ export const useFetchNextConversation = () => {
193
+ const { conversationId } = useGetChatSearchParams();
194
+ const {
195
+ data,
196
+ isFetching: loading,
197
+ refetch,
198
+ } = useQuery<IClientConversation>({
199
+ queryKey: ['fetchConversation', conversationId],
200
+ initialData: {} as IClientConversation,
201
+ // enabled: isConversationIdExist(conversationId),
202
+ gcTime: 0,
203
+ refetchOnWindowFocus: false,
204
+ queryFn: async () => {
205
+ if (isConversationIdExist(conversationId)) {
206
+ const { data } = await chatService.getConversation({ conversationId });
207
+ // if (data.retcode === 0 && needToBeSaved) {
208
+ // yield put({
209
+ // type: 'kFModel/fetch_document_thumbnails',
210
+ // payload: {
211
+ // doc_ids: getDocumentIdsFromConversionReference(data.data),
212
+ // },
213
+ // });
214
+ // yield put({ type: 'setCurrentConversation', payload: data.data });
215
+ // }
216
+ const conversation = data?.data ?? {};
217
+
218
+ const messageList =
219
+ conversation?.message?.map((x: Message | IMessage) => ({
220
+ ...x,
221
+ id: 'id' in x && x.id ? x.id : uuid(),
222
+ })) ?? [];
223
+
224
+ return { ...conversation, message: messageList };
225
+ }
226
+ return { message: [] };
227
+ },
228
+ });
229
 
230
+ return { data, loading, refetch };
231
+ };
232
+
233
+ export const useFetchManualConversation = () => {
234
+ const {
235
+ data,
236
+ isPending: loading,
237
+ mutateAsync,
238
+ } = useMutation({
239
+ mutationKey: ['fetchManualConversation'],
240
+ gcTime: 0,
241
+ mutationFn: async (conversationId: string) => {
242
+ const { data } = await chatService.getConversation({ conversationId });
243
+
244
+ return data;
245
  },
246
+ });
 
247
 
248
+ return { data, loading, fetchConversation: mutateAsync };
249
  };
250
 
251
  export const useUpdateNextConversation = () => {
252
+ const queryClient = useQueryClient();
253
  const {
254
  data,
255
  isPending: loading,
 
258
  mutationKey: ['updateConversation'],
259
  mutationFn: async (params: Record<string, any>) => {
260
  const { data } = await chatService.setConversation(params);
261
+ if (data.retcode === 0) {
262
+ queryClient.invalidateQueries({ queryKey: ['fetchConversationList'] });
263
+ }
264
  return data;
265
  },
266
  });
 
268
  return { data, loading, updateConversation: mutateAsync };
269
  };
270
 
271
+ export const useRemoveNextConversation = () => {
272
+ const queryClient = useQueryClient();
273
+ const { dialogId } = useGetChatSearchParams();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
 
275
+ const {
276
+ data,
277
+ isPending: loading,
278
+ mutateAsync,
279
+ } = useMutation({
280
+ mutationKey: ['removeConversation'],
281
+ mutationFn: async (conversationIds: string[]) => {
282
+ const { data } = await chatService.removeConversation({
283
+ conversationIds,
284
+ dialogId,
 
285
  });
286
+ if (data.retcode === 0) {
287
+ queryClient.invalidateQueries({ queryKey: ['fetchConversationList'] });
288
+ }
289
+ return data.retcode;
290
  },
291
+ });
 
292
 
293
+ return { data, loading, removeConversation: mutateAsync };
294
  };
295
+ //#endregion
296
 
297
  // #region API provided for external calls
298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  export const useCreateNextToken = () => {
300
  const queryClient = useQueryClient();
301
  const {
 
391
 
392
  //#region shared chat
393
 
394
+ export const useCreateNextSharedConversation = () => {
395
+ const {
396
+ data,
397
+ isPending: loading,
398
+ mutateAsync,
399
+ } = useMutation({
400
+ mutationKey: ['createSharedConversation'],
401
+ mutationFn: async (userId?: string) => {
402
+ const { data } = await chatService.createExternalConversation({ userId });
403
 
404
+ return data;
 
 
 
 
 
405
  },
406
+ });
 
407
 
408
+ return { data, loading, createSharedConversation: mutateAsync };
409
  };
410
 
411
+ export const useFetchNextSharedConversation = () => {
412
+ const {
413
+ data,
414
+ isPending: loading,
415
+ mutateAsync,
416
+ } = useMutation({
417
+ mutationKey: ['fetchSharedConversation'],
418
+ mutationFn: async (conversationId: string) => {
419
+ const { data } = await chatService.getExternalConversation(
420
+ null,
421
+ conversationId,
422
+ );
423
 
424
+ return data;
 
 
 
 
 
425
  },
426
+ });
 
427
 
428
+ return { data, loading, fetchConversation: mutateAsync };
429
  };
430
 
431
  //#endregion
web/src/interfaces/database/user-setting.ts CHANGED
@@ -28,8 +28,9 @@ export interface ISystemStatus {
28
  mysql: Minio;
29
  redis: Redis;
30
  task_executor: {
 
31
  status: string;
32
- elapsed: TaskExecutorElapsed;
33
  };
34
  }
35
 
 
28
  mysql: Minio;
29
  redis: Redis;
30
  task_executor: {
31
+ error?: string;
32
  status: string;
33
+ elapsed?: TaskExecutorElapsed;
34
  };
35
  }
36
 
web/src/pages/chat/chat-container/index.tsx CHANGED
@@ -8,7 +8,6 @@ import {
8
  useFetchConversationOnMount,
9
  useGetFileIcon,
10
  useGetSendButtonDisabled,
11
- useSelectConversationLoading,
12
  useSendButtonDisabled,
13
  useSendMessage,
14
  } from '../hooks';
@@ -16,6 +15,7 @@ import { buildMessageItemReference } from '../utils';
16
 
17
  import MessageInput from '@/components/message-input';
18
  import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
 
19
  import styles from './index.less';
20
 
21
  const ChatContainer = () => {
@@ -26,6 +26,7 @@ const ChatContainer = () => {
26
  removeLatestMessage,
27
  addNewestAnswer,
28
  conversationId,
 
29
  } = useFetchConversationOnMount();
30
  const {
31
  handleInputChange,
@@ -43,7 +44,6 @@ const ChatContainer = () => {
43
  const disabled = useGetSendButtonDisabled();
44
  const sendDisabled = useSendButtonDisabled(value);
45
  useGetFileIcon();
46
- const loading = useSelectConversationLoading();
47
  const { data: userInfo } = useFetchUserInfo();
48
  const { createConversationBeforeUploadDocument } =
49
  useCreateConversationBeforeUploadDocument();
@@ -104,4 +104,4 @@ const ChatContainer = () => {
104
  );
105
  };
106
 
107
- export default ChatContainer;
 
8
  useFetchConversationOnMount,
9
  useGetFileIcon,
10
  useGetSendButtonDisabled,
 
11
  useSendButtonDisabled,
12
  useSendMessage,
13
  } from '../hooks';
 
15
 
16
  import MessageInput from '@/components/message-input';
17
  import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
18
+ import { memo } from 'react';
19
  import styles from './index.less';
20
 
21
  const ChatContainer = () => {
 
26
  removeLatestMessage,
27
  addNewestAnswer,
28
  conversationId,
29
+ loading,
30
  } = useFetchConversationOnMount();
31
  const {
32
  handleInputChange,
 
44
  const disabled = useGetSendButtonDisabled();
45
  const sendDisabled = useSendButtonDisabled(value);
46
  useGetFileIcon();
 
47
  const { data: userInfo } = useFetchUserInfo();
48
  const { createConversationBeforeUploadDocument } =
49
  useCreateConversationBeforeUploadDocument();
 
104
  );
105
  };
106
 
107
+ export default memo(ChatContainer);
web/src/pages/chat/hooks.ts CHANGED
@@ -1,16 +1,16 @@
1
  import { MessageType } from '@/constants/chat';
2
  import { fileIconMap } from '@/constants/common';
3
  import {
4
- useFetchConversation,
5
- useFetchConversationList,
6
- useFetchDialog,
7
- useFetchDialogList,
8
- useRemoveConversation,
9
- useRemoveDialog,
10
- useSelectConversationList,
11
- useSelectDialogList,
12
- useSetDialog,
13
- useUpdateConversation,
14
  } from '@/hooks/chat-hooks';
15
  import {
16
  useSetModalState,
@@ -18,7 +18,6 @@ import {
18
  useTranslate,
19
  } from '@/hooks/common-hooks';
20
  import { useSendMessageWithSse } from '@/hooks/logic-hooks';
21
- import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
22
  import {
23
  IAnswer,
24
  IConversation,
@@ -27,6 +26,8 @@ import {
27
  } from '@/interfaces/database/chat';
28
  import { IChunk } from '@/interfaces/database/knowledge';
29
  import { getFileExtension } from '@/utils';
 
 
30
  import omit from 'lodash/omit';
31
  import trim from 'lodash/trim';
32
  import {
@@ -37,7 +38,7 @@ import {
37
  useRef,
38
  useState,
39
  } from 'react';
40
- import { useDispatch, useSearchParams, useSelector } from 'umi';
41
  import { v4 as uuid } from 'uuid';
42
  import { ChatSearchParams } from './constants';
43
  import {
@@ -45,70 +46,20 @@ import {
45
  IMessage,
46
  VariableTableDataType,
47
  } from './interface';
48
- import { ChatModelState } from './model';
49
- import { isConversationIdExist } from './utils';
50
 
51
  export const useSelectCurrentDialog = () => {
52
- const currentDialog: IDialog = useSelector(
53
- (state: any) => state.chatModel.currentDialog,
54
- );
55
-
56
- return currentDialog;
57
- };
58
-
59
- export const useFetchDialogOnMount = (
60
- dialogId: string,
61
- visible: boolean,
62
- ): IDialog => {
63
- const currentDialog: IDialog = useSelectCurrentDialog();
64
- const fetchDialog = useFetchDialog();
65
-
66
- useEffect(() => {
67
- if (dialogId && visible) {
68
- fetchDialog(dialogId);
69
- }
70
- }, [dialogId, fetchDialog, visible]);
71
-
72
- return currentDialog;
73
- };
74
-
75
- export const useSetCurrentDialog = () => {
76
- const dispatch = useDispatch();
77
-
78
- const currentDialog: IDialog = useSelector(
79
- (state: any) => state.chatModel.currentDialog,
80
- );
81
-
82
- const setCurrentDialog = useCallback(
83
- (dialogId: string) => {
84
- dispatch({
85
- type: 'chatModel/setCurrentDialog',
86
- payload: { id: dialogId },
87
- });
88
  },
89
- [dispatch],
90
- );
91
 
92
- return { currentDialog, setCurrentDialog };
93
- };
94
-
95
- export const useResetCurrentDialog = () => {
96
- const dispatch = useDispatch();
97
-
98
- const resetCurrentDialog = useCallback(() => {
99
- dispatch({
100
- type: 'chatModel/setCurrentDialog',
101
- payload: {},
102
- });
103
- }, [dispatch]);
104
-
105
- return { resetCurrentDialog };
106
  };
107
 
108
  export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
109
- const currentDialog: IDialog = useSelector(
110
- (state: any) => state.chatModel.currentDialog,
111
- );
112
 
113
  const finalParameters: VariableTableDataType[] = useMemo(() => {
114
  const parameters = currentDialog?.prompt_config?.parameters ?? [];
@@ -129,83 +80,15 @@ export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
129
  export const useDeleteDialog = () => {
130
  const showDeleteConfirm = useShowDeleteConfirm();
131
 
132
- const removeDocument = useRemoveDialog();
133
 
134
  const onRemoveDialog = (dialogIds: Array<string>) => {
135
- showDeleteConfirm({ onOk: () => removeDocument(dialogIds) });
136
  };
137
 
138
  return { onRemoveDialog };
139
  };
140
 
141
- export const useGetChatSearchParams = () => {
142
- const [currentQueryParameters] = useSearchParams();
143
-
144
- return {
145
- dialogId: currentQueryParameters.get(ChatSearchParams.DialogId) || '',
146
- conversationId:
147
- currentQueryParameters.get(ChatSearchParams.ConversationId) || '',
148
- };
149
- };
150
-
151
- export const useSetCurrentConversation = () => {
152
- const dispatch = useDispatch();
153
-
154
- const setCurrentConversation = useCallback(
155
- (currentConversation: IClientConversation) => {
156
- dispatch({
157
- type: 'chatModel/setCurrentConversation',
158
- payload: currentConversation,
159
- });
160
- },
161
- [dispatch],
162
- );
163
-
164
- return setCurrentConversation;
165
- };
166
-
167
- export const useClickDialogCard = () => {
168
- const [currentQueryParameters, setSearchParams] = useSearchParams();
169
-
170
- const newQueryParameters: URLSearchParams = useMemo(() => {
171
- return new URLSearchParams();
172
- }, []);
173
-
174
- const handleClickDialog = useCallback(
175
- (dialogId: string) => {
176
- newQueryParameters.set(ChatSearchParams.DialogId, dialogId);
177
- // newQueryParameters.set(
178
- // ChatSearchParams.ConversationId,
179
- // EmptyConversationId,
180
- // );
181
- setSearchParams(newQueryParameters);
182
- },
183
- [newQueryParameters, setSearchParams],
184
- );
185
-
186
- return { handleClickDialog };
187
- };
188
-
189
- export const useSelectFirstDialogOnMount = () => {
190
- const fetchDialogList = useFetchDialogList();
191
- const dialogList = useSelectDialogList();
192
-
193
- const { handleClickDialog } = useClickDialogCard();
194
-
195
- const fetchList = useCallback(async () => {
196
- const data = await fetchDialogList();
197
- if (data.retcode === 0 && data.data.length > 0) {
198
- handleClickDialog(data.data[0].id);
199
- }
200
- }, [fetchDialogList, handleClickDialog]);
201
-
202
- useEffect(() => {
203
- fetchList();
204
- }, [fetchList]);
205
-
206
- return dialogList;
207
- };
208
-
209
  export const useHandleItemHover = () => {
210
  const [activated, setActivated] = useState<string>('');
211
 
@@ -226,9 +109,8 @@ export const useHandleItemHover = () => {
226
 
227
  export const useEditDialog = () => {
228
  const [dialog, setDialog] = useState<IDialog>({} as IDialog);
229
- const fetchDialog = useFetchDialog();
230
- const submitDialog = useSetDialog();
231
- const loading = useOneNamespaceEffectsLoading('chatModel', ['setDialog']);
232
 
233
  const {
234
  visible: dialogEditVisible,
@@ -255,7 +137,7 @@ export const useEditDialog = () => {
255
  const handleShowDialogEditModal = useCallback(
256
  async (dialogId?: string) => {
257
  if (dialogId) {
258
- const ret = await fetchDialog(dialogId, false);
259
  if (ret.retcode === 0) {
260
  setDialog(ret.data);
261
  }
@@ -282,25 +164,15 @@ export const useEditDialog = () => {
282
 
283
  //#region conversation
284
 
285
- export const useFetchConversationListOnMount = () => {
286
- const conversationList = useSelectConversationList();
287
- const { dialogId } = useGetChatSearchParams();
288
- const fetchConversationList = useFetchConversationList();
289
-
290
- useEffect(() => {
291
- fetchConversationList(dialogId);
292
- }, [fetchConversationList, dialogId]);
293
-
294
- return conversationList;
295
- };
296
-
297
  export const useSelectDerivedConversationList = () => {
 
 
298
  const [list, setList] = useState<Array<IConversation>>([]);
299
- let chatModel: ChatModelState = useSelector((state: any) => state.chatModel);
300
- const { conversationList, currentDialog } = chatModel;
301
  const { dialogId } = useGetChatSearchParams();
302
  const prologue = currentDialog?.prompt_config?.prologue ?? '';
303
- const { t } = useTranslate('chat');
304
  const addTemporaryConversation = useCallback(() => {
305
  setList((pre) => {
306
  if (dialogId) {
@@ -329,7 +201,7 @@ export const useSelectDerivedConversationList = () => {
329
  addTemporaryConversation();
330
  }, [addTemporaryConversation]);
331
 
332
- return { list, addTemporaryConversation };
333
  };
334
 
335
  export const useClickConversationCard = () => {
@@ -352,7 +224,7 @@ export const useClickConversationCard = () => {
352
 
353
  export const useSetConversation = () => {
354
  const { dialogId } = useGetChatSearchParams();
355
- const updateConversation = useUpdateConversation();
356
 
357
  const setConversation = useCallback(
358
  (message: string) => {
@@ -376,11 +248,8 @@ export const useSetConversation = () => {
376
  export const useSelectCurrentConversation = () => {
377
  const [currentConversation, setCurrentConversation] =
378
  useState<IClientConversation>({} as IClientConversation);
379
-
380
- const conversation: IClientConversation = useSelector(
381
- (state: any) => state.chatModel.currentConversation,
382
- );
383
- const dialog = useSelectCurrentDialog();
384
  const { conversationId, dialogId } = useGetChatSearchParams();
385
 
386
  const addNewestConversation = useCallback(
@@ -474,6 +343,7 @@ export const useSelectCurrentConversation = () => {
474
  addNewestConversation,
475
  removeLatestMessage,
476
  addNewestAnswer,
 
477
  };
478
  };
479
 
@@ -495,25 +365,15 @@ export const useScrollToBottom = (currentConversation: IClientConversation) => {
495
 
496
  export const useFetchConversationOnMount = () => {
497
  const { conversationId } = useGetChatSearchParams();
498
- const fetchConversation = useFetchConversation();
499
  const {
500
  currentConversation,
501
  addNewestConversation,
502
  removeLatestMessage,
503
  addNewestAnswer,
 
504
  } = useSelectCurrentConversation();
505
  const ref = useScrollToBottom(currentConversation);
506
 
507
- const fetchConversationOnMount = useCallback(() => {
508
- if (isConversationIdExist(conversationId)) {
509
- fetchConversation(conversationId);
510
- }
511
- }, [fetchConversation, conversationId]);
512
-
513
- useEffect(() => {
514
- fetchConversationOnMount();
515
- }, [fetchConversationOnMount]);
516
-
517
  return {
518
  currentConversation,
519
  addNewestConversation,
@@ -521,6 +381,7 @@ export const useFetchConversationOnMount = () => {
521
  removeLatestMessage,
522
  addNewestAnswer,
523
  conversationId,
 
524
  };
525
  };
526
 
@@ -655,13 +516,12 @@ export const useGetFileIcon = () => {
655
  };
656
 
657
  export const useDeleteConversation = () => {
658
- const { dialogId } = useGetChatSearchParams();
659
  const { handleClickConversation } = useClickConversationCard();
660
  const showDeleteConfirm = useShowDeleteConfirm();
661
- const removeConversation = useRemoveConversation();
662
 
663
  const deleteConversation = (conversationIds: Array<string>) => async () => {
664
- const ret = await removeConversation(conversationIds, dialogId);
665
  if (ret === 0) {
666
  handleClickConversation('');
667
  }
@@ -679,13 +539,13 @@ export const useRenameConversation = () => {
679
  const [conversation, setConversation] = useState<IClientConversation>(
680
  {} as IClientConversation,
681
  );
682
- const fetchConversation = useFetchConversation();
683
  const {
684
  visible: conversationRenameVisible,
685
  hideModal: hideConversationRenameModal,
686
  showModal: showConversationRenameModal,
687
  } = useSetModalState();
688
- const updateConversation = useUpdateConversation();
689
 
690
  const onConversationRenameOk = useCallback(
691
  async (name: string) => {
@@ -702,13 +562,9 @@ export const useRenameConversation = () => {
702
  [updateConversation, conversation, hideConversationRenameModal],
703
  );
704
 
705
- const loading = useOneNamespaceEffectsLoading('chatModel', [
706
- 'setConversation',
707
- ]);
708
-
709
  const handleShowConversationRenameModal = useCallback(
710
  async (conversationId: string) => {
711
- const ret = await fetchConversation(conversationId, false);
712
  if (ret.retcode === 0) {
713
  setConversation(ret.data);
714
  }
@@ -751,16 +607,6 @@ export const useClickDrawer = () => {
751
  };
752
  };
753
 
754
- export const useSelectDialogListLoading = () => {
755
- return useOneNamespaceEffectsLoading('chatModel', ['listDialog']);
756
- };
757
- export const useSelectConversationListLoading = () => {
758
- return useOneNamespaceEffectsLoading('chatModel', ['listConversation']);
759
- };
760
- export const useSelectConversationLoading = () => {
761
- return useOneNamespaceEffectsLoading('chatModel', ['getConversation']);
762
- };
763
-
764
  export const useGetSendButtonDisabled = () => {
765
  const { dialogId, conversationId } = useGetChatSearchParams();
766
 
 
1
  import { MessageType } from '@/constants/chat';
2
  import { fileIconMap } from '@/constants/common';
3
  import {
4
+ useFetchManualConversation,
5
+ useFetchManualDialog,
6
+ useFetchNextConversation,
7
+ useFetchNextConversationList,
8
+ useFetchNextDialog,
9
+ useGetChatSearchParams,
10
+ useRemoveNextConversation,
11
+ useRemoveNextDialog,
12
+ useSetNextDialog,
13
+ useUpdateNextConversation,
14
  } from '@/hooks/chat-hooks';
15
  import {
16
  useSetModalState,
 
18
  useTranslate,
19
  } from '@/hooks/common-hooks';
20
  import { useSendMessageWithSse } from '@/hooks/logic-hooks';
 
21
  import {
22
  IAnswer,
23
  IConversation,
 
26
  } from '@/interfaces/database/chat';
27
  import { IChunk } from '@/interfaces/database/knowledge';
28
  import { getFileExtension } from '@/utils';
29
+ import { useMutationState } from '@tanstack/react-query';
30
+ import { get } from 'lodash';
31
  import omit from 'lodash/omit';
32
  import trim from 'lodash/trim';
33
  import {
 
38
  useRef,
39
  useState,
40
  } from 'react';
41
+ import { useSearchParams } from 'umi';
42
  import { v4 as uuid } from 'uuid';
43
  import { ChatSearchParams } from './constants';
44
  import {
 
46
  IMessage,
47
  VariableTableDataType,
48
  } from './interface';
 
 
49
 
50
  export const useSelectCurrentDialog = () => {
51
+ const data = useMutationState({
52
+ filters: { mutationKey: ['fetchDialog'] },
53
+ select: (mutation) => {
54
+ return get(mutation, 'state.data.data', {});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  },
56
+ });
 
57
 
58
+ return (data.at(-1) ?? {}) as IDialog;
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  };
60
 
61
  export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
62
+ const { data: currentDialog } = useFetchNextDialog();
 
 
63
 
64
  const finalParameters: VariableTableDataType[] = useMemo(() => {
65
  const parameters = currentDialog?.prompt_config?.parameters ?? [];
 
80
  export const useDeleteDialog = () => {
81
  const showDeleteConfirm = useShowDeleteConfirm();
82
 
83
+ const { removeDialog } = useRemoveNextDialog();
84
 
85
  const onRemoveDialog = (dialogIds: Array<string>) => {
86
+ showDeleteConfirm({ onOk: () => removeDialog(dialogIds) });
87
  };
88
 
89
  return { onRemoveDialog };
90
  };
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  export const useHandleItemHover = () => {
93
  const [activated, setActivated] = useState<string>('');
94
 
 
109
 
110
  export const useEditDialog = () => {
111
  const [dialog, setDialog] = useState<IDialog>({} as IDialog);
112
+ const { fetchDialog } = useFetchManualDialog();
113
+ const { setDialog: submitDialog, loading } = useSetNextDialog();
 
114
 
115
  const {
116
  visible: dialogEditVisible,
 
137
  const handleShowDialogEditModal = useCallback(
138
  async (dialogId?: string) => {
139
  if (dialogId) {
140
+ const ret = await fetchDialog(dialogId);
141
  if (ret.retcode === 0) {
142
  setDialog(ret.data);
143
  }
 
164
 
165
  //#region conversation
166
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  export const useSelectDerivedConversationList = () => {
168
+ const { t } = useTranslate('chat');
169
+
170
  const [list, setList] = useState<Array<IConversation>>([]);
171
+ const { data: currentDialog } = useFetchNextDialog();
172
+ const { data: conversationList, loading } = useFetchNextConversationList();
173
  const { dialogId } = useGetChatSearchParams();
174
  const prologue = currentDialog?.prompt_config?.prologue ?? '';
175
+
176
  const addTemporaryConversation = useCallback(() => {
177
  setList((pre) => {
178
  if (dialogId) {
 
201
  addTemporaryConversation();
202
  }, [addTemporaryConversation]);
203
 
204
+ return { list, addTemporaryConversation, loading };
205
  };
206
 
207
  export const useClickConversationCard = () => {
 
224
 
225
  export const useSetConversation = () => {
226
  const { dialogId } = useGetChatSearchParams();
227
+ const { updateConversation } = useUpdateNextConversation();
228
 
229
  const setConversation = useCallback(
230
  (message: string) => {
 
248
  export const useSelectCurrentConversation = () => {
249
  const [currentConversation, setCurrentConversation] =
250
  useState<IClientConversation>({} as IClientConversation);
251
+ const { data: conversation, loading } = useFetchNextConversation();
252
+ const { data: dialog } = useFetchNextDialog();
 
 
 
253
  const { conversationId, dialogId } = useGetChatSearchParams();
254
 
255
  const addNewestConversation = useCallback(
 
343
  addNewestConversation,
344
  removeLatestMessage,
345
  addNewestAnswer,
346
+ loading,
347
  };
348
  };
349
 
 
365
 
366
  export const useFetchConversationOnMount = () => {
367
  const { conversationId } = useGetChatSearchParams();
 
368
  const {
369
  currentConversation,
370
  addNewestConversation,
371
  removeLatestMessage,
372
  addNewestAnswer,
373
+ loading,
374
  } = useSelectCurrentConversation();
375
  const ref = useScrollToBottom(currentConversation);
376
 
 
 
 
 
 
 
 
 
 
 
377
  return {
378
  currentConversation,
379
  addNewestConversation,
 
381
  removeLatestMessage,
382
  addNewestAnswer,
383
  conversationId,
384
+ loading,
385
  };
386
  };
387
 
 
516
  };
517
 
518
  export const useDeleteConversation = () => {
 
519
  const { handleClickConversation } = useClickConversationCard();
520
  const showDeleteConfirm = useShowDeleteConfirm();
521
+ const { removeConversation } = useRemoveNextConversation();
522
 
523
  const deleteConversation = (conversationIds: Array<string>) => async () => {
524
+ const ret = await removeConversation(conversationIds);
525
  if (ret === 0) {
526
  handleClickConversation('');
527
  }
 
539
  const [conversation, setConversation] = useState<IClientConversation>(
540
  {} as IClientConversation,
541
  );
542
+ const { fetchConversation } = useFetchManualConversation();
543
  const {
544
  visible: conversationRenameVisible,
545
  hideModal: hideConversationRenameModal,
546
  showModal: showConversationRenameModal,
547
  } = useSetModalState();
548
+ const { updateConversation, loading } = useUpdateNextConversation();
549
 
550
  const onConversationRenameOk = useCallback(
551
  async (name: string) => {
 
562
  [updateConversation, conversation, hideConversationRenameModal],
563
  );
564
 
 
 
 
 
565
  const handleShowConversationRenameModal = useCallback(
566
  async (conversationId: string) => {
567
+ const ret = await fetchConversation(conversationId);
568
  if (ret.retcode === 0) {
569
  setConversation(ret.data);
570
  }
 
607
  };
608
  };
609
 
 
 
 
 
 
 
 
 
 
 
610
  export const useGetSendButtonDisabled = () => {
611
  const { dialogId, conversationId } = useGetChatSearchParams();
612
 
web/src/pages/chat/index.tsx CHANGED
@@ -26,22 +26,20 @@ import ChatConfigurationModal from './chat-configuration-modal';
26
  import ChatContainer from './chat-container';
27
  import {
28
  useClickConversationCard,
29
- useClickDialogCard,
30
  useDeleteConversation,
31
  useDeleteDialog,
32
  useEditDialog,
33
- useFetchConversationListOnMount,
34
- useFetchDialogOnMount,
35
- useGetChatSearchParams,
36
  useHandleItemHover,
37
  useRenameConversation,
38
- useSelectConversationListLoading,
39
  useSelectDerivedConversationList,
40
- useSelectDialogListLoading,
41
- useSelectFirstDialogOnMount,
42
  } from './hooks';
43
 
44
  import ChatOverviewModal from '@/components/api-service/chat-overview-modal';
 
 
 
 
 
45
  import { useSetModalState, useTranslate } from '@/hooks/common-hooks';
46
  import { useSetSelectedRecord } from '@/hooks/logic-hooks';
47
  import { IDialog } from '@/interfaces/database/chat';
@@ -50,14 +48,17 @@ import styles from './index.less';
50
  const { Text } = Typography;
51
 
52
  const Chat = () => {
53
- const dialogList = useSelectFirstDialogOnMount();
54
  const { onRemoveDialog } = useDeleteDialog();
55
  const { onRemoveConversation } = useDeleteConversation();
56
  const { handleClickDialog } = useClickDialogCard();
57
  const { handleClickConversation } = useClickConversationCard();
58
  const { dialogId, conversationId } = useGetChatSearchParams();
59
- const { list: conversationList, addTemporaryConversation } =
60
- useSelectDerivedConversationList();
 
 
 
61
  const { activated, handleItemEnter, handleItemLeave } = useHandleItemHover();
62
  const {
63
  activated: conversationActivated,
@@ -81,8 +82,6 @@ const Chat = () => {
81
  hideDialogEditModal,
82
  showDialogEditModal,
83
  } = useEditDialog();
84
- const dialogLoading = useSelectDialogListLoading();
85
- const conversationLoading = useSelectConversationListLoading();
86
  const { t } = useTranslate('chat');
87
  const {
88
  visible: overviewVisible,
@@ -91,8 +90,6 @@ const Chat = () => {
91
  } = useSetModalState();
92
  const { currentRecord, setRecord } = useSetSelectedRecord<IDialog>();
93
 
94
- useFetchDialogOnMount(dialogId, true);
95
-
96
  const handleAppCardEnter = (id: string) => () => {
97
  handleItemEnter(id);
98
  };
@@ -236,8 +233,6 @@ const Chat = () => {
236
  return appItems;
237
  };
238
 
239
- useFetchConversationListOnMount();
240
-
241
  return (
242
  <Flex className={styles.chatWrapper}>
243
  <Flex className={styles.chatAppWrapper}>
 
26
  import ChatContainer from './chat-container';
27
  import {
28
  useClickConversationCard,
 
29
  useDeleteConversation,
30
  useDeleteDialog,
31
  useEditDialog,
 
 
 
32
  useHandleItemHover,
33
  useRenameConversation,
 
34
  useSelectDerivedConversationList,
 
 
35
  } from './hooks';
36
 
37
  import ChatOverviewModal from '@/components/api-service/chat-overview-modal';
38
+ import {
39
+ useClickDialogCard,
40
+ useFetchNextDialogList,
41
+ useGetChatSearchParams,
42
+ } from '@/hooks/chat-hooks';
43
  import { useSetModalState, useTranslate } from '@/hooks/common-hooks';
44
  import { useSetSelectedRecord } from '@/hooks/logic-hooks';
45
  import { IDialog } from '@/interfaces/database/chat';
 
48
  const { Text } = Typography;
49
 
50
  const Chat = () => {
51
+ const { data: dialogList, loading: dialogLoading } = useFetchNextDialogList();
52
  const { onRemoveDialog } = useDeleteDialog();
53
  const { onRemoveConversation } = useDeleteConversation();
54
  const { handleClickDialog } = useClickDialogCard();
55
  const { handleClickConversation } = useClickConversationCard();
56
  const { dialogId, conversationId } = useGetChatSearchParams();
57
+ const {
58
+ list: conversationList,
59
+ addTemporaryConversation,
60
+ loading: conversationLoading,
61
+ } = useSelectDerivedConversationList();
62
  const { activated, handleItemEnter, handleItemLeave } = useHandleItemHover();
63
  const {
64
  activated: conversationActivated,
 
82
  hideDialogEditModal,
83
  showDialogEditModal,
84
  } = useEditDialog();
 
 
85
  const { t } = useTranslate('chat');
86
  const {
87
  visible: overviewVisible,
 
90
  } = useSetModalState();
91
  const { currentRecord, setRecord } = useSetSelectedRecord<IDialog>();
92
 
 
 
93
  const handleAppCardEnter = (id: string) => () => {
94
  handleItemEnter(id);
95
  };
 
233
  return appItems;
234
  };
235
 
 
 
236
  return (
237
  <Flex className={styles.chatWrapper}>
238
  <Flex className={styles.chatAppWrapper}>
web/src/pages/chat/shared-hooks.ts CHANGED
@@ -1,10 +1,9 @@
1
  import { MessageType, SharedFrom } from '@/constants/chat';
2
  import {
3
- useCreateSharedConversation,
4
- useFetchSharedConversation,
5
  } from '@/hooks/chat-hooks';
6
  import { useSendMessageWithSse } from '@/hooks/logic-hooks';
7
- import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
8
  import { IAnswer, Message } from '@/interfaces/database/chat';
9
  import api from '@/utils/api';
10
  import omit from 'lodash/omit';
@@ -25,12 +24,12 @@ export const useCreateSharedConversationOnMount = () => {
25
  const [currentQueryParameters] = useSearchParams();
26
  const [conversationId, setConversationId] = useState('');
27
 
28
- const createConversation = useCreateSharedConversation();
 
29
  const sharedId = currentQueryParameters.get('shared_id');
30
  const userId = currentQueryParameters.get('user_id');
31
 
32
  const setConversation = useCallback(async () => {
33
- console.info(sharedId);
34
  if (sharedId) {
35
  const data = await createConversation(userId ?? undefined);
36
  const id = data.data?.id;
@@ -50,10 +49,7 @@ export const useCreateSharedConversationOnMount = () => {
50
  export const useSelectCurrentSharedConversation = (conversationId: string) => {
51
  const [currentConversation, setCurrentConversation] =
52
  useState<IClientConversation>({} as IClientConversation);
53
- const fetchConversation = useFetchSharedConversation();
54
- const loading = useOneNamespaceEffectsLoading('chatModel', [
55
- 'getExternalConversation',
56
- ]);
57
 
58
  const ref = useScrollToBottom(currentConversation);
59
 
@@ -147,7 +143,8 @@ export const useSendSharedMessage = (
147
  addNewestAnswer: (answer: IAnswer) => void,
148
  ) => {
149
  const conversationId = conversation.id;
150
- const setConversation = useCreateSharedConversation();
 
151
  const { handleInputChange, value, setValue } = useHandleMessageInputChange();
152
 
153
  const { send, answer, done } = useSendMessageWithSse(
 
1
  import { MessageType, SharedFrom } from '@/constants/chat';
2
  import {
3
+ useCreateNextSharedConversation,
4
+ useFetchNextSharedConversation,
5
  } from '@/hooks/chat-hooks';
6
  import { useSendMessageWithSse } from '@/hooks/logic-hooks';
 
7
  import { IAnswer, Message } from '@/interfaces/database/chat';
8
  import api from '@/utils/api';
9
  import omit from 'lodash/omit';
 
24
  const [currentQueryParameters] = useSearchParams();
25
  const [conversationId, setConversationId] = useState('');
26
 
27
+ const { createSharedConversation: createConversation } =
28
+ useCreateNextSharedConversation();
29
  const sharedId = currentQueryParameters.get('shared_id');
30
  const userId = currentQueryParameters.get('user_id');
31
 
32
  const setConversation = useCallback(async () => {
 
33
  if (sharedId) {
34
  const data = await createConversation(userId ?? undefined);
35
  const id = data.data?.id;
 
49
  export const useSelectCurrentSharedConversation = (conversationId: string) => {
50
  const [currentConversation, setCurrentConversation] =
51
  useState<IClientConversation>({} as IClientConversation);
52
+ const { fetchConversation, loading } = useFetchNextSharedConversation();
 
 
 
53
 
54
  const ref = useScrollToBottom(currentConversation);
55
 
 
143
  addNewestAnswer: (answer: IAnswer) => void,
144
  ) => {
145
  const conversationId = conversation.id;
146
+ const { createSharedConversation: setConversation } =
147
+ useCreateNextSharedConversation();
148
  const { handleInputChange, value, setValue } = useHandleMessageInputChange();
149
 
150
  const { send, answer, done } = useSendMessageWithSse(
web/src/pages/force-graph/input-upload.tsx CHANGED
@@ -1,72 +1,14 @@
1
  import { Authorization } from '@/constants/authorization';
2
  import { getAuthorization } from '@/utils/authorization-util';
3
  import { PlusOutlined } from '@ant-design/icons';
4
- import type { GetProp, UploadFile, UploadProps } from 'antd';
5
  import { Image, Input, Upload } from 'antd';
6
  import { useState } from 'react';
7
- import { useGetChatSearchParams } from '../chat/hooks';
8
-
9
- type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
10
-
11
- const getBase64 = (file: FileType): Promise<string> =>
12
- new Promise((resolve, reject) => {
13
- const reader = new FileReader();
14
- reader.readAsDataURL(file);
15
- reader.onload = () => resolve(reader.result as string);
16
- reader.onerror = (error) => reject(error);
17
- });
18
 
19
  const InputWithUpload = () => {
20
  const [previewOpen, setPreviewOpen] = useState(false);
21
  const [previewImage, setPreviewImage] = useState('');
22
- const { conversationId } = useGetChatSearchParams();
23
- const [fileList, setFileList] = useState<UploadFile[]>([
24
- {
25
- uid: '-1',
26
- name: 'image.png',
27
- status: 'done',
28
- url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
29
- },
30
- {
31
- uid: '-2',
32
- name: 'image.png',
33
- status: 'done',
34
- url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
35
- },
36
- {
37
- uid: '-3',
38
- name: 'image.png',
39
- status: 'done',
40
- url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
41
- },
42
- {
43
- uid: '-4',
44
- name: 'image.png',
45
- status: 'done',
46
- url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
47
- },
48
- {
49
- uid: '-xxx',
50
- percent: 50,
51
- name: 'image.png',
52
- status: 'uploading',
53
- url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
54
- },
55
- {
56
- uid: '-5',
57
- name: 'image.png',
58
- status: 'error',
59
- },
60
- ]);
61
-
62
- const handlePreview = async (file: UploadFile) => {
63
- if (!file.url && !file.preview) {
64
- file.preview = await getBase64(file.originFileObj as FileType);
65
- }
66
-
67
- setPreviewImage(file.url || (file.preview as string));
68
- setPreviewOpen(true);
69
- };
70
 
71
  const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) =>
72
  setFileList(newFileList);
@@ -84,7 +26,6 @@ const InputWithUpload = () => {
84
  action="/v1/document/upload_and_parse"
85
  listType="picture-card"
86
  fileList={fileList}
87
- onPreview={handlePreview}
88
  onChange={handleChange}
89
  multiple
90
  headers={{ [Authorization]: getAuthorization() }}
 
1
  import { Authorization } from '@/constants/authorization';
2
  import { getAuthorization } from '@/utils/authorization-util';
3
  import { PlusOutlined } from '@ant-design/icons';
4
+ import type { UploadFile, UploadProps } from 'antd';
5
  import { Image, Input, Upload } from 'antd';
6
  import { useState } from 'react';
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  const InputWithUpload = () => {
9
  const [previewOpen, setPreviewOpen] = useState(false);
10
  const [previewImage, setPreviewImage] = useState('');
11
+ const [fileList, setFileList] = useState<UploadFile[]>([]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) =>
14
  setFileList(newFileList);
 
26
  action="/v1/document/upload_and_parse"
27
  listType="picture-card"
28
  fileList={fileList}
 
29
  onChange={handleChange}
30
  multiple
31
  headers={{ [Authorization]: getAuthorization() }}
web/src/pages/user-setting/setting-system/index.tsx CHANGED
@@ -70,9 +70,13 @@ const SystemInfo = () => {
70
  key={key}
71
  >
72
  {key === 'task_executor' ? (
73
- <TaskBarChat
74
- data={info.elapsed as TaskExecutorElapsed}
75
- ></TaskBarChat>
 
 
 
 
76
  ) : (
77
  Object.keys(info)
78
  .filter((x) => x !== 'status')
 
70
  key={key}
71
  >
72
  {key === 'task_executor' ? (
73
+ info?.elapsed ? (
74
+ <TaskBarChat
75
+ data={info.elapsed as TaskExecutorElapsed}
76
+ ></TaskBarChat>
77
+ ) : (
78
+ <Text className={styles.error}>{info.error}</Text>
79
+ )
80
  ) : (
81
  Object.keys(info)
82
  .filter((x) => x !== 'status')
web/src/utils/chat.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import { EmptyConversationId } from '@/constants/chat';
2
+
3
+ export const isConversationIdExist = (conversationId: string) => {
4
+ return conversationId !== EmptyConversationId && conversationId !== '';
5
+ };