feat(whatsapp): QWEN primary AI backend, Hermes fallback, conversation history, vehicle persistence, demo prompts

- Add QWEN (qwen3.6) as primary AI backend with short system prompt
- Hermes remains as fallback with 45s timeout
- Increase QWEN timeout to 35s, max_tokens to 4000
- Add conversation history loading from whatsapp_messages (last 4 msgs)
- Persist detected vehicle in whatsapp_sessions table
- Add 'limpiar chat' / 'nuevo chat' / 'reset' commands to clear history
- Fix CSS conflict: rename whatsapp chat-panel classes to wa-chat-panel
- Fix JS ID conflicts with chat.js widget (waChatPanel, waChatMessages, etc.)
- Improve no-stock response: conversational with alternatives
- Split search_query by | for multi-part lookups
- Add DEMO_PROMPTS.md and DEMO_PROMPTS_V2.md
This commit is contained in:
2026-05-06 20:27:14 +00:00
parent 371d72887e
commit ff45905b49
33 changed files with 3040 additions and 445 deletions

View File

@@ -273,7 +273,7 @@
<script src="/pos/static/js/app-init.js" defer></script>
<script src="/pos/static/js/pos-utils.js" defer></script>
<script src="/pos/static/js/sidebar.js" defer></script>
<script src="/pos/static/js/catalog.js" defer></script>
<script src="/pos/static/js/catalog.js?v=2" defer></script>
<script src="/pos/static/js/offline-banner.js" defer></script>
<script src="/pos/static/js/chat.js" defer></script>
<script src="/pos/static/js/sync-engine.js" defer></script>

View File

@@ -815,7 +815,7 @@
<script src="/pos/static/js/pos-utils.js" defer></script>
<script src="/pos/static/js/sidebar.js" defer></script>
<script src="/pos/static/js/virtual-scroll.js" defer></script>
<script src="/pos/static/js/inventory.js?v=2" defer></script>
<script src="/pos/static/js/inventory.js?v=3" defer></script>
<script src="/pos/static/js/offline-banner.js" defer></script>
<script src="/pos/static/js/sync-engine.js" defer></script>
<script>if('serviceWorker' in navigator){navigator.serviceWorker.register('/pos/sw.js',{scope:'/pos/'});}</script>

View File

