Skip to content

Commit 4e58bc4

Browse files
authored
fix: duplicate chat content (#916)
* style: add dark drop shadow to images * docs: add release note * style: add dark * fix: duplicate chat content * docs: add release note * chore: update history list
1 parent a9a4b53 commit 4e58bc4

12 files changed

Lines changed: 252 additions & 124 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ feat: support opening logs from about page #915
1919
### 🐛 Bug fix
2020

2121
fix: automatic update of service list #913
22+
fix: duplicate chat content #916
2223

2324
### ✈️ Improvements
2425

src/components/Assistant/Chat.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface ChatAIProps {
4141
startPage?: StartPage;
4242
formatUrl?: (data: any) => string;
4343
instanceId?: string;
44+
getChatHistoryChatPage?: () => void;
4445
}
4546

4647
export interface SendMessageParams {
@@ -52,6 +53,7 @@ export interface ChatAIRef {
5253
init: (params: SendMessageParams) => void;
5354
cancelChat: () => void;
5455
clearChat: () => void;
56+
onSelectChat: (chat: Chat) => void;
5557
}
5658

5759
const ChatAI = memo(
@@ -73,13 +75,15 @@ const ChatAI = memo(
7375
startPage,
7476
formatUrl,
7577
instanceId,
78+
getChatHistoryChatPage,
7679
},
7780
ref
7881
) => {
7982
useImperativeHandle(ref, () => ({
8083
init: init,
8184
cancelChat: () => cancelChat(activeChat),
8285
clearChat: clearChat,
86+
onSelectChat: onSelectChat,
8387
}));
8488

8589
const curChatEnd = useChatStore((state) => state.curChatEnd);
@@ -193,7 +197,8 @@ const ChatAI = memo(
193197
isDeepThinkActive,
194198
isMCPActive,
195199
changeInput,
196-
showChatHistory
200+
showChatHistory,
201+
getChatHistoryChatPage,
197202
);
198203

199204
const { dealMsg } = useMessageHandler(

src/components/Assistant/ChatContent.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { ChatMessage } from "@/components/ChatMessage";
55
import { Greetings } from "./Greetings";
66
import AttachmentList from "@/components/Assistant/AttachmentList";
77
import { useChatScroll } from "@/hooks/useChatScroll";
8-
98
import type { Chat, IChunkData } from "@/types/chat";
109
import { useConnectStore } from "@/stores/connectStore";
1110
// import SessionFile from "./SessionFile";
@@ -45,20 +44,23 @@ export const ChatContent = ({
4544
handleSendMessage,
4645
formatUrl,
4746
}: ChatContentProps) => {
48-
const { currentSessionId, setCurrentSessionId } = useConnectStore();
49-
5047
const { t } = useTranslation();
5148

52-
const { uploadAttachments } = useChatStore();
49+
const currentSessionId = useConnectStore((state) => state.currentSessionId);
50+
const setCurrentSessionId = useConnectStore(
51+
(state) => state.setCurrentSessionId
52+
);
53+
const visibleStartPage = useConnectStore((state) => state.visibleStartPage);
54+
55+
const uploadAttachments = useChatStore((state) => state.uploadAttachments);
56+
const curChatEnd = useChatStore((state) => state.curChatEnd);
5357

5458
const messagesEndRef = useRef<HTMLDivElement>(null);
5559

5660
const { scrollToBottom } = useChatScroll(messagesEndRef);
61+
5762
const scrollRef = useRef<HTMLDivElement>(null);
5863
const [isAtBottom, setIsAtBottom] = useState(true);
59-
const visibleStartPage = useConnectStore((state) => state.visibleStartPage);
60-
61-
const curChatEnd = useChatStore((state) => state.curChatEnd);
6264

6365
useEffect(() => {
6466
setIsAtBottom(true);

src/components/Search/ExtensionStore.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const ExtensionStore = ({ extensionId }: { extensionId?: string }) => {
139139
}
140140
);
141141

142-
console.log("search_extension", result);
142+
// console.log("search_extension", result);
143143

144144
setList(result ?? []);
145145

src/components/Search/InputBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default function ChatInput({
121121
const handleSubmit = useCallback(() => {
122122
const trimmedValue = inputValue.trim();
123123

124-
console.log("handleSubmit", trimmedValue, disabled);
124+
// console.log("handleSubmit", trimmedValue, disabled);
125125

126126
if ((trimmedValue || !isEmpty(uploadAttachments)) && !disabled) {
127127
changeInput("");

src/hooks/useChatActions.ts

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export function useChatActions(
2929
isDeepThinkActive?: boolean,
3030
isMCPActive?: boolean,
3131
changeInput?: (val: string) => void,
32-
showChatHistory?: boolean
32+
showChatHistory?: boolean,
33+
getChatHistoryChatPage?: () => void,
3334
) {
3435
const isCurrentLogin = useAuthStore((state) => state.isCurrentLogin);
3536

@@ -197,34 +198,34 @@ export function useChatActions(
197198
) {
198199
try {
199200
const response = JSON.parse(msg);
200-
console.log("first", response);
201+
// console.log("first", response);
201202

202203
let updatedChat: Chat;
203204
if (Array.isArray(response)) {
204205
curIdRef.current = response[0]?._id;
205206
curSessionIdRef.current = response[0]?._source?.session_id;
206-
console.log(
207-
"curIdRef-curSessionIdRef-Array",
208-
curIdRef.current,
209-
curSessionIdRef.current
210-
);
207+
// console.log(
208+
// "curIdRef-curSessionIdRef-Array",
209+
// curIdRef.current,
210+
// curSessionIdRef.current
211+
// );
211212
updatedChat = {
212213
...updatedChatRef.current,
213214
messages: [
214215
...(updatedChatRef.current?.messages || []),
215216
...(response || []),
216217
],
217218
};
218-
console.log("array", updatedChat, updatedChatRef.current?.messages);
219+
// console.log("array", updatedChat, updatedChatRef.current?.messages);
219220
} else {
220221
const newChat: Chat = response;
221222
curIdRef.current = response?.payload?.id;
222223
curSessionIdRef.current = response?.payload?.session_id;
223-
console.log(
224-
"curIdRef-curSessionIdRef",
225-
curIdRef.current,
226-
curSessionIdRef.current
227-
);
224+
// console.log(
225+
// "curIdRef-curSessionIdRef",
226+
// curIdRef.current,
227+
// curSessionIdRef.current
228+
// );
228229

229230
newChat._source = {
230231
...response?.payload,
@@ -252,7 +253,7 @@ export function useChatActions(
252253
async (timestamp: number) => {
253254
cleanupListeners();
254255

255-
console.log("setupListeners", clientId, timestamp);
256+
// console.log("setupListeners", clientId, timestamp);
256257
const unlisten_chat_message = await platformAdapter.listenEvent(
257258
`chat-stream-${clientId}-${timestamp}`,
258259
(event) => {
@@ -300,12 +301,45 @@ export function useChatActions(
300301
[setupListeners]
301302
);
302303

304+
const getChatHistory = useCallback(async () => {
305+
let response: any;
306+
if (isTauri) {
307+
if (await unrequitable()) {
308+
return setChats([]);
309+
}
310+
311+
response = await platformAdapter.commands("chat_history", {
312+
serverId: currentService?.id,
313+
from: 0,
314+
size: 100,
315+
query: keyword,
316+
});
317+
318+
response = response ? JSON.parse(response) : null;
319+
} else {
320+
const [_error, res] = await Get(`/chat/_history`, {
321+
from: 0,
322+
size: 100,
323+
});
324+
response = res;
325+
}
326+
327+
const hits = response?.hits?.hits || [];
328+
setChats(hits);
329+
}, [
330+
currentService?.id,
331+
keyword,
332+
isTauri,
333+
currentService?.enabled,
334+
isCurrentLogin,
335+
]);
336+
303337
const createNewChat = useCallback(
304338
async (params?: SendMessageParams) => {
305339
const { message, attachments } = params || {};
306340

307-
console.log("message", message);
308-
console.log("attachments", attachments);
341+
// console.log("message", message);
342+
// console.log("attachments", attachments);
309343

310344
if (!message && isEmpty(attachments)) return;
311345

@@ -325,7 +359,7 @@ export function useChatActions(
325359
if (isTauri) {
326360
if (!currentService?.id) return;
327361

328-
console.log("chat_create", clientId, timestamp);
362+
// console.log("chat_create", clientId, timestamp);
329363

330364
await platformAdapter.commands("chat_create", {
331365
serverId: currentService?.id,
@@ -334,20 +368,25 @@ export function useChatActions(
334368
queryParams,
335369
clientId: `chat-stream-${clientId}-${timestamp}`,
336370
});
337-
console.log("_create end", message);
371+
// console.log("_create end", message);
338372
resetChatState();
339373
} else {
340374
await streamPost({
341375
url: "/chat/_create",
342376
body: { message },
343377
queryParams,
344378
onMessage: (line) => {
345-
console.log("⏳", line);
379+
// console.log("⏳", line);
346380
handleChatCreateStreamMessage(line);
347381
// append to chat box
348382
},
349383
});
350384
}
385+
// console.log("showChatHistory", showChatHistory);
386+
387+
if (showChatHistory) {
388+
getChatHistoryChatPage ? getChatHistoryChatPage() : getChatHistory();
389+
}
351390
},
352391
[
353392
isTauri,
@@ -360,6 +399,8 @@ export function useChatActions(
360399
currentAssistant,
361400
chatClose,
362401
clientId,
402+
showChatHistory,
403+
getChatHistory,
363404
]
364405
);
365406

@@ -386,7 +427,7 @@ export function useChatActions(
386427

387428
if (isTauri) {
388429
if (!currentService?.id) return;
389-
console.log("chat_chat", clientId, timestamp);
430+
// console.log("chat_chat", clientId, timestamp);
390431
await platformAdapter.commands("chat_chat", {
391432
serverId: currentService?.id,
392433
sessionId: newChat?._id,
@@ -395,15 +436,15 @@ export function useChatActions(
395436
attachments,
396437
clientId: `chat-stream-${clientId}-${timestamp}`,
397438
});
398-
console.log("chat_chat end", message, clientId);
439+
// console.log("chat_chat end", message, clientId);
399440
resetChatState();
400441
} else {
401442
await streamPost({
402443
url: `/chat/${newChat?._id}/_chat`,
403444
body: { message },
404445
queryParams,
405446
onMessage: (line) => {
406-
console.log("line", line);
447+
// console.log("line", line);
407448
handleChatCreateStreamMessage(line);
408449
// append to chat box
409450
},
@@ -468,39 +509,6 @@ export function useChatActions(
468509
[currentService?.id, isTauri]
469510
);
470511

471-
const getChatHistory = useCallback(async () => {
472-
let response: any;
473-
if (isTauri) {
474-
if (await unrequitable()) {
475-
return setChats([]);
476-
}
477-
478-
response = await platformAdapter.commands("chat_history", {
479-
serverId: currentService?.id,
480-
from: 0,
481-
size: 100,
482-
query: keyword,
483-
});
484-
485-
response = response ? JSON.parse(response) : null;
486-
} else {
487-
const [_error, res] = await Get(`/chat/_history`, {
488-
from: 0,
489-
size: 100,
490-
});
491-
response = res;
492-
}
493-
494-
const hits = response?.hits?.hits || [];
495-
setChats(hits);
496-
}, [
497-
currentService?.id,
498-
keyword,
499-
isTauri,
500-
currentService?.enabled,
501-
isCurrentLogin,
502-
]);
503-
504512
useEffect(() => {
505513
if (showChatHistory) {
506514
getChatHistory();

0 commit comments

Comments
 (0)