| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import React, { useCallback, useEffect, useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { useContext } from 'use-context-selector' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiCloseLine, | 
					
						
							|  |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import { AuthHeaderPrefix, AuthType, CollectionType } from '../types' | 
					
						
							|  |  |  | import type { Collection, CustomCollectionBackend, Tool, WorkflowToolProviderRequest, WorkflowToolProviderResponse } from '../types' | 
					
						
							|  |  |  | import ToolItem from './tool-item' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import I18n from '@/context/i18n' | 
					
						
							|  |  |  | import { getLanguage } from '@/i18n/language' | 
					
						
							| 
									
										
										
										
											2024-06-26 19:27:22 +08:00
										 |  |  | import Confirm from '@/app/components/base/confirm' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import Button from '@/app/components/base/button' | 
					
						
							|  |  |  | import Indicator from '@/app/components/header/indicator' | 
					
						
							|  |  |  | import { LinkExternal02, Settings01 } from '@/app/components/base/icons/src/vender/line/general' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import Icon from '@/app/components/plugins/card/base/card-icon' | 
					
						
							|  |  |  | import Title from '@/app/components/plugins/card/base/title' | 
					
						
							|  |  |  | import OrgInfo from '@/app/components/plugins/card/base/org-info' | 
					
						
							|  |  |  | import Description from '@/app/components/plugins/card/base/description' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials' | 
					
						
							|  |  |  | import EditCustomToolModal from '@/app/components/tools/edit-custom-collection-modal' | 
					
						
							|  |  |  | import WorkflowToolModal from '@/app/components/tools/workflow-tool' | 
					
						
							|  |  |  | import Toast from '@/app/components/base/toast' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import Drawer from '@/app/components/base/drawer' | 
					
						
							|  |  |  | import ActionButton from '@/app/components/base/action-button' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   deleteWorkflowTool, | 
					
						
							|  |  |  |   fetchBuiltInToolList, | 
					
						
							|  |  |  |   fetchCustomCollection, | 
					
						
							|  |  |  |   fetchCustomToolList, | 
					
						
							|  |  |  |   fetchModelToolList, | 
					
						
							|  |  |  |   fetchWorkflowToolDetail, | 
					
						
							|  |  |  |   removeBuiltInToolCredential, | 
					
						
							|  |  |  |   removeCustomCollection, | 
					
						
							|  |  |  |   saveWorkflowToolProvider, | 
					
						
							|  |  |  |   updateBuiltInToolCredential, | 
					
						
							|  |  |  |   updateCustomCollection, | 
					
						
							|  |  |  | } from '@/service/tools' | 
					
						
							|  |  |  | import { useModalContext } from '@/context/modal-context' | 
					
						
							|  |  |  | import { useProviderContext } from '@/context/provider-context' | 
					
						
							| 
									
										
										
										
											2024-06-05 14:01:12 +08:00
										 |  |  | import { ConfigurationMethodEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import Loading from '@/app/components/base/loading' | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  | import { useAppContext } from '@/context/app-context' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import { useInvalidateAllWorkflowTools } from '@/service/use-tools' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Props = { | 
					
						
							|  |  |  |   collection: Collection | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   onHide: () => void | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   onRefreshData: () => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ProviderDetail = ({ | 
					
						
							|  |  |  |   collection, | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   onHide, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   onRefreshData, | 
					
						
							|  |  |  | }: Props) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const { locale } = useContext(I18n) | 
					
						
							|  |  |  |   const language = getLanguage(locale) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const needAuth = collection.allow_delete || collection.type === CollectionType.model | 
					
						
							|  |  |  |   const isAuthed = collection.is_team_authorization | 
					
						
							|  |  |  |   const isBuiltIn = collection.type === CollectionType.builtIn | 
					
						
							|  |  |  |   const isModel = collection.type === CollectionType.model | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |   const { isCurrentWorkspaceManager } = useAppContext() | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   const invalidateAllWorkflowTools = useInvalidateAllWorkflowTools() | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   const [isDetailLoading, setIsDetailLoading] = useState(false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // built in provider
 | 
					
						
							|  |  |  |   const [showSettingAuth, setShowSettingAuth] = useState(false) | 
					
						
							|  |  |  |   const { setShowModelModal } = useModalContext() | 
					
						
							|  |  |  |   const { modelProviders: providers } = useProviderContext() | 
					
						
							|  |  |  |   const showSettingAuthModal = () => { | 
					
						
							|  |  |  |     if (isModel) { | 
					
						
							|  |  |  |       const provider = providers.find(item => item.provider === collection?.id) | 
					
						
							|  |  |  |       if (provider) { | 
					
						
							|  |  |  |         setShowModelModal({ | 
					
						
							|  |  |  |           payload: { | 
					
						
							|  |  |  |             currentProvider: provider, | 
					
						
							| 
									
										
										
										
											2024-06-05 14:01:12 +08:00
										 |  |  |             currentConfigurationMethod: ConfigurationMethodEnum.predefinedModel, | 
					
						
							|  |  |  |             currentCustomConfigurationModelFixedFields: undefined, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |           }, | 
					
						
							|  |  |  |           onSaveCallback: () => { | 
					
						
							|  |  |  |             onRefreshData() | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       setShowSettingAuth(true) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   // custom provider
 | 
					
						
							|  |  |  |   const [customCollection, setCustomCollection] = useState<CustomCollectionBackend | WorkflowToolProviderResponse | null>(null) | 
					
						
							|  |  |  |   const [isShowEditCollectionToolModal, setIsShowEditCustomCollectionModal] = useState(false) | 
					
						
							| 
									
										
										
										
											2024-06-26 19:27:22 +08:00
										 |  |  |   const [showConfirmDelete, setShowConfirmDelete] = useState(false) | 
					
						
							| 
									
										
										
										
											2024-07-25 11:21:51 +08:00
										 |  |  |   const [deleteAction, setDeleteAction] = useState('') | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   const doUpdateCustomToolCollection = async (data: CustomCollectionBackend) => { | 
					
						
							|  |  |  |     await updateCustomCollection(data) | 
					
						
							|  |  |  |     onRefreshData() | 
					
						
							|  |  |  |     Toast.notify({ | 
					
						
							|  |  |  |       type: 'success', | 
					
						
							|  |  |  |       message: t('common.api.actionSuccess'), | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setIsShowEditCustomCollectionModal(false) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const doRemoveCustomToolCollection = async () => { | 
					
						
							|  |  |  |     await removeCustomCollection(collection?.name as string) | 
					
						
							|  |  |  |     onRefreshData() | 
					
						
							|  |  |  |     Toast.notify({ | 
					
						
							|  |  |  |       type: 'success', | 
					
						
							|  |  |  |       message: t('common.api.actionSuccess'), | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setIsShowEditCustomCollectionModal(false) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const getCustomProvider = useCallback(async () => { | 
					
						
							|  |  |  |     setIsDetailLoading(true) | 
					
						
							|  |  |  |     const res = await fetchCustomCollection(collection.name) | 
					
						
							|  |  |  |     if (res.credentials.auth_type === AuthType.apiKey && !res.credentials.api_key_header_prefix) { | 
					
						
							|  |  |  |       if (res.credentials.api_key_value) | 
					
						
							|  |  |  |         res.credentials.api_key_header_prefix = AuthHeaderPrefix.custom | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     setCustomCollection({ | 
					
						
							|  |  |  |       ...res, | 
					
						
							|  |  |  |       labels: collection.labels, | 
					
						
							|  |  |  |       provider: collection.name, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setIsDetailLoading(false) | 
					
						
							| 
									
										
										
										
											2024-07-11 11:09:14 +08:00
										 |  |  |   }, [collection.labels, collection.name]) | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   // workflow provider
 | 
					
						
							|  |  |  |   const [isShowEditWorkflowToolModal, setIsShowEditWorkflowToolModal] = useState(false) | 
					
						
							|  |  |  |   const getWorkflowToolProvider = useCallback(async () => { | 
					
						
							|  |  |  |     setIsDetailLoading(true) | 
					
						
							|  |  |  |     const res = await fetchWorkflowToolDetail(collection.id) | 
					
						
							|  |  |  |     const payload = { | 
					
						
							|  |  |  |       ...res, | 
					
						
							|  |  |  |       parameters: res.tool?.parameters.map((item) => { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           name: item.name, | 
					
						
							|  |  |  |           description: item.llm_description, | 
					
						
							|  |  |  |           form: item.form, | 
					
						
							|  |  |  |           required: item.required, | 
					
						
							|  |  |  |           type: item.type, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) || [], | 
					
						
							|  |  |  |       labels: res.tool?.labels || [], | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     setCustomCollection(payload) | 
					
						
							|  |  |  |     setIsDetailLoading(false) | 
					
						
							|  |  |  |   }, [collection.id]) | 
					
						
							|  |  |  |   const removeWorkflowToolProvider = async () => { | 
					
						
							|  |  |  |     await deleteWorkflowTool(collection.id) | 
					
						
							|  |  |  |     onRefreshData() | 
					
						
							|  |  |  |     Toast.notify({ | 
					
						
							|  |  |  |       type: 'success', | 
					
						
							|  |  |  |       message: t('common.api.actionSuccess'), | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setIsShowEditWorkflowToolModal(false) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const updateWorkflowToolProvider = async (data: WorkflowToolProviderRequest & Partial<{ | 
					
						
							|  |  |  |     workflow_app_id: string | 
					
						
							|  |  |  |     workflow_tool_id: string | 
					
						
							|  |  |  |   }>) => { | 
					
						
							|  |  |  |     await saveWorkflowToolProvider(data) | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |     invalidateAllWorkflowTools() | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     onRefreshData() | 
					
						
							|  |  |  |     getWorkflowToolProvider() | 
					
						
							|  |  |  |     Toast.notify({ | 
					
						
							|  |  |  |       type: 'success', | 
					
						
							|  |  |  |       message: t('common.api.actionSuccess'), | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setIsShowEditWorkflowToolModal(false) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-06-26 19:27:22 +08:00
										 |  |  |   const onClickCustomToolDelete = () => { | 
					
						
							|  |  |  |     setDeleteAction('customTool') | 
					
						
							|  |  |  |     setShowConfirmDelete(true) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const onClickWorkflowToolDelete = () => { | 
					
						
							|  |  |  |     setDeleteAction('workflowTool') | 
					
						
							|  |  |  |     setShowConfirmDelete(true) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const handleConfirmDelete = () => { | 
					
						
							|  |  |  |     if (deleteAction === 'customTool') | 
					
						
							|  |  |  |       doRemoveCustomToolCollection() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     else if (deleteAction === 'workflowTool') | 
					
						
							|  |  |  |       removeWorkflowToolProvider() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setShowConfirmDelete(false) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // ToolList
 | 
					
						
							|  |  |  |   const [toolList, setToolList] = useState<Tool[]>([]) | 
					
						
							|  |  |  |   const getProviderToolList = useCallback(async () => { | 
					
						
							|  |  |  |     setIsDetailLoading(true) | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       if (collection.type === CollectionType.builtIn) { | 
					
						
							|  |  |  |         const list = await fetchBuiltInToolList(collection.name) | 
					
						
							|  |  |  |         setToolList(list) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (collection.type === CollectionType.model) { | 
					
						
							|  |  |  |         const list = await fetchModelToolList(collection.name) | 
					
						
							|  |  |  |         setToolList(list) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (collection.type === CollectionType.workflow) { | 
					
						
							|  |  |  |         setToolList([]) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         const list = await fetchCustomToolList(collection.name) | 
					
						
							|  |  |  |         setToolList(list) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     catch (e) { } | 
					
						
							|  |  |  |     setIsDetailLoading(false) | 
					
						
							|  |  |  |   }, [collection.name, collection.type]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (collection.type === CollectionType.custom) | 
					
						
							|  |  |  |       getCustomProvider() | 
					
						
							|  |  |  |     if (collection.type === CollectionType.workflow) | 
					
						
							|  |  |  |       getWorkflowToolProvider() | 
					
						
							|  |  |  |     getProviderToolList() | 
					
						
							|  |  |  |   }, [collection.name, collection.type, getCustomProvider, getProviderToolList, getWorkflowToolProvider]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |     <Drawer | 
					
						
							|  |  |  |       isOpen={!!collection} | 
					
						
							|  |  |  |       clickOutsideNotOpen={false} | 
					
						
							|  |  |  |       onClose={onHide} | 
					
						
							|  |  |  |       footer={null} | 
					
						
							|  |  |  |       mask={false} | 
					
						
							|  |  |  |       positionCenter={false} | 
					
						
							|  |  |  |       panelClassname={cn('justify-start mt-[64px] mr-2 mb-2 !w-[420px] !max-w-[420px] !p-0 !bg-components-panel-bg rounded-2xl border-[0.5px] border-components-panel-border shadow-xl')} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <div className='p-4'> | 
					
						
							|  |  |  |         <div className='mb-3 flex'> | 
					
						
							|  |  |  |           <Icon src={collection.icon} /> | 
					
						
							|  |  |  |           <div className="ml-3 w-0 grow"> | 
					
						
							|  |  |  |             <div className="flex items-center h-5"> | 
					
						
							|  |  |  |               <Title title={collection.label[language]} /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |             <div className='mb-1 flex justify-between items-center h-4'> | 
					
						
							|  |  |  |               <OrgInfo | 
					
						
							|  |  |  |                 className="mt-0.5" | 
					
						
							|  |  |  |                 packageNameClassName='w-auto' | 
					
						
							|  |  |  |                 orgName={collection.author} | 
					
						
							|  |  |  |                 packageName={collection.name} | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <div className='flex gap-1'> | 
					
						
							|  |  |  |             <ActionButton onClick={onHide}> | 
					
						
							|  |  |  |               <RiCloseLine className='w-4 h-4' /> | 
					
						
							|  |  |  |             </ActionButton> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |         {!!collection.description[language] && ( | 
					
						
							|  |  |  |           <Description text={collection.description[language]} descriptionLineRows={2}></Description> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |         )} | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |         <div className='flex gap-1 border-b-[0.5px] border-divider-subtle'> | 
					
						
							|  |  |  |           {collection.type === CollectionType.custom && !isDetailLoading && ( | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |             <Button | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |               className={cn('shrink-0 my-3 w-full')} | 
					
						
							|  |  |  |               onClick={() => setIsShowEditCustomCollectionModal(true)} | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |             > | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |               <Settings01 className='mr-1 w-4 h-4 text-text-tertiary' /> | 
					
						
							|  |  |  |               <div className='system-sm-medium text-text-secondary'>{t('tools.createTool.editAction')}</div> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |             </Button> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |           )} | 
					
						
							|  |  |  |           {collection.type === CollectionType.workflow && !isDetailLoading && customCollection && ( | 
					
						
							|  |  |  |             <> | 
					
						
							|  |  |  |               <Button | 
					
						
							|  |  |  |                 variant='primary' | 
					
						
							|  |  |  |                 className={cn('shrink-0 my-3 w-[183px]')} | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 <a className='flex items-center text-text-primary' href={`/app/${(customCollection as WorkflowToolProviderResponse).workflow_app_id}/workflow`} rel='noreferrer' target='_blank'> | 
					
						
							|  |  |  |                   <div className='system-sm-medium'>{t('tools.openInStudio')}</div> | 
					
						
							|  |  |  |                   <LinkExternal02 className='ml-1 w-4 h-4' /> | 
					
						
							|  |  |  |                 </a> | 
					
						
							|  |  |  |               </Button> | 
					
						
							|  |  |  |               <Button | 
					
						
							|  |  |  |                 className={cn('shrink-0 my-3 w-[183px]')} | 
					
						
							|  |  |  |                 onClick={() => setIsShowEditWorkflowToolModal(true)} | 
					
						
							|  |  |  |                 disabled={!isCurrentWorkspaceManager} | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 <div className='system-sm-medium text-text-secondary'>{t('tools.createTool.editAction')}</div> | 
					
						
							|  |  |  |               </Button> | 
					
						
							|  |  |  |             </> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         {/* Tools */} | 
					
						
							|  |  |  |         <div className='pt-3'> | 
					
						
							|  |  |  |           {isDetailLoading && <div className='flex h-[200px]'><Loading type='app' /></div>} | 
					
						
							|  |  |  |           {/* Builtin type */} | 
					
						
							|  |  |  |           {!isDetailLoading && (collection.type === CollectionType.builtIn) && isAuthed && ( | 
					
						
							|  |  |  |             <div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'> | 
					
						
							|  |  |  |               {t('plugin.detailPanel.actionNum', { num: toolList.length, action: toolList.length > 1 ? 'actions' : 'action' })} | 
					
						
							|  |  |  |               {needAuth && ( | 
					
						
							|  |  |  |                 <Button | 
					
						
							|  |  |  |                   variant='secondary' | 
					
						
							|  |  |  |                   size='small' | 
					
						
							|  |  |  |                   onClick={() => { | 
					
						
							|  |  |  |                     if (collection.type === CollectionType.builtIn || collection.type === CollectionType.model) | 
					
						
							|  |  |  |                       showSettingAuthModal() | 
					
						
							|  |  |  |                   }} | 
					
						
							|  |  |  |                   disabled={!isCurrentWorkspaceManager} | 
					
						
							|  |  |  |                 > | 
					
						
							|  |  |  |                   <Indicator className='mr-2' color={'green'} /> | 
					
						
							|  |  |  |                   {t('tools.auth.authorized')} | 
					
						
							|  |  |  |                 </Button> | 
					
						
							|  |  |  |               )} | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |           {!isDetailLoading && (collection.type === CollectionType.builtIn) && needAuth && !isAuthed && ( | 
					
						
							|  |  |  |             <> | 
					
						
							|  |  |  |               <div className='text-text-secondary system-sm-semibold-uppercase'> | 
					
						
							|  |  |  |                 <span className=''>{t('tools.includeToolNum', { num: toolList.length, action: toolList.length > 1 ? 'actions' : 'action' }).toLocaleUpperCase()}</span> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |                 <span className='px-1'>·</span> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |                 <span className='text-util-colors-orange-orange-600'>{t('tools.auth.setup').toLocaleUpperCase()}</span> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |               <Button | 
					
						
							|  |  |  |                 variant='primary' | 
					
						
							|  |  |  |                 className={cn('shrink-0 my-3 w-full')} | 
					
						
							|  |  |  |                 onClick={() => { | 
					
						
							|  |  |  |                   if (collection.type === CollectionType.builtIn || collection.type === CollectionType.model) | 
					
						
							|  |  |  |                     showSettingAuthModal() | 
					
						
							|  |  |  |                 }} | 
					
						
							|  |  |  |                 disabled={!isCurrentWorkspaceManager} | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 {t('tools.auth.unauthorized')} | 
					
						
							|  |  |  |               </Button> | 
					
						
							|  |  |  |             </> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |           {/* Custom type */} | 
					
						
							|  |  |  |           {!isDetailLoading && (collection.type === CollectionType.custom) && ( | 
					
						
							|  |  |  |             <div className='text-text-secondary system-sm-semibold-uppercase'> | 
					
						
							|  |  |  |               <span className=''>{t('tools.includeToolNum', { num: toolList.length }).toLocaleUpperCase()}</span> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |           {/* Workflow type */} | 
					
						
							|  |  |  |           {!isDetailLoading && (collection.type === CollectionType.workflow) && ( | 
					
						
							|  |  |  |             <div className='text-text-secondary system-sm-semibold-uppercase'> | 
					
						
							|  |  |  |               <span className=''>{t('tools.createTool.toolInput.title').toLocaleUpperCase()}</span> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |           {!isDetailLoading && ( | 
					
						
							|  |  |  |             <div className='mt-1 py-2'> | 
					
						
							|  |  |  |               {collection.type !== CollectionType.workflow && toolList.map(tool => ( | 
					
						
							|  |  |  |                 <ToolItem | 
					
						
							|  |  |  |                   key={tool.name} | 
					
						
							|  |  |  |                   disabled={false} | 
					
						
							|  |  |  |                   // disabled={needAuth && (isBuiltIn || isModel) && !isAuthed}
 | 
					
						
							|  |  |  |                   collection={collection} | 
					
						
							|  |  |  |                   tool={tool} | 
					
						
							|  |  |  |                   isBuiltIn={isBuiltIn} | 
					
						
							|  |  |  |                   isModel={isModel} | 
					
						
							|  |  |  |                 /> | 
					
						
							|  |  |  |               ))} | 
					
						
							|  |  |  |               {collection.type === CollectionType.workflow && (customCollection as WorkflowToolProviderResponse)?.tool?.parameters.map(item => ( | 
					
						
							|  |  |  |                 <div key={item.name} className='mb-1 py-1'> | 
					
						
							|  |  |  |                   <div className='mb-1 flex items-center gap-2'> | 
					
						
							|  |  |  |                     <span className='text-text-secondary code-sm-semibold'>{item.name}</span> | 
					
						
							|  |  |  |                     <span className='text-text-tertiary system-xs-regular'>{item.type}</span> | 
					
						
							|  |  |  |                     <span className='text-text-warning-secondary system-xs-medium'>{item.required ? t('tools.createTool.toolInput.required') : ''}</span> | 
					
						
							|  |  |  |                   </div> | 
					
						
							|  |  |  |                   <div className='text-text-tertiary system-xs-regular'>{item.llm_description}</div> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |               ))} | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         {showSettingAuth && ( | 
					
						
							|  |  |  |           <ConfigCredential | 
					
						
							|  |  |  |             collection={collection} | 
					
						
							|  |  |  |             onCancel={() => setShowSettingAuth(false)} | 
					
						
							|  |  |  |             onSaved={async (value) => { | 
					
						
							|  |  |  |               await updateBuiltInToolCredential(collection.name, value) | 
					
						
							|  |  |  |               Toast.notify({ | 
					
						
							|  |  |  |                 type: 'success', | 
					
						
							|  |  |  |                 message: t('common.api.actionSuccess'), | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               await onRefreshData() | 
					
						
							|  |  |  |               setShowSettingAuth(false) | 
					
						
							|  |  |  |             }} | 
					
						
							|  |  |  |             onRemove={async () => { | 
					
						
							|  |  |  |               await removeBuiltInToolCredential(collection.name) | 
					
						
							|  |  |  |               Toast.notify({ | 
					
						
							|  |  |  |                 type: 'success', | 
					
						
							|  |  |  |                 message: t('common.api.actionSuccess'), | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               await onRefreshData() | 
					
						
							|  |  |  |               setShowSettingAuth(false) | 
					
						
							|  |  |  |             }} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							|  |  |  |         {isShowEditCollectionToolModal && ( | 
					
						
							|  |  |  |           <EditCustomToolModal | 
					
						
							|  |  |  |             payload={customCollection} | 
					
						
							|  |  |  |             onHide={() => setIsShowEditCustomCollectionModal(false)} | 
					
						
							|  |  |  |             onEdit={doUpdateCustomToolCollection} | 
					
						
							|  |  |  |             onRemove={onClickCustomToolDelete} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							|  |  |  |         {isShowEditWorkflowToolModal && ( | 
					
						
							|  |  |  |           <WorkflowToolModal | 
					
						
							|  |  |  |             payload={customCollection} | 
					
						
							|  |  |  |             onHide={() => setIsShowEditWorkflowToolModal(false)} | 
					
						
							|  |  |  |             onRemove={onClickWorkflowToolDelete} | 
					
						
							|  |  |  |             onSave={updateWorkflowToolProvider} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							|  |  |  |         {showConfirmDelete && ( | 
					
						
							|  |  |  |           <Confirm | 
					
						
							|  |  |  |             title={t('tools.createTool.deleteToolConfirmTitle')} | 
					
						
							|  |  |  |             content={t('tools.createTool.deleteToolConfirmContent')} | 
					
						
							|  |  |  |             isShow={showConfirmDelete} | 
					
						
							|  |  |  |             onConfirm={handleConfirmDelete} | 
					
						
							|  |  |  |             onCancel={() => setShowConfirmDelete(false)} | 
					
						
							|  |  |  |           /> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |         )} | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |     </Drawer> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default ProviderDetail |