wujingjing
2025-02-11 557a57c627dbaf97ec343de7933168f78187a489
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 }[] = [];
@@ -39,10 +42,18 @@
         msgList.value.splice(resultItem.index, 0, ...resultItem.item);
      });
   };
   const historyUpdate = async (data: any) => {
      if (!checkCanSync(data)) return;
      if (!data) return;
      if (data?.type === 'chat_start') {
         const groupId = unref(historyGroupId);
         const startGroupId = data?.history_group_id;
         if (groupId !== startGroupId) return;
         showTip(data);
      }
      if (data?.type === 'chat_history_id') {
         const groupId = unref(historyGroupId);
         if (!groupId) return;
@@ -74,6 +85,7 @@
         updateLoadIndex(unSyncedHistoryIds.length);
         scrollToBottom();
      }
   };
   onActivated(() => {