mirror of
https://github.com/langgenius/dify.git
synced 2026-06-18 07:41:09 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
86 lines
3.7 KiB
TypeScript
86 lines
3.7 KiB
TypeScript
import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types'
|
|
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
|
import { useInvalidateDefaultModel, useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
|
import { useProviderContext } from '@/context/provider-context'
|
|
import { useInvalidDataSourceListAuth } from '@/service/use-datasource'
|
|
import { useInvalidDataSourceList } from '@/service/use-pipeline'
|
|
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
|
|
import { useInvalidateStrategyProviders } from '@/service/use-strategy'
|
|
import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders, useInvalidateRAGRecommendedPlugins } from '@/service/use-tools'
|
|
import { useInvalidateAllTriggerPlugins } from '@/service/use-triggers'
|
|
import { PluginCategoryEnum } from '../../types'
|
|
|
|
type PluginCategoryPayload = {
|
|
category: PluginCategoryEnum | string
|
|
}
|
|
|
|
const SYSTEM_MODEL_TYPES = [
|
|
ModelTypeEnum.textGeneration,
|
|
ModelTypeEnum.textEmbedding,
|
|
ModelTypeEnum.rerank,
|
|
ModelTypeEnum.speech2text,
|
|
ModelTypeEnum.tts,
|
|
]
|
|
|
|
const useRefreshPluginList = () => {
|
|
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
|
const { mutate: refetchLLMModelList } = useModelList(ModelTypeEnum.textGeneration)
|
|
const { mutate: refetchEmbeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
|
|
const { mutate: refetchRerankModelList } = useModelList(ModelTypeEnum.rerank)
|
|
const { mutate: refetchSpeech2textModelList } = useModelList(ModelTypeEnum.speech2text)
|
|
const { mutate: refetchTTSModelList } = useModelList(ModelTypeEnum.tts)
|
|
const invalidateDefaultModel = useInvalidateDefaultModel()
|
|
const { refreshModelProviders } = useProviderContext()
|
|
|
|
const invalidateAllToolProviders = useInvalidateAllToolProviders()
|
|
const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools()
|
|
const invalidateAllDataSources = useInvalidDataSourceList()
|
|
|
|
const invalidateDataSourceListAuth = useInvalidDataSourceListAuth()
|
|
|
|
const invalidateStrategyProviders = useInvalidateStrategyProviders()
|
|
|
|
const invalidateAllTriggerPlugins = useInvalidateAllTriggerPlugins()
|
|
|
|
const invalidateRAGRecommendedPlugins = useInvalidateRAGRecommendedPlugins()
|
|
return {
|
|
refreshPluginList: (manifest?: PluginManifestInMarket | Plugin | PluginDeclaration | PluginCategoryPayload | null, refreshAllType?: boolean) => {
|
|
// installed list
|
|
invalidateInstalledPluginList()
|
|
|
|
// tool page, tool select
|
|
if ((manifest && PluginCategoryEnum.tool.includes(manifest.category)) || refreshAllType) {
|
|
invalidateAllToolProviders()
|
|
invalidateAllBuiltInTools()
|
|
invalidateRAGRecommendedPlugins('tool')
|
|
// TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins
|
|
}
|
|
|
|
if ((manifest && PluginCategoryEnum.trigger.includes(manifest.category)) || refreshAllType)
|
|
invalidateAllTriggerPlugins()
|
|
|
|
if ((manifest && PluginCategoryEnum.datasource.includes(manifest.category)) || refreshAllType) {
|
|
invalidateAllDataSources()
|
|
invalidateDataSourceListAuth()
|
|
}
|
|
|
|
// model select
|
|
if ((manifest && PluginCategoryEnum.model.includes(manifest.category)) || refreshAllType) {
|
|
refreshModelProviders()
|
|
refetchLLMModelList()
|
|
refetchEmbeddingModelList()
|
|
refetchRerankModelList()
|
|
refetchSpeech2textModelList()
|
|
refetchTTSModelList()
|
|
SYSTEM_MODEL_TYPES.forEach(type => invalidateDefaultModel(type))
|
|
}
|
|
|
|
// agent select
|
|
if ((manifest && PluginCategoryEnum.agent.includes(manifest.category)) || refreshAllType)
|
|
invalidateStrategyProviders()
|
|
},
|
|
}
|
|
}
|
|
|
|
export default useRefreshPluginList
|