feat: 清理 AIResponseBox 和表单组件代码,移除冗余注释和未使用的导入

This commit is contained in:
sd0ric4
2025-03-27 12:34:20 +08:00
parent c8a9c8157e
commit c160721cbe
3 changed files with 1 additions and 28 deletions

View File

@@ -6,7 +6,6 @@ import {
AccordionItem, AccordionItem,
AccordionPanel, AccordionPanel,
Box, Box,
Button,
Flex, Flex,
HStack HStack
} from '@chakra-ui/react'; } from '@chakra-ui/react';
@@ -16,7 +15,7 @@ import {
ToolModuleResponseItemType, ToolModuleResponseItemType,
UserChatItemValueItemType UserChatItemValueItemType
} from '@fastgpt/global/core/chat/type'; } 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 MyIcon from '@fastgpt/web/components/common/Icon';
import Avatar from '@fastgpt/web/components/common/Avatar'; import Avatar from '@fastgpt/web/components/common/Avatar';
import { import {
@@ -223,7 +222,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
// 处理默认值
const defaultValues = useMemo(() => { const defaultValues = useMemo(() => {
if (interactive.type === 'userInput') { if (interactive.type === 'userInput') {
return interactive.params.inputForm?.reduce((acc: Record<string, any>, item) => { return interactive.params.inputForm?.reduce((acc: Record<string, any>, item) => {
@@ -234,7 +232,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
return {}; return {};
}, [interactive]); }, [interactive]);
// 提交表单时的处理
const handleFormSubmit = useCallback((data: Record<string, any>) => { const handleFormSubmit = useCallback((data: Record<string, any>) => {
onSendPrompt({ onSendPrompt({
text: JSON.stringify(data), text: JSON.stringify(data),

View File

@@ -11,16 +11,13 @@ import MyNumberInput from '@fastgpt/web/components/common/Input/NumberInput';
import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import MyIcon from '@fastgpt/web/components/common/Icon'; import MyIcon from '@fastgpt/web/components/common/Icon';
// 定义IconName类型 - 这应该与MyIcon组件要求的类型匹配
type IconName = 'core/workflow/debugNext' | 'common/loading' | 'core/chat/think'; type IconName = 'core/workflow/debugNext' | 'common/loading' | 'core/chat/think';
// 定义选项接口
export interface SelectOption { export interface SelectOption {
key: string; key: string;
value: string; value: string;
} }
// 定义SelectOptionsComponent接口
export interface SelectOptionsComponentProps { export interface SelectOptionsComponentProps {
options: SelectOption[]; options: SelectOption[];
description?: string; description?: string;
@@ -30,9 +27,6 @@ export interface SelectOptionsComponentProps {
variant?: string; variant?: string;
} }
/**
* 共享的选项按钮组件
*/
export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({
options = [], options = [],
description, description,
@@ -101,7 +95,6 @@ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent
); );
}); });
// 定义表单项接口
export interface FormItem { export interface FormItem {
label: string; label: string;
key?: string; key?: string;
@@ -119,7 +112,6 @@ export interface FormItem {
}>; }>;
} }
// 定义FormInputComponent接口
export interface FormInputComponentProps { export interface FormInputComponentProps {
inputForm: FormItem[]; inputForm: FormItem[];
description?: string; description?: string;
@@ -132,9 +124,6 @@ export interface FormInputComponentProps {
isCompact?: boolean; isCompact?: boolean;
} }
/**
* 共享的表单呈现组件
*/
export const FormInputComponent = React.memo(function FormInputComponent({ export const FormInputComponent = React.memo(function FormInputComponent({
inputForm = [], inputForm = [],
description, description,
@@ -319,7 +308,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
); );
}); });
// 定义FormHandler接口
export interface UseFormHandlerReturn<T extends FieldValues = Record<string, any>> { export interface UseFormHandlerReturn<T extends FieldValues = Record<string, any>> {
register: UseFormReturn<T>['register']; register: UseFormReturn<T>['register'];
setValue: UseFormReturn<T>['setValue']; setValue: UseFormReturn<T>['setValue'];
@@ -330,9 +318,6 @@ export interface UseFormHandlerReturn<T extends FieldValues = Record<string, any
getValues: UseFormReturn<T>['getValues']; getValues: UseFormReturn<T>['getValues'];
} }
/**
* 创建共享的表单Hook
*/
export const useFormHandler = <T extends FieldValues = Record<string, any>>( export const useFormHandler = <T extends FieldValues = Record<string, any>>(
formConfig: UseFormProps<T> = {}, formConfig: UseFormProps<T> = {},
onSubmitCallback?: (data: T) => void onSubmitCallback?: (data: T) => void

View File

@@ -17,7 +17,6 @@ import {
SelectOptionsComponent SelectOptionsComponent
} from './Form/FormComponents'; } from './Form/FormComponents';
// 创建共用的交互式调试 Hook
const useInteractiveDebug = ( const useInteractiveDebug = (
interactive: UserSelectInteractive | UserInputInteractive, interactive: UserSelectInteractive | UserInputInteractive,
nodeId?: string nodeId?: string
@@ -27,7 +26,6 @@ const useInteractiveDebug = (
workflowDebugData: v.workflowDebugData workflowDebugData: v.workflowDebugData
})); }));
// 处理交互数据结构
const interactiveData = useMemo(() => { const interactiveData = useMemo(() => {
return { return {
...interactive, ...interactive,
@@ -37,7 +35,6 @@ const useInteractiveDebug = (
}; };
}, [interactive]); }, [interactive]);
// 创建模拟的历史记录
const createMockHistory = useCallback((): ChatItemType[] => { const createMockHistory = useCallback((): ChatItemType[] => {
return [ return [
{ {
@@ -52,12 +49,9 @@ const useInteractiveDebug = (
]; ];
}, [interactiveData]); }, [interactiveData]);
// 启动调试的通用函数
const startDebug = useCallback( const startDebug = useCallback(
(userContent: string, nodeUpdater: (node: any) => any) => { (userContent: string, nodeUpdater: (node: any) => any) => {
if (!nodeId || !workflowDebugData) return; if (!nodeId || !workflowDebugData) return;
// 创建包含用户交互的查询数据
const updatedQuery: UserChatItemValueItemType[] = [ const updatedQuery: UserChatItemValueItemType[] = [
...(workflowDebugData.query || []), ...(workflowDebugData.query || []),
{ {
@@ -139,7 +133,6 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({
const [isSubmitted, setIsSubmitted] = useState(false); const [isSubmitted, setIsSubmitted] = useState(false);
const { startDebug } = useInteractiveDebug(interactive, nodeId); const { startDebug } = useInteractiveDebug(interactive, nodeId);
// 处理默认值
const defaultValues = useMemo(() => { const defaultValues = useMemo(() => {
return interactive.params.inputForm?.reduce((acc: Record<string, any>, item) => { return interactive.params.inputForm?.reduce((acc: Record<string, any>, item) => {
acc[item.label] = !!item.value ? item.value : item.defaultValue; acc[item.label] = !!item.value ? item.value : item.defaultValue;
@@ -147,7 +140,6 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({
}, {}); }, {});
}, [interactive.params.inputForm]); }, [interactive.params.inputForm]);
// 提交表单时的处理
const handleFormSubmit = useCallback( const handleFormSubmit = useCallback(
(formData: Record<string, any>) => { (formData: Record<string, any>) => {
if (!nodeId) return; if (!nodeId) return;
@@ -170,7 +162,6 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({
[nodeId, startDebug, interactive.params.inputForm] [nodeId, startDebug, interactive.params.inputForm]
); );
// 设置已提交状态
useEffect(() => { useEffect(() => {
if (interactive.params.submitted) { if (interactive.params.submitted) {
setIsSubmitted(true); setIsSubmitted(true);