From 1387c6bd1cc5959fec49c61b9cce4296d8365009 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Mon, 28 Oct 2024 21:23:23 +0800 Subject: [PATCH] update style of agent tool list --- .../config/agent/agent-tools/index.tsx | 235 +++++++++++------- .../components/base/app-icon/style.module.css | 2 +- web/i18n/en-US/tools.ts | 3 +- web/i18n/zh-Hans/tools.ts | 1 + 4 files changed, 152 insertions(+), 89 deletions(-) diff --git a/web/app/components/app/configuration/config/agent/agent-tools/index.tsx b/web/app/components/app/configuration/config/agent/agent-tools/index.tsx index 52e5d5d906..b66f331f5b 100644 --- a/web/app/components/app/configuration/config/agent/agent-tools/index.tsx +++ b/web/app/components/app/configuration/config/agent/agent-tools/index.tsx @@ -1,21 +1,25 @@ 'use client' import type { FC } from 'react' -import React, { useState } from 'react' +import React, { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' +import copy from 'copy-to-clipboard' import produce from 'immer' import { RiDeleteBinLine, + RiEqualizer2Line, RiHammerFill, + RiInformation2Line, } from '@remixicon/react' import { useFormattingChangedDispatcher } from '../../../debug/hooks' import SettingBuiltInTool from './setting-built-in-tool' -import cn from '@/utils/classnames' import Panel from '@/app/components/app/configuration/base/feature-panel' -import { InfoCircle } from '@/app/components/base/icons/src/vender/line/general' import OperationBtn from '@/app/components/app/configuration/base/operation-btn' import AppIcon from '@/app/components/base/app-icon' +import Button from '@/app/components/base/button' +import Indicator from '@/app/components/header/indicator' import Switch from '@/app/components/base/switch' +import Toast from '@/app/components/base/toast' import ConfigContext from '@/context/debug-configuration' import type { AgentTool } from '@/types/app' import { type Collection, CollectionType } from '@/app/components/tools/types' @@ -24,6 +28,9 @@ import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/aler import Tooltip from '@/app/components/base/tooltip' import { DefaultToolIcon } from '@/app/components/base/icons/src/public/other' import AddToolModal from '@/app/components/tools/add-tool-modal' +import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials' +import { updateBuiltInToolCredential } from '@/service/tools' +import cn from '@/utils/classnames' type AgentToolWithMoreInfo = AgentTool & { icon: any; collection?: Collection } | null const AgentTools: FC = () => { @@ -33,7 +40,13 @@ const AgentTools: FC = () => { const formattingChangedDispatcher = useFormattingChangedDispatcher() const [currentTool, setCurrentTool] = useState(null) + const currentCollection = useMemo(() => { + if (!currentTool) return null + const collection = collectionList.find(collection => collection.id === currentTool?.provider_id && collection.type === currentTool?.provider_type) + return collection + }, [currentTool, collectionList]) const [isShowSettingTool, setIsShowSettingTool] = useState(false) + const [isShowSettingAuth, setShowSettingAuth] = useState(false) const tools = (modelConfig?.agentConfig?.tools as AgentTool[] || []).map((item) => { const collection = collectionList.find(collection => collection.id === item.provider_id && collection.type === item.provider_type) const icon = collection?.icon @@ -55,6 +68,19 @@ const AgentTools: FC = () => { formattingChangedDispatcher() } + const handleToolAuthSetting = (value: any) => { + 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(-1) + return ( <> {
{tools.map((item: AgentTool & { icon: any; collection?: Collection }, index) => (
1 && 'mt-1', 'group relative flex justify-between items-center last-of-type:mb-0 pl-2.5 py-2 pr-3 w-full rounded-lg border-[0.5px] border-gray-200 ')} + className={cn( + 'group relative flex justify-between items-center last-of-type:mb-0 p-1.5 pr-2 w-full bg-components-panel-on-panel-item-bg rounded-lg border-[0.5px] border-components-panel-border-subtle shadow-xs hover:bg-components-panel-on-panel-item-bg-hover hover:shadow-sm cursor', + isDeleting === index && 'hover:bg-state-destructive-hover border-state-destructive-border', + )} >
- {(item.isDeleted || item.notAuthor) - ? ( - - ) - : ( - typeof item.icon === 'string' - ? ( -
- ) - : ( - - ))} + {item.isDeleted && } + {!item.isDeleted && ( +
+ {typeof item.icon === 'string' &&
} + {typeof item.icon !== 'string' && } +
+ )}
- {item.provider_type === CollectionType.builtIn ? item.provider_name : item.tool_label} - - {item.tool_name} - + {item.provider_type === CollectionType.builtIn ? item.provider_name : item.tool_label} + {item.tool_name} + {!item.isDeleted && ( + +
{item.tool_name}
+
{t('tools.toolNameUsageTip')}
+
copy(item.tool_name)}>{t('tools.copyToolName')}
+
+ } + > +
+
+ +
+
+ + )}
- {(item.isDeleted || item.notAuthor) - ? ( -
- -
{ - if (item.notAuthor) - setIsShowChooseTool(true) - }}> - -
-
- -
{ + {item.isDeleted && ( +
+ +
+ +
+
+
{ const newModelConfig = produce(modelConfig, (draft) => { draft.agentConfig.tools.splice(index, 1) }) setModelConfig(newModelConfig) formattingChangedDispatcher() - }}> - -
-
+ }} + onMouseOver={() => setIsDeleting(index)} + onMouseLeave={() => setIsDeleting(-1)} + > +
- ) - : ( -
+
+ )} + {!item.isDeleted && ( +
+ {!item.notAuthor && ( { setCurrentTool(item) setIsShowSettingTool(true) }}> - +
- -
{ + )} +
{ const newModelConfig = produce(modelConfig, (draft) => { draft.agentConfig.tools.splice(index, 1) }) setModelConfig(newModelConfig) formattingChangedDispatcher() - }}> - -
-
+ }} + onMouseOver={() => setIsDeleting(index)} + onMouseLeave={() => setIsDeleting(-1)} + > +
+
+ )} +
+ {!item.notAuthor && ( + { + const newModelConfig = produce(modelConfig, (draft) => { + (draft.agentConfig.tools[index] as any).enabled = enabled + }) + setModelConfig(newModelConfig) + formattingChangedDispatcher() + }} /> + )} + {item.notAuthor && ( + )} -
- { - const newModelConfig = produce(modelConfig, (draft) => { - (draft.agentConfig.tools[index] as any).enabled = enabled - }) - setModelConfig(newModelConfig) - formattingChangedDispatcher() - }} />
@@ -201,18 +248,32 @@ const AgentTools: FC = () => { {isShowChooseTool && ( setIsShowChooseTool(false)} /> )} - { - isShowSettingTool && ( - setIsShowSettingTool(false)} - />) - } + {isShowSettingTool && ( + setIsShowSettingTool(false)} + /> + )} + {isShowSettingAuth && ( + setShowSettingAuth(false)} + onSaved={async (value) => { + await updateBuiltInToolCredential((currentCollection as any).name, value) + Toast.notify({ + type: 'success', + message: t('common.api.actionSuccess'), + }) + handleToolAuthSetting(currentTool as any) + setShowSettingAuth(false) + }} + /> + )} ) } diff --git a/web/app/components/base/app-icon/style.module.css b/web/app/components/base/app-icon/style.module.css index 06a2478d41..151bc6d3fc 100644 --- a/web/app/components/base/app-icon/style.module.css +++ b/web/app/components/base/app-icon/style.module.css @@ -15,7 +15,7 @@ } .appIcon.xs { - @apply w-3 h-3 text-base; + @apply w-5 h-5 text-base; } .appIcon.rounded { diff --git a/web/i18n/en-US/tools.ts b/web/i18n/en-US/tools.ts index 2e860f5ceb..9c2d22b711 100644 --- a/web/i18n/en-US/tools.ts +++ b/web/i18n/en-US/tools.ts @@ -144,10 +144,11 @@ const translation = { }, builtInPromptTitle: 'Prompt', toolRemoved: 'Tool removed', - notAuthorized: 'Tool not authorized', + notAuthorized: 'Not authorized', howToGet: 'How to get', openInStudio: 'Open in Studio', toolNameUsageTip: 'Tool call name for agent reasoning and prompting', + copyToolName: 'Copy Name', } export default translation diff --git a/web/i18n/zh-Hans/tools.ts b/web/i18n/zh-Hans/tools.ts index 0a5a39317c..fa1e8344a7 100644 --- a/web/i18n/zh-Hans/tools.ts +++ b/web/i18n/zh-Hans/tools.ts @@ -148,6 +148,7 @@ const translation = { howToGet: '如何获取', openInStudio: '在工作室中打开', toolNameUsageTip: '工具调用名称,用于 Agent 推理和提示词', + copyToolName: '复制名称', } export default translation