Skip to content

Commit 83d0142

Browse files
authored
fix: refresh after install plugin (#13593)
1 parent 56c7f49 commit 83d0142

File tree

14 files changed

+49
-36
lines changed

14 files changed

+49
-36
lines changed

web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
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'
23
import { useProviderContext } from '@/context/provider-context'
34
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
45
import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools'
@@ -8,7 +9,9 @@ import { PluginType } from '../../types'
89

910
const useRefreshPluginList = () => {
1011
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
11-
const updateModelProviders = useUpdateModelProviders()
12+
const { mutate: refetchLLMModelList } = useModelList(ModelTypeEnum.textGeneration)
13+
const { mutate: refetchEmbeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
14+
const { mutate: refetchRerankModelList } = useModelList(ModelTypeEnum.rerank)
1215
const { refreshModelProviders } = useProviderContext()
1316

1417
const invalidateAllToolProviders = useInvalidateAllToolProviders()
@@ -31,8 +34,10 @@ const useRefreshPluginList = () => {
3134

3235
// model select
3336
if (PluginType.model.includes(manifest.category) || refreshAllType) {
34-
updateModelProviders()
3537
refreshModelProviders()
38+
refetchLLMModelList()
39+
refetchEmbeddingModelList()
40+
refetchRerankModelList()
3641
}
3742

3843
// agent select

web/app/components/plugins/install-plugin/install-from-github/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
136136
setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.uploadFailed }))
137137
}, [])
138138

139-
const handleInstalled = useCallback(() => {
139+
const handleInstalled = useCallback((notRefresh?: boolean) => {
140140
setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.installed }))
141-
refreshPluginList(manifest)
141+
if (!notRefresh)
142+
refreshPluginList(manifest)
142143
setIsInstalling(false)
143144
onSuccess()
144145
}, [manifest, onSuccess, refreshPluginList, setIsInstalling])

web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type LoadedProps = {
2424
selectedPackage: string
2525
onBack: () => void
2626
onStartToInstall?: () => void
27-
onInstalled: () => void
27+
onInstalled: (notRefresh?: boolean) => void
2828
onFailed: (message?: string) => void
2929
}
3030

