tool-detail.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import {
  4. RiArrowDownSLine,
  5. RiArrowRightSLine,
  6. RiHammerFill,
  7. RiLoader2Line,
  8. } from '@remixicon/react'
  9. import type { ToolInfoInThought } from '../type'
  10. import cn from '@/utils/classnames'
  11. type ToolDetailProps = {
  12. payload: ToolInfoInThought
  13. }
  14. const ToolDetail = ({
  15. payload,
  16. }: ToolDetailProps) => {
  17. const { t } = useTranslation()
  18. const { name, label, input, isFinished, output } = payload
  19. const toolLabel = name.startsWith('dataset_') ? t('dataset.knowledge') : label
  20. const [expand, setExpand] = useState(false)
  21. return (
  22. <div
  23. className={cn(
  24. 'rounded-xl',
  25. !expand && 'border-l-[0.25px] border-components-panel-border bg-workflow-process-bg',
  26. expand && 'border-[0.5px] border-components-panel-border-subtle bg-background-section-burn',
  27. )}
  28. >
  29. <div
  30. className={cn(
  31. 'flex items-center system-xs-medium text-text-tertiary px-2.5 py-2 cursor-pointer',
  32. expand && 'pb-1.5',
  33. )}
  34. onClick={() => setExpand(!expand)}
  35. >
  36. {isFinished && <RiHammerFill className='mr-1 w-3.5 h-3.5' />}
  37. {!isFinished && <RiLoader2Line className='mr-1 w-3.5 h-3.5 animate-spin' />}
  38. {t(`tools.thought.${isFinished ? 'used' : 'using'}`)}
  39. <div className='mx-1 text-text-secondary'>{toolLabel}</div>
  40. {!expand && <RiArrowRightSLine className='w-4 h-4' />}
  41. {expand && <RiArrowDownSLine className='ml-auto w-4 h-4' />}
  42. </div>
  43. {
  44. expand && (
  45. <>
  46. <div className='mb-0.5 mx-1 rounded-[10px] bg-components-panel-on-panel-item-bg text-text-secondary'>
  47. <div className='flex items-center justify-between px-2 pt-1 h-7 system-xs-semibold-uppercase'>
  48. {t('tools.thought.requestTitle')}
  49. </div>
  50. <div className='pt-1 px-3 pb-2 code-xs-regular break-words'>
  51. {input}
  52. </div>
  53. </div>
  54. <div className='mx-1 mb-1 rounded-[10px] bg-components-panel-on-panel-item-bg text-text-secondary'>
  55. <div className='flex items-center justify-between px-2 pt-1 h-7 system-xs-semibold-uppercase'>
  56. {t('tools.thought.responseTitle')}
  57. </div>
  58. <div className='pt-1 px-3 pb-2 code-xs-regular break-words'>
  59. {output}
  60. </div>
  61. </div>
  62. </>
  63. )
  64. }
  65. </div>
  66. )
  67. }
  68. export default ToolDetail