@@ -114,7 +114,12 @@
html += '<div style="font-size:var(--text-h5);font-weight:700;color:var(--color-text-accent);">Total: $' + fmt(q.total) + '</div>';
html += '</div>';
html += '<div style="margin-top:var(--space-5);display:flex;gap:var(--space-3);justify-content:flex-end;">';
html += '<div style="margin-top:var(--space-5);display:flex;gap:var(--space-3);justify-content:flex-end;flex-wrap:wrap;">';
if (q.status === 'active') {
html += '<button class="btn btn--ghost" onclick="editQuote(' + q.id + ')" style="color:#4f46e5;">Editar</button>';
html += '<button class="btn btn--ghost" onclick="convertQuote(' + q.id + ')" style="color:#059669;">Convertir a venta</button>';
html += '<button class="btn btn--ghost" onclick="shareQuote(' + q.id + ')">Compartir link</button>';
}
html += '<button class="btn btn--ghost" onclick="deleteQuote(' + q.id + ')" style="color:#F85149;">Eliminar</button>';
html += '<button class="btn btn--ghost" onclick="exportVisibleTableCSV(\'cotizacion_' + q.id + '\')">Exportar CSV</button>';
html += '<button class="btn btn--ghost" onclick="window.print()">Imprimir</button>';
@@ -140,6 +145,68 @@
});
};
window.editQuote = function(id) {
fetch(API + '/quotations/' + id, { headers: headers() })
.then(function(r) { return r.json(); })
.then(function(q) {
if (!q.items) { alert('Error cargando cotización'); return; }
var cartItems = q.items.map(function(it) {
return {
inventory_id: it.inventory_id,
part_number: it.part_number,
name: it.name,
quantity: it.quantity,
unit_price: it.unit_price,
discount_pct: it.discount_pct,
tax_rate: it.tax_rate
};
});
localStorage.setItem('pos_edit_quote_id', id);
localStorage.setItem('pos_edit_quote_customer_id', q.customer_id || '');
localStorage.setItem('pos_edit_quote_notes', q.notes || '');
localStorage.setItem('pos_cart', JSON.stringify(cartItems));
window.location.href = '/pos';
});
};
window.convertQuote = function(id) {
fetch(API + '/quotations/' + id, { headers: headers() })
.then(function(r) { return r.json(); })
.then(function(q) {
if (!q.items) { alert('Error cargando cotización'); return; }
var cartItems = q.items.map(function(it) {
return {
inventory_id: it.inventory_id,
part_number: it.part_number,
name: it.name,
quantity: it.quantity,
unit_price: it.unit_price,
discount_pct: it.discount_pct,
tax_rate: it.tax_rate
};
});
localStorage.setItem('pos_convert_quote_id', id);
localStorage.setItem('pos_cart', JSON.stringify(cartItems));
window.location.href = '/pos';
});
};
window.shareQuote = function(id) {
fetch(API + '/quotations/' + id + '/share', { method: 'POST', headers: headers() })
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.url) {
navigator.clipboard.writeText(d.url).then(function() {
alert('Link copiado al portapapeles:\n' + d.url);
}).catch(function() {
prompt('Copia este link:', d.url);
});
} else {
alert('Error: ' + (d.error || 'desconocido'));
}
});
};
// Close modal on outside click
document.getElementById('quoteModal').addEventListener('click', function(e) {
if (e.target === this) this.classList.remove('open');

View File

@@ -4,6 +4,9 @@
<script>/*pos_theme_early*/(function(){var t=localStorage.getItem("pos_theme")||"industrial";document.documentElement.setAttribute("data-theme",t);})()</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>WhatsApp — Nexus Autoparts POS</title>
<link rel="stylesheet" href="/pos/static/css/chat.css" />
<link rel="stylesheet" href="/pos/static/css/tokens.css" />
@@ -89,10 +92,11 @@
<div class="empty-state__hint">Los mensajes de WhatsApp aparecen aqui en tiempo real</div>
</div>
<div class="chat-panel" id="chatPanel" style="display:none">
<div class="chat-panel__header">
<span class="chat-panel__phone" id="chatHeaderPhone"></span>
<div class="chat-panel__actions">
<div class="wa-chat-panel" id="waChatPanel" style="display:none">
<div class="wa-chat-panel__header">
<button class="btn btn--sm" id="backToListBtn" style="display:none;margin-right:8px;">&larr; Volver</button>
<span class="wa-chat-panel__phone" id="chatHeaderPhone"></span>
<div class="wa-chat-panel__actions">
<button class="btn btn--sm" id="sendQuoteBtn" title="Enviar cotizacion por WhatsApp">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>
@@ -102,11 +106,11 @@
</div>
</div>
<div class="chat-panel__messages" id="chatMessages"></div>
<div class="wa-chat-panel__messages" id="waChatMessages"></div>
<div class="chat-input-bar">
<textarea id="chatInput" placeholder="Escribe un mensaje..." rows="1"></textarea>
<button class="btn btn--primary" id="sendBtn">
<textarea id="waChatInput" placeholder="Escribe un mensaje..." rows="1"></textarea>
<button class="btn btn--primary" id="waSendBtn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/>
</svg>
@@ -127,7 +131,7 @@ function posLogout(){localStorage.removeItem('pos_token');window.location.href='
<!-- Sidebar -->
<script src="/pos/static/js/i18n.js" defer></script>
<script src="/pos/static/js/whatsapp.js" defer></script>
<script src="/pos/static/js/whatsapp2.js" defer></script>
<script src="/pos/static/js/pos-utils.js" defer></script>
<script src="/pos/static/js/sidebar.js" defer></script>