literally-aeo 0.4.2 → 0.4.3

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 (122) hide show
  1. package/README.md +16 -0
  2. package/dist/cli.mjs +1503 -548
  3. package/dist/lib/agents/methodology.js +3 -3
  4. package/dist/lib/bundle/contracts.js +1 -1
  5. package/dist/lib/bundle/export.js +12 -12
  6. package/dist/lib/bundle/journal.js +2 -2
  7. package/dist/lib/bundle/project-journal.js +5 -5
  8. package/dist/lib/bundle/project.js +10 -10
  9. package/dist/lib/bundle/read.js +13 -13
  10. package/dist/lib/bundle/recorder.js +3 -3
  11. package/dist/lib/bundle/redact.js +2 -2
  12. package/dist/lib/bundle/trace-coverage.js +2 -2
  13. package/dist/lib/bundle/verify-integrity.js +4 -4
  14. package/dist/lib/bundle/verify-measurement.js +2 -2
  15. package/dist/lib/bundle/verify-report.js +3 -3
  16. package/dist/lib/bundle/verify.js +8 -8
  17. package/dist/lib/checks/run-checks.js +4 -4
  18. package/dist/lib/chunks/{chunk-22SP35NA.js → chunk-2ANSPIUT.js} +1 -1
  19. package/dist/lib/chunks/{chunk-ITLJZUKL.js → chunk-54GMIPWV.js} +1 -1
  20. package/dist/lib/chunks/{chunk-QJX6YXXQ.js → chunk-65OIYOUH.js} +2 -2
  21. package/dist/lib/chunks/{chunk-ENPRRXH5.js → chunk-6MGXILUJ.js} +1 -1
  22. package/dist/lib/chunks/chunk-6OURIXQZ.js +472 -0
  23. package/dist/lib/chunks/{chunk-AMK6IHJD.js → chunk-746643QV.js} +1 -1
  24. package/dist/lib/chunks/{chunk-AMF3T5A3.js → chunk-74K4E3ZS.js} +1 -1
  25. package/dist/lib/chunks/{chunk-5EM6J7TG.js → chunk-7HCVSLVG.js} +1 -1
  26. package/dist/lib/chunks/{chunk-RWVXK7XE.js → chunk-7K2XT3WI.js} +5 -5
  27. package/dist/lib/chunks/{chunk-VOK4TUXV.js → chunk-7L4Y6N3V.js} +1 -1
  28. package/dist/lib/chunks/{chunk-TD47AB37.js → chunk-7QWT7LFM.js} +2 -2
  29. package/dist/lib/chunks/{chunk-ATKP5ZW6.js → chunk-7SA2CRSS.js} +1 -1
  30. package/dist/lib/chunks/{chunk-Q6TZB2OQ.js → chunk-ARKZ5PJN.js} +1 -1
  31. package/dist/lib/chunks/{chunk-FBMO6UV4.js → chunk-B6XGNJUU.js} +1 -1
  32. package/dist/lib/chunks/{chunk-RR63UE5H.js → chunk-BNX7S4GK.js} +4 -4
  33. package/dist/lib/chunks/chunk-BWBPEXEU.js +83 -0
  34. package/dist/lib/chunks/{chunk-DKR7LSP2.js → chunk-BZAPAGXM.js} +1 -1
  35. package/dist/lib/chunks/{chunk-FFDMGNRO.js → chunk-C2Q7YE7Y.js} +6 -6
  36. package/dist/lib/chunks/{chunk-NWABYXDQ.js → chunk-D2LJMNH3.js} +2 -2
  37. package/dist/lib/chunks/{chunk-XT5M3PPQ.js → chunk-EVEJ3MFU.js} +3 -3
  38. package/dist/lib/chunks/{chunk-U4AROC2Z.js → chunk-GC7DISQO.js} +1 -1
  39. package/dist/lib/chunks/{chunk-YRXYTCMY.js → chunk-JHUI2K5X.js} +1 -1
  40. package/dist/lib/chunks/chunk-JQFLWUCA.js +123 -0
  41. package/dist/lib/chunks/{chunk-HJEIEMPE.js → chunk-JREYIUNG.js} +4 -4
  42. package/dist/lib/chunks/{chunk-FXCUGNFL.js → chunk-JXQOWHWB.js} +1 -1
  43. package/dist/lib/chunks/{chunk-BKAERR7J.js → chunk-KFJ5O5CL.js} +2 -2
  44. package/dist/lib/chunks/{chunk-6P7EZJI7.js → chunk-KSJ3NZIJ.js} +4 -2
  45. package/dist/lib/chunks/{chunk-EZ23TKTX.js → chunk-L5HFTFFG.js} +2 -2
  46. package/dist/lib/chunks/{chunk-DI4LZR37.js → chunk-LJD37WAV.js} +2 -2
  47. package/dist/lib/chunks/{chunk-YPGJN232.js → chunk-MKA2EP7M.js} +1 -1
  48. package/dist/lib/chunks/{chunk-JN4332MJ.js → chunk-MMJ5UR2E.js} +1 -1
  49. package/dist/lib/chunks/{chunk-A2RW4ZMR.js → chunk-MQFFMD4Q.js} +1 -1
  50. package/dist/lib/chunks/{chunk-CRXJFOCK.js → chunk-NM2LUMQT.js} +4 -4
  51. package/dist/lib/chunks/{chunk-RYV25YGT.js → chunk-P5VVHTZU.js} +1 -1
  52. package/dist/lib/chunks/{chunk-JKBXKACC.js → chunk-PFG3ESJE.js} +7 -7
  53. package/dist/lib/chunks/{chunk-OF3WIGG7.js → chunk-Q7CWM6LZ.js} +6 -6
  54. package/dist/lib/chunks/{chunk-DU3MAXVC.js → chunk-R5NLULQW.js} +1 -1
  55. package/dist/lib/chunks/{chunk-T5Q5CBTA.js → chunk-RM7U5M5L.js} +1 -1
  56. package/dist/lib/chunks/{chunk-JGBJQ3TO.js → chunk-RQ6GUJI5.js} +1 -1
  57. package/dist/lib/chunks/{chunk-CMB2KSW2.js → chunk-RUSMX6JH.js} +16 -7
  58. package/dist/lib/chunks/{chunk-KFYTORIT.js → chunk-UNNRLD2U.js} +4 -4
  59. package/dist/lib/chunks/chunk-VFN2J4Z3.js +626 -0
  60. package/dist/lib/chunks/{chunk-3DVFQMJT.js → chunk-VPJN2GNC.js} +1 -1
  61. package/dist/lib/chunks/{chunk-NZOKSFIA.js → chunk-XSOTCSD3.js} +3 -3
  62. package/dist/lib/chunks/{chunk-M4XGUJMO.js → chunk-YX4EH6FR.js} +1 -1
  63. package/dist/lib/chunks/{chunk-WIRVKAYB.js → chunk-ZC4MKS3J.js} +11 -11
  64. package/dist/lib/chunks/{chunk-KC35BXW7.js → chunk-ZM4RHMBI.js} +1 -1
  65. package/dist/lib/cli/bundle-commands.js +57 -32
  66. package/dist/lib/cli/guide-command.js +1 -1
  67. package/dist/lib/cli/run-commands.js +36 -36
  68. package/dist/lib/cli/status-command.js +18 -18
  69. package/dist/lib/codex-workflow/aggregate.js +2 -2
  70. package/dist/lib/codex-workflow/author.js +3 -3
  71. package/dist/lib/codex-workflow/capture.js +5 -5
  72. package/dist/lib/codex-workflow/copy-editor.js +3 -3
  73. package/dist/lib/codex-workflow/copy.js +2 -2
  74. package/dist/lib/codex-workflow/finish.js +5 -5
  75. package/dist/lib/codex-workflow/loop.js +13 -13
  76. package/dist/lib/codex-workflow/run-source.js +5 -5
  77. package/dist/lib/codex-workflow/stage.js +4 -4
  78. package/dist/lib/engine/audit-file.js +3 -3
  79. package/dist/lib/engine/author.js +10 -10
  80. package/dist/lib/engine/cost-estimate.js +3 -3
  81. package/dist/lib/engine/local-run.js +17 -17
  82. package/dist/lib/engine/preflight.js +3 -3
  83. package/dist/lib/engine/rejudge.js +24 -24
  84. package/dist/lib/engine/resources.js +1 -1
  85. package/dist/lib/engine/run-bindings.js +3 -3
  86. package/dist/lib/engine/run-method.js +2 -2
  87. package/dist/lib/engine/run-models.js +4 -4
  88. package/dist/lib/engine/run-status.js +18 -18
  89. package/dist/lib/engine/templates.js +4 -4
  90. package/dist/lib/grounding/grounding-runtime.js +5 -5
  91. package/dist/lib/grounding/recorded-tools.js +4 -4
  92. package/dist/lib/pipeline.js +4 -4
  93. package/dist/lib/probes/bindings.js +2 -2
  94. package/dist/lib/probes/charged-trace.js +3 -3
  95. package/dist/lib/probes/probes.js +3 -3
  96. package/dist/lib/viewer/alternatives.js +8 -0
  97. package/dist/lib/viewer/cited-domains.js +8 -0
  98. package/dist/lib/viewer/page.js +3 -1
  99. package/dist/lib/viewer/presentation.js +41 -0
  100. package/dist/lib/viewer/server.js +15 -10
  101. package/dist/types/bundle/contracts.d.ts +1 -1
  102. package/dist/types/engine/resources.d.ts +2 -0
  103. package/dist/types/viewer/alternatives.d.ts +16 -0
  104. package/dist/types/viewer/cited-domains.d.ts +22 -0
  105. package/dist/types/viewer/page.d.ts +9 -2
  106. package/dist/types/viewer/presentation.d.ts +112 -0
  107. package/dist/types/viewer/server.d.ts +7 -3
  108. package/package.json +2 -1
  109. package/resources/fonts/Mulish-OFL.txt +93 -0
  110. package/resources/fonts/Mulish-VariableFont_wght.ttf +0 -0
  111. package/resources/fonts/SourceCodePro-OFL.txt +93 -0
  112. package/resources/fonts/SourceCodePro-VariableFont_wght.ttf +0 -0
  113. package/src/bundle/contracts.ts +1 -1
  114. package/src/cli/bundle-commands.ts +21 -0
  115. package/src/engine/resources.ts +9 -5
  116. package/src/report/core/rate-interval.ts +1 -2
  117. package/src/viewer/alternatives.ts +202 -0
  118. package/src/viewer/cited-domains.ts +127 -0
  119. package/src/viewer/page.ts +549 -236
  120. package/src/viewer/presentation.ts +759 -0
  121. package/src/viewer/server.ts +25 -4
  122. package/dist/lib/chunks/chunk-3TF4JGQA.js +0 -323
