Skip to content

Commit 07e3e9f

Browse files
committed
Show artifacts_json in sidebar and in /program/ pages
1 parent f25c3ce commit 07e3e9f

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

scripts/static/js/sidebar.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function showSidebarContent(d, fromHover = false) {
3232
let tabContentHtml = '';
3333
let tabNames = [];
3434
if (d.code && typeof d.code === 'string' && d.code.trim() !== '') tabNames.push('Code');
35-
if (d.prompts && typeof d.prompts === 'object' && Object.keys(d.prompts).length > 0) tabNames.push('Prompts');
35+
if ((d.prompts && typeof d.prompts === 'object' && Object.keys(d.prompts).length > 0) || (d.artifacts_json && typeof d.artifacts_json === 'object' && Object.keys(d.artifacts_json).length > 0)) tabNames.push('Prompts');
3636
const children = allNodeData.filter(n => n.parent_id === d.id);
3737
if (children.length > 0) tabNames.push('Children');
3838
let activeTab = lastSidebarTab && tabNames.includes(lastSidebarTab) ? lastSidebarTab : tabNames[0];
@@ -46,19 +46,28 @@ export function showSidebarContent(d, fromHover = false) {
4646
// --- Prompt select logic ---
4747
let promptOptions = [];
4848
let promptMap = {};
49-
for (const [k, v] of Object.entries(d.prompts)) {
50-
if (v && typeof v === 'object' && !Array.isArray(v)) {
51-
for (const [subKey, subVal] of Object.entries(v)) {
52-
const optLabel = `${k} - ${subKey}`;
49+
// Prompts
50+
if (d.prompts && typeof d.prompts === 'object') {
51+
for (const [k, v] of Object.entries(d.prompts)) {
52+
if (v && typeof v === 'object' && !Array.isArray(v)) {
53+
for (const [subKey, subVal] of Object.entries(v)) {
54+
const optLabel = `${k} - ${subKey}`;
55+
promptOptions.push(optLabel);
56+
promptMap[optLabel] = subVal;
57+
}
58+
} else {
59+
const optLabel = `${k}`;
5360
promptOptions.push(optLabel);
54-
promptMap[optLabel] = subVal;
61+
promptMap[optLabel] = v;
5562
}
56-
} else {
57-
const optLabel = `${k}`;
58-
promptOptions.push(optLabel);
59-
promptMap[optLabel] = v;
6063
}
6164
}
65+
// Artifacts
66+
if (d.artifacts_json) {
67+
const optLabel = `artifacts`;
68+
promptOptions.push(optLabel);
69+
promptMap[optLabel] = d.artifacts_json;
70+
}
6271
// Get last selected prompt from localStorage, or default to first
6372
let lastPromptKey = localStorage.getItem('sidebarPromptSelect') || promptOptions[0] || '';
6473
if (!promptMap[lastPromptKey]) lastPromptKey = promptOptions[0] || '';
@@ -118,6 +127,24 @@ export function showSidebarContent(d, fromHover = false) {
118127
<b>Metrics:</b><br>${formatMetrics(d.metrics)}<br><br>
119128
${tabHtml}${tabContentHtml}
120129
</div>`;
130+
131+
// Helper to attach prompt select handler
132+
function attachPromptSelectHandler() {
133+
const promptSelect = document.getElementById('sidebar-prompt-select');
134+
if (promptSelect) {
135+
promptSelect.onchange = function() {
136+
localStorage.setItem('sidebarPromptSelect', promptSelect.value);
137+
// Only re-render the Prompts tab, not the whole sidebar
138+
const tabContent = document.getElementById('sidebar-tab-content');
139+
if (tabContent) {
140+
tabContent.innerHTML = renderSidebarTabContent('Prompts', d, children);
141+
attachPromptSelectHandler();
142+
}
143+
};
144+
}
145+
}
146+
attachPromptSelectHandler();
147+
121148
if (tabNames.length > 1) {
122149
const tabBar = document.getElementById('sidebar-tab-bar');
123150
Array.from(tabBar.children).forEach(tabEl => {
@@ -128,19 +155,8 @@ export function showSidebarContent(d, fromHover = false) {
128155
lastSidebarTab = tabName;
129156
const tabContent = document.getElementById('sidebar-tab-content');
130157
tabContent.innerHTML = renderSidebarTabContent(tabName, d, children);
131-
// Add prompt select event if Prompts tab
132158
if (tabName === 'Prompts') {
133-
const promptSelect = document.getElementById('sidebar-prompt-select');
134-
if (promptSelect) {
135-
promptSelect.onchange = function() {
136-
localStorage.setItem('sidebarPromptSelect', promptSelect.value);
137-
// Re-render Prompts tab with new selection
138-
tabContent.innerHTML = renderSidebarTabContent('Prompts', d, children);
139-
// Re-attach event
140-
const newPromptSelect = document.getElementById('sidebar-prompt-select');
141-
if (newPromptSelect) newPromptSelect.onchange = promptSelect.onchange;
142-
};
143-
}
159+
attachPromptSelectHandler();
144160
}
145161
setTimeout(() => {
146162
document.querySelectorAll('.child-link').forEach(link => {
@@ -167,18 +183,7 @@ export function showSidebarContent(d, fromHover = false) {
167183
});
168184
}
169185
setTimeout(() => {
170-
const promptSelect = document.getElementById('sidebar-prompt-select');
171-
if (promptSelect) {
172-
promptSelect.onchange = function() {
173-
localStorage.setItem('sidebarPromptSelect', promptSelect.value);
174-
// Re-render Prompts tab with new selection
175-
const tabContent = document.getElementById('sidebar-tab-content');
176-
tabContent.innerHTML = renderSidebarTabContent('Prompts', d, children);
177-
// Re-attach event
178-
const newPromptSelect = document.getElementById('sidebar-prompt-select');
179-
if (newPromptSelect) newPromptSelect.onchange = promptSelect.onchange;
180-
};
181-
}
186+
attachPromptSelectHandler();
182187
document.querySelectorAll('.child-link').forEach(link => {
183188
link.onclick = function(e) {
184189
e.preventDefault();

scripts/templates/program_page.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ <h2>Prompts:</h2>
3131
<li><strong>{{ key }}:</strong> <pre style="white-space: pre-wrap; word-break: break-word;">{{ value }}</pre></li>
3232
{% endfor %}
3333
</ul>
34+
{% if artifacts_json %}
35+
<h2>Artifacts:</h2>
36+
<pre style="white-space: pre-wrap; word-break: break-word;">{{ artifacts_json }}</pre>
37+
{% endif %}
3438
</body>
3539
</html>

scripts/visualizer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ def program_page(program_id):
9696
data = load_evolution_data(checkpoint_dir)
9797
program_data = next((p for p in data["nodes"] if p["id"] == program_id), None)
9898
program_data = {"code": "", "prompts": {}, **program_data}
99+
artifacts_json = program_data.get("artifacts_json", None)
99100

100101
return render_template(
101-
"program_page.html", program_data=program_data, checkpoint_dir=checkpoint_dir
102+
"program_page.html",
103+
program_data=program_data,
104+
checkpoint_dir=checkpoint_dir,
105+
artifacts_json=artifacts_json,
102106
)
103107

104108

0 commit comments

Comments
 (0)