fix: restore all messages from chat history on page load

Co-authored-by: aider (openai//models/Qwen/Qwen2.5-Coder-32B-Instruct-GGUF/qwen2.5-coder-32b-instruct-q4_k_m.gguf) <aider@aider.chat>
This commit is contained in:
mike
2025-12-28 03:00:31 +01:00
parent db0811e8a7
commit 4d5467753b

View File

@@ -29,6 +29,14 @@ let currentStreamController = null
let isStreaming = false let isStreaming = false
let chatHistory = JSON.parse(localStorage.getItem('chatHistory')) || [] // Stores conversation history let chatHistory = JSON.parse(localStorage.getItem('chatHistory')) || [] // Stores conversation history
// Ensure chatHistory is an array of objects with the correct structure
chatHistory = chatHistory.map(message => ({
role: message.role || 'user',
content: message.content || '',
markdown: message.markdown || false,
messageId: message.messageId || `msg-${ Date.now() }`
}))
// Get current API URL based on selected backend // Get current API URL based on selected backend
function getApiUrl() { function getApiUrl() {
const backend = BACKENDS[currentBackend] const backend = BACKENDS[currentBackend]
@@ -605,27 +613,10 @@ window.onload = () => {
// Load chat history from localStorage // Load chat history from localStorage
if (chatHistory.length === 0) { if (chatHistory.length === 0) {
// Add welcome message (this will be the first entry in chatHistory) // Re-add all messages from chatHistory
const welcomeMessage = `# Welcome to LM Studio Chat! ? chatHistory.forEach(message => {
addMessage(message.role, message.content, message.markdown, message.messageId)
I now support **full conversation history**, **real-time streaming responses** and **dark, readable text formatting**. })
## Features:
1. **Full Chat History** - Complete conversation context is now sent to the AI
2. **Smart History Management** - Automatically keeps the last ${ MAX_CHAT_HISTORY } messages
3. **Streaming Mode** (enabled by default) - Watch responses appear word-by-word
4. **Markdown Rendering** - Proper formatting for code, lists, tables, and more
5. **Readable Dark Text** - No more eye strain from light gray text
## Try it out:
- Ask follow-up questions that reference earlier messages
- Have a multi-turn conversation with full context
- Ask "what did I just ask?" to test history retention
- Watch the streaming response in real-time!
> *Tip: You can toggle streaming and markdown using the checkboxes below.*`
addMessage('assistant', welcomeMessage, true)
} else { } else {
// Re-add all messages from chatHistory // Re-add all messages from chatHistory
chatHistory.forEach(message => { chatHistory.forEach(message => {