diff --git a/backend/app/main.py b/backend/app/main.py index 7c88796..437d9ff 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -278,7 +278,7 @@ def extract_pdf_text_smart(pdf_content: bytes, max_chars: int = None) -> dict: } -BACKEND_VERSION = "1.2.5" +BACKEND_VERSION = "1.2.6" app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION) # S3/MinIO configuration @@ -3417,6 +3417,7 @@ async def chat_with_ai_assistant( user_message: str = Form(""), chat_history: str = Form("[]"), context_photos: str = Form("[]"), + context_answers: str = Form("[]"), vehicle_info: str = Form("{}"), assistant_prompt: str = Form(""), assistant_instructions: str = Form(""), @@ -3438,6 +3439,7 @@ async def chat_with_ai_assistant( import json chat_history_list = json.loads(chat_history) context_photos_list = json.loads(context_photos) + context_answers_list = json.loads(context_answers) vehicle_info_dict = json.loads(vehicle_info) print(f"📋 Question ID: {question_id}") @@ -3445,6 +3447,7 @@ async def chat_with_ai_assistant( print(f"💬 User message: {user_message}") print(f"📎 Attached files: {len(files)}") print(f"📸 Context photos: {len(context_photos_list)} fotos") + print(f"📝 Context answers: {len(context_answers_list)} respuestas previas") print(f"💭 Chat history: {len(chat_history_list)} mensajes previos") # Procesar archivos adjuntos @@ -3523,6 +3526,21 @@ INFORMACIÓN DEL VEHÍCULO: status = analysis_text.get('status', 'unknown') photos_context += f"\n{idx}. Pregunta ID {photo.get('questionId')}: Status={status}\n Observaciones: {obs[:200]}...\n" + # NUEVO: Construir contexto de respuestas de texto de preguntas anteriores + answers_context = "" + if context_answers_list: + answers_context = f"\n\nRESPUESTAS DE PREGUNTAS ANTERIORES ({len(context_answers_list)} respuestas):\n" + for idx, ans in enumerate(context_answers_list, 1): + question_text = ans.get('questionText', f"Pregunta {ans.get('questionId')}") + answer_value = ans.get('answer', '') + observations = ans.get('observations', '') + + answers_context += f"\n{idx}. {question_text}\n" + if answer_value: + answers_context += f" Respuesta: {answer_value}\n" + if observations: + answers_context += f" Observaciones: {observations}\n" + # Definir la longitud de respuesta max_tokens_map = { 'short': 200, @@ -3559,6 +3577,8 @@ INFORMACIÓN DEL VEHÍCULO: CONTEXTO DEL VEHÍCULO Y PREGUNTA: {vehicle_context} +{answers_context} + {photos_context} {attached_context} diff --git a/frontend/package.json b/frontend/package.json index 993eae9..fb8034c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "checklist-frontend", "private": true, - "version": "1.2.7", + "version": "1.2.8", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/public/service-worker.js b/frontend/public/service-worker.js index 815bf26..5787191 100644 --- a/frontend/public/service-worker.js +++ b/frontend/public/service-worker.js @@ -1,6 +1,6 @@ // 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.2.7'; +const CACHE_NAME = 'ayutec-v1.2.8'; const urlsToCache = [ '/', '/index.html' diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index a8f01d9..ea27ed8 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -5632,6 +5632,7 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM // Recopilar fotos de preguntas anteriores según configuración const contextPhotos = [] + const contextAnswers = [] // NUEVO: respuestas de texto de preguntas anteriores const contextQuestionIds = config.context_questions ? config.context_questions.split(',').map(id => parseInt(id.trim())) : Object.keys(allAnswers).map(id => parseInt(id)) @@ -5641,6 +5642,8 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM previousQuestionIds.forEach(qId => { const answer = allAnswers[qId] + + // Agregar fotos si existen if (answer?.photos && answer.photos.length > 0) { answer.photos.forEach(photoUrl => { contextPhotos.push({ @@ -5650,9 +5653,22 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM }) }) } + + // NUEVO: Agregar respuestas de texto (incluyendo observations) + if (answer?.value || answer?.observations) { + // Buscar la pregunta para obtener su texto + const questionData = inspection.checklist.questions.find(q => q.id === qId) + contextAnswers.push({ + questionId: qId, + questionText: questionData?.text || `Pregunta ${qId}`, + answer: answer.value || '', + observations: answer.observations || '' + }) + } }) formData.append('context_photos', JSON.stringify(contextPhotos)) + formData.append('context_answers', JSON.stringify(contextAnswers)) // NUEVO formData.append('vehicle_info', JSON.stringify({ brand: inspection.vehicle_brand, model: inspection.vehicle_model, diff --git a/frontend/src/Sidebar.jsx b/frontend/src/Sidebar.jsx index be90127..0aed864 100644 --- a/frontend/src/Sidebar.jsx +++ b/frontend/src/Sidebar.jsx @@ -153,7 +153,7 @@ export default function Sidebar({ user, activeTab, setActiveTab, sidebarOpen, se className="w-10 h-10 object-contain bg-white rounded p-1" />
- Ayutec v1.2.7 + Ayutec v1.2.8