use-refresh-plugin-list.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
  2. import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
  3. import { useProviderContext } from '@/context/provider-context'
  4. import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
  5. import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools'
  6. import { useInvalidateStrategyProviders } from '@/service/use-strategy'
  7. import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types'
  8. import { PluginType } from '../../types'
  9. const useRefreshPluginList = () => {
  10. const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
  11. const { mutate: refetchLLMModelList } = useModelList(ModelTypeEnum.textGeneration)
  12. const { mutate: refetchEmbeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
  13. const { mutate: refetchRerankModelList } = useModelList(ModelTypeEnum.rerank)
  14. const { refreshModelProviders } = useProviderContext()
  15. const invalidateAllToolProviders = useInvalidateAllToolProviders()
  16. const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools()
  17. const invalidateStrategyProviders = useInvalidateStrategyProviders()
  18. return {
  19. refreshPluginList: (manifest?: PluginManifestInMarket | Plugin | PluginDeclaration | null, refreshAllType?: boolean) => {
  20. // installed list
  21. invalidateInstalledPluginList()
  22. if (!manifest) return
  23. // tool page, tool select
  24. if (PluginType.tool.includes(manifest.category) || refreshAllType) {
  25. invalidateAllToolProviders()
  26. invalidateAllBuiltInTools()
  27. // TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins
  28. }
  29. // model select
  30. if (PluginType.model.includes(manifest.category) || refreshAllType) {
  31. refreshModelProviders()
  32. refetchLLMModelList()
  33. refetchEmbeddingModelList()
  34. refetchRerankModelList()
  35. }
  36. // agent select
  37. if (PluginType.agent.includes(manifest.category) || refreshAllType)
  38. invalidateStrategyProviders()
  39. },
  40. }
  41. }
  42. export default useRefreshPluginList