forked from openai/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.js
More file actions
331 lines (304 loc) · 10.5 KB
/
Copy pathhtml.js
File metadata and controls
331 lines (304 loc) · 10.5 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
function escapeHtml(value) {
return String(value)
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll("\"", """);
}
function renderList(items) {
if (items.length === 0) {
return "<p>None.</p>";
}
return `<ul>${items.map((item) => `<li>${escapeHtml(item)}</li>`).join("")}</ul>`;
}
function renderOptionalList(items, emptyLabel = "None.") {
return renderList(Array.isArray(items) && items.length > 0 ? items : [emptyLabel]);
}
function renderChecks(checks) {
if (checks.length === 0) {
return "<p>No checks recorded.</p>";
}
return `<ul>${checks
.map(
(check) =>
`<li><strong>${escapeHtml(check.id)}</strong> [${escapeHtml(check.status)}] ${escapeHtml(check.message)}</li>`,
)
.join("")}</ul>`;
}
function renderMetrics(metrics) {
if (metrics.length === 0) {
return "<p>No metrics recorded.</p>";
}
return `<ul>${metrics
.map(
(metric) =>
`<li><strong>${escapeHtml(metric.id)}</strong>: ${escapeHtml(metric.value)} ${escapeHtml(metric.unit)} (${escapeHtml(metric.band)})</li>`,
)
.join("")}</ul>`;
}
function renderDeductions(summary) {
if (!summary.deductions || summary.deductions.length === 0) {
return "<p>No deductions were applied.</p>";
}
return `<ul>${summary.deductions
.map(
(entry) =>
`<li><strong>-${escapeHtml(entry.penalty)} points</strong> <code>${escapeHtml(entry.id)}</code> [${escapeHtml(entry.status)}/${escapeHtml(entry.severity)}] ${escapeHtml(entry.message)}</li>`,
)
.join("")}</ul>`;
}
function renderCategoryDeductions(summary) {
if (!summary.categoryDeductions || summary.categoryDeductions.length === 0) {
return "<p>No category deductions recorded.</p>";
}
return `<ul>${summary.categoryDeductions
.map(
(entry) =>
`<li><strong>${escapeHtml(entry.category)}</strong>: -${escapeHtml(entry.totalPenalty)} points across ${escapeHtml(entry.checks)} check${entry.checks === 1 ? "" : "s"}</li>`,
)
.join("")}</ul>`;
}
function renderObservedUsage(observedUsage) {
if (!observedUsage) {
return "<p>No observed usage supplied.</p>";
}
const items = [
`Samples: ${observedUsage.sampleCount}`,
`Observed input avg: ${observedUsage.inputTokens.average}`,
`Observed output avg: ${observedUsage.outputTokens.average}`,
`Observed total avg: ${observedUsage.totalTokens.average}`,
];
if (observedUsage.cachedTokens.total > 0) {
items.push(`Observed cached avg: ${observedUsage.cachedTokens.average}`);
}
if (observedUsage.estimateComparison) {
items.push(`Estimated active tokens: ${observedUsage.estimateComparison.estimatedActiveTokens}`);
items.push(`Estimate delta: ${observedUsage.estimateComparison.deltaTokens}`);
items.push(`Estimate ratio: ${observedUsage.estimateComparison.deltaRatio} (${observedUsage.estimateComparison.band})`);
}
return renderList(items);
}
function renderMeasurementPlan(plan) {
if (!plan) {
return "<p>No measurement plan available.</p>";
}
return `<p>${escapeHtml(plan.summary)}</p><ul>${plan.toolsets
.map(
(toolset) =>
`<li><strong>${escapeHtml(toolset.label)}</strong> [${escapeHtml(toolset.priority)}] ${escapeHtml(toolset.goal)}</li>`,
)
.join("")}</ul>`;
}
function renderWorkflowGuide(guide) {
if (!guide) {
return "<p>No chat workflow guidance available.</p>";
}
const startHere = guide.startHere || {
chatPrompt: guide.recommendedWorkflow.chatPrompt,
routingExplanation: guide.recommendedWorkflow.summary,
startCommand: guide.recommendedWorkflow.startCommand,
firstCommand: guide.recommendedWorkflow.firstCommand,
};
return [
`<p>${escapeHtml(guide.beginnerSummary)}</p>`,
`<p><strong>Start with this chat request:</strong> ${escapeHtml(`"${startHere.chatPrompt}"`)}</p>`,
`<p><strong>Why this path:</strong> ${escapeHtml(startHere.routingExplanation)}</p>`,
`<p><strong>Quick local entrypoint:</strong> <code>${escapeHtml(startHere.startCommand)}</code></p>`,
`<p><strong>Plugin Eval will run first:</strong> <code>${escapeHtml(startHere.firstCommand)}</code></p>`,
"<h3>Other chat requests you can use</h3>",
renderList(
guide.entrypoints.map(
(entry) => `${entry.label}: say "${entry.chatPrompt}" then run ${entry.firstCommand}`,
),
),
].join("");
}
function renderNextAction(nextAction) {
if (!nextAction) {
return "<p>No recommended next step.</p>";
}
return renderList([
nextAction.label,
`Why: ${nextAction.why}`,
...(nextAction.chatPrompt ? [`Chat request: "${nextAction.chatPrompt}"`] : []),
...(nextAction.command ? [`Local command: ${nextAction.command}`] : []),
]);
}
export function renderHtml(result) {
if (result.kind === "workflow-guide") {
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Plugin Eval Start Here</title>
</head>
<body>
<main>
<h1>Plugin Eval Start Here: ${escapeHtml(result.target.name)}</h1>
${renderWorkflowGuide(result)}
<h2>Recommended Next Step</h2>
${renderNextAction(result.nextAction)}
<h2>Current Local State</h2>
${renderList([
`Benchmark config present: ${result.workflowStatus.hasBenchmarkConfig ? "yes" : "no"}`,
`Usage log present: ${result.workflowStatus.hasUsageLog ? "yes" : "no"}`,
])}
<h2>Full Local Sequence</h2>
${renderList(result.startHere?.commands || [])}
</main>
</body>
</html>`;
}
if (result.kind === "measurement-plan") {
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Measurement Plan</title>
</head>
<body>
<main>
<h1>Measurement Plan: ${escapeHtml(result.target.name)}</h1>
${renderMeasurementPlan(result)}
<h2>Recommended Next Step</h2>
${renderNextAction(result.nextAction)}
<h2>Use From Codex Chat</h2>
${renderWorkflowGuide(result.workflowGuide)}
</main>
</body>
</html>`;
}
if (result.kind === "benchmark-template-init") {
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Benchmark Template Ready</title>
</head>
<body>
<main>
<h1>Benchmark Template Ready: ${escapeHtml(result.target.name)}</h1>
<p>Config: ${escapeHtml(result.configPath)}</p>
<h2>Recommended Next Step</h2>
${renderNextAction(result.nextAction)}
<h2>Setup Questions To Ask First</h2>
${renderOptionalList(result.setupQuestions, "No setup questions provided.")}
${renderList(result.nextSteps || [])}
<h2>Use From Codex Chat</h2>
${renderWorkflowGuide(result.workflowGuide)}
</main>
</body>
</html>`;
}
if (result.kind === "benchmark-run") {
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Benchmark Run</title>
</head>
<body>
<main>
<h1>Benchmark Run: ${escapeHtml(result.target.name)}</h1>
<p>Mode: ${escapeHtml(result.mode)}</p>
<p>Codex version: ${escapeHtml(result.codexVersion || "unknown")}</p>
<p>Model: ${escapeHtml(result.config?.model || "")}</p>
<p>Workspace source: ${escapeHtml(result.config?.workspaceSourcePath || "")}</p>
<p>Run directory: ${escapeHtml(result.runDirectory || "")}</p>
<h2>Recommended Next Step</h2>
${renderNextAction(result.nextAction)}
<h2>Next Steps</h2>
${renderList(result.nextSteps || [])}
<h2>Use From Codex Chat</h2>
${renderWorkflowGuide(result.workflowGuide)}
</main>
</body>
</html>`;
}
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Plugin Eval Report</title>
<style>
:root {
color-scheme: light;
--bg: #f4faf8;
--ink: #16302b;
--accent: #0f766e;
--panel: #ffffff;
--border: #c8ece6;
}
body {
font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
background: radial-gradient(circle at top left, #d9fbe8 0, var(--bg) 40%);
color: var(--ink);
margin: 0;
padding: 2rem;
}
main {
max-width: 900px;
margin: 0 auto;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 20px;
padding: 2rem;
box-shadow: 0 20px 40px rgba(15, 118, 110, 0.08);
}
h1, h2 {
margin-top: 0;
}
.summary {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 1rem;
}
.card {
padding: 1rem;
border-radius: 16px;
background: #f0fdfa;
border: 1px solid var(--border);
}
</style>
</head>
<body>
<main>
<h1>Plugin Eval Report: ${escapeHtml(result.target.name)}</h1>
<section class="summary">
<div class="card"><strong>Score</strong><div>${escapeHtml(result.summary.score)}/100</div></div>
<div class="card"><strong>Grade</strong><div>${escapeHtml(result.summary.grade)}</div></div>
<div class="card"><strong>Risk</strong><div>${escapeHtml(result.summary.riskLevel)}</div></div>
<div class="card"><strong>Deductions</strong><div>-${escapeHtml(result.summary.scoreBreakdown?.totalDeductions || 0)}</div></div>
<div class="card"><strong>Total Tokens</strong><div>${escapeHtml(result.budgets.total_tokens?.value || 0)}</div></div>
</section>
<h2>Why It Matters</h2>
${renderList(result.summary.whyBullets || [
`Started at ${result.summary.scoreBreakdown?.startingScore || 100} and deducted ${result.summary.scoreBreakdown?.totalDeductions || 0} points.`,
`Final score: ${result.summary.scoreBreakdown?.finalScore || result.summary.score}/100.`,
])}
<h2>Fix First</h2>
${renderList((result.summary.fixFirst || []).map((item) => `${item.message} Why: ${item.why}`))}
<h2>Recommended Next Step</h2>
${renderNextAction(result.nextAction)}
<h2>Risk Assessment</h2>
${renderList(result.summary.riskReasons || [])}
<h2>Deductions</h2>
${renderDeductions(result.summary)}
<h2>Deductions By Category</h2>
${renderCategoryDeductions(result.summary)}
<h2>Recommendations</h2>
${renderList(result.summary.topRecommendations)}
<h2>Observed Usage</h2>
${renderObservedUsage(result.observedUsage)}
<h2>Measurement Plan</h2>
${renderMeasurementPlan(result.measurementPlan)}
<h2>Use From Codex Chat</h2>
${renderWorkflowGuide(result.workflowGuide)}
<h2>Checks</h2>
${renderChecks(result.checks)}
<h2>Metrics</h2>
${renderMetrics(result.metrics)}
</main>
</body>
</html>`;
}