| | |
| | | import { RoleEnum, type ChatMessage } from '../model/types'; |
| | | import { QueryHistoryDetail } from '/@/api/ai/chat'; |
| | | import { sseClient } from '/@/stores/global'; |
| | | import { Logger } from '/@/model/logger/Logger'; |
| | | import { ElNotification } from 'element-plus'; |
| | | |
| | | type UseSyncMsgOptions = { |
| | | updateLoadIndex: (addCount: number) => void; |
| | |
| | | checkCanSync: (data: any) => boolean; |
| | | loadReplyData: (data: any) => Promise<ChatMessage[]>; |
| | | scrollToBottom: () => void; |
| | | showTip: (data: any) => void; |
| | | }; |
| | | |
| | | export const useSyncMsg = (options: UseSyncMsgOptions) => { |
| | | const { updateLoadIndex, msgList, historyGroupId, checkCanSync, loadReplyData, scrollToBottom } = options; |
| | | const { updateLoadIndex, msgList, historyGroupId, checkCanSync, loadReplyData, scrollToBottom, showTip } = options; |
| | | |
| | | const insertSyncMsg = (replayData: any[]) => { |
| | | const insertResult: { index: number; item: any }[] = []; |
| | |
| | | const historyUpdate = async (data: any) => { |
| | | if (!checkCanSync(data)) return; |
| | | if (!data) return; |
| | | Logger.info('sync message notification:\n\n' + JSON.stringify(data)); |
| | | |
| | | if (data?.type === 'chat_start') { |
| | | |
| | | showTip(data); |
| | | } |
| | | if (data?.type === 'chat_history_id') { |
| | | const groupId = unref(historyGroupId); |
| | | if (!groupId) return; |