feat: local install refresh

pull/12560/head
Joel 1 year ago
parent 2f5da1f6aa
commit 5817c07db6

@ -3,7 +3,7 @@ import { useProviderContext } from '@/context/provider-context'
import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools' import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools'
import { useInvalidateStrategyProviders } from '@/service/use-strategy' import { useInvalidateStrategyProviders } from '@/service/use-strategy'
import type { Plugin, PluginManifestInMarket } from '../../types' import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types'
import { PluginType } from '../../types' import { PluginType } from '../../types'
const useRefreshPluginList = () => { const useRefreshPluginList = () => {
@ -16,25 +16,27 @@ const useRefreshPluginList = () => {
const invalidateStrategyProviders = useInvalidateStrategyProviders() const invalidateStrategyProviders = useInvalidateStrategyProviders()
return { return {
refreshPluginList: (manifest: PluginManifestInMarket | Plugin) => { refreshPluginList: (manifest?: PluginManifestInMarket | Plugin | PluginDeclaration | null, refreshAllType?: boolean) => {
// installed list // installed list
invalidateInstalledPluginList() invalidateInstalledPluginList()
if (!manifest) return
// tool page, tool select // tool page, tool select
if (PluginType.tool.includes(manifest.category)) { if (PluginType.tool.includes(manifest.category) || refreshAllType) {
invalidateAllToolProviders() invalidateAllToolProviders()
invalidateAllBuiltInTools() invalidateAllBuiltInTools()
// TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins // TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins
} }
// model select // model select
if (PluginType.model.includes(manifest.category)) { if (PluginType.model.includes(manifest.category) || refreshAllType) {
updateModelProviders() updateModelProviders()
refreshModelProviders() refreshModelProviders()
} }
// agent select // agent select
if (PluginType.agent.includes(manifest.category)) if (PluginType.agent.includes(manifest.category) || refreshAllType)
invalidateStrategyProviders() invalidateStrategyProviders()
}, },
} }

@ -7,7 +7,7 @@ import { RiLoader2Line } from '@remixicon/react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import InstallMulti from './install-multi' import InstallMulti from './install-multi'
import { useInstallOrUpdate } from '@/service/use-plugins' import { useInstallOrUpdate } from '@/service/use-plugins'
import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import useRefreshPluginList from '../../hooks/use-refresh-plugin-list'
const i18nPrefix = 'plugin.installModal' const i18nPrefix = 'plugin.installModal'
type Props = { type Props = {
@ -29,7 +29,7 @@ const Install: FC<Props> = ({
const [selectedPlugins, setSelectedPlugins] = React.useState<Plugin[]>([]) const [selectedPlugins, setSelectedPlugins] = React.useState<Plugin[]>([])
const [selectedIndexes, setSelectedIndexes] = React.useState<number[]>([]) const [selectedIndexes, setSelectedIndexes] = React.useState<number[]>([])
const selectedPluginsNum = selectedPlugins.length const selectedPluginsNum = selectedPlugins.length
const invalidateInstalledPluginList = useInvalidateInstalledPluginList() const { refreshPluginList } = useRefreshPluginList()
const handleSelect = (plugin: Plugin, selectedIndex: number) => { const handleSelect = (plugin: Plugin, selectedIndex: number) => {
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id) const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
let nextSelectedPlugins let nextSelectedPlugins
@ -61,7 +61,7 @@ const Install: FC<Props> = ({
})) }))
const hasInstallSuccess = res.some(r => r.success) const hasInstallSuccess = res.some(r => r.success)
if (hasInstallSuccess) if (hasInstallSuccess)
invalidateInstalledPluginList() refreshPluginList(undefined, true)
}, },
}) })
const handleInstall = () => { const handleInstall = () => {

@ -2,12 +2,11 @@
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import type { PluginDeclaration } from '../../types' import type { PluginDeclaration } from '../../types'
import { InstallStep, PluginType } from '../../types' import { InstallStep } from '../../types'
import Install from './steps/install' import Install from './steps/install'
import Installed from '../base/installed' import Installed from '../base/installed'
import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import useRefreshPluginList from '../hooks/use-refresh-plugin-list'
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useInvalidateAllToolProviders } from '@/service/use-tools'
type Props = { type Props = {
step: InstallStep step: InstallStep
onStepChange: (step: InstallStep) => void, onStepChange: (step: InstallStep) => void,
@ -27,20 +26,12 @@ const ReadyToInstall: FC<Props> = ({
errorMsg, errorMsg,
onError, onError,
}) => { }) => {
const invalidateInstalledPluginList = useInvalidateInstalledPluginList() const { refreshPluginList } = useRefreshPluginList()
const updateModelProviders = useUpdateModelProviders()
const invalidateAllToolProviders = useInvalidateAllToolProviders()
const handleInstalled = useCallback(() => { const handleInstalled = useCallback(() => {
onStepChange(InstallStep.installed) onStepChange(InstallStep.installed)
invalidateInstalledPluginList() refreshPluginList(manifest)
if (!manifest) }, [manifest, onStepChange, refreshPluginList])
return
if (PluginType.model.includes(manifest.category))
updateModelProviders()
if (PluginType.tool.includes(manifest.category))
invalidateAllToolProviders()
}, [invalidateAllToolProviders, invalidateInstalledPluginList, manifest, onStepChange, updateModelProviders])
const handleFailed = useCallback((errorMsg?: string) => { const handleFailed = useCallback((errorMsg?: string) => {
onStepChange(InstallStep.installFailed) onStepChange(InstallStep.installFailed)

Loading…
Cancel
Save