From 5817c07db6f959624583d57257dd9ee271df58a6 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 7 Jan 2025 16:33:58 +0800 Subject: [PATCH] feat: local install refresh --- .../hooks/use-refresh-plugin-list.tsx | 12 ++++++----- .../install-bundle/steps/install.tsx | 6 +++--- .../ready-to-install.tsx | 21 ++++++------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx b/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx index 6bcb8f0321..acb486c703 100644 --- a/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx +++ b/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx @@ -3,7 +3,7 @@ import { useProviderContext } from '@/context/provider-context' import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools' import { useInvalidateStrategyProviders } from '@/service/use-strategy' -import type { Plugin, PluginManifestInMarket } from '../../types' +import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types' import { PluginType } from '../../types' const useRefreshPluginList = () => { @@ -16,25 +16,27 @@ const useRefreshPluginList = () => { const invalidateStrategyProviders = useInvalidateStrategyProviders() return { - refreshPluginList: (manifest: PluginManifestInMarket | Plugin) => { + refreshPluginList: (manifest?: PluginManifestInMarket | Plugin | PluginDeclaration | null, refreshAllType?: boolean) => { // installed list invalidateInstalledPluginList() + if (!manifest) return + // tool page, tool select - if (PluginType.tool.includes(manifest.category)) { + if (PluginType.tool.includes(manifest.category) || refreshAllType) { invalidateAllToolProviders() invalidateAllBuiltInTools() // TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins } // model select - if (PluginType.model.includes(manifest.category)) { + if (PluginType.model.includes(manifest.category) || refreshAllType) { updateModelProviders() refreshModelProviders() } // agent select - if (PluginType.agent.includes(manifest.category)) + if (PluginType.agent.includes(manifest.category) || refreshAllType) invalidateStrategyProviders() }, } diff --git a/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx b/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx index 7f33c5cef3..a1a17f2df1 100644 --- a/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx +++ b/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx @@ -7,7 +7,7 @@ import { RiLoader2Line } from '@remixicon/react' import { useTranslation } from 'react-i18next' import InstallMulti from './install-multi' import { useInstallOrUpdate } from '@/service/use-plugins' -import { useInvalidateInstalledPluginList } from '@/service/use-plugins' +import useRefreshPluginList from '../../hooks/use-refresh-plugin-list' const i18nPrefix = 'plugin.installModal' type Props = { @@ -29,7 +29,7 @@ const Install: FC = ({ const [selectedPlugins, setSelectedPlugins] = React.useState([]) const [selectedIndexes, setSelectedIndexes] = React.useState([]) const selectedPluginsNum = selectedPlugins.length - const invalidateInstalledPluginList = useInvalidateInstalledPluginList() + const { refreshPluginList } = useRefreshPluginList() const handleSelect = (plugin: Plugin, selectedIndex: number) => { const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id) let nextSelectedPlugins @@ -61,7 +61,7 @@ const Install: FC = ({ })) const hasInstallSuccess = res.some(r => r.success) if (hasInstallSuccess) - invalidateInstalledPluginList() + refreshPluginList(undefined, true) }, }) const handleInstall = () => { diff --git a/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx b/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx index f41ecd3469..78907f4494 100644 --- a/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx +++ b/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx @@ -2,12 +2,11 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import type { PluginDeclaration } from '../../types' -import { InstallStep, PluginType } from '../../types' +import { InstallStep } from '../../types' import Install from './steps/install' import Installed from '../base/installed' -import { useInvalidateInstalledPluginList } from '@/service/use-plugins' -import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks' -import { useInvalidateAllToolProviders } from '@/service/use-tools' +import useRefreshPluginList from '../hooks/use-refresh-plugin-list' + type Props = { step: InstallStep onStepChange: (step: InstallStep) => void, @@ -27,20 +26,12 @@ const ReadyToInstall: FC = ({ errorMsg, onError, }) => { - const invalidateInstalledPluginList = useInvalidateInstalledPluginList() - const updateModelProviders = useUpdateModelProviders() - const invalidateAllToolProviders = useInvalidateAllToolProviders() + const { refreshPluginList } = useRefreshPluginList() const handleInstalled = useCallback(() => { onStepChange(InstallStep.installed) - invalidateInstalledPluginList() - if (!manifest) - return - if (PluginType.model.includes(manifest.category)) - updateModelProviders() - if (PluginType.tool.includes(manifest.category)) - invalidateAllToolProviders() - }, [invalidateAllToolProviders, invalidateInstalledPluginList, manifest, onStepChange, updateModelProviders]) + refreshPluginList(manifest) + }, [manifest, onStepChange, refreshPluginList]) const handleFailed = useCallback((errorMsg?: string) => { onStepChange(InstallStep.installFailed)