From ecae7e9b4caba329c073f7f0ee17b2f53f94b6b3 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 2 Jul 2025 09:26:32 -0400 Subject: [PATCH] fix(hermes): save intro message to history and prevent regeneration - Only generate intro message when no conversation history exists - Save generated intro to chatHistory so it persists across modal opens - Set up page context when loading existing conversation history - Prevent intro from being regenerated every time modal opens - Intro message now properly saved and reused like other messages --- src/ui.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ui.js b/src/ui.js index f77175b..aaf8684 100644 --- a/src/ui.js +++ b/src/ui.js @@ -1242,11 +1242,30 @@ async function openHermesModalNew() { try { const history = loadConversationHistory(); if (history && history.length > 0) { + // Set up page context for existing conversation + const pageContent = extractWebpageContent(); + const pageTitle = document.title || window.location.hostname; + const conversationContextAppend = ` + +PAGE CONTEXT FOR THIS CONVERSATION: +You are embedded on the webpage: "${pageTitle}" +URL: ${window.location.href} + +FULL PAGE CONTENT: +${pageContent} + +You have complete knowledge of this page content and can reference any details, names, topics, or information mentioned on this page. Answer questions about the page content accurately and helpfully.`; + + setSystemMessageAppend(conversationContextAppend); + // Sync the loaded history with the chat.js module // Clear existing non-system messages and add loaded history const systemMsg = chatHistory.find(msg => msg.role === 'system'); chatHistory.length = 0; // Clear array - if (systemMsg) chatHistory.push(systemMsg); + if (systemMsg) { + const { getSystemMessage } = await import('./config.js'); + chatHistory.push({ role: 'system', content: getSystemMessage() }); + } chatHistory.push(...history); console.log("Chat history synced with loaded data:", chatHistory.length, "messages"); console.log("Current chatHistory contents:", chatHistory); @@ -1471,6 +1490,10 @@ You have complete knowledge of this page content and can reference any details, systemMsg.content = getSystemMessage(); } + // Add the intro message to chat history so it's not regenerated + chatHistory.push({ role: 'assistant', content: response }); + console.log("Added intro message to chat history"); + // Add TTS and delete buttons to intro message const messageActions = document.createElement("div"); messageActions.style.cssText = `