import { apiInterceptors, postAgentHubUpdate, postAgentInstall, postAgentQuery, postAgentUninstall, } from '@/client/api'; import BlurredCard, { ChatButton } from '@/new-components/common/blurredCard'; import { PostAgentQueryParams } from '@/types/agent'; import { ClearOutlined, DownloadOutlined, SearchOutlined, SyncOutlined } from '@ant-design/icons'; import { useRequest } from 'ahooks'; import { Button, Form, Input, Spin, Tag, message } from 'antd'; import moment from 'moment'; import { useCallback, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import MyEmpty from '../common/MyEmpty'; function MarketPlugins() { const { t } = useTranslation(); const [uploading, setUploading] = useState(false); const [isError, setIsError] = useState(false); const [actionIndex, setActionIndex] = useState(); const [form] = Form.useForm(); const pagination = useMemo<{ pageNo: number; pageSize: number }>( () => ({ pageNo: 1, pageSize: 20, }), [], ); const { data: agents = [], loading, refresh, } = useRequest(async () => { const queryParams: PostAgentQueryParams = { page_index: pagination.pageNo, page_size: pagination.pageSize, filter: form.getFieldsValue(), }; const [err, res] = await apiInterceptors(postAgentQuery(queryParams)); setIsError(!!err); return res?.datas ?? []; }); const updateFromGithub = async () => { try { setUploading(true); const [err] = await apiInterceptors(postAgentHubUpdate()); if (err) return; message.success('success'); refresh(); } finally { setUploading(false); } }; const pluginAction = useCallback( async (name: string, index: number, isInstall: boolean) => { if (actionIndex) return; setActionIndex(index); const [err] = await apiInterceptors((isInstall ? postAgentInstall : postAgentUninstall)(name)); if (!err) { message.success('success'); refresh(); } setActionIndex(undefined); }, [actionIndex, refresh], ); // const renderAction = useCallback( // (agent: IAgentPlugin, index: number) => { // if (index === actionIndex) { // return ; // } // return agent.installed ? ( // //
{ // pluginAction(agent.name, index, false); // }} // > // //
//
// ) : ( // //
{ // pluginAction(agent.name, index, true); // }} // > // //
//
// ); // }, // [actionIndex, pluginAction], // ); console.log(agents); return (
{!agents.length && !loading && }
{/*
{ window.open(agent.storage_url, '_blank'); }} >
, ]} >

{agent.name}

{agent.author && {agent.author}} {agent.version && v{agent.version}} {agent.type && Type {agent.type}} {agent.storage_channel && {agent.storage_channel}}

{agent.description}

*/} {agents.map((agent, index) => ( { window.open(agent.storage_url, '_blank'); }} description={agent.description} name={agent.name} key={agent.id} Tags={
{agent.author && {agent.author}} {agent.version && v{agent.version}} {agent.type && Type {agent.type}} {agent.storage_channel && {agent.storage_channel}}
} LeftBottom={
{agent.author} {agent?.gmt_created && {moment(agent?.gmt_created).fromNow() + ' ' + t('update')}}
} RightBottom={ agent.installed ? ( } text='Uninstall' onClick={() => { pluginAction(agent.name, index, false); }} /> ) : ( } text='Install' onClick={() => { pluginAction(agent.name, index, true); }} /> ) } /> ))}
); } export default MarketPlugins;