"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { KBStats, KBIndexType } from "@/types"; import { Database, Code, FileText, MessageSquare, BookOpen, AlertTriangle, Scale, GitBranch, ClipboardCheck, Lightbulb } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; const indexIcons: Record = { [KBIndexType.CODE]: , [KBIndexType.DOCUMENTATION]: , [KBIndexType.CONVERSATIONS]: , [KBIndexType.JOURNALS]: , [KBIndexType.ERRORS]: , [KBIndexType.STANDARDS]: , [KBIndexType.DECISIONS]: , [KBIndexType.REVIEWS]: , [KBIndexType.LEARNINGS]: , }; const indexLabels: Record = { [KBIndexType.CODE]: "Code", [KBIndexType.DOCUMENTATION]: "Docs", [KBIndexType.CONVERSATIONS]: "Convos", [KBIndexType.JOURNALS]: "Journals", [KBIndexType.ERRORS]: "Errors", [KBIndexType.STANDARDS]: "Standards", [KBIndexType.DECISIONS]: "Decisions", [KBIndexType.REVIEWS]: "Reviews", [KBIndexType.LEARNINGS]: "Learnings", }; interface KBStatsCardProps { stats: KBStats | undefined; isLoading: boolean; } export function KBStatsCard({ stats, isLoading }: KBStatsCardProps) { if (isLoading) { return ( Index Stats {[1, 2, 3, 4].map((i) => (
))}
); } if (!stats || !Array.isArray(stats.indexes)) { return ( Index Stats

No data available

); } return ( Index Stats {stats.indexes.map((idx) => (
{indexIcons[idx.index_type]} {indexLabels[idx.index_type]}
{idx.document_count.toLocaleString()} docs
))}
Total {stats.total_documents.toLocaleString()}
Chunks {stats.total_chunks.toLocaleString()}
{stats.indexes[0]?.last_updated && (

Updated {formatDistanceToNow(new Date(stats.indexes[0].last_updated))} ago

)}
); }