fix: aislamiento estricto de conversaciones de chat por usuario e inferencia simultanea (v3.8.26)

This commit is contained in:
2026-10-27 08:11:07 -03:00
parent fb46de5f28
commit a5b014efbe
11 changed files with 134 additions and 27 deletions
+35 -10
View File
@@ -7,7 +7,35 @@
'use strict';
let isProcessing = false;
const STORAGE_KEY = 'edu_space_udeci_chat_history_v2';
// Limpiar clave histórica compartida para evitar contaminación entre perfiles
try {
sessionStorage.removeItem('edu_space_udeci_chat_history_v2');
localStorage.removeItem('edu_space_udeci_chat_history_v2');
} catch (e) {}
function getContainer() {
return document.getElementById('aiChatContainer');
}
function getUserId() {
const container = getContainer();
const rawId = container ? (container.getAttribute('data-user-id') || container.getAttribute('data-user-email')) : null;
if (rawId && rawId.toString().trim()) {
return 'usr_' + rawId.toString().trim().replace(/[^a-zA-Z0-9_-]/g, '_');
}
// Identificador único de sesión por pestaña si no está logueado
let anonId = sessionStorage.getItem('edu_space_anon_chat_session');
if (!anonId) {
anonId = 'anon_' + Math.random().toString(36).substring(2, 10) + '_' + Date.now();
sessionStorage.setItem('edu_space_anon_chat_session', anonId);
}
return anonId;
}
function getStorageKey() {
return 'edu_space_udeci_chat_usr_' + getUserId();
}
const ROLE_CHIPS = {
docente: [
@@ -28,10 +56,6 @@
]
};
function getContainer() {
return document.getElementById('aiChatContainer');
}
function getUserRole() {
const container = getContainer();
const rawRole = (container ? container.getAttribute('data-user-role') : 'alumno') || 'alumno';
@@ -53,7 +77,7 @@
function loadHistory() {
try {
const raw = sessionStorage.getItem(STORAGE_KEY);
const raw = sessionStorage.getItem(getStorageKey());
return raw ? JSON.parse(raw) : [];
} catch (e) {
return [];
@@ -62,7 +86,7 @@
function saveHistory(messages) {
try {
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(messages));
sessionStorage.setItem(getStorageKey(), JSON.stringify(messages));
} catch (e) {}
}
@@ -169,7 +193,8 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: payloadMessages,
user_role: userRole
user_role: userRole,
conversation_id: getUserId()
})
});
@@ -225,10 +250,10 @@
});
}
// Reiniciar conversación
// Reiniciar conversación del usuario actual
if (clearBtn) {
clearBtn.addEventListener('click', () => {
sessionStorage.removeItem(STORAGE_KEY);
sessionStorage.removeItem(getStorageKey());
const messagesContainer = document.getElementById('aiChatMessages');
if (messagesContainer) messagesContainer.innerHTML = '';
const initialOptions = (ROLE_CHIPS[role] || []).map(c => c.label);