mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 03:35:57 +08:00
feat: template transform single run
This commit is contained in:
parent
739ee05446
commit
308baed9c9
@ -7,6 +7,7 @@ import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/c
|
|||||||
import useLLMSingleRunFormParams from '@/app/components/workflow/nodes/llm/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 useKnowledgeRetrievalSingleRunFormParams from '../../../../knowledge-retrieval/use-single-run-form-params'
|
||||||
import useCodeSingleRunFormParams from '../../../../code/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 { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
import {
|
import {
|
||||||
useNodesSyncDraft,
|
useNodesSyncDraft,
|
||||||
@ -16,12 +17,12 @@ const singleRunFormParamsHooks: Record<BlockEnum, any> = {
|
|||||||
[BlockEnum.LLM]: useLLMSingleRunFormParams,
|
[BlockEnum.LLM]: useLLMSingleRunFormParams,
|
||||||
[BlockEnum.KnowledgeRetrieval]: useKnowledgeRetrievalSingleRunFormParams,
|
[BlockEnum.KnowledgeRetrieval]: useKnowledgeRetrievalSingleRunFormParams,
|
||||||
[BlockEnum.Code]: useCodeSingleRunFormParams,
|
[BlockEnum.Code]: useCodeSingleRunFormParams,
|
||||||
|
[BlockEnum.TemplateTransform]: useTemplateTransformSingleRunFormParams,
|
||||||
[BlockEnum.Start]: undefined,
|
[BlockEnum.Start]: undefined,
|
||||||
[BlockEnum.End]: undefined,
|
[BlockEnum.End]: undefined,
|
||||||
[BlockEnum.Answer]: undefined,
|
[BlockEnum.Answer]: undefined,
|
||||||
[BlockEnum.QuestionClassifier]: undefined,
|
[BlockEnum.QuestionClassifier]: undefined,
|
||||||
[BlockEnum.IfElse]: undefined,
|
[BlockEnum.IfElse]: undefined,
|
||||||
[BlockEnum.TemplateTransform]: undefined,
|
|
||||||
[BlockEnum.HttpRequest]: undefined,
|
[BlockEnum.HttpRequest]: undefined,
|
||||||
[BlockEnum.VariableAssigner]: undefined,
|
[BlockEnum.VariableAssigner]: undefined,
|
||||||
[BlockEnum.VariableAggregator]: undefined,
|
[BlockEnum.VariableAggregator]: undefined,
|
||||||
|
@ -14,8 +14,6 @@ import Split from '@/app/components/workflow/nodes/_base/components/split'
|
|||||||
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars'
|
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars'
|
||||||
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
||||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||||
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
|
|
||||||
import ResultPanel from '@/app/components/workflow/run/result-panel'
|
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.templateTransform'
|
const i18nPrefix = 'workflow.nodes.templateTransform'
|
||||||
|
|
||||||
@ -35,16 +33,6 @@ const Panel: FC<NodePanelProps<TemplateTransformNodeType>> = ({
|
|||||||
handleAddEmptyVariable,
|
handleAddEmptyVariable,
|
||||||
handleCodeChange,
|
handleCodeChange,
|
||||||
filterVar,
|
filterVar,
|
||||||
// single run
|
|
||||||
isShowSingleRun,
|
|
||||||
hideSingleRun,
|
|
||||||
runningStatus,
|
|
||||||
handleRun,
|
|
||||||
handleStop,
|
|
||||||
varInputs,
|
|
||||||
inputVarValues,
|
|
||||||
setInputVarValues,
|
|
||||||
runResult,
|
|
||||||
} = useConfig(id, data)
|
} = useConfig(id, data)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -106,23 +94,6 @@ const Panel: FC<NodePanelProps<TemplateTransformNodeType>> = ({
|
|||||||
</>
|
</>
|
||||||
</OutputVars>
|
</OutputVars>
|
||||||
</div>
|
</div>
|
||||||
{isShowSingleRun && (
|
|
||||||
<BeforeRunForm
|
|
||||||
nodeName={inputs.title}
|
|
||||||
onHide={hideSingleRun}
|
|
||||||
forms={[
|
|
||||||
{
|
|
||||||
inputs: varInputs,
|
|
||||||
values: inputVarValues,
|
|
||||||
onChange: setInputVarValues,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
runningStatus={runningStatus}
|
|
||||||
onRun={handleRun}
|
|
||||||
onStop={handleStop}
|
|
||||||
result={<ResultPanel {...runResult} showSteps={false} />}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import { VarType } from '../../types'
|
|||||||
import { useStore } from '../../store'
|
import { useStore } from '../../store'
|
||||||
import type { TemplateTransformNodeType } from './types'
|
import type { TemplateTransformNodeType } from './types'
|
||||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||||
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
|
|
||||||
import {
|
import {
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
@ -76,37 +75,6 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
|||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
// single run
|
|
||||||
const {
|
|
||||||
isShowSingleRun,
|
|
||||||
hideSingleRun,
|
|
||||||
toVarInputs,
|
|
||||||
runningStatus,
|
|
||||||
handleRun,
|
|
||||||
handleStop,
|
|
||||||
runInputData,
|
|
||||||
setRunInputData,
|
|
||||||
runResult,
|
|
||||||
} = useOneStepRun<TemplateTransformNodeType>({
|
|
||||||
id,
|
|
||||||
data: inputs,
|
|
||||||
defaultRunInputData: {},
|
|
||||||
})
|
|
||||||
const varInputs = toVarInputs(inputs.variables)
|
|
||||||
|
|
||||||
const inputVarValues = (() => {
|
|
||||||
const vars: Record<string, any> = {}
|
|
||||||
Object.keys(runInputData)
|
|
||||||
.forEach((key) => {
|
|
||||||
vars[key] = runInputData[key]
|
|
||||||
})
|
|
||||||
return vars
|
|
||||||
})()
|
|
||||||
|
|
||||||
const setInputVarValues = useCallback((newPayload: Record<string, any>) => {
|
|
||||||
setRunInputData(newPayload)
|
|
||||||
}, [setRunInputData])
|
|
||||||
|
|
||||||
const filterVar = useCallback((varPayload: Var) => {
|
const filterVar = useCallback((varPayload: Var) => {
|
||||||
return [VarType.string, VarType.number, VarType.object, VarType.array, VarType.arrayNumber, VarType.arrayString, VarType.arrayObject].includes(varPayload.type)
|
return [VarType.string, VarType.number, VarType.object, VarType.array, VarType.arrayNumber, VarType.arrayString, VarType.arrayObject].includes(varPayload.type)
|
||||||
}, [])
|
}, [])
|
||||||
@ -121,16 +89,6 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
|||||||
handleAddEmptyVariable,
|
handleAddEmptyVariable,
|
||||||
handleCodeChange,
|
handleCodeChange,
|
||||||
filterVar,
|
filterVar,
|
||||||
// single run
|
|
||||||
isShowSingleRun,
|
|
||||||
hideSingleRun,
|
|
||||||
runningStatus,
|
|
||||||
handleRun,
|
|
||||||
handleStop,
|
|
||||||
varInputs,
|
|
||||||
inputVarValues,
|
|
||||||
setInputVarValues,
|
|
||||||
runResult,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
import type { MutableRefObject } from 'react'
|
||||||
|
import type { InputVar, Variable } from '@/app/components/workflow/types'
|
||||||
|
import { useCallback, useMemo } from 'react'
|
||||||
|
import useNodeCrud from '../_base/hooks/use-node-crud'
|
||||||
|
import type { TemplateTransformNodeType } from './types'
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
id: string,
|
||||||
|
payload: TemplateTransformNodeType,
|
||||||
|
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 = ({
|
||||||
|
id,
|
||||||
|
payload,
|
||||||
|
runInputData,
|
||||||
|
toVarInputs,
|
||||||
|
setRunInputData,
|
||||||
|
}: Params) => {
|
||||||
|
const { inputs } = useNodeCrud<TemplateTransformNodeType>(id, payload)
|
||||||
|
|
||||||
|
const varInputs = toVarInputs(inputs.variables)
|
||||||
|
const setInputVarValues = useCallback((newPayload: Record<string, any>) => {
|
||||||
|
setRunInputData(newPayload)
|
||||||
|
}, [setRunInputData])
|
||||||
|
const inputVarValues = (() => {
|
||||||
|
const vars: Record<string, any> = {}
|
||||||
|
Object.keys(runInputData)
|
||||||
|
.forEach((key) => {
|
||||||
|
vars[key] = runInputData[key]
|
||||||
|
})
|
||||||
|
return vars
|
||||||
|
})()
|
||||||
|
|
||||||
|
const forms = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
inputs: varInputs,
|
||||||
|
values: inputVarValues,
|
||||||
|
onChange: setInputVarValues,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}, [inputVarValues, setInputVarValues, varInputs])
|
||||||
|
|
||||||
|
return {
|
||||||
|
forms,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useSingleRunFormParams
|
Loading…
x
Reference in New Issue
Block a user