"use client"; import { useSetAtom } from "jotai"; import { FileText } from "lucide-react"; import type { FC } from "react"; import { useState } from "react"; import { openCitationPanelAtom } from "@/atoms/citation/citation-panel.atom"; import { useCitationMetadata } from "@/components/assistant-ui/citation-metadata-context"; import { CitationPanelContent } from "@/components/citation-panel/citation-panel"; import { Citation } from "@/components/tool-ui/citation"; import { Button } from "@/components/ui/button"; import { Drawer, DrawerContent, DrawerHandle, DrawerHeader, DrawerTitle, } from "@/components/ui/drawer"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { useMediaQuery } from "@/hooks/use-media-query"; interface InlineCitationProps { chunkId: number; isDocsChunk?: boolean; } /** * Inline citation badge for knowledge-base chunks (numeric chunk IDs). * * Numeric KB chunks: clicking opens the citation panel in the right * sidebar (alongside the chat — does not replace it). The panel shows * the cited chunk surrounded by adjacent chunks (via the API's * `chunk_window`), with the cited one highlighted and an option to * expand the window or jump into the full document via the editor panel. * * Negative chunk IDs and legacy SurfSense-docs chunks (`isDocsChunk`) render * as a static, non-interactive "doc" pill. The SurfSense product-docs feature * was removed, so those markers are inert (no fetch, no preview) — they only * survive in old persisted messages. */ export const InlineCitation: FC = ({ chunkId, isDocsChunk = false }) => { if (chunkId < 0 || isDocsChunk) { return ( doc {isDocsChunk ? "Documentation reference" : "Uploaded document"} ); } return ; }; const NumericChunkCitation: FC<{ chunkId: number }> = ({ chunkId }) => { const isTouchLike = useMediaQuery("(hover: none), (pointer: coarse)"); const openCitationPanel = useSetAtom(openCitationPanelAtom); const [mobilePreviewOpen, setMobilePreviewOpen] = useState(false); const handleClick = () => { if (isTouchLike) { setMobilePreviewOpen(true); return; } openCitationPanel({ chunkId }); }; return ( <> Citation
); }; import { tryGetHostname } from "@/lib/url"; interface UrlCitationProps { url: string; } /** * Inline citation for live web search results (URL-based chunk IDs). * Renders a compact chip with favicon + domain and a hover popover showing the * page title and snippet (extracted deterministically from web_search tool results). */ export const UrlCitation: FC = ({ url }) => { const domain = tryGetHostname(url) ?? url; const meta = useCitationMetadata(url); return ( ); };