|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import type { FC } from 'react'
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
import type {
|
|
|
|
|
CustomConfigurationModelFixedFields,
|
|
|
|
|
@ -9,6 +9,7 @@ import type {
|
|
|
|
|
import {
|
|
|
|
|
ConfigurationMethodEnum,
|
|
|
|
|
CustomConfigurationStatusEnum,
|
|
|
|
|
ModelTypeEnum,
|
|
|
|
|
} from '../declarations'
|
|
|
|
|
import { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from '../provider-added-card'
|
|
|
|
|
import type { PluginInfoFromMarketPlace } from '@/app/components/plugins/types'
|
|
|
|
|
@ -54,13 +55,19 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|
|
|
|
const updateModelProviders = useUpdateModelProviders()
|
|
|
|
|
const updateModelList = useUpdateModelList()
|
|
|
|
|
const { eventEmitter } = useEventEmitterContextContext()
|
|
|
|
|
const modelProvider = modelProviders.find(item => item.provider === providerName)
|
|
|
|
|
const needsConfiguration = modelProvider?.custom_configuration.status === CustomConfigurationStatusEnum.noConfigure && !(
|
|
|
|
|
modelProvider.system_configuration.enabled === true
|
|
|
|
|
&& modelProvider.system_configuration.quota_configurations.find(
|
|
|
|
|
item => item.quota_type === modelProvider.system_configuration.current_quota_type,
|
|
|
|
|
const { modelProvider, needsConfiguration } = useMemo(() => {
|
|
|
|
|
const modelProvider = modelProviders.find(item => item.provider === providerName)
|
|
|
|
|
const needsConfiguration = modelProvider?.custom_configuration.status === CustomConfigurationStatusEnum.noConfigure && !(
|
|
|
|
|
modelProvider.system_configuration.enabled === true
|
|
|
|
|
&& modelProvider.system_configuration.quota_configurations.find(
|
|
|
|
|
item => item.quota_type === modelProvider.system_configuration.current_quota_type,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return {
|
|
|
|
|
modelProvider,
|
|
|
|
|
needsConfiguration,
|
|
|
|
|
}
|
|
|
|
|
}, [modelProviders, providerName])
|
|
|
|
|
const [pluginInfo, setPluginInfo] = useState<PluginInfoFromMarketPlace | null>(null)
|
|
|
|
|
const [isPluginChecked, setIsPluginChecked] = useState(false)
|
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
@ -124,6 +131,24 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleInstall = async (pluginInfo: PluginInfoFromMarketPlace) => {
|
|
|
|
|
setLoading(true)
|
|
|
|
|
try {
|
|
|
|
|
const { all_installed } = await installPackageFromMarketPlace(pluginInfo.latest_package_identifier)
|
|
|
|
|
if (all_installed) {
|
|
|
|
|
setInstalled(true)
|
|
|
|
|
updateModelProviders()
|
|
|
|
|
updateModelList(ModelTypeEnum.textGeneration)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
console.error('Installation failed:', error)
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
setLoading(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
@ -158,15 +183,18 @@ const AgentModelTrigger: FC<AgentModelTriggerProps> = ({
|
|
|
|
|
{!installed && !modelProvider && pluginInfo && (
|
|
|
|
|
<InstallButton
|
|
|
|
|
loading={loading}
|
|
|
|
|
onInstall={async () => {
|
|
|
|
|
setLoading(true)
|
|
|
|
|
const { all_installed } = await installPackageFromMarketPlace(pluginInfo.latest_package_identifier)
|
|
|
|
|
if (all_installed)
|
|
|
|
|
setInstalled(true)
|
|
|
|
|
onInstall={(e) => {
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
handleInstall(pluginInfo)
|
|
|
|
|
}}
|
|
|
|
|
t={t}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{modelProvider && !disabled && (
|
|
|
|
|
<div className="flex pr-1 items-center">
|
|
|
|
|
<RiEqualizer2Line className="w-4 h-4 text-text-tertiary group-hover:text-text-secondary" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
|