0.9.0 - Added Trilium ETAPI integration.

Lyra can now: Search trilium notes and create new notes. with proper ETAPI auth.
This commit is contained in:
serversdwn
2025-12-29 01:58:20 -05:00
parent 64429b19e6
commit 794baf2a96
14 changed files with 2063 additions and 39 deletions

View File

@@ -13,9 +13,44 @@
</head>
<body>
<!-- Mobile Menu Overlay -->
<div class="mobile-menu-overlay" id="mobileMenuOverlay"></div>
<!-- Mobile Slide-out Menu -->
<div class="mobile-menu" id="mobileMenu">
<div class="mobile-menu-section">
<h4>Mode</h4>
<select id="mobileMode">
<option value="standard">Standard</option>
<option value="cortex">Cortex</option>
</select>
</div>
<div class="mobile-menu-section">
<h4>Session</h4>
<select id="mobileSessions"></select>
<button id="mobileNewSessionBtn"> New Session</button>
<button id="mobileRenameSessionBtn">✏️ Rename Session</button>
</div>
<div class="mobile-menu-section">
<h4>Actions</h4>
<button id="mobileThinkingStreamBtn">🧠 Show Work</button>
<button id="mobileSettingsBtn">⚙ Settings</button>
<button id="mobileToggleThemeBtn">🌙 Toggle Theme</button>
<button id="mobileForceReloadBtn">🔄 Force Reload</button>
</div>
</div>
<div id="chat">
<!-- Mode selector -->
<div id="model-select">
<!-- Hamburger menu (mobile only) -->
<button class="hamburger-menu" id="hamburgerMenu" aria-label="Menu">
<span></span>
<span></span>
<span></span>
</button>
<label for="mode">Mode:</label>
<select id="mode">
<option value="standard">Standard</option>
@@ -33,7 +68,7 @@
<select id="sessions"></select>
<button id="newSessionBtn"> New</button>
<button id="renameSessionBtn">✏️ Rename</button>
<button id="thinkingStreamBtn" title="Show thinking stream in new window">🧠 Show Work</button>
<button id="thinkingStreamBtn" title="Show thinking stream panel">🧠 Show Work</button>
</div>
<!-- Status -->
@@ -45,6 +80,24 @@
<!-- Chat messages -->
<div id="messages"></div>
<!-- Thinking Stream Panel (collapsible) -->
<div id="thinkingPanel" class="thinking-panel collapsed">
<div class="thinking-header" id="thinkingHeader">
<span>🧠 Thinking Stream</span>
<div class="thinking-controls">
<span class="thinking-status-dot" id="thinkingStatusDot"></span>
<button class="thinking-clear-btn" id="thinkingClearBtn" title="Clear events">🗑️</button>
<button class="thinking-toggle-btn" id="thinkingToggleBtn"></button>
</div>
</div>
<div class="thinking-content" id="thinkingContent">
<div class="thinking-empty" id="thinkingEmpty">
<div class="thinking-empty-icon">🤔</div>
<p>Waiting for thinking events...</p>
</div>
</div>
</div>
<!-- Input box -->
<div id="input">
<input id="userInput" type="text" placeholder="Type a message..." autofocus />
@@ -124,7 +177,9 @@
async function renderSessions() {
const select = document.getElementById("sessions");
const mobileSelect = document.getElementById("mobileSessions");
select.innerHTML = "";
mobileSelect.innerHTML = "";
sessions.forEach(s => {
const opt = document.createElement("option");
@@ -132,6 +187,10 @@
opt.textContent = s.name || s.id;
if (s.id === currentSession) opt.selected = true;
select.appendChild(opt);
// Clone for mobile menu
const mobileOpt = opt.cloneNode(true);
mobileSelect.appendChild(mobileOpt);
});
}
@@ -268,6 +327,97 @@
}
document.addEventListener("DOMContentLoaded", () => {
// Mobile Menu Toggle
const hamburgerMenu = document.getElementById("hamburgerMenu");
const mobileMenu = document.getElementById("mobileMenu");
const mobileMenuOverlay = document.getElementById("mobileMenuOverlay");
function toggleMobileMenu() {
mobileMenu.classList.toggle("open");
mobileMenuOverlay.classList.toggle("show");
hamburgerMenu.classList.toggle("active");
}
function closeMobileMenu() {
mobileMenu.classList.remove("open");
mobileMenuOverlay.classList.remove("show");
hamburgerMenu.classList.remove("active");
}
hamburgerMenu.addEventListener("click", toggleMobileMenu);
mobileMenuOverlay.addEventListener("click", closeMobileMenu);
// Sync mobile menu controls with desktop
const mobileMode = document.getElementById("mobileMode");
const desktopMode = document.getElementById("mode");
// Sync mode selection
mobileMode.addEventListener("change", (e) => {
desktopMode.value = e.target.value;
desktopMode.dispatchEvent(new Event("change"));
});
desktopMode.addEventListener("change", (e) => {
mobileMode.value = e.target.value;
});
// Mobile theme toggle
document.getElementById("mobileToggleThemeBtn").addEventListener("click", () => {
document.getElementById("toggleThemeBtn").click();
updateMobileThemeButton();
});
function updateMobileThemeButton() {
const isDark = document.body.classList.contains("dark");
document.getElementById("mobileToggleThemeBtn").textContent = isDark ? "☀️ Light Mode" : "🌙 Dark Mode";
}
// Mobile settings button
document.getElementById("mobileSettingsBtn").addEventListener("click", () => {
closeMobileMenu();
document.getElementById("settingsBtn").click();
});
// Mobile thinking stream button
document.getElementById("mobileThinkingStreamBtn").addEventListener("click", () => {
closeMobileMenu();
document.getElementById("thinkingStreamBtn").click();
});
// Mobile new session button
document.getElementById("mobileNewSessionBtn").addEventListener("click", () => {
closeMobileMenu();
document.getElementById("newSessionBtn").click();
});
// Mobile rename session button
document.getElementById("mobileRenameSessionBtn").addEventListener("click", () => {
closeMobileMenu();
document.getElementById("renameSessionBtn").click();
});
// Sync mobile session selector with desktop
document.getElementById("mobileSessions").addEventListener("change", async (e) => {
closeMobileMenu();
const desktopSessions = document.getElementById("sessions");
desktopSessions.value = e.target.value;
desktopSessions.dispatchEvent(new Event("change"));
});
// Mobile force reload button
document.getElementById("mobileForceReloadBtn").addEventListener("click", async () => {
if (confirm("Force reload the app? This will clear cache and reload.")) {
// Clear all caches if available
if ('caches' in window) {
const cacheNames = await caches.keys();
await Promise.all(cacheNames.map(name => caches.delete(name)));
}
// Force reload from server (bypass cache)
window.location.reload(true);
}
});
// Dark mode toggle - defaults to dark
const btn = document.getElementById("toggleThemeBtn");
@@ -286,8 +436,12 @@
const isDark = document.body.classList.contains("dark");
btn.textContent = isDark ? "☀️ Light Mode" : "🌙 Dark Mode";
localStorage.setItem("theme", isDark ? "dark" : "light");
updateMobileThemeButton();
});
// Initialize mobile theme button
updateMobileThemeButton();
// Sessions - Load from server
(async () => {
await loadSessionsFromServer();
@@ -529,6 +683,236 @@
document.getElementById("userInput").addEventListener("keypress", e => {
if (e.key === "Enter") sendMessage();
});
// ========== THINKING STREAM INTEGRATION ==========
const thinkingPanel = document.getElementById("thinkingPanel");
const thinkingHeader = document.getElementById("thinkingHeader");
const thinkingToggleBtn = document.getElementById("thinkingToggleBtn");
const thinkingClearBtn = document.getElementById("thinkingClearBtn");
const thinkingContent = document.getElementById("thinkingContent");
const thinkingStatusDot = document.getElementById("thinkingStatusDot");
const thinkingEmpty = document.getElementById("thinkingEmpty");
let thinkingEventSource = null;
let thinkingEventCount = 0;
const CORTEX_BASE = "http://10.0.0.41:7081";
// Load thinking panel state from localStorage
const isPanelCollapsed = localStorage.getItem("thinkingPanelCollapsed") === "true";
if (!isPanelCollapsed) {
thinkingPanel.classList.remove("collapsed");
}
// Toggle thinking panel
thinkingHeader.addEventListener("click", (e) => {
if (e.target === thinkingClearBtn) return; // Don't toggle if clicking clear
thinkingPanel.classList.toggle("collapsed");
localStorage.setItem("thinkingPanelCollapsed", thinkingPanel.classList.contains("collapsed"));
});
// Clear thinking events
thinkingClearBtn.addEventListener("click", (e) => {
e.stopPropagation();
clearThinkingEvents();
});
function clearThinkingEvents() {
thinkingContent.innerHTML = '';
thinkingContent.appendChild(thinkingEmpty);
thinkingEventCount = 0;
// Clear from localStorage
if (currentSession) {
localStorage.removeItem(`thinkingEvents_${currentSession}`);
}
}
function connectThinkingStream() {
if (!currentSession) return;
// Close existing connection
if (thinkingEventSource) {
thinkingEventSource.close();
}
// Load persisted events
loadThinkingEvents();
const url = `${CORTEX_BASE}/stream/thinking/${currentSession}`;
console.log('Connecting thinking stream:', url);
thinkingEventSource = new EventSource(url);
thinkingEventSource.onopen = () => {
console.log('Thinking stream connected');
thinkingStatusDot.className = 'thinking-status-dot connected';
};
thinkingEventSource.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
addThinkingEvent(data);
saveThinkingEvent(data); // Persist event
} catch (e) {
console.error('Failed to parse thinking event:', e);
}
};
thinkingEventSource.onerror = (error) => {
console.error('Thinking stream error:', error);
thinkingStatusDot.className = 'thinking-status-dot disconnected';
// Retry connection after 2 seconds
setTimeout(() => {
if (thinkingEventSource && thinkingEventSource.readyState === EventSource.CLOSED) {
console.log('Reconnecting thinking stream...');
connectThinkingStream();
}
}, 2000);
};
}
function addThinkingEvent(event) {
// Remove empty state if present
if (thinkingEventCount === 0 && thinkingEmpty.parentNode) {
thinkingContent.removeChild(thinkingEmpty);
}
const eventDiv = document.createElement('div');
eventDiv.className = `thinking-event thinking-event-${event.type}`;
let icon = '';
let message = '';
let details = '';
switch (event.type) {
case 'connected':
icon = '✓';
message = 'Stream connected';
details = `Session: ${event.session_id}`;
break;
case 'thinking':
icon = '🤔';
message = event.data.message;
break;
case 'tool_call':
icon = '🔧';
message = event.data.message;
if (event.data.args) {
details = JSON.stringify(event.data.args, null, 2);
}
break;
case 'tool_result':
icon = '📊';
message = event.data.message;
if (event.data.result && event.data.result.stdout) {
details = `stdout: ${event.data.result.stdout}`;
}
break;
case 'done':
icon = '✅';
message = event.data.message;
if (event.data.final_answer) {
details = event.data.final_answer;
}
break;
case 'error':
icon = '❌';
message = event.data.message;
break;
default:
icon = '•';
message = JSON.stringify(event.data);
}
eventDiv.innerHTML = `
<span class="thinking-event-icon">${icon}</span>
<span>${message}</span>
${details ? `<div class="thinking-event-details">${details}</div>` : ''}
`;
thinkingContent.appendChild(eventDiv);
thinkingContent.scrollTop = thinkingContent.scrollHeight;
thinkingEventCount++;
}
// Persist thinking events to localStorage
function saveThinkingEvent(event) {
if (!currentSession) return;
const key = `thinkingEvents_${currentSession}`;
let events = JSON.parse(localStorage.getItem(key) || '[]');
// Keep only last 50 events to avoid bloating localStorage
if (events.length >= 50) {
events = events.slice(-49);
}
events.push({
...event,
timestamp: Date.now()
});
localStorage.setItem(key, JSON.stringify(events));
}
// Load persisted thinking events
function loadThinkingEvents() {
if (!currentSession) return;
const key = `thinkingEvents_${currentSession}`;
const events = JSON.parse(localStorage.getItem(key) || '[]');
// Clear current display
thinkingContent.innerHTML = '';
thinkingEventCount = 0;
// Replay events
events.forEach(event => addThinkingEvent(event));
// Show empty state if no events
if (events.length === 0) {
thinkingContent.appendChild(thinkingEmpty);
}
}
// Update the old thinking stream button to toggle panel instead
document.getElementById("thinkingStreamBtn").addEventListener("click", () => {
thinkingPanel.classList.remove("collapsed");
localStorage.setItem("thinkingPanelCollapsed", "false");
});
// Mobile thinking stream button
document.getElementById("mobileThinkingStreamBtn").addEventListener("click", () => {
closeMobileMenu();
thinkingPanel.classList.remove("collapsed");
localStorage.setItem("thinkingPanelCollapsed", "false");
});
// Connect thinking stream when session loads
if (currentSession) {
connectThinkingStream();
}
// Reconnect thinking stream when session changes
const originalSessionChange = document.getElementById("sessions").onchange;
document.getElementById("sessions").addEventListener("change", () => {
setTimeout(() => {
connectThinkingStream();
}, 500); // Wait for session to load
});
// Cleanup on page unload
window.addEventListener('beforeunload', () => {
if (thinkingEventSource) {
thinkingEventSource.close();
}
});
});
</script>
</body>

