'use client'; import { useEffect, useState, use } from 'react'; import Link from 'next/link'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Skeleton } from '@/components/ui/skeleton'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { AnalyzeButton } from '@/components/analyzer/analyze-button'; import { Sparkles } from 'lucide-react'; import type { PersistedAnalysis } from '@/lib/types/analyzer'; export default function TicketAnalyzerPage({ params, }: { params: Promise<{ ticketNumber: string }>; }) { const { ticketNumber } = use(params); const [analyses, setAnalyses] = useState(null); const [error, setError] = useState(null); useEffect(() => { let cancelled = false; (async () => { try { const res = await fetch( `/api/analyzer/tickets/${encodeURIComponent(ticketNumber)}/analyses` ); if (!res.ok) { const data = (await res.json().catch(() => ({}))) as { error?: string }; throw new Error(data.error ?? `Request failed: ${res.status}`); } const { analyses } = (await res.json()) as { analyses: PersistedAnalysis[] }; if (!cancelled) setAnalyses(analyses); } catch (err) { if (!cancelled) setError(err instanceof Error ? err.message : 'Unknown error'); } })(); return () => { cancelled = true; }; }, [ticketNumber]); const latest = analyses?.[0]; return (

Ticket

{ticketNumber}

Click Analyze to run the AI pipeline. If a current analysis already exists, you’ll be navigated straight to it. Otherwise the run takes ~10–60 seconds.

{error && ( Couldn’t load analysis history {error} )} Analysis history {analyses === null && !error ? (
) : analyses && analyses.length === 0 ? (

No analyses yet. Run one above.

) : (
    {(analyses ?? []).map((a) => (
  • Version {a.analysisVersion} {latest?.id === a.id && ( latest )} {a.needsHumanReview && ( Needs review )}

    {new Date(a.triggeredAt).toLocaleString()} {' · '} {a.opusUsed ? 'Haiku → Sonnet → Opus' : a.sonnetUsed ? 'Haiku → Sonnet' : 'Haiku'} {' · '}${a.estimatedCostUsd.toFixed(4)}

    {a.confidenceScore !== null && ( {Math.round(a.confidenceScore * 100)}% )}
  • ))}
)}
); }