mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 21:55:58 +08:00
feat: node before and after run
This commit is contained in:
@ -2,6 +2,8 @@ import type { NodeDefault } from '../../types'
|
||||
import { CodeLanguage, type CodeNodeType } from './types'
|
||||
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
|
||||
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const nodeDefault: NodeDefault<CodeNodeType> = {
|
||||
defaultValue: {
|
||||
code: '',
|
||||
@ -17,18 +19,22 @@ const nodeDefault: NodeDefault<CodeNodeType> = {
|
||||
const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
|
||||
return nodes
|
||||
},
|
||||
checkValid(payload: CodeNodeType) {
|
||||
let isValid = true
|
||||
checkValid(payload: CodeNodeType, t: any) {
|
||||
let errorMessages = ''
|
||||
if (payload.type) {
|
||||
isValid = true
|
||||
errorMessages = ''
|
||||
}
|
||||
const { code, variables } = payload
|
||||
if (!errorMessages && variables.filter(v => !v.variable).length > 0)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variable`) })
|
||||
if (!errorMessages && variables.filter(v => !v.value_selector.length).length > 0)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variableValue`) })
|
||||
if (!errorMessages && !code)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.code`) })
|
||||
|
||||
return {
|
||||
isValid,
|
||||
isValid: !errorMessages,
|
||||
errorMessage: errorMessages,
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
export default nodeDefault
|
||||
|
||||
@ -48,6 +48,12 @@ const useConfig = (id: string, payload: CodeNodeType) => {
|
||||
id,
|
||||
data: inputs,
|
||||
defaultRunInputData: {},
|
||||
beforeRunCheckValid: () => {
|
||||
return {
|
||||
isValid: true,
|
||||
// errorMessage: 'xxxx',
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const varInputs = toVarInputs(inputs.variables)
|
||||
@ -63,7 +69,7 @@ const useConfig = (id: string, payload: CodeNodeType) => {
|
||||
|
||||
const setInputVarValues = useCallback((newPayload: Record<string, any>) => {
|
||||
setRunInputData(newPayload)
|
||||
}, [runInputData, setRunInputData])
|
||||
}, [setRunInputData])
|
||||
|
||||
return {
|
||||
inputs,
|
||||
|
||||
Reference in New Issue
Block a user