evalvcr 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +221 -2
- package/dist/cassette.d.ts +75 -0
- package/dist/cassette.d.ts.map +1 -0
- package/dist/cassette.js +390 -0
- package/dist/cassette.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +422 -0
- package/dist/cli.js.map +1 -0
- package/dist/evalite-compat.d.ts +23 -0
- package/dist/evalite-compat.d.ts.map +1 -0
- package/dist/evalite-compat.js +19 -0
- package/dist/evalite-compat.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/ai-sdk.d.ts +14 -0
- package/dist/interceptors/ai-sdk.d.ts.map +1 -0
- package/dist/interceptors/ai-sdk.js +216 -0
- package/dist/interceptors/ai-sdk.js.map +1 -0
- package/dist/interceptors/anthropic.d.ts +15 -0
- package/dist/interceptors/anthropic.d.ts.map +1 -0
- package/dist/interceptors/anthropic.js +180 -0
- package/dist/interceptors/anthropic.js.map +1 -0
- package/dist/interceptors/fetch.d.ts +3 -0
- package/dist/interceptors/fetch.d.ts.map +1 -0
- package/dist/interceptors/fetch.js +121 -0
- package/dist/interceptors/fetch.js.map +1 -0
- package/dist/interceptors/index.d.ts +6 -0
- package/dist/interceptors/index.d.ts.map +1 -0
- package/dist/interceptors/index.js +8 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/interceptors/mcp.d.ts +70 -0
- package/dist/interceptors/mcp.d.ts.map +1 -0
- package/dist/interceptors/mcp.js +294 -0
- package/dist/interceptors/mcp.js.map +1 -0
- package/dist/interceptors/openai.d.ts +17 -0
- package/dist/interceptors/openai.d.ts.map +1 -0
- package/dist/interceptors/openai.js +210 -0
- package/dist/interceptors/openai.js.map +1 -0
- package/dist/migrate-evalite.d.ts +25 -0
- package/dist/migrate-evalite.d.ts.map +1 -0
- package/dist/migrate-evalite.js +138 -0
- package/dist/migrate-evalite.js.map +1 -0
- package/dist/report.d.ts +2 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +4 -0
- package/dist/report.js.map +1 -0
- package/dist/reporters/index.d.ts +9 -0
- package/dist/reporters/index.d.ts.map +1 -0
- package/dist/reporters/index.js +23 -0
- package/dist/reporters/index.js.map +1 -0
- package/dist/reporters/json.d.ts +3 -0
- package/dist/reporters/json.d.ts.map +1 -0
- package/dist/reporters/json.js +6 -0
- package/dist/reporters/json.js.map +1 -0
- package/dist/reporters/markdown.d.ts +3 -0
- package/dist/reporters/markdown.d.ts.map +1 -0
- package/dist/reporters/markdown.js +41 -0
- package/dist/reporters/markdown.js.map +1 -0
- package/dist/reporters/pretty.d.ts +6 -0
- package/dist/reporters/pretty.d.ts.map +1 -0
- package/dist/reporters/pretty.js +59 -0
- package/dist/reporters/pretty.js.map +1 -0
- package/dist/reporters/sarif.d.ts +43 -0
- package/dist/reporters/sarif.d.ts.map +1 -0
- package/dist/reporters/sarif.js +74 -0
- package/dist/reporters/sarif.js.map +1 -0
- package/dist/runner.d.ts +49 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +689 -0
- package/dist/runner.js.map +1 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +275 -0
- package/dist/schemas.js.map +1 -0
- package/dist/scorer-utils.d.ts +6 -0
- package/dist/scorer-utils.d.ts.map +1 -0
- package/dist/scorer-utils.js +59 -0
- package/dist/scorer-utils.js.map +1 -0
- package/dist/scrub.d.ts +25 -0
- package/dist/scrub.d.ts.map +1 -0
- package/dist/scrub.js +285 -0
- package/dist/scrub.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +493 -0
- package/dist/server.js.map +1 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +19 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/json-file.d.ts +17 -0
- package/dist/storage/json-file.d.ts.map +1 -0
- package/dist/storage/json-file.js +89 -0
- package/dist/storage/json-file.js.map +1 -0
- package/dist/storage/sqlite.d.ts +16 -0
- package/dist/storage/sqlite.d.ts.map +1 -0
- package/dist/storage/sqlite.js +125 -0
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/types.d.ts +336 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +95 -3
package/dist/server.js
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
// packages/core/src/server.ts
|
|
2
|
+
// language: TypeScript | runtime: Node >= 20 (ESM) | local zero-dependency Web UI & JSON API server
|
|
3
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
import { basename, join, resolve } from "node:path";
|
|
6
|
+
import { validateCassetteV1 } from "./schemas.js";
|
|
7
|
+
import { createLocalStorage } from "./storage/index.js";
|
|
8
|
+
const DASHBOARD_HTML = `<!doctype html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="utf-8" />
|
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
13
|
+
<title>evalvcr — Local Evaluation & Cassette Inspector</title>
|
|
14
|
+
<style>
|
|
15
|
+
:root {
|
|
16
|
+
--bg: #09090b;
|
|
17
|
+
--surface-1: #0f0f12;
|
|
18
|
+
--surface-2: #141418;
|
|
19
|
+
--surface-3: #1b1b21;
|
|
20
|
+
--border: #232329;
|
|
21
|
+
--border-strong: #32323c;
|
|
22
|
+
--text: #f4f4f5;
|
|
23
|
+
--secondary: #a1a1aa;
|
|
24
|
+
--muted: #71717a;
|
|
25
|
+
--accent: #10b981;
|
|
26
|
+
--accent-soft: rgba(16, 185, 129, 0.12);
|
|
27
|
+
--pass: #10b981;
|
|
28
|
+
--fail: #f43f5e;
|
|
29
|
+
--warn: #f59e0b;
|
|
30
|
+
--mono: "JetBrains Mono", "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
31
|
+
--sans: "Inter", "Geist", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
32
|
+
}
|
|
33
|
+
* { box-sizing: border-box; }
|
|
34
|
+
body {
|
|
35
|
+
margin: 0;
|
|
36
|
+
font-family: var(--sans);
|
|
37
|
+
font-size: 13.5px;
|
|
38
|
+
background: var(--bg);
|
|
39
|
+
color: var(--text);
|
|
40
|
+
line-height: 1.5;
|
|
41
|
+
-webkit-font-smoothing: antialiased;
|
|
42
|
+
}
|
|
43
|
+
header {
|
|
44
|
+
height: 52px;
|
|
45
|
+
padding: 0 20px;
|
|
46
|
+
border-bottom: 1px solid var(--border);
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: space-between;
|
|
50
|
+
background: var(--surface-1);
|
|
51
|
+
position: sticky;
|
|
52
|
+
top: 0;
|
|
53
|
+
z-index: 10;
|
|
54
|
+
}
|
|
55
|
+
.brand { display: flex; align-items: center; gap: 10px; }
|
|
56
|
+
.logo {
|
|
57
|
+
width: 26px; height: 26px; border-radius: 7px;
|
|
58
|
+
background: var(--surface-2); border: 1px solid var(--border-strong);
|
|
59
|
+
display: grid; place-items: center; color: var(--accent);
|
|
60
|
+
}
|
|
61
|
+
h1 { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.02em; }
|
|
62
|
+
.crumb { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 13px; }
|
|
63
|
+
.badge {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
padding: 2px 7px;
|
|
67
|
+
border-radius: 5px;
|
|
68
|
+
font-family: var(--mono);
|
|
69
|
+
font-size: 11px;
|
|
70
|
+
font-weight: 600;
|
|
71
|
+
text-transform: uppercase;
|
|
72
|
+
font-variant-numeric: tabular-nums;
|
|
73
|
+
}
|
|
74
|
+
.passed { background: rgba(16, 185, 129, 0.14); color: var(--pass); }
|
|
75
|
+
.failed { background: rgba(244, 63, 94, 0.14); color: var(--fail); }
|
|
76
|
+
.error { background: rgba(245, 158, 11, 0.14); color: var(--warn); }
|
|
77
|
+
main {
|
|
78
|
+
display: grid;
|
|
79
|
+
grid-template-columns: 320px minmax(0, 1fr);
|
|
80
|
+
min-height: calc(100vh - 52px);
|
|
81
|
+
max-width: 1480px;
|
|
82
|
+
margin: 0 auto;
|
|
83
|
+
}
|
|
84
|
+
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
|
|
85
|
+
aside {
|
|
86
|
+
border-right: 1px solid var(--border);
|
|
87
|
+
background: var(--surface-1);
|
|
88
|
+
padding: 14px;
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
gap: 16px;
|
|
92
|
+
}
|
|
93
|
+
.section-label {
|
|
94
|
+
margin: 0 0 8px;
|
|
95
|
+
font-size: 11px;
|
|
96
|
+
font-weight: 600;
|
|
97
|
+
color: var(--muted);
|
|
98
|
+
text-transform: uppercase;
|
|
99
|
+
letter-spacing: 0.06em;
|
|
100
|
+
}
|
|
101
|
+
ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
|
|
102
|
+
li.item {
|
|
103
|
+
padding: 9px 11px;
|
|
104
|
+
border: 1px solid var(--border);
|
|
105
|
+
border-left: 2px solid transparent;
|
|
106
|
+
background: var(--surface-2);
|
|
107
|
+
border-radius: 7px;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
transition: background 0.12s ease, border-color 0.12s ease;
|
|
110
|
+
}
|
|
111
|
+
li.item:hover { background: var(--surface-3); border-color: var(--border-strong); }
|
|
112
|
+
li.item.active { background: var(--surface-3); border-color: var(--border-strong); border-left-color: var(--accent); }
|
|
113
|
+
.meta { font-size: 11.5px; color: var(--muted); font-family: var(--mono); font-variant-numeric: tabular-nums; }
|
|
114
|
+
.workspace-pane { padding: 16px 20px; min-width: 0; }
|
|
115
|
+
.tabs {
|
|
116
|
+
display: flex; gap: 4px;
|
|
117
|
+
border-bottom: 1px solid var(--border);
|
|
118
|
+
margin-bottom: 14px;
|
|
119
|
+
}
|
|
120
|
+
button.tab {
|
|
121
|
+
background: transparent;
|
|
122
|
+
color: var(--secondary);
|
|
123
|
+
border: none;
|
|
124
|
+
border-bottom: 2px solid transparent;
|
|
125
|
+
padding: 8px 12px;
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
font-size: 12.5px;
|
|
128
|
+
font-weight: 500;
|
|
129
|
+
}
|
|
130
|
+
button.tab:hover { color: var(--text); }
|
|
131
|
+
button.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
|
|
132
|
+
button.btn {
|
|
133
|
+
background: var(--surface-2);
|
|
134
|
+
color: var(--text);
|
|
135
|
+
border: 1px solid var(--border);
|
|
136
|
+
padding: 6px 11px;
|
|
137
|
+
border-radius: 6px;
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
font-size: 12.5px;
|
|
140
|
+
font-weight: 500;
|
|
141
|
+
}
|
|
142
|
+
button.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
|
|
143
|
+
.kpi-row {
|
|
144
|
+
display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
145
|
+
border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
|
|
146
|
+
background: var(--surface-1); margin-bottom: 14px;
|
|
147
|
+
}
|
|
148
|
+
.kpi-cell { padding: 10px 12px; border-right: 1px solid var(--border); }
|
|
149
|
+
.kpi-cell:last-child { border-right: none; }
|
|
150
|
+
.kpi-val { font-family: var(--mono); font-size: 16px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
|
|
151
|
+
.card-row {
|
|
152
|
+
margin: 8px 0; padding: 10px 12px;
|
|
153
|
+
border: 1px solid var(--border); border-radius: 8px;
|
|
154
|
+
background: var(--surface-1);
|
|
155
|
+
}
|
|
156
|
+
pre {
|
|
157
|
+
background: var(--surface-1);
|
|
158
|
+
border: 1px solid var(--border);
|
|
159
|
+
border-radius: 8px;
|
|
160
|
+
padding: 12px 14px;
|
|
161
|
+
overflow-x: auto;
|
|
162
|
+
font-family: var(--mono);
|
|
163
|
+
font-size: 12px;
|
|
164
|
+
line-height: 1.55;
|
|
165
|
+
color: #d4d4d8;
|
|
166
|
+
}
|
|
167
|
+
</style>
|
|
168
|
+
</head>
|
|
169
|
+
<body>
|
|
170
|
+
<header>
|
|
171
|
+
<div class="brand">
|
|
172
|
+
<div class="logo">
|
|
173
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="20" height="14" rx="3"/><circle cx="8.5" cy="12" r="2.2"/><circle cx="15.5" cy="12" r="2.2"/><line x1="10.7" y1="12" x2="13.3" y2="12"/></svg>
|
|
174
|
+
</div>
|
|
175
|
+
<h1>evalvcr <span class="crumb">/ Local Inspector</span></h1>
|
|
176
|
+
</div>
|
|
177
|
+
<button class="btn" id="refreshBtn">Refresh</button>
|
|
178
|
+
</header>
|
|
179
|
+
<main>
|
|
180
|
+
<aside>
|
|
181
|
+
<div>
|
|
182
|
+
<h2 class="section-label">Eval Runs</h2>
|
|
183
|
+
<ul id="runsList"><li class="meta">Loading...</li></ul>
|
|
184
|
+
</div>
|
|
185
|
+
<div>
|
|
186
|
+
<h2 class="section-label">Cassettes</h2>
|
|
187
|
+
<ul id="cassettesList"><li class="meta">Loading...</li></ul>
|
|
188
|
+
</div>
|
|
189
|
+
</aside>
|
|
190
|
+
<section class="workspace-pane">
|
|
191
|
+
<div class="tabs">
|
|
192
|
+
<button class="tab active" id="viewPrettyBtn">Summary</button>
|
|
193
|
+
<button class="tab" id="viewRawBtn">Raw JSON</button>
|
|
194
|
+
</div>
|
|
195
|
+
<div id="detailPane"><p class="meta">Select a run or cassette to inspect.</p></div>
|
|
196
|
+
</section>
|
|
197
|
+
</main>
|
|
198
|
+
<script>
|
|
199
|
+
let currentData = null;
|
|
200
|
+
let viewMode = "pretty";
|
|
201
|
+
let activeKey = "";
|
|
202
|
+
const runsList = document.getElementById("runsList");
|
|
203
|
+
const cassettesList = document.getElementById("cassettesList");
|
|
204
|
+
const detailPane = document.getElementById("detailPane");
|
|
205
|
+
const viewPrettyBtn = document.getElementById("viewPrettyBtn");
|
|
206
|
+
const viewRawBtn = document.getElementById("viewRawBtn");
|
|
207
|
+
|
|
208
|
+
function esc(s) {
|
|
209
|
+
return String(s).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function syncTabs() {
|
|
213
|
+
viewPrettyBtn.classList.toggle("active", viewMode === "pretty");
|
|
214
|
+
viewRawBtn.classList.toggle("active", viewMode === "raw");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function renderDetail() {
|
|
218
|
+
syncTabs();
|
|
219
|
+
if (!currentData) {
|
|
220
|
+
detailPane.innerHTML = '<p class="meta">Select a run or cassette to inspect.</p>';
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (viewMode === "raw") {
|
|
224
|
+
detailPane.innerHTML = "<pre>" + esc(JSON.stringify(currentData, null, 2)) + "</pre>";
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (currentData.schemaVersion === "evalvcr.report.v1") {
|
|
228
|
+
const s = currentData.summary || {};
|
|
229
|
+
let html = '<h3 style="margin:0 0 10px">Run ' + esc(currentData.runId) + ' <span class="badge ' + esc(currentData.status) + '">' + esc(currentData.status) + '</span></h3>';
|
|
230
|
+
html += '<div class="kpi-row">'
|
|
231
|
+
+ '<div class="kpi-cell"><div class="meta">MODE</div><div class="kpi-val">' + esc(currentData.mode) + '</div></div>'
|
|
232
|
+
+ '<div class="kpi-cell"><div class="meta">AVG SCORE</div><div class="kpi-val">' + ((s.averageScore || 0) * 100).toFixed(1) + '%</div></div>'
|
|
233
|
+
+ '<div class="kpi-cell"><div class="meta">CASES</div><div class="kpi-val">' + (s.casesPassed || 0) + '/' + (s.casesTotal || 0) + '</div></div>'
|
|
234
|
+
+ '<div class="kpi-cell"><div class="meta">FINDINGS</div><div class="kpi-val">' + (s.findingsCount || 0) + '</div></div>'
|
|
235
|
+
+ '</div>';
|
|
236
|
+
for (const suite of currentData.suites || []) {
|
|
237
|
+
html += '<div style="margin-top:12px"><strong>' + esc(suite.name) + '</strong> <span class="meta">(' + ((suite.averageScore || 0) * 100).toFixed(1) + '%)</span>';
|
|
238
|
+
for (const tc of suite.cases || []) {
|
|
239
|
+
html += '<div class="card-row" style="border-left:2px solid ' + (tc.passed ? 'var(--pass)' : 'var(--fail)') + '">';
|
|
240
|
+
html += '<div>' + esc(tc.name) + ' — <span class="meta">' + ((tc.averageScore || 0) * 100).toFixed(1) + '%</span></div>';
|
|
241
|
+
html += '<div class="meta">' + (tc.trials || []).length + ' trial(s) · ' + tc.durationMs + ' ms</div>';
|
|
242
|
+
html += '</div>';
|
|
243
|
+
}
|
|
244
|
+
html += '</div>';
|
|
245
|
+
}
|
|
246
|
+
detailPane.innerHTML = html;
|
|
247
|
+
} else {
|
|
248
|
+
let html = '<h3 style="margin:0 0 8px">Cassette: ' + esc(currentData.name) + '</h3>';
|
|
249
|
+
html += '<p class="meta">Interactions: ' + (currentData.interactions || []).length + ' · Redacted: ' + (currentData.scrubbing?.redactedCount || 0) + '</p>';
|
|
250
|
+
for (const ix of currentData.interactions || []) {
|
|
251
|
+
html += '<div class="card-row">';
|
|
252
|
+
html += '<div><strong>#' + ix.seq + ' ' + esc(ix.kind) + '</strong> <span class="meta">(' + esc(ix.provider) + ') · ' + ix.durationMs + ' ms</span></div>';
|
|
253
|
+
html += '<div class="meta">Target: ' + esc(ix.request?.target || '') + '</div>';
|
|
254
|
+
html += '<div class="meta">SHA-256: ' + esc(ix.fingerprint) + '</div>';
|
|
255
|
+
html += '</div>';
|
|
256
|
+
}
|
|
257
|
+
detailPane.innerHTML = html;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function markActive(key) {
|
|
262
|
+
activeKey = key;
|
|
263
|
+
document.querySelectorAll("li.item").forEach((el) => {
|
|
264
|
+
el.classList.toggle("active", el.dataset.key === activeKey);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function loadAll() {
|
|
269
|
+
const [runsRes, casRes] = await Promise.all([fetch("/api/runs"), fetch("/api/cassettes")]);
|
|
270
|
+
const runsData = await runsRes.json();
|
|
271
|
+
const casData = await casRes.json();
|
|
272
|
+
const runs = runsData.runs || [];
|
|
273
|
+
const cassettes = casData.cassettes || [];
|
|
274
|
+
runsList.innerHTML = runs.length ? "" : '<li class="meta">No eval runs recorded yet.</li>';
|
|
275
|
+
for (const r of runs) {
|
|
276
|
+
const li = document.createElement("li");
|
|
277
|
+
li.className = "item";
|
|
278
|
+
li.dataset.key = "run:" + r.runId;
|
|
279
|
+
li.innerHTML = '<div><span class="badge ' + esc(r.status) + '">' + esc(r.status) + '</span> <strong style="font-family:var(--mono)">' + ((r.averageScore || 0) * 100).toFixed(1) + '%</strong></div><div class="meta">' + esc(r.createdAt) + '</div>';
|
|
280
|
+
li.onclick = async () => {
|
|
281
|
+
markActive(li.dataset.key);
|
|
282
|
+
const res = await fetch("/api/runs/" + encodeURIComponent(r.runId));
|
|
283
|
+
currentData = await res.json();
|
|
284
|
+
renderDetail();
|
|
285
|
+
};
|
|
286
|
+
runsList.appendChild(li);
|
|
287
|
+
}
|
|
288
|
+
cassettesList.innerHTML = cassettes.length ? "" : '<li class="meta">No cassettes found.</li>';
|
|
289
|
+
for (const c of cassettes) {
|
|
290
|
+
const li = document.createElement("li");
|
|
291
|
+
li.className = "item";
|
|
292
|
+
li.dataset.key = "cas:" + c.file;
|
|
293
|
+
li.innerHTML = '<div><strong>' + esc(c.name) + '</strong></div><div class="meta">' + c.interactionCount + ' interaction(s)</div>';
|
|
294
|
+
li.onclick = async () => {
|
|
295
|
+
markActive(li.dataset.key);
|
|
296
|
+
const res = await fetch("/api/cassettes/" + encodeURIComponent(c.file));
|
|
297
|
+
currentData = await res.json();
|
|
298
|
+
renderDetail();
|
|
299
|
+
};
|
|
300
|
+
cassettesList.appendChild(li);
|
|
301
|
+
}
|
|
302
|
+
if (activeKey) markActive(activeKey);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
document.getElementById("refreshBtn").onclick = loadAll;
|
|
306
|
+
viewPrettyBtn.onclick = () => { viewMode = "pretty"; renderDetail(); };
|
|
307
|
+
viewRawBtn.onclick = () => { viewMode = "raw"; renderDetail(); };
|
|
308
|
+
loadAll();
|
|
309
|
+
</script>
|
|
310
|
+
</body>
|
|
311
|
+
</html>
|
|
312
|
+
`;
|
|
313
|
+
function sendJson(res, status, data) {
|
|
314
|
+
const body = JSON.stringify(data, null, 2);
|
|
315
|
+
res.writeHead(status, {
|
|
316
|
+
"content-type": "application/json; charset=utf-8",
|
|
317
|
+
"cache-control": "no-store",
|
|
318
|
+
});
|
|
319
|
+
res.end(body);
|
|
320
|
+
}
|
|
321
|
+
function sendHtml(res, status, html) {
|
|
322
|
+
res.writeHead(status, {
|
|
323
|
+
"content-type": "text/html; charset=utf-8",
|
|
324
|
+
"cache-control": "no-store",
|
|
325
|
+
});
|
|
326
|
+
res.end(html);
|
|
327
|
+
}
|
|
328
|
+
function listCassettes(cassetteDir) {
|
|
329
|
+
if (!existsSync(cassetteDir)) {
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
const entries = readdirSync(cassetteDir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
333
|
+
const out = [];
|
|
334
|
+
for (const entry of entries) {
|
|
335
|
+
if (!entry.isFile() || !entry.name.endsWith(".json")) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const raw = JSON.parse(readFileSync(join(cassetteDir, entry.name), "utf8"));
|
|
340
|
+
const validated = validateCassetteV1(raw);
|
|
341
|
+
if (validated.valid) {
|
|
342
|
+
const c = validated.data;
|
|
343
|
+
out.push({
|
|
344
|
+
file: entry.name,
|
|
345
|
+
name: c.name,
|
|
346
|
+
interactionCount: c.interactions.length,
|
|
347
|
+
redactedCount: c.scrubbing.redactedCount,
|
|
348
|
+
updatedAt: c.updatedAt,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
// Skip unreadable/invalid cassette files
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return out;
|
|
357
|
+
}
|
|
358
|
+
function readCassetteByName(cassetteDir, nameOrFile) {
|
|
359
|
+
if (!existsSync(cassetteDir)) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
const safeName = basename(decodeURIComponent(nameOrFile));
|
|
363
|
+
const candidates = safeName.endsWith(".json")
|
|
364
|
+
? [safeName]
|
|
365
|
+
: [`${safeName}.evalvcr.json`, `${safeName}.json`, safeName];
|
|
366
|
+
const baseDir = resolve(cassetteDir);
|
|
367
|
+
for (const cand of candidates) {
|
|
368
|
+
const full = resolve(baseDir, cand);
|
|
369
|
+
if (!full.startsWith(baseDir) || !existsSync(full)) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const parsed = JSON.parse(readFileSync(full, "utf8"));
|
|
374
|
+
const validated = validateCassetteV1(parsed);
|
|
375
|
+
if (validated.valid) {
|
|
376
|
+
return validated.data;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
export async function startServer(options = {}) {
|
|
386
|
+
const host = options.host ?? "127.0.0.1";
|
|
387
|
+
const port = options.port ?? 4310;
|
|
388
|
+
const storageDir = options.storageDir ?? ".evalvcr";
|
|
389
|
+
const cassetteDir = options.cassetteDir ?? join(storageDir, "cassettes");
|
|
390
|
+
const storage = await createLocalStorage(storageDir);
|
|
391
|
+
const server = createServer(async (req, res) => {
|
|
392
|
+
try {
|
|
393
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
394
|
+
const urlObj = new URL(req.url ?? "/", `http://${host}`);
|
|
395
|
+
const pathname = urlObj.pathname;
|
|
396
|
+
if (method === "GET" && pathname === "/") {
|
|
397
|
+
sendHtml(res, 200, DASHBOARD_HTML);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (method === "GET" && pathname === "/api/health") {
|
|
401
|
+
sendJson(res, 200, {
|
|
402
|
+
ok: true,
|
|
403
|
+
service: "evalvcr",
|
|
404
|
+
timestamp: new Date().toISOString(),
|
|
405
|
+
});
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (method === "GET" && pathname === "/api/runs") {
|
|
409
|
+
const limitParam = urlObj.searchParams.get("limit");
|
|
410
|
+
const branchParam = urlObj.searchParams.get("branch") ?? undefined;
|
|
411
|
+
const limit = limitParam ? Number(limitParam) : undefined;
|
|
412
|
+
const runs = await storage.listRuns({
|
|
413
|
+
...(limit !== undefined && Number.isFinite(limit) ? { limit } : {}),
|
|
414
|
+
...(branchParam ? { branch: branchParam } : {}),
|
|
415
|
+
});
|
|
416
|
+
sendJson(res, 200, { runs });
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (method === "GET" && pathname.startsWith("/api/runs/")) {
|
|
420
|
+
const runId = decodeURIComponent(pathname.slice("/api/runs/".length));
|
|
421
|
+
const run = await storage.getRun(runId);
|
|
422
|
+
if (!run) {
|
|
423
|
+
sendJson(res, 404, { error: `Run not found: ${runId}` });
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
sendJson(res, 200, run);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (method === "GET" && pathname === "/api/cassettes") {
|
|
430
|
+
const cassettes = listCassettes(cassetteDir);
|
|
431
|
+
sendJson(res, 200, { cassettes });
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (method === "GET" && pathname.startsWith("/api/cassettes/")) {
|
|
435
|
+
const name = pathname.slice("/api/cassettes/".length);
|
|
436
|
+
const cassette = readCassetteByName(cassetteDir, name);
|
|
437
|
+
if (!cassette) {
|
|
438
|
+
sendJson(res, 404, { error: `Cassette not found: ${name}` });
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
sendJson(res, 200, cassette);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
sendJson(res, 404, { error: "Not found" });
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
sendJson(res, 500, {
|
|
448
|
+
error: err instanceof Error ? err.message : String(err),
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
453
|
+
const onError = (err) => {
|
|
454
|
+
server.off("listening", onListening);
|
|
455
|
+
rejectListen(err);
|
|
456
|
+
};
|
|
457
|
+
const onListening = () => {
|
|
458
|
+
server.off("error", onError);
|
|
459
|
+
resolveListen();
|
|
460
|
+
};
|
|
461
|
+
server.once("error", onError);
|
|
462
|
+
server.once("listening", onListening);
|
|
463
|
+
server.listen(port, host);
|
|
464
|
+
});
|
|
465
|
+
const addr = server.address();
|
|
466
|
+
const actualPort = typeof addr === "object" && addr !== null ? addr.port : port;
|
|
467
|
+
const actualHost = typeof addr === "object" && addr !== null && addr.address !== "::"
|
|
468
|
+
? addr.address
|
|
469
|
+
: host;
|
|
470
|
+
const url = `http://${actualHost}:${actualPort}`;
|
|
471
|
+
const close = async () => {
|
|
472
|
+
server.closeAllConnections?.();
|
|
473
|
+
await new Promise((resolveClose, rejectClose) => {
|
|
474
|
+
server.close((err) => {
|
|
475
|
+
if (err) {
|
|
476
|
+
rejectClose(err);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
resolveClose();
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
await storage.close();
|
|
484
|
+
};
|
|
485
|
+
return {
|
|
486
|
+
url,
|
|
487
|
+
host: actualHost,
|
|
488
|
+
port: actualPort,
|
|
489
|
+
server,
|
|
490
|
+
close,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,oGAAoG;AAEpG,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAkBxD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgTtB,CAAC;AAEF,SAAS,QAAQ,CAAC,GAAmB,EAAE,MAAc,EAAE,IAAa;IAClE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC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YACpD,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACnB,IAAI,GAAG,EAAE,CAAC;oBACR,WAAW,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,YAAY,EAAE,CAAC;gBACjB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC,CAAC;IAEF,OAAO;QACL,GAAG;QACH,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,UAAU;QAChB,MAAM;QACN,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,wBAAsB,kBAAkB,CAAC,GAAG,SAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAU/E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// packages/core/src/storage/index.ts
|
|
2
|
+
// language: TypeScript | runtime: Node >= 20 (ESM) | storage factory with node:sqlite + JSON fallback
|
|
3
|
+
import { JsonFileStorage } from "./json-file.js";
|
|
4
|
+
import { SqliteStorage } from "./sqlite.js";
|
|
5
|
+
export { JsonFileStorage } from "./json-file.js";
|
|
6
|
+
export { SqliteStorage } from "./sqlite.js";
|
|
7
|
+
export async function createLocalStorage(dir = ".evalvcr") {
|
|
8
|
+
try {
|
|
9
|
+
const sqlite = new SqliteStorage(dir);
|
|
10
|
+
await sqlite.init();
|
|
11
|
+
return sqlite;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
const jsonStore = new JsonFileStorage(dir);
|
|
15
|
+
await jsonStore.init();
|
|
16
|
+
return jsonStore;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,sGAAsG;AAGtG,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAG,GAAG,UAAU;IACvD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,SAAS,GAAG,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EvalStorage, ReportV1, RunSummaryRecord } from "../types.js";
|
|
2
|
+
export declare class JsonFileStorage implements EvalStorage {
|
|
3
|
+
readonly filePath: string;
|
|
4
|
+
private runs;
|
|
5
|
+
private initialized;
|
|
6
|
+
constructor(dirOrFilePath?: string);
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
private persist;
|
|
9
|
+
saveRun(report: ReportV1): Promise<void>;
|
|
10
|
+
getRun(runId: string): Promise<ReportV1 | null>;
|
|
11
|
+
listRuns(opts?: {
|
|
12
|
+
limit?: number;
|
|
13
|
+
branch?: string;
|
|
14
|
+
}): Promise<RunSummaryRecord[]>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=json-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-file.d.ts","sourceRoot":"","sources":["../../src/storage/json-file.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAO3E,qBAAa,eAAgB,YAAW,WAAW;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,WAAW,CAAS;gBAEhB,aAAa,SAAa;IAMhC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAe3B,OAAO,CAAC,OAAO;IAWT,OAAO,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAO/C,QAAQ,CAAC,IAAI,CAAC,EAAE;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IA6BzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// packages/core/src/storage/json-file.ts
|
|
2
|
+
// language: TypeScript | runtime: Node >= 20 (ESM) | pure-JS JSON file history storage
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
export class JsonFileStorage {
|
|
6
|
+
filePath;
|
|
7
|
+
runs = [];
|
|
8
|
+
initialized = false;
|
|
9
|
+
constructor(dirOrFilePath = ".evalvcr") {
|
|
10
|
+
this.filePath = dirOrFilePath.endsWith(".json")
|
|
11
|
+
? dirOrFilePath
|
|
12
|
+
: join(dirOrFilePath, "history.json");
|
|
13
|
+
}
|
|
14
|
+
async init() {
|
|
15
|
+
if (this.initialized) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
mkdirSync(dirname(this.filePath), { recursive: true });
|
|
19
|
+
if (existsSync(this.filePath)) {
|
|
20
|
+
const raw = readFileSync(this.filePath, "utf8").trim();
|
|
21
|
+
if (raw.length > 0) {
|
|
22
|
+
const parsed = JSON.parse(raw);
|
|
23
|
+
this.runs = Array.isArray(parsed.runs) ? parsed.runs : [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
this.initialized = true;
|
|
27
|
+
}
|
|
28
|
+
persist() {
|
|
29
|
+
mkdirSync(dirname(this.filePath), { recursive: true });
|
|
30
|
+
const tmpPath = `${this.filePath}.tmp`;
|
|
31
|
+
const payload = {
|
|
32
|
+
version: 1,
|
|
33
|
+
runs: this.runs,
|
|
34
|
+
};
|
|
35
|
+
writeFileSync(tmpPath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
|
|
36
|
+
renameSync(tmpPath, this.filePath);
|
|
37
|
+
}
|
|
38
|
+
async saveRun(report) {
|
|
39
|
+
if (!this.initialized) {
|
|
40
|
+
await this.init();
|
|
41
|
+
}
|
|
42
|
+
const idx = this.runs.findIndex((r) => r.runId === report.runId);
|
|
43
|
+
if (idx >= 0) {
|
|
44
|
+
this.runs[idx] = report;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.runs.unshift(report);
|
|
48
|
+
}
|
|
49
|
+
// Keep up to 500 most recent runs to bound disk usage
|
|
50
|
+
if (this.runs.length > 500) {
|
|
51
|
+
this.runs = this.runs.slice(0, 500);
|
|
52
|
+
}
|
|
53
|
+
this.persist();
|
|
54
|
+
}
|
|
55
|
+
async getRun(runId) {
|
|
56
|
+
if (!this.initialized) {
|
|
57
|
+
await this.init();
|
|
58
|
+
}
|
|
59
|
+
return this.runs.find((r) => r.runId === runId) ?? null;
|
|
60
|
+
}
|
|
61
|
+
async listRuns(opts) {
|
|
62
|
+
if (!this.initialized) {
|
|
63
|
+
await this.init();
|
|
64
|
+
}
|
|
65
|
+
const limit = Math.max(1, Math.min(opts?.limit ?? 50, 500));
|
|
66
|
+
const filtered = opts?.branch
|
|
67
|
+
? this.runs.filter((r) => r.runtime.branch === opts.branch)
|
|
68
|
+
: this.runs;
|
|
69
|
+
const sorted = [...filtered].sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
70
|
+
return sorted.slice(0, limit).map((r) => ({
|
|
71
|
+
runId: r.runId,
|
|
72
|
+
createdAt: r.createdAt,
|
|
73
|
+
status: r.status,
|
|
74
|
+
mode: r.mode,
|
|
75
|
+
averageScore: r.summary.averageScore,
|
|
76
|
+
passRate: r.summary.passRate,
|
|
77
|
+
durationMs: r.durationMs,
|
|
78
|
+
casesTotal: r.summary.casesTotal,
|
|
79
|
+
casesPassed: r.summary.casesPassed,
|
|
80
|
+
findingsCount: r.summary.findingsCount,
|
|
81
|
+
...(r.runtime.branch !== undefined ? { branch: r.runtime.branch } : {}),
|
|
82
|
+
...(r.runtime.gitSha !== undefined ? { gitSha: r.runtime.gitSha } : {}),
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
async close() {
|
|
86
|
+
this.initialized = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=json-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-file.js","sourceRoot":"","sources":["../../src/storage/json-file.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,uFAAuF;AAEvF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQ1C,MAAM,OAAO,eAAe;IACjB,QAAQ,CAAS;I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