diff --git a/web/app/components/base/install-button/index.tsx b/web/app/components/base/install-button/index.tsx index 983e9b343e..848183780c 100644 --- a/web/app/components/base/install-button/index.tsx +++ b/web/app/components/base/install-button/index.tsx @@ -17,7 +17,7 @@ const InstallButton = ({ loading, onInstall, t }: InstallButtonProps) => { {loading ? t('workflow.nodes.agent.pluginInstaller.installing') : t('workflow.nodes.agent.pluginInstaller.install')} {loading - ? + ? : } diff --git a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/agent-model-trigger.tsx b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/agent-model-trigger.tsx index adffecb82a..fd510f0beb 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/agent-model-trigger.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/agent-model-trigger.tsx @@ -13,7 +13,7 @@ import { } from '../declarations' import { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from '../provider-added-card' import type { PluginInfoFromMarketPlace } from '@/app/components/plugins/types' -import { useInstallPackageFromMarketPlace } from '@/service/use-plugins' +import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import ConfigurationButton from './configuration-button' import { PluginType } from '@/app/components/plugins/types' import { @@ -22,7 +22,7 @@ import { } from '../hooks' import ModelIcon from '../model-icon' import ModelDisplay from './model-display' -import InstallButton from '@/app/components/base/install-button' +import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import StatusIndicators from './status-indicators' import cn from '@/utils/classnames' import { useProviderContext } from '@/context/provider-context' @@ -72,10 +72,8 @@ const AgentModelTrigger: FC = ({ }, [modelProviders, providerName]) const [pluginInfo, setPluginInfo] = useState(null) const [isPluginChecked, setIsPluginChecked] = useState(false) - const [loading, setLoading] = useState(false) const [installed, setInstalled] = useState(false) - const { mutateAsync: installPackageFromMarketPlace } = useInstallPackageFromMarketPlace() - + const invalidateInstalledPluginList = useInvalidateInstalledPluginList() useEffect(() => { (async () => { if (providerName && !modelProvider) { @@ -133,34 +131,6 @@ const AgentModelTrigger: FC = ({ }) } - const handleInstall = async (pluginInfo: PluginInfoFromMarketPlace) => { - setLoading(true) - try { - const { all_installed } = await installPackageFromMarketPlace(pluginInfo.latest_package_identifier) - if (all_installed) { - [ - ModelTypeEnum.textGeneration, - ModelTypeEnum.textEmbedding, - ModelTypeEnum.rerank, - ModelTypeEnum.moderation, - ModelTypeEnum.speech2text, - ModelTypeEnum.tts, - ].forEach((type: ModelTypeEnum) => { - if (scope?.includes(type)) - updateModelList(type) - }) - updateModelProviders() - setInstalled(true) - } - } - catch (error) { - console.error('Installation failed:', error) - } - finally { - setLoading(false) - } - } - return (
= ({ t={t} /> {!installed && !modelProvider && pluginInfo && ( - { - e.stopPropagation() - handleInstall(pluginInfo) + e.stopPropagation()} + size={'small'} + uniqueIdentifier={pluginInfo.latest_package_identifier} + onSuccess={() => { + [ + ModelTypeEnum.textGeneration, + ModelTypeEnum.textEmbedding, + ModelTypeEnum.rerank, + ModelTypeEnum.moderation, + ModelTypeEnum.speech2text, + ModelTypeEnum.tts, + ].forEach((type: ModelTypeEnum) => { + if (scope?.includes(type)) + updateModelList(type) + }, + ) + updateModelProviders() + invalidateInstalledPluginList() + setInstalled(true) }} - t={t} /> )} {modelProvider && !disabled && !needsConfiguration && ( diff --git a/web/app/components/workflow/nodes/_base/components/install-plugin-button.tsx b/web/app/components/workflow/nodes/_base/components/install-plugin-button.tsx index bdbcdfde5a..bf4073358f 100644 --- a/web/app/components/workflow/nodes/_base/components/install-plugin-button.tsx +++ b/web/app/components/workflow/nodes/_base/components/install-plugin-button.tsx @@ -38,6 +38,6 @@ export const InstallPluginButton = (props: InstallPluginButtonProps) => { className={classNames('flex items-center', className)} > {!isLoading ? t('workflow.nodes.agent.pluginInstaller.install') : t('workflow.nodes.agent.pluginInstaller.installing')} - {!isLoading ? : } + {!isLoading ? : } }