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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "3.8.25",
"version": "3.8.26",
"description": "",
"main": "index.js",
"scripts": {
+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);
+3 -3
View File
@@ -86,9 +86,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
});
// Versiones institucionales del sistema
const APP_VERSION = '3.8.25';
const FRONTEND_VERSION = '3.8.25';
const BACKEND_VERSION = '3.8.25';
const APP_VERSION = '3.8.26';
const FRONTEND_VERSION = '3.8.26';
const BACKEND_VERSION = '3.8.26';
env.addGlobal('app_version', APP_VERSION);
env.addGlobal('frontend_version', FRONTEND_VERSION);
+8 -2
View File
@@ -1,10 +1,16 @@
{% set current_role_name = (current_user.role if current_user and current_user.role else (user.role if user and user.role else 'alumno')) | lower %}
{% set active_auth_user = auth_user if (auth_user and auth_user.is_authenticated) else (current_user if (current_user and current_user.is_authenticated) else user) %}
{% set current_user_id = active_auth_user.id if active_auth_user and active_auth_user.id else '' %}
{% set current_user_email = active_auth_user.email if active_auth_user and active_auth_user.email else '' %}
{% set current_role_name = (active_auth_user.role if active_auth_user and active_auth_user.role else 'alumno') | lower %}
<!-- ===================================================== -->
<!-- WIDGET FLOTANTE: UdeCi - TUTOR VIRTUAL UNICABA -->
<!-- SDD-010: Arquitectura RAG y Asistencia Contextual -->
<!-- ===================================================== -->
<div id="aiChatContainer" class="ai-chat-container" data-user-role="{{ current_role_name }}">
<div id="aiChatContainer" class="ai-chat-container"
data-user-id="{{ current_user_id }}"
data-user-email="{{ current_user_email }}"
data-user-role="{{ current_role_name }}">
<!-- Botón Lanzador Flotante -->
<button id="aiChatLauncher" class="ai-chat-launcher btn shadow-lg" type="button" aria-label="Abrir UdeCi" title="UdeCi - Tutor Virtual UniCABA">
<span class="ai-launcher-icon"><i class="bi bi-chat-heart-fill"></i></span>