({ stats }: Props)
| 89 | } |
| 90 | |
| 91 | export default function Home({ stats }: Props) { |
| 92 | const { recent } = useLiveData(); |
| 93 | const turns = groupTurns(recent).slice(0, 8); |
| 94 | |
| 95 | const seenTurnsRef = useRef<Set<string>>(new Set()); |
| 96 | const initialPrimedRef = useRef(false); |
| 97 | |
| 98 | const newKeys = new Set<string>(); |
| 99 | if (initialPrimedRef.current) { |
| 100 | for (const g of turns) { |
| 101 | if (!seenTurnsRef.current.has(g.key)) newKeys.add(g.key); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | useEffect(() => { |
| 106 | if (!initialPrimedRef.current) { |
| 107 | if (turns.length > 0) { |
| 108 | seenTurnsRef.current = new Set(turns.map((g) => g.key)); |
| 109 | initialPrimedRef.current = true; |
| 110 | } |
| 111 | return; |
| 112 | } |
| 113 | for (const g of turns) seenTurnsRef.current.add(g.key); |
| 114 | }, [turns]); |
| 115 | |
| 116 | const totalRequests = stats?.total_requests ?? 0; |
| 117 | const totalSaved = stats?.total_savings_absolute ?? 0; |
| 118 | const savingsRatio = stats?.total_savings_ratio ?? 0; |
| 119 | const baselineCost = stats?.total_baseline_cost ?? 0; |
| 120 | |
| 121 | const lowCount = stats?.by_tier?.SIMPLE?.count ?? 0; |
| 122 | const midCount = stats?.by_tier?.MEDIUM?.count ?? 0; |
| 123 | const highCount = stats?.by_tier?.COMPLEX?.count ?? 0; |
| 124 | const totalTier = lowCount + midCount + highCount || 1; |
| 125 | |
| 126 | // ─── Empty state ─── |
| 127 | if (totalRequests === 0 && turns.length === 0) { |
| 128 | return ( |
| 129 | <div className="flex flex-col items-center justify-center min-h-[calc(100vh-64px)] animate-fadeIn"> |
| 130 | <div className="font-display text-[64px] text-n-display tracking-tight">0</div> |
| 131 | <div className="label mt-4">REQUESTS ROUTED</div> |
| 132 | <p className="mt-6 text-[14px] text-n-secondary max-w-sm text-center"> |
| 133 | Send a request through the proxy to see routing in action. |
| 134 | </p> |
| 135 | <div className="mt-8 bg-n-surface border border-n-border rounded-compact p-5 font-mono text-[12px] text-n-secondary leading-relaxed max-w-lg w-full"> |
| 136 | <span className="text-n-disabled">$</span> curl localhost:8403/v1/chat/completions \{"\n"} |
| 137 | {" "}-H "Content-Type: application/json" \{"\n"} |
| 138 | {" "}-d '{`{"model":"uncommon-route/auto","messages":[{"role":"user","content":"hello"}]}`}' |
| 139 | </div> |
| 140 | </div> |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | return ( |
| 145 | <div className="flex flex-col min-h-[calc(100vh-64px)] pt-4 animate-fadeIn"> |
| 146 | {/* ─── ZONE A: Hero Savings ─── */} |
| 147 | <div className="mb-10"> |
| 148 | <div className="label mb-2">TOTAL SAVED</div> |
nothing calls this directly
no test coverage detected