chore: start var name check

This commit is contained in:
Joel 2024-03-29 11:19:24 +08:00
parent 42ad622a6c
commit f930521d64
3 changed files with 14 additions and 5 deletions

View File

@ -70,7 +70,7 @@ const Prompt: FC<IPromptProps> = ({
}])
return
}
const lastMessageType = currentAdvancedPromptList[currentAdvancedPromptList.length - 1].role
const lastMessageType = currentAdvancedPromptList[currentAdvancedPromptList.length - 1]?.role
const appendMessage = {
role: lastMessageType === PromptRole.user ? PromptRole.assistant : PromptRole.user,
text: '',

View File

@ -9,10 +9,9 @@ import ConfigString from '../config-string'
import SelectTypeItem from '../select-type-item'
import Field from './field'
import Toast from '@/app/components/base/toast'
import { getNewVarInWorkflow } from '@/utils/var'
import { checkKeys, getNewVarInWorkflow } from '@/utils/var'
import ConfigContext from '@/context/debug-configuration'
import type { InputVar, MoreInfo } from '@/app/components/workflow/types'
import Modal from '@/app/components/base/modal'
import Switch from '@/app/components/base/switch'
import { ChangeType, InputVarType } from '@/app/components/workflow/types'
@ -42,6 +41,16 @@ const ConfigModal: FC<IConfigModalProps> = ({
const isStringInput = type === InputVarType.textInput || type === InputVarType.paragraph
const handlePayloadChange = useCallback((key: string) => {
return (value: any) => {
if (key === 'variable') {
const { isValid, errorKey, errorMessageKey } = checkKeys([value], true)
if (!isValid) {
Toast.notify({
type: 'error',
message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: errorKey }),
})
return
}
}
setTempPayload((prev) => {
return {
...prev,
@ -49,7 +58,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
}
})
}
}, [])
}, [t])
const handleConfirm = () => {
const moreInfo = tempPayload.variable === payload?.variable

View File

@ -40,7 +40,7 @@ export const getNewVarInWorkflow = (key: string, type = InputVarType.textInput)
}
}
const checkKey = (key: string, canBeEmpty?: boolean) => {
export const checkKey = (key: string, canBeEmpty?: boolean) => {
if (key.length === 0 && !canBeEmpty)
return 'canNoBeEmpty'