fix: enhance workflow node handling by including paused state and improving human input management

This commit is contained in:
twwu 2025-12-31 13:45:16 +08:00
parent 0c69466b0f
commit f0f1ae0b49
3 changed files with 21 additions and 26 deletions

View File

@ -4,20 +4,15 @@ import { useCallback } from 'react'
import {
useStoreApi,
} from 'reactflow'
import { useWorkflowStore } from '@/app/components/workflow/store'
import { NodeRunningStatus } from '@/app/components/workflow/types'
// import { WorkflowRunningStatus } from '@/app/components/workflow/types'
export const useWorkflowNodeHumanInputRequired = () => {
const workflowStore = useWorkflowStore()
const store = useStoreApi()
// ! Human input required !== Workflow Paused
const handleWorkflowNodeHumanInputRequired = useCallback((params: HumanInputRequiredResponse) => {
const { data } = params
const {
workflowRunningData,
setWorkflowRunningData,
} = workflowStore.getState()
const {
getNodes,
setNodes,
@ -26,19 +21,9 @@ export const useWorkflowNodeHumanInputRequired = () => {
const currentNodeIndex = nodes.findIndex(node => node.id === data.node_id)
const newNodes = produce(nodes, (draft) => {
draft[currentNodeIndex].data._runningStatus = NodeRunningStatus.Paused
// draft[currentNodeIndex].data._waitingRun = false
// store form data & input form schema
})
setNodes(newNodes)
// cache form data & generate input form UI in node data
setWorkflowRunningData(produce(workflowRunningData!, (draft) => {
draft.result = {
...draft.result,
// status: WorkflowRunningStatus.Paused, // human input required !== workflow 'Paused'
}
}))
}, [store, workflowStore])
}, [store])
return {
handleWorkflowNodeHumanInputRequired,

View File

@ -479,11 +479,21 @@ export const useNodesReadOnly = () => {
isRestoring,
} = workflowStore.getState()
return !!(workflowRunningData?.result.status === WorkflowRunningStatus.Running || historyWorkflowData || isRestoring)
return !!(
workflowRunningData?.result.status === WorkflowRunningStatus.Running
|| workflowRunningData?.result.status === WorkflowRunningStatus.Paused
|| historyWorkflowData
|| isRestoring
)
}, [workflowStore])
return {
nodesReadOnly: !!(workflowRunningData?.result.status === WorkflowRunningStatus.Running || historyWorkflowData || isRestoring),
nodesReadOnly: !!(
workflowRunningData?.result.status === WorkflowRunningStatus.Running
|| workflowRunningData?.result.status === WorkflowRunningStatus.Paused
|| historyWorkflowData
|| isRestoring
),
getNodesReadOnly,
}
}

View File

@ -515,13 +515,13 @@ export const useChat = (
const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.node_id === data.node_id)
if (currentTracingIndex > -1) {
responseItem.workflowProcess!.tracing[currentTracingIndex].status = NodeRunningStatus.Paused
updateCurrentQAOnTree({
placeholderQuestionId,
questionItem,
responseItem,
parentId: params.parent_message_id,
})
}
updateCurrentQAOnTree({
placeholderQuestionId,
questionItem,
responseItem,
parentId: params.parent_message_id,
})
},
onWorkflowPaused: ({ data: _data }) => {
responseItem.workflowProcess!.status = WorkflowRunningStatus.Paused