This repository was archived by the owner on Mar 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheval_viewer.html
More file actions
764 lines (722 loc) · 29.7 KB
/
eval_viewer.html
File metadata and controls
764 lines (722 loc) · 29.7 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Eval Viewer</title>
<!-- TailwindCSS via CDN for quick styling. This makes the page lightweight and
easy to ship with any project without additional build steps. -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Preconnects improve the loading performance of Google fonts. -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
<style>
body {
font-family: "Inter", sans-serif;
}
/* Brand colours used to highlight decisions and sort criteria. */
.pass-highlight {
background-color: #22c55e;
color: white;
}
.fail-highlight {
background-color: #ef4444;
color: white;
}
.sort-highlight {
background-color: #3b82f6;
color: white;
}
/* Improve table readability by alternating row backgrounds. */
.table-striped tbody tr:nth-child(odd) {
background-color: #f9fafb;
}
/* Styles for truncating long text */
.text-truncate {
display: inline-block;
max-width: 30ch;
vertical-align: bottom;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body class="bg-gray-50 text-gray-800">
<div class="container mx-auto p-4 md:p-8">
<!-- Page header -->
<header class="mb-8">
<h1 class="text-3xl font-bold text-gray-900">Eval Viewer</h1>
<p class="mt-2 text-lg text-gray-600">
Browse and analyze proposal evaluations from JSON reports in ./evals/.
View per-proposal details, full prompts, scores, reasoning, and
outcomes, with aggregated stats for prompt improvement.
</p>
</header>
<!-- Summary of key insights will be injected here -->
<section id="summary-container" class="mb-8"></section>
<!-- Controls to select baseline eval, sorting and filtering -->
<section
class="bg-white p-4 rounded-xl shadow-sm border border-gray-200 mb-8 flex flex-col gap-4 md:flex-row md:items-end sticky top-0 z-10"
>
<!-- Baseline eval selector -->
<div
class="flex-1"
id="baseline-selector-container"
style="display: none"
>
<label
for="eval-select"
class="block text-sm font-medium text-gray-700 mb-1"
>Select Eval Report</label
>
<select
id="eval-select"
class="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500"
></select>
</div>
<!-- Sorting control -->
<div class="flex-1">
<label
for="sort-select"
class="block text-sm font-medium text-gray-700 mb-1"
>Sort by</label
>
<select
id="sort-select"
class="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500"
>
<option value="final-score-desc">Final Score (High to Low)</option>
<option value="final-score-asc">Final Score (Low to High)</option>
<option value="proposal-id-asc">Proposal ID (A-Z)</option>
</select>
</div>
<!-- Proposal filter -->
<div class="flex-1">
<label
for="proposal-filter-select"
class="block text-sm font-medium text-gray-700 mb-1"
>Filter by Proposal ID</label
>
<select
id="proposal-filter-select"
class="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500"
>
<option value="all">All Proposals</option>
</select>
</div>
<!-- View controls -->
<div class="flex-1" id="view-controls-container" style="display: none">
<label class="block text-sm font-medium text-gray-700 mb-1"
>View Controls</label
>
<div class="flex gap-2">
<button
id="expand-all-btn"
class="w-full p-2 border border-gray-300 rounded-md shadow-sm hover:bg-gray-50"
>
Expand All
</button>
<button
id="collapse-all-btn"
class="w-full p-2 border border-gray-300 rounded-md shadow-sm hover:bg-gray-50"
>
Collapse All
</button>
</div>
</div>
</section>
<!-- Container for eval cards (per report) -->
<main id="eval-container"></main>
</div>
<!-- Template to display a loading spinner while processing eval reports -->
<template id="loading-template">
<div
class="flex flex-col items-center justify-center p-12 bg-white rounded-xl shadow-sm border border-gray-200"
>
<svg
class="animate-spin h-8 w-8 text-gray-500"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
class="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
stroke-width="4"
></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
<p class="mt-4 text-lg font-medium text-gray-600">
Loading eval reports...
</p>
</div>
</template>
<script type="module">
/**
* This script loads eval reports from a manifest, renders summaries,
* sorting/filtering, and per-proposal details. It relies on
* relative file fetching via HTTP, so serve this file with a local
* server (e.g. `npx serve .`) when opening it.
*/
// Store processed evals per report path.
const evalData = new Map();
// Keep a list of human friendly names for each report (timestamps).
const evalNames = new Map();
// Active processed evals for baseline view.
let currentEvals = [];
/**
* Entry point: discover available reports and initialise UI.
*/
document.addEventListener("DOMContentLoaded", async () => {
// Bind controls only once.
document
.getElementById("sort-select")
.addEventListener("change", updateEvalView);
document
.getElementById("proposal-filter-select")
.addEventListener("change", updateEvalView);
document
.getElementById("expand-all-btn")
.addEventListener("click", () => toggleAll(true));
document
.getElementById("collapse-all-btn")
.addEventListener("click", () => toggleAll(false));
// Load manifest of reports. This should be a JSON array of
// objects with `path` and `name` fields.
let manifest = [];
try {
const resp = await fetch("./evals/evals-manifest.json");
if (resp.ok) {
manifest = await resp.json();
}
} catch (err) {
console.warn("No manifest found; skipping load.");
}
// Populate selector and preload reports.
const baselineSelector = document.getElementById("eval-select");
manifest.forEach((report, idx) => {
evalNames.set(report.path, report.name || report.path);
const option = document.createElement("option");
option.value = report.path;
option.textContent = report.name || report.path;
baselineSelector.appendChild(option);
});
// Show selectors if reports available.
if (manifest.length > 0) {
document.getElementById("baseline-selector-container").style.display =
"block";
document.getElementById("view-controls-container").style.display =
"block";
}
// Preload all reports.
for (const report of manifest) {
try {
const response = await fetch(report.path);
if (!response.ok) {
console.warn(
`Could not load report at ${report.path}: ${response.statusText}`
);
continue;
}
const rawData = await response.json();
const processed = processEvalData(rawData);
evalData.set(report.path, processed);
} catch (error) {
console.warn(`Error loading report ${report.path}:`, error);
}
}
// Display the first one as baseline if available.
const firstReport = manifest.find((r) => evalData.has(r.path));
if (firstReport) {
baselineSelector.value = firstReport.path;
currentEvals = evalData.get(firstReport.path);
updateViewForEval(firstReport.path);
} else {
// Display error if no reports could be loaded.
displayError(
new Error(
"No eval reports were loaded. Make sure evals-manifest.json exists and points to valid JSON files."
)
);
}
});
/**
* Transform raw eval data into a more usable form. Compute aggregates like pass rates and category averages.
*/
function processEvalData(data) {
if (!data || !data.overall_stats || !data.compact_scores) {
throw new Error("Invalid eval data structure");
}
const proposals = data.compact_scores.map((item) => ({
...item,
categories: [],
expected_decision: item.expected_decision || null,
mismatch:
item.expected_decision !== null &&
item.expected_decision !== item.decision,
}));
// Merge categories and prompts from full_results
data.full_results.forEach((full) => {
const prop = proposals.find(
(p) => p.proposal_id === full.proposal_id
);
if (prop) {
prop.proposal_number = full.proposal_number || "00";
prop.categories = full.categories || [];
prop.full_system_prompt = full.full_system_prompt || "N/A";
prop.full_user_prompt = full.full_user_prompt || "N/A";
prop.full_messages = full.full_messages || [];
}
});
// Compute aggregates
const total = data.overall_stats.total_proposals;
const passed = data.overall_stats.passed;
const passRate = (passed / total) * 100;
const categoryAverages = {};
proposals.forEach((prop) => {
prop.categories.forEach((cat) => {
categoryAverages[cat.category] = categoryAverages[cat.category] || {
sum: 0,
count: 0,
};
categoryAverages[cat.category].sum += cat.score;
categoryAverages[cat.category].count++;
});
});
Object.keys(categoryAverages).forEach((key) => {
categoryAverages[key].avg =
categoryAverages[key].sum / categoryAverages[key].count;
});
return {
timestamp: data.timestamp,
overall_stats: { ...data.overall_stats, passRate },
proposals,
categoryAverages,
full_results: data.full_results || [],
};
}
/**
* Display an error message in place of eval contents.
*/
function displayError(error) {
const container = document.getElementById("eval-container");
container.innerHTML = `<div class="col-span-full bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded-lg" role="alert"><strong class="font-bold">Error:</strong><span class="block sm:inline"> ${error.message}. Please ensure the JSON files are available and this page is served over HTTP.</span></div>`;
}
/**
* When the baseline eval changes, load its data and re-render the view.
*/
document.getElementById("eval-select").addEventListener("change", (e) => {
const path = e.target.value;
updateViewForEval(path);
});
/**
* Update both the summary and detailed view when switching evals.
*/
function updateViewForEval(path) {
const evals = evalData.get(path) || [];
currentEvals = evals;
// Update page header with eval name.
const header = document.querySelector("header h1");
const evalName = evalNames.get(path);
header.textContent = `Eval Viewer${evalName ? `: ${evalName}` : ""}`;
// Render summary and card view.
renderSummary(evals);
populateProposalFilter(evals);
updateEvalView();
}
/**
* Build the key insights table for an eval.
*/
function renderSummary(evals) {
const container = document.getElementById("summary-container");
if (!evals || evals.proposals.length === 0) {
container.innerHTML = "";
return;
}
// Top insights: e.g., highest/lowest scores, pass rate, category avgs
const byScoreDesc = [...evals.proposals]
.sort((a, b) => b.final_score - a.final_score)
.slice(0, 3);
const byScoreAsc = [...evals.proposals]
.sort((a, b) => a.final_score - b.final_score)
.slice(0, 3);
const mismatches = evals.proposals
.filter((p) => p.mismatch)
.slice(0, 3);
// Helper to build grouped rows
const createRows = (label, arr, formatFn) => {
if (arr.length === 0) return "";
return arr
.map((prop, idx) => {
const propId = prop.proposal_id.slice(0, 8);
const metricVal = formatFn(prop);
const labelCell =
idx === 0
? `<td class="py-3 px-4 border-b border-gray-200 text-sm font-medium text-gray-800 align-top" rowspan="${arr.length}">${label}</td>`
: "";
return `
<tr>
${labelCell}
<td class="py-3 px-4 border-b border-gray-200 text-sm text-gray-600 font-mono">${propId}</td>
<td class="py-3 px-4 border-b border-gray-200 text-sm text-gray-600 font-mono text-right">${metricVal}</td>
</tr>
`;
})
.join("");
};
container.innerHTML = `
<div class="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
<h2 id="summary-title" class="text-2xl font-bold text-gray-800 mb-4 pb-2 border-b-2 border-gray-200 cursor-pointer flex justify-between items-center">
<span>Key Insights</span>
<svg class="w-6 h-6 transform transition-transform chevron rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
</h2>
<div id="summary-content" class="overflow-x-auto">
<div class="mb-4 text-sm text-gray-600">
<span class="mr-4"><strong>Pass Rate:</strong> ${evals.overall_stats.passRate.toFixed(
2
)}%</span>
<span class="mr-4"><strong>Avg Score:</strong> ${evals.overall_stats.avg_score.toFixed(
2
)}</span>
<span><strong>Mismatches:</strong> ${mismatches.length}</span>
</div>
<table class="min-w-full table-striped">
<thead>
<tr>
<th class="py-3 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Category</th>
<th class="py-3 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Proposal</th>
<th class="py-3 px-4 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Metric</th>
</tr>
</thead>
<tbody>
${createRows(
"Highest Scores",
byScoreDesc,
(prop) =>
`${prop.final_score.toFixed(2)} (${
prop.decision ? "PASS" : "FAIL"
})`
)}
${createRows(
"Lowest Scores",
byScoreAsc,
(prop) =>
`${prop.final_score.toFixed(2)} (${
prop.decision ? "PASS" : "FAIL"
})`
)}
${createRows(
"Mismatches",
mismatches,
(prop) =>
`Expected: ${
prop.expected_decision ? "APPROVE" : "REJECT"
} | Actual: ${prop.decision ? "APPROVE" : "REJECT"}`
)}
</tbody>
</table>
<div class="mt-4">
<h3 class="font-bold">Category Averages</h3>
<ul class="list-disc pl-5 text-sm">
${Object.entries(evals.categoryAverages)
.map(
([key, val]) => `<li>${key}: ${val.avg.toFixed(2)}</li>`
)
.join("")}
</ul>
</div>
</div>
</div>
`;
// Add click listener for collapsible summary.
const summaryTitle = container.querySelector("#summary-title");
const summaryContent = container.querySelector("#summary-content");
if (summaryTitle && summaryContent) {
summaryTitle.addEventListener("click", () => {
const isCollapsed = summaryContent.style.display === "none";
summaryContent.style.display = isCollapsed ? "block" : "none";
summaryTitle
.querySelector(".chevron")
.classList.toggle("rotate-90", isCollapsed);
});
}
}
/**
* Populate the proposal filter dropdown with unique proposal IDs.
*/
function populateProposalFilter(evals) {
const select = document.getElementById("proposal-filter-select");
select.innerHTML = `<option value="all">All Proposals</option>`;
const uniqueProposals = [
...new Set(evals.proposals.map((p) => p.proposal_id)),
].sort();
uniqueProposals.forEach((pid) => {
const opt = document.createElement("option");
opt.value = pid;
opt.textContent = pid.slice(0, 8);
select.appendChild(opt);
});
}
/**
* Update the eval view based on current evals, sort order and filter.
*/
function updateEvalView() {
const container = document.getElementById("eval-container");
const expansionState = new Map();
container
.querySelectorAll("section[data-proposal-id]")
.forEach((section) => {
const pid = section.dataset.proposalId;
const details = section.querySelector(".details");
if (pid && details) {
expansionState.set(pid, details.style.display !== "none");
}
});
if (!currentEvals || currentEvals.proposals.length === 0) {
container.innerHTML = "";
return;
}
// Filter by proposal.
const selectedProposal = document.getElementById(
"proposal-filter-select"
).value;
let proposals = currentEvals.proposals;
if (selectedProposal !== "all") {
proposals = proposals.filter(
(p) => p.proposal_id === selectedProposal
);
}
// Determine sort order.
const sortValue = document.getElementById("sort-select").value;
let sortField, sortDir;
[sortField, sortDir] = sortValue.split("-");
proposals.sort((a, b) => {
let valA =
sortField === "final-score" ? a.final_score : a.proposal_id;
let valB =
sortField === "final-score" ? b.final_score : b.proposal_id;
return sortDir === "asc"
? valA > valB
? 1
: -1
: valA < valB
? 1
: -1;
});
container.innerHTML = "";
if (proposals.length === 0) {
container.innerHTML = `<div class="text-center p-12 bg-white rounded-xl shadow-sm border border-gray-200"><p class="text-lg font-medium text-gray-600">No proposals match the current filter.</p></div>`;
return;
}
// Create a wrapper for all proposal sections.
const wrapper = document.createElement("div");
wrapper.className =
"bg-white p-6 rounded-xl shadow-sm border border-gray-200";
const mainTitle = document.createElement("h2");
mainTitle.className =
"text-2xl font-bold text-gray-800 mb-4 pb-2 border-b-2 border-gray-200 cursor-pointer flex justify-between items-center";
mainTitle.innerHTML = `
<span>Proposals</span>
<svg class="w-6 h-6 transform transition-transform chevron rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
`;
wrapper.appendChild(mainTitle);
const contentDiv = document.createElement("div");
contentDiv.className = "space-y-8 pt-4";
mainTitle.addEventListener("click", () => {
const isCollapsed = contentDiv.style.display === "none";
contentDiv.style.display = isCollapsed ? "block" : "none";
mainTitle
.querySelector(".chevron")
.classList.toggle("rotate-90", isCollapsed);
});
// Render each proposal card.
proposals.forEach((prop) => {
const card = createProposalCard(prop);
contentDiv.appendChild(card);
});
wrapper.appendChild(contentDiv);
container.appendChild(wrapper);
// Re-apply expansion state
expansionState.forEach((isExpanded, pid) => {
if (isExpanded) {
const section = wrapper.querySelector(
`section[data-proposal-id="${pid}"]`
);
if (section) {
const title = section.querySelector("h2");
const details = section.querySelector(".details");
if (title && details) {
details.style.display = "block";
title.querySelector(".chevron").classList.add("rotate-90");
}
}
}
});
}
/**
* Expand or collapse all proposal sections.
*/
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function toggleAll(expand) {
const container = document.getElementById("eval-container");
container.querySelectorAll("section > h2").forEach((title) => {
const details = title.nextElementSibling;
if (details && details.classList.contains("details")) {
const isCurrentlyCollapsed = details.style.display === "none";
if (expand && isCurrentlyCollapsed) {
details.style.display = "block";
title.querySelector(".chevron").classList.add("rotate-90");
} else if (!expand && !isCurrentlyCollapsed) {
details.style.display = "none";
title.querySelector(".chevron").classList.remove("rotate-90");
}
}
});
}
/**
* Create a card summarising a single proposal's eval profile.
*/
function createProposalCard(prop) {
const card = document.createElement("section");
card.dataset.proposalId = prop.proposal_id;
const proposalNumber = prop.proposal_number;
const shortId = prop.proposal_id.slice(0, 8);
const title = document.createElement("h2");
title.className =
"text-xl font-bold text-gray-800 mb-4 cursor-pointer flex justify-between items-center";
const outcomeColor = prop.decision
? "text-green-600 border-green-600"
: "text-red-600 border-red-600";
title.innerHTML = `
<span class="${outcomeColor}">#${proposalNumber} - ${shortId} - Score: ${prop.final_score.toFixed(
2
)} (${prop.decision ? "PASS" : "FAIL"})</span>
<svg class="w-6 h-6 transform transition-transform chevron" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
`;
card.appendChild(title);
const details = document.createElement("div");
details.className = "details space-y-4";
details.style.display = "none"; // Collapsed by default
title.addEventListener("click", () => {
const isCollapsed = details.style.display === "none";
details.style.display = isCollapsed ? "block" : "none";
title
.querySelector(".chevron")
.classList.toggle("rotate-90", isCollapsed);
});
// Outcome and explanation
let outcomeText = `Outcome: ${prop.decision ? "APPROVE" : "REJECT"}`;
if (prop.expected_decision !== null) {
const expected = prop.expected_decision ? "APPROVE" : "REJECT";
const actual = prop.decision ? "APPROVE" : "REJECT";
outcomeText += ` (Expected: ${expected})`;
if (prop.mismatch) {
outcomeText += ` - Mismatch`;
}
}
const outcomeClass = prop.decision
? "border-green-600"
: "border-red-600";
details.innerHTML = `
<div class="p-4 rounded-md border ${outcomeClass}">
<p class="font-bold ${outcomeColor}">${outcomeText}</p>
<p class="text-sm">Explanation: ${prop.explanation || "N/A"}</p>
</div>
`;
// Prompt info
const promptInfo = document.createElement("div");
promptInfo.className = "space-y-2 mb-4";
promptInfo.innerHTML = `
<details class="bg-gray-50 p-3 rounded-md">
<summary class="font-medium text-gray-700 cursor-pointer">Full System Prompt</summary>
<pre class="mt-2 text-sm text-gray-600 whitespace-pre-wrap overflow-x-auto">${escapeHtml(
prop.full_system_prompt
)}</pre>
</details>
<details class="bg-gray-50 p-3 rounded-md">
<summary class="font-medium text-gray-700 cursor-pointer">Full User Prompt</summary>
<pre class="mt-2 text-sm text-gray-600 whitespace-pre-wrap overflow-x-auto">${escapeHtml(
prop.full_user_prompt
)}</pre>
</details>
<details class="bg-gray-50 p-3 rounded-md">
<summary class="font-medium text-gray-700 cursor-pointer">Full LLM Messages</summary>
<pre class="mt-2 text-sm text-gray-600 whitespace-pre-wrap overflow-x-auto">${escapeHtml(
JSON.stringify(prop.full_messages, null, 2)
)}</pre>
</details>
`;
details.appendChild(promptInfo);
// Categories table
details.innerHTML += `
<div class="border-t border-gray-200 pt-4 overflow-x-auto">
<table class="min-w-full table-striped">
<thead>
<tr>
<th class="py-2 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Category</th>
<th class="py-2 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Score</th>
<th class="py-2 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Weight</th>
<th class="py-2 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Reasoning</th>
</tr>
</thead>
<tbody>
${
prop.categories && prop.categories.length > 0
? prop.categories
.map(
(cat) => `
<tr>
<td class="py-2 px-4 border-b border-gray-200 text-sm font-medium">${
cat.category
}</td>
<td class="py-2 px-4 border-b border-gray-200 text-sm">${cat.score.toFixed(
2
)}</td>
<td class="py-2 px-4 border-b border-gray-200 text-sm">${cat.weight.toFixed(
2
)}</td>
<td class="py-2 px-4 border-b border-gray-200 text-sm">
<div class="text-gray-600 whitespace-pre-wrap">
${cat.reasoning
.map((r) => {
const escaped = escapeHtml(r);
return `<div class="mb-2">- ${escaped}</div>`;
})
.join("")}
</div>
</td>
</tr>
`
)
.join("")
: '<tr><td colspan="4" class="py-2 px-4 text-center text-sm text-gray-500">No categories available</td></tr>'
}
</tbody>
</table>
</div>
`;
card.appendChild(details);
return card;
}
</script>
</body>
</html>