|
|
|
@ -18,7 +18,6 @@ import AppIcon from '@/app/components/base/app-icon'
|
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
import Indicator from '@/app/components/header/indicator'
|
|
|
|
import Indicator from '@/app/components/header/indicator'
|
|
|
|
import Switch from '@/app/components/base/switch'
|
|
|
|
import Switch from '@/app/components/base/switch'
|
|
|
|
import Toast from '@/app/components/base/toast'
|
|
|
|
|
|
|
|
import ConfigContext from '@/context/debug-configuration'
|
|
|
|
import ConfigContext from '@/context/debug-configuration'
|
|
|
|
import type { AgentTool } from '@/types/app'
|
|
|
|
import type { AgentTool } from '@/types/app'
|
|
|
|
import { type Collection, CollectionType } from '@/app/components/tools/types'
|
|
|
|
import { type Collection, CollectionType } from '@/app/components/tools/types'
|
|
|
|
@ -26,8 +25,6 @@ import { MAX_TOOLS_NUM } from '@/config'
|
|
|
|
import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
|
|
|
|
import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
|
|
|
|
import Tooltip from '@/app/components/base/tooltip'
|
|
|
|
import Tooltip from '@/app/components/base/tooltip'
|
|
|
|
import { DefaultToolIcon } from '@/app/components/base/icons/src/public/other'
|
|
|
|
import { DefaultToolIcon } from '@/app/components/base/icons/src/public/other'
|
|
|
|
import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials'
|
|
|
|
|
|
|
|
import { updateBuiltInToolCredential } from '@/service/tools'
|
|
|
|
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
import ToolPicker from '@/app/components/workflow/block-selector/tool-picker'
|
|
|
|
import ToolPicker from '@/app/components/workflow/block-selector/tool-picker'
|
|
|
|
import type { ToolDefaultValue, ToolValue } from '@/app/components/workflow/block-selector/types'
|
|
|
|
import type { ToolDefaultValue, ToolValue } from '@/app/components/workflow/block-selector/types'
|
|
|
|
@ -57,13 +54,7 @@ const AgentTools: FC = () => {
|
|
|
|
|
|
|
|
|
|
|
|
const formattingChangedDispatcher = useFormattingChangedDispatcher()
|
|
|
|
const formattingChangedDispatcher = useFormattingChangedDispatcher()
|
|
|
|
const [currentTool, setCurrentTool] = useState<AgentToolWithMoreInfo>(null)
|
|
|
|
const [currentTool, setCurrentTool] = useState<AgentToolWithMoreInfo>(null)
|
|
|
|
const currentCollection = useMemo(() => {
|
|
|
|
|
|
|
|
if (!currentTool) return null
|
|
|
|
|
|
|
|
const collection = collectionList.find(collection => canFindTool(collection.id, currentTool?.provider_id) && collection.type === currentTool?.provider_type)
|
|
|
|
|
|
|
|
return collection
|
|
|
|
|
|
|
|
}, [currentTool, collectionList])
|
|
|
|
|
|
|
|
const [isShowSettingTool, setIsShowSettingTool] = useState(false)
|
|
|
|
const [isShowSettingTool, setIsShowSettingTool] = useState(false)
|
|
|
|
const [isShowSettingAuth, setShowSettingAuth] = useState(false)
|
|
|
|
|
|
|
|
const tools = (modelConfig?.agentConfig?.tools as AgentTool[] || []).map((item) => {
|
|
|
|
const tools = (modelConfig?.agentConfig?.tools as AgentTool[] || []).map((item) => {
|
|
|
|
const collection = collectionList.find(
|
|
|
|
const collection = collectionList.find(
|
|
|
|
collection =>
|
|
|
|
collection =>
|
|
|
|
@ -100,17 +91,6 @@ const AgentTools: FC = () => {
|
|
|
|
formattingChangedDispatcher()
|
|
|
|
formattingChangedDispatcher()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleToolAuthSetting = (value: AgentToolWithMoreInfo) => {
|
|
|
|
|
|
|
|
const newModelConfig = produce(modelConfig, (draft) => {
|
|
|
|
|
|
|
|
const tool = (draft.agentConfig.tools).find((item: any) => item.provider_id === value?.collection?.id && item.tool_name === value?.tool_name)
|
|
|
|
|
|
|
|
if (tool)
|
|
|
|
|
|
|
|
(tool as AgentTool).notAuthor = false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
setModelConfig(newModelConfig)
|
|
|
|
|
|
|
|
setIsShowSettingTool(false)
|
|
|
|
|
|
|
|
formattingChangedDispatcher()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [isDeleting, setIsDeleting] = useState<number>(-1)
|
|
|
|
const [isDeleting, setIsDeleting] = useState<number>(-1)
|
|
|
|
const getToolValue = (tool: ToolDefaultValue) => {
|
|
|
|
const getToolValue = (tool: ToolDefaultValue) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
@ -144,6 +124,20 @@ const AgentTools: FC = () => {
|
|
|
|
return item.provider_name
|
|
|
|
return item.provider_name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleAuthorizationItemClick = useCallback((credentialId: string) => {
|
|
|
|
|
|
|
|
const newModelConfig = produce(modelConfig, (draft) => {
|
|
|
|
|
|
|
|
const tool = (draft.agentConfig.tools).find((item: any) => item.provider_id === currentTool?.provider_id)
|
|
|
|
|
|
|
|
if (tool)
|
|
|
|
|
|
|
|
(tool as AgentTool).credential_id = credentialId
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
setCurrentTool({
|
|
|
|
|
|
|
|
...currentTool,
|
|
|
|
|
|
|
|
credential_id: credentialId,
|
|
|
|
|
|
|
|
} as any)
|
|
|
|
|
|
|
|
setModelConfig(newModelConfig)
|
|
|
|
|
|
|
|
formattingChangedDispatcher()
|
|
|
|
|
|
|
|
}, [currentTool, modelConfig, setModelConfig, formattingChangedDispatcher])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Panel
|
|
|
|
<Panel
|
|
|
|
@ -302,7 +296,7 @@ const AgentTools: FC = () => {
|
|
|
|
{item.notAuthor && (
|
|
|
|
{item.notAuthor && (
|
|
|
|
<Button variant='secondary' size='small' onClick={() => {
|
|
|
|
<Button variant='secondary' size='small' onClick={() => {
|
|
|
|
setCurrentTool(item)
|
|
|
|
setCurrentTool(item)
|
|
|
|
setShowSettingAuth(true)
|
|
|
|
setIsShowSettingTool(true)
|
|
|
|
}}>
|
|
|
|
}}>
|
|
|
|
{t('tools.notAuthorized')}
|
|
|
|
{t('tools.notAuthorized')}
|
|
|
|
<Indicator className='ml-2' color='orange' />
|
|
|
|
<Indicator className='ml-2' color='orange' />
|
|
|
|
@ -322,21 +316,8 @@ const AgentTools: FC = () => {
|
|
|
|
isModel={currentTool?.collection?.type === CollectionType.model}
|
|
|
|
isModel={currentTool?.collection?.type === CollectionType.model}
|
|
|
|
onSave={handleToolSettingChange}
|
|
|
|
onSave={handleToolSettingChange}
|
|
|
|
onHide={() => setIsShowSettingTool(false)}
|
|
|
|
onHide={() => setIsShowSettingTool(false)}
|
|
|
|
/>
|
|
|
|
credentialId={currentTool?.credential_id}
|
|
|
|
)}
|
|
|
|
onAuthorizationItemClick={handleAuthorizationItemClick}
|
|
|
|
{isShowSettingAuth && (
|
|
|
|
|
|
|
|
<ConfigCredential
|
|
|
|
|
|
|
|
collection={currentCollection as any}
|
|
|
|
|
|
|
|
onCancel={() => setShowSettingAuth(false)}
|
|
|
|
|
|
|
|
onSaved={async (value) => {
|
|
|
|
|
|
|
|
await updateBuiltInToolCredential((currentCollection as any).name, value)
|
|
|
|
|
|
|
|
Toast.notify({
|
|
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
|
|
message: t('common.api.actionSuccess'),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
handleToolAuthSetting(currentTool)
|
|
|
|
|
|
|
|
setShowSettingAuth(false)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
|