agent-content.tsx 1.5 KB

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