gerson
2025-01-21 952977720041f6332e08609f22774a844c725e18
src/components/chat/hooks/useSyncMsg.ts
@@ -4,6 +4,8 @@
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;
@@ -12,10 +14,11 @@
   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 }[] = [];
@@ -42,7 +45,12 @@
   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;