@ -11,7 +11,6 @@ import { getNodeInfoById, isConversationVar, isENV, isSystemVar, toNodeOutputVar
import type { CommonNodeType , InputVar , ValueSelector , Var , Variable } from '@/app/components/workflow/types'
import type { CommonNodeType , InputVar , ValueSelector , Var , Variable } from '@/app/components/workflow/types'
import { BlockEnum , InputVarType , NodeRunningStatus , VarType } from '@/app/components/workflow/types'
import { BlockEnum , InputVarType , NodeRunningStatus , VarType } from '@/app/components/workflow/types'
import { useStore as useAppStore } from '@/app/components/app/store'
import { useStore , useWorkflowStore } from '@/app/components/workflow/store'
import { useStore , useWorkflowStore } from '@/app/components/workflow/store'
import { fetchNodeInspectVars , getIterationSingleNodeRunUrl , getLoopSingleNodeRunUrl , singleNodeRun } from '@/service/workflow'
import { fetchNodeInspectVars , getIterationSingleNodeRunUrl , getLoopSingleNodeRunUrl , singleNodeRun } from '@/service/workflow'
import Toast from '@/app/components/base/toast'
import Toast from '@/app/components/base/toast'
@ -52,6 +51,7 @@ import {
} from 'reactflow'
} from 'reactflow'
import { useInvalidLastRun } from '@/service/use-workflow'
import { useInvalidLastRun } from '@/service/use-workflow'
import useInspectVarsCrud from '../../../hooks/use-inspect-vars-crud'
import useInspectVarsCrud from '../../../hooks/use-inspect-vars-crud'
import type { FlowType } from '@/types/common'
// eslint-disable-next-line ts/no-unsafe-function-type
// eslint-disable-next-line ts/no-unsafe-function-type
const checkValidFns : Record < BlockEnum , Function > = {
const checkValidFns : Record < BlockEnum , Function > = {
[ BlockEnum . LLM ] : checkLLMValid ,
[ BlockEnum . LLM ] : checkLLMValid ,
@ -72,6 +72,8 @@ const checkValidFns: Record<BlockEnum, Function> = {
export type Params < T > = {
export type Params < T > = {
id : string
id : string
flowId : string
flowType : FlowType
data : CommonNodeType < T >
data : CommonNodeType < T >
defaultRunInputData : Record < string , any >
defaultRunInputData : Record < string , any >
moreDataForCheckValid? : any
moreDataForCheckValid? : any
@ -106,6 +108,8 @@ const varTypeToInputVarType = (type: VarType, {
const useOneStepRun = < T > ( {
const useOneStepRun = < T > ( {
id ,
id ,
flowId ,
flowType ,
data ,
data ,
defaultRunInputData ,
defaultRunInputData ,
moreDataForCheckValid ,
moreDataForCheckValid ,
@ -153,7 +157,6 @@ const useOneStepRun = <T>({
const checkValid = checkValidFns [ data . type ]
const checkValid = checkValidFns [ data . type ]
const appId = useAppStore . getState ( ) . appDetail ? . id
const [ runInputData , setRunInputData ] = useState < Record < string , any > > ( defaultRunInputData || { } )
const [ runInputData , setRunInputData ] = useState < Record < string , any > > ( defaultRunInputData || { } )
const runInputDataRef = useRef ( runInputData )
const runInputDataRef = useRef ( runInputData )
const handleSetRunInputData = useCallback ( ( data : Record < string , any > ) = > {
const handleSetRunInputData = useCallback ( ( data : Record < string , any > ) = > {
@ -168,7 +171,7 @@ const useOneStepRun = <T>({
const {
const {
setShowSingleRunPanel ,
setShowSingleRunPanel ,
} = workflowStore . getState ( )
} = workflowStore . getState ( )
const invalidLastRun = useInvalidLastRun ( app Id! , id )
const invalidLastRun = useInvalidLastRun ( flowType, flow Id! , id )
const [ runResult , doSetRunResult ] = useState < NodeRunResult | null > ( null )
const [ runResult , doSetRunResult ] = useState < NodeRunResult | null > ( null )
const {
const {
appendNodeInspectVars ,
appendNodeInspectVars ,
@ -195,7 +198,7 @@ const useOneStepRun = <T>({
}
}
// run fail may also update the inspect vars when the node set the error default output.
// run fail may also update the inspect vars when the node set the error default output.
const vars = await fetchNodeInspectVars ( app Id! , id )
const vars = await fetchNodeInspectVars ( flowType, flow Id! , id )
const { getNodes } = store . getState ( )
const { getNodes } = store . getState ( )
const nodes = getNodes ( )
const nodes = getNodes ( )
appendNodeInspectVars ( id , vars , nodes )
appendNodeInspectVars ( id , vars , nodes )
@ -205,7 +208,7 @@ const useOneStepRun = <T>({
invalidateSysVarValues ( )
invalidateSysVarValues ( )
invalidateConversationVarValues ( ) // loop, iteration, variable assigner node can update the conversation variables, but to simple the logic(some nodes may also can update in the future), all nodes refresh.
invalidateConversationVarValues ( ) // loop, iteration, variable assigner node can update the conversation variables, but to simple the logic(some nodes may also can update in the future), all nodes refresh.
}
}
} , [ isRunAfterSingleRun , runningStatus , app Id, id , store , appendNodeInspectVars , invalidLastRun , isStartNode , invalidateSysVarValues , invalidateConversationVarValues ] )
} , [ isRunAfterSingleRun , runningStatus , flow Id, id , store , appendNodeInspectVars , invalidLastRun , isStartNode , invalidateSysVarValues , invalidateConversationVarValues ] )
const { handleNodeDataUpdate } : { handleNodeDataUpdate : ( data : any ) = > void } = useNodeDataUpdate ( )
const { handleNodeDataUpdate } : { handleNodeDataUpdate : ( data : any ) = > void } = useNodeDataUpdate ( )
const setNodeRunning = ( ) = > {
const setNodeRunning = ( ) = > {
@ -305,14 +308,14 @@ const useOneStepRun = <T>({
else {
else {
postData . inputs = submitData
postData . inputs = submitData
}
}
res = await singleNodeRun ( app Id! , id , postData ) as any
res = await singleNodeRun ( flow Id! , id , postData ) as any
}
}
else if ( isIteration ) {
else if ( isIteration ) {
setIterationRunResult ( [ ] )
setIterationRunResult ( [ ] )
let _iterationResult : NodeTracing [ ] = [ ]
let _iterationResult : NodeTracing [ ] = [ ]
let _runResult : any = null
let _runResult : any = null
ssePost (
ssePost (
getIterationSingleNodeRunUrl ( isChatMode , app Id! , id ) ,
getIterationSingleNodeRunUrl ( isChatMode , flow Id! , id ) ,
{ body : { inputs : submitData } } ,
{ body : { inputs : submitData } } ,
{
{
onWorkflowStarted : noop ,
onWorkflowStarted : noop ,
@ -415,7 +418,7 @@ const useOneStepRun = <T>({
let _loopResult : NodeTracing [ ] = [ ]
let _loopResult : NodeTracing [ ] = [ ]
let _runResult : any = null
let _runResult : any = null
ssePost (
ssePost (
getLoopSingleNodeRunUrl ( isChatMode , app Id! , id ) ,
getLoopSingleNodeRunUrl ( isChatMode , flow Id! , id ) ,
{ body : { inputs : submitData } } ,
{ body : { inputs : submitData } } ,
{
{
onWorkflowStarted : noop ,
onWorkflowStarted : noop ,
@ -633,7 +636,6 @@ const useOneStepRun = <T>({
}
}
return {
return {
appId ,
isShowSingleRun ,
isShowSingleRun ,
hideSingleRun ,
hideSingleRun ,
showSingleRun ,
showSingleRun ,