Spaces:
Running
Running
File size: 5,671 Bytes
c2ea5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
import React from "react";
import { ExampleTrace } from "@/types";
import { Dialog, DialogContent } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { AlertTriangle, CheckCircle, Target, User } from "lucide-react";
interface Props {
open: boolean;
example: ExampleTrace;
onOpenChange: (open: boolean) => void;
onImport: () => void;
}
const ExampleTraceDetailModal: React.FC<Props> = ({
open,
example,
onOpenChange,
onImport,
}) => {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="w-full max-w-4xl max-h-[90vh] overflow-y-auto rounded-xl bg-background/95 backdrop-blur shadow-xl data-[state=open]:animate-fadeIn p-6 space-y-6">
{/* Correctness Status */}
<div className="flex items-center gap-2">
{example.is_correct && (
<div className="flex items-center gap-2 text-green-600">
<CheckCircle className="h-5 w-5" />
<span className="font-medium">Correct Response</span>
</div>
)}
</div>
{/* Question */}
<div className="space-y-2">
<h2 className="text-lg font-semibold leading-relaxed">
Full Question
</h2>
<p className="whitespace-pre-line break-words">{example.question}</p>
</div>
{/* Agents */}
{example.agents && example.agents.length > 0 && (
<div className="space-y-2 border-t pt-4">
<h3 className="text-sm font-semibold text-muted-foreground">
Agents Involved
</h3>
<div className="flex flex-wrap gap-2">
{example.agents.map((a) => (
<Badge
key={a}
variant="secondary"
className={
a === example.mistake_agent
? "bg-orange-100 text-orange-700 border-orange-300"
: ""
}
>
{a}
{a === example.mistake_agent && " ⚠️"}
</Badge>
))}
</div>
</div>
)}
{/* Failure Analysis Section */}
{!example.is_correct && (
<div className="space-y-4 border-2 border-blue-100 bg-blue-50/50 rounded-lg p-4">
<div className="flex items-center gap-2 text-blue-700">
<AlertTriangle className="h-5 w-5" />
<h3 className="font-semibold">Failure Analysis</h3>
</div>
{/* Mistake Reason - The key insight field! */}
{example.mistake_reason && (
<div className="space-y-2">
<h4 className="text-sm font-medium text-blue-700">
Why This Failed:
</h4>
<div className="bg-white/80 rounded-md p-3 border border-blue-200">
<p className="text-sm text-gray-700">
{example.mistake_reason}
</p>
</div>
</div>
)}
{/* Mistake Agent */}
{example.mistake_agent && (
<div className="flex items-center gap-2">
<User className="h-4 w-4 text-orange-600" />
<span className="text-sm font-medium text-gray-700">
Agent that made the mistake:
</span>
<Badge
variant="secondary"
className="bg-orange-100 text-orange-700 border-orange-300"
>
{example.mistake_agent}
</Badge>
</div>
)}
{/* Ground Truth */}
{example.ground_truth && (
<div className="space-y-2">
<div className="flex items-center gap-2">
<Target className="h-4 w-4 text-green-600" />
<h4 className="text-sm font-medium text-green-700">
Correct Answer:
</h4>
</div>
<div className="bg-green-50 rounded-md p-3 border border-green-200">
<p className="text-sm text-green-800">
{example.ground_truth}
</p>
</div>
</div>
)}
</div>
)}
{/* Trace Preview */}
{example.trace && (
<div className="space-y-2 border-t pt-4">
<h3 className="text-sm font-semibold text-muted-foreground">
Trace Preview
</h3>
<pre className="text-xs font-mono bg-muted/50 rounded-md p-4 overflow-x-auto overflow-y-auto whitespace-pre-wrap max-h-64 scrollbar-thin">
{(() => {
try {
const obj = JSON.parse(example.trace);
return JSON.stringify(obj, null, 2);
} catch {
return example.trace;
}
})()}
</pre>
</div>
)}
{/* Footer */}
<div className="border-t pt-4 flex justify-end gap-2">
<Button variant="outline" onClick={() => onOpenChange(false)}>
Close
</Button>
<Button
variant="outline"
onClick={() =>
navigator.clipboard.writeText(JSON.stringify(example, null, 2))
}
>
Copy JSON
</Button>
<Button onClick={onImport}>Import</Button>
</div>
</DialogContent>
</Dialog>
);
};
export default ExampleTraceDetailModal;
|