| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>RAG Chatbot — Fleet AI Oversight</title> |
| <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet"> |
| <style> |
| *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } |
| |
| :root { |
| --sidebar-bg: #0e0f11; |
| --sidebar-text: #a1a1aa; |
| --sidebar-accent: #6366f1; |
| --canvas: #f4f4f5; |
| --surface: #ffffff; |
| --border: #e4e4e7; |
| --border-soft: #f0f0ef; |
| --text-primary: #111112; |
| --text-secondary: #71717a; |
| --text-mono: #3d3d3a; |
| --indigo: #6366f1; |
| --indigo-soft: #eef2ff; |
| --indigo-border: #c7d2fe; |
| --emerald: #059669; |
| --emerald-soft: #ecfdf5; |
| --amber: #d97706; |
| --amber-soft: #fffbeb; |
| --rose: #e11d48; |
| --rose-soft: #fff1f2; |
| --gray-100: #f4f4f5; |
| --gray-200: #e4e4e7; |
| --gray-300: #d4d4d8; |
| --gray-400: #a1a1aa; |
| --radius: 8px; |
| --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04); |
| --shadow-md: 0 4px 12px rgba(0,0,0,0.08); |
| } |
| |
| body { font-family: 'Plus Jakarta Sans', sans-serif; background: var(--canvas); color: var(--text-primary); font-size: 13px; line-height: 1.5; } |
| |
| .app-shell { display: flex; min-height: 100vh; } |
| .sidebar { width: 220px; flex-shrink: 0; background: var(--sidebar-bg); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; } |
| .sidebar-logo { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,0.06); display: flex; align-items: center; gap: 9px; } |
| .logo-mark { width: 28px; height: 28px; background: var(--sidebar-accent); border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; } |
| .logo-text { font-size: 13px; font-weight: 600; color: #fff; line-height: 1.2; } |
| .logo-text span { display: block; font-size: 10px; color: var(--sidebar-text); font-weight: 400; } |
| .nav-section { padding: 20px 12px 6px; font-size: 10px; font-weight: 600; color: rgba(161,161,170,0.5); text-transform: uppercase; letter-spacing: 0.1em; } |
| .nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 12px; margin: 1px 4px; border-radius: 6px; font-size: 13px; color: var(--sidebar-text); text-decoration: none; transition: all 0.15s; } |
| .nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; } |
| .nav-item.active { background: rgba(99,102,241,0.18); color: #fff; } |
| .nav-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.5; flex-shrink: 0; } |
| .nav-item.active .nav-dot { opacity: 1; background: var(--sidebar-accent); } |
| |
| .main { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; } |
| |
| .chat-header { padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; } |
| .chat-header-left h2 { font-size: 15px; font-weight: 700; } |
| .chat-header-left p { font-size: 11px; color: var(--text-secondary); margin-top: 1px; } |
| .pipe-badge { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; border: 1px solid; cursor: pointer; transition: opacity 0.15s; } |
| .pipe-badge:hover { opacity: 0.8; } |
| .pipe-ready { background: var(--emerald-soft); color: var(--emerald); border-color: #a7f3d0; } |
| .pipe-not-ready{ background: var(--amber-soft); color: var(--amber); border-color: #fcd34d; } |
| .pipe-checking { background: var(--gray-100); color: var(--text-secondary); border-color: var(--gray-200); } |
| .pipe-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; } |
| .pipe-dot.pulse { animation: pulse 2s infinite; } |
| |
| .banner { margin: 12px 24px 0; padding: 10px 14px; background: var(--amber-soft); border: 1px solid #fcd34d; border-radius: var(--radius); font-size: 12px; color: var(--amber); display: none; } |
| .banner a { color: var(--amber); font-weight: 600; } |
| |
| .chat-area { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; background: var(--canvas); } |
| .chat-area::-webkit-scrollbar { width: 3px; } |
| .chat-area::-webkit-scrollbar-track { background: transparent; } |
| .chat-area::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; } |
| |
| .message { display: flex; gap: 9px; max-width: 720px; } |
| .message.user { flex-direction: row-reverse; margin-left: auto; } |
| .msg-avatar { width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; border: 1px solid var(--border); background: var(--surface); } |
| .msg-content { flex: 1; min-width: 0; } |
| .msg-bubble { padding: 10px 13px; border-radius: var(--radius); font-size: 13px; line-height: 1.6; } |
| .message.bot .msg-bubble { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text-primary); } |
| .message.user .msg-bubble { background: var(--indigo-soft); border: 1px solid var(--indigo-border); color: var(--text-primary); } |
| |
| .conf-bar { display: flex; align-items: center; gap: 7px; margin-top: 6px; font-size: 11px; color: var(--text-secondary); } |
| .conf-track { width: 72px; height: 4px; background: var(--gray-200); border-radius: 2px; overflow: hidden; } |
| .conf-fill { height: 100%; border-radius: 2px; background: var(--indigo); transition: width 0.3s; } |
| |
| .sources { margin-top: 8px; } |
| .src-toggle { font-size: 11px; color: var(--gray-400); cursor: pointer; display: inline-flex; align-items: center; gap: 3px; user-select: none; } |
| .src-toggle:hover { color: var(--text-secondary); } |
| .src-list { margin-top: 6px; display: flex; flex-direction: column; gap: 5px; } |
| .src-chip { padding: 7px 10px; background: var(--gray-100); border: 1px solid var(--border); border-radius: 6px; } |
| .src-id { color: var(--indigo); font-family: 'DM Mono', monospace; font-size: 10px; margin-bottom: 3px; } |
| .src-text { color: var(--text-secondary); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 540px; } |
| .src-score { color: var(--gray-400); font-size: 10px; font-family: 'DM Mono', monospace; margin-top: 2px; } |
| |
| .typing { display: flex; gap: 4px; padding: 10px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: fit-content; box-shadow: var(--shadow); } |
| .td { width: 5px; height: 5px; border-radius: 50%; background: var(--indigo); animation: tbounce 1.2s infinite; } |
| .td:nth-child(2) { animation-delay: 0.2s; } |
| .td:nth-child(3) { animation-delay: 0.4s; } |
| @keyframes tbounce { 0%,80%,100% { transform:scale(0.6); opacity:0.4; } 40% { transform:scale(1); opacity:1; } } |
| |
| .chat-input-area { padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 9px; flex-shrink: 0; } |
| .chat-input { flex: 1; background: var(--gray-100); border: 1px solid var(--border); color: var(--text-primary); padding: 10px 13px; border-radius: var(--radius); font-size: 13px; font-family: 'Plus Jakarta Sans', sans-serif; resize: none; line-height: 1.5; } |
| .chat-input:focus { outline: none; border-color: var(--indigo); background: #fff; } |
| .chat-input::placeholder { color: var(--gray-300); } |
| .send-btn { background: var(--indigo); color: #fff; border: none; padding: 10px 16px; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 600; font-family: 'Plus Jakarta Sans', sans-serif; transition: background 0.15s; align-self: flex-end; } |
| .send-btn:hover:not(:disabled) { background: #4f46e5; } |
| .send-btn:disabled { background: var(--gray-200); color: var(--gray-400); cursor: not-allowed; } |
| |
| .welcome { text-align: center; padding: 28px 0; } |
| .welcome-icon { font-size: 26px; margin-bottom: 10px; } |
| .welcome-title { font-size: 15px; font-weight: 700; margin-bottom: 5px; color: var(--text-primary); } |
| .welcome-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; } |
| .sq-row { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; } |
| .sq { padding: 5px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; color: var(--text-secondary); cursor: pointer; transition: all 0.15s; box-shadow: var(--shadow); } |
| .sq:hover { border-color: var(--indigo-border); color: var(--indigo); background: var(--indigo-soft); } |
| |
| @keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.35; } } |
| </style> |
| </head> |
| <body> |
| <div class="app-shell"> |
| <nav class="sidebar"> |
| <div class="sidebar-logo"> |
| <div class="logo-mark">⚡</div> |
| <div class="logo-text">Fleet Oversight<span>v2.0 · Hackathon Finals</span></div> |
| </div> |
| <div class="nav-section">Workspace</div> |
| <a href="/ui/" class="nav-item"><span class="nav-dot"></span>Dashboard</a> |
| <a href="/ui/fleet" class="nav-item"><span class="nav-dot"></span>Fleet Runner</a> |
| <a href="/ui/chat" class="nav-item active"><span class="nav-dot"></span>RAG Chatbot</a> |
| <div class="nav-section">Evaluation</div> |
| <a href="/ui/results" class="nav-item"><span class="nav-dot"></span>Training Results</a> |
| <div class="nav-section">API</div> |
| <a href="/ui/api" class="nav-item"><span class="nav-dot"></span>API Docs</a> |
| <a href="/ui/health" class="nav-item"><span class="nav-dot"></span>Health Check</a> |
| </nav> |
|
|
| <main class="main"> |
| <div class="chat-header"> |
| <div class="chat-header-left"> |
| <h2>Enterprise RAG Chatbot</h2> |
| <p>NexaCRM knowledge base · powered by the fleet pipeline</p> |
| </div> |
| <div class="pipe-badge pipe-checking" id="pipe-badge" onclick="checkPipeline()"> |
| <div class="pipe-dot" id="pipe-dot"></div> |
| <span id="pipe-text">Checking pipeline...</span> |
| </div> |
| </div> |
|
|
| <div class="banner" id="banner"> |
| ⚠ The embedding pipeline hasn't been built yet. |
| <a href="/ui/fleet">Run a fleet episode first</a>, then return here. |
| </div> |
|
|
| <div class="chat-area" id="chat-area"> |
| <div class="welcome"> |
| <div class="welcome-icon">💬</div> |
| <div class="welcome-title">NexaCRM Knowledge Base</div> |
| <div class="welcome-sub">Ask anything about NexaCRM — pricing, integrations, security, support</div> |
| <div class="sq-row"> |
| <div class="sq" onclick="ask('What is the price of the Pro plan?')">Pro plan pricing</div> |
| <div class="sq" onclick="ask('Does NexaCRM integrate with Slack?')">Slack integration</div> |
| <div class="sq" onclick="ask('Is customer data encrypted at rest?')">Data security</div> |
| <div class="sq" onclick="ask('How do I cancel my subscription?')">Cancel subscription</div> |
| <div class="sq" onclick="ask('What is the free trial period?')">Free trial</div> |
| <div class="sq" onclick="ask('Is there a mobile app available?')">Mobile app</div> |
| </div> |
| </div> |
| </div> |
|
|
| <div class="chat-input-area"> |
| <textarea class="chat-input" id="chat-input" rows="1" placeholder="Ask about NexaCRM..." onkeydown="handleKey(event)"></textarea> |
| <button class="send-btn" id="send-btn" onclick="send()">Send →</button> |
| </div> |
| </main> |
| </div> |
|
|
| <script> |
| let loading = false; |
| |
| async function checkPipeline() { |
| const badge = document.getElementById('pipe-badge'); |
| const dot = document.getElementById('pipe-dot'); |
| const txt = document.getElementById('pipe-text'); |
| const banner = document.getElementById('banner'); |
| badge.className = 'pipe-badge pipe-checking'; |
| dot.classList.remove('pulse'); |
| txt.textContent = 'Checking...'; |
| try { |
| const resp = await fetch('/rag/query', { |
| method: 'POST', headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ question: 'ping' }) |
| }); |
| const data = await resp.json(); |
| if (data.error) { |
| badge.className = 'pipe-badge pipe-not-ready'; |
| txt.textContent = '⚠ Pipeline not built'; |
| banner.style.display = 'block'; |
| } else { |
| badge.className = 'pipe-badge pipe-ready'; |
| dot.classList.add('pulse'); |
| txt.textContent = '✓ Pipeline ready'; |
| banner.style.display = 'none'; |
| } |
| } catch (e) { |
| badge.className = 'pipe-badge pipe-not-ready'; |
| txt.textContent = '⚠ Cannot reach server'; |
| } |
| } |
| |
| function ask(q) { document.getElementById('chat-input').value = q; send(); } |
| function handleKey(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); } } |
| |
| async function send() { |
| const input = document.getElementById('chat-input'); |
| const q = input.value.trim(); |
| if (!q || loading) return; |
| loading = true; |
| input.value = ''; |
| document.getElementById('send-btn').disabled = true; |
| addMsg('user', q, null, null); |
| const tid = addTyping(); |
| try { |
| const resp = await fetch('/rag/query', { |
| method: 'POST', headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ question: q }) |
| }); |
| const data = await resp.json(); |
| removeTyping(tid); |
| if (data.error) { |
| addMsg('bot', data.error, null, null); |
| document.getElementById('pipe-badge').className = 'pipe-badge pipe-not-ready'; |
| document.getElementById('pipe-text').textContent = '⚠ Pipeline not built'; |
| document.getElementById('banner').style.display = 'block'; |
| } else { |
| addMsg('bot', data.answer, data.source_chunks, data.confidence); |
| } |
| } catch (e) { |
| removeTyping(tid); |
| addMsg('bot', 'Connection error — is the server running?', null, null); |
| } |
| loading = false; |
| document.getElementById('send-btn').disabled = false; |
| } |
| |
| function addMsg(role, text, sources, confidence) { |
| const area = document.getElementById('chat-area'); |
| const div = document.createElement('div'); |
| div.className = 'message ' + role; |
| |
| let srcHtml = ''; |
| if (sources && sources.length > 0) { |
| const chips = sources.map(s => ` |
| <div class="src-chip"> |
| <div class="src-id">${s.chunk_id}</div> |
| <div class="src-text">${esc(s.text)}</div> |
| <div class="src-score">similarity: ${s.score}</div> |
| </div>`).join(''); |
| srcHtml = `<div class="sources"> |
| <div class="src-toggle" onclick="this.nextElementSibling.style.display=this.nextElementSibling.style.display==='none'?'flex':'none'"> |
| ▸ ${sources.length} source chunk${sources.length > 1 ? 's' : ''} |
| </div> |
| <div class="src-list" style="display:none">${chips}</div> |
| </div>`; |
| } |
| |
| let confHtml = ''; |
| if (confidence !== null && confidence !== undefined) { |
| const pct = Math.round(confidence * 100); |
| confHtml = `<div class="conf-bar"><span>Confidence</span><div class="conf-track"><div class="conf-fill" style="width:${pct}%"></div></div><span>${pct}%</span></div>`; |
| } |
| |
| div.innerHTML = ` |
| <div class="msg-avatar">${role === 'bot' ? '🤖' : '👤'}</div> |
| <div class="msg-content"> |
| <div class="msg-bubble">${esc(text)}</div> |
| ${confHtml}${srcHtml} |
| </div>`; |
| area.appendChild(div); |
| area.scrollTop = area.scrollHeight; |
| } |
| |
| function addTyping() { |
| const area = document.getElementById('chat-area'); |
| const id = 'typing-' + Date.now(); |
| const div = document.createElement('div'); |
| div.id = id; div.className = 'message bot'; |
| div.innerHTML = `<div class="msg-avatar">🤖</div><div class="typing"><div class="td"></div><div class="td"></div><div class="td"></div></div>`; |
| area.appendChild(div); |
| area.scrollTop = area.scrollHeight; |
| return id; |
| } |
| |
| function removeTyping(id) { document.getElementById(id)?.remove(); } |
| function esc(s) { return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); } |
| |
| checkPipeline(); |
| </script> |
| </body> |
| </html> |
|
|