import { Search } from "lucide-preact"; import type { SearchDetail, SearchResultItem } from "@/lib/api"; function summarizeResult(result: SearchResultItem) { const highlights = Array.isArray(result.highlights) ? result.highlights.filter(Boolean) : []; if (highlights.length) return highlights.join(" ").slice(0, 420); return (result.text ?? "").slice(0, 420); } function formatHost(url: string) { try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return url; } } type Props = { search: SearchDetail | null; isLoading: boolean; isRunning: boolean; showPrompt?: boolean; className?: string; }; export function SearchResultsPanel({ search, isLoading, isRunning, showPrompt = true, className }: Props) { return (
{search?.query ? (

Results for

{search.query}

{search.results.length} result{search.results.length === 1 ? "" : "s"} {search.latencyMs ? ` • ${search.latencyMs} ms` : ""}

) : null} {(isRunning || !!search?.answerText || !!search?.answerError) && (

Answer

{isRunning && !search?.answerText ?

Generating answer...

: null} {search?.answerText ?

{search.answerText}

: null} {search?.answerError ?

{search.answerError}

: null} {!!search?.answerCitations?.length && (
{search.answerCitations.slice(0, 6).map((citation, index) => { const href = citation.url || citation.id || ""; if (!href) return null; return ( {citation.title?.trim() || formatHost(href)} ); })}
)}
)} {(isLoading || isRunning) && !search?.results.length ? (

{isRunning ? "Searching Exa..." : "Loading search..."}

) : null} {showPrompt && !isLoading && !search?.query ? (

Search the web

Use the composer below to run a new Exa search.

) : null} {!isLoading && !isRunning && !!search?.query && search.results.length === 0 ? (

No results found.

) : null}
{search?.results.map((result) => { const summary = summarizeResult(result); return (

{formatHost(result.url)}

{result.title || result.url} {(result.publishedDate || result.author) && (

{[result.publishedDate, result.author].filter(Boolean).join(" • ")}

)} {summary ?

{summary}

: null}
); })}
{search?.error ?

{search.error}

: null}
); }