mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 18:08:07 +08:00
fix(workflow): update stop state for preview chat
This commit is contained in:
@ -1,6 +1,9 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { DEFAULT_ITER_TIMES, DEFAULT_LOOP_TIMES } from '../../../constants'
|
import { DEFAULT_ITER_TIMES, DEFAULT_LOOP_TIMES } from '../../../constants'
|
||||||
|
import { useEdgesInteractionsWithoutSync } from '../../../hooks/use-edges-interactions-without-sync'
|
||||||
|
import { useNodesInteractionsWithoutSync } from '../../../hooks/use-nodes-interactions-without-sync'
|
||||||
import { useStore, useWorkflowStore } from '../../../store'
|
import { useStore, useWorkflowStore } from '../../../store'
|
||||||
|
import { WorkflowRunningStatus } from '../../../types'
|
||||||
|
|
||||||
type UseChatFlowControlParams = {
|
type UseChatFlowControlParams = {
|
||||||
stopChat?: (taskId: string) => void
|
stopChat?: (taskId: string) => void
|
||||||
@ -16,6 +19,8 @@ export function useChatFlowControl({
|
|||||||
const setHasStopResponded = useStore(s => s.setHasStopResponded)
|
const setHasStopResponded = useStore(s => s.setHasStopResponded)
|
||||||
const setSuggestedQuestionsAbortController = useStore(s => s.setSuggestedQuestionsAbortController)
|
const setSuggestedQuestionsAbortController = useStore(s => s.setSuggestedQuestionsAbortController)
|
||||||
const invalidateRun = useStore(s => s.invalidateRun)
|
const invalidateRun = useStore(s => s.invalidateRun)
|
||||||
|
const { handleNodeCancelRunningStatus } = useNodesInteractionsWithoutSync()
|
||||||
|
const { handleEdgeCancelRunningStatus } = useEdgesInteractionsWithoutSync()
|
||||||
|
|
||||||
const { setIterTimes, setLoopTimes } = workflowStore.getState()
|
const { setIterTimes, setLoopTimes } = workflowStore.getState()
|
||||||
|
|
||||||
@ -24,7 +29,14 @@ export function useChatFlowControl({
|
|||||||
}, [setIsResponding])
|
}, [setIsResponding])
|
||||||
|
|
||||||
const handleStop = useCallback(() => {
|
const handleStop = useCallback(() => {
|
||||||
const { activeTaskId, suggestedQuestionsAbortController } = workflowStore.getState()
|
const {
|
||||||
|
activeTaskId,
|
||||||
|
suggestedQuestionsAbortController,
|
||||||
|
workflowRunningData,
|
||||||
|
setWorkflowRunningData,
|
||||||
|
} = workflowStore.getState()
|
||||||
|
const runningStatus = workflowRunningData?.result?.status
|
||||||
|
const isActiveRun = runningStatus === WorkflowRunningStatus.Running || runningStatus === WorkflowRunningStatus.Waiting
|
||||||
setHasStopResponded(true)
|
setHasStopResponded(true)
|
||||||
handleResponding(false)
|
handleResponding(false)
|
||||||
if (stopChat && activeTaskId)
|
if (stopChat && activeTaskId)
|
||||||
@ -36,6 +48,19 @@ export function useChatFlowControl({
|
|||||||
setSuggestedQuestionsAbortController(null)
|
setSuggestedQuestionsAbortController(null)
|
||||||
setActiveTaskId('')
|
setActiveTaskId('')
|
||||||
invalidateRun()
|
invalidateRun()
|
||||||
|
if (isActiveRun && workflowRunningData) {
|
||||||
|
setWorkflowRunningData({
|
||||||
|
...workflowRunningData,
|
||||||
|
result: {
|
||||||
|
...workflowRunningData.result,
|
||||||
|
status: WorkflowRunningStatus.Stopped,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (isActiveRun) {
|
||||||
|
handleNodeCancelRunningStatus()
|
||||||
|
handleEdgeCancelRunningStatus()
|
||||||
|
}
|
||||||
}, [
|
}, [
|
||||||
handleResponding,
|
handleResponding,
|
||||||
setIterTimes,
|
setIterTimes,
|
||||||
@ -46,6 +71,8 @@ export function useChatFlowControl({
|
|||||||
setSuggestedQuestionsAbortController,
|
setSuggestedQuestionsAbortController,
|
||||||
setActiveTaskId,
|
setActiveTaskId,
|
||||||
invalidateRun,
|
invalidateRun,
|
||||||
|
handleNodeCancelRunningStatus,
|
||||||
|
handleEdgeCancelRunningStatus,
|
||||||
])
|
])
|
||||||
|
|
||||||
const handleRestart = useCallback(() => {
|
const handleRestart = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user