Skip to content

Commit eee9f14

Browse files
committed
feat(traces): show a trial's conversation call by call, with its pictures
The Conversation tab lists the steps of a trajectory, and the pictures an agent sent its model show nowhere. A trial with an exchange record now opens the tab on its model calls, twelve a page: the selected call shows what it sent that the call before had not, its answer and the steps under it. A picture is served from the trial's own store by its sha256, only when that store lists it and only as an image type; a click opens it in a dialog over the page, and a click with a key held opens it in a tab of its own. The Artifacts tab counts the pictures and their size, with a link to the tab.
1 parent 3e3a7a0 commit eee9f14

7 files changed

Lines changed: 454 additions & 9 deletions

File tree

‎app/static/traces/conversation.css‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/static/traces/conversation.js‎

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
return node;
1515
};
1616
const number = value => Number(value).toLocaleString();
17+
// A picture of the conversation over the page: one dialog, made at the first, closed by Close, Esc or a click
18+
// outside the picture (on the backdrop, which is the dialog itself)
19+
let viewer = null;
20+
const viewPicture = (url, alt) => {
21+
if (!viewer) {
22+
viewer = el('dialog', 'picture-view'); viewer.setAttribute('aria-label', 'Picture');
23+
const box = el('div', 'picture-view-box');
24+
box.append(button('Close', () => viewer.close(), false, 'btn sm picture-view-close'), el('img', 'picture-view-img'));
25+
viewer.append(box);
26+
viewer.addEventListener('click', event => { if (event.target === viewer) viewer.close(); });
27+
document.body.append(viewer);
28+
}
29+
const img = viewer.querySelector('img'); img.src = url; img.alt = alt;
30+
viewer.showModal();
31+
};
1732
const readJSON = async (url, signal) => {
1833
const response = await nulliusFetch(url, {signal, headers: {'Accept': 'application/json'}, cache: 'no-store'});
1934
if (!response.ok) throw new Error(response.status === 404 ? 'This evidence is no longer in the current workspace or trace view.' : 'Could not load this evidence. Try again.');
@@ -85,7 +100,7 @@
85100
let loadConversation = () => {};
86101
if (reader?.querySelector('.reader-layout')) {
87102
const urlState = new URL(location.href).searchParams;
88-
let state = {q: urlState.get('c_q') || '', kind: urlState.get('c_kind') || 'all',
103+
let state = {q: urlState.get('c_q') || '', kind: urlState.get('c_kind') || reader.dataset.defaultKind || 'all',
89104
page: urlState.get('c_page') || 1, position: urlState.get('c_position'),
90105
section: urlState.get('c_section'), chunk: urlState.get('c_chunk') || 0};
91106
let controller, latest;
@@ -96,6 +111,102 @@
96111
const indexHost = reader.querySelector('.reader-rows');
97112
const pages = reader.querySelector('.reader-pages');
98113
const change = patch => { state = {...state, ...patch}; loadConversation(); };
114+
// The view by model call: one row a call, then what it sent, its answer and the steps under it.
115+
const clock = iso => { const at = new Date(iso); return Number.isNaN(at.getTime()) ? '' : at.toLocaleTimeString(); };
116+
const size = value => value >= 1048576 ? `${(value / 1048576).toFixed(1)} MB` : `${number(Math.max(1, Math.round(value / 1024)))} KB`;
117+
const said = value => typeof value === 'string' ? value : JSON.stringify(value);
118+
const part = (title, children) => { const box = el('div', 'call-part'); box.append(el('h4', '', title), ...children); return box; };
119+
const picture = p => {
120+
if (!p.url) return el('span', 'call-picture-kept', [p.type, p.bytes ? size(p.bytes) : '', 'not kept'].filter(Boolean).join(' · '));
121+
const link = el('a', 'call-picture-link'); link.href = p.url; link.target = '_blank'; link.rel = 'noopener';
122+
const img = el('img', 'call-picture'); img.src = p.url; img.alt = `Picture ${p.sha256.slice(0, 12)}, ${p.type}`;
123+
img.loading = 'lazy'; img.decoding = 'async'; link.title = `sha256 ${p.sha256}`;
124+
// a click opens it over the page; a click with a key held still opens it in a tab of its own
125+
link.addEventListener('click', event => {
126+
if (event.button || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
127+
event.preventDefault(); viewPicture(p.url, img.alt);
128+
});
129+
link.append(img); return link;
130+
};
131+
const item = (entry, selected) => {
132+
const node = button('', () => change({section: entry.key, chunk: 0}), false, 'call-item');
133+
node.setAttribute('aria-pressed', String(selected === entry.key));
134+
node.append(el('span', 'call-item-kind', entry.label), el('span', 'call-item-preview', entry.preview));
135+
if (entry.characters) node.append(el('span', 'call-item-size mono', number(entry.characters)));
136+
return node;
137+
};
138+
const step = entry => {
139+
const node = button('', () => { searchInput.value = ''; change({kind: 'all', q: '', step: String(entry.step_id), position: null, page: 1, section: null, chunk: 0}); }, false, 'call-item');
140+
node.append(el('span', 'call-item-kind mono', `#${entry.step_id} ${entry.source || ''}`), el('span', 'call-item-preview', entry.preview));
141+
return node;
142+
};
143+
const textWindow = content => {
144+
const block = el('div', 'reader-content'), head = el('div', 'reader-content-head');
145+
head.append(el('h4', '', content.label), el('span', 'mono', `${number(content.characters)} characters`));
146+
block.append(head);
147+
if (content.text) { const pre = el('pre', '', content.text); pre.tabIndex = 0; pre.setAttribute('aria-label', content.label); block.append(pre); }
148+
else block.append(el('p', 'muted', 'No content recorded.'));
149+
const nav = el('nav', 'reader-content-nav'); nav.setAttribute('aria-label', 'Content pages');
150+
nav.append(button('← Previous', () => change({section: content.key, chunk: content.chunk - 1}), content.chunk === 0),
151+
el('span', '', `Part ${number(content.chunk + 1)} / ${number(content.chunks)} · ${number(content.start + (content.characters ? 1 : 0))}–${number(content.end)}`),
152+
button('Next →', () => change({section: content.key, chunk: content.chunk + 1}), content.chunk + 1 >= content.chunks));
153+
block.append(nav); return block;
154+
};
155+
const renderCalls = data => {
156+
status.textContent = `${number(data.matches)} of ${number(data.total)} calls${data.query ? ` match “${data.query}”` : ''}. ${data.notice || 'Select a call to see what it sent and answered.'}`;
157+
indexHost.replaceChildren();
158+
data.rows.forEach(row => {
159+
const node = button('', () => change({position: row.position, section: null, chunk: 0}), false, 'reader-row');
160+
node.setAttribute('aria-current', String(row.position === data.selected?.position));
161+
const meta = el('span', 'reader-row-meta');
162+
meta.append(el('span', 'mono', row.label));
163+
if (row.time) meta.append(el('span', '', clock(row.time)));
164+
if (row.tokens && row.tokens.input !== undefined) meta.append(el('span', '', `${number(row.tokens.input)} in · ${number(row.tokens.output || 0)} out`));
165+
if (row.pictures) meta.append(el('span', '', `${row.pictures} picture${row.pictures === 1 ? '' : 's'}`));
166+
if (row.unreadable || row.status !== 200) meta.append(el('span', 'reader-error', '!'));
167+
node.append(meta, el('span', 'reader-row-preview', row.preview)); indexHost.append(node);
168+
});
169+
pages.querySelector('span').textContent = `${data.page} / ${data.pages}`;
170+
pages.querySelector('[data-page=previous]').disabled = data.page <= 1;
171+
pages.querySelector('[data-page=next]').disabled = data.page >= data.pages;
172+
selectedHost.replaceChildren();
173+
const chosen = data.selected;
174+
if (!chosen) { selectedHost.append(el('p', 'muted', data.notice || 'No calls match.')); return; }
175+
const header = el('div', 'reader-step-nav'), info = el('div');
176+
info.append(el('h3', '', [chosen.label, chosen.model, chosen.side ? 'side call' : ''].filter(Boolean).join(' · ')));
177+
const facts = [`${chosen.match_number} of ${data.matches} calls`];
178+
if (chosen.time) facts.push(chosen.time);
179+
if (chosen.seconds !== null) facts.push(`${chosen.seconds.toFixed(2)}s`);
180+
const t = chosen.tokens || {};
181+
if (t.input !== undefined) facts.push(`input ${number(t.input)}${t.cached ? ` (cached ${number(t.cached)})` : ''} · output ${number(t.output || 0)}${t.reasoning ? ` (reasoning ${number(t.reasoning)})` : ''}`);
182+
if (chosen.cost_usd !== null) facts.push(`$${chosen.cost_usd.toFixed(4)}${chosen.cost_from === 'estimate' ? ' estimated' : ''}`);
183+
info.append(el('p', '', facts.join(' · ')));
184+
const actions = el('div', 'reader-step-actions');
185+
actions.append(button('← Previous', () => change({position: chosen.previous, section: null, chunk: 0}), chosen.previous === null), button('Next →', () => change({position: chosen.next, section: null, chunk: 0}), chosen.next === null));
186+
header.append(info, actions); selectedHost.append(header);
187+
const selected = chosen.content?.key, sent = [], answer = [];
188+
if (!chosen.sent.recorded) sent.push(el('p', chosen.sent.unreadable ? 'small bad' : 'muted', chosen.sent.note));
189+
else {
190+
if (!chosen.sent.items.length && !chosen.sent.folded) sent.push(el('p', 'muted', 'Nothing the call before did not send.'));
191+
chosen.sent.items.forEach(entry => {
192+
sent.push(item(entry, selected));
193+
if (entry.pictures.length) { const row = el('div', 'call-pictures'); entry.pictures.forEach(p => row.append(picture(p))); sent.push(row); }
194+
});
195+
const folded = chosen.sent.folded;
196+
if (folded) sent.push(item({key: folded.key, label: 'Rewritten or dropped', preview: [folded.rewritten ? `${folded.rewritten} rewritten` : '', folded.dropped ? `${folded.dropped} dropped` : ''].filter(Boolean).join(' · ')}, selected));
197+
}
198+
selectedHost.append(part('Sent', sent));
199+
const a = chosen.answer;
200+
const ended = [a.end ? `ended ${said(a.end)}` : '', a.served_by ? `served by ${a.served_by}` : '', a.abridged ? 'abridged in the call record' : ''].filter(Boolean);
201+
if (ended.length) answer.push(el('p', 'call-facts', ended.join(' · ')));
202+
if (a.error) answer.push(el('p', 'small bad', `Error in the reply · ${a.error.message || said(a.error)}`));
203+
a.items.forEach(entry => answer.push(item(entry, selected)));
204+
if (!a.items.length) answer.push(el('p', 'muted', chosen.refused ? 'Refused: nothing was sent.' : 'No answer recorded.'));
205+
selectedHost.append(part('Answer', answer));
206+
if (chosen.content) selectedHost.append(textWindow(chosen.content));
207+
if (chosen.before.length) selectedHost.append(part('Before the first call', chosen.before.map(step)));
208+
if (chosen.steps.length) selectedHost.append(part('Steps under it', [...chosen.steps.map(step), ...(chosen.more_steps ? [el('p', 'muted small', `and ${number(chosen.more_steps)} more`)] : [])]));
209+
};
99210
loadConversation = async () => {
100211
conversationStarted = true;
101212
controller?.abort(); controller = new AbortController();
@@ -118,6 +229,8 @@
118229
else current.searchParams.delete(`c_${key}`);
119230
});
120231
history.replaceState(null, '', current);
232+
reader.querySelectorAll('[data-kind]').forEach(node => node.setAttribute('aria-pressed', String(node.dataset.kind === data.kind)));
233+
if (data.view === 'calls') { renderCalls(data); return; }
121234
status.textContent = `${number(data.matches)} of ${number(data.total)} source steps${data.query ? ` match “${data.query}”` : ''}. ${data.notice || 'Select a row to keep its message and tools together.'}`;
122235
reader.querySelectorAll('[data-kind]').forEach(node => node.setAttribute('aria-pressed', String(node.dataset.kind === data.kind)));
123236
indexHost.replaceChildren();
@@ -180,6 +293,12 @@
180293
if (next !== undefined) { event.preventDefault(); tabs[next].focus(); openTab(tabs[next].dataset.tab); }
181294
});
182295
});
296+
// a link of the Artifacts tab to another tab of this page opens it in place
297+
document.getElementById('trial-artifacts')?.addEventListener('click', event => {
298+
const link = event.target.closest('a[data-open-tab]');
299+
if (!link || !tabs.some(tab => tab.dataset.tab === link.dataset.openTab)) return;
300+
event.preventDefault(); openTab(link.dataset.openTab); document.getElementById('tab-' + link.dataset.openTab)?.focus();
301+
});
183302
openTab(location.hash.startsWith('#span=') ? 'trace' : new URL(location.href).searchParams.get('tab') || 'overview', false);
184303

