tool-item.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 bg-components-panel-item-bg rounded-xl border-[0.5px] border-components-panel-border-subtle shadow-xs cursor-pointer hover:bg-components-panel-on-panel-item-bg-hover', disabled && 'opacity-50 !cursor-not-allowed')}
  30. onClick={() => !disabled && setShowDetail(true)}
  31. >
  32. <div className='pb-0.5 text-text-secondary system-md-semibold'>{tool.label[language]}</div>
  33. <div className='text-text-tertiary system-xs-regular line-clamp-2' title={tool.description[language]}>{tool.description[language]}</div>
  34. </div>
  35. {showDetail && (
  36. <SettingBuiltInTool
  37. showBackButton
  38. collection={collection}
  39. toolName={tool.name}
  40. readonly
  41. onHide={() => {
  42. setShowDetail(false)
  43. }}
  44. isBuiltIn={isBuiltIn}
  45. isModel={isModel}
  46. />
  47. )}
  48. </>
  49. )
  50. }
  51. export default ToolItem