"use client" import { useChat, useCompletion, type UIMessage } from "@ai-sdk/react" import { cn } from "@lib/utils" import { Button } from "@ui/components/button" import { DefaultChatTransport } from "ai" import { ArrowUp, Check, ChevronDown, ChevronRight, Copy, RotateCcw, X, } from "lucide-react" import { useCallback, useEffect, useRef, useState } from "react" import { toast } from "sonner" import { Streamdown } from "streamdown" import { TextShimmer } from "@/components/text-shimmer" import { usePersistentChat, useProject } from "@/stores" import { useGraphHighlights } from "@/stores/highlights" import { modelNames, ModelIcon } from "@/lib/models" import { Spinner } from "../../spinner" import { areUIMessageArraysEqual } from "@/stores/chat" interface MemoryResult { documentId?: string title?: string content?: string url?: string score?: number } interface ExpandableMemoriesProps { foundCount: number results: MemoryResult[] } interface MessagePart { type: string state?: string text?: string output?: { count?: number results?: Array<{ documentId?: string title?: string content?: string url?: string score?: number }> } } interface ChatMessage { id: string role: "user" | "assistant" parts: MessagePart[] } function ExpandableMemories({ foundCount, results }: ExpandableMemoriesProps) { const [isExpanded, setIsExpanded] = useState(false) if (foundCount === 0) { return (