feat: agent node check install strategy

pull/12560/head
AkaraChen 1 year ago
parent c469da2020
commit add6dff789

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

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

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

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

Loading…
Cancel
Save