@@ -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 ( ) ;
0 commit comments