@@ -27,7 +27,7 @@ import { useMarkdown } from '@/hooks/useMarkdown';
27
27
import { AppModuleItemType , VariableItemType } from '@/types/app' ;
28
28
import { VariableInputEnum } from '@/constants/app' ;
29
29
import { useForm } from 'react-hook-form' ;
30
- import { MessageItemType } from '@/pages/api/openapi/v1/ chat/completions ' ;
30
+ import type { MessageItemType } from '@/types/core/ chat/type ' ;
31
31
import { fileDownload } from '@/utils/web/file' ;
32
32
import { htmlTemplate } from '@/constants/common' ;
33
33
import { useRouter } from 'next/router' ;
@@ -158,6 +158,7 @@ const ChatBox = (
158
158
onStartChat ?: ( e : StartChatFnProps ) => Promise < {
159
159
responseText : string ;
160
160
[ TaskResponseKeyEnum . responseData ] : ChatHistoryItemResType [ ] ;
161
+ isNewChat ?: boolean ;
161
162
} > ;
162
163
onDelMessage ?: ( e : { contentId ?: string ; index : number } ) => void ;
163
164
} ,
@@ -173,6 +174,7 @@ const ChatBox = (
173
174
const TextareaDom = useRef < HTMLTextAreaElement > ( null ) ;
174
175
const chatController = useRef ( new AbortController ( ) ) ;
175
176
const questionGuideController = useRef ( new AbortController ( ) ) ;
177
+ const isNewChatReplace = useRef ( false ) ;
176
178
177
179
const [ refresh , setRefresh ] = useState ( false ) ;
178
180
const [ variables , setVariables ] = useState < Record < string , any > > ( { } ) ; // settings variable
@@ -381,14 +383,20 @@ const ChatBox = (
381
383
382
384
const messages = adaptChat2GptMessages ( { messages : newChatList , reserveId : true } ) ;
383
385
384
- const { responseData, responseText } = await onStartChat ( {
386
+ const {
387
+ responseData,
388
+ responseText,
389
+ isNewChat = false
390
+ } = await onStartChat ( {
385
391
chatList : newChatList ,
386
392
messages,
387
393
controller : abortSignal ,
388
394
generatingMessage,
389
395
variables
390
396
} ) ;
391
397
398
+ isNewChatReplace . current = isNewChat ;
399
+
392
400
// set finish status
393
401
setChatHistory ( ( state ) =>
394
402
state . map ( ( item , index ) => {
@@ -542,9 +550,12 @@ const ChatBox = (
542
550
543
551
// page change and abort request
544
552
useEffect ( ( ) => {
553
+ isNewChatReplace . current = false ;
545
554
return ( ) => {
546
555
chatController . current ?. abort ( 'leave' ) ;
547
- questionGuideController . current ?. abort ( 'leave' ) ;
556
+ if ( ! isNewChatReplace . current ) {
557
+ questionGuideController . current ?. abort ( 'leave' ) ;
558
+ }
548
559
// close voice
549
560
cancelBroadcast ( ) ;
550
561
} ;
0 commit comments