agent-content.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 {
  17. allToolIcons,
  18. isResponsing,
  19. } = useChatContext()
  20. const {
  21. annotation,
  22. agent_thoughts,
  23. } = item
  24. const getImgs = (list?: VisionFile[]) => {
  25. if (!list)
  26. return []
  27. return list.filter(file => file.type === 'image' && file.belongs_to === 'assistant')
  28. }
  29. if (annotation?.logAnnotation)
  30. return <Markdown content={annotation?.logAnnotation.content || ''} />
  31. return (
  32. <div>
  33. {agent_thoughts?.map((thought, index) => (
  34. <div key={index}>
  35. {thought.thought && (
  36. <Markdown content={thought.thought} />
  37. )}
  38. {/* {item.tool} */}
  39. {/* perhaps not use tool */}
  40. {!!thought.tool && (
  41. <Thought
  42. thought={thought}
  43. allToolIcons={allToolIcons || {}}
  44. isFinished={!!thought.observation || !isResponsing}
  45. />
  46. )}
  47. {getImgs(thought.message_files).length > 0 && (
  48. <ImageGallery srcs={getImgs(thought.message_files).map(file => file.url)} />
  49. )}
  50. </div>
  51. ))}
  52. </div>
  53. )
  54. }
  55. export default AgentContent