chore: update the model install button
This commit is contained in:
parent
275696edba
commit
e6eae8568f
@ -17,7 +17,7 @@ const InstallButton = ({ loading, onInstall, t }: InstallButtonProps) => {
|
|||||||
{loading ? t('workflow.nodes.agent.pluginInstaller.installing') : t('workflow.nodes.agent.pluginInstaller.install')}
|
{loading ? t('workflow.nodes.agent.pluginInstaller.installing') : t('workflow.nodes.agent.pluginInstaller.install')}
|
||||||
</div>
|
</div>
|
||||||
{loading
|
{loading
|
||||||
? <RiLoader2Line className='w-3.5 h-3.5 text-text-quaternary' />
|
? <RiLoader2Line className='w-3.5 h-3.5 text-text-quaternary animate-spin' />
|
||||||
: <RiInstallLine className='w-3.5 h-3.5 text-text-secondary' />
|
: <RiInstallLine className='w-3.5 h-3.5 text-text-secondary' />
|
||||||
}
|
}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
} from '../declarations'
|
} from '../declarations'
|
||||||
import { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from '../provider-added-card'
|
import { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from '../provider-added-card'
|
||||||
import type { PluginInfoFromMarketPlace } from '@/app/components/plugins/types'
|
import type { PluginInfoFromMarketPlace } from '@/app/components/plugins/types'
|
||||||
import { useInstallPackageFromMarketPlace } from '@/service/use-plugins'
|
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
|
||||||
import ConfigurationButton from './configuration-button'
|
import ConfigurationButton from './configuration-button'
|
||||||
import { PluginType } from '@/app/components/plugins/types'
|
import { PluginType } from '@/app/components/plugins/types'
|
||||||
import {
|
import {
|
||||||
@ -22,7 +22,7 @@ import {
|
|||||||
} from '../hooks'
|
} from '../hooks'
|
||||||
import ModelIcon from '../model-icon'
|
import ModelIcon from '../model-icon'
|
||||||
import ModelDisplay from './model-display'
|
import ModelDisplay from './model-display'
|
||||||
import InstallButton from '@/app/components/base/install-button'
|
import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button'
|
||||||
import StatusIndicators from './status-indicators'
|
import StatusIndicators from './status-indicators'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
@ -72,10 +72,8 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|||||||
}, [modelProviders, providerName])
|
}, [modelProviders, providerName])
|
||||||
const [pluginInfo, setPluginInfo] = useState<PluginInfoFromMarketPlace | null>(null)
|
const [pluginInfo, setPluginInfo] = useState<PluginInfoFromMarketPlace | null>(null)
|
||||||
const [isPluginChecked, setIsPluginChecked] = useState(false)
|
const [isPluginChecked, setIsPluginChecked] = useState(false)
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const [installed, setInstalled] = useState(false)
|
const [installed, setInstalled] = useState(false)
|
||||||
const { mutateAsync: installPackageFromMarketPlace } = useInstallPackageFromMarketPlace()
|
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (providerName && !modelProvider) {
|
if (providerName && !modelProvider) {
|
||||||
@ -133,34 +131,6 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInstall = async (pluginInfo: PluginInfoFromMarketPlace) => {
|
|
||||||
setLoading(true)
|
|
||||||
try {
|
|
||||||
const { all_installed } = await installPackageFromMarketPlace(pluginInfo.latest_package_identifier)
|
|
||||||
if (all_installed) {
|
|
||||||
[
|
|
||||||
ModelTypeEnum.textGeneration,
|
|
||||||
ModelTypeEnum.textEmbedding,
|
|
||||||
ModelTypeEnum.rerank,
|
|
||||||
ModelTypeEnum.moderation,
|
|
||||||
ModelTypeEnum.speech2text,
|
|
||||||
ModelTypeEnum.tts,
|
|
||||||
].forEach((type: ModelTypeEnum) => {
|
|
||||||
if (scope?.includes(type))
|
|
||||||
updateModelList(type)
|
|
||||||
})
|
|
||||||
updateModelProviders()
|
|
||||||
setInstalled(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('Installation failed:', error)
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
@ -193,13 +163,27 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|||||||
t={t}
|
t={t}
|
||||||
/>
|
/>
|
||||||
{!installed && !modelProvider && pluginInfo && (
|
{!installed && !modelProvider && pluginInfo && (
|
||||||
<InstallButton
|
<InstallPluginButton
|
||||||
loading={loading}
|
onClick={e => e.stopPropagation()}
|
||||||
onInstall={(e) => {
|
size={'small'}
|
||||||
e.stopPropagation()
|
uniqueIdentifier={pluginInfo.latest_package_identifier}
|
||||||
handleInstall(pluginInfo)
|
onSuccess={() => {
|
||||||
|
[
|
||||||
|
ModelTypeEnum.textGeneration,
|
||||||
|
ModelTypeEnum.textEmbedding,
|
||||||
|
ModelTypeEnum.rerank,
|
||||||
|
ModelTypeEnum.moderation,
|
||||||
|
ModelTypeEnum.speech2text,
|
||||||
|
ModelTypeEnum.tts,
|
||||||
|
].forEach((type: ModelTypeEnum) => {
|
||||||
|
if (scope?.includes(type))
|
||||||
|
updateModelList(type)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
updateModelProviders()
|
||||||
|
invalidateInstalledPluginList()
|
||||||
|
setInstalled(true)
|
||||||
}}
|
}}
|
||||||
t={t}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{modelProvider && !disabled && !needsConfiguration && (
|
{modelProvider && !disabled && !needsConfiguration && (
|
||||||
|
@ -38,6 +38,6 @@ export const InstallPluginButton = (props: InstallPluginButtonProps) => {
|
|||||||
className={classNames('flex items-center', className)}
|
className={classNames('flex items-center', className)}
|
||||||
>
|
>
|
||||||
{!isLoading ? t('workflow.nodes.agent.pluginInstaller.install') : t('workflow.nodes.agent.pluginInstaller.installing')}
|
{!isLoading ? t('workflow.nodes.agent.pluginInstaller.install') : t('workflow.nodes.agent.pluginInstaller.installing')}
|
||||||
{!isLoading ? <RiInstallLine className='size-4 ml-1' /> : <RiLoader2Line className='size-4 ml-1 animate-spin' />}
|
{!isLoading ? <RiInstallLine className='size-3.5 ml-1' /> : <RiLoader2Line className='size-3.5 ml-1 animate-spin' />}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user