🎯 Nueva Funcionalidad Completa Se ha implementado un sistema de chat conversacional con IA que permite adjuntar archivos (imágenes y PDFs), similar a ChatGPT, con prompt personalizable y envío completo al webhook. 📋 Características Implementadas 1. Adjuntar Archivos en el Chat ✅ Botón 📎 para adjuntar archivos ✅ Soporte para imágenes (JPG, PNG, etc.) y PDFs ✅ Preview de archivos adjuntos antes de enviar ✅ Eliminación individual de archivos adjuntos ✅ Múltiples archivos por mensaje ✅ Validación de tipos de archivo 2. Procesamiento Backend de Archivos ✅ Endpoint modificado para recibir FormData con archivos ✅ PDFs: Extracción automática de texto con pypdf ✅ Imágenes: Conversión a base64 para Vision AI ✅ Análisis combinado de texto + imágenes ✅ Límite de 2000 caracteres por PDF para optimizar 3. Integración con IA ✅ OpenAI Vision: Soporte multimodal (texto + imágenes) ✅ Gemini: Soporte de imágenes y texto ✅ Contexto enriquecido con archivos adjuntos ✅ Prompts adaptados según tipo de archivo 4. Custom Prompt por Checklist ✅ Campo assistant_prompt configurable por pregunta ✅ Campo assistant_instructions para instrucciones adicionales ✅ Control de longitud de respuesta (short/medium/long) ✅ Contexto automático del vehículo en cada mensaje 5. Persistencia del Chat ✅ Nuevo campo chat_history en modelo Answer ✅ Migración SQL: add_chat_history_to_answers.sql ✅ Guardado automático del historial completo ✅ Restauración del chat al reabrir 6. Envío al Webhook (n8n) ✅ Todos los chats incluidos en send_completed_inspection_to_n8n() ✅ Campo chat_history en cada respuesta del webhook ✅ Incluye metadata de archivos adjuntos ✅ Tipo de pregunta identificado en webhook ✅ Datos completos para análisis posterior
68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
// Service Worker para PWA con detección de actualizaciones
|
|
// IMPORTANTE: Actualizar esta versión cada vez que se despliegue una nueva versión
|
|
const CACHE_NAME = 'ayutec-v1.0.93';
|
|
const urlsToCache = [
|
|
'/',
|
|
'/index.html'
|
|
];
|
|
|
|
// Instalación del service worker
|
|
self.addEventListener('install', (event) => {
|
|
console.log('Service Worker: Installing version', CACHE_NAME);
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then((cache) => {
|
|
console.log('Service Worker: Caching files');
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
// NO hacer skipWaiting automáticamente - esperar a que el usuario lo active
|
|
);
|
|
});
|
|
|
|
// Activación del service worker
|
|
self.addEventListener('activate', (event) => {
|
|
console.log('Service Worker: Activating...');
|
|
event.waitUntil(
|
|
caches.keys().then((cacheNames) => {
|
|
return Promise.all(
|
|
cacheNames.map((cacheName) => {
|
|
if (cacheName !== CACHE_NAME) {
|
|
console.log('Service Worker: Deleting old cache:', cacheName);
|
|
return caches.delete(cacheName);
|
|
}
|
|
})
|
|
);
|
|
})
|
|
// NO hacer claim automáticamente - solo cuando el usuario actualice manualmente
|
|
);
|
|
});
|
|
|
|
// Estrategia: Network First, fallback to Cache
|
|
self.addEventListener('fetch', (event) => {
|
|
event.respondWith(
|
|
fetch(event.request)
|
|
.then((response) => {
|
|
// Clone la respuesta
|
|
const responseToCache = response.clone();
|
|
|
|
// Actualizar cache con la nueva respuesta
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
cache.put(event.request, responseToCache);
|
|
});
|
|
|
|
return response;
|
|
})
|
|
.catch(() => {
|
|
// Si falla la red, usar cache
|
|
return caches.match(event.request);
|
|
})
|
|
);
|
|
});
|
|
|
|
// Mensaje para notificar actualización
|
|
self.addEventListener('message', (event) => {
|
|
if (event.data && event.data.type === 'SKIP_WAITING') {
|
|
self.skipWaiting();
|
|
}
|
|
});
|