"use client"; import { useState, useEffect } from "react"; import { Card } from "@/shared/components"; import { useTranslations } from "next-intl"; interface CompressionStats { originalTokens: number; compressedTokens: number; savingsPercent: number; techniquesUsed: string[]; mode: string; timestamp: number; rulesApplied?: string[]; durationMs?: number; } interface LogEntry { id: string; timestamp: string; model: string; provider: string; compressionStats?: CompressionStats | null; } export default function CompressionLogTab() { const t = useTranslations("logs"); const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/logs?filter=compressed&limit=50") .then((r) => (r.ok ? r.json() : [])) .then((data) => { setLogs(Array.isArray(data) ? data : []); }) .catch(() => {}) .finally(() => setLoading(false)); }, []); if (loading) { return (

{t("loading")}

); } if (logs.length === 0) { return (
compress

{t("compressionLogTitle")}

{t("compressionLogEmpty")}

); } return (
compress

{t("compressionLogTitle")}

{logs.map((entry) => { const stats = entry.compressionStats; if (!stats) return null; return (
{entry.provider}/{entry.model} {stats.mode}
{stats.originalTokens} → {stats.compressedTokens} {t("tokens")} = 25 ? "text-emerald-400" : stats.savingsPercent >= 10 ? "text-yellow-400" : "text-text-muted" }`} > -{stats.savingsPercent.toFixed(1)}% {stats.durationMs !== undefined && {stats.durationMs}ms}
{stats.techniquesUsed.length > 0 && (
{stats.techniquesUsed.map((technique) => ( {technique} ))}
)} {stats.rulesApplied && stats.rulesApplied.length > 0 && (
{stats.rulesApplied.map((rule) => ( {rule.replace(/_/g, " ")} ))}
)}
); })}
); }