"use client"; import { useEffect, useState } from "react"; import { Card } from "@/shared/components"; import { useTranslations } from "next-intl"; interface AutoRoutingStats { totalRequests: number; variantBreakdown: Record; avgSelectionScore: number; topProviders: Array<{ provider: string; count: number }>; explorationRate: number; lkgpHitRate: number; } export default function AutoRoutingAnalyticsTab() { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const t = useTranslations("analytics"); useEffect(() => { fetch("/api/analytics/auto-routing") .then((res) => res.json()) .then((data) => { setStats(data); setLoading(false); }) .catch(() => setLoading(false)); }, []); if (loading) { return (
); } if (!stats) { return (
No auto-routing analytics available. Make requests using the auto/ prefix to see metrics.
); } return (
{/* Summary Cards */}
auto_awesome

{t("autoRoutingTotalAutoRequests")}

{stats.totalRequests.toLocaleString()}

target

{t("autoRoutingAvgSelectionScore")}

{(stats.avgSelectionScore * 100).toFixed(1)}%

explore

{t("autoRoutingExplorationRate")}

{(stats.explorationRate * 100).toFixed(1)}%

history

{t("autoRoutingLkgpHitRate")}

{(stats.lkgpHitRate * 100).toFixed(1)}%

{/* Variant Breakdown */}

{t("autoRoutingRequestsByVariant")}

{Object.entries(stats.variantBreakdown).map(([variant, count]) => { const percentage = stats.totalRequests > 0 ? (count / stats.totalRequests) * 100 : 0; return (
{variant || "default"}
{count.toLocaleString()} ({percentage.toFixed(1)}%)
); })}
{/* Top Providers */}

{t("autoRoutingTopRoutedProviders")}

{stats.topProviders.map((provider, index) => { const percentage = stats.totalRequests > 0 ? (provider.count / stats.totalRequests) * 100 : 0; return ( ); })}
Provider Requests Share
#{index + 1} {provider.provider}
{provider.count.toLocaleString()} {percentage.toFixed(1)}%
); }