feat: new var input editor

This commit is contained in:
Joel
2024-02-22 18:49:21 +08:00
parent ee616ee6dd
commit 235bec6481
13 changed files with 250 additions and 134 deletions

View File

@ -1,5 +1,6 @@
import { MAX_VAR_KEY_LENGHT, VAR_ITEM_TEMPLATE, getMaxVarNameLength } from '@/config'
import { MAX_VAR_KEY_LENGHT, VAR_ITEM_TEMPLATE, VAR_ITEM_TEMPLATE_IN_WORKFLOW, getMaxVarNameLength } from '@/config'
import { CONTEXT_PLACEHOLDER_TEXT, HISTORY_PLACEHOLDER_TEXT, PRE_PROMPT_PLACEHOLDER_TEXT, QUERY_PLACEHOLDER_TEXT } from '@/app/components/base/prompt-editor/constants'
import { InputVarType } from '@/app/components/workflow/types'
const otherAllowedRegex = /^[a-zA-Z0-9_]+$/
@ -21,6 +22,24 @@ export const getNewVar = (key: string, type: string) => {
}
}
export const getNewVarInWorkflow = (key: string, type = InputVarType.textInput) => {
const { max_length, ...rest } = VAR_ITEM_TEMPLATE_IN_WORKFLOW
if (type !== InputVarType.textInput) {
return {
...rest,
type,
variable: key,
label: key.slice(0, getMaxVarNameLength(key)),
}
}
return {
...VAR_ITEM_TEMPLATE_IN_WORKFLOW,
type,
variable: key,
label: key.slice(0, getMaxVarNameLength(key)),
}
}
const checkKey = (key: string, canBeEmpty?: boolean) => {
if (key.length === 0 && !canBeEmpty)
return 'canNoBeEmpty'