Fix: Unified Context Memory between Web and Telegram

This commit is contained in:
Marcos
2026-03-22 12:40:06 -03:00
parent 6cf2c30e59
commit 75d2a16fec
3 changed files with 16 additions and 4 deletions

View File

@@ -853,6 +853,7 @@
<script>
let webPassword = localStorage.getItem('vps_web_password') || '';
let chatHistory = []; // Memória da conversa na Web
// Helper para chamadas de API com autenticação
async function apiFetch(url, options = {}) {
@@ -1011,7 +1012,7 @@
const res = await apiFetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
body: JSON.stringify({ text, history: chatHistory })
});
const data = await res.json();
processAIReply(data.reply);
@@ -1059,6 +1060,14 @@
div.textContent = text;
box.appendChild(div);
box.scrollTop = box.scrollHeight;
// Atualiza o histórico local (limita a 10 mensagens)
if (sender === 'user') {
chatHistory.push({ user: text, bot: "" });
} else if (chatHistory.length > 0) {
chatHistory[chatHistory.length - 1].bot = text;
}
if (chatHistory.length > 10) chatHistory.shift();
}
async function loadConfig() {