fix(web): stream support abort
This commit is contained in:
@@ -92,6 +92,7 @@ const TestChat: FC<TestChatProps> = ({
|
||||
const audioPollingRef = useRef<Map<string, ReturnType<typeof setInterval>>>(new Map())
|
||||
const streamLoadingRef = useRef(false)
|
||||
const [audioStatusMap, setAudioStatusMap] = useState<Record<string, string>>({})
|
||||
const abortRef = useRef<(() => void) | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
getVariables()
|
||||
@@ -99,6 +100,8 @@ const TestChat: FC<TestChatProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
abortRef.current?.()
|
||||
abortRef.current = null
|
||||
audioPollingRef.current.forEach(timer => clearInterval(timer))
|
||||
audioPollingRef.current.clear()
|
||||
}
|
||||
@@ -262,7 +265,8 @@ const TestChat: FC<TestChatProps> = ({
|
||||
draftRun(
|
||||
application.id,
|
||||
formatParams((msg || message) as string, conversationId, files, params),
|
||||
handleStreamMessage
|
||||
handleStreamMessage,
|
||||
(abort) => { abortRef.current = abort }
|
||||
)
|
||||
.catch(() => {
|
||||
updateErrorAssistantMessage(0)
|
||||
@@ -373,7 +377,8 @@ const TestChat: FC<TestChatProps> = ({
|
||||
draftRun(
|
||||
application.id,
|
||||
formatParams((msg || message) as string, conversationId, files, params),
|
||||
handleWorkflowStreamMessage
|
||||
handleWorkflowStreamMessage,
|
||||
(abort) => { abortRef.current = abort }
|
||||
)
|
||||
.catch((error) => {
|
||||
const errorInfo = JSON.parse(error.message)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 16:26:44
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-20 13:53:05
|
||||
* @Last Modified time: 2026-04-21 14:50:21
|
||||
*/
|
||||
/**
|
||||
* AI Prompt Assistant Modal
|
||||
@@ -61,11 +61,14 @@ const AiPromptModal = forwardRef<AiPromptModalRef, AiPromptModalProps>(({
|
||||
const aiPromptVariableModalRef = useRef<AiPromptVariableModalRef>(null)
|
||||
const editorRef = useRef<any>(null)
|
||||
const currentPromptValueRef = useRef<string>('')
|
||||
const abortRef = useRef<(() => void) | null>(null)
|
||||
|
||||
const values = Form.useWatch([], form)
|
||||
|
||||
/** Close modal and reset state */
|
||||
const handleClose = () => {
|
||||
abortRef.current?.()
|
||||
abortRef.current = null
|
||||
setVisible(false);
|
||||
setLoading(false)
|
||||
setChatList([])
|
||||
@@ -148,7 +151,7 @@ const AiPromptModal = forwardRef<AiPromptModalRef, AiPromptModalProps>(({
|
||||
updatePromptMessages(promptSession, {
|
||||
...values,
|
||||
skill: source === 'skills'
|
||||
}, handleStreamMessage)
|
||||
}, handleStreamMessage, undefined, abort => { abortRef.current = abort })
|
||||
.finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
@@ -221,7 +224,7 @@ const AiPromptModal = forwardRef<AiPromptModalRef, AiPromptModalProps>(({
|
||||
</Form.Item>
|
||||
|
||||
<ChatContent
|
||||
classNames="rb:h-105.5 rb:pb-[15px]!"
|
||||
classNames="rb:h-[calc(100vh-330px)] rb:pb-[15px]!"
|
||||
contentClassNames="rb:max-w-75!"
|
||||
empty={<Empty url={ConversationEmptyIcon} title={t(`${source}.promptChatEmpty`)} isNeedSubTitle={false} size={[140, 100]} className="rb:h-full" />}
|
||||
data={chatList || []}
|
||||
@@ -292,10 +295,10 @@ const AiPromptModal = forwardRef<AiPromptModalRef, AiPromptModalProps>(({
|
||||
{values?.current_prompt
|
||||
? <Editor
|
||||
ref={editorRef}
|
||||
className="rb:h-119 rb:bg-white! rb:border-none! rb:p-0!"
|
||||
className="rb:h-[calc(100vh-278px)] rb:bg-white! rb:border-none! rb:p-0!"
|
||||
onChange={(value) => form.setFieldValue('current_prompt', value)}
|
||||
/>
|
||||
: <Empty url={analysisEmptyIcon} title={t(`${source}.promptOptimizationEmpty`)} isNeedSubTitle={false} size={[270, 170]} className="rb:h-119 rb:w-70 rb:mx-auto! rb:text-center! rb:text-[12px]! rb:leading-4!" />
|
||||
: <Empty url={analysisEmptyIcon} title={t(`${source}.promptOptimizationEmpty`)} isNeedSubTitle={false} size={[270, 170]} className="rb:h-[calc(100vh-278px)] rb:w-70 rb:mx-auto! rb:text-center! rb:text-[12px]! rb:leading-4!" />
|
||||
}
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
@@ -73,11 +73,14 @@ const Chat: FC<ChatProps> = ({
|
||||
const [message, setMessage] = useState<string | undefined>(undefined)
|
||||
const [features, setFeatures] = useState<FeaturesConfigForm>({} as FeaturesConfigForm)
|
||||
const [audioStatusMap, setAudioStatusMap] = useState<Record<string, string>>({})
|
||||
const abortRef = useRef<(() => void) | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
setCompareLoading(false)
|
||||
setLoading(false)
|
||||
return () => {
|
||||
abortRef.current?.()
|
||||
abortRef.current = null
|
||||
audioPollingRef.current.forEach(timer => clearInterval(timer))
|
||||
audioPollingRef.current.clear()
|
||||
}
|
||||
@@ -85,6 +88,8 @@ const Chat: FC<ChatProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
abortRef.current?.()
|
||||
abortRef.current = null
|
||||
audioPollingRef.current.forEach(timer => clearInterval(timer))
|
||||
audioPollingRef.current.clear()
|
||||
}
|
||||
@@ -393,7 +398,7 @@ const Chat: FC<ChatProps> = ({
|
||||
parallel: true,
|
||||
stream: true,
|
||||
timeout: 60,
|
||||
}, handleStreamMessage)
|
||||
}, handleStreamMessage, (abort) => { abortRef.current = abort })
|
||||
.catch(() => {
|
||||
setLoading(false)
|
||||
setCompareLoading(false)
|
||||
@@ -537,7 +542,8 @@ const Chat: FC<ChatProps> = ({
|
||||
}
|
||||
}),
|
||||
},
|
||||
handleStreamMessage
|
||||
handleStreamMessage,
|
||||
(abort) => { abortRef.current = abort }
|
||||
)
|
||||
.catch(() => {
|
||||
setLoading(false)
|
||||
|
||||
Reference in New Issue
Block a user