2024-01-23 19:31:56 +08:00
|
|
|
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import React, { useState } from 'react'
|
|
|
|
import { useContext } from 'use-context-selector'
|
|
|
|
import cn from 'classnames'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import type { Collection, Tool } from '../types'
|
|
|
|
import Button from '../../base/button'
|
|
|
|
import { CollectionType } from '../types'
|
|
|
|
import TooltipPlus from '../../base/tooltip-plus'
|
|
|
|
import I18n from '@/context/i18n'
|
|
|
|
import SettingBuiltInTool from '@/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool'
|
2024-02-23 14:31:06 +08:00
|
|
|
import { getLanguage } from '@/i18n/language'
|
2024-01-23 19:31:56 +08:00
|
|
|
type Props = {
|
|
|
|
collection: Collection
|
|
|
|
icon: JSX.Element
|
|
|
|
payload: Tool
|
|
|
|
isInToolsPage: boolean
|
|
|
|
isToolNumMax: boolean
|
|
|
|
added?: boolean
|
|
|
|
onAdd?: (payload: Tool) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const Item: FC<Props> = ({
|
|
|
|
collection,
|
|
|
|
icon,
|
|
|
|
payload,
|
|
|
|
isInToolsPage,
|
|
|
|
isToolNumMax,
|
|
|
|
added,
|
|
|
|
onAdd,
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { locale } = useContext(I18n)
|
2024-02-23 14:31:06 +08:00
|
|
|
const language = getLanguage(locale)
|
|
|
|
|
2024-01-23 19:31:56 +08:00
|
|
|
const isBuiltIn = collection.type === CollectionType.builtIn
|
2024-03-08 15:22:55 +08:00
|
|
|
const isModel = collection.type === CollectionType.model
|
2024-03-01 18:47:12 +08:00
|
|
|
const canShowDetail = isInToolsPage
|
2024-01-23 19:31:56 +08:00
|
|
|
const [showDetail, setShowDetail] = useState(false)
|
|
|
|
const addBtn = <Button className='shrink-0 flex items-center h-7 !px-3 !text-xs !font-medium !text-gray-700' disabled={added || !collection.is_team_authorization} onClick={() => onAdd?.(payload)}>{t(`common.operation.${added ? 'added' : 'add'}`)}</Button>
|
2024-03-01 18:47:12 +08:00
|
|
|
|
2024-01-23 19:31:56 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
className={cn(canShowDetail && 'cursor-pointer', 'flex justify-between items-start p-4 rounded-xl border border-gray-200 bg-gray-50 shadow-xs')}
|
|
|
|
onClick={() => canShowDetail && setShowDetail(true)}
|
|
|
|
>
|
|
|
|
<div className='flex items-start w-full'>
|
|
|
|
{icon}
|
|
|
|
<div className='ml-3 w-0 grow'>
|
2024-01-24 11:08:11 +08:00
|
|
|
<div className={cn('text-base font-semibold text-gray-900 truncate')}>{payload.label[language]}</div>
|
2024-01-23 19:31:56 +08:00
|
|
|
<div className={cn('leading-[18px] text-[13px] font-normal text-gray-500')}>
|
2024-01-24 11:08:11 +08:00
|
|
|
{payload.description[language]}
|
2024-01-23 19:31:56 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className='shrink-0'>
|
|
|
|
{!isToolNumMax && onAdd && (
|
|
|
|
!collection.is_team_authorization
|
|
|
|
? <TooltipPlus popupContent={t('tools.auth.unauthorized')}>
|
|
|
|
{addBtn}
|
|
|
|
</TooltipPlus>
|
|
|
|
: addBtn
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-03-01 17:58:38 +08:00
|
|
|
{showDetail && (
|
2024-01-23 19:31:56 +08:00
|
|
|
<SettingBuiltInTool
|
|
|
|
collection={collection}
|
|
|
|
toolName={payload.name}
|
|
|
|
readonly
|
|
|
|
onHide={() => {
|
|
|
|
setShowDetail(false)
|
|
|
|
}}
|
2024-03-01 17:58:38 +08:00
|
|
|
isBuiltIn={isBuiltIn}
|
2024-03-08 15:22:55 +08:00
|
|
|
isModel={isModel}
|
2024-01-23 19:31:56 +08:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(Item)
|