mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
perf: mcp tool type (#4820)
This commit is contained in:
@@ -553,7 +553,7 @@ const ChatBox = ({
|
||||
const responseData = mergeChatResponseData(item.responseData || []);
|
||||
if (responseData[responseData.length - 1]?.error) {
|
||||
toast({
|
||||
title: t(responseData[responseData.length - 1].error?.message),
|
||||
title: t(getErrText(responseData[responseData.length - 1].error)),
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext';
|
||||
import { type AppFileSelectConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { defaultAppSelectFileConfig } from '@fastgpt/global/core/app/constants';
|
||||
import { mergeChatResponseData } from '@fastgpt/global/core/chat/utils';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
|
||||
type PluginRunContextType = PluginRunBoxProps & {
|
||||
isChatting: boolean;
|
||||
@@ -258,7 +259,7 @@ const PluginRunContextProvider = ({
|
||||
const responseData = mergeChatResponseData(item.responseData || []);
|
||||
if (responseData[responseData.length - 1]?.error) {
|
||||
toast({
|
||||
title: t(responseData[responseData.length - 1].error?.message),
|
||||
title: t(getErrText(responseData[responseData.length - 1].error)),
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import ChatRecordContextProvider from '@/web/core/chat/context/chatRecordContext
|
||||
import { Box, Button, Flex, Switch, Textarea } from '@chakra-ui/react';
|
||||
import { cardStyles } from '../constants';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel';
|
||||
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
@@ -19,7 +19,7 @@ import { postRunMCPTool } from '@/web/core/app/api/plugin';
|
||||
|
||||
const JsonEditor = dynamic(() => import('@fastgpt/web/components/common/Textarea/JsonEditor'));
|
||||
|
||||
const ChatTest = ({ currentTool, url }: { currentTool: ToolType | null; url: string }) => {
|
||||
const ChatTest = ({ currentTool, url }: { currentTool: McpToolConfigType | null; url: string }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [output, setOutput] = useState<string>('');
|
||||
@@ -135,7 +135,7 @@ const ChatTest = ({ currentTool, url }: { currentTool: ToolType | null; url: str
|
||||
);
|
||||
};
|
||||
|
||||
const Render = ({ currentTool, url }: { currentTool: ToolType | null; url: string }) => {
|
||||
const Render = ({ currentTool, url }: { currentTool: McpToolConfigType | null; url: string }) => {
|
||||
const { chatId } = useChatStore();
|
||||
const { appDetail } = useContextSelector(AppContext, (v) => v);
|
||||
|
||||
@@ -178,7 +178,7 @@ const RenderToolInput = ({
|
||||
type: string;
|
||||
description?: string;
|
||||
};
|
||||
toolData: ToolType | null;
|
||||
toolData: McpToolConfigType | null;
|
||||
value: any;
|
||||
onChange: (value: any) => void;
|
||||
isInvalid: boolean;
|
||||
|
@@ -7,7 +7,7 @@ import AppCard from './AppCard';
|
||||
import ChatTest from './ChatTest';
|
||||
import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
import EditForm from './EditForm';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
|
||||
const Edit = ({
|
||||
url,
|
||||
@@ -19,10 +19,10 @@ const Edit = ({
|
||||
}: {
|
||||
url: string;
|
||||
setUrl: (url: string) => void;
|
||||
toolList: ToolType[];
|
||||
setToolList: (toolList: ToolType[]) => void;
|
||||
currentTool: ToolType | null;
|
||||
setCurrentTool: (tool: ToolType) => void;
|
||||
toolList: McpToolConfigType[];
|
||||
setToolList: (toolList: McpToolConfigType[]) => void;
|
||||
currentTool: McpToolConfigType | null;
|
||||
setCurrentTool: (tool: McpToolConfigType) => void;
|
||||
}) => {
|
||||
const { isPc } = useSystem();
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import { AppContext } from '../context';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import MyIconButton from '@fastgpt/web/components/common/Icon/button';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import MyModal from '@fastgpt/web/components/common/MyModal';
|
||||
import Avatar from '@fastgpt/web/components/common/Avatar';
|
||||
import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
@@ -24,14 +24,14 @@ const EditForm = ({
|
||||
}: {
|
||||
url: string;
|
||||
setUrl: (url: string) => void;
|
||||
toolList: ToolType[];
|
||||
setToolList: (toolList: ToolType[]) => void;
|
||||
currentTool: ToolType | null;
|
||||
setCurrentTool: (tool: ToolType) => void;
|
||||
toolList: McpToolConfigType[];
|
||||
setToolList: (toolList: McpToolConfigType[]) => void;
|
||||
currentTool: McpToolConfigType | null;
|
||||
setCurrentTool: (tool: McpToolConfigType) => void;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [toolDetail, setToolDetail] = useState<ToolType | null>(null);
|
||||
const [toolDetail, setToolDetail] = useState<McpToolConfigType | null>(null);
|
||||
|
||||
const { runAsync: runGetMCPTools, loading: isGettingTools } = useRequest2(
|
||||
async (data: getMCPToolsBody) => await getMCPTools(data),
|
||||
@@ -180,7 +180,7 @@ const EditForm = ({
|
||||
|
||||
export default React.memo(EditForm);
|
||||
|
||||
const ToolDetailModal = ({ tool, onClose }: { tool: ToolType; onClose: () => void }) => {
|
||||
const ToolDetailModal = ({ tool, onClose }: { tool: McpToolConfigType; onClose: () => void }) => {
|
||||
const { t } = useTranslation();
|
||||
const appDetail = useContextSelector(AppContext, (v) => v.appDetail);
|
||||
|
||||
|
@@ -8,10 +8,10 @@ import { getAppFolderPath } from '@/web/core/app/api/app';
|
||||
import { useCallback } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { postUpdateMCPTools } from '@/web/core/app/api/plugin';
|
||||
|
||||
const Header = ({ url, toolList }: { url: string; toolList: ToolType[] }) => {
|
||||
const Header = ({ url, toolList }: { url: string; toolList: McpToolConfigType[] }) => {
|
||||
const { t } = useTranslation();
|
||||
const appId = useContextSelector(AppContext, (v) => v.appId);
|
||||
const router = useRouter();
|
||||
|
@@ -5,7 +5,7 @@ import Edit from './Edit';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { AppContext } from '../context';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { type MCPToolSetData } from '@/pageComponents/dashboard/apps/MCPToolsEditModal';
|
||||
|
||||
const MCPTools = () => {
|
||||
@@ -18,8 +18,10 @@ const MCPTools = () => {
|
||||
}, [appDetail.modules]);
|
||||
|
||||
const [url, setUrl] = useState(toolSetData?.url || '');
|
||||
const [toolList, setToolList] = useState<ToolType[]>(toolSetData?.toolList || []);
|
||||
const [currentTool, setCurrentTool] = useState<ToolType | null>(toolSetData?.toolList[0] || null);
|
||||
const [toolList, setToolList] = useState<McpToolConfigType[]>(toolSetData?.toolList || []);
|
||||
const [currentTool, setCurrentTool] = useState<McpToolConfigType | null>(
|
||||
toolSetData?.toolList[0] || null
|
||||
);
|
||||
|
||||
return (
|
||||
<Flex h={'100%'} flexDirection={'column'} px={[3, 0]} pr={[3, 3]}>
|
||||
|
@@ -5,14 +5,15 @@ import NodeCard from './render/NodeCard';
|
||||
import IOTitle from '../components/IOTitle';
|
||||
import Container from '../components/Container';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { Box, Flex } from '@chakra-ui/react';
|
||||
|
||||
const NodeToolSet = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { inputs } = data;
|
||||
const toolList: ToolType[] = inputs.find((item) => item.key === 'toolSetData')?.value?.toolList;
|
||||
const toolList: McpToolConfigType[] = inputs.find((item) => item.key === 'toolSetData')?.value
|
||||
?.toolList;
|
||||
|
||||
return (
|
||||
<NodeCard minW={'350px'} selected={selected} {...data}>
|
||||
|
@@ -20,17 +20,16 @@ import Avatar from '@fastgpt/web/components/common/Avatar';
|
||||
import MyModal from '@fastgpt/web/components/common/MyModal';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import { useToast } from '@fastgpt/web/hooks/useToast';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AppListContext } from './context';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import type { getMCPToolsBody } from '@/pages/api/support/mcp/client/getTools';
|
||||
|
||||
export type MCPToolSetData = {
|
||||
url: string;
|
||||
toolList: ToolType[];
|
||||
toolList: McpToolConfigType[];
|
||||
};
|
||||
|
||||
export type EditMCPToolsProps = {
|
||||
@@ -41,7 +40,6 @@ export type EditMCPToolsProps = {
|
||||
|
||||
const MCPToolsEditModal = ({ onClose }: { onClose: () => void }) => {
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
|
||||
const { parentId, loadMyApps } = useContextSelector(AppListContext, (v) => v);
|
||||
|
||||
@@ -81,7 +79,7 @@ const MCPToolsEditModal = ({ onClose }: { onClose: () => void }) => {
|
||||
const { runAsync: runGetMCPTools, loading: isGettingTools } = useRequest2(
|
||||
(data: getMCPToolsBody) => getMCPTools(data),
|
||||
{
|
||||
onSuccess: (res: ToolType[]) => {
|
||||
onSuccess: (res: McpToolConfigType[]) => {
|
||||
setValue('mcpData.toolList', res);
|
||||
},
|
||||
errorToast: t('app:MCP_tools_parse_failed')
|
||||
|
@@ -4,7 +4,7 @@ import { TeamAppCreatePermissionVal } from '@fastgpt/global/support/permission/u
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { authUserPer } from '@fastgpt/service/support/permission/user/auth';
|
||||
import { type CreateAppBody, onCreateApp } from '../create';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
import {
|
||||
@@ -22,7 +22,7 @@ export type createMCPToolsBody = Omit<
|
||||
'type' | 'modules' | 'edges' | 'chatConfig'
|
||||
> & {
|
||||
url: string;
|
||||
toolList: ToolType[];
|
||||
toolList: McpToolConfigType[];
|
||||
};
|
||||
|
||||
export type createMCPToolsResponse = {};
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { type AppDetailType, type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type AppDetailType, type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||
@@ -24,7 +24,7 @@ export type updateMCPToolsQuery = {};
|
||||
export type updateMCPToolsBody = {
|
||||
appId: string;
|
||||
url: string;
|
||||
toolList: ToolType[];
|
||||
toolList: McpToolConfigType[];
|
||||
};
|
||||
|
||||
export type updateMCPToolsResponse = {};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { MCPClient } from '@fastgpt/service/core/app/mcp';
|
||||
|
||||
@@ -7,7 +7,7 @@ export type getMCPToolsQuery = {};
|
||||
|
||||
export type getMCPToolsBody = { url: string };
|
||||
|
||||
export type getMCPToolsResponse = ToolType[];
|
||||
export type getMCPToolsResponse = McpToolConfigType[];
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<getMCPToolsBody, getMCPToolsQuery>,
|
||||
|
@@ -262,7 +262,7 @@ const MyApps = ({ MenuIcon }: { MenuIcon: JSX.Element }) => {
|
||||
|
||||
{/* Folder slider */}
|
||||
{!!folderDetail && isPc && (
|
||||
<Box pt={[4, 6]} pr={[4, 6]}>
|
||||
<Box pt={[4, 6]} pr={[4, 6]} h={'100%'} pb={4} overflow={'auto'}>
|
||||
<FolderSlideCard
|
||||
refetchResource={() => Promise.all([refetchFolderDetail(), loadMyApps()])}
|
||||
resumeInheritPermission={() => resumeInheritPer(folderDetail._id)}
|
||||
|
@@ -223,7 +223,7 @@ const Dataset = () => {
|
||||
</Flex>
|
||||
|
||||
{!!folderDetail && isPc && (
|
||||
<Box ml="6">
|
||||
<Box ml="6" h={'100%'} pb={4} overflow={'auto'}>
|
||||
<FolderSlideCard
|
||||
resumeInheritPermission={() => resumeInheritPer(folderDetail._id)}
|
||||
isInheritPermission={folderDetail.inheritPermission}
|
||||
|
@@ -20,7 +20,7 @@ import type { PluginGroupSchemaType } from '@fastgpt/service/core/app/plugin/typ
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { defaultGroup } from '@fastgpt/web/core/workflow/constants';
|
||||
import type { createMCPToolsBody } from '@/pages/api/core/app/mcpTools/create';
|
||||
import { type ToolType } from '@fastgpt/global/core/app/type';
|
||||
import { type McpToolConfigType } from '@fastgpt/global/core/app/type';
|
||||
import type { updateMCPToolsBody } from '@/pages/api/core/app/mcpTools/update';
|
||||
import type { RunMCPToolBody } from '@/pages/api/support/mcp/client/runTool';
|
||||
import type { getMCPToolsBody } from '@/pages/api/support/mcp/client/getTools';
|
||||
@@ -79,7 +79,7 @@ export const postUpdateMCPTools = (data: updateMCPToolsBody) =>
|
||||
POST('/core/app/mcpTools/update', data);
|
||||
|
||||
export const getMCPTools = (data: getMCPToolsBody) =>
|
||||
POST<ToolType[]>('/support/mcp/client/getTools', data);
|
||||
POST<McpToolConfigType[]>('/support/mcp/client/getTools', data);
|
||||
|
||||
export const postRunMCPTool = (data: RunMCPToolBody) => POST('/support/mcp/client/runTool', data);
|
||||
|
||||
|
Reference in New Issue
Block a user