185304
let spanController;

‎app/templates/traces/_conversation.html‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<section class="conversation-reader" id="conversation-reader"
2-
data-endpoint="{{ url_for('conversation_data', job_id=job.job_id, trial_name=trial.trial_name) }}"
2+
data-endpoint="{{ url_for('conversation_data', job_id=job.job_id, trial_name=trial.trial_name) }}"{% if n_calls %} data-default-kind="calls"{% endif %}
33
aria-label="Conversation reader">
4-
{% if traj and not traj.error %}
4+
{% if (traj and not traj.error) or n_calls %}
55
<div class="reader-heading">
6-
<span class="reader-total mono">{{ traj.n_steps }} steps</span>
6+
<span class="reader-total mono">{% if n_calls %}{{ n_calls }} call{{ 's' if n_calls != 1 }}{% if traj and not traj.error %} · {% endif %}{% endif %}{% if traj and not traj.error %}{{ traj.n_steps }} steps{% endif %}</span>
77
</div>
88
{% endif %}
9-
{% if not traj or traj.error %}
9+
{% if (not traj or traj.error) and not n_calls %}
1010
<div class="panel"><p class="muted" style="margin:0">{% if traj and traj.error %}Trajectory unreadable: {{ traj.error }}{% elif trial.agent_type == 'control' %}This control has no recorded conversation.{% else %}No trajectory recorded for this trial.{% endif %}</p></div>
1111
{% else %}
1212
<form class="reader-search" role="search">
@@ -17,7 +17,8 @@
1717
</form>
1818
<div class="reader-toolbar">
1919
<div class="reader-filters" role="group" aria-label="Conversation filter">
20-
<button type="button" data-kind="all" aria-pressed="true">All steps</button>
20+
{% if n_calls %}<button type="button" data-kind="calls" aria-pressed="true">Calls</button>
21+
{% endif %}<button type="button" data-kind="all" aria-pressed="{{ 'false' if n_calls else 'true' }}">All steps</button>
2122
<button type="button" data-kind="messages" aria-pressed="false">Messages</button>
2223
<button type="button" data-kind="tools" aria-pressed="false">Tools</button>
2324
<button type="button" data-kind="errors" aria-pressed="false" title="Tool failures flagged by the existing trajectory reader, not benchmark verdicts">Errors</button>

