mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 21:23:22 +08:00
feat: use all refresh plugin tools to hooks
This commit is contained in:
parent
1419430015
commit
0e98794d49
@ -0,0 +1,43 @@
|
|||||||
|
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
|
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 { PluginType } from '../../types'
|
||||||
|
|
||||||
|
const useRefreshPluginList = () => {
|
||||||
|
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
||||||
|
const updateModelProviders = useUpdateModelProviders()
|
||||||
|
const { refreshModelProviders } = useProviderContext()
|
||||||
|
|
||||||
|
const invalidateAllToolProviders = useInvalidateAllToolProviders()
|
||||||
|
const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools()
|
||||||
|
|
||||||
|
const invalidateStrategyProviders = useInvalidateStrategyProviders()
|
||||||
|
return {
|
||||||
|
refreshPluginList: (manifest: PluginManifestInMarket | Plugin) => {
|
||||||
|
// installed list
|
||||||
|
invalidateInstalledPluginList()
|
||||||
|
|
||||||
|
// tool page, tool select
|
||||||
|
if (PluginType.tool.includes(manifest.category)) {
|
||||||
|
invalidateAllToolProviders()
|
||||||
|
invalidateAllBuiltInTools()
|
||||||
|
// TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins
|
||||||
|
}
|
||||||
|
|
||||||
|
// model select
|
||||||
|
if (PluginType.model.includes(manifest.category)) {
|
||||||
|
updateModelProviders()
|
||||||
|
refreshModelProviders()
|
||||||
|
}
|
||||||
|
|
||||||
|
// agent select
|
||||||
|
if (PluginType.agent.includes(manifest.category))
|
||||||
|
invalidateStrategyProviders()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useRefreshPluginList
|
||||||
@ -3,13 +3,11 @@
|
|||||||
import React, { useCallback, useState } from 'react'
|
import React, { useCallback, useState } from 'react'
|
||||||
import Modal from '@/app/components/base/modal'
|
import Modal from '@/app/components/base/modal'
|
||||||
import type { Dependency, Plugin, PluginManifestInMarket } from '../../types'
|
import type { Dependency, Plugin, PluginManifestInMarket } 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 { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
import useRefreshPluginList from '../hooks/use-refresh-plugin-list'
|
||||||
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
|
|
||||||
import { useInvalidateAllToolProviders } from '@/service/use-tools'
|
|
||||||
import ReadyToInstallBundle from '../install-bundle/ready-to-install'
|
import ReadyToInstallBundle from '../install-bundle/ready-to-install'
|
||||||
|
|
||||||
const i18nPrefix = 'plugin.installModal'
|
const i18nPrefix = 'plugin.installModal'
|
||||||
@ -35,9 +33,7 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
|
|||||||
// readyToInstall -> check installed -> installed/failed
|
// readyToInstall -> check installed -> installed/failed
|
||||||
const [step, setStep] = useState<InstallStep>(InstallStep.readyToInstall)
|
const [step, setStep] = useState<InstallStep>(InstallStep.readyToInstall)
|
||||||
const [errorMsg, setErrorMsg] = useState<string | null>(null)
|
const [errorMsg, setErrorMsg] = useState<string | null>(null)
|
||||||
const updateModelProviders = useUpdateModelProviders()
|
const { refreshPluginList } = useRefreshPluginList()
|
||||||
const invalidateAllToolProviders = useInvalidateAllToolProviders()
|
|
||||||
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
|
||||||
|
|
||||||
const getTitle = useCallback(() => {
|
const getTitle = useCallback(() => {
|
||||||
if (isBundle && step === InstallStep.installed)
|
if (isBundle && step === InstallStep.installed)
|
||||||
@ -51,12 +47,8 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
|
|||||||
|
|
||||||
const handleInstalled = useCallback(() => {
|
const handleInstalled = useCallback(() => {
|
||||||
setStep(InstallStep.installed)
|
setStep(InstallStep.installed)
|
||||||
invalidateInstalledPluginList()
|
refreshPluginList(manifest)
|
||||||
if (PluginType.model.includes(manifest.category))
|
}, [manifest, refreshPluginList])
|
||||||
updateModelProviders()
|
|
||||||
if (PluginType.tool.includes(manifest.category))
|
|
||||||
invalidateAllToolProviders()
|
|
||||||
}, [invalidateAllToolProviders, invalidateInstalledPluginList, manifest, updateModelProviders])
|
|
||||||
|
|
||||||
const handleFailed = useCallback((errorMsg?: string) => {
|
const handleFailed = useCallback((errorMsg?: string) => {
|
||||||
setStep(InstallStep.installFailed)
|
setStep(InstallStep.installFailed)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user