Merge branch 'dbgpts_hub_dev' of https://github.com/eosphoros-ai/DB-GPT into dbgpts_hub_dev

This commit is contained in:
yhjun1026
2024-08-26 13:57:58 +08:00
4 changed files with 36 additions and 23 deletions

View File

@@ -350,9 +350,9 @@ export const postAgentInstall = (pluginName: string, user?: string) => {
timeout: 60000, timeout: 60000,
}); });
}; };
export const postDbgptsInstall = (pluginName: string, user?: string) => { export const postDbgptsInstall = (data: object, user?: string) => {
return POST("/api/v1/serve/dbgpts/hub/install", undefined, { return POST("/api/v1/serve/dbgpts/hub/install", data, {
params: { plugin_name: pluginName, user }, params: { user },
timeout: 60000, timeout: 60000,
}); });
}; };
@@ -364,7 +364,7 @@ export const postAgentUninstall = (pluginName: string, user?: string) => {
}; };
export const postDbgptsUninstall = (pluginName: string, user?: string) => { export const postDbgptsUninstall = (pluginName: string, user?: string) => {
return POST("/api/v1/serve/dbgpts/my/uninstall", undefined, { return POST("/api/v1/serve/dbgpts/my/uninstall", undefined, {
params: { plugin_name: pluginName, user }, params: { name: pluginName, user },
timeout: 60000, timeout: 60000,
}); });
}; };

View File

@@ -62,18 +62,18 @@ function ConstructLayout({ children }: { children: React.ReactNode }) {
// path: '/agent', // path: '/agent',
// icon: <BuildOutlined />, // icon: <BuildOutlined />,
// }, // },
{
key: 'dbgpts',
name: t('dbgpts_community'),
path: '/dbgpts',
icon: <BuildOutlined />,
},
{ {
key: 'prompt', key: 'prompt',
name: t('Prompt'), name: t('Prompt'),
icon: <MessageOutlined />, icon: <MessageOutlined />,
path: '/prompt', path: '/prompt',
}, },
{
key: 'dbgpts',
name: t('dbgpts_community'),
path: '/dbgpts',
icon: <BuildOutlined />,
},
]; ];
const router = useRouter(); const router = useRouter();
const activeKey = router.pathname.split('/')[2]; const activeKey = router.pathname.split('/')[2];

View File

