Compare commits

..

No commits in common. "pages" and "main" have entirely different histories.
pages ... main

View File

@ -96,16 +96,8 @@ const knowledgeBase = {
}
};
// === История чата в localStorage (ключ уникальный для этого чата) ===
const STORAGE_KEY = 'zakupkiChatHistory_v1';
let chatHistory = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
// Миграция: если есть старая история без ключа версии — очищаем
const oldHistory = localStorage.getItem('chatHistory');
if (oldHistory) {
localStorage.removeItem('chatHistory');
chatHistory = [];
}
// === История чата в localStorage ===
let chatHistory = JSON.parse(localStorage.getItem('chatHistory') || '[]');
// === Инициализация ===
function init() {
@ -132,7 +124,7 @@ function sendMessage() {
const userMsg = {
role: 'user',
text: question,
time: Date.now()
time: new Date().toISOString()
};
chatHistory.push(userMsg);
@ -141,12 +133,12 @@ function sendMessage() {
const assistantMsg = {
role: 'assistant',
text: response,
time: Date.now()
time: new Date().toISOString()
};
chatHistory.push(assistantMsg);
// Сохраняем и рисуем
localStorage.setItem(STORAGE_KEY, JSON.stringify(chatHistory));
localStorage.setItem('chatHistory', JSON.stringify(chatHistory));
input.value = '';
renderMessages();
scrollToBottom();
@ -191,18 +183,14 @@ function renderMessages() {
}
chatHistory.forEach(msg => {
// Проверка на битые сообщения
if (!msg || !msg.text || !msg.time) return;
const div = document.createElement('div');
div.className = `chat-message ${msg.role}`;
const date = new Date(msg.time);
const time = isNaN(date.getTime()) ? '' : date.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
const time = new Date(msg.time).toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
div.innerHTML = `
<div class="chat-bubble">${escapeHtml(msg.text)}</div>
${time ? `<div class="message-time">${time}</div>` : ''}
<div class="message-time">${time}</div>
`;
container.appendChild(div);
});