import ReactMarkdown from "react-markdown"; import { Microscope, User } from "lucide-react"; import { cn } from "@/lib/utils"; import type { Source } from "@/lib/api"; export interface Message { id: string; role: "user" | "assistant"; content: string; sources?: Source[]; streaming?: boolean; } /** Turn `[3]` reference markers into markdown links (#cite-3) so we can render * them as interactive citation chips via the `a` component override. */ function withCitationLinks(text: string): string { return text.replace(/\[(\d+)\]/g, "[$1](#cite-$1)"); } export function MessageBubble({ message, onCitation, children, }: { message: Message; onCitation?: (index: number) => void; children?: React.ReactNode; }) { const isUser = message.role === "user"; return (
{isUser ? : }
{isUser ? ( {message.content} ) : (
{ const m = href?.match(/^#cite-(\d+)$/); if (m) { const idx = Number(m[1]); return ( ); } return ( {c} ); }, }} > {withCitationLinks(message.content) || "​"} {message.streaming && ( )}
)}
{children}
); }