From c160721cbe922f2c7d6e461c1748b2f2d756ce65 Mon Sep 17 00:00:00 2001 From: sd0ric4 <1286518974@qq.com> Date: Thu, 27 Mar 2025 12:34:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=85=E7=90=86=20AIResponseBox=20?= =?UTF-8?q?=E5=92=8C=E8=A1=A8=E5=8D=95=E7=BB=84=E4=BB=B6=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E5=92=8C=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/chat/components/AIResponseBox.tsx | 5 +---- .../core/chat/components/Form/FormComponents.tsx | 15 --------------- .../chat/components/InteractiveComponents.tsx | 9 --------- 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/projects/app/src/components/core/chat/components/AIResponseBox.tsx b/projects/app/src/components/core/chat/components/AIResponseBox.tsx index 0f3b51a7e..a2674a834 100644 --- a/projects/app/src/components/core/chat/components/AIResponseBox.tsx +++ b/projects/app/src/components/core/chat/components/AIResponseBox.tsx @@ -6,7 +6,6 @@ import { AccordionItem, AccordionPanel, Box, - Button, Flex, HStack } from '@chakra-ui/react'; @@ -16,7 +15,7 @@ import { ToolModuleResponseItemType, UserChatItemValueItemType } from '@fastgpt/global/core/chat/type'; -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useCallback, useMemo } from 'react'; import MyIcon from '@fastgpt/web/components/common/Icon'; import Avatar from '@fastgpt/web/components/common/Avatar'; import { @@ -223,7 +222,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({ }) { const { t } = useTranslation(); - // 处理默认值 const defaultValues = useMemo(() => { if (interactive.type === 'userInput') { return interactive.params.inputForm?.reduce((acc: Record, item) => { @@ -234,7 +232,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({ return {}; }, [interactive]); - // 提交表单时的处理 const handleFormSubmit = useCallback((data: Record) => { onSendPrompt({ text: JSON.stringify(data), diff --git a/projects/app/src/components/core/chat/components/Form/FormComponents.tsx b/projects/app/src/components/core/chat/components/Form/FormComponents.tsx index a897ac1e5..a85fd10ce 100644 --- a/projects/app/src/components/core/chat/components/Form/FormComponents.tsx +++ b/projects/app/src/components/core/chat/components/Form/FormComponents.tsx @@ -11,16 +11,13 @@ import MyNumberInput from '@fastgpt/web/components/common/Input/NumberInput'; import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import MyIcon from '@fastgpt/web/components/common/Icon'; -// 定义IconName类型 - 这应该与MyIcon组件要求的类型匹配 type IconName = 'core/workflow/debugNext' | 'common/loading' | 'core/chat/think'; -// 定义选项接口 export interface SelectOption { key: string; value: string; } -// 定义SelectOptionsComponent接口 export interface SelectOptionsComponentProps { options: SelectOption[]; description?: string; @@ -30,9 +27,6 @@ export interface SelectOptionsComponentProps { variant?: string; } -/** - * 共享的选项按钮组件 - */ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({ options = [], description, @@ -101,7 +95,6 @@ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent ); }); -// 定义表单项接口 export interface FormItem { label: string; key?: string; @@ -119,7 +112,6 @@ export interface FormItem { }>; } -// 定义FormInputComponent接口 export interface FormInputComponentProps { inputForm: FormItem[]; description?: string; @@ -132,9 +124,6 @@ export interface FormInputComponentProps { isCompact?: boolean; } -/** - * 共享的表单呈现组件 - */ export const FormInputComponent = React.memo(function FormInputComponent({ inputForm = [], description, @@ -319,7 +308,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({ ); }); -// 定义FormHandler接口 export interface UseFormHandlerReturn> { register: UseFormReturn['register']; setValue: UseFormReturn['setValue']; @@ -330,9 +318,6 @@ export interface UseFormHandlerReturn['getValues']; } -/** - * 创建共享的表单Hook - */ export const useFormHandler = >( formConfig: UseFormProps = {}, onSubmitCallback?: (data: T) => void diff --git a/projects/app/src/components/core/chat/components/InteractiveComponents.tsx b/projects/app/src/components/core/chat/components/InteractiveComponents.tsx index 529883351..5e6dcd161 100644 --- a/projects/app/src/components/core/chat/components/InteractiveComponents.tsx +++ b/projects/app/src/components/core/chat/components/InteractiveComponents.tsx @@ -17,7 +17,6 @@ import { SelectOptionsComponent } from './Form/FormComponents'; -// 创建共用的交互式调试 Hook const useInteractiveDebug = ( interactive: UserSelectInteractive | UserInputInteractive, nodeId?: string @@ -27,7 +26,6 @@ const useInteractiveDebug = ( workflowDebugData: v.workflowDebugData })); - // 处理交互数据结构 const interactiveData = useMemo(() => { return { ...interactive, @@ -37,7 +35,6 @@ const useInteractiveDebug = ( }; }, [interactive]); - // 创建模拟的历史记录 const createMockHistory = useCallback((): ChatItemType[] => { return [ { @@ -52,12 +49,9 @@ const useInteractiveDebug = ( ]; }, [interactiveData]); - // 启动调试的通用函数 const startDebug = useCallback( (userContent: string, nodeUpdater: (node: any) => any) => { if (!nodeId || !workflowDebugData) return; - - // 创建包含用户交互的查询数据 const updatedQuery: UserChatItemValueItemType[] = [ ...(workflowDebugData.query || []), { @@ -139,7 +133,6 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({ const [isSubmitted, setIsSubmitted] = useState(false); const { startDebug } = useInteractiveDebug(interactive, nodeId); - // 处理默认值 const defaultValues = useMemo(() => { return interactive.params.inputForm?.reduce((acc: Record, item) => { acc[item.label] = !!item.value ? item.value : item.defaultValue; @@ -147,7 +140,6 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({ }, {}); }, [interactive.params.inputForm]); - // 提交表单时的处理 const handleFormSubmit = useCallback( (formData: Record) => { if (!nodeId) return; @@ -170,7 +162,6 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({ [nodeId, startDebug, interactive.params.inputForm] ); - // 设置已提交状态 useEffect(() => { if (interactive.params.submitted) { setIsSubmitted(true);