@@ -297,7 +297,7 @@ export default function AppContent() {
</Button> </Button>
</div> </div>
</div> </div>
<div className=" w-full flex flex-wrap pb-12 mx-[-8px]"> <div className="w-full flex flex-wrap pb-12 mx-[-8px]">
{apps.map((item) => { {apps.map((item) => {
return ( return (
<BlurredCard <BlurredCard

View File

@@ -17,6 +17,7 @@ function Agent() {
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const [activeKey, setActiveKey] = useState<string>('market'); const [activeKey, setActiveKey] = useState<string>('market');
const [uploading, setUploading] = useState(false); const [uploading, setUploading] = useState(false);
const [loading, setLoading] = useState(false);
const [isError, setIsError] = useState(false); const [isError, setIsError] = useState(false);
const [actionIndex, setActionIndex] = useState<number | undefined>(); const [actionIndex, setActionIndex] = useState<number | undefined>();
@@ -33,10 +34,10 @@ function Agent() {
const { const {
data: agents = [], data: agents = [],
loading,
refresh, refresh,
} = useRequest<IAgentPlugin[], []>( } = useRequest<IAgentPlugin[], []>(
async () => { async () => {
setLoading(true);
if (activeKey === 'my') { if (activeKey === 'my') {
const [err, res] = await apiInterceptors(postDbgptsMy({ const [err, res] = await apiInterceptors(postDbgptsMy({
name: searchValue || undefined, name: searchValue || undefined,
@@ -44,6 +45,7 @@ function Agent() {
page_index: pagination.pageNo, page_index: pagination.pageNo,
page_size: pagination.pageSize, page_size: pagination.pageSize,
})); }));
setLoading(false);
setIsError(!!err); setIsError(!!err);
return res?.items ?? []; return res?.items ?? [];
} }
@@ -54,6 +56,7 @@ function Agent() {
type: typeStr === 'all' ? undefined : typeStr, type: typeStr === 'all' ? undefined : typeStr,
}; };
const [err, res] = await apiInterceptors(postDbgptsQuery(queryParams)); const [err, res] = await apiInterceptors(postDbgptsQuery(queryParams));
setLoading(false);
setIsError(!!err); setIsError(!!err);
return res?.items ?? []; return res?.items ?? [];
}, },
@@ -76,12 +79,22 @@ function Agent() {
useEffect(() => { useEffect(() => {
refresh(); refresh();
}, [activeKey, typeStr]); }, [activeKey, typeStr]);
const pluginAction = useCallback( const pluginAction = useCallback(
async (name: string, index: number, isInstall: boolean) => { async (agent: { name: string }, index: number, isInstall: boolean) => {
if (actionIndex) return; if (actionIndex) return;
setActionIndex(index); setActionIndex(index);
const [err] = await apiInterceptors((isInstall ? postDbgptsInstall : postDbgptsUninstall)(name)); setLoading(true);
if (!err) { let errs = null;
if (isInstall) {
const [err] = await apiInterceptors(postDbgptsInstall(agent));
errs = err;
} else {
const [err] = await apiInterceptors(postDbgptsUninstall(agent.name));
errs = err;
}
setLoading(false);
if (!errs) {
message.success('success'); message.success('success');
refresh(); refresh();
} }
@@ -145,8 +158,8 @@ function Agent() {
return ( return (
<ConstructLayout> <ConstructLayout>
<div className="px-6">
<Spin spinning={loading}> <Spin spinning={loading}>
<div className="h-screen w-full p-4 md:p-6 overflow-y-auto">
<div className="flex justify-between items-center mb-6"> <div className="flex justify-between items-center mb-6">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<Segmented <Segmented
@@ -181,7 +194,7 @@ function Agent() {
</Button> </Button>
</div> </div>
</div> </div>
<div className='flex justify-start'> <div className='w-full flex flex-wrap pb-12 mx-[-8px]'>
<Segmented <Segmented
className="backdrop-filter backdrop-blur-lg bg-white bg-opacity-30 border-2 border-white rounded-lg shadow p-1 dark:border-[#6f7f95] dark:bg-[#6f7f95] dark:bg-opacity-60" className="backdrop-filter backdrop-blur-lg bg-white bg-opacity-30 border-2 border-white rounded-lg shadow p-1 dark:border-[#6f7f95] dark:bg-[#6f7f95] dark:bg-opacity-60"
options={typeItems} options={typeItems}
@@ -201,7 +214,7 @@ function Agent() {
className="w-[230px] h-[40px] border-1 border-white ml-4 backdrop-filter backdrop-blur-lg bg-white bg-opacity-30 dark:border-[#6f7f95] dark:bg-[#6f7f95] dark:bg-opacity-60" className="w-[230px] h-[40px] border-1 border-white ml-4 backdrop-filter backdrop-blur-lg bg-white bg-opacity-30 dark:border-[#6f7f95] dark:bg-[#6f7f95] dark:bg-opacity-60"
/> />
</div> </div>
<div className='flex flex-wrap'> <div className='flex flex-wrap pb-12'>
{agents.map((agent, index) => ( {agents.map((agent, index) => (
<BlurredCard <BlurredCard
logo={logoFn(agent.type)} logo={logoFn(agent.type)}
@@ -236,7 +249,7 @@ function Agent() {
Icon={<ClearOutlined />} Icon={<ClearOutlined />}
text="Uninstall" text="Uninstall"
onClick={() => { onClick={() => {
pluginAction(agent.name, index, false); pluginAction(agent, index, false);
}} }}
/> />
) : ( ) : (
@@ -244,7 +257,7 @@ function Agent() {
Icon={<DownloadOutlined />} Icon={<DownloadOutlined />}
text="Install" text="Install"
onClick={() => { onClick={() => {
pluginAction(agent.name, index, true); pluginAction(agent, index, true);
}} }}
/> />
) )
@@ -253,8 +266,8 @@ function Agent() {
))} ))}
</div> </div>
{/* {activeKey !== 'market' ? <MyPlugins /> : <MarketPlugins />} */} {/* {activeKey !== 'market' ? <MyPlugins /> : <MarketPlugins />} */}
</Spin>
</div> </div>
</Spin>
</ConstructLayout> </ConstructLayout>
); );
} }