You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-refresh-plugin-list.tsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. import { useInvalidDataSourceList } from '@/service/use-pipeline'
  10. const useRefreshPluginList = () => {
  11. const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
  12. const { mutate: refetchLLMModelList } = useModelList(ModelTypeEnum.textGeneration)
  13. const { mutate: refetchEmbeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
  14. const { mutate: refetchRerankModelList } = useModelList(ModelTypeEnum.rerank)
  15. const { refreshModelProviders } = useProviderContext()
  16. const invalidateAllToolProviders = useInvalidateAllToolProviders()
  17. const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools()
  18. const invalidateAllDataSources = useInvalidDataSourceList()
  19. const invalidateStrategyProviders = useInvalidateStrategyProviders()
  20. return {
  21. refreshPluginList: (manifest?: PluginManifestInMarket | Plugin | PluginDeclaration | null, refreshAllType?: boolean) => {
  22. // installed list
  23. invalidateInstalledPluginList()
  24. // tool page, tool select
  25. if ((manifest && PluginType.tool.includes(manifest.category)) || refreshAllType) {
  26. invalidateAllToolProviders()
  27. invalidateAllBuiltInTools()
  28. // TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins
  29. }
  30. if ((manifest && PluginType.datasource.includes(manifest.category)) || refreshAllType)
  31. invalidateAllDataSources()
  32. // model select
  33. if ((manifest && PluginType.model.includes(manifest.category)) || refreshAllType) {
  34. refreshModelProviders()
  35. refetchLLMModelList()
  36. refetchEmbeddingModelList()
  37. refetchRerankModelList()
  38. }
  39. // agent select
  40. if ((manifest && PluginType.agent.includes(manifest.category)) || refreshAllType)
  41. invalidateStrategyProviders()
  42. },
  43. }
  44. }
  45. export default useRefreshPluginList