@@ -9,6 +9,7 @@ import { RunOrigin, toolVersion } from '../bundle/contracts';
9
9
  import { parseBundleJson } from '../bundle/json';
10
10
  import { verifyBundle } from '../bundle/verify';
11
11
  import { viewerPage } from './page';
12
+ import { presentReport } from './presentation';
12
13
 
13
14
  // ============================================================================
14
15
  // `literally-aeo view` (specs/aeo-open-source-cli-spec.md §4.3). Any local
@@ -78,7 +79,8 @@ const plain = (status: number, body: string): Reply => {
78
79
  return { status, body, contentType: 'text/plain; charset=utf-8' };
79
80
  };
80
81
 
81
- /** The page's metadata and the verifier's result, served beside the files. */
82
+ /** The page's metadata, the verifier's result and the report the page
83
+ * shows, served beside the files. */
82
84
  const derivedDocuments = (bundle: ViewerBundle) => {
83
85
  const verification = verifyBundle(bundle.files, bundle.description);
84
86
  const manifest = bundle.files.get('manifest.json');
@@ -110,13 +112,21 @@ const derivedDocuments = (bundle: ViewerBundle) => {
110
112
  },
111
113
  ],
112
114
  ['__verification', bundle.workingState ? null : verification],
115
+ ['__report', presentReport(bundle.files)],
113
116
  ]);
