LiamKhoaLe commited on
Commit
607bc14
·
1 Parent(s): 2364a33

Upd dw btn and references at state saver

Browse files
Files changed (2) hide show
  1. static/projects.js +4 -0
  2. static/script.js +35 -0
static/projects.js CHANGED
@@ -283,6 +283,8 @@
283
  if (msg.role === 'assistant' && Array.isArray(msg.sources) && msg.sources.length) {
284
  if (typeof window.appendSources === 'function') {
285
  window.appendSources(msg.sources);
 
 
286
  }
287
  }
288
  } else {
@@ -298,6 +300,8 @@
298
  srcDiv.className = 'sources';
299
  srcDiv.textContent = 'Sources: ' + msg.sources.map(s => s.filename).join(', ');
300
  messagesContainer.appendChild(srcDiv);
 
 
301
  }
302
  }
303
  });
 
283
  if (msg.role === 'assistant' && Array.isArray(msg.sources) && msg.sources.length) {
284
  if (typeof window.appendSources === 'function') {
285
  window.appendSources(msg.sources);
286
+ // Store sources for PDF generation
287
+ window.__sb_current_sources = msg.sources;
288
  }
289
  }
290
  } else {
 
300
  srcDiv.className = 'sources';
301
  srcDiv.textContent = 'Sources: ' + msg.sources.map(s => s.filename).join(', ');
302
  messagesContainer.appendChild(srcDiv);
303
+ // Store sources for PDF generation
304
+ window.__sb_current_sources = msg.sources;
305
  }
306
  }
307
  });
static/script.js CHANGED
@@ -935,11 +935,46 @@
935
  sourcesDiv.innerHTML = `<strong>Sources:</strong> ${sourcesList}`;
936
  messages.appendChild(sourcesDiv);
937
 
 
 
 
938
  requestAnimationFrame(() => {
939
  sourcesDiv.scrollIntoView({ behavior: 'smooth', block: 'end' });
940
  });
941
  }
942
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
  function showButtonLoading(button, isLoading) {
944
  const textSpan = button.querySelector('.btn-text');
945
  const loadingSpan = button.querySelector('.btn-loading');
 
935
  sourcesDiv.innerHTML = `<strong>Sources:</strong> ${sourcesList}`;
936
  messages.appendChild(sourcesDiv);
937
 
938
+ // Store sources for PDF generation
939
+ window.__sb_current_sources = sources;
940
+
941
  requestAnimationFrame(() => {
942
  sourcesDiv.scrollIntoView({ behavior: 'smooth', block: 'end' });
943
  });
944
  }
945
 
946
+ function findCurrentSources() {
947
+ // Try to get sources from the current message context
948
+ if (window.__sb_current_sources) {
949
+ return window.__sb_current_sources;
950
+ }
951
+
952
+ // Fallback: look for sources in the last assistant message
953
+ const lastAssistantMsg = Array.from(messages.children).reverse().find(msg =>
954
+ msg.classList.contains('msg') && msg.classList.contains('assistant')
955
+ );
956
+
957
+ if (lastAssistantMsg) {
958
+ const sourcesDiv = lastAssistantMsg.nextElementSibling;
959
+ if (sourcesDiv && sourcesDiv.classList.contains('sources')) {
960
+ // Extract sources from the DOM (this is a fallback)
961
+ const pills = sourcesDiv.querySelectorAll('.pill');
962
+ const sources = Array.from(pills).map(pill => {
963
+ const text = pill.textContent;
964
+ const parts = text.split(' • ');
965
+ return {
966
+ filename: parts[0] || 'Unknown',
967
+ topic_name: parts[1] || '',
968
+ score: 0.0
969
+ };
970
+ });
971
+ return sources;
972
+ }
973
+ }
974
+
975
+ return [];
976
+ }
977
+
978
  function showButtonLoading(button, isLoading) {
979
  const textSpan = button.querySelector('.btn-text');
980
  const loadingSpan = button.querySelector('.btn-loading');