@warmdrift/kgauto-compiler 2.0.0-alpha.7 → 2.0.0-alpha.71

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.
Files changed (55) hide show
  1. package/README.md +176 -46
  2. package/dist/brain-proxy.d.mts +113 -0
  3. package/dist/brain-proxy.d.ts +113 -0
  4. package/dist/brain-proxy.js +193 -0
  5. package/dist/brain-proxy.mjs +6 -0
  6. package/dist/chunk-4UO4CCSP.mjs +1620 -0
  7. package/dist/chunk-65ZMX5OT.mjs +169 -0
  8. package/dist/{chunk-5TI6PNSK.mjs → chunk-BVEXV5KC.mjs} +11 -0
  9. package/dist/chunk-NBO4R5PC.mjs +313 -0
  10. package/dist/chunk-P3TOAEG4.mjs +56 -0
  11. package/dist/chunk-RO22VFIF.mjs +29 -0
  12. package/dist/chunk-SBFSYCQG.mjs +719 -0
  13. package/dist/chunk-URFQR3SB.mjs +203 -0
  14. package/dist/dialect.d.mts +41 -3
  15. package/dist/dialect.d.ts +41 -3
  16. package/dist/dialect.js +14 -2
  17. package/dist/dialect.mjs +5 -3
  18. package/dist/glassbox/index.d.mts +59 -0
  19. package/dist/glassbox/index.d.ts +59 -0
  20. package/dist/glassbox/index.js +312 -0
  21. package/dist/glassbox/index.mjs +12 -0
  22. package/dist/glassbox-routes/format.d.mts +24 -0
  23. package/dist/glassbox-routes/format.d.ts +24 -0
  24. package/dist/glassbox-routes/format.js +86 -0
  25. package/dist/glassbox-routes/format.mjs +18 -0
  26. package/dist/glassbox-routes/index.d.mts +191 -0
  27. package/dist/glassbox-routes/index.d.ts +191 -0
  28. package/dist/glassbox-routes/index.js +2888 -0
  29. package/dist/glassbox-routes/index.mjs +667 -0
  30. package/dist/glassbox-routes/react/index.d.mts +74 -0
  31. package/dist/glassbox-routes/react/index.d.ts +74 -0
  32. package/dist/glassbox-routes/react/index.js +819 -0
  33. package/dist/glassbox-routes/react/index.mjs +754 -0
  34. package/dist/index.d.mts +2745 -17
  35. package/dist/index.d.ts +2745 -17
  36. package/dist/index.js +9006 -1651
  37. package/dist/index.mjs +5103 -367
  38. package/dist/ir-BEQ28muo.d.ts +1608 -0
  39. package/dist/ir-CnnJST_N.d.mts +1608 -0
  40. package/dist/key-health.d.mts +131 -0
  41. package/dist/key-health.d.ts +131 -0
  42. package/dist/key-health.js +228 -0
  43. package/dist/key-health.mjs +6 -0
  44. package/dist/profiles.d.mts +292 -2
  45. package/dist/profiles.d.ts +292 -2
  46. package/dist/profiles.js +1231 -16
  47. package/dist/profiles.mjs +9 -1
  48. package/dist/types-B--CYzMo.d.ts +131 -0
  49. package/dist/types-BDFrJkma.d.mts +131 -0
  50. package/dist/types-DSeJJ6tt.d.ts +149 -0
  51. package/dist/types-DeGRCTlJ.d.mts +149 -0
  52. package/package.json +54 -8
  53. package/dist/chunk-MBEI5UOM.mjs +0 -409
  54. package/dist/profiles-B3eNQ2py.d.ts +0 -619
  55. package/dist/profiles-Py8c7zjJ.d.mts +0 -619