View File

@@ -432,3 +432,478 @@ select:hover {
color: #ff3333;
box-shadow: 0 0 8px rgba(255,0,0,0.3);
}
/* Thinking Stream Panel */
.thinking-panel {
border-top: 1px solid var(--accent);
background: rgba(255, 102, 0, 0.02);
display: flex;
flex-direction: column;
transition: max-height 0.3s ease;
max-height: 300px;
}
.thinking-panel.collapsed {
max-height: 40px;
}
.thinking-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 12px;
background: rgba(255, 102, 0, 0.08);
cursor: pointer;
user-select: none;
border-bottom: 1px solid rgba(255, 102, 0, 0.2);
font-size: 0.9rem;
font-weight: 500;
}
.thinking-header:hover {
background: rgba(255, 102, 0, 0.12);
}
.thinking-controls {
display: flex;
align-items: center;
gap: 8px;
}
.thinking-status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #666;
display: inline-block;
}
.thinking-status-dot.connected {
background: #00ff66;
box-shadow: 0 0 8px #00ff66;
}
.thinking-status-dot.disconnected {
background: #ff3333;
}
.thinking-clear-btn,
.thinking-toggle-btn {
background: transparent;
border: 1px solid rgba(255, 102, 0, 0.5);
color: var(--text-main);
padding: 4px 8px;
border-radius: 4px;
cursor: pointer;
font-size: 0.85rem;
}
.thinking-clear-btn:hover,
.thinking-toggle-btn:hover {
background: rgba(255, 102, 0, 0.2);
box-shadow: 0 0 6px rgba(255, 102, 0, 0.3);
}
.thinking-toggle-btn {
transition: transform 0.3s ease;
}
.thinking-panel.collapsed .thinking-toggle-btn {
transform: rotate(-90deg);
}
.thinking-content {
flex: 1;
overflow-y: auto;
padding: 12px;
display: flex;
flex-direction: column;
gap: 8px;
min-height: 0;
}
.thinking-panel.collapsed .thinking-content {
display: none;
}
.thinking-empty {
text-align: center;
padding: 40px 20px;
color: var(--text-fade);
font-size: 0.85rem;
}
.thinking-empty-icon {
font-size: 2rem;
margin-bottom: 10px;
}
.thinking-event {
padding: 8px 12px;
border-radius: 6px;
font-size: 0.85rem;
font-family: 'Courier New', monospace;
animation: thinkingSlideIn 0.3s ease-out;
border-left: 3px solid;
word-wrap: break-word;
}
@keyframes thinkingSlideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.thinking-event-connected {
background: rgba(0, 255, 102, 0.1);
border-color: #00ff66;
color: #00ff66;
}
.thinking-event-thinking {
background: rgba(138, 43, 226, 0.1);
border-color: #8a2be2;
color: #c79cff;
}
.thinking-event-tool_call {
background: rgba(255, 165, 0, 0.1);
border-color: #ffa500;
color: #ffb84d;
}
.thinking-event-tool_result {
background: rgba(0, 191, 255, 0.1);
border-color: #00bfff;
color: #7dd3fc;
}
.thinking-event-done {
background: rgba(168, 85, 247, 0.1);
border-color: #a855f7;
color: #e9d5ff;
font-weight: bold;
}
.thinking-event-error {
background: rgba(255, 51, 51, 0.1);
border-color: #ff3333;
color: #fca5a5;
}
.thinking-event-icon {
display: inline-block;
margin-right: 8px;
}
.thinking-event-details {
font-size: 0.75rem;
color: var(--text-fade);
margin-top: 4px;
padding-left: 20px;
white-space: pre-wrap;
max-height: 100px;
overflow-y: auto;
}
/* ========== MOBILE RESPONSIVE STYLES ========== */
/* Hamburger Menu */
.hamburger-menu {
display: none;
flex-direction: column;
gap: 4px;
cursor: pointer;
padding: 8px;
border: 1px solid var(--accent);
border-radius: 4px;
background: transparent;
z-index: 100;
}
.hamburger-menu span {
width: 20px;
height: 2px;
background: var(--accent);
transition: all 0.3s;
display: block;
}
.hamburger-menu.active span:nth-child(1) {
transform: rotate(45deg) translate(5px, 5px);
}
.hamburger-menu.active span:nth-child(2) {
opacity: 0;
}
.hamburger-menu.active span:nth-child(3) {
transform: rotate(-45deg) translate(5px, -5px);
}
/* Mobile Menu Container */
.mobile-menu {
display: none;
position: fixed;
top: 0;
left: -100%;
width: 280px;
height: 100vh;
background: var(--bg-dark);
border-right: 2px solid var(--accent);
box-shadow: var(--accent-glow);
z-index: 999;
transition: left 0.3s ease;
overflow-y: auto;
padding: 20px;
flex-direction: column;
gap: 16px;
}
.mobile-menu.open {
left: 0;
}
.mobile-menu-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 998;
}
.mobile-menu-overlay.show {
display: block;
}
.mobile-menu-section {
display: flex;
flex-direction: column;
gap: 8px;
padding-bottom: 16px;
border-bottom: 1px solid rgba(255, 102, 0, 0.3);
}
.mobile-menu-section:last-child {
border-bottom: none;
}
.mobile-menu-section h4 {
margin: 0;
color: var(--accent);
font-size: 0.9rem;
text-transform: uppercase;
letter-spacing: 1px;
}
.mobile-menu button,
.mobile-menu select {
width: 100%;
padding: 10px;
font-size: 0.95rem;
text-align: left;
}
/* Mobile Breakpoints */
@media screen and (max-width: 768px) {
body {
padding: 0;
}
#chat {
width: 100%;
max-width: 100%;
height: 100vh;
border-radius: 0;
border-left: none;
border-right: none;
}
/* Show hamburger, hide desktop header controls */
.hamburger-menu {
display: flex;
}
#model-select {
padding: 12px;
justify-content: space-between;
}
/* Hide all controls except hamburger on mobile */
#model-select > *:not(.hamburger-menu) {
display: none;
}
#session-select {
display: none;
}
/* Show mobile menu */
.mobile-menu {
display: flex;
}
/* Messages - more width on mobile */
.msg {
max-width: 90%;
font-size: 0.95rem;
}
/* Status bar */
#status {
padding: 10px 12px;
font-size: 0.85rem;
}
/* Input area - bigger touch targets */
#input {
padding: 12px;
}
#userInput {
font-size: 16px; /* Prevents zoom on iOS */
padding: 12px;
}
#sendBtn {
padding: 12px 16px;
font-size: 1rem;
}
/* Modal - full width on mobile */
.modal-content {
width: 95%;
min-width: unset;
max-width: unset;
max-height: 90vh;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.modal-header {
padding: 12px 16px;
}
.modal-body {
padding: 16px;
}
.modal-footer {
padding: 12px 16px;
flex-wrap: wrap;
}
.modal-footer button {
flex: 1;
min-width: 120px;
}
/* Radio labels - stack better on mobile */
.radio-label {
padding: 10px;
}
.radio-label small {
margin-left: 20px;
font-size: 0.75rem;
}
/* Session list */
.session-item {
padding: 10px;
}
.session-info strong {
font-size: 0.9rem;
}
.session-info small {
font-size: 0.7rem;
}
/* Settings button in header */
#settingsBtn {
padding: 8px 12px;
}
/* Thinking panel adjustments for mobile */
.thinking-panel {
max-height: 250px;
}
.thinking-panel.collapsed {
max-height: 38px;
}
.thinking-header {
padding: 8px 10px;
font-size: 0.85rem;
}
.thinking-event {
font-size: 0.8rem;
padding: 6px 10px;
}
.thinking-event-details {
font-size: 0.7rem;
max-height: 80px;
}
}
/* Extra small devices (phones in portrait) */
@media screen and (max-width: 480px) {
.mobile-menu {
width: 240px;
}
.msg {
max-width: 95%;
font-size: 0.9rem;
padding: 8px 12px;
}
#userInput {
font-size: 16px;
padding: 10px;
}
#sendBtn {
padding: 10px 14px;
font-size: 0.95rem;
}
.modal-header h3 {
font-size: 1.1rem;
}
.settings-section h4 {
font-size: 0.95rem;
}
.radio-label span {
font-size: 0.9rem;
}
}
/* Tablet landscape and desktop */
@media screen and (min-width: 769px) {
/* Ensure mobile menu is hidden on desktop */
.mobile-menu,
.mobile-menu-overlay {
display: none !important;
}
.hamburger-menu {
display: none !important;
}
}