‎app/templates/traces/trial.html‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,12 @@ <h3>Waterfall</h3>
564564
{% include 'traces/_conversation.html' %}
565565
</section>
566566
<section class="trial-tab" id="trial-artifacts" role="tabpanel" aria-labelledby="tab-artifacts">
567-
{% if artifacts %}
567+
{% if artifacts or pictures %}
568568
<div class="panel">
569569
<table class="grid"><thead><tr><th>Record</th><th class="num">Size</th><th></th></tr></thead><tbody>
570+
{#- the pictures sent to the model, each kept once in the record of its calls, read on the Conversation tab #}
571+
{% if pictures %}<tr class="artifact-pictures"><td>Pictures sent to the model <span class="muted">· {{ pictures.count }}</span></td><td class="num mono muted">{{ '%.2f'|format(pictures.bytes / 1024) }} KB</td>
572+
<td><span class="artifact-actions"><a class="btn ghost sm" href="{{ url_for('trial', job_id=job.job_id, trial_name=trial.trial_name, tab='conversation', workspace=request.args.get('workspace')) }}" data-open-tab="conversation">Conversation</a></span></td></tr>{% endif %}
570573
{% for artifact in artifacts %}
571574
<tr><td>{{ artifact.label }}</td><td class="num mono muted">{{ '%.2f'|format(artifact.size / 1024) }} KB</td>
572575
<td><span class="artifact-actions"><a class="btn ghost sm" href="{{ artifact.url }}">Read</a><a class="btn ghost sm" href="{{ artifact.download }}" download>Download</a></span></td></tr>

0 commit comments

Comments
 (0)