Chore/workflow last run (#21823)

Co-authored-by: Joel <iamjoel007@gmail.com>
This commit is contained in:
zxhlyh
2025-07-02 17:48:07 +08:00
committed by GitHub
parent 8978b9d38b
commit 3bfa9767c0
13 changed files with 422 additions and 235 deletions

View File

@@ -1,19 +1,23 @@
import { useCallback } from 'react'
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
import { useWorkflowStore } from '../../workflow/store'
import { useWorkflowStore } from '@/app/components/workflow/store'
import { useStoreApi } from 'reactflow'
import type { Node } from '@/app/components/workflow/types'
import { fetchAllInspectVars } from '@/service/workflow'
import { useInvalidateConversationVarValues, useInvalidateSysVarValues } from '@/service/use-workflow'
import { useNodesInteractionsWithoutSync } from '../../workflow/hooks/use-nodes-interactions-without-sync'
const useSetWorkflowVarsWithValue = () => {
import { useNodesInteractionsWithoutSync } from '@/app/components/workflow/hooks/use-nodes-interactions-without-sync'
import { useConfigsMap } from './use-configs-map'
export const useSetWorkflowVarsWithValue = () => {
const workflowStore = useWorkflowStore()
const { setNodesWithInspectVars, appId } = workflowStore.getState()
const store = useStoreApi()
const invalidateConversationVarValues = useInvalidateConversationVarValues(appId)
const invalidateSysVarValues = useInvalidateSysVarValues(appId)
const { conversationVarsUrl, systemVarsUrl } = useConfigsMap()
const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl)
const invalidateSysVarValues = useInvalidateSysVarValues(systemVarsUrl)
const { handleCancelAllNodeSuccessStatus } = useNodesInteractionsWithoutSync()
const setInspectVarsToStore = (inspectVars: VarInInspect[]) => {
const setInspectVarsToStore = useCallback((inspectVars: VarInInspect[]) => {
const { setNodesWithInspectVars } = workflowStore.getState()
const { getNodes } = store.getState()
const nodeArr = getNodes()
const nodesKeyValue: Record<string, Node> = {}
@@ -51,18 +55,17 @@ const useSetWorkflowVarsWithValue = () => {
return nodeWithVar
})
setNodesWithInspectVars(res)
}
}, [workflowStore, store])
const fetchInspectVars = async () => {
const fetchInspectVars = useCallback(async () => {
const { appId } = workflowStore.getState()
invalidateConversationVarValues()
invalidateSysVarValues()
const data = await fetchAllInspectVars(appId)
setInspectVarsToStore(data)
handleCancelAllNodeSuccessStatus() // to make sure clear node output show the unset status
}
}, [workflowStore, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarsToStore, handleCancelAllNodeSuccessStatus])
return {
fetchInspectVars,
}
}
export default useSetWorkflowVarsWithValue