@@ -67,7 +67,6 @@ import { VariableInputEnum } from '@fastgpt/global/core/workflow/constants';
6767import { valueTypeFormat } from '@fastgpt/global/core/workflow/runtime/utils' ;
6868import { formatTime2YMDHMS } from '@fastgpt/global/common/string/time' ;
6969import { TeamErrEnum } from '@fastgpt/global/common/error/code/team' ;
70- import { useDeletedGroups } from './hooks/useDeletedGroups' ;
7170
7271const FeedbackModal = dynamic ( ( ) => import ( './components/FeedbackModal' ) ) ;
7372const SelectMarkCollection = dynamic ( ( ) => import ( './components/SelectMarkCollection' ) ) ;
@@ -127,6 +126,7 @@ const ChatBox = ({
127126 const [ feedbackId , setFeedbackId ] = useState < string > ( ) ;
128127 const [ adminMarkData , setAdminMarkData ] = useState < AdminMarkType & { dataId : string } > ( ) ;
129128 const [ questionGuides , setQuestionGuide ] = useState < string [ ] > ( [ ] ) ;
129+ const [ expandedDeletedGroups , setExpandedDeletedGroups ] = useState < number [ ] > ( [ ] ) ;
130130
131131 const appAvatar = useContextSelector ( ChatItemContext , ( v ) => v . chatBoxData ?. app ?. avatar ) ;
132132 const userAvatar = useContextSelector ( ChatItemContext , ( v ) => v . chatBoxData ?. userAvatar ) ;
@@ -1013,7 +1013,75 @@ const ChatBox = ({
10131013 return chatType === ChatTypeEnum . home && chatRecords . length === 0 && ! chatStartedWatch ;
10141014 } , [ chatType , chatRecords . length , chatStartedWatch ] ) ;
10151015
1016- const { processedRecords, toggleDeletedGroup } = useDeletedGroups ( chatRecords ) ;
1016+ const toggleDeletedGroup = useCallback ( ( groupIndex : number ) => {
1017+ setExpandedDeletedGroups ( ( prev ) => {
1018+ if ( prev . includes ( groupIndex ) ) {
1019+ return prev . filter ( ( i ) => i !== groupIndex ) ;
1020+ } else {
1021+ return [ ...prev , groupIndex ] ;
1022+ }
1023+ } ) ;
1024+ } , [ ] ) ;
1025+
1026+ // 预处理聊天记录:根据类型生成统一的数据结构
1027+ const processedRecords = useMemo ( ( ) => {
1028+ // Log 类型:计算删除分组信息
1029+ if ( chatType === ChatTypeEnum . log ) {
1030+ let deletedGroupIndex = - 1 ;
1031+ let isInDeletedGroup = false ;
1032+ let currentGroupCount = 0 ;
1033+
1034+ return chatRecords . map ( ( item , index ) => {
1035+ const isDeleted = ! ! item . deleteTime ;
1036+ const prevIsDeleted = index > 0 ? ! ! chatRecords [ index - 1 ] . deleteTime : false ;
1037+ const nextIsDeleted =
1038+ index < chatRecords . length - 1 ? ! ! chatRecords [ index + 1 ] . deleteTime : false ;
1039+
1040+ const enteringDeletedGroup = isDeleted && ! prevIsDeleted ;
1041+ const leavingDeletedGroup = ! isDeleted && prevIsDeleted ;
1042+ const isLastInDeletedGroup = isDeleted && ! nextIsDeleted ;
1043+
1044+ if ( enteringDeletedGroup ) {
1045+ deletedGroupIndex ++ ;
1046+ isInDeletedGroup = true ;
1047+ currentGroupCount = 0 ;
1048+ for ( let i = index ; i < chatRecords . length ; i ++ ) {
1049+ if ( chatRecords [ i ] . deleteTime ) currentGroupCount ++ ;
1050+ else break ;
1051+ }
1052+ } else if ( leavingDeletedGroup ) {
1053+ isInDeletedGroup = false ;
1054+ currentGroupCount = 0 ;
1055+ }
1056+
1057+ const currentDeletedGroupIndex = deletedGroupIndex ;
1058+ const isExpanded = expandedDeletedGroups . includes ( currentDeletedGroupIndex ) ;
1059+
1060+ return {
1061+ item,
1062+ index,
1063+ enteringDeletedGroup,
1064+ isLastInDeletedGroup,
1065+ deletedGroupIndex : currentDeletedGroupIndex ,
1066+ isExpanded,
1067+ deletedCount : currentGroupCount ,
1068+ shouldRender : ! isInDeletedGroup || isExpanded
1069+ } ;
1070+ } ) ;
1071+ }
1072+
1073+ // 普通类型:包装成统一结构,但不需要删除逻辑
1074+ return chatRecords . map ( ( item , index ) => ( {
1075+ item,
1076+ index,
1077+ enteringDeletedGroup : false ,
1078+ isLastInDeletedGroup : false ,
1079+ deletedGroupIndex : - 1 ,
1080+ isExpanded : false ,
1081+ deletedCount : 0 ,
1082+ shouldRender : true
1083+ } ) ) ;
1084+ } , [ chatType , chatRecords , expandedDeletedGroups ] ) ;
10171085
10181086 //chat history
10191087 const RecordsBox = useMemo ( ( ) => {
0 commit comments