2024-12-27 11:30:43 +08:00
|
|
|
import { type FC, useMemo } from 'react'
|
2024-12-24 14:20:15 +08:00
|
|
|
import type { NodeProps } from '../../types'
|
|
|
|
import type { AgentNodeType } from './types'
|
|
|
|
import { SettingItem } from '../_base/components/setting-item'
|
|
|
|
import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
|
|
|
|
import { Group, GroupLabel } from '../_base/components/group'
|
2024-12-27 11:30:43 +08:00
|
|
|
import type { ToolIconProps } from './components/tool-icon'
|
2024-12-24 14:20:15 +08:00
|
|
|
import { ToolIcon } from './components/tool-icon'
|
2024-12-25 11:24:24 +08:00
|
|
|
import useConfig from './use-config'
|
2024-12-25 14:23:57 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-12-27 11:30:43 +08:00
|
|
|
import { useInstalledPluginList } from '@/service/use-plugins'
|
2024-12-24 14:20:15 +08:00
|
|
|
|
|
|
|
const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
|
2024-12-27 11:30:43 +08:00
|
|
|
const { inputs, currentStrategy } = useConfig(props.id, props.data)
|
2024-12-25 14:23:57 +08:00
|
|
|
const { t } = useTranslation()
|
2024-12-27 11:30:43 +08:00
|
|
|
const pluginList = useInstalledPluginList()
|
|
|
|
// TODO: Implement models
|
|
|
|
const models = useMemo(() => {
|
|
|
|
const models = []
|
|
|
|
// if selected, show in node
|
|
|
|
// if required and not selected, show empty selector
|
|
|
|
// if not required and not selected, show nothing
|
|
|
|
}, [currentStrategy, inputs.agent_parameters])
|
|
|
|
|
|
|
|
const tools = useMemo(() => {
|
|
|
|
const tools: Array<ToolIconProps> = []
|
|
|
|
currentStrategy?.parameters.forEach((param) => {
|
|
|
|
if (['array[tool]', 'tool'].includes(param.type)) {
|
|
|
|
const vari = inputs.agent_parameters?.[param.name]
|
|
|
|
if (!vari) return
|
|
|
|
if (Array.isArray(vari.value)) {
|
|
|
|
// TODO: Implement array of tools
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// TODO: Implement single tool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, [currentStrategy, inputs.agent_parameters])
|
2024-12-24 14:20:15 +08:00
|
|
|
return <div className='mb-1 px-3 py-1 space-y-1'>
|
2024-12-25 11:24:24 +08:00
|
|
|
{inputs.agent_strategy_name
|
2024-12-25 14:52:11 +08:00
|
|
|
? <SettingItem
|
|
|
|
label={t('workflow.nodes.agent.strategy.shortLabel')}
|
|
|
|
status='error'
|
|
|
|
tooltip={t('workflow.nodes.agent.strategyNotInstallTooltip', {
|
2024-12-26 10:16:52 +08:00
|
|
|
strategy: inputs.agent_strategy_label,
|
2024-12-25 14:52:11 +08:00
|
|
|
})}
|
|
|
|
>
|
2024-12-26 10:16:52 +08:00
|
|
|
{inputs.agent_strategy_label}
|
2024-12-24 14:20:15 +08:00
|
|
|
</SettingItem>
|
2024-12-25 14:23:57 +08:00
|
|
|
: <SettingItem label={t('workflow.nodes.agent.strategyNotSet')} />}
|
2024-12-25 11:24:24 +08:00
|
|
|
<Group
|
|
|
|
label={<GroupLabel className='mt-1'>
|
2024-12-25 14:23:57 +08:00
|
|
|
{t('workflow.nodes.agent.model')}
|
2024-12-25 11:24:24 +08:00
|
|
|
</GroupLabel>}
|
|
|
|
>
|
2024-12-24 14:20:15 +08:00
|
|
|
<ModelSelector
|
|
|
|
modelList={[]}
|
|
|
|
readonly
|
|
|
|
/>
|
|
|
|
<ModelSelector
|
|
|
|
modelList={[]}
|
|
|
|
readonly
|
|
|
|
/>
|
|
|
|
<ModelSelector
|
|
|
|
modelList={[]}
|
|
|
|
readonly
|
|
|
|
/>
|
|
|
|
</Group>
|
|
|
|
<Group label={<GroupLabel className='mt-1'>
|
2024-12-25 14:23:57 +08:00
|
|
|
{t('workflow.nodes.agent.toolbox')}
|
2024-12-24 14:20:15 +08:00
|
|
|
</GroupLabel>}>
|
|
|
|
<div className='grid grid-cols-10 gap-0.5'>
|
|
|
|
<ToolIcon src='/logo/logo.png' />
|
2024-12-25 14:52:11 +08:00
|
|
|
<ToolIcon
|
|
|
|
src='/logo/logo.png'
|
|
|
|
status='error'
|
|
|
|
tooltip={t('workflow.nodes.agent.toolNotInstallTooltip', {
|
|
|
|
tool: 'Gmail Sender',
|
|
|
|
})} />
|
|
|
|
<ToolIcon
|
|
|
|
src='/logo/logo.png'
|
|
|
|
status='warning'
|
|
|
|
tooltip={t('workflow.nodes.agent.toolNotAuthorizedTooltip', {
|
|
|
|
tool: 'DuckDuckGo AI Search',
|
|
|
|
})} />
|
2024-12-24 14:20:15 +08:00
|
|
|
</div>
|
|
|
|
</Group>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AgentNode
|