feat: start node single run

This commit is contained in:
Joel 2025-05-06 14:15:59 +08:00
parent a4b807c9df
commit c414b2613a
4 changed files with 65 additions and 12 deletions

View File

@ -55,6 +55,8 @@ function formatValue(value: string | any, type: InputVarType) {
if (type === InputVarType.singleFile) {
if (Array.isArray(value))
return getProcessedFiles(value)
if (!value)
return undefined
return getProcessedFiles([value])[0]
}

View File

@ -4,16 +4,17 @@ import { useCallback, useState } from 'react'
import { TabType } from '../tab'
import { useWorkflowStore } from '@/app/components/workflow/store'
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form'
import useStartSingleRunFormParams from '@/app/components/workflow/nodes/start/use-single-run-form-params'
import useLLMSingleRunFormParams from '@/app/components/workflow/nodes/llm/use-single-run-form-params'
import useKnowledgeRetrievalSingleRunFormParams from '../../../../knowledge-retrieval/use-single-run-form-params'
import useCodeSingleRunFormParams from '../../../../code/use-single-run-form-params'
import useTemplateTransformSingleRunFormParams from '../../../../template-transform/use-single-run-form-params'
import useQuestionClassifierSingleRunFormParams from '../../../../question-classifier/use-single-run-form-params'
import useParameterExtractorSingleRunFormParams from '../../../../parameter-extractor/use-single-run-form-params'
import useHttpRequestSingleRunFormParams from '../../../../http/use-single-run-form-params'
import useIterationSingleRunFormParams from '../../../../iteration/use-single-run-form-params'
import useDocExtractorSingleRunFormParams from '../../../../document-extractor/use-single-run-form-params'
import useLoopSingleRunFormParams from '../../../../loop/use-single-run-form-params'
import useKnowledgeRetrievalSingleRunFormParams from '@/app/components/workflow/nodes/knowledge-retrieval/use-single-run-form-params'
import useCodeSingleRunFormParams from '@/app/components/workflow/nodes/code/use-single-run-form-params'
import useTemplateTransformSingleRunFormParams from '@/app/components/workflow/nodes/template-transform/use-single-run-form-params'
import useQuestionClassifierSingleRunFormParams from '@/app/components/workflow/nodes/question-classifier/use-single-run-form-params'
import useParameterExtractorSingleRunFormParams from '@/app/components/workflow/nodes/parameter-extractor/use-single-run-form-params'
import useHttpRequestSingleRunFormParams from '@/app/components/workflow/nodes/http/use-single-run-form-params'
import useIterationSingleRunFormParams from '@/app/components/workflow/nodes/iteration/use-single-run-form-params'
import useDocExtractorSingleRunFormParams from '@/app/components/workflow/nodes/document-extractor/use-single-run-form-params'
import useLoopSingleRunFormParams from '@/app/components/workflow/nodes/loop/use-single-run-form-params'
import { BlockEnum } from '@/app/components/workflow/types'
import {
useNodesSyncDraft,
@ -32,12 +33,12 @@ const singleRunFormParamsHooks: Record<BlockEnum, any> = {
[BlockEnum.Agent]: undefined,
[BlockEnum.DocExtractor]: useDocExtractorSingleRunFormParams,
[BlockEnum.Loop]: useLoopSingleRunFormParams,
[BlockEnum.Start]: undefined,
[BlockEnum.Start]: useStartSingleRunFormParams,
[BlockEnum.IfElse]: undefined,
[BlockEnum.VariableAggregator]: undefined,
[BlockEnum.End]: undefined,
[BlockEnum.Answer]: undefined,
[BlockEnum.IfElse]: undefined,
[BlockEnum.VariableAssigner]: undefined,
[BlockEnum.VariableAggregator]: undefined,
[BlockEnum.ListFilter]: undefined,
[BlockEnum.IterationStart]: undefined,
[BlockEnum.Assigner]: undefined,

View File

@ -0,0 +1,47 @@
import type { MutableRefObject } from 'react'
import { useTranslation } from 'react-i18next'
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form'
import type { InputVar, Variable } from '@/app/components/workflow/types'
import type { StartNodeType } from './types'
type Params = {
id: string,
payload: StartNodeType,
runInputData: Record<string, any>
runInputDataRef: MutableRefObject<Record<string, any>>
getInputVars: (textList: string[]) => InputVar[]
setRunInputData: (data: Record<string, any>) => void
toVarInputs: (variables: Variable[]) => InputVar[]
}
const useSingleRunFormParams = ({
payload,
runInputData,
setRunInputData,
}: Params) => {
const { t } = useTranslation()
const forms = (() => {
const forms: FormProps[] = []
forms.push(
{
label: t('workflow.nodes.llm.singleRun.variable')!,
inputs: payload.variables.map((item: InputVar) => ({
label: item.variable,
variable: item.variable,
type: item.type,
required: item.required,
})),
values: runInputData,
onChange: setRunInputData,
},
)
return forms
})()
return {
forms,
}
}
export default useSingleRunFormParams

View File

@ -32,6 +32,9 @@ export const canRunBySingle = (nodeType: BlockEnum) => {
|| nodeType === BlockEnum.Agent
|| nodeType === BlockEnum.DocExtractor
|| nodeType === BlockEnum.Loop
|| nodeType === BlockEnum.Start
|| nodeType === BlockEnum.IfElse
|| nodeType === BlockEnum.VariableAggregator
}
type ConnectedSourceOrTargetNodesChange = {