diff --git a/web/src/views/Workflow/components/Chat/Chat.tsx b/web/src/views/Workflow/components/Chat/Chat.tsx index b81f5fae..4824cc9c 100644 --- a/web/src/views/Workflow/components/Chat/Chat.tsx +++ b/web/src/views/Workflow/components/Chat/Chat.tsx @@ -60,7 +60,7 @@ const Chat = forwardRef(({ appId const handleSave = (values: StartVariableItem[]) => { setVariables([...values]) } - const handleClusterSend = () => { + const handleSend = () => { if (loading || !appId) return let isCanSend = true const params: Record = {} @@ -99,36 +99,41 @@ const Chat = forwardRef(({ appId const handleStreamMessage = (data: SSEMessage[]) => { setStreamLoading(false) - data.map(item => { + data.forEach(item => { const { chunk } = item.data as { chunk: string; }; switch(item.event) { case 'message': setChatList(prev => { - const lastChat = { ...prev[prev.length - 1] } - lastChat.content = lastChat.content + chunk - - return [ - ...prev.slice(0, prev.length - 1), - lastChat - ] + const newList = [...prev] + const lastIndex = newList.length - 1 + if (lastIndex >= 0) { + newList[lastIndex] = { + ...newList[lastIndex], + content: newList[lastIndex].content + chunk + } + } + return newList }) break case 'workflow_end': setChatList(prev => { - const lastChat = { ...prev[prev.length - 1] } - lastChat.content = lastChat.content === '' ? null : lastChat.content - - return [ - ...prev.slice(0, prev.length - 1), - lastChat - ] + const newList = [...prev] + const lastIndex = newList.length - 1 + if (lastIndex >= 0) { + newList[lastIndex] = { + ...newList[lastIndex], + content: newList[lastIndex].content === '' ? null : newList[lastIndex].content + } + } + return newList }) - setStreamLoading(false); - break; + setStreamLoading(false) + break } }) - }; + } + form.setFieldValue('message', undefined) draftRun(appId, { message: message, @@ -178,13 +183,13 @@ const Chat = forwardRef(({ appId + })} onClick={handleSend} />