You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import type { ChatItem } from '../../types'
  4. import { useChatContext } from '../context'
  5. import { useCurrentAnswerIsResponsing } from '../hooks'
  6. import Operation from './operation'
  7. import AgentContent from './agent-content'
  8. import BasicContent from './basic-content'
  9. import SuggestedQuestions from './suggested-questions'
  10. import More from './more'
  11. import { AnswerTriangle } from '@/app/components/base/icons/src/vender/solid/general'
  12. import LoadingAnim from '@/app/components/app/chat/loading-anim'
  13. import Citation from '@/app/components/app/chat/citation'
  14. import { EditTitle } from '@/app/components/app/annotation/edit-annotation-modal/edit-item'
  15. type AnswerProps = {
  16. item: ChatItem
  17. question: string
  18. index: number
  19. }
  20. const Answer: FC<AnswerProps> = ({
  21. item,
  22. question,
  23. index,
  24. }) => {
  25. const { t } = useTranslation()
  26. const {
  27. config,
  28. answerIcon,
  29. } = useChatContext()
  30. const responsing = useCurrentAnswerIsResponsing(item.id)
  31. const {
  32. content,
  33. citation,
  34. agent_thoughts,
  35. more,
  36. annotation,
  37. } = item
  38. const hasAgentThoughts = !!agent_thoughts?.length
  39. return (
  40. <div className='flex mb-2 last:mb-0'>
  41. <div className='shrink-0 relative w-10 h-10'>
  42. {
  43. answerIcon || (
  44. <div className='flex items-center justify-center w-full h-full rounded-full bg-[#d5f5f6] border-[0.5px] border-black/5 text-xl'>
  45. 🤖
  46. </div>
  47. )
  48. }
  49. {
  50. responsing && (
  51. <div className='absolute -top-[3px] -left-[3px] pl-[6px] flex items-center w-4 h-4 bg-white rounded-full shadow-xs border-[0.5px] border-gray-50'>
  52. <LoadingAnim type='avatar' />
  53. </div>
  54. )
  55. }
  56. </div>
  57. <div className='chat-answer-container grow w-0 group ml-4'>
  58. <div className='relative pr-10'>
  59. <AnswerTriangle className='absolute -left-2 top-0 w-2 h-3 text-gray-100' />
  60. <div className='group relative inline-block px-4 py-3 max-w-full bg-gray-100 rounded-b-2xl rounded-tr-2xl text-sm text-gray-900'>
  61. {
  62. !responsing && (
  63. <Operation
  64. item={item}
  65. question={question}
  66. index={index}
  67. />
  68. )
  69. }
  70. {
  71. responsing && !content && !hasAgentThoughts && (
  72. <div className='flex items-center justify-center w-6 h-5'>
  73. <LoadingAnim type='text' />
  74. </div>
  75. )
  76. }
  77. {
  78. content && !hasAgentThoughts && (
  79. <BasicContent item={item} />
  80. )
  81. }
  82. {
  83. hasAgentThoughts && (
  84. <AgentContent item={item} />
  85. )
  86. }
  87. {
  88. annotation?.id && annotation.authorName && (
  89. <EditTitle
  90. className='mt-1'
  91. title={t('appAnnotation.editBy', { author: annotation.authorName })}
  92. />
  93. )
  94. }
  95. <SuggestedQuestions item={item} />
  96. {
  97. !!citation?.length && config?.retriever_resource?.enabled && !responsing && (
  98. <Citation data={citation} showHitInfo={config.supportCitationHitInfo} />
  99. )
  100. }
  101. </div>
  102. </div>
  103. <More more={more} />
  104. </div>
  105. </div>
  106. )
  107. }
  108. export default Answer