tool-item.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use client'
  2. import React, { useState } from 'react'
  3. import { useContext } from 'use-context-selector'
  4. import type { Collection, Tool } from '../types'
  5. import cn from '@/utils/classnames'
  6. import I18n from '@/context/i18n'
  7. import { getLanguage } from '@/i18n/language'
  8. import SettingBuiltInTool from '@/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool'
  9. type Props = {
  10. disabled?: boolean
  11. collection: Collection
  12. tool: Tool
  13. isBuiltIn: boolean
  14. isModel: boolean
  15. }
  16. const ToolItem = ({
  17. disabled,
  18. collection,
  19. tool,
  20. isBuiltIn,
  21. isModel,
  22. }: Props) => {
  23. const { locale } = useContext(I18n)
  24. const language = getLanguage(locale)
  25. const [showDetail, setShowDetail] = useState(false)
  26. return (
  27. <>
  28. <div
  29. className={cn('mb-2 px-4 py-3 rounded-xl bg-gray-25 border-[0.5px] border-gary-200 shadow-xs cursor-pointer', disabled && 'opacity-50 !cursor-not-allowed')}
  30. onClick={() => !disabled && setShowDetail(true)}
  31. >
  32. <div className='text-gray-800 font-semibold text-sm leading-5'>{tool.label[language]}</div>
  33. <div className='mt-0.5 text-xs leading-[18px] text-gray-500 line-clamp-2' title={tool.description[language]}>{tool.description[language]}</div>
  34. </div>
  35. {showDetail && (
  36. <SettingBuiltInTool
  37. collection={collection}
  38. toolName={tool.name}
  39. readonly
  40. onHide={() => {
  41. setShowDetail(false)
  42. }}
  43. isBuiltIn={isBuiltIn}
  44. isModel={isModel}
  45. />
  46. )}
  47. </>
  48. )
  49. }
  50. export default ToolItem