"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { HelpTip } from "@/components/ui/help-tip"; import { getIndexTypeDescription } from "./kb-index-type-badge"; import { KBStats, KBIndexType } from "@/types"; import { Database, FileText, MessageSquare, BookOpen, AlertTriangle, Scale, GitBranch, ClipboardCheck, Lightbulb, ScrollText, StickyNote, } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; const indexIcons: Record = { [KBIndexType.DOCUMENTATION]: , [KBIndexType.CONVERSATIONS]: ( ), [KBIndexType.JOURNALS]: , [KBIndexType.ERRORS]: , [KBIndexType.STANDARDS]: , [KBIndexType.DECISIONS]: , [KBIndexType.REVIEWS]: , [KBIndexType.LEARNINGS]: , [KBIndexType.PLAYBOOKS]: , [KBIndexType.VAULT_NOTES]: , }; const indexLabels: Record = { [KBIndexType.DOCUMENTATION]: "Docs", [KBIndexType.CONVERSATIONS]: "Convos", [KBIndexType.JOURNALS]: "Journals", [KBIndexType.ERRORS]: "Errors", [KBIndexType.STANDARDS]: "Standards", [KBIndexType.DECISIONS]: "Decisions", [KBIndexType.REVIEWS]: "Reviews", [KBIndexType.LEARNINGS]: "Learnings", [KBIndexType.PLAYBOOKS]: "Playbooks", [KBIndexType.VAULT_NOTES]: "Vault Notes", }; 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

); } const latestUpdated = stats.indexes.reduce( (acc, idx) => idx.last_updated && (!acc || idx.last_updated > acc) ? idx.last_updated : acc, null, ); 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()}
{latestUpdated && (

Updated {formatDistanceToNow(new Date(latestUpdated))} ago

)}
); }