import * as React from 'react'; import { Activity, BarChart3, Clock, HelpCircle, MessageSquare, ThumbsDown, ThumbsUp, Wrench, } from 'lucide-react'; import { Badge, EmptyState } from '@/components/ds'; import { readHistory } from '@/components/ai-assistant/history'; import { conversationStats, reviewRow } from '@/lib/agents/conversationInsights'; import { allSkills } from '@/lib/skills/registry'; import { usePreferences } from '@/lib/krowHooks'; import { cn } from '@/lib/utils'; /** * What this agent has actually been asked. * * Real-time usage analytics computed directly from the local telemetry log. */ function MetricCard({ icon: Icon, label, value, detail, highlight }: any) { return (
{label}
{value} {highlight && ( {highlight} )}
{detail &&

{detail}

}
); } export function AgentInsightsPanel({ agentId, agentName }: any) { const preferences = usePreferences(); const [records] = React.useState(() => readHistory()); const stats = React.useMemo( () => conversationStats(records, { agentId }), [records, agentId] ); const skillName = React.useMemo(() => { const byId = new Map(allSkills(preferences.customSkills || []).map((s) => [s.id, s.name])); return (id) => byId.get(id) || id; }, [preferences.customSkills]); const conversations = React.useMemo( () => records .filter((r) => (agentId ? r.agentId === agentId : true)) .slice(0, 8) .map(reviewRow), [records, agentId] ); if (stats.empty) { return (
); } return (
{/* ── KPI Metric Cards ───────────────────────────────────────────── */}
{/* ── 2-Column Ranking Breakdowns ────────────────────────────────── */}
{/* Most Used Skills */}

Most Triggered Skills

{stats.bySkill.length ? (
{stats.bySkill.slice(0, 5).map((row) => (
{skillName(row.id)} {row.count} query{row.count === 1 ? '' : 'ies'}
))}
) : (
No skill executions logged yet. Conversations were handled directly by native page readers.
)}
{/* Actions Executed */}

Actions & Tool Usage

{stats.byTool.length ? (
{stats.byTool.slice(0, 5).map((row) => (
{row.id.replace(/_/g, ' ')} {row.count} run{row.count === 1 ? '' : 's'}
))}
) : (
No action tool executions recorded in current audit window.
)}
{/* ── Recent Conversations Table ─────────────────────────────────── */}

Recent Conversation Logs

{conversations.map((row) => (

{row.title || 'General consultation'}

Surface:{' '} {row.page || 'Direct'}

{row.turns} turn{row.turns === 1 ? '' : 's'} {row.feedback && ( {row.feedback.rating === 'up' ? ( <> Helpful ) : ( <> Unhelpful )} )}
))}
); } export default AgentInsightsPanel;