diff --git a/projects/app/src/components/core/app/formRender/LabelAndForm.tsx b/projects/app/src/components/core/app/formRender/LabelAndForm.tsx index ea0c35e32..5b466b64d 100644 --- a/projects/app/src/components/core/app/formRender/LabelAndForm.tsx +++ b/projects/app/src/components/core/app/formRender/LabelAndForm.tsx @@ -2,7 +2,7 @@ import type { BoxProps } from '@chakra-ui/react'; import { Box, Flex } from '@chakra-ui/react'; import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip'; -import React, { useMemo } from 'react'; +import React from 'react'; import type { UseFormReturn } from 'react-hook-form'; import { Controller } from 'react-hook-form'; import InputRender from '.'; @@ -46,14 +46,13 @@ const LabelAndFormRender = ({ const { control } = variablesForm; return ( - + {label} {placeholder && } { if (inputType === VariableInputEnum.textarea) return InputTypeEnum.textarea; if (inputType === VariableInputEnum.numberInput) return InputTypeEnum.numberInput; if (inputType === VariableInputEnum.select) return InputTypeEnum.select; - return InputTypeEnum.textarea; + return InputTypeEnum.JSONEditor; }; // 节点输入类型(通常是一个 reference+一个 form input) diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInputForm.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInputForm.tsx index dae633225..01c816b59 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInputForm.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInputForm.tsx @@ -37,16 +37,21 @@ const VariableInput = ({ [allVariableList, showExternalVariables] ); - const { getValues, setValue } = variablesForm; + const { getValues, setValue, reset } = variablesForm; + // Init variables and add default values useEffect(() => { + const values = getValues(); + allVariableList.forEach((item) => { const val = getValues(`variables.${item.key}`); if (item.defaultValue !== undefined && (val === undefined || val === null || val === '')) { - setValue(`variables.${item.key}`, item.defaultValue); + values.variables[item.key] = item.defaultValue; } }); - }, [allVariableList, getValues, setValue, variableList]); + + reset(values); + }, [allVariableList, getValues, reset, setValue, variableList]); return ( @@ -90,6 +95,7 @@ const VariableInput = ({ leftIcon={} size={'sm'} maxW={'100px'} + mt={4} onClick={variablesForm.handleSubmit(() => { chatForm.setValue('chatStarted', true); })} @@ -123,18 +129,17 @@ const VariableInput = ({ /> ))} {!chatStarted && ( - - - + )} diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx index 6384a4901..6d5a35e6f 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx @@ -29,16 +29,18 @@ const VariablePopover = ({ const hasExternalVariable = externalVariableList.length > 0; const hasVariable = variableList.length > 0; - const { getValues, setValue } = variablesForm; + const { getValues, reset } = variablesForm; useEffect(() => { + const values = getValues(); variables.forEach((item) => { const val = getValues(`variables.${item.key}`); if (item.defaultValue !== undefined && (val === undefined || val === null || val === '')) { - setValue(`variables.${item.key}`, item.defaultValue); + values.variables[item.key] = item.defaultValue; } }); - }, [variables]); + reset(values); + }, [getValues, reset, variables]); return ( {({ onClose }) => ( - + {hasExternalVariable && ( } {hasVariable && ( - + {variableList.map((item) => ( )} - - - )}