From a8ef25ef6c5806aece67ac3836fbc359f86fb929 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 2 Jul 2025 07:29:04 -0400 Subject: [PATCH] fix(hermes): persist conversation history across modal sessions - Save chat history to localStorage after each AI response - Load complete conversation history with TTS buttons on modal open - Add TTS and delete buttons to historical AI messages - Ensure conversation continuity when reopening modal - Add debugging logs for history save operations --- src/ui.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/ui.js b/src/ui.js index 088bc5f..2b91a84 100644 --- a/src/ui.js +++ b/src/ui.js @@ -986,6 +986,11 @@ async function openHermesModalNew() { aiMsg.innerHTML = marked.parse(response); } + // Save conversation history after successful response + const { chatHistory } = await import('./chat.js'); + saveConversationHistory(chatHistory); + console.log("Conversation history saved:", chatHistory.length, "messages"); + // Add TTS and delete buttons to AI message const messageActions = document.createElement("div"); messageActions.style.cssText = ` @@ -1106,6 +1111,55 @@ async function openHermesModalNew() { box-shadow: 0 1px 2px rgba(0,0,0,0.1); `; aiMsg.innerHTML = marked.parse(msg.content); + + // Add TTS and delete buttons to historical AI messages + const messageActions = document.createElement("div"); + messageActions.style.cssText = ` + margin-top: 8px; + display: flex; + gap: 8px; + opacity: 0.7; + `; + + const ttsBtn = document.createElement("button"); + ttsBtn.textContent = "🔊"; + ttsBtn.title = "Read aloud"; + ttsBtn.style.cssText = ` + background: none; + border: 1px solid #dee2e6; + border-radius: 4px; + padding: 4px 8px; + cursor: pointer; + font-size: 12px; + transition: all 0.2s; + `; + ttsBtn.onclick = () => { + const modalVoiceSelect = document.getElementById('hermes-voice-select'); + const selectedVoice = modalVoiceSelect?.value || 'alloy'; + speakText(msg.content, selectedVoice, 1.0); + }; + + const deleteBtn = document.createElement("button"); + deleteBtn.textContent = "🗑️"; + deleteBtn.title = "Delete message"; + deleteBtn.style.cssText = ` + background: none; + border: 1px solid #dee2e6; + border-radius: 4px; + padding: 4px 8px; + cursor: pointer; + font-size: 12px; + transition: all 0.2s; + `; + deleteBtn.onclick = () => { + aiMsg.remove(); + // TODO: Remove from chat history + }; + + messageActions.appendChild(ttsBtn); + messageActions.appendChild(deleteBtn); + aiMsg.appendChild(messageActions); + chatBox.appendChild(aiMsg); } });