mirror of https://github.com/langgenius/dify.git
add workflow run events
This commit is contained in:
parent
949a894f03
commit
6b11973151
|
|
@ -44,6 +44,7 @@ export const useWorkflowRun = () => {
|
|||
handleWorkflowFailed,
|
||||
handleWorkflowNodeStarted,
|
||||
handleWorkflowNodeFinished,
|
||||
handleWorkflowNodeHumanInputRequired,
|
||||
handleWorkflowNodeIterationStarted,
|
||||
handleWorkflowNodeIterationNext,
|
||||
handleWorkflowNodeIterationFinished,
|
||||
|
|
@ -54,6 +55,7 @@ export const useWorkflowRun = () => {
|
|||
handleWorkflowAgentLog,
|
||||
handleWorkflowTextChunk,
|
||||
handleWorkflowTextReplace,
|
||||
handleWorkflowSuspended,
|
||||
} = useWorkflowRunEvent()
|
||||
|
||||
const handleBackupDraft = useCallback(() => {
|
||||
|
|
@ -138,6 +140,8 @@ export const useWorkflowRun = () => {
|
|||
onNodeRetry,
|
||||
onAgentLog,
|
||||
onError,
|
||||
onWorkflowSuspended,
|
||||
onHumanInputRequired,
|
||||
...restCallback
|
||||
} = callback || {}
|
||||
workflowStore.setState({ historyWorkflowData: undefined })
|
||||
|
|
@ -304,6 +308,16 @@ export const useWorkflowRun = () => {
|
|||
onTTSEnd: (messageId: string, audio: string) => {
|
||||
player.playAudioWithAudio(audio, false)
|
||||
},
|
||||
onWorkflowSuspended: (params) => {
|
||||
handleWorkflowSuspended()
|
||||
if (onWorkflowSuspended)
|
||||
onWorkflowSuspended(params)
|
||||
},
|
||||
onHumanInputRequired: (params) => {
|
||||
handleWorkflowNodeHumanInputRequired(params)
|
||||
if (onHumanInputRequired)
|
||||
onHumanInputRequired(params)
|
||||
},
|
||||
...restCallback,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,3 +13,5 @@ export * from './use-workflow-node-retry'
|
|||
export * from './use-workflow-text-chunk'
|
||||
export * from './use-workflow-text-replace'
|
||||
export * from './use-workflow-agent-log'
|
||||
export * from './use-workflow-suspended'
|
||||
export * from './use-workflow-node-human-input-required'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
import { useCallback } from 'react'
|
||||
import {
|
||||
useStoreApi,
|
||||
} from 'reactflow'
|
||||
import produce from 'immer'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import type { HumanInputRequiredResponse } from '@/types/workflow'
|
||||
import { NodeRunningStatus } from '@/app/components/workflow/types'
|
||||
import { WorkflowRunningStatus } from '@/app/components/workflow/types'
|
||||
|
||||
export const useWorkflowNodeHumanInputRequired = () => {
|
||||
const workflowStore = useWorkflowStore()
|
||||
const store = useStoreApi()
|
||||
|
||||
const handleWorkflowNodeHumanInputRequired = useCallback((params: HumanInputRequiredResponse) => {
|
||||
const { data } = params
|
||||
const {
|
||||
workflowRunningData,
|
||||
setWorkflowRunningData,
|
||||
} = workflowStore.getState()
|
||||
const {
|
||||
getNodes,
|
||||
setNodes,
|
||||
} = store.getState()
|
||||
const nodes = getNodes()
|
||||
const currentNodeIndex = nodes.findIndex(node => node.id === data.node_id)
|
||||
const newNodes = produce(nodes, (draft) => {
|
||||
draft[currentNodeIndex].data._runningStatus = NodeRunningStatus.Suspended
|
||||
// draft[currentNodeIndex].data._waitingRun = false
|
||||
})
|
||||
setNodes(newNodes)
|
||||
|
||||
setWorkflowRunningData(produce(workflowRunningData!, (draft) => {
|
||||
draft.result = {
|
||||
...draft.result,
|
||||
status: WorkflowRunningStatus.Suspended,
|
||||
}
|
||||
}))
|
||||
}, [workflowStore])
|
||||
|
||||
return {
|
||||
handleWorkflowNodeHumanInputRequired,
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ import {
|
|||
useWorkflowFailed,
|
||||
useWorkflowFinished,
|
||||
useWorkflowNodeFinished,
|
||||
useWorkflowNodeHumanInputRequired,
|
||||
useWorkflowNodeIterationFinished,
|
||||
useWorkflowNodeIterationNext,
|
||||
useWorkflowNodeIterationStarted,
|
||||
|
|
@ -12,6 +13,7 @@ import {
|
|||
useWorkflowNodeRetry,
|
||||
useWorkflowNodeStarted,
|
||||
useWorkflowStarted,
|
||||
useWorkflowSuspended,
|
||||
useWorkflowTextChunk,
|
||||
useWorkflowTextReplace,
|
||||
} from '.'
|
||||
|
|
@ -32,6 +34,8 @@ export const useWorkflowRunEvent = () => {
|
|||
const { handleWorkflowTextChunk } = useWorkflowTextChunk()
|
||||
const { handleWorkflowTextReplace } = useWorkflowTextReplace()
|
||||
const { handleWorkflowAgentLog } = useWorkflowAgentLog()
|
||||
const { handleWorkflowSuspended } = useWorkflowSuspended()
|
||||
const { handleWorkflowNodeHumanInputRequired } = useWorkflowNodeHumanInputRequired()
|
||||
|
||||
return {
|
||||
handleWorkflowStarted,
|
||||
|
|
@ -49,5 +53,7 @@ export const useWorkflowRunEvent = () => {
|
|||
handleWorkflowTextChunk,
|
||||
handleWorkflowTextReplace,
|
||||
handleWorkflowAgentLog,
|
||||
handleWorkflowSuspended,
|
||||
handleWorkflowNodeHumanInputRequired,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import { useCallback } from 'react'
|
||||
import produce from 'immer'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { WorkflowRunningStatus } from '@/app/components/workflow/types'
|
||||
|
||||
export const useWorkflowSuspended = () => {
|
||||
const workflowStore = useWorkflowStore()
|
||||
|
||||
const handleWorkflowSuspended = useCallback(() => {
|
||||
const {
|
||||
workflowRunningData,
|
||||
setWorkflowRunningData,
|
||||
} = workflowStore.getState()
|
||||
|
||||
setWorkflowRunningData(produce(workflowRunningData!, (draft) => {
|
||||
draft.result = {
|
||||
...draft.result,
|
||||
status: WorkflowRunningStatus.Suspended,
|
||||
}
|
||||
}))
|
||||
}, [workflowStore])
|
||||
|
||||
return {
|
||||
handleWorkflowSuspended,
|
||||
}
|
||||
}
|
||||
|
|
@ -98,10 +98,7 @@ const InputsPanel = ({ onRun }: Props) => {
|
|||
}, [files, handleRun, initialInputs, onRun, variables, checkInputsForm])
|
||||
|
||||
const canRun = useMemo(() => {
|
||||
if (files?.some(item => (item.transfer_method as any) === TransferMethod.local_file && !item.upload_file_id))
|
||||
return false
|
||||
|
||||
return true
|
||||
return !(files?.some(item => (item.transfer_method as any) === TransferMethod.local_file && !item.upload_file_id))
|
||||
}, [files])
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -341,6 +341,7 @@ export enum NodeRunningStatus {
|
|||
Exception = 'exception',
|
||||
Retry = 'retry',
|
||||
Stopped = 'stopped',
|
||||
Suspended = 'suspended',
|
||||
}
|
||||
|
||||
export type OnNodeAdd = (
|
||||
|
|
|
|||
Loading…
Reference in New Issue