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
This commit is contained in:
Russell Ballestrini 2025-07-02 09:26:32 -04:00
parent 4486cec23b
commit ecae7e9b4c

View file

@ -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 = `