feat: support bool type variable frontend (#24437)

Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
This commit is contained in:
Joel
2025-08-26 18:16:05 +08:00
committed by GitHub
parent b5c2756261
commit dac72b078d
126 changed files with 3832 additions and 512 deletions

View File

@@ -18,6 +18,9 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
if (item.number)
return ['number', item.number]
if (item.checkbox)
return ['boolean', item.checkbox]
if (item.file)
return ['file', item.file]
@@ -27,6 +30,9 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
if (item.external_data_tool)
return [item.external_data_tool.type, item.external_data_tool]
if (item.json_object)
return ['json_object', item.json_object]
return ['select', item.select || {}]
})()
const is_context_var = dataset_query_variable === content?.variable
@@ -135,9 +141,9 @@ export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[
} as any)
return
}
if (item.type === 'number') {
if (item.type === 'number' || item.type === 'checkbox') {
userInputs.push({
number: {
[item.type]: {
label: item.name,
variable: item.key,
required: item.required !== false, // default true
@@ -177,3 +183,17 @@ export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[
return userInputs
}
export const formatBooleanInputs = (useInputs?: PromptVariable[] | null, inputs?: Record<string, string | number | object | boolean> | null) => {
if(!useInputs)
return inputs
const res = { ...(inputs || {}) }
useInputs.forEach((item) => {
const isBooleanInput = item.type === 'boolean'
if (isBooleanInput) {
// Convert boolean inputs to boolean type
res[item.key] = !!res[item.key]
}
})
return res
}

View File

@@ -45,7 +45,7 @@ export const getNewVarInWorkflow = (key: string, type = InputVarType.textInput)
}
}
export const checkKey = (key: string, canBeEmpty?: boolean) => {
export const checkKey = (key: string, canBeEmpty?: boolean, keys?: string[]) => {
if (key.length === 0 && !canBeEmpty)
return 'canNoBeEmpty'
@@ -82,6 +82,17 @@ export const checkKeys = (keys: string[], canBeEmpty?: boolean) => {
return { isValid, errorKey, errorMessageKey }
}
export const hasDuplicateStr = (strArr: string[]) => {
const strObj: Record<string, number> = {}
strArr.forEach((str) => {
if (strObj[str])
strObj[str] += 1
else
strObj[str] = 1
})
return !!Object.keys(strObj).find(key => strObj[key] > 1)
}
const varRegex = /\{\{([a-zA-Z_]\w*)\}\}/g
export const getVars = (value: string) => {
if (!value)