v2.5.1 — Chat-Verlauf bleibt beim Reload erhalten
- loadHistory() leert Chat nicht mehr (chat.innerHTML = '' entfernt) - Nur fehlende Nachrichten werden angehängt, bestehende bleiben - Cookie mit path=/ für konsistente Session über alle Routen - cowboy shot statt upper body (besserer Danbooru-Tag für NoobAI-XL) - very aesthetic, absurdres als Quality-Tags
This commit is contained in:
+10
-15
@@ -258,28 +258,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Load history on reconnect (fixes the "conversation is somewhere else" bug)
|
||||
// Load history on reconnect — preserves existing messages
|
||||
async function loadHistory() {
|
||||
try {
|
||||
const resp = await fetch(`/api/history/${encodeURIComponent(charFilename)}`);
|
||||
const data = await resp.json();
|
||||
if (data.history && data.history.length > 0) {
|
||||
// Only reload if we have more messages than currently shown
|
||||
const currentMsgs = chat.querySelectorAll('.msg').length;
|
||||
if (data.history.length > currentMsgs || currentMsgs === 0) {
|
||||
chat.innerHTML = '';
|
||||
if ("{{ character.greeting }}") {
|
||||
const g = document.createElement('div');
|
||||
g.className = 'msg msg-greeting';
|
||||
g.textContent = "{{ character.greeting }}";
|
||||
chat.appendChild(g);
|
||||
}
|
||||
data.history.forEach(h => {
|
||||
// Count current messages (exclude greeting)
|
||||
const currentMsgs = chat.querySelectorAll('.msg-user, .msg-bot').length;
|
||||
// Only append messages we don't already have
|
||||
if (data.history.length > currentMsgs) {
|
||||
// Keep existing DOM, only append missing messages
|
||||
for (let i = currentMsgs; i < data.history.length; i++) {
|
||||
const h = data.history[i];
|
||||
const div = document.createElement('div');
|
||||
div.className = `msg ${h.role === 'user' ? 'msg-user' : 'msg-bot'}`;
|
||||
div.textContent = h.content;
|
||||
chat.appendChild(div);
|
||||
});
|
||||
}
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
}
|
||||
}
|
||||
@@ -288,8 +284,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Load history on page load (fixes reconnect issue)
|
||||
// Only if we don't already have history from server-side rendering
|
||||
// Load history on page load ONLY if server didn't render any
|
||||
{% if not history %}
|
||||
loadHistory();
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user