"use client" import { ArrowUpRightIcon, GlobeIcon } from "lucide-react" import { type ChatMessagePart, type SourceUrlPart } from "@/tools" import { safeHttpUrl } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer" import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle, } from "@/components/ui/item" function getUniqueSources(parts: ChatMessagePart[]): SourceUrlPart[] { return parts .filter((part): part is SourceUrlPart => part.type === "source-url") .filter((source) => safeHttpUrl(source.url)) .filter( (source, index, all) => all.findIndex((other) => other.url === source.url) === index ) } function getHostname(url: string) { try { return new URL(url).hostname } catch { return url } } export function SourcesPart({ parts }: { parts: ChatMessagePart[] }) { const sources = getUniqueSources(parts) if (sources.length === 0) { return null } const count = sources.length const label = `Searched ${count} ${count === 1 ? "website" : "websites"}` return (