feat: agent node check install strategy

This commit is contained in:
AkaraChen 2025-01-02 14:27:19 +08:00
parent c469da2020
commit add6dff789
4 changed files with 22 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import useConfig from './use-config'
import { useTranslation } from 'react-i18next'
import { FormTypeEnum, ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useRenderI18nObject } from '@/hooks/use-i18n'
const useAllModel = () => {
const { data: textGeneration } = useModelList(ModelTypeEnum.textGeneration)
@ -32,7 +33,8 @@ const useAllModel = () => {
}
const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const { inputs, currentStrategy } = useConfig(props.id, props.data)
const { inputs, currentStrategy, currentStrategyStatus, pluginDetail } = useConfig(props.id, props.data)
const renderI18nObject = useRenderI18nObject()
const { t } = useTranslation()
const modelList = useAllModel()
const models = useMemo(() => {
@ -87,9 +89,16 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
{inputs.agent_strategy_name
? <SettingItem
label={t('workflow.nodes.agent.strategy.shortLabel')}
status='error'
tooltip={t('workflow.nodes.agent.strategyNotInstallTooltip', {
status={
['plugin-not-found', 'strategy-not-found'].includes(currentStrategyStatus)
? 'error'
: undefined
}
tooltip={t(`workflow.nodes.agent.${currentStrategyStatus === 'plugin-not-found' ? 'strategyNotInstallTooltip' : 'strategyNotFoundInPlugin'}`, {
strategy: inputs.agent_strategy_label,
plugin: pluginDetail?.declaration.label
? renderI18nObject(pluginDetail?.declaration.label)
: undefined,
})}
>
{inputs.agent_strategy_label}

View File

@ -8,6 +8,7 @@ import {
} from '@/app/components/workflow/hooks'
import { useMemo } from 'react'
import { type ToolVarInputs, VarType } from '../tool/types'
import { useCheckInstalled } from '@/service/use-plugins'
const useConfig = (id: string, payload: AgentNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
@ -20,16 +21,20 @@ const useConfig = (id: string, payload: AgentNodeType) => {
const strategyProvider = useStrategyProviderDetail(
inputs.agent_strategy_provider_name || '',
)
const currentStrategy = strategyProvider.data?.declaration.strategies.find(
str => str.identity.name === inputs.agent_strategy_name,
)
const currentStrategyStatus = useMemo(() => {
const currentStrategyStatus: 'loading' | 'plugin-not-found' | 'strategy-not-found' | 'success' = useMemo(() => {
if (strategyProvider.isLoading) return 'loading'
if (strategyProvider.isError) return 'plugin-not-found'
if (!currentStrategy) return 'strategy-not-found'
return 'success'
}, [currentStrategy, strategyProvider])
const pluginId = inputs.agent_strategy_provider_name?.split('/').splice(0, 2).join('/')
const pluginDetail = useCheckInstalled({
pluginIds: [pluginId || ''],
enabled: Boolean(pluginId),
})
const formData = useMemo(() => {
return Object.fromEntries(
Object.entries(inputs.agent_parameters || {}).map(([key, value]) => {
@ -91,6 +96,7 @@ const useConfig = (id: string, payload: AgentNodeType) => {
onFormChange,
currentStrategyStatus,
strategyProvider: strategyProvider.data,
pluginDetail: pluginDetail.data?.plugins.at(0),
isShowSingleRun,
showSingleRun,

View File

@ -732,6 +732,7 @@ const translation = {
toolNotInstallTooltip: '{{tool}} is not installed',
toolNotAuthorizedTooltip: '{{tool}} Not Authorized',
strategyNotInstallTooltip: '{{strategy}} is not installed',
strategyNotFoundInPlugin: '{{strategy}} is not found in {{plugin}}',
modelSelectorTooltips: {
deprecated: 'This model is deprecated',
},

View File

@ -732,6 +732,7 @@ const translation = {
toolNotInstallTooltip: '{{tool}} 未安装',
toolNotAuthorizedTooltip: '{{tool}} 未授权',
strategyNotInstallTooltip: '{{strategy}} 未安装',
strategyNotFoundInPlugin: '在 {{plugin}} 中未找到 {{strategy}}',
modelSelectorTooltips: {
deprecated: '此模型已弃用',
},