@@ -0,0 +1,754 @@
1
+ import {
2
+ formatAgo,
3
+ formatCost,
4
+ formatMs,
5
+ formatMutation,
6
+ formatOrDash,
7
+ inputRatioLabel,
8
+ shortTraceId
9
+ } from "../../chunk-P3TOAEG4.mjs";
10
+
11
+ // src/glassbox-routes/react/theme.ts
12
+ var DEFAULT_GLASSBOX_THEME = {
13
+ colors: {
14
+ surface: "#F8FAFC",
15
+ border: "#E2E8F0",
16
+ borderSoft: "#F1F5F9",
17
+ cardBg: "#FFFFFF",
18
+ text: "#1E293B",
19
+ textMuted: "#64748B",
20
+ textFaint: "#94A3B8",
21
+ ok: "#15803D",
22
+ warn: "#B45309",
23
+ fail: "#B91C1C",
24
+ info: "#1D4ED8"
25
+ },
26
+ fonts: {
27
+ sans: 'system-ui, -apple-system, "Segoe UI", sans-serif',
28
+ serif: 'Georgia, "Times New Roman", serif',
29
+ mono: "ui-monospace, Menlo, Consolas, monospace"
30
+ }
31
+ };
32
+
33
+ // src/glassbox-routes/react/GlassboxTraceCard.tsx
34
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
35
+ function Card({ children, title, emphasis = "default", theme }) {
36
+ const { colors, fonts } = theme;
37
+ const accentColor = emphasis === "coaching" ? colors.warn : emphasis === "counterfactuals" ? colors.ok : emphasis === "mutations" ? colors.textMuted : null;
38
+ return /* @__PURE__ */ jsxs(
39
+ "div",
40
+ {
41
+ style: {
42
+ background: colors.cardBg,
43
+ border: `1px solid ${colors.border}`,
44
+ borderLeft: accentColor ? `4px solid ${accentColor}` : `1px solid ${colors.border}`,
45
+ borderRadius: 6,
46
+ padding: 14,
47
+ marginBottom: 10
48
+ },
49
+ children: [
50
+ title && /* @__PURE__ */ jsx(
51
+ "div",
52
+ {
53
+ style: {
54
+ fontSize: 11,
55
+ fontWeight: 600,
56
+ textTransform: "uppercase",
57
+ letterSpacing: 0.4,
58
+ color: colors.textMuted,
59
+ fontFamily: fonts.sans,
60
+ marginBottom: 8
61
+ },
62
+ children: title
63
+ }
64
+ ),
65
+ children
66
+ ]
67
+ }
68
+ );
69
+ }
70
+ function HealthDot({
71
+ axis,
72
+ status,
73
+ theme
74
+ }) {
75
+ const { colors } = theme;
76
+ const color = status === "green" ? colors.ok : status === "yellow" ? colors.warn : status === "red" ? colors.fail : colors.textFaint;
77
+ return /* @__PURE__ */ jsx(
78
+ "span",
79
+ {
80
+ title: `${axis}: ${status}`,
81
+ "aria-label": `${axis} ${status}`,
82
+ style: {
83
+ display: "inline-block",
84
+ width: 8,
85
+ height: 8,
86
+ borderRadius: "50%",
87
+ background: color,
88
+ marginRight: 6
89
+ }
90
+ }
91
+ );
92
+ }
93
+ function AdvisoryRow({
94
+ advisory,
95
+ theme
96
+ }) {
97
+ const { colors, fonts } = theme;
98
+ const color = advisory.level === "critical" ? colors.fail : advisory.level === "warn" ? colors.warn : colors.info;
99
+ return /* @__PURE__ */ jsxs(
100
+ "div",
101
+ {
102
+ style: {
103
+ display: "flex",
104
+ flexWrap: "wrap",
105
+ gap: 8,
106
+ alignItems: "baseline",
107
+ padding: "6px 0",
108
+ borderTop: `1px solid ${colors.borderSoft}`,
109
+ fontFamily: fonts.sans,
110
+ fontSize: 13
111
+ },
112
+ children: [
113
+ /* @__PURE__ */ jsx(
114
+ "span",
115
+ {
116
+ style: {
117
+ fontFamily: fonts.mono,
118
+ fontSize: 11,
119
+ color,
120
+ fontWeight: 600,
121
+ minWidth: 140
122
+ },
123
+ children: advisory.code
124
+ }
125
+ ),
126
+ /* @__PURE__ */ jsx("span", { style: { color: colors.text, flex: 1 }, children: advisory.message }),
127
+ advisory.suggestedAdaptation && /* @__PURE__ */ jsxs(
128
+ "span",
129
+ {
130
+ style: {
131
+ fontFamily: fonts.mono,
132
+ fontSize: 11,
133
+ color: colors.textMuted
134
+ },
135
+ title: advisory.suggestedAdaptation.consequence,
136
+ children: [
137
+ "\u2192 try ",
138
+ advisory.suggestedAdaptation.parameter,
139
+ ":\xA0",
140
+ String(advisory.suggestedAdaptation.value)
141
+ ]
142
+ }
143
+ )
144
+ ]
145
+ }
146
+ );
147
+ }
148
+ function SectionRewriteRow({
149
+ rewrite,
150
+ theme
151
+ }) {
152
+ const { colors, fonts } = theme;
153
+ return /* @__PURE__ */ jsxs(
154
+ "div",
155
+ {
156
+ style: {
157
+ display: "flex",
158
+ flexWrap: "wrap",
159
+ gap: 8,
160
+ alignItems: "baseline",
161
+ padding: "6px 0",
162
+ borderTop: `1px solid ${colors.borderSoft}`,
163
+ fontFamily: fonts.sans,
164
+ fontSize: 13
165
+ },
166
+ title: `${rewrite.rule} \xB7 ${rewrite.kind} \xB7 ${rewrite.sectionId}`,
167
+ children: [
168
+ /* @__PURE__ */ jsx(
169
+ "span",
170
+ {
171
+ style: {
172
+ fontFamily: fonts.mono,
173
+ fontSize: 11,
174
+ color: colors.info,
175
+ fontWeight: 600,
176
+ minWidth: 140
177
+ },
178
+ children: "translator-rewrite"
179
+ }
180
+ ),
181
+ /* @__PURE__ */ jsx("span", { style: { color: colors.text, flex: 1 }, children: rewrite.summary })
182
+ ]
183
+ }
184
+ );
185
+ }
186
+ function CounterfactualAsAdvisoryRow({
187
+ cf,
188
+ theme
189
+ }) {
190
+ const { colors, fonts } = theme;
191
+ return /* @__PURE__ */ jsxs(
192
+ "div",
193
+ {
194
+ style: {
195
+ display: "flex",
196
+ flexWrap: "wrap",
197
+ gap: 8,
198
+ alignItems: "baseline",
199
+ padding: "6px 0",
200
+ borderTop: `1px solid ${colors.borderSoft}`,
201
+ fontFamily: fonts.sans,
202
+ fontSize: 13
203
+ },
204
+ children: [
205
+ /* @__PURE__ */ jsx(
206
+ "span",
207
+ {
208
+ style: {
209
+ fontFamily: fonts.mono,
210
+ fontSize: 11,
211
+ color: colors.info,
212
+ fontWeight: 600,
213
+ minWidth: 140
214
+ },
215
+ children: "cheaper-alternative"
216
+ }
217
+ ),
218
+ /* @__PURE__ */ jsxs("span", { style: { color: colors.text, flex: 1 }, children: [
219
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: fonts.serif, fontWeight: 600, fontSize: 15 }, children: cf.modelId }),
220
+ " ",
221
+ "would do this for ",
222
+ formatCost(cf.estimatedCostUsd),
223
+ " (saves",
224
+ " ",
225
+ formatCost(cf.savingsUsd),
226
+ " / ",
227
+ cf.savingsPercent,
228
+ "%)"
229
+ ] })
230
+ ]
231
+ }
232
+ );
233
+ }
234
+ function HeaderRow({
235
+ detail,
236
+ theme
237
+ }) {
238
+ const { colors, fonts } = theme;
239
+ return /* @__PURE__ */ jsxs(
240
+ "div",
241
+ {
242
+ style: {
243
+ display: "flex",
244
+ alignItems: "baseline",
245
+ gap: 12,
246
+ flexWrap: "wrap"
247
+ },
248
+ children: [
249
+ /* @__PURE__ */ jsx(
250
+ "span",
251
+ {
252
+ style: {
253
+ fontFamily: fonts.serif,
254
+ fontWeight: 600,
255
+ fontSize: 22,
256
+ color: colors.text
257
+ },
258
+ children: detail.archetype
259
+ }
260
+ ),
261
+ /* @__PURE__ */ jsx("span", { style: { color: colors.textFaint }, children: "\xB7" }),
262
+ /* @__PURE__ */ jsx(
263
+ "span",
264
+ {
265
+ style: {
266
+ fontFamily: fonts.sans,
267
+ fontSize: 12,
268
+ color: colors.textMuted
269
+ },
270
+ children: formatAgo(detail.createdAt)
271
+ }
272
+ ),
273
+ /* @__PURE__ */ jsx("span", { style: { color: colors.textFaint }, children: "\xB7" }),
274
+ /* @__PURE__ */ jsx(
275
+ "span",
276
+ {
277
+ title: detail.traceId,
278
+ style: {
279
+ fontFamily: fonts.mono,
280
+ fontSize: 11,
281
+ background: colors.surface,
282
+ border: `1px solid ${colors.border}`,
283
+ borderRadius: 999,
284
+ padding: "2px 10px",
285
+ color: colors.textMuted
286
+ },
287
+ children: shortTraceId(detail.traceId)
288
+ }
289
+ )
290
+ ]
291
+ }
292
+ );
293
+ }
294
+ function OutcomeCard({
295
+ detail,
296
+ theme
297
+ }) {
298
+ const { colors, fonts } = theme;
299
+ const isFail = detail.finishReason !== void 0 && detail.finishReason !== "stop" && detail.finishReason !== "tool_use";
300
+ const statusColor = isFail ? colors.fail : colors.ok;
301
+ const totalLabel = detail.totalMs !== void 0 ? formatMs(detail.totalMs) : "\u2014";
302
+ const ttftLabel = detail.ttftMs !== void 0 ? ` \xB7 TTFT ${formatMs(detail.ttftMs)}` : "";
303
+ return /* @__PURE__ */ jsxs(Card, { theme, children: [
304
+ /* @__PURE__ */ jsxs(
305
+ "div",
306
+ {
307
+ style: {
308
+ display: "flex",
309
+ alignItems: "baseline",
310
+ gap: 14,
311
+ flexWrap: "wrap",
312
+ fontFamily: fonts.sans,
313
+ fontSize: 14
314
+ },
315
+ children: [
316
+ /* @__PURE__ */ jsx(
317
+ "span",
318
+ {
319
+ style: {
320
+ color: statusColor,
321
+ fontWeight: 700,
322
+ fontSize: 18
323
+ },
324
+ children: isFail ? "\u2717" : "\u2713"
325
+ }
326
+ ),
327
+ /* @__PURE__ */ jsx(
328
+ "span",
329
+ {
330
+ style: {
331
+ fontFamily: fonts.mono,
332
+ fontSize: 13,
333
+ color: colors.text,
334
+ fontWeight: 600
335
+ },
336
+ children: detail.target
337
+ }
338
+ ),
339
+ /* @__PURE__ */ jsx(
340
+ "span",
341
+ {
342
+ style: {
343
+ fontFamily: fonts.serif,
344
+ fontWeight: 600,
345
+ fontSize: 18,
346
+ color: colors.text
347
+ },
348
+ children: formatCost(detail.estimatedCostUsd)
349
+ }
350
+ ),
351
+ /* @__PURE__ */ jsxs("span", { style: { color: colors.textMuted, fontSize: 12 }, children: [
352
+ totalLabel,
353
+ ttftLabel
354
+ ] })
355
+ ]
356
+ }
357
+ ),
358
+ detail.fellOverFrom && detail.fellOverFrom !== detail.target && /* @__PURE__ */ jsxs(
359
+ "div",
360
+ {
361
+ style: {
362
+ marginTop: 6,
363
+ fontFamily: fonts.sans,
364
+ fontSize: 12,
365
+ color: colors.warn
366
+ },
367
+ children: [
368
+ "\u2191 fell over from",
369
+ " ",
370
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: fonts.mono }, children: detail.fellOverFrom }),
371
+ detail.fallbackReason && ` (${detail.fallbackReason})`
372
+ ]
373
+ }
374
+ )
375
+ ] });
376
+ }
377
+ function CoachingCard({
378
+ detail,
379
+ theme
380
+ }) {
381
+ const advisories = detail.advisories ?? [];
382
+ const sectionRewrites = detail.sectionRewritesApplied ?? [];
383
+ const counterfactuals = detail.counterfactuals ?? [];
384
+ const topCF = counterfactuals[0];
385
+ if (advisories.length === 0 && sectionRewrites.length === 0 && !topCF) {
386
+ return null;
387
+ }
388
+ return /* @__PURE__ */ jsx(Card, { title: "\u26A0 Coaching", emphasis: "coaching", theme, children: /* @__PURE__ */ jsxs("div", { children: [
389
+ advisories.map((a, i) => /* @__PURE__ */ jsx(AdvisoryRow, { advisory: a, theme }, `adv-${i}`)),
390
+ sectionRewrites.map((r, i) => /* @__PURE__ */ jsx(SectionRewriteRow, { rewrite: r, theme }, `rw-${i}`)),
391
+ topCF && /* @__PURE__ */ jsx(CounterfactualAsAdvisoryRow, { cf: topCF, theme })
392
+ ] }) });
393
+ }
394
+ function ShapeCard({
395
+ detail,
396
+ theme
397
+ }) {
398
+ const { colors, fonts } = theme;
399
+ const total = detail.tokensIn + detail.tokensOut;
400
+ const ratioPct = total > 0 ? Math.round(detail.tokensIn / total * 100) : 0;
401
+ const cachingOff = detail.historyCacheableTokens > 1e3 && detail.cacheReadInputTokens === 0;
402
+ return /* @__PURE__ */ jsxs(Card, { theme, children: [
403
+ /* @__PURE__ */ jsxs(
404
+ "div",
405
+ {
406
+ style: {
407
+ display: "flex",
408
+ justifyContent: "space-between",
409
+ alignItems: "center",
410
+ marginBottom: 8
411
+ },
412
+ children: [
413
+ /* @__PURE__ */ jsx(
414
+ "div",
415
+ {
416
+ style: {
417
+ fontSize: 11,
418
+ fontWeight: 600,
419
+ textTransform: "uppercase",
420
+ letterSpacing: 0.4,
421
+ color: colors.textMuted,
422
+ fontFamily: fonts.sans
423
+ },
424
+ children: "\u{1F4CA} Shape"
425
+ }
426
+ ),
427
+ /* @__PURE__ */ jsxs("div", { children: [
428
+ /* @__PURE__ */ jsx(
429
+ HealthDot,
430
+ {
431
+ axis: "input",
432
+ status: detail.health.inputRatioStatus,
433
+ theme
434
+ }
435
+ ),
436
+ /* @__PURE__ */ jsx(
437
+ HealthDot,
438
+ {
439
+ axis: "cache",
440
+ status: detail.health.cacheStatus,
441
+ theme
442
+ }
443
+ ),
444
+ /* @__PURE__ */ jsx(
445
+ HealthDot,
446
+ {
447
+ axis: "fallback",
448
+ status: detail.health.fallbackStatus,
449
+ theme
450
+ }
451
+ )
452
+ ] })
453
+ ]
454
+ }
455
+ ),
456
+ /* @__PURE__ */ jsxs(
457
+ "div",
458
+ {
459
+ style: {
460
+ fontFamily: fonts.sans,
461
+ fontSize: 13,
462
+ color: colors.text,
463
+ marginBottom: 4
464
+ },
465
+ children: [
466
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: fonts.serif, fontWeight: 600, fontSize: 15 }, children: detail.tokensIn.toLocaleString() }),
467
+ " ",
468
+ "in \xB7",
469
+ " ",
470
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: fonts.serif, fontWeight: 600, fontSize: 15 }, children: detail.tokensOut.toLocaleString() }),
471
+ " ",
472
+ "out (",
473
+ ratioPct,
474
+ "% input \u2014 ",
475
+ inputRatioLabel(detail.health.inputRatioStatus),
476
+ ")"
477
+ ]
478
+ }
479
+ ),
480
+ /* @__PURE__ */ jsx(
481
+ "div",
482
+ {
483
+ style: {
484
+ fontFamily: fonts.sans,
485
+ fontSize: 12,
486
+ color: colors.textMuted,
487
+ marginBottom: 4
488
+ },
489
+ children: detail.historyCacheableTokens === 0 ? "cache: no cacheable history" : `cache: ${detail.cacheReadInputTokens.toLocaleString()} / ${detail.historyCacheableTokens.toLocaleString()} of cacheable history${cachingOff ? " (caching off)" : ""}`
490
+ }
491
+ ),
492
+ /* @__PURE__ */ jsxs(
493
+ "div",
494
+ {
495
+ style: {
496
+ fontFamily: fonts.sans,
497
+ fontSize: 12,
498
+ color: colors.textMuted
499
+ },
500
+ children: [
501
+ formatOrDash(detail.toolsCount),
502
+ " tools \xB7",
503
+ " ",
504
+ formatOrDash(detail.historyDepth),
505
+ " history msgs \xB7 system",
506
+ " ",
507
+ detail.systemPromptChars !== void 0 ? `${detail.systemPromptChars.toLocaleString()} chars` : "\u2014"
508
+ ]
509
+ }
510
+ )
511
+ ] });
512
+ }
513
+ function MutationsCard({
514
+ detail,
515
+ theme
516
+ }) {
517
+ const { colors, fonts } = theme;
518
+ const mutations = detail.mutationsApplied ?? [];
519
+ if (mutations.length === 0) return null;
520
+ return /* @__PURE__ */ jsx(Card, { title: "\u{1F4CB} What kgauto did", emphasis: "mutations", theme, children: /* @__PURE__ */ jsx(
521
+ "ul",
522
+ {
523
+ style: {
524
+ margin: 0,
525
+ padding: 0,
526
+ listStyle: "none",
527
+ fontFamily: fonts.sans,
528
+ fontSize: 13,
529
+ color: colors.text
530
+ },
531
+ children: mutations.map((m, i) => /* @__PURE__ */ jsx(
532
+ "li",
533
+ {
534
+ style: {
535
+ padding: "4px 0",
536
+ borderTop: i === 0 ? "none" : `1px solid ${colors.borderSoft}`,
537
+ fontFamily: fonts.mono,
538
+ fontSize: 12
539
+ },
540
+ children: formatMutation(m)
541
+ },
542
+ `mut-${i}`
543
+ ))
544
+ }
545
+ ) });
546
+ }
547
+ function CounterfactualsCard({
548
+ detail,
549
+ coachingPresent,
550
+ theme
551
+ }) {
552
+ const { colors, fonts } = theme;
553
+ const cfs = detail.counterfactuals ?? [];
554
+ if (cfs.length === 0) return null;
555
+ if (coachingPresent) return null;
556
+ return /* @__PURE__ */ jsx(Card, { title: "\u{1F4B0} Cheaper alternatives", emphasis: "counterfactuals", theme, children: /* @__PURE__ */ jsx(
557
+ "ul",
558
+ {
559
+ style: {
560
+ margin: 0,
561
+ padding: 0,
562
+ listStyle: "none",
563
+ fontFamily: fonts.sans,
564
+ fontSize: 13,
565
+ color: colors.text
566
+ },
567
+ children: cfs.slice(0, 2).map((cf, i) => {
568
+ const yearlySavings = detail.projectedDailyCostUsd !== void 0 && detail.estimatedCostUsd > 0 ? cf.savingsUsd * (detail.projectedDailyCostUsd / Math.max(detail.estimatedCostUsd, 1e-9)) * 365 : null;
569
+ return /* @__PURE__ */ jsxs(
570
+ "li",
571
+ {
572
+ style: {
573
+ padding: "6px 0",
574
+ borderTop: i === 0 ? "none" : `1px solid ${colors.borderSoft}`
575
+ },
576
+ children: [
577
+ /* @__PURE__ */ jsx(
578
+ "span",
579
+ {
580
+ style: {
581
+ fontFamily: fonts.serif,
582
+ fontWeight: 600,
583
+ fontSize: 16
584
+ },
585
+ children: cf.modelId
586
+ }
587
+ ),
588
+ " ",
589
+ /* @__PURE__ */ jsx("span", { style: { fontFamily: fonts.mono, fontSize: 12 }, children: formatCost(cf.estimatedCostUsd) }),
590
+ " ",
591
+ /* @__PURE__ */ jsxs("span", { style: { color: colors.textMuted, fontSize: 12 }, children: [
592
+ "(saves ",
593
+ formatCost(cf.savingsUsd),
594
+ " / ",
595
+ cf.savingsPercent,
596
+ "%",
597
+ yearlySavings !== null ? ` / $${yearlySavings.toFixed(0)}/year at current volume` : "",
598
+ ")"
599
+ ] })
600
+ ]
601
+ },
602
+ `cf-${i}`
603
+ );
604
+ })
605
+ }
606
+ ) });
607
+ }
608
+ function RawExpandCard({
609
+ detail,
610
+ theme
611
+ }) {
612
+ const { colors, fonts } = theme;
613
+ if (detail.rawRequest === void 0 && detail.rawResponse === void 0) {
614
+ return null;
615
+ }
616
+ return /* @__PURE__ */ jsx(Card, { theme, children: /* @__PURE__ */ jsxs("details", { children: [
617
+ /* @__PURE__ */ jsx(
618
+ "summary",
619
+ {
620
+ style: {
621
+ cursor: "pointer",
622
+ fontFamily: fonts.sans,
623
+ fontSize: 12,
624
+ color: colors.textMuted,
625
+ listStyle: "none"
626
+ },
627
+ children: "\u25B6 Request / Response"
628
+ }
629
+ ),
630
+ /* @__PURE__ */ jsxs("div", { style: { marginTop: 8 }, children: [
631
+ detail.rawRequest !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
632
+ /* @__PURE__ */ jsx(
633
+ "div",
634
+ {
635
+ style: {
636
+ fontFamily: fonts.sans,
637
+ fontSize: 10,
638
+ fontWeight: 600,
639
+ textTransform: "uppercase",
640
+ letterSpacing: 0.4,
641
+ color: colors.textMuted,
642
+ marginTop: 6,
643
+ marginBottom: 4
644
+ },
645
+ children: "Request"
646
+ }
647
+ ),
648
+ /* @__PURE__ */ jsx(
649
+ "pre",
650
+ {
651
+ style: {
652
+ fontFamily: fonts.mono,
653
+ fontSize: 11,
654
+ lineHeight: 1.5,
655
+ background: colors.surface,
656
+ border: `1px solid ${colors.border}`,
657
+ borderRadius: 6,
658
+ padding: 10,
659
+ maxHeight: 280,
660
+ overflow: "auto",
661
+ whiteSpace: "pre-wrap",
662
+ wordBreak: "break-word",
663
+ color: colors.text,
664
+ margin: 0
665
+ },
666
+ children: detail.rawRequest
667
+ }
668
+ )
669
+ ] }),
670
+ detail.rawResponse !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
671
+ /* @__PURE__ */ jsx(
672
+ "div",
673
+ {
674
+ style: {
675
+ fontFamily: fonts.sans,
676
+ fontSize: 10,
677
+ fontWeight: 600,
678
+ textTransform: "uppercase",
679
+ letterSpacing: 0.4,
680
+ color: colors.textMuted,
681
+ marginTop: 10,
682
+ marginBottom: 4
683
+ },
684
+ children: "Response"
685
+ }
686
+ ),
687
+ /* @__PURE__ */ jsx(
688
+ "pre",
689
+ {
690
+ style: {
691
+ fontFamily: fonts.mono,
692
+ fontSize: 11,
693
+ lineHeight: 1.5,
694
+ background: colors.surface,
695
+ border: `1px solid ${colors.border}`,
696
+ borderRadius: 6,
697
+ padding: 10,
698
+ maxHeight: 280,
699
+ overflow: "auto",
700
+ whiteSpace: "pre-wrap",
701
+ wordBreak: "break-word",
702
+ color: colors.text,
703
+ margin: 0
704
+ },
705
+ children: detail.rawResponse
706
+ }
707
+ )
708
+ ] })
709
+ ] })
710
+ ] }) });
711
+ }
712
+ function GlassboxTraceCard({
713
+ detail,
714
+ theme = DEFAULT_GLASSBOX_THEME
715
+ }) {
716
+ const { colors } = theme;
717
+ const advisories = detail.advisories ?? [];
718
+ const sectionRewrites = detail.sectionRewritesApplied ?? [];
719
+ const counterfactuals = detail.counterfactuals ?? [];
720
+ const topCF = counterfactuals[0];
721
+ const coachingPresent = advisories.length > 0 || sectionRewrites.length > 0 || !!topCF;
722
+ return /* @__PURE__ */ jsxs(
723
+ "div",
724
+ {
725
+ style: {
726
+ background: colors.surface,
727
+ border: `1px solid ${colors.border}`,
728
+ borderRadius: 8,
729
+ padding: 14,
730
+ marginBottom: 16
731
+ },
732
+ children: [
733
+ /* @__PURE__ */ jsx("div", { style: { marginBottom: 10 }, children: /* @__PURE__ */ jsx(HeaderRow, { detail, theme }) }),
734
+ /* @__PURE__ */ jsx(OutcomeCard, { detail, theme }),
735
+ coachingPresent && /* @__PURE__ */ jsx(CoachingCard, { detail, theme }),
736
+ /* @__PURE__ */ jsx(ShapeCard, { detail, theme }),
737
+ /* @__PURE__ */ jsx(MutationsCard, { detail, theme }),
738
+ /* @__PURE__ */ jsx(
739
+ CounterfactualsCard,
740
+ {
741
+ detail,
742
+ coachingPresent,
743
+ theme
744
+ }
745
+ ),
746
+ /* @__PURE__ */ jsx(RawExpandCard, { detail, theme })
747
+ ]
748
+ }
749
+ );
750
+ }
751
+ export {
752
+ DEFAULT_GLASSBOX_THEME,
753
+ GlassboxTraceCard
754
+ };