mirror of
https://github.com/langgenius/dify.git
synced 2026-04-23 08:26:28 +08:00
feat: template transform
This commit is contained in:
parent
cedc1bada2
commit
1653e5eebe
@ -5,7 +5,7 @@ import type { CommonNodeType, InputVar, Variable } from '@/app/components/workfl
|
|||||||
import { InputVarType, NodeRunningStatus } from '@/app/components/workflow/types'
|
import { InputVarType, NodeRunningStatus } from '@/app/components/workflow/types'
|
||||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||||
import { singleNodeRun } from '@/service/workflow'
|
import { singleNodeRun } from '@/service/workflow'
|
||||||
import Toast from '@/app/components/base/toast'
|
// import Toast from '@/app/components/base/toast'
|
||||||
|
|
||||||
type Params<T> = {
|
type Params<T> = {
|
||||||
id: string
|
id: string
|
||||||
@ -51,10 +51,10 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
|
|||||||
throw new Error(res.error)
|
throw new Error(res.error)
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
Toast.notify({
|
// Toast.notify({
|
||||||
type: 'error',
|
// type: 'error',
|
||||||
message: e.toString(),
|
// message: e.toString(),
|
||||||
})
|
// })
|
||||||
handleNodeDataUpdate({
|
handleNodeDataUpdate({
|
||||||
id,
|
id,
|
||||||
data: {
|
data: {
|
||||||
@ -65,7 +65,10 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
setRunResult(res)
|
setRunResult({
|
||||||
|
...res,
|
||||||
|
created_by: res.created_by_account?.name || '',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
handleNodeDataUpdate({
|
handleNodeDataUpdate({
|
||||||
id,
|
id,
|
||||||
@ -74,10 +77,10 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
|
|||||||
_singleRunningStatus: NodeRunningStatus.Succeeded,
|
_singleRunningStatus: NodeRunningStatus.Succeeded,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
Toast.notify({
|
// Toast.notify({
|
||||||
type: 'success',
|
// type: 'success',
|
||||||
message: t('common.api.success'),
|
// message: t('common.api.success'),
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleStop = () => {
|
const handleStop = () => {
|
||||||
|
|||||||
@ -43,22 +43,13 @@ const useConfig = (id: string, payload: CodeNodeType) => {
|
|||||||
handleStop,
|
handleStop,
|
||||||
runInputData,
|
runInputData,
|
||||||
setRunInputData,
|
setRunInputData,
|
||||||
runResult: unformattedRunResult,
|
runResult,
|
||||||
} = useOneStepRun<CodeNodeType>({
|
} = useOneStepRun<CodeNodeType>({
|
||||||
id,
|
id,
|
||||||
data: inputs,
|
data: inputs,
|
||||||
defaultRunInputData: {},
|
defaultRunInputData: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
const runResult = (() => {
|
|
||||||
if (!unformattedRunResult)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...unformattedRunResult,
|
|
||||||
created_by: unformattedRunResult.created_by_account?.name || '',
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
const varInputs = toVarInputs(inputs.variables)
|
const varInputs = toVarInputs(inputs.variables)
|
||||||
|
|
||||||
const inputVarValues = (() => {
|
const inputVarValues = (() => {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/compo
|
|||||||
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
|
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
|
||||||
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 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'
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ const Panel: FC<NodePanelProps<TemplateTransformNodeType>> = ({
|
|||||||
varInputs,
|
varInputs,
|
||||||
inputVarValues,
|
inputVarValues,
|
||||||
setInputVarValues,
|
setInputVarValues,
|
||||||
|
runResult,
|
||||||
} = useConfig(id, data)
|
} = useConfig(id, data)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -105,6 +107,7 @@ const Panel: FC<NodePanelProps<TemplateTransformNodeType>> = ({
|
|||||||
runningStatus={runningStatus}
|
runningStatus={runningStatus}
|
||||||
onRun={handleRun}
|
onRun={handleRun}
|
||||||
onStop={handleStop}
|
onStop={handleStop}
|
||||||
|
result={<ResultPanel {...runResult} showSteps={false} />}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -29,6 +29,7 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
|||||||
handleStop,
|
handleStop,
|
||||||
runInputData,
|
runInputData,
|
||||||
setRunInputData,
|
setRunInputData,
|
||||||
|
runResult,
|
||||||
} = useOneStepRun<TemplateTransformNodeType>({
|
} = useOneStepRun<TemplateTransformNodeType>({
|
||||||
id,
|
id,
|
||||||
data: inputs,
|
data: inputs,
|
||||||
@ -63,6 +64,7 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
|||||||
varInputs,
|
varInputs,
|
||||||
inputVarValues,
|
inputVarValues,
|
||||||
setInputVarValues,
|
setInputVarValues,
|
||||||
|
runResult,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user