refactor: 移除多余的空行

This commit is contained in:
sd0ric4
2025-03-27 14:49:08 +08:00
parent 787152468c
commit 0675b2a11e
3 changed files with 0 additions and 54 deletions

View File

@@ -32,10 +32,8 @@ import {
FormInputComponent, FormInputComponent,
type FormItemType type FormItemType
} from './Form/FormComponents'; } from './Form/FormComponents';
const onSendPrompt = (e: { text: string; isInteractivePrompt: boolean }) => const onSendPrompt = (e: { text: string; isInteractivePrompt: boolean }) =>
eventBus.emit(EventNameEnum.sendQuestion, e); eventBus.emit(EventNameEnum.sendQuestion, e);
const formatJsonString = (jsonString: string) => { const formatJsonString = (jsonString: string) => {
try { try {
return JSON.stringify(JSON.parse(jsonString), null, 2); return JSON.stringify(JSON.parse(jsonString), null, 2);
@@ -43,7 +41,6 @@ const formatJsonString = (jsonString: string) => {
return jsonString; return jsonString;
} }
}; };
const StyledAccordionItem = React.memo(function StyledAccordionItem({ const StyledAccordionItem = React.memo(function StyledAccordionItem({
children children
}: { }: {
@@ -55,7 +52,6 @@ const StyledAccordionItem = React.memo(function StyledAccordionItem({
</AccordionItem> </AccordionItem>
); );
}); });
const StyledAccordionButton = React.memo(function StyledAccordionButton({ const StyledAccordionButton = React.memo(function StyledAccordionButton({
children, children,
py = 0 py = 0
@@ -82,7 +78,6 @@ const StyledAccordionButton = React.memo(function StyledAccordionButton({
</AccordionButton> </AccordionButton>
); );
}); });
const RenderText = React.memo(function RenderText({ const RenderText = React.memo(function RenderText({
showAnimation, showAnimation,
text text
@@ -107,7 +102,6 @@ const RenderTool = React.memo(
{tools.map((tool) => { {tools.map((tool) => {
const toolParams = formatJsonString(tool.params); const toolParams = formatJsonString(tool.params);
const toolResponse = formatJsonString(tool.response); const toolResponse = formatJsonString(tool.response);
return ( return (
<Accordion key={tool.id} allowToggle _notLast={{ mb: 2 }}> <Accordion key={tool.id} allowToggle _notLast={{ mb: 2 }}>
<StyledAccordionItem> <StyledAccordionItem>
@@ -152,7 +146,6 @@ ${toolResponse}`}
}, },
(prevProps, nextProps) => isEqual(prevProps, nextProps) (prevProps, nextProps) => isEqual(prevProps, nextProps)
); );
const RenderResoningContent = React.memo(function RenderResoningContent({ const RenderResoningContent = React.memo(function RenderResoningContent({
content, content,
isChatting, isChatting,
@@ -164,7 +157,6 @@ const RenderResoningContent = React.memo(function RenderResoningContent({
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const showAnimation = isChatting && isLastResponseValue; const showAnimation = isChatting && isLastResponseValue;
return ( return (
<Accordion allowToggle defaultIndex={isLastResponseValue ? 0 : undefined}> <Accordion allowToggle defaultIndex={isLastResponseValue ? 0 : undefined}>
<StyledAccordionItem> <StyledAccordionItem>
@@ -173,7 +165,6 @@ const RenderResoningContent = React.memo(function RenderResoningContent({
<MyIcon name={'core/chat/think'} w={'0.85rem'} /> <MyIcon name={'core/chat/think'} w={'0.85rem'} />
<Box fontSize={'sm'}>{t('chat:ai_reasoning')}</Box> <Box fontSize={'sm'}>{t('chat:ai_reasoning')}</Box>
</HStack> </HStack>
{showAnimation && <MyIcon name={'common/loading'} w={'0.85rem'} />} {showAnimation && <MyIcon name={'common/loading'} w={'0.85rem'} />}
<AccordionIcon color={'myGray.600'} ml={5} /> <AccordionIcon color={'myGray.600'} ml={5} />
</StyledAccordionButton> </StyledAccordionButton>
@@ -192,7 +183,6 @@ const RenderResoningContent = React.memo(function RenderResoningContent({
</Accordion> </Accordion>
); );
}); });
const RenderUserSelectInteractive = React.memo(function RenderInteractive({ const RenderUserSelectInteractive = React.memo(function RenderInteractive({
interactive interactive
}: { }: {
@@ -214,7 +204,6 @@ const RenderUserSelectInteractive = React.memo(function RenderInteractive({
/> />
); );
}); });
const RenderUserFormInteractive = React.memo(function RenderFormInput({ const RenderUserFormInteractive = React.memo(function RenderFormInput({
interactive interactive
}: { }: {
@@ -238,7 +227,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
isInteractivePrompt: true isInteractivePrompt: true
}); });
}, []); }, []);
return ( return (
<Flex flexDirection={'column'} gap={2} w={'250px'}> <Flex flexDirection={'column'} gap={2} w={'250px'}>
<FormInputComponent <FormInputComponent
@@ -253,7 +241,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
</Flex> </Flex>
); );
}); });
const getResponseRenderer = ( const getResponseRenderer = (
value: UserChatItemValueItemType | AIChatItemValueItemType, value: UserChatItemValueItemType | AIChatItemValueItemType,
isChatting: boolean, isChatting: boolean,
@@ -264,7 +251,6 @@ const getResponseRenderer = (
<RenderText showAnimation={isChatting && isLastResponseValue} text={value.text.content} /> <RenderText showAnimation={isChatting && isLastResponseValue} text={value.text.content} />
); );
} }
if (value.type === ChatItemValueTypeEnum.reasoning && value.reasoning) { if (value.type === ChatItemValueTypeEnum.reasoning && value.reasoning) {
return ( return (
<RenderResoningContent <RenderResoningContent
@@ -274,11 +260,9 @@ const getResponseRenderer = (
/> />
); );
} }
if (value.type === ChatItemValueTypeEnum.tool && value.tools) { if (value.type === ChatItemValueTypeEnum.tool && value.tools) {
return <RenderTool showAnimation={isChatting} tools={value.tools} />; return <RenderTool showAnimation={isChatting} tools={value.tools} />;
} }
if (value.type === ChatItemValueTypeEnum.interactive && value.interactive) { if (value.type === ChatItemValueTypeEnum.interactive && value.interactive) {
if (value.interactive.type === 'userSelect') { if (value.interactive.type === 'userSelect') {
return <RenderUserSelectInteractive interactive={value.interactive} />; return <RenderUserSelectInteractive interactive={value.interactive} />;
@@ -287,10 +271,8 @@ const getResponseRenderer = (
return <RenderUserFormInteractive interactive={value.interactive} />; return <RenderUserFormInteractive interactive={value.interactive} />;
} }
} }
return null; return null;
}; };
const AIResponseBox = React.memo(function AIResponseBox({ const AIResponseBox = React.memo(function AIResponseBox({
value, value,
isLastResponseValue, isLastResponseValue,
@@ -302,5 +284,4 @@ const AIResponseBox = React.memo(function AIResponseBox({
}) { }) {
return getResponseRenderer(value, isChatting, isLastResponseValue); return getResponseRenderer(value, isChatting, isLastResponseValue);
}); });
export default AIResponseBox; export default AIResponseBox;

View File

@@ -10,14 +10,11 @@ import MyTextarea from '@/components/common/Textarea/MyTextarea';
import MyNumberInput from '@fastgpt/web/components/common/Input/NumberInput'; 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';
type IconNameType = 'core/workflow/debugNext' | 'common/loading' | 'core/chat/think'; type IconNameType = 'core/workflow/debugNext' | 'common/loading' | 'core/chat/think';
export type SelectOptionType = { export type SelectOptionType = {
key: string; key: string;
value: string; value: string;
}; };
export type SelectOptionsComponentPropsType = { export type SelectOptionsComponentPropsType = {
options: SelectOptionType[]; options: SelectOptionType[];
description?: string; description?: string;
@@ -26,7 +23,6 @@ export type SelectOptionsComponentPropsType = {
isDisabled?: boolean; isDisabled?: boolean;
variant?: string; variant?: string;
}; };
const DescriptionBox = React.memo(function DescriptionBox({ const DescriptionBox = React.memo(function DescriptionBox({
description description
}: { }: {
@@ -49,7 +45,6 @@ const DescriptionBox = React.memo(function DescriptionBox({
</Box> </Box>
); );
}); });
const inputBaseStyle = { const inputBaseStyle = {
bg: 'white', bg: 'white',
borderWidth: '1px', borderWidth: '1px',
@@ -61,7 +56,6 @@ const inputBaseStyle = {
}, },
borderRadius: 'md' borderRadius: 'md'
}; };
export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({
options = [], options = [],
description, description,
@@ -116,7 +110,6 @@ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent
</Box> </Box>
); );
}); });
export type FormItemType = { export type FormItemType = {
label: string; label: string;
key?: string; key?: string;
@@ -133,7 +126,6 @@ export type FormItemType = {
value: string; value: string;
}>; }>;
}; };
export type FormInputComponentProps = { export type FormInputComponentProps = {
inputForm: FormItemType[]; inputForm: FormItemType[];
description?: string; description?: string;
@@ -145,8 +137,6 @@ export type FormInputComponentProps = {
submitButtonIcon?: IconNameType; submitButtonIcon?: IconNameType;
isCompact?: boolean; isCompact?: boolean;
}; };
// 表单项标签组件
const FormItemLabel = React.memo(function FormItemLabel({ const FormItemLabel = React.memo(function FormItemLabel({
label, label,
required, required,
@@ -165,8 +155,6 @@ const FormItemLabel = React.memo(function FormItemLabel({
</Flex> </Flex>
); );
}); });
// 渲染不同类型的表单输入项
const renderFormInput = ( const renderFormInput = (
input: FormItemType, input: FormItemType,
register: any, register: any,
@@ -175,7 +163,6 @@ const renderFormInput = (
isDisabled: boolean isDisabled: boolean
) => { ) => {
const { type, label, required, maxLength, min, max, defaultValue, list } = input; const { type, label, required, maxLength, min, max, defaultValue, list } = input;
switch (type) { switch (type) {
case FlowNodeInputTypeEnum.input: case FlowNodeInputTypeEnum.input:
return ( return (
@@ -189,7 +176,6 @@ const renderFormInput = (
p={3} p={3}
/> />
); );
case FlowNodeInputTypeEnum.textarea: case FlowNodeInputTypeEnum.textarea:
return ( return (
<Textarea <Textarea
@@ -201,7 +187,6 @@ const renderFormInput = (
p={3} p={3}
/> />
); );
case FlowNodeInputTypeEnum.numberInput: case FlowNodeInputTypeEnum.numberInput:
return ( return (
<Box position="relative"> <Box position="relative">
@@ -232,7 +217,6 @@ const renderFormInput = (
/> />
</Box> </Box>
); );
case FlowNodeInputTypeEnum.select: case FlowNodeInputTypeEnum.select:
return ( return (
<Controller <Controller
@@ -261,12 +245,10 @@ const renderFormInput = (
}} }}
/> />
); );
default: default:
return null; return null;
} }
}; };
export const FormInputComponent = React.memo(function FormInputComponent({ export const FormInputComponent = React.memo(function FormInputComponent({
inputForm = [], inputForm = [],
description, description,
@@ -282,7 +264,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
const { register, setValue, handleSubmit, control, reset, getValues } = useForm({ const { register, setValue, handleSubmit, control, reset, getValues } = useForm({
defaultValues defaultValues
}); });
const handleFormSubmit = useCallback( const handleFormSubmit = useCallback(
(data: Record<string, any>) => { (data: Record<string, any>) => {
if (onSubmit) { if (onSubmit) {
@@ -291,7 +272,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
}, },
[onSubmit] [onSubmit]
); );
return ( return (
<Box> <Box>
<DescriptionBox description={description} /> <DescriptionBox description={description} />
@@ -335,7 +315,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
</Box> </Box>
); );
}); });
export type UseFormHandlerReturnType<T extends FieldValues = Record<string, any>> = { export type UseFormHandlerReturnType<T extends FieldValues = Record<string, any>> = {
register: UseFormReturn<T>['register']; register: UseFormReturn<T>['register'];
setValue: UseFormReturn<T>['setValue']; setValue: UseFormReturn<T>['setValue'];
@@ -345,14 +324,12 @@ export type UseFormHandlerReturnType<T extends FieldValues = Record<string, any>
reset: UseFormReturn<T>['reset']; reset: UseFormReturn<T>['reset'];
getValues: UseFormReturn<T>['getValues']; getValues: UseFormReturn<T>['getValues'];
}; };
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
): UseFormHandlerReturnType<T> => { ): UseFormHandlerReturnType<T> => {
const methods = useForm<T>(formConfig); const methods = useForm<T>(formConfig);
const { handleSubmit } = methods; const { handleSubmit } = methods;
const onSubmit = useCallback( const onSubmit = useCallback(
(data: T) => { (data: T) => {
if (onSubmitCallback) { if (onSubmitCallback) {
@@ -361,7 +338,6 @@ export const useFormHandler = <T extends FieldValues = Record<string, any>>(
}, },
[onSubmitCallback] [onSubmitCallback]
); );
return { return {
...methods, ...methods,
onSubmit: handleSubmit(onSubmit) onSubmit: handleSubmit(onSubmit)

View File

@@ -10,7 +10,6 @@ import { NextAPI } from '@/service/middleware/entry';
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant'; import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import { defaultApp } from '@/web/core/app/constants'; import { defaultApp } from '@/web/core/app/constants';
import { WORKFLOW_MAX_RUN_TIMES } from '@fastgpt/service/core/workflow/constants'; import { WORKFLOW_MAX_RUN_TIMES } from '@fastgpt/service/core/workflow/constants';
async function handler( async function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse res: NextApiResponse
@@ -23,7 +22,6 @@ async function handler(
query = [], query = [],
history = [] history = []
} = req.body as PostWorkflowDebugProps; } = req.body as PostWorkflowDebugProps;
if (!nodes) { if (!nodes) {
throw new Error('Prams Error'); throw new Error('Prams Error');
} }
@@ -33,7 +31,6 @@ async function handler(
if (!Array.isArray(edges)) { if (!Array.isArray(edges)) {
throw new Error('Edges is not array'); throw new Error('Edges is not array');
} }
/* user auth */ /* user auth */
const [{ teamId, tmbId }, { app }] = await Promise.all([ const [{ teamId, tmbId }, { app }] = await Promise.all([
authCert({ authCert({
@@ -42,10 +39,8 @@ async function handler(
}), }),
authApp({ req, authToken: true, appId, per: ReadPermissionVal }) authApp({ req, authToken: true, appId, per: ReadPermissionVal })
]); ]);
// auth balance // auth balance
const { timezone, externalProvider } = await getUserChatInfoAndAuthTeamPoints(tmbId); const { timezone, externalProvider } = await getUserChatInfoAndAuthTeamPoints(tmbId);
/* start process */ /* start process */
const { flowUsages, flowResponses, debugResponse, newVariables, workflowInteractiveResponse } = const { flowUsages, flowResponses, debugResponse, newVariables, workflowInteractiveResponse } =
await dispatchWorkFlow({ await dispatchWorkFlow({
@@ -55,7 +50,6 @@ async function handler(
timezone, timezone,
externalProvider, externalProvider,
uid: tmbId, uid: tmbId,
runningAppInfo: { runningAppInfo: {
id: app._id, id: app._id,
teamId: app.teamId, teamId: app.teamId,
@@ -65,7 +59,6 @@ async function handler(
teamId, teamId,
tmbId tmbId
}, },
runtimeNodes: nodes, runtimeNodes: nodes,
runtimeEdges: edges, runtimeEdges: edges,
variables, variables,
@@ -75,7 +68,6 @@ async function handler(
stream: false, stream: false,
maxRunTimes: WORKFLOW_MAX_RUN_TIMES maxRunTimes: WORKFLOW_MAX_RUN_TIMES
}); });
createChatUsage({ createChatUsage({
appName: `${app.name}-Debug`, appName: `${app.name}-Debug`,
appId, appId,
@@ -84,7 +76,6 @@ async function handler(
source: UsageSourceEnum.fastgpt, source: UsageSourceEnum.fastgpt,
flowUsages flowUsages
}); });
return { return {
...debugResponse, ...debugResponse,
newVariables, newVariables,
@@ -92,9 +83,7 @@ async function handler(
workflowInteractiveResponse workflowInteractiveResponse
}; };
} }
export default NextAPI(handler); export default NextAPI(handler);
export const config = { export const config = {
api: { api: {
bodyParser: { bodyParser: {