@@ -55,7 +55,7 @@ const Loaded: React.FC<LoadedProps> = ({
5555

5656
const [isInstalling, setIsInstalling] = React.useState(false)
5757
const { mutateAsync: installPackageFromGitHub } = useInstallPackageFromGitHub()
58-
const { handleRefetch } = usePluginTaskList()
58+
const { handleRefetch } = usePluginTaskList(payload.category)
5959
const { check } = checkTaskStatus()
6060

6161
useEffect(() => {
@@ -127,7 +127,7 @@ const Loaded: React.FC<LoadedProps> = ({
127127
onFailed(error)
128128
return
129129
}
130-
onInstalled()
130+
onInstalled(true)
131131
}
132132
catch (e) {
133133
if (typeof e === 'string') {

web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ const ReadyToInstall: FC<Props> = ({
3232
}) => {
3333
const { refreshPluginList } = useRefreshPluginList()
3434

35-
const handleInstalled = useCallback(() => {
35+
const handleInstalled = useCallback((notRefresh?: boolean) => {
3636
onStepChange(InstallStep.installed)
37-
refreshPluginList(manifest)
37+
if (!notRefresh)
38+
refreshPluginList(manifest)
3839
setIsInstalling(false)
3940
}, [manifest, onStepChange, refreshPluginList, setIsInstalling])
4041

web/app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Props = {
2020
payload: PluginDeclaration
2121
onCancel: () => void
2222
onStartToInstall?: () => void
23-
onInstalled: () => void
23+
onInstalled: (notRefresh?: boolean) => void
2424
onFailed: (message?: string) => void
2525
}
2626

@@ -62,7 +62,7 @@ const Installed: FC<Props> = ({
6262
onCancel()
6363
}
6464

65-
const { handleRefetch } = usePluginTaskList()
65+
const { handleRefetch } = usePluginTaskList(payload.category)
6666
const handleInstall = async () => {
6767
if (isInstalling) return
6868
setIsInstalling(true)
@@ -92,7 +92,7 @@ const Installed: FC<Props> = ({
9292
onFailed(error)
9393
return
9494
}
95-
onInstalled()
95+
onInstalled(true)
9696
}
9797
catch (e) {
9898
if (typeof e === 'string') {

web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
5454
return t(`${i18nPrefix}.installPlugin`)
5555
}, [isBundle, step, t])
5656

57-
const handleInstalled = useCallback(() => {
57+
const handleInstalled = useCallback((notRefresh?: boolean) => {
5858
setStep(InstallStep.installed)
59-
refreshPluginList(manifest)
59+
if (!notRefresh)
60+
refreshPluginList(manifest)
6061
setIsInstalling(false)
6162
}, [manifest, refreshPluginList, setIsInstalling])
6263

web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Props = {
2121
payload: PluginManifestInMarket | Plugin
2222
onCancel: () => void
2323
onStartToInstall?: () => void
24-
onInstalled: () => void
24+
onInstalled: (notRefresh?: boolean) => void
2525
onFailed: (message?: string) => void
2626
}
2727

@@ -51,7 +51,7 @@ const Installed: FC<Props> = ({
5151
check,
5252
stop,
5353
} = checkTaskStatus()
54-
const { handleRefetch } = usePluginTaskList()
54+
const { handleRefetch } = usePluginTaskList(payload.category)
5555

5656
useEffect(() => {
5757
if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier)
@@ -106,7 +106,7 @@ const Installed: FC<Props> = ({
106106
onFailed(error)
107107
return
108108
}
109-
onInstalled()
109+
onInstalled(true)
110110
}
111111
catch (e) {
112112
if (typeof e === 'string') {

web/app/components/plugins/plugin-detail-panel/detail-header.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const DetailHeader = ({
113113
},
114114
payload: {
115115
type: PluginSource.github,
116+
category: detail.declaration.category,
116117
github: {
117118
originalPackageInfo: {
118119
id: detail.plugin_unique_identifier,
@@ -287,6 +288,7 @@ const DetailHeader = ({
287288
isShowUpdateModal && (
288289
<UpdateFromMarketplace
289290
payload={{
291+
category: detail.declaration.category,
290292
originalPackageInfo: {
291293
id: detail.plugin_unique_identifier,
292294
payload: detail.declaration,

web/app/components/plugins/plugin-item/action.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useGitHubReleases } from '../install-plugin/hooks'
1414
import Toast from '@/app/components/base/toast'
1515
import { useModalContext } from '@/context/modal-context'
1616
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
17+
import type { PluginType } from '@/app/components/plugins/types'
1718

1819
const i18nPrefix = 'plugin.action'
1920

@@ -22,6 +23,7 @@ type Props = {
2223
installationId: string
2324
pluginUniqueIdentifier: string
2425
pluginName: string
26+
category: PluginType
2527
usedInApps: number
2628
isShowFetchNewVersion: boolean
2729
isShowInfo: boolean
@@ -34,6 +36,7 @@ const Action: FC<Props> = ({
3436
installationId,
3537
pluginUniqueIdentifier,
3638
pluginName,
39+
category,
3740
isShowFetchNewVersion,
3841
isShowInfo,
3942
isShowDelete,
@@ -67,6 +70,7 @@ const Action: FC<Props> = ({
6770
},
6871
payload: {
6972
type: PluginSource.github,
73+
category,
7074
github: {
7175
originalPackageInfo: {
7276
id: pluginUniqueIdentifier,

web/app/components/plugins/plugin-item/index.tsx

+4-14
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import Title from '../card/base/title'
2020
import Action from './action'
2121
import cn from '@/utils/classnames'
2222
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
23-
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
24-
import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools'
2523
import { useSingleCategories } from '../hooks'
26-
import { useProviderContext } from '@/context/provider-context'
2724
import { useRenderI18nObject } from '@/hooks/use-i18n'
25+
import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list'
2826

2927
type Props = {
3028
className?: string
@@ -39,10 +37,7 @@ const PluginItem: FC<Props> = ({
3937
const { categoriesMap } = useSingleCategories()
4038
const currentPluginID = usePluginPageContext(v => v.currentPluginID)
4139
const setCurrentPluginID = usePluginPageContext(v => v.setCurrentPluginID)
42-
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
43-
const invalidateAllToolProviders = useInvalidateAllToolProviders()
44-
const invalidateAllBuiltinTools = useInvalidateAllBuiltInTools()
45-
const { refreshModelProviders } = useProviderContext()
40+
const { refreshPluginList } = useRefreshPluginList()
4641

4742
const {
4843
source,
@@ -60,13 +55,7 @@ const PluginItem: FC<Props> = ({
6055
}, [source, author])
6156

6257
const handleDelete = () => {
63-
invalidateInstalledPluginList()
64-
if (PluginType.model.includes(category))
65-
refreshModelProviders()
66-
if (PluginType.tool.includes(category)) {
67-
invalidateAllToolProviders()
68-
invalidateAllBuiltinTools()
69-
}
58+
refreshPluginList({ category } as any)
7059
}
7160
const getValueFromI18nObject = useRenderI18nObject()
7261
const title = getValueFromI18nObject(label)
@@ -116,6 +105,7 @@ const PluginItem: FC<Props> = ({
116105
isShowDelete
117106
meta={meta}
118107
onDelete={handleDelete}
108+
category={category}
119109
/>
120110
</div>
121111
</div>

web/app/components/plugins/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export type Permissions = {
151151
}
152152

153153
export type UpdateFromMarketPlacePayload = {
154+
category: PluginType
154155
originalPackageInfo: {
155156
id: string
156157
payload: PluginDeclaration
@@ -173,6 +174,7 @@ export type UpdateFromGitHubPayload = {
173174

174175
export type UpdatePluginPayload = {
175176
type: PluginSource
177+
category: PluginType
176178
marketPlace?: UpdateFromMarketPlacePayload
177179
github?: UpdateFromGitHubPayload
178180
}

web/app/components/plugins/update-plugin/from-market-place.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const UpdatePluginModal: FC<Props> = ({
5757
}
5858

5959
const [uploadStep, setUploadStep] = useState<UploadStep>(UploadStep.notStarted)
60-
const { handleRefetch } = usePluginTaskList()
60+
const { handleRefetch } = usePluginTaskList(payload.category)
6161

6262
const configBtnText = useMemo(() => {
6363
return ({

web/app/components/tools/provider-list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ProviderList = () => {
6969
className='relative flex flex-col overflow-y-auto bg-background-body grow'
7070
>
7171
<div className={cn(
72-
'sticky top-0 flex justify-between items-center pt-4 px-12 pb-2 leading-[56px] z-20 flex-wrap gap-y-2',
72+
'sticky top-0 flex justify-between items-center pt-4 px-12 pb-2 leading-[56px] bg-background-body z-20 flex-wrap gap-y-2',
7373
currentProvider && 'pr-6',
7474
)}>
7575
<TabSliderNew

web/service/use-plugins.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
PluginDetail,
1212
PluginInfoFromMarketPlace,
1313
PluginTask,
14+
PluginType,
1415
PluginsFromMarketplaceByInfoResponse,
1516
PluginsFromMarketplaceResponse,
1617
VersionInfo,
@@ -31,6 +32,7 @@ import {
3132
import { useInvalidateAllBuiltInTools } from './use-tools'
3233
import usePermission from '@/app/components/plugins/plugin-page/use-permission'
3334
import { uninstallPlugin } from '@/service/plugins'
35+
import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list'
3436

3537
const NAME_SPACE = 'plugins'
3638

@@ -367,10 +369,11 @@ export const useFetchPluginsInMarketPlaceByInfo = (infos: Record<string, any>[])
367369
}
368370

369371
const usePluginTaskListKey = [NAME_SPACE, 'pluginTaskList']
370-
export const usePluginTaskList = () => {
372+
export const usePluginTaskList = (category?: PluginType) => {
371373
const {
372374
canManagement,
373375
} = usePermission()
376+
const { refreshPluginList } = useRefreshPluginList()
374377
const {
375378
data,
376379
isFetched,
@@ -383,8 +386,12 @@ export const usePluginTaskList = () => {
383386
refetchInterval: (lastQuery) => {
384387
const lastData = lastQuery.state.data
385388
const taskDone = lastData?.tasks.every(task => task.status === TaskStatus.success || task.status === TaskStatus.failed)
386-
if (taskDone)
389+
const taskAllFailed = lastData?.tasks.every(task => task.status === TaskStatus.failed)
390+
if (taskDone) {
391+
if (lastData?.tasks.length && !taskAllFailed)
392+
refreshPluginList(category ? { category } as any : undefined, !category)
387393
return false
394+
}
388395

389396
return 5000
390397
},

0 commit comments

Comments
 (0)