{% for message in history %}
{% if message.role == "AI" %}
-
- {{ message.content }}
+
+ {{ message.content|safe }}
{% if message.references %}
{% include "chat/reference_list.html" %}
@@ -13,42 +13,130 @@
{% else %}
-
- {{ message.content }}
+
+ {{ message.content|safe }}
{% endif %}
{% endfor %}
+
\ No newline at end of file
diff --git a/html-router/templates/chat/reference_list.html b/html-router/templates/chat/reference_list.html
index 4bdb00c..75bf761 100644
--- a/html-router/templates/chat/reference_list.html
+++ b/html-router/templates/chat/reference_list.html
@@ -1,11 +1,12 @@
-
+
{% for reference in message.references %}
@@ -19,72 +20,130 @@
\ No newline at end of file
+
+ document.body.addEventListener('htmx:afterSwap', function () {
+ initializeReferenceTooltips();
+ });
+
+ function initializeReferenceTooltips() {
+ document.querySelectorAll('.reference-badge-container').forEach(container => {
+ if (container.dataset.initialized === 'true') return;
+
+ const reference = container.dataset.reference;
+ const messageId = container.dataset.messageId;
+ const index = container.dataset.index;
+ let tooltipId = `tooltip-${messageId}-${index}`;
+ let tooltipContent = null;
+ let tooltipTimeout;
+
+ // Create tooltip element (initially hidden)
+ function createTooltip() {
+ const tooltip = document.createElement('div');
+ tooltip.id = tooltipId;
+ tooltip.className = 'fixed z-[9999] bg-neutral-800 text-white p-3 rounded-md shadow-lg text-sm w-72 max-w-xs border border-neutral-700 hidden';
+ tooltip.innerHTML = '
Loading...
';
+ document.body.appendChild(tooltip);
+ return tooltip;
+ }
+
+ container.addEventListener('mouseenter', function () {
+ // Clear any existing timeout
+ if (tooltipTimeout) clearTimeout(tooltipTimeout);
+
+ // Get or create tooltip
+ let tooltip = document.getElementById(tooltipId);
+ if (!tooltip) tooltip = createTooltip();
+
+ // Position tooltip
+ const rect = container.getBoundingClientRect();
+ tooltip.style.top = `${rect.bottom + window.scrollY + 5}px`;
+ tooltip.style.left = `${rect.left + window.scrollX}px`;
+
+ // Adjust position if it would overflow viewport
+ const tooltipRect = tooltip.getBoundingClientRect();
+ if (rect.left + tooltipRect.width > window.innerWidth - 20) {
+ tooltip.style.left = `${window.innerWidth - tooltipRect.width - 20 + window.scrollX}px`;
+ }
+
+ // Show tooltip
+ tooltip.classList.remove('hidden');
+
+ // Load content if needed
+ if (!tooltipContent) {
+ fetch(`/chat/reference/${encodeURIComponent(reference)}`)
+ .then(response => response.text())
+ .then(html => {
+ tooltipContent = html;
+ if (document.getElementById(tooltipId)) {
+ document.getElementById(tooltipId).innerHTML = html;
+ }
+ });
+ } else if (tooltip) {
+ // Set content if already loaded
+ tooltip.innerHTML = tooltipContent;
+ }
+ });
+
+ container.addEventListener('mouseleave', function () {
+ tooltipTimeout = setTimeout(() => {
+ const tooltip = document.getElementById(tooltipId);
+ if (tooltip) tooltip.classList.add('hidden');
+ }, 200);
+ });
+
+ container.dataset.initialized = 'true';
+ });
+ }
+
+
+
\ No newline at end of file
diff --git a/html-router/templates/head_base.html b/html-router/templates/head_base.html
index a9f674c..d275fb2 100644
--- a/html-router/templates/head_base.html
+++ b/html-router/templates/head_base.html
@@ -19,7 +19,6 @@
-