mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 14:51:39 +08:00
Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
38 lines
1.7 KiB
TypeScript
38 lines
1.7 KiB
TypeScript
import type { TFunction } from 'i18next'
|
|
import type { FormInputItem, HumanInputSharedConfig } from './types'
|
|
import type { Var } from '@/app/components/workflow/types'
|
|
import { VarType } from '@/app/components/workflow/types'
|
|
import { HUMAN_INPUT_TIMEOUT_HANDLE } from './constants'
|
|
|
|
const getFormInputVarType = (input: FormInputItem): VarType => {
|
|
if (input.type === 'file') return VarType.file
|
|
if (input.type === 'file-list') return VarType.arrayFile
|
|
return VarType.string
|
|
}
|
|
|
|
export const buildHumanInputOutputVars = (inputs: FormInputItem[]): Var[] =>
|
|
inputs.map((input) => ({
|
|
variable: input.output_variable_name,
|
|
type: getFormInputVarType(input),
|
|
}))
|
|
|
|
export const getHumanInputSharedValidationError = (
|
|
payload: Pick<HumanInputSharedConfig, 'user_actions'>,
|
|
t: TFunction<['workflow']>,
|
|
): string => {
|
|
if (!payload.user_actions.length)
|
|
return t(($) => $['nodes.humanInput.errorMsg.noUserActions'], { ns: 'workflow' })
|
|
if (new Set(payload.user_actions.map((action) => action.id)).size !== payload.user_actions.length)
|
|
return t(($) => $['nodes.humanInput.errorMsg.duplicateActionId'], { ns: 'workflow' })
|
|
if (payload.user_actions.some((action) => !action.id?.trim()))
|
|
return t(($) => $['nodes.humanInput.errorMsg.emptyActionId'], { ns: 'workflow' })
|
|
if (payload.user_actions.some((action) => action.id === HUMAN_INPUT_TIMEOUT_HANDLE))
|
|
return t(($) => $['nodes.humanInput.errorMsg.reservedActionId'], {
|
|
ns: 'workflow',
|
|
id: HUMAN_INPUT_TIMEOUT_HANDLE,
|
|
})
|
|
if (payload.user_actions.some((action) => !action.title?.trim()))
|
|
return t(($) => $['nodes.humanInput.errorMsg.emptyActionTitle'], { ns: 'workflow' })
|
|
return ''
|
|
}
|