refact workflow run

This commit is contained in:
zxhlyh 2024-12-24 15:38:54 +08:00
parent b98dd22491
commit 754baf8d02
14 changed files with 36 additions and 36 deletions

View File

@ -8,4 +8,4 @@ export * from './use-workflow-node-iteration-next'
export * from './use-workflow-node-iteration-finished'
export * from './use-workflow-node-retry'
export * from './use-workflow-text-chunk'
export * from './use-workflow-text-replace'
export * from './use-workflow-text-replace'

View File

@ -18,9 +18,9 @@ export const useWorkflowFailed = () => {
status: WorkflowRunningStatus.Failed,
}
}))
}, [])
}, [workflowStore])
return {
handleWorkflowFailed,
}
}
}

View File

@ -27,9 +27,9 @@ export const useWorkflowFinished = () => {
draft.resultText = data.outputs[Object.keys(data.outputs)[0]]
}
}))
}, [])
}, [workflowStore])
return {
handleWorkflowFinished,
}
}
}

View File

@ -145,9 +145,9 @@ export const useWorkflowNodeFinished = () => {
})
setEdges(newEdges)
}
}, [])
}, [workflowStore, store])
return {
handleWorkflowNodeFinished,
}
}
}

View File

@ -12,7 +12,6 @@ export const useWorkflowNodeIterationFinished = () => {
const handleWorkflowNodeIterationFinished = useCallback((params: IterationFinishedResponse) => {
const { data } = params
const {
workflowRunningData,
setWorkflowRunningData,
@ -23,6 +22,7 @@ export const useWorkflowNodeIterationFinished = () => {
setNodes,
} = store.getState()
const nodes = getNodes()
setWorkflowRunningData(produce(workflowRunningData!, (draft) => {
const tracing = draft.tracing!
const currIterationNode = tracing.find(trace => trace.node_id === data.node_id)
@ -40,9 +40,9 @@ export const useWorkflowNodeIterationFinished = () => {
currentNode.data._runningStatus = data.status
})
setNodes(newNodes)
}, [])
}, [workflowStore, store])
return {
handleWorkflowNodeIterationFinished,
}
}
}

View File

@ -40,9 +40,9 @@ export const useWorkflowNodeIterationNext = () => {
setIterTimes(iterTimes + 1)
})
setNodes(newNodes)
}, [])
}, [workflowStore, store])
return {
handleWorkflowNodeIterationNext,
}
}
}

View File

@ -1,5 +1,5 @@
import { useCallback } from 'react'
import {
import {
useReactFlow,
useStoreApi,
} from 'reactflow'
@ -79,9 +79,9 @@ export const useWorkflowNodeIterationStarted = () => {
})
})
setEdges(newEdges)
}, [])
}, [workflowStore, store, reactflow])
return {
handleWorkflowNodeIterationStarted,
}
}
}

View File

@ -1,7 +1,7 @@
import { useCallback } from 'react'
import { useStoreApi } from 'reactflow'
import produce from 'immer'
import type {
import type {
NodeFinishedResponse,
NodeTracing,
} from '@/types/workflow'
@ -90,9 +90,9 @@ export const useWorkflowNodeRetry = () => {
currentNode.data._retryIndex = data.retry_index
})
setNodes(newNodes)
}, [])
}, [workflowStore, store])
return {
handleWorkflowNodeRetry,
}
}
}

View File

@ -113,9 +113,9 @@ export const useWorkflowNodeStarted = () => {
})
setEdges(newEdges)
}
}, [])
}, [workflowStore, store, reactflow])
return {
handleWorkflowNodeStarted,
}
}
}

View File

@ -1,13 +1,13 @@
import {
useWorkflowStarted,
useWorkflowFinished,
import {
useWorkflowFailed,
useWorkflowNodeStarted,
useWorkflowFinished,
useWorkflowNodeFinished,
useWorkflowNodeIterationStarted,
useWorkflowNodeIterationNext,
useWorkflowNodeIterationFinished,
useWorkflowNodeIterationNext,
useWorkflowNodeIterationStarted,
useWorkflowNodeRetry,
useWorkflowNodeStarted,
useWorkflowStarted,
useWorkflowTextChunk,
useWorkflowTextReplace,
} from '.'
@ -38,4 +38,4 @@ export const useWorkflowRunEvent = () => {
handleWorkflowTextChunk,
handleWorkflowTextReplace,
}
}
}

View File

@ -50,9 +50,9 @@ export const useWorkflowStarted = () => {
})
})
setEdges(newEdges)
}, [])
}, [workflowStore, store])
return {
handleWorkflowStarted,
}
}
}

View File

@ -17,9 +17,9 @@ export const useWorkflowTextChunk = () => {
draft.resultTabActive = true
draft.resultText += text
}))
}, [])
}, [workflowStore])
return {
handleWorkflowTextChunk,
}
}
}

View File

@ -15,9 +15,9 @@ export const useWorkflowTextReplace = () => {
setWorkflowRunningData(produce(workflowRunningData!, (draft) => {
draft.resultText = text
}))
}, [])
}, [workflowStore])
return {
handleWorkflowTextReplace,
}
}
}

View File

@ -242,19 +242,19 @@ export const useWorkflowRun = () => {
onTextReplace: (params) => {
handleWorkflowTextReplace(params)
},
onTTSChunk: (messageId: string, audio: string, audioType?: string) => {
onTTSChunk: (messageId: string, audio: string) => {
if (!audio || audio === '')
return
player.playAudioWithAudio(audio, true)
AudioPlayerManager.getInstance().resetMsgId(messageId)
},
onTTSEnd: (messageId: string, audio: string, audioType?: string) => {
onTTSEnd: (messageId: string, audio: string) => {
player.playAudioWithAudio(audio, false)
},
...restCallback,
},
)
}, [store, reactflow, workflowStore, doSyncWorkflowDraft])
}, [store, workflowStore, doSyncWorkflowDraft, handleWorkflowStarted, handleWorkflowFinished, handleWorkflowFailed, handleWorkflowNodeStarted, handleWorkflowNodeFinished, handleWorkflowNodeIterationStarted, handleWorkflowNodeIterationNext, handleWorkflowNodeIterationFinished, handleWorkflowNodeRetry, handleWorkflowTextChunk, handleWorkflowTextReplace, pathname])
const handleStopRun = useCallback((taskId: string) => {
const appId = useAppStore.getState().appDetail?.id