mirror of https://github.com/langgenius/dify.git
Fix plugin install detection for tool nodes
This commit is contained in:
parent
6e0765fbaf
commit
ff0f645e54
|
|
@ -7,15 +7,25 @@ import { useCheckInstalled, useInstallPackageFromMarketPlace } from '@/service/u
|
|||
|
||||
type InstallPluginButtonProps = Omit<ComponentProps<typeof Button>, 'children' | 'loading'> & {
|
||||
uniqueIdentifier: string
|
||||
extraIdentifiers?: string[]
|
||||
onSuccess?: () => void
|
||||
}
|
||||
|
||||
export const InstallPluginButton = (props: InstallPluginButtonProps) => {
|
||||
const { className, uniqueIdentifier, onSuccess, ...rest } = props
|
||||
const {
|
||||
className,
|
||||
uniqueIdentifier,
|
||||
extraIdentifiers = [],
|
||||
onSuccess,
|
||||
...rest
|
||||
} = props
|
||||
const { t } = useTranslation()
|
||||
const identifiers = Array.from(new Set(
|
||||
[uniqueIdentifier, ...extraIdentifiers].filter((item): item is string => Boolean(item)),
|
||||
))
|
||||
const manifest = useCheckInstalled({
|
||||
pluginIds: [uniqueIdentifier],
|
||||
enabled: !!uniqueIdentifier,
|
||||
pluginIds: identifiers,
|
||||
enabled: identifiers.length > 0,
|
||||
})
|
||||
const install = useInstallPackageFromMarketPlace()
|
||||
const isLoading = manifest.isLoading || install.isPending
|
||||
|
|
@ -31,7 +41,13 @@ export const InstallPluginButton = (props: InstallPluginButtonProps) => {
|
|||
})
|
||||
}
|
||||
if (!manifest.data) return null
|
||||
if (manifest.data.plugins.some(plugin => plugin.id === uniqueIdentifier)) return null
|
||||
const identifierSet = new Set(identifiers)
|
||||
const isInstalled = manifest.data.plugins.some(plugin => (
|
||||
identifierSet.has(plugin.id)
|
||||
|| (plugin.plugin_unique_identifier && identifierSet.has(plugin.plugin_unique_identifier))
|
||||
|| (plugin.plugin_id && identifierSet.has(plugin.plugin_id))
|
||||
))
|
||||
if (isInstalled) return null
|
||||
return <Button
|
||||
variant={'secondary'}
|
||||
disabled={isLoading}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ const Node: FC<NodeProps<DataSourceNodeType>> = ({
|
|||
<div className='absolute right-3 top-[-32px] z-20'>
|
||||
<InstallPluginButton
|
||||
size='small'
|
||||
extraIdentifiers={[
|
||||
data.plugin_id,
|
||||
data.provider_name,
|
||||
].filter(Boolean) as string[]}
|
||||
className='!font-medium !text-text-accent'
|
||||
uniqueIdentifier={uniqueIdentifier!}
|
||||
onSuccess={onInstallSuccess}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ const Node: FC<NodeProps<ToolNodeType>> = ({
|
|||
<InstallPluginButton
|
||||
size='small'
|
||||
className='!font-medium !text-text-accent'
|
||||
extraIdentifiers={[
|
||||
data.plugin_id,
|
||||
data.provider_id,
|
||||
data.provider_name,
|
||||
].filter(Boolean) as string[]}
|
||||
uniqueIdentifier={uniqueIdentifier!}
|
||||
onSuccess={onInstallSuccess}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -65,6 +65,11 @@ const Node: FC<NodeProps<PluginTriggerNodeType>> = ({
|
|||
<div className="absolute right-3 top-[-32px] z-20">
|
||||
<InstallPluginButton
|
||||
size="small"
|
||||
extraIdentifiers={[
|
||||
data.plugin_id,
|
||||
data.provider_id,
|
||||
data.provider_name,
|
||||
].filter(Boolean) as string[]}
|
||||
className="!font-medium !text-text-accent"
|
||||
uniqueIdentifier={uniqueIdentifier!}
|
||||
onSuccess={onInstallSuccess}
|
||||
|
|
|
|||
Loading…
Reference in New Issue