Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore: improve bool input of start node (#26647)

非法操作9cca605bac55
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 b0f0ea87794..bedcbfedbd5 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<IConfigModalProps> = ({
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<IConfigModalProps> = ({
</Field>
)}
+ {type === InputVarType.checkbox && (
+ <Field title={t('appDebug.variableConfig.defaultValue')}>
+ <SimpleSelect
+ className="w-full"
+ optionWrapClassName="max-h-[140px] overflow-y-auto"
+ items={[
+ { value: CHECKBOX_DEFAULT_TRUE_VALUE, name: t('appDebug.variableConfig.startChecked') },
+ { value: CHECKBOX_DEFAULT_FALSE_VALUE, name: t('appDebug.variableConfig.noDefaultSelected') },
+ ]}
+ defaultValue={checkboxDefaultSelectValue}
+ onSelect={item => handlePayloadChange('default')(parseCheckboxSelectValue(String(item.value)))}
+ placeholder={t('appDebug.variableConfig.selectDefaultValue')}
+ allowSearch={false}
+ />
+ </Field>
+ )}
+
{type === InputVarType.select && (
<>
<Field title={t('appDebug.variableConfig.options')}>
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 fb3e1bb8f37..79b6984bfe4 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 14a32860b9b..aa7006db253 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 a7eb7f75916..ddc0d772c39 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<IResultProps> = ({
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 7896776f357..4f94aa1fe81 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<IRunOnceProps> = ({
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<IRunOnceProps> = ({
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<IRunOnceProps> = ({
{(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) || !isInitialized ? null
: promptConfig.prompt_variables.map(item => (
<div className='mt-4 w-full' key={item.key}>
- {item.type !== 'boolean' && (
+ {item.type !== 'checkbox' && (
<label className='system-md-semibold flex h-6 items-center text-text-secondary'>{item.name}</label>
)}
<div className='mt-1'>
@@ -134,7 +138,7 @@ const RunOnce: FC<IRunOnceProps> = ({
onChange={(e: ChangeEvent<HTMLInputElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
/>
)}
- {item.type === 'boolean' && (
+ {item.type === 'checkbox' && (
<BoolInput
name={item.name || item.key}
value={!!inputs[item.key]}
diff --git a/web/utils/model-config.ts b/web/utils/model-config.ts
index c940a6969f9..3f655ce0366 100644
--- a/web/utils/model-config.ts
+++ b/web/utils/model-config.ts
@@ -61,6 +61,17 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
default: content.default,
})
}
+ else if (type === 'boolean') {
+ promptVariables.push({
+ key: content.variable,
+ name: content.label,
+ required: content.required,
+ type: 'checkbox',
+ options: [],
+ hide: content.hide,
+ default: content.default,
+ })
+ }
else if (type === 'select') {
promptVariables.push({
key: content.variable,