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.

Fix variable config (#23070)

GuanMu77216488675d
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 72c66cf76a1..27072f52085 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
@@ -244,6 +244,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
<SimpleSelect
key={`default-select-${options.join('-')}`}
className="w-full"
+ optionWrapClassName="max-h-[140px] overflow-y-auto"
items={[
{ value: '', name: t('appDebug.variableConfig.noDefaultValue') },
...options.filter(opt => opt.trim() !== '').map(option => ({
diff --git a/web/app/components/base/select/index.tsx b/web/app/components/base/select/index.tsx
index 77d229672fc..d9285c10615 100644
--- a/web/app/components/base/select/index.tsx
+++ b/web/app/components/base/select/index.tsx
@@ -77,7 +77,6 @@ const Select: FC<ISelectProps> = ({
defaultSelect = existed
setSelectedItem(defaultSelect)
- // eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultValue])
const filteredItems: Item[]
@@ -201,7 +200,6 @@ const SimpleSelect: FC<ISelectProps> = ({
defaultSelect = existed
setSelectedItem(defaultSelect)
- // eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultValue])
const listboxRef = useRef<HTMLDivElement>(null)
@@ -344,7 +342,7 @@ const PortalSelect: FC<PortalSelectProps> = ({
>
<span
className={`
- grow truncate
+ grow truncate text-text-secondary
${!selectedItem?.name && 'text-components-input-text-placeholder'}
`}
>
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 546b21d2b0a..cfafe73bf29 100644
--- a/web/app/components/share/text-generation/run-once/index.tsx
+++ b/web/app/components/share/text-generation/run-once/index.tsx
@@ -66,7 +66,9 @@ const RunOnce: FC<IRunOnceProps> = ({
useEffect(() => {
const newInputs: Record<string, any> = {}
promptConfig.prompt_variables.forEach((item) => {
- if (item.type === 'string' || item.type === 'paragraph')
+ if (item.type === 'select')
+ newInputs[item.key] = item.default
+ else if (item.type === 'string' || item.type === 'paragraph')
newInputs[item.key] = ''
else
newInputs[item.key] = undefined
diff --git a/web/app/components/workflow/panel/inputs-panel.tsx b/web/app/components/workflow/panel/inputs-panel.tsx
index 8be8d810f0f..64ac6d86865 100644
--- a/web/app/components/workflow/panel/inputs-panel.tsx
+++ b/web/app/components/workflow/panel/inputs-panel.tsx
@@ -1,6 +1,7 @@
import {
memo,
useCallback,
+ useEffect,
useMemo,
} from 'react'
import { useTranslation } from 'react-i18next'
@@ -32,9 +33,12 @@ type Props = {
const InputsPanel = ({ onRun }: Props) => {
const { t } = useTranslation()
const workflowStore = useWorkflowStore()
+ const { inputs, setInputs } = useStore(s => ({
+ inputs: s.inputs,
+ setInputs: s.setInputs,
+ }))
const fileSettings = useFeatures(s => s.features.file)
const nodes = useNodes<StartNodeType>()
- const inputs = useStore(s => s.inputs)
const files = useStore(s => s.files)
const workflowRunningData = useStore(s => s.workflowRunningData)
const {
@@ -44,6 +48,24 @@ const InputsPanel = ({ onRun }: Props) => {
const startVariables = startNode?.data.variables
const { checkInputsForm } = useCheckInputsForms()
+ const initialInputs = useMemo(() => {
+ const initInputs: Record<string, any> = {}
+ if (startVariables) {
+ startVariables.forEach((variable) => {
+ if (variable.default)
+ initInputs[variable.variable] = variable.default
+ })
+ }
+ return initInputs
+ }, [startVariables])
+
+ useEffect(() => {
+ setInputs({
+ ...initialInputs,
+ ...inputs,
+ })
+ }, [initialInputs])
+
const variables = useMemo(() => {
const data = startVariables || []
if (fileSettings?.image?.enabled) {
diff --git a/web/utils/model-config.ts b/web/utils/model-config.ts
index 330d8f9b528..3a500f22bcd 100644
--- a/web/utils/model-config.ts
+++ b/web/utils/model-config.ts
@@ -62,6 +62,7 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
options: content.options,
is_context_var,
hide: content.hide,
+ default: content.default,
})
}
else if (type === 'file') {
@@ -148,7 +149,7 @@ export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[
variable: item.key,
required: item.required !== false, // default true
options: item.options,
- default: '',
+ default: item.default ?? '',
hide: item.hide,
},
} as any)