mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 06:55:57 +08:00
fix: Inconsistency Between Actual and Debug Input Variables (#6055)
This commit is contained in:
parent
0046ef7707
commit
22aaf8960b
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback, useMemo } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
import type { InputVar } from '../../../../types'
|
import type { InputVar } from '../../../../types'
|
||||||
@ -24,14 +24,39 @@ const Form: FC<Props> = ({
|
|||||||
values,
|
values,
|
||||||
onChange,
|
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 handleChange = useCallback((key: string) => {
|
||||||
|
const mKeys = mapKeysWithSameValueSelector.get(key) ?? [key]
|
||||||
return (value: any) => {
|
return (value: any) => {
|
||||||
const newValues = produce(values, (draft) => {
|
const newValues = produce(values, (draft) => {
|
||||||
draft[key] = value
|
for (const k of mKeys)
|
||||||
|
draft[k] = value
|
||||||
})
|
})
|
||||||
onChange(newValues)
|
onChange(newValues)
|
||||||
}
|
}
|
||||||
}, [values, onChange])
|
}, [values, onChange, mapKeysWithSameValueSelector])
|
||||||
const isArrayLikeType = [InputVarType.contexts, InputVarType.iterator].includes(inputs[0]?.type)
|
const isArrayLikeType = [InputVarType.contexts, InputVarType.iterator].includes(inputs[0]?.type)
|
||||||
const isContext = inputs[0]?.type === InputVarType.contexts
|
const isContext = inputs[0]?.type === InputVarType.contexts
|
||||||
const handleAddContext = useCallback(() => {
|
const handleAddContext = useCallback(() => {
|
||||||
|
@ -337,6 +337,7 @@ const useOneStepRun = <T>({
|
|||||||
variable: item.variable,
|
variable: item.variable,
|
||||||
type: InputVarType.textInput,
|
type: InputVarType.textInput,
|
||||||
required: true,
|
required: true,
|
||||||
|
value_selector: item.value_selector,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
@ -132,6 +132,7 @@ export type InputVar = {
|
|||||||
required: boolean
|
required: boolean
|
||||||
hint?: string
|
hint?: string
|
||||||
options?: string[]
|
options?: string[]
|
||||||
|
value_selector?: ValueSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ModelConfig = {
|
export type ModelConfig = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user