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: Inconsistency Between Actual and Debug Input Variables (#6055)

AIxGEEK22aaf8960b6c
diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx
index 40aee2a0e5e..43cd07d61fd 100644
--- a/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx
+++ b/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx
@@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
-import React, { useCallback } from 'react'
+import React, { useCallback, useMemo } from 'react'
import produce from 'immer'
import cn from 'classnames'
import type { InputVar } from '../../../../types'
@@ -24,14 +24,39 @@ const Form: FC<Props> = ({
values,
onChange,
}) => {
+ const mapKeysWithSameValueSelector = useMemo(() => {
+ const keysWithSameValueSelector = (key: string) => {
+ const targetValueSelector = inputs.find(
+ item => item.variable === key,
+ )?.value_selector
+ if (!targetValueSelector)
+ return [key]
+
+ const result: string[] = []
+ inputs.forEach((item) => {
+ if (item.value_selector?.join('.') === targetValueSelector.join('.'))
+ result.push(item.variable)
+ })
+ return result
+ }
+
+ const m = new Map()
+ for (const input of inputs)
+ m.set(input.variable, keysWithSameValueSelector(input.variable))
+
+ return m
+ }, [inputs])
+
const handleChange = useCallback((key: string) => {
+ const mKeys = mapKeysWithSameValueSelector.get(key) ?? [key]
return (value: any) => {
const newValues = produce(values, (draft) => {
- draft[key] = value
+ for (const k of mKeys)
+ draft[k] = value
})
onChange(newValues)
}
- }, [values, onChange])
+ }, [values, onChange, mapKeysWithSameValueSelector])
const isArrayLikeType = [InputVarType.contexts, InputVarType.iterator].includes(inputs[0]?.type)
const isContext = inputs[0]?.type === InputVarType.contexts
const handleAddContext = useCallback(() => {
diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts
index a3ffcbcc1f2..75fcb7dcc79 100644
--- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts
+++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts
@@ -337,6 +337,7 @@ const useOneStepRun = <T>({
variable: item.variable,
type: InputVarType.textInput,
required: true,
+ value_selector: item.value_selector,
}
}
return {
diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts
index 69b488344d6..b9605421678 100644
--- a/web/app/components/workflow/types.ts
+++ b/web/app/components/workflow/types.ts
@@ -132,6 +132,7 @@ export type InputVar = {
required: boolean
hint?: string
options?: string[]
+ value_selector?: ValueSelector
}
export type ModelConfig = {