feat(web): workflow's chat support abort output
This commit is contained in:
@@ -60,7 +60,7 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
|
|||||||
const handleSave = (values: StartVariableItem[]) => {
|
const handleSave = (values: StartVariableItem[]) => {
|
||||||
setVariables([...values])
|
setVariables([...values])
|
||||||
}
|
}
|
||||||
const handleClusterSend = () => {
|
const handleSend = () => {
|
||||||
if (loading || !appId) return
|
if (loading || !appId) return
|
||||||
let isCanSend = true
|
let isCanSend = true
|
||||||
const params: Record<string, any> = {}
|
const params: Record<string, any> = {}
|
||||||
@@ -99,36 +99,41 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
|
|||||||
const handleStreamMessage = (data: SSEMessage[]) => {
|
const handleStreamMessage = (data: SSEMessage[]) => {
|
||||||
setStreamLoading(false)
|
setStreamLoading(false)
|
||||||
|
|
||||||
data.map(item => {
|
data.forEach(item => {
|
||||||
const { chunk } = item.data as { chunk: string; };
|
const { chunk } = item.data as { chunk: string; };
|
||||||
|
|
||||||
switch(item.event) {
|
switch(item.event) {
|
||||||
case 'message':
|
case 'message':
|
||||||
setChatList(prev => {
|
setChatList(prev => {
|
||||||
const lastChat = { ...prev[prev.length - 1] }
|
const newList = [...prev]
|
||||||
lastChat.content = lastChat.content + chunk
|
const lastIndex = newList.length - 1
|
||||||
|
if (lastIndex >= 0) {
|
||||||
return [
|
newList[lastIndex] = {
|
||||||
...prev.slice(0, prev.length - 1),
|
...newList[lastIndex],
|
||||||
lastChat
|
content: newList[lastIndex].content + chunk
|
||||||
]
|
}
|
||||||
|
}
|
||||||
|
return newList
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'workflow_end':
|
case 'workflow_end':
|
||||||
setChatList(prev => {
|
setChatList(prev => {
|
||||||
const lastChat = { ...prev[prev.length - 1] }
|
const newList = [...prev]
|
||||||
lastChat.content = lastChat.content === '' ? null : lastChat.content
|
const lastIndex = newList.length - 1
|
||||||
|
if (lastIndex >= 0) {
|
||||||
return [
|
newList[lastIndex] = {
|
||||||
...prev.slice(0, prev.length - 1),
|
...newList[lastIndex],
|
||||||
lastChat
|
content: newList[lastIndex].content === '' ? null : newList[lastIndex].content
|
||||||
]
|
}
|
||||||
|
}
|
||||||
|
return newList
|
||||||
})
|
})
|
||||||
setStreamLoading(false);
|
setStreamLoading(false)
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
form.setFieldValue('message', undefined)
|
form.setFieldValue('message', undefined)
|
||||||
draftRun(appId, {
|
draftRun(appId, {
|
||||||
message: message,
|
message: message,
|
||||||
@@ -178,13 +183,13 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
|
|||||||
<Input
|
<Input
|
||||||
className="rb:h-11 rb:shadow-[0px_2px_8px_0px_rgba(33,35,50,0.1)]"
|
className="rb:h-11 rb:shadow-[0px_2px_8px_0px_rgba(33,35,50,0.1)]"
|
||||||
placeholder={t('application.chatPlaceholder')}
|
placeholder={t('application.chatPlaceholder')}
|
||||||
onPressEnter={handleClusterSend}
|
onPressEnter={handleSend}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
<img src={ChatSendIcon} className={clsx("rb:w-11 rb:h-11 rb:cursor-pointer", {
|
<img src={ChatSendIcon} className={clsx("rb:w-11 rb:h-11 rb:cursor-pointer", {
|
||||||
'rb:opacity-50': loading,
|
'rb:opacity-50': loading,
|
||||||
})} onClick={handleClusterSend} />
|
})} onClick={handleSend} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<VariableConfigModal
|
<VariableConfigModal
|
||||||
|
|||||||
Reference in New Issue
Block a user