({ agentId })
| 773 | // --- Image Memory Preview Component --- |
| 774 | |
| 775 | const ImageMemoryPreview: React.FC<{ agentId: string }> = ({ agentId }) => { |
| 776 | const [images, setImages] = useState<string[]>([]); |
| 777 | const [isLoading, setIsLoading] = useState(true); |
| 778 | |
| 779 | // Load initial image memory |
| 780 | useEffect(() => { |
| 781 | const loadImages = async () => { |
| 782 | try { |
| 783 | const imageData = await getAgentImageMemory(agentId); |
| 784 | setImages(imageData || []); |
| 785 | } catch (error) { |
| 786 | console.error('Failed to load image memory:', error); |
| 787 | setImages([]); |
| 788 | } finally { |
| 789 | setIsLoading(false); |
| 790 | } |
| 791 | }; |
| 792 | loadImages(); |
| 793 | }, [agentId]); |
| 794 | |
| 795 | // Listen for memory updates via custom events |
| 796 | useEffect(() => { |
| 797 | const handleMemoryUpdate = async (event: CustomEvent) => { |
| 798 | if (event.detail.agentId === agentId) { |
| 799 | try { |
| 800 | const imageData = await getAgentImageMemory(agentId); |
| 801 | setImages(imageData || []); |
| 802 | } catch (error) { |
| 803 | console.error('Failed to reload image memory:', error); |
| 804 | } |
| 805 | } |
| 806 | }; |
| 807 | |
| 808 | window.addEventListener('agent-memory-update', handleMemoryUpdate as any); |
| 809 | return () => { |
| 810 | window.removeEventListener('agent-memory-update', handleMemoryUpdate as any); |
| 811 | }; |
| 812 | }, [agentId]); |
| 813 | |
| 814 | if (isLoading) { |
| 815 | return ( |
| 816 | <div className="flex items-center gap-2 bg-purple-50 px-3 py-2 rounded-lg border border-purple-200 flex-1 min-w-0"> |
| 817 | <Images className="w-4 h-4 text-purple-600 flex-shrink-0" /> |
| 818 | <span className="text-purple-700 text-sm italic">Loading image memory...</span> |
| 819 | </div> |
| 820 | ); |
| 821 | } |
| 822 | |
| 823 | if (images.length === 0) { |
| 824 | return ( |
| 825 | <div className="flex items-center gap-2 bg-purple-50 px-3 py-2 rounded-lg border border-purple-200 flex-1 min-w-0"> |
| 826 | <Images className="w-4 h-4 text-purple-600 flex-shrink-0" /> |
| 827 | <span className="text-purple-700 text-sm italic">No image memory yet</span> |
| 828 | </div> |
| 829 | ); |
| 830 | } |
| 831 | |
| 832 | const imagesToShow = images.slice(-3); // Show last 3 images |
nothing calls this directly
no test coverage detected