agent-content.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import type {
  4. ChatItem,
  5. VisionFile,
  6. } from '../../types'
  7. import { Markdown } from '@/app/components/base/markdown'
  8. import Thought from '@/app/components/base/chat/chat/thought'
  9. import ImageGallery from '@/app/components/base/image-gallery'
  10. import type { Emoji } from '@/app/components/tools/types'
  11. type AgentContentProps = {
  12. item: ChatItem
  13. responding?: boolean
  14. allToolIcons?: Record<string, string | Emoji>
  15. }
  16. const AgentContent: FC<AgentContentProps> = ({
  17. item,
  18. responding,
  19. allToolIcons,
  20. }) => {
  21. const {
  22. annotation,
  23. agent_thoughts,
  24. } = item
  25. const getImgs = (list?: VisionFile[]) => {
  26. if (!list)
  27. return []
  28. return list.filter(file => file.type === 'image' && file.belongs_to === 'assistant')
  29. }
  30. if (annotation?.logAnnotation)
  31. return <Markdown content={annotation?.logAnnotation.content || ''} />
  32. return (
  33. <div>
  34. {agent_thoughts?.map((thought, index) => (
  35. <div key={index}>
  36. {thought.thought && (
  37. <Markdown content={thought.thought} />
  38. )}
  39. {/* {item.tool} */}
  40. {/* perhaps not use tool */}
  41. {!!thought.tool && (
  42. <Thought
  43. thought={thought}
  44. allToolIcons={allToolIcons || {}}
  45. isFinished={!!thought.observation || !responding}
  46. />
  47. )}
  48. {getImgs(thought.message_files).length > 0 && (
  49. <ImageGallery srcs={getImgs(thought.message_files).map(file => file.url)} />
  50. )}
  51. </div>
  52. ))}
  53. </div>
  54. )
  55. }
  56. export default memo(AgentContent)