import { createFileRoute, Link } from "@tanstack/react-router"; import { useEffect, useState } from "react"; import { api, type Chunk } from "@/lib/api"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; import { RatioBar, COLORS } from "@/components/analytics"; import { ArrowLeft, ChevronDown, Layers, Code, FileText } from "lucide-react"; export const Route = createFileRoute("/knowledge_/$dbHash/$sourceId")({ component: ChunkView }); function ChunkView() { const { dbHash, sourceId } = Route.useParams(); const [chunks, setChunks] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { api.chunks(dbHash, Number(sourceId)).then(c => { setChunks(c); setLoading(false); }); }, [dbHash, sourceId]); if (loading) return

Loading chunks...

; const sourceLabel = chunks[0]?.label || dbHash; // Compute stats const totalChunks = chunks.length; const codeChunks = chunks.filter(c => c.content_type === "code").length; const textChunks = totalChunks - codeChunks; // Content type breakdown const typeCounts: Record = {}; chunks.forEach(c => { typeCounts[c.content_type] = (typeCounts[c.content_type] || 0) + 1; }); const typeEntries = Object.entries(typeCounts).sort((a, b) => b[1] - a[1]); // Average content length const avgLen = totalChunks > 0 ? Math.round(chunks.reduce((a, c) => a + (c.content?.length || 0), 0) / totalChunks) : 0; return (
Back to Knowledge Base

Source Detail

{dbHash.slice(0, 8)}

{sourceLabel}

{/* KPI Strip */}
Chunks
{totalChunks}

~{avgLen} chars avg

Code
{codeChunks}

{totalChunks > 0 ? `${Math.round(100 * codeChunks / totalChunks)}% of total` : "none"}

Text
{textChunks}

{totalChunks > 0 ? `${Math.round(100 * textChunks / totalChunks)}% of total` : "none"}

{/* Content type ratio bar */} {typeEntries.length > 1 && ( Content Types ({ label: type, value: count, color: type === "code" ? "#06b6d4" : COLORS[i % COLORS.length], }))} /> )} {/* Chunk list */}
{chunks.map((chunk, i) => ( {chunk.title || "(untitled)"}
{chunk.content_type} {chunk.content?.length || 0} chars
                      {chunk.content}
                    
))}
); }