diff --git a/web/app/components/app/configuration/config-var/config-modal/index.tsx b/web/app/components/app/configuration/config-var/config-modal/index.tsx index b0f0ea8779..bedcbfedbd 100644 --- a/web/app/components/app/configuration/config-var/config-modal/index.tsx +++ b/web/app/components/app/configuration/config-var/config-modal/index.tsx @@ -32,6 +32,19 @@ import { TransferMethod } from '@/types/app' import type { FileEntity } from '@/app/components/base/file-uploader/types' const TEXT_MAX_LENGTH = 256 +const CHECKBOX_DEFAULT_TRUE_VALUE = 'true' +const CHECKBOX_DEFAULT_FALSE_VALUE = 'false' + +const getCheckboxDefaultSelectValue = (value: InputVar['default']) => { + if (typeof value === 'boolean') + return value ? CHECKBOX_DEFAULT_TRUE_VALUE : CHECKBOX_DEFAULT_FALSE_VALUE + if (typeof value === 'string') + return value.toLowerCase() === CHECKBOX_DEFAULT_TRUE_VALUE ? CHECKBOX_DEFAULT_TRUE_VALUE : CHECKBOX_DEFAULT_FALSE_VALUE + return CHECKBOX_DEFAULT_FALSE_VALUE +} + +const parseCheckboxSelectValue = (value: string) => + value === CHECKBOX_DEFAULT_TRUE_VALUE export type IConfigModalProps = { isCreate?: boolean @@ -198,6 +211,8 @@ const ConfigModal: FC = ({ handlePayloadChange('variable')(e.target.value) }, [handlePayloadChange, t]) + const checkboxDefaultSelectValue = useMemo(() => getCheckboxDefaultSelectValue(tempPayload.default), [tempPayload.default]) + const handleConfirm = () => { const moreInfo = tempPayload.variable === payload?.variable ? undefined @@ -324,6 +339,23 @@ const ConfigModal: FC = ({ )} + {type === InputVarType.checkbox && ( + + handlePayloadChange('default')(parseCheckboxSelectValue(String(item.value)))} + placeholder={t('appDebug.variableConfig.selectDefaultValue')} + allowSearch={false} + /> + + )} + {type === InputVarType.select && ( <> diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index fb3e1bb8f3..79b6984bfe 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -235,13 +235,15 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { } } - if(item.checkbox) { + if (item.checkbox) { + const preset = initInputs[item.checkbox.variable] === true return { ...item.checkbox, - default: false, + default: preset || item.default || item.checkbox.default, type: 'checkbox', } } + if (item.select) { const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) return { diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 14a32860b9..aa7006db25 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -195,13 +195,16 @@ export const useEmbeddedChatbot = () => { type: 'number', } } + if (item.checkbox) { + const preset = initInputs[item.checkbox.variable] === true return { ...item.checkbox, - default: false, + default: preset || item.default || item.checkbox.default, type: 'checkbox', } } + if (item.select) { const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) return { diff --git a/web/app/components/share/text-generation/result/index.tsx b/web/app/components/share/text-generation/result/index.tsx index a7eb7f7591..ddc0d772c3 100644 --- a/web/app/components/share/text-generation/result/index.tsx +++ b/web/app/components/share/text-generation/result/index.tsx @@ -126,8 +126,8 @@ const Result: FC = ({ let hasEmptyInput = '' const requiredVars = prompt_variables?.filter(({ key, name, required, type }) => { - if(type === 'boolean') - return false // boolean input is not required + if(type === 'boolean' || type === 'checkbox') + return false // boolean/checkbox input is not required const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) || [] // compatible with old version diff --git a/web/app/components/share/text-generation/run-once/index.tsx b/web/app/components/share/text-generation/run-once/index.tsx index 7896776f35..4f94aa1fe8 100644 --- a/web/app/components/share/text-generation/run-once/index.tsx +++ b/web/app/components/share/text-generation/run-once/index.tsx @@ -51,6 +51,8 @@ const RunOnce: FC = ({ promptConfig.prompt_variables.forEach((item) => { if (item.type === 'string' || item.type === 'paragraph') newInputs[item.key] = '' + else if (item.type === 'checkbox') + newInputs[item.key] = false else newInputs[item.key] = undefined }) @@ -77,6 +79,8 @@ const RunOnce: FC = ({ newInputs[item.key] = item.default || '' else if (item.type === 'number') newInputs[item.key] = item.default + else if (item.type === 'checkbox') + newInputs[item.key] = item.default || false else if (item.type === 'file') newInputs[item.key] = item.default else if (item.type === 'file-list') @@ -96,7 +100,7 @@ const RunOnce: FC = ({ {(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) || !isInitialized ? null : promptConfig.prompt_variables.map(item => (
- {item.type !== 'boolean' && ( + {item.type !== 'checkbox' && ( )}
@@ -134,7 +138,7 @@ const RunOnce: FC = ({ onChange={(e: ChangeEvent) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }} /> )} - {item.type === 'boolean' && ( + {item.type === 'checkbox' && (