"use client"; import { Card, CardContent } from "@/components/ui/card"; import { KBSearchResult } from "@/types"; import { KBIndexTypeBadge } from "./kb-index-type-badge"; import { HelpTip } from "@/components/ui/help-tip"; import { ExternalLink, FileCode, Hash } from "lucide-react"; interface KBResultCardProps { result: KBSearchResult; onClick?: () => void; } export function KBResultCard({ result, onClick }: KBResultCardProps) { // Truncate content for display (snippet) const snippet = result.content.length > 300 ? result.content.substring(0, 300) + "..." : result.content; // Format source for display const formatSource = (source: string) => { // Remove common prefixes if (source.startsWith("journal:")) { return source.replace("journal:", "Journal: "); } // Shorten file paths if (source.includes("/")) { const parts = source.split("/"); if (parts.length > 3) { return ".../" + parts.slice(-2).join("/"); } } return source; }; // Score as percentage const scorePercent = Math.round(result.score * 100); return (
{/* Header */}
{scorePercent}% match
{/* Source */}
{formatSource(result.source)}
{/* Content snippet */}

{snippet}

{/* Metadata */} {result.metadata && Object.keys(result.metadata).length > 0 && (
{typeof result.metadata.language === "string" && ( {result.metadata.language} )} {typeof result.metadata.agent === "string" && ( @{result.metadata.agent} )} {typeof result.metadata.section === "string" && ( {result.metadata.section} )}
)}
{onClick && ( )}
); }