114
117
  };
115
118
 
119
+ export type ViewerOptions = {
120
+ port?: number;
121
+ /** The page's fonts by file name (viewerFontFiles), from the engine's
122
+ * resources; without them the page falls back to system fonts. */
123
+ fonts?: ReadonlyMap<string, Buffer>;
124
+ };
125
+
116
126
  /** startViewer serves a bundle on loopback until closed. */
117
127
  export const startViewer = async (
118
128
  bundle: ViewerBundle,
119
- { port = 0 }: { port?: number } = {},
129
+ { port = 0, fonts = new Map() }: ViewerOptions = {},
120
130
  ): Promise<ViewerServer> => {
121
131
  const token = randomBytes(32).toString('hex');
122
132
  const derived = derivedDocuments(bundle);
@@ -143,14 +153,25 @@ export const startViewer = async (
143
153
 
144
154
  send(response, {
145
155
  status: 200,
146
- body: viewerPage(nonce),
156
+ body: viewerPage(nonce, fonts.size > 0 ? token : undefined),
147
157
  contentType: 'text/html; charset=utf-8',
148
- csp: `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; connect-src 'self'; img-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
158
+ csp: `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; font-src 'self'; connect-src 'self'; img-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
149
159
  });
150
160
 
151
161
  return;
152
162
  }
153
163
 
164
+ // Font names are plain ASCII: the path is looked up as sent.
165
+ const font = url.pathname.startsWith('/fonts/')
166
+ ? fonts.get(url.pathname.slice('/fonts/'.length))
167
+ : undefined;
168
+
169
+ if (font !== undefined) {
170
+ send(response, { status: 200, body: font, contentType: 'font/ttf' });
171
+
172
+ return;
173
+ }
174
+
154
175
  const file = decodeURIComponent(url.pathname.replace(/^\/data\//, ''));
155
176
  const derivedDocument = derived.get(file);
156
177
 
@@ -1,323 +0,0 @@
1
- // src/viewer/page.ts
2
- var styles = `
3
- :root {
4
- --bg: #ffffff; --fg: #16181d; --muted: #5d6470; --line: #e3e6eb;
5
- --panel: #f6f7f9; --accent: #3651d4; --pass: #1f7a46; --fail: #b3261e;
6
- --warn: #8a5a00;
7
- color-scheme: light;
8
- }
9
- @media (prefers-color-scheme: dark) {
10
- :root {
11
- --bg: #111317; --fg: #e8eaee; --muted: #9aa1ad; --line: #2a2e36;
12
- --panel: #181b21; --accent: #8fa2ff; --pass: #5fd08f; --fail: #ff8a80;
13
- --warn: #e5b45a;
14
- color-scheme: dark;
15
- }
16
- }
17
- * { box-sizing: border-box; }
18
- body { margin: 0; background: var(--bg); color: var(--fg);
19
- font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
20
- main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
21
- h1 { font-size: 24px; margin: 0 0 4px; }
22
- h2 { font-size: 18px; margin: 32px 0 12px; }
23
- h3 { font-size: 15px; margin: 20px 0 8px; }
24
- .muted { color: var(--muted); }
25
- .banner { border: 1px solid var(--line); background: var(--panel);
26
- padding: 12px 14px; border-radius: 8px; margin: 16px 0; }
27
- .banner.warn { border-color: var(--warn); }
28
- .grid { display: grid; gap: 12px;
29
- grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
30
- .stat { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
31
- .stat b { display: block; font-size: 22px; }
32
- .interval { display: block; color: var(--muted); font-size: 13px; }
33
- button.tip-trigger { background: none; border: 0; padding: 0; color: inherit; font: inherit;
34
- text-align: left; cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
35
- button.tip-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
36
- .tip { display: block; color: var(--fg); }
37
- .tip[hidden] { display: none; }
38
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
39
- th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line);
40
- vertical-align: top; }
41
- th { color: var(--muted); font-weight: 600; }
42
- tr.row { cursor: pointer; }
43
- tr.row:hover, tr.row:focus { background: var(--panel); outline: none; }
44
- .pass { color: var(--pass); } .fail { color: var(--fail); }
45
- .limited { color: var(--warn); }
46
- .drawer { border: 1px solid var(--line); border-radius: 8px; padding: 14px;
47
- margin-top: 12px; background: var(--panel); }
48
- pre { white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace,
49
- SFMono-Regular, Menlo, monospace; margin: 8px 0 0; }
50
- button.link { background: none; border: 0; color: var(--accent); padding: 0;
51
- font: inherit; cursor: pointer; text-decoration: underline; }
52
- .table-wrap { overflow-x: auto; }
53
- ul.methodology { padding-left: 20px; color: var(--muted); font-size: 14px; }
54
- ul.methodology li { margin: 6px 0; }
55
- footer { margin-top: 48px; color: var(--muted); font-size: 13px; }
56
- `;
57
- var script = `
58
- const token = new URLSearchParams(location.search).get('t');
59
- const get = async (path) => {
60
- const response = await fetch('/data/' + path + '?t=' + encodeURIComponent(token));
61
- if (!response.ok) return null;
62
- return response.json();
63
- };
64
- const el = (tag, attrs = {}, ...children) => {
65
- const node = document.createElement(tag);
66
- for (const [key, value] of Object.entries(attrs)) {
67
- if (key === 'class') node.className = value;
68
- else if (key.startsWith('on')) node.addEventListener(key.slice(2), value);
69
- else node.setAttribute(key, value);
70
- }
71
- for (const child of children) {
72
- if (child === null || child === undefined) continue;
73
- node.append(typeof child === 'string' ? document.createTextNode(child) : child);
74
- }
75
- return node;
76
- };
77
- const percent = (value) =>
78
- typeof value === 'number' && Number.isFinite(value) ? Math.round(value * 100) + '%' : 'n/a';
79
- const isShare = (value) => typeof value === 'number' && value >= 0 && value <= 1;
80
- const isCount = (value) => Number.isSafeInteger(value) && value >= 0;
81
- // The evidence beside a rate (calculation version 2), or null when the
82
- // bundle has none or it is malformed: a bundle is shown even when it fails
83
- // verification, so its numbers are checked before they are displayed.
84
- const evidenceOf = (evidence) =>
85
- evidence && isShare(evidence.low) && isShare(evidence.high) && evidence.low <= evidence.high
86
- && isCount(evidence.count) && isCount(evidence.captured) && isCount(evidence.planned)
87
- ? evidence : null;
88
- // Outward to whole percents, so the range shown always contains the computed
89
- // interval. The bounds are stored to 6 decimals; scaling them to an integer
90
- // first keeps a bound of 0.07 (7.000000000000001 once multiplied) at 7%.
91
- // The rule of report/core/rate-interval.ts, repeated here because this page
92
- // is one self-contained script; page.spec.ts holds the two to the same
93
- // answers.
94
- const intervalText = (evidence) =>
95
- Math.floor(Math.round(evidence.low * 1e6) / 1e4) + '\u2013'
96
- + Math.ceil(Math.round(evidence.high * 1e6) / 1e4) + '%';
97
- // The counts behind an interval, in a tooltip (WCAG 1.4.13). It opens on
98
- // hover, on keyboard focus and on a tap; it stays open while the pointer is
99
- // over it; Escape closes it; and a screen reader reads it as the interval's
100
- // description. It sits in the flow under the interval, so a scrolling table
101
- // cannot clip it and it hides nothing.
102
- const tipDismissals = [];
103
- document.addEventListener('keydown', (event) => {
104
- if (event.key === 'Escape') for (const dismiss of tipDismissals) dismiss();
105
- });
106
- let tipCount = 0;
107
- const withTip = (label, name, text) => {
108
- tipCount += 1;
109
- const id = 'tip-' + tipCount;
110
- const tip = el('span', { class: 'tip', role: 'tooltip', id, hidden: '' }, text);
111
- let hovered = false;
112
- let focused = false;
113
- const sync = () => {
114
- if (hovered || focused) tip.removeAttribute('hidden');
115
- else tip.setAttribute('hidden', '');
116
- };
117
- const trigger = el('button', { type: 'button', class: 'tip-trigger',
118
- 'aria-label': name, 'aria-describedby': id,
119
- // Safari focuses no button on a click or a tap, and a button that kept
120
- // focus through Escape gets no new focus event: a click (or Enter or
121
- // Space) opens the tip itself, until focus moves on.
122
- onclick: () => { trigger.focus(); focused = true; sync(); },
123
- onfocus: () => { focused = true; sync(); },
124
- onblur: () => { focused = false; sync(); },
125
- }, label);
126
- tipDismissals.push(() => { hovered = false; focused = false; sync(); });
127
- return el('span', { class: 'interval',
128
- onmouseenter: () => { hovered = true; sync(); },
129
- onmouseleave: () => { hovered = false; sync(); },
130
- }, trigger, tip);
131
- };
132
- // A rate, with its interval and counts beneath when the bundle carries them.
133
- // subject names the rate for a screen reader, which reaches the interval
134
- // without the label or the column heading beside it.
135
- const rateFigure = (rate, recorded, subject, counted) => {
136
- const figure = el('b', {}, percent(rate));
137
- const evidence = evidenceOf(recorded);
138
- if (!evidence) return [figure];
139
- const interval = 'approx. 95% interval ' + intervalText(evidence);
140
- return [figure, withTip(interval, interval + ' for ' + subject,
141
- counted + ' in ' + evidence.count + ' of ' + evidence.planned + ' planned answers; '
142
- + evidence.captured + ' captured')];
143
- };
144
- const rateStat = (label, rate, recorded, counted) =>
145
- el('div', { class: 'stat' }, ...rateFigure(rate, recorded, label.toLowerCase(), counted), label);
146
- // Every surface that ran, each with its own pair of rates.
147
- const modelTable = (byModel, labelOf) => {
148
- const rows = Object.entries(byModel && typeof byModel === 'object' ? byModel : {})
149
- .map(([surface, rates]) => {
150
- const { shareOfVoice, citationRate, shareOfVoiceEvidence, citationRateEvidence } = rates || {};
151
- const model = labelOf(surface);
152
- return el('tr', {},
153
- el('td', {}, model),
154
- el('td', {}, ...rateFigure(shareOfVoice, shareOfVoiceEvidence, model + ' share of voice', 'Mentioned')),
155
- el('td', {}, ...rateFigure(citationRate, citationRateEvidence, model + ' citation rate', 'Cited')),
156
- );
157
- });
158
- if (!rows.length) return [];
159
- return [el('h3', {}, 'By model'), el('table', { class: 'by-model' },
160
- el('thead', {}, el('tr', {}, el('th', {}, 'Model'), el('th', {}, 'Share of voice'),
161
- el('th', {}, 'Citation rate'))),
162
- el('tbody', {}, ...rows))];
163
- };
164
- const answerKey = (section, promptId, surface, runIndex) =>
165
- section + '|' + promptId + '|' + surface + '|' + runIndex;
166
-
167
- const sourceLink = (url) => {
168
- // External sources open only on a deliberate click, in a new context.
169
- const button = el('button', { class: 'link', type: 'button' }, url);
170
- button.addEventListener('click', () => {
171
- if (/^https?:\\/\\//.test(url)) window.open(url, '_blank', 'noopener,noreferrer');
172
- });
173
- return button;
174
- };
175
-
176
- const render = async () => {
177
- const root = document.getElementById('app');
178
- const [info, verification, snapshot, captures, config] = await Promise.all([
179
- get('__viewer'), get('__verification'), get('report/snapshot.json'),
180
- get('captures/units.json'), get('inputs/config.json'),
181
- ]);
182
- root.replaceChildren();
183
- if (!info) {
184
- root.append(el('p', {}, 'This viewer link is not valid. Start it again with literally-aeo view.'));
185
- return;
186
- }
187
- const brand = (snapshot && snapshot.brand && snapshot.brand.name)
188
- || (config && config.brand && config.brand.name) || 'Audit';
189
- root.append(
190
- el('h1', {}, brand + ': AI visibility audit'),
191
- el('p', { class: 'muted' }, info.originLabel + ' \xB7 ' + info.source),
192
- );
193
- if (info.workingState) {
194
- root.append(el('div', { class: 'banner warn' },
195
- 'Working state, not a finalized revision: this is not an integrity receipt. Export the run to finalize it.'));
196
- }
197
- if (verification) {
198
- const rows = verification.checks.map((check) => el('tr', {},
199
- el('td', {}, check.title),
200
- el('td', { class: check.outcome === 'pass' ? 'pass' : check.outcome === 'fail' ? 'fail' : 'limited' },
201
- check.outcome.replace('_', ' ')),
202
- el('td', { class: 'muted' }, check.outcome === 'pass' ? '' : check.explanation),
203
- ));
204
- root.append(el('h2', {}, 'Verification'),
205
- el('p', { class: 'muted' }, 'Capture authenticity: self-reported. Checks run on this machine, offline.'),
206
- el('div', { class: 'table-wrap' }, el('table', {}, el('tbody', {}, ...rows))));
207
- }
208
- if (!snapshot) {
209
- root.append(el('div', { class: 'banner' }, 'This run has no report yet: the measurement did not finish.'));
210
- return;
211
- }
212
- const answers = new Map();
213
- for (const record of captures || []) {
214
- answers.set(answerKey(record.sectionKey, record.promptId, record.surface, record.runIndex), record);
215
- }
216
- // The snapshot names prompts by text; their ids, which key the captured
217
- // answers, come from the frozen configuration in the same order.
218
- const promptIds = new Map();
219
- for (const configured of (config && config.sections) || []) {
220
- promptIds.set(configured.key, configured.prompts.map((prompt) => prompt.id));
221
- }
222
-
223
- // A surface asked of another model than its default, and every custom
224
- // surface, carries its own label in the snapshot; any other is shown by
225
- // its ID. Like every string of a bundle, a label is inserted as text.
226
- const labels = (snapshot.meta && snapshot.meta.surfaceLabels) || {};
227
- const labelOf = (surface) =>
228
- typeof labels[surface] === 'string' && labels[surface] ? labels[surface] : surface;
229
-
230
- for (const section of snapshot.sections) {
231
- const { summary, matrix, prompts } = section.visibility;
232
- root.append(el('h2', {}, 'Section ' + section.key));
233
- root.append(el('div', { class: 'grid' },
234
- rateStat('Assistant share of voice', summary.prospectShareOfVoice,
235
- summary.prospectShareOfVoiceEvidence, 'Mentioned'),
236
- rateStat('Assistant citation rate', summary.prospectCitationRate,
237
- summary.prospectCitationRateEvidence, 'Cited'),
238
- rateStat('Coding-agent share of voice', summary.agentShareOfVoice,
239
- summary.agentShareOfVoiceEvidence, 'Mentioned'),
240
- rateStat('Coding-agent citation rate', summary.agentCitationRate,
241
- summary.agentCitationRateEvidence, 'Cited'),
242
- // The scraped consumer apps, only for a run that planned one.
243
- ...(summary.consumerShareOfVoice === undefined ? [] : [
244
- rateStat('Consumer-app share of voice', summary.consumerShareOfVoice,
245
- summary.consumerShareOfVoiceEvidence, 'Mentioned'),
246
- rateStat('Consumer-app citation rate', summary.consumerCitationRate,
247
- summary.consumerCitationRateEvidence, 'Cited'),
248
- ]),
249
- el('div', { class: 'stat' }, el('b', {}, summary.topCompetitorDomain || 'none'), 'Most mentioned competitor'),
250
- ));
251
- root.append(el('p', { class: 'muted' },
252
- 'Share of voice is how often the measured answers name the product, not market share.'));
253
- root.append(...modelTable(summary.byModel, labelOf));
254
- const drawer = el('div', { class: 'drawer', hidden: '' });
255
- const body = el('tbody');
256
- for (const row of matrix) {
257
- const prompt = prompts[row.promptIdx] || { text: '' };
258
- const promptId = (promptIds.get(section.key) || [])[row.promptIdx];
259
- const record = answers.get(answerKey(section.key, promptId, row.surface, row.runIndex || 0));
260
- const open = () => {
261
- drawer.removeAttribute('hidden');
262
- drawer.replaceChildren(
263
- el('h3', {}, labelOf(row.surface) + ', run ' + (row.runIndex || 0)),
264
- el('p', {}, prompt.text),
265
- record ? el('pre', {}, record.probe.text)
266
- : el('p', { class: 'limited' }, 'The answer is not in this bundle.'),
267
- ...(row.citedUrls && row.citedUrls.length
268
- ? [el('h3', {}, 'Cited sources'), ...row.citedUrls.map((url) => el('div', {}, sourceLink(url)))]
269
- : []),
270
- );
271
- drawer.scrollIntoView({ block: 'nearest' });
272
- };
273
- body.append(el('tr', { class: 'row', tabindex: '0', onclick: open,
274
- onkeydown: (event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); open(); } } },
275
- el('td', {}, prompt.text),
276
- el('td', {}, labelOf(row.surface)),
277
- el('td', {}, String(row.runIndex || 0)),
278
- el('td', {}, row.prospectMentioned ? 'mentioned' + (row.prospectPosition ? ' (' + row.prospectPosition + ')' : '') : 'not mentioned'),
279
- el('td', {}, (row.qualifiedCompetitors || []).map((entry) => entry.name).join(', ')),
280
- ));
281
- }
282
- root.append(el('div', { class: 'table-wrap' }, el('table', {},
283
- el('thead', {}, el('tr', {}, el('th', {}, 'Question'), el('th', {}, 'Surface'),
284
- el('th', {}, 'Run'), el('th', {}, 'Product'), el('th', {}, 'Alternatives named'))),
285
- body)), drawer);
286
- }
287
- const methodology = snapshot.meta && Array.isArray(snapshot.meta.methodology)
288
- ? snapshot.meta.methodology.filter((sentence) => typeof sentence === 'string')
289
- : [];
290
- if (methodology.length) {
291
- root.append(el('h2', {}, 'Methodology'),
292
- el('ul', { class: 'methodology' },
293
- ...methodology.map((sentence) => el('li', {}, sentence))));
294
- }
295
- root.append(el('footer', {},
296
- 'Generated with Literally.dev AEO, an open-source AI visibility audit tool. ',
297
- info.originLabel + '. Literally.dev did not review this result. Engine ' + info.toolVersion + '.'));
298
- };
299
-
300
- render().catch((error) => {
301
- document.getElementById('app').textContent = 'The viewer could not load this bundle: ' + error.message;
302
- });
303
- `;
304
- var viewerPage = (nonce) => {
305
- return `<!doctype html>
306
- <html lang="en">
307
- <head>
308
- <meta charset="utf-8">
309
- <meta name="viewport" content="width=device-width, initial-scale=1">
310
- <meta name="referrer" content="no-referrer">
311
- <title>Literally.dev AEO</title>
312
- <style nonce="${nonce}">${styles}</style>
313
- </head>
314
- <body>
315
- <main id="app"><p class="muted">Loading the audit\u2026</p></main>
316
- <script nonce="${nonce}">${script}</script>
317
- </body>
318
- </html>`;
319
- };
320
-
321
- export {
322
- viewerPage
323
- };