File size: 13,208 Bytes
2f00f43 1035089 2f00f43 4cc00df 2f00f43 4cc00df 1035089 2f00f43 4cc00df 2f00f43 4cc00df 1035089 4cc00df 1035089 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 4cc00df 2f00f43 | 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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | import { useEffect, useState } from "react";
import { Eye, Stethoscope, Wrench, FileText, Share2, CheckCircle2, AlertTriangle, XCircle, WifiOff, Twitter, Linkedin } from "lucide-react";
const ICONS = {
inspector: Eye,
diagnostician: Stethoscope,
action: Wrench,
reporter: FileText,
social: Share2,
};
const VERDICT_CONFIG = {
pass: { label: "PASS", color: "#10B981", Icon: CheckCircle2 },
warn: { label: "WARN", color: "#F59E0B", Icon: AlertTriangle },
fail: { label: "FAIL", color: "#ED1C24", Icon: XCircle },
};
// ββ Renderers β one per agent role βββββββββββββββββββββββββββββββββββββββββ
function InspectorOutput({ parsed, isMock }) {
const vc = VERDICT_CONFIG[parsed?.verdict] || VERDICT_CONFIG.warn;
const defects = parsed?.defects || [];
return (
<div className="space-y-4">
{isMock && (
<div className="flex items-center gap-2 px-3 py-2 bg-yellow-500/10 border border-yellow-500/30 rounded text-yellow-400 font-mono text-xs">
<WifiOff className="w-3 h-3 shrink-0" />
AMD server offline β showing demo data. Start the vLLM server for live inference.
</div>
)}
{/* Verdict banner */}
<div className="flex items-center gap-3 p-4 border rounded" style={{ borderColor: `${vc.color}44`, background: `${vc.color}0d` }}>
<vc.Icon className="w-5 h-5" style={{ color: vc.color }} />
<div>
<div className="font-mono text-xs text-zinc-400 mb-0.5">VERDICT</div>
<div className="font-display font-black text-xl tracking-tight" style={{ color: vc.color }}>{vc.label}</div>
</div>
<div className="ml-auto text-right">
<div className="font-mono text-xs text-zinc-400 mb-0.5">CONFIDENCE</div>
<div className="font-display font-black text-xl">{Math.round((parsed?.confidence || 0) * 100)}%</div>
</div>
</div>
{/* Observation */}
{parsed?.observation && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-1.5">Observation</div>
<p className="text-sm text-zinc-300 leading-relaxed">{parsed.observation.replace("[LOCAL MOCK β AMD server offline]", "").trim()}</p>
</div>
)}
{/* Defects */}
{defects.length > 0 && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-2">Detected Defects ({defects.length})</div>
<div className="space-y-2">
{defects.map((d, i) => (
<div key={i} className="flex gap-3 p-3 border border-white/10 bg-white/[0.02] rounded">
<div className="shrink-0 w-1.5 rounded-full self-stretch" style={{ background: d.severity === "high" ? "#ED1C24" : d.severity === "medium" ? "#F59E0B" : "#71717A" }} />
<div className="min-w-0">
<div className="flex items-center gap-2 flex-wrap mb-0.5">
<span className="font-mono text-xs font-bold text-white">{d.type}</span>
<span className="font-mono text-[10px] px-1.5 py-0.5 rounded border" style={{ color: d.severity === "high" ? "#ED1C24" : d.severity === "medium" ? "#F59E0B" : "#71717A", borderColor: "currentColor", background: "transparent" }}>{d.severity?.toUpperCase()}</span>
{d.location && <span className="font-mono text-[10px] text-zinc-500">@ {d.location}</span>}
</div>
<p className="text-xs text-zinc-400">{d.description}</p>
</div>
</div>
))}
</div>
</div>
)}
</div>
);
}
function DiagnosticianOutput({ parsed }) {
const factors = parsed?.contributing_factors || [];
return (
<div className="space-y-3">
{parsed?.probable_cause && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-1.5">Root Cause</div>
<p className="text-sm text-zinc-200 leading-relaxed font-medium">{parsed.probable_cause.replace("[LOCAL MOCK]", "").trim()}</p>
</div>
)}
{parsed?.affected_process_step && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-1.5">Affected Process Step</div>
<span className="font-mono text-xs px-2 py-1 border border-white/20 text-zinc-300">{parsed.affected_process_step}</span>
</div>
)}
{factors.length > 0 && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-2">Contributing Factors</div>
<ul className="space-y-1">
{factors.map((f, i) => (
<li key={i} className="flex items-start gap-2 text-sm text-zinc-300">
<span className="text-[#ED1C24] font-mono text-xs mt-0.5 shrink-0">β</span>
{f}
</li>
))}
</ul>
</div>
)}
</div>
);
}
function ActionOutput({ parsed }) {
const steps = parsed?.steps || [];
const tools = parsed?.parts_or_tools || [];
const priorityColor = { P0: "#ED1C24", P1: "#F97316", P2: "#F59E0B", P3: "#71717A" }[parsed?.priority] || "#71717A";
return (
<div className="space-y-3">
<div className="flex gap-4 flex-wrap">
{parsed?.priority && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-1">Priority</div>
<span className="font-display font-black text-xl" style={{ color: priorityColor }}>{parsed.priority}</span>
</div>
)}
{parsed?.assignee_role && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-1">Assign To</div>
<span className="font-mono text-sm text-zinc-200">{parsed.assignee_role}</span>
</div>
)}
{parsed?.estimated_minutes && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-1">Est. Time</div>
<span className="font-mono text-sm text-zinc-200">{parsed.estimated_minutes} min</span>
</div>
)}
</div>
{steps.length > 0 && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-2">Work Order Steps</div>
<ol className="space-y-1.5">
{steps.map((s, i) => (
<li key={i} className="flex items-start gap-3 text-sm text-zinc-300">
<span className="font-mono text-xs text-zinc-500 w-5 shrink-0 text-right">{String(i + 1).padStart(2, "0")}.</span>
{s}
</li>
))}
</ol>
</div>
)}
{tools.length > 0 && (
<div>
<div className="font-mono text-[10px] text-zinc-500 uppercase tracking-wider mb-2">Parts / Tools Required</div>
<div className="flex flex-wrap gap-1.5">
{tools.map((t, i) => <span key={i} className="font-mono text-xs px-2 py-1 border border-white/15 text-zinc-400">{t}</span>)}
</div>
</div>
)}
</div>
);
}
function ReporterOutput({ parsed }) {
const tags = parsed?.tags || [];
return (
<div className="space-y-3">
{parsed?.headline && (
<div className="font-display font-black text-2xl tracking-tighter text-white">{parsed.headline.replace("[Mock]", "").trim()}</div>
)}
{parsed?.summary && (
<p className="text-sm text-zinc-300 leading-relaxed">{parsed.summary}</p>
)}
{tags.length > 0 && (
<div className="flex flex-wrap gap-1.5">
{tags.map((t, i) => (
<span key={i} className="font-mono text-[10px] px-2 py-1 border border-[#ED1C24]/40 text-[#ED1C24] bg-[#ED1C24]/5">#{t}</span>
))}
</div>
)}
</div>
);
}
function SocialOutput({ parsed }) {
const xText = parsed?.x_post || "";
const linkedInText = parsed?.linkedin_post || "";
return (
<div className="grid md:grid-cols-2 gap-4">
<div className="p-4 border border-white/5 bg-[#141416] rounded-sm fs-rise">
<div className="flex items-center gap-2 mb-3">
<Twitter className="w-4 h-4 text-[#1DA1F2]" />
<span className="font-mono text-[10px] text-zinc-500 uppercase tracking-widest">X / Twitter</span>
</div>
<p className="text-xs text-zinc-300 font-mono leading-relaxed">{xText}</p>
<div className="mt-4 flex justify-end">
<button
onClick={() => window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(xText)}`, '_blank')}
className="font-mono text-[10px] px-2 py-1 border border-white/10 hover:bg-white/5 transition-colors text-zinc-400"
>
Draft Post
</button>
</div>
</div>
<div className="p-4 border border-white/5 bg-[#141416] rounded-sm fs-rise">
<div className="flex items-center gap-2 mb-3">
<Linkedin className="w-4 h-4 text-[#0A66C2]" />
<span className="font-mono text-[10px] text-zinc-500 uppercase tracking-widest">LinkedIn</span>
</div>
<div className="text-[11px] text-zinc-400 font-sans whitespace-pre-wrap leading-relaxed max-h-32 overflow-y-auto pr-2 custom-scrollbar">
{linkedInText}
</div>
<div className="mt-4 flex justify-end">
<button
onClick={() => {
navigator.clipboard.writeText(linkedInText);
alert("LinkedIn text copied!");
}}
className="font-mono text-[10px] px-2 py-1 border border-white/10 hover:bg-white/5 transition-colors text-zinc-400"
>
Copy Text
</button>
</div>
</div>
</div>
);
}
function AgentContent({ agent, isMock }) {
const { role, output } = agent;
const parsed = output?.parsed || {};
if (role === "inspector") return <InspectorOutput parsed={parsed} isMock={isMock} />;
if (role === "diagnostician") return <DiagnosticianOutput parsed={parsed} />;
if (role === "action") return <ActionOutput parsed={parsed} />;
if (role === "reporter") return <ReporterOutput parsed={parsed} />;
if (role === "social") return <SocialOutput parsed={parsed} />;
return <pre className="font-mono text-xs text-zinc-400 whitespace-pre-wrap break-words">{JSON.stringify(parsed, null, 2)}</pre>;
}
// ββ Main component ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export default function AgentTranscript({ transcript }) {
const [revealed, setRevealed] = useState(0);
useEffect(() => {
if (!transcript) return;
setRevealed(0);
const agents = transcript.agents || [];
agents.forEach((_, i) => {
setTimeout(() => setRevealed((r) => Math.max(r, i + 1)), i * 400);
});
}, [transcript]);
if (!transcript) return null;
const agents = transcript.agents || [];
// Detect mock mode from first agent's source
const isMock = agents[0]?.output?.source?.includes("mock");
return (
<div className="space-y-0 border border-white/10 bg-[#0d0d10]" data-testid="agent-transcript">
{agents.map((a, idx) => {
const Icon = ICONS[a.role] || Eye;
const isVisible = idx < revealed;
const isActive = idx === revealed - 1;
return (
<div
key={a.role}
className={`border-b border-white/10 last:border-b-0 transition-all duration-500 ${isVisible ? "opacity-100" : "opacity-0"}`}
data-testid={`agent-block-${a.role}`}
>
{/* Agent header */}
<div className={`flex items-center justify-between px-5 py-3 border-b border-white/5 ${isActive ? "bg-[#ED1C24]/5" : "bg-[#141416]"}`}>
<div className="flex items-center gap-3">
<div className={`w-7 h-7 flex items-center justify-center border ${isVisible ? "border-[#ED1C24] text-[#ED1C24]" : "border-white/20 text-zinc-500"}`}>
<Icon className="w-3.5 h-3.5" />
</div>
<div>
<div className="font-display font-bold tracking-tight text-sm text-white">{a.label}</div>
<div className="font-mono text-[10px] text-zinc-500">{a.model}</div>
</div>
</div>
<StatusPill visible={isVisible} active={isActive} />
</div>
{/* Agent body */}
{isVisible && (
<div className="p-5">
<AgentContent agent={a} isMock={isMock} />
</div>
)}
</div>
);
})}
</div>
);
}
function StatusPill({ visible, active }) {
if (!visible) return <span className="fs-chip text-zinc-600">queued</span>;
if (active) return <span className="fs-chip" style={{ color: "#ED1C24", borderColor: "#ED1C24", background: "#ED1C2411" }}>complete</span>;
return <span className="fs-chip fs-chip-pass">complete</span>;
}
|