Files
admin-edu-space/frontend/views/partials/ai_chat_widget.html
T

266 lines
8.8 KiB
HTML

{% 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 %}
<!-- ===================================================== -->
<!-- WIDGET FLOTANTE: ASISTENTE IA Y CHATBOT CONTEXTUAL -->
<!-- SDD-009: UniCABA Edu-Space AI Assistant (Llama.cpp) -->
<!-- ===================================================== -->
<div id="aiChatContainer" class="ai-chat-container" 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 Asistente IA" title="Asistente IA - Tutor Contextual UniCABA">
<span class="ai-launcher-icon"><i class="bi bi-robot"></i></span>
<span class="ai-launcher-badge pulse-dot"></span>
</button>
<!-- Panel de Conversación (Expandible) -->
<div id="aiChatPanel" class="ai-chat-panel card shadow-lg border-0 d-none" role="dialog" aria-modal="true" aria-labelledby="aiChatTitle">
<!-- Cabecera del Chat -->
<div class="card-header ai-chat-header d-flex align-items-center justify-content-between p-3 border-bottom">
<div class="d-flex align-items-center gap-2 overflow-hidden">
<div class="ai-avatar-circle">
<i class="bi bi-cpu-fill text-white"></i>
</div>
<div class="lh-sm text-truncate">
<h6 class="mb-0 fw-bold text-truncate text-white" id="aiChatTitle">
Tutor Edu-Space
<span class="badge bg-success-subtle text-success-emphasis border border-success-subtle ms-1 font-monospace" style="font-size: 0.65rem;">Llama.cpp</span>
</h6>
<small class="text-white-50" style="font-size: 0.72rem;">
<span class="status-indicator-dot me-1"></span>Qwen3 Coder 30B &bull;
<span class="text-uppercase fw-semibold text-warning-emphasis" id="aiRoleBadge">{{ current_role_name }}</span>
</small>
</div>
</div>
<div class="d-flex align-items-center gap-1">
<button type="button" class="btn btn-sm btn-outline-light border-0 py-1 px-2" id="aiChatClearBtn" title="Limpiar conversación">
<i class="bi bi-trash3"></i>
</button>
<button type="button" class="btn btn-sm btn-outline-light border-0 py-1 px-2" id="aiChatCloseBtn" title="Minimizar chat">
<i class="bi bi-x-lg"></i>
</button>
</div>
</div>
<!-- Cuerpo de Mensajes -->
<div class="card-body ai-chat-messages p-3" id="aiChatMessages" tabindex="0">
<!-- Mensaje de Bienvenida Inicial generado dinámicamente por JS según el rol -->
</div>
<!-- Indicador de Escritura -->
<div id="aiChatTyping" class="ai-typing-indicator px-3 py-1 d-none">
<small class="text-muted d-flex align-items-center gap-2">
<span class="typing-dot"></span>
<span class="typing-dot"></span>
<span class="typing-dot"></span>
<span>El tutor está formulando la respuesta...</span>
</small>
</div>
<!-- Área de Entrada / Envío -->
<div class="card-footer ai-chat-footer p-2 bg-body-tertiary border-top">
<form id="aiChatForm" class="d-flex align-items-center gap-2 m-0" onsubmit="handleAiChatSubmit(event)">
<textarea id="aiChatInput" class="form-control form-control-sm ai-chat-textarea"
rows="1"
placeholder="Pregúntale al tutor sobre el sistema..."
aria-label="Mensaje para el Asistente"></textarea>
<button type="submit" class="btn btn-primary btn-sm rounded-circle ai-send-btn" id="aiChatSendBtn" title="Enviar mensaje">
<i class="bi bi-send-fill"></i>
</button>
</form>
<div class="text-center mt-1">
<small class="text-muted font-monospace" style="font-size: 0.65rem;">
Inferencia local segura UniCABA &bull; Presiona Enter para enviar
</small>
</div>
</div>
</div>
</div>
<style>
/* Estilos del Contenedor Flotante */
.ai-chat-container {
position: fixed;
bottom: 24px;
right: 24px;
z-index: 1060;
font-family: inherit;
}
/* Botón Lanzador */
.ai-chat-launcher {
width: 58px;
height: 58px;
border-radius: 50% !important;
background: linear-gradient(135deg, #B43E8E 0%, #0d6efd 100%) !important;
color: #ffffff !important;
display: flex;
align-items: center;
justify-content: center;
border: 2px solid rgba(255, 255, 255, 0.4) !important;
position: relative;
cursor: pointer;
transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}
.ai-chat-launcher:hover {
transform: scale(1.08);
box-shadow: 0 10px 25px rgba(180, 62, 142, 0.45) !important;
}
.ai-launcher-icon {
font-size: 1.65rem;
line-height: 1;
}
.pulse-dot {
position: absolute;
top: 4px;
right: 4px;
width: 12px;
height: 12px;
background-color: #22c55e;
border-radius: 50%;
border: 2px solid #ffffff;
box-shadow: 0 0 8px #22c55e;
animation: aiPulse 2s infinite;
}
@keyframes aiPulse {
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
/* Panel de Chat */
.ai-chat-panel {
width: 380px;
max-width: calc(100vw - 32px);
height: 540px;
max-height: calc(100vh - 100px);
border-radius: 16px !important;
overflow: hidden;
display: flex;
flex-direction: column;
animation: aiSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
box-shadow: 0 20px 45px rgba(0, 0, 0, 0.28) !important;
}
@keyframes aiSlideUp {
from { opacity: 0; transform: translateY(20px) scale(0.96); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
/* Cabecera del Chat */
.ai-chat-header {
background: linear-gradient(135deg, #992875 0%, #0d6efd 100%) !important;
}
.ai-avatar-circle {
width: 36px;
height: 36px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.22);
display: flex;
align-items: center;
justify-content: center;
font-size: 1.15rem;
}
.status-indicator-dot {
display: inline-block;
width: 7px;
height: 7px;
background-color: #22c55e;
border-radius: 50%;
}
/* Área de Mensajes */
.ai-chat-messages {
flex: 1 1 auto;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 12px;
scroll-behavior: smooth;
}
/* Burbujas de Mensaje */
.ai-msg {
max-width: 85%;
padding: 10px 14px;
border-radius: 14px;
font-size: 0.88rem;
line-height: 1.45;
word-break: break-word;
}
.ai-msg-user {
align-self: flex-end;
background-color: #0d6efd;
color: #ffffff;
border-bottom-right-radius: 4px;
}
.ai-msg-assistant {
align-self: flex-start;
border-bottom-left-radius: 4px;
}
[data-bs-theme="dark"] .ai-msg-assistant {
background-color: #1e293b;
color: #f1f5f9;
border: 1px solid #334155;
}
[data-bs-theme="light"] .ai-msg-assistant {
background-color: #f8fafc;
color: #0f172a;
border: 1px solid #e2e8f0;
}
.ai-msg code {
font-size: 0.82rem;
padding: 2px 5px;
border-radius: 4px;
background: rgba(0, 0, 0, 0.1);
}
[data-bs-theme="dark"] .ai-msg code {
background: rgba(255, 255, 255, 0.1);
}
/* Indicador de Escritura */
.ai-typing-indicator .typing-dot {
width: 6px;
height: 6px;
background-color: #94a3b8;
border-radius: 50%;
animation: typingBounce 1.4s infinite ease-in-out;
}
.ai-typing-indicator .typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-typing-indicator .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-indicator .typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
40% { transform: scale(1.1); opacity: 1; }
}
/* Formulario del Chat */
.ai-chat-textarea {
resize: none;
border-radius: 20px;
padding-left: 14px;
padding-right: 14px;
max-height: 80px;
}
.ai-send-btn {
width: 36px;
height: 36px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
@media (max-width: 576px) {
.ai-chat-container {
bottom: 16px;
right: 16px;
}
.ai-chat-panel {
width: calc(100vw - 32px);
height: calc(100vh - 120px);
}
}
</style>
<!-- Script Lógico del Widget -->
<script src="/js/ai-chat-widget.js"></script>