refactor: 移除多余的空行
This commit is contained in:
@@ -32,10 +32,8 @@ import {
|
||||
FormInputComponent,
|
||||
type FormItemType
|
||||
} from './Form/FormComponents';
|
||||
|
||||
const onSendPrompt = (e: { text: string; isInteractivePrompt: boolean }) =>
|
||||
eventBus.emit(EventNameEnum.sendQuestion, e);
|
||||
|
||||
const formatJsonString = (jsonString: string) => {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(jsonString), null, 2);
|
||||
@@ -43,7 +41,6 @@ const formatJsonString = (jsonString: string) => {
|
||||
return jsonString;
|
||||
}
|
||||
};
|
||||
|
||||
const StyledAccordionItem = React.memo(function StyledAccordionItem({
|
||||
children
|
||||
}: {
|
||||
@@ -55,7 +52,6 @@ const StyledAccordionItem = React.memo(function StyledAccordionItem({
|
||||
</AccordionItem>
|
||||
);
|
||||
});
|
||||
|
||||
const StyledAccordionButton = React.memo(function StyledAccordionButton({
|
||||
children,
|
||||
py = 0
|
||||
@@ -82,7 +78,6 @@ const StyledAccordionButton = React.memo(function StyledAccordionButton({
|
||||
</AccordionButton>
|
||||
);
|
||||
});
|
||||
|
||||
const RenderText = React.memo(function RenderText({
|
||||
showAnimation,
|
||||
text
|
||||
@@ -107,7 +102,6 @@ const RenderTool = React.memo(
|
||||
{tools.map((tool) => {
|
||||
const toolParams = formatJsonString(tool.params);
|
||||
const toolResponse = formatJsonString(tool.response);
|
||||
|
||||
return (
|
||||
<Accordion key={tool.id} allowToggle _notLast={{ mb: 2 }}>
|
||||
<StyledAccordionItem>
|
||||
@@ -152,7 +146,6 @@ ${toolResponse}`}
|
||||
},
|
||||
(prevProps, nextProps) => isEqual(prevProps, nextProps)
|
||||
);
|
||||
|
||||
const RenderResoningContent = React.memo(function RenderResoningContent({
|
||||
content,
|
||||
isChatting,
|
||||
@@ -164,7 +157,6 @@ const RenderResoningContent = React.memo(function RenderResoningContent({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const showAnimation = isChatting && isLastResponseValue;
|
||||
|
||||
return (
|
||||
<Accordion allowToggle defaultIndex={isLastResponseValue ? 0 : undefined}>
|
||||
<StyledAccordionItem>
|
||||
@@ -173,7 +165,6 @@ const RenderResoningContent = React.memo(function RenderResoningContent({
|
||||
<MyIcon name={'core/chat/think'} w={'0.85rem'} />
|
||||
<Box fontSize={'sm'}>{t('chat:ai_reasoning')}</Box>
|
||||
</HStack>
|
||||
|
||||
{showAnimation && <MyIcon name={'common/loading'} w={'0.85rem'} />}
|
||||
<AccordionIcon color={'myGray.600'} ml={5} />
|
||||
</StyledAccordionButton>
|
||||
@@ -192,7 +183,6 @@ const RenderResoningContent = React.memo(function RenderResoningContent({
|
||||
</Accordion>
|
||||
);
|
||||
});
|
||||
|
||||
const RenderUserSelectInteractive = React.memo(function RenderInteractive({
|
||||
interactive
|
||||
}: {
|
||||
@@ -214,7 +204,6 @@ const RenderUserSelectInteractive = React.memo(function RenderInteractive({
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
||||
interactive
|
||||
}: {
|
||||
@@ -238,7 +227,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
||||
isInteractivePrompt: true
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Flex flexDirection={'column'} gap={2} w={'250px'}>
|
||||
<FormInputComponent
|
||||
@@ -253,7 +241,6 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
||||
</Flex>
|
||||
);
|
||||
});
|
||||
|
||||
const getResponseRenderer = (
|
||||
value: UserChatItemValueItemType | AIChatItemValueItemType,
|
||||
isChatting: boolean,
|
||||
@@ -264,7 +251,6 @@ const getResponseRenderer = (
|
||||
<RenderText showAnimation={isChatting && isLastResponseValue} text={value.text.content} />
|
||||
);
|
||||
}
|
||||
|
||||
if (value.type === ChatItemValueTypeEnum.reasoning && value.reasoning) {
|
||||
return (
|
||||
<RenderResoningContent
|
||||
@@ -274,11 +260,9 @@ const getResponseRenderer = (
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (value.type === ChatItemValueTypeEnum.tool && value.tools) {
|
||||
return <RenderTool showAnimation={isChatting} tools={value.tools} />;
|
||||
}
|
||||
|
||||
if (value.type === ChatItemValueTypeEnum.interactive && value.interactive) {
|
||||
if (value.interactive.type === 'userSelect') {
|
||||
return <RenderUserSelectInteractive interactive={value.interactive} />;
|
||||
@@ -287,10 +271,8 @@ const getResponseRenderer = (
|
||||
return <RenderUserFormInteractive interactive={value.interactive} />;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const AIResponseBox = React.memo(function AIResponseBox({
|
||||
value,
|
||||
isLastResponseValue,
|
||||
@@ -302,5 +284,4 @@ const AIResponseBox = React.memo(function AIResponseBox({
|
||||
}) {
|
||||
return getResponseRenderer(value, isChatting, isLastResponseValue);
|
||||
});
|
||||
|
||||
export default AIResponseBox;
|
||||
|
||||
@@ -10,14 +10,11 @@ import MyTextarea from '@/components/common/Textarea/MyTextarea';
|
||||
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';
|
||||
|
||||
type IconNameType = 'core/workflow/debugNext' | 'common/loading' | 'core/chat/think';
|
||||
|
||||
export type SelectOptionType = {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
export type SelectOptionsComponentPropsType = {
|
||||
options: SelectOptionType[];
|
||||
description?: string;
|
||||
@@ -26,7 +23,6 @@ export type SelectOptionsComponentPropsType = {
|
||||
isDisabled?: boolean;
|
||||
variant?: string;
|
||||
};
|
||||
|
||||
const DescriptionBox = React.memo(function DescriptionBox({
|
||||
description
|
||||
}: {
|
||||
@@ -49,7 +45,6 @@ const DescriptionBox = React.memo(function DescriptionBox({
|
||||
</Box>
|
||||
);
|
||||
});
|
||||
|
||||
const inputBaseStyle = {
|
||||
bg: 'white',
|
||||
borderWidth: '1px',
|
||||
@@ -61,7 +56,6 @@ const inputBaseStyle = {
|
||||
},
|
||||
borderRadius: 'md'
|
||||
};
|
||||
|
||||
export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({
|
||||
options = [],
|
||||
description,
|
||||
@@ -116,7 +110,6 @@ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent
|
||||
</Box>
|
||||
);
|
||||
});
|
||||
|
||||
export type FormItemType = {
|
||||
label: string;
|
||||
key?: string;
|
||||
@@ -133,7 +126,6 @@ export type FormItemType = {
|
||||
value: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type FormInputComponentProps = {
|
||||
inputForm: FormItemType[];
|
||||
description?: string;
|
||||
@@ -145,8 +137,6 @@ export type FormInputComponentProps = {
|
||||
submitButtonIcon?: IconNameType;
|
||||
isCompact?: boolean;
|
||||
};
|
||||
|
||||
// 表单项标签组件
|
||||
const FormItemLabel = React.memo(function FormItemLabel({
|
||||
label,
|
||||
required,
|
||||
@@ -165,8 +155,6 @@ const FormItemLabel = React.memo(function FormItemLabel({
|
||||
</Flex>
|
||||
);
|
||||
});
|
||||
|
||||
// 渲染不同类型的表单输入项
|
||||
const renderFormInput = (
|
||||
input: FormItemType,
|
||||
register: any,
|
||||
@@ -175,7 +163,6 @@ const renderFormInput = (
|
||||
isDisabled: boolean
|
||||
) => {
|
||||
const { type, label, required, maxLength, min, max, defaultValue, list } = input;
|
||||
|
||||
switch (type) {
|
||||
case FlowNodeInputTypeEnum.input:
|
||||
return (
|
||||
@@ -189,7 +176,6 @@ const renderFormInput = (
|
||||
p={3}
|
||||
/>
|
||||
);
|
||||
|
||||
case FlowNodeInputTypeEnum.textarea:
|
||||
return (
|
||||
<Textarea
|
||||
@@ -201,7 +187,6 @@ const renderFormInput = (
|
||||
p={3}
|
||||
/>
|
||||
);
|
||||
|
||||
case FlowNodeInputTypeEnum.numberInput:
|
||||
return (
|
||||
<Box position="relative">
|
||||
@@ -232,7 +217,6 @@ const renderFormInput = (
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
case FlowNodeInputTypeEnum.select:
|
||||
return (
|
||||
<Controller
|
||||
@@ -261,12 +245,10 @@ const renderFormInput = (
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const FormInputComponent = React.memo(function FormInputComponent({
|
||||
inputForm = [],
|
||||
description,
|
||||
@@ -282,7 +264,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
|
||||
const { register, setValue, handleSubmit, control, reset, getValues } = useForm({
|
||||
defaultValues
|
||||
});
|
||||
|
||||
const handleFormSubmit = useCallback(
|
||||
(data: Record<string, any>) => {
|
||||
if (onSubmit) {
|
||||
@@ -291,7 +272,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
|
||||
},
|
||||
[onSubmit]
|
||||
);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<DescriptionBox description={description} />
|
||||
@@ -335,7 +315,6 @@ export const FormInputComponent = React.memo(function FormInputComponent({
|
||||
</Box>
|
||||
);
|
||||
});
|
||||
|
||||
export type UseFormHandlerReturnType<T extends FieldValues = Record<string, any>> = {
|
||||
register: UseFormReturn<T>['register'];
|
||||
setValue: UseFormReturn<T>['setValue'];
|
||||
@@ -345,14 +324,12 @@ export type UseFormHandlerReturnType<T extends FieldValues = Record<string, any>
|
||||
reset: UseFormReturn<T>['reset'];
|
||||
getValues: UseFormReturn<T>['getValues'];
|
||||
};
|
||||
|
||||
export const useFormHandler = <T extends FieldValues = Record<string, any>>(
|
||||
formConfig: UseFormProps<T> = {},
|
||||
onSubmitCallback?: (data: T) => void
|
||||
): UseFormHandlerReturnType<T> => {
|
||||
const methods = useForm<T>(formConfig);
|
||||
const { handleSubmit } = methods;
|
||||
|
||||
const onSubmit = useCallback(
|
||||
(data: T) => {
|
||||
if (onSubmitCallback) {
|
||||
@@ -361,7 +338,6 @@ export const useFormHandler = <T extends FieldValues = Record<string, any>>(
|
||||
},
|
||||
[onSubmitCallback]
|
||||
);
|
||||
|
||||
return {
|
||||
...methods,
|
||||
onSubmit: handleSubmit(onSubmit)
|
||||
|
||||
@@ -10,7 +10,6 @@ import { NextAPI } from '@/service/middleware/entry';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { defaultApp } from '@/web/core/app/constants';
|
||||
import { WORKFLOW_MAX_RUN_TIMES } from '@fastgpt/service/core/workflow/constants';
|
||||
|
||||
async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
@@ -23,7 +22,6 @@ async function handler(
|
||||
query = [],
|
||||
history = []
|
||||
} = req.body as PostWorkflowDebugProps;
|
||||
|
||||
if (!nodes) {
|
||||
throw new Error('Prams Error');
|
||||
}
|
||||
@@ -33,7 +31,6 @@ async function handler(
|
||||
if (!Array.isArray(edges)) {
|
||||
throw new Error('Edges is not array');
|
||||
}
|
||||
|
||||
/* user auth */
|
||||
const [{ teamId, tmbId }, { app }] = await Promise.all([
|
||||
authCert({
|
||||
@@ -42,10 +39,8 @@ async function handler(
|
||||
}),
|
||||
authApp({ req, authToken: true, appId, per: ReadPermissionVal })
|
||||
]);
|
||||
|
||||
// auth balance
|
||||
const { timezone, externalProvider } = await getUserChatInfoAndAuthTeamPoints(tmbId);
|
||||
|
||||
/* start process */
|
||||
const { flowUsages, flowResponses, debugResponse, newVariables, workflowInteractiveResponse } =
|
||||
await dispatchWorkFlow({
|
||||
@@ -55,7 +50,6 @@ async function handler(
|
||||
timezone,
|
||||
externalProvider,
|
||||
uid: tmbId,
|
||||
|
||||
runningAppInfo: {
|
||||
id: app._id,
|
||||
teamId: app.teamId,
|
||||
@@ -65,7 +59,6 @@ async function handler(
|
||||
teamId,
|
||||
tmbId
|
||||
},
|
||||
|
||||
runtimeNodes: nodes,
|
||||
runtimeEdges: edges,
|
||||
variables,
|
||||
@@ -75,7 +68,6 @@ async function handler(
|
||||
stream: false,
|
||||
maxRunTimes: WORKFLOW_MAX_RUN_TIMES
|
||||
});
|
||||
|
||||
createChatUsage({
|
||||
appName: `${app.name}-Debug`,
|
||||
appId,
|
||||
@@ -84,7 +76,6 @@ async function handler(
|
||||
source: UsageSourceEnum.fastgpt,
|
||||
flowUsages
|
||||
});
|
||||
|
||||
return {
|
||||
...debugResponse,
|
||||
newVariables,
|
||||
@@ -92,9 +83,7 @@ async function handler(
|
||||
workflowInteractiveResponse
|
||||
};
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: {
|
||||
|
||||
Reference in New Issue
Block a user