import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Activity, Clock, DollarSign, MessageSquare } from "lucide-react"; import type { Session, DashboardStats } from "@/lib/types"; import { PageHeader } from "@/components/layout/page-header"; async function getSessions(projectId: string): Promise { try { const res = await fetch( `${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/api/sessions?projectId=${projectId}&limit=20`, { cache: 'no-store' } ); if (!res.ok) throw new Error('Failed to fetch sessions'); return res.json(); } catch (error) { console.error('Error fetching sessions:', error); return []; } } async function getStats(projectId: string): Promise { try { const res = await fetch( `${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/api/stats?projectId=${projectId}`, { cache: 'no-store' } ); if (!res.ok) throw new Error('Failed to fetch stats'); return res.json(); } catch (error) { return { totalSessions: 0, totalCost: 0, totalTokens: 0, totalFeatures: 0, completedFeatures: 0, totalDuration: 0, }; } } export default async function SessionsPage({ params, }: { params: Promise<{ workspace: string; projectId: string }>; }) { const { workspace, projectId } = await params; const [sessions, stats] = await Promise.all([ getSessions(projectId), getStats(projectId), ]); return ( <>
{/* Stats Section */}

Sessions

Track all your AI coding sessions

{/* Content */}
{/* Stats */}
Total Sessions
{stats.totalSessions}
Total Duration
{Math.round(stats.totalDuration / 60)}h
Total Cost
${stats.totalCost.toFixed(2)}
{/* Sessions List */} Recent Sessions Your AI coding activity with conversation history {sessions.length === 0 ? (

No sessions yet

Start coding with AI and your sessions will appear here

) : (
{sessions.map((session) => (

{session.summary || `Session ${session.session_id.substring(0, 8)}...`}

{session.duration_minutes} min {session.message_count} messages {session.estimated_cost_usd && ( ${session.estimated_cost_usd.toFixed(3)} )}
{session.primary_ai_model && ( {session.primary_ai_model} )} {session.ide_name && ( {session.ide_name} )} {session.github_branch && ( {session.github_branch} )}
))}
)}
); }