import React, { useMemo } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { TraceAnalyticsData } from "@/hooks/useDashboardVisualizationData"; import { FileText, ArrowRight, Clock, Zap } from "lucide-react"; interface TraceAnalyticsProps { data: TraceAnalyticsData[]; isLoading?: boolean; error?: string | null; className?: string; } export function TraceAnalytics({ data, isLoading = false, error, className, }: TraceAnalyticsProps) { // Calculate key metrics const stats = useMemo(() => { if (!data.length) return null; const totalTraces = data.length; const avgReadingTime = data.reduce((sum, item) => sum + item.readingTime, 0) / totalTraces; const avgTimeWithoutAgentGraph = data.reduce((sum, item) => sum + item.timeWithoutAgentGraph, 0) / totalTraces; const avgComplexity = data.reduce((sum, item) => sum + item.complexity, 0) / totalTraces; const efficiencyMultiplier = avgTimeWithoutAgentGraph / avgReadingTime; const timeSavedMinutes = (avgTimeWithoutAgentGraph - avgReadingTime) * 3.5; // Simplified complexity calculation - 1-10 scale const complexityScore = Math.min( 10, Math.max(1, Math.round(3 + (avgComplexity / 100) * 7)) ); const readabilityGrade = Math.min(16, Math.max(6, 6 + complexityScore)); return { timeSavedMinutes, efficiencyMultiplier, complexityScore, // 1-10 scale for red circle readabilityGrade, }; }, [data]); if (error) { return (

{error}

); } if (isLoading) { return ( ); } if (data.length === 0 || !stats) { return (

No data available

); } return (
{/* Transformation Example */}
{/* Complex Trace Example */}
Raw Agent Trace
{stats.complexityScore}
{/* Example trace content */}
{"{"}
"agent_action": "web_search",
"tool_calls": [
{"{"} "function": "search",
"parameters": {"{"}
"query": "analyze data"
{"}"} {"}"}
],
"reasoning": "User needs...
{"}"}
+ 47 more nested objects...
Complexity {stats.complexityScore}/10 • Grade{" "} {stats.readabilityGrade}
{/* Arrow */}
AgentGraph
Auto-transforms
{/* Agent Graph Preview */}
Agent Graph
{/* Example graph visualization */}
User
Agent
Search Tool
Simplified to Grade 5 • 1/10 complexity
{/* Impact Metrics */}
{stats.timeSavedMinutes.toFixed(0)} min saved
per trace
{stats.efficiencyMultiplier.toFixed(1)}× faster
comprehension
{stats.complexityScore}
1
complexity reduction
{/* Complexity Scale Explanation */}
Complexity Scale: What does "{stats.complexityScore}" mean?
1-3: Simple 4-6: Moderate 7-10: Complex
); }