Chat: wait for the AI assistant on WebGPU devices; knowledge base only without it or after Not now
Browse filesFiles changed (3)
- chat/chat.css+3-1
- chat/chat.js+21-7
- index.html+1-1
36 unmodified lines3738394041424325 unmodified lines69707172737436 unmodified lines.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 600px; margin: 0 auto; }@media (max-width: 520px) { .chips { grid-template-columns: 1fr; } }.chip { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; color: var(--text); font-size: 15px; }.chip:hover { border-color: var(--accent-border); background: var(--accent-soft); }#thread { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }.msg { display: flex; gap: 10px; align-items: flex-start; }25 unmodified lines.input-pill { flex: 1; display: flex; background: var(--input-bg); border: 1px solid var(--border); border-radius: 22px; padding: 4px 6px 4px 16px; }.input-pill:focus-within { box-shadow: 0 0 0 2px var(--accent-border); }#input { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); font: inherit; max-height: 180px; padding: 9px 0; }.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }.send-btn:disabled { opacity: .4; cursor: default; }.attach { width: 44px; height: 44px; flex: none; }36 unmodified lines373839404142434425 unmodified lines7071727374757636 unmodified lines.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 600px; margin: 0 auto; }@media (max-width: 520px) { .chips { grid-template-columns: 1fr; } }.chip { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; color: var(--text); font-size: 15px; }.chip:hover:not(:disabled) { border-color: var(--accent-border); background: var(--accent-soft); }.chip:disabled { opacity: .45; cursor: default; }#thread { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }.msg { display: flex; gap: 10px; align-items: flex-start; }25 unmodified lines.input-pill { flex: 1; display: flex; background: var(--input-bg); border: 1px solid var(--border); border-radius: 22px; padding: 4px 6px 4px 16px; }.input-pill:focus-within { box-shadow: 0 0 0 2px var(--accent-border); }#input { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); font: inherit; max-height: 180px; padding: 9px 0; }#input:disabled { cursor: not-allowed; }.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }.send-btn:disabled { opacity: .4; cursor: default; }.attach { width: 44px; height: 44px; flex: none; }
57 unmodified lines5859606162636410 unmodified lines757677787980815 unmodified lines878889909192939482 unmodified lines177178179180181182183154 unmodified lines3383393403413423433443 unmodified lines34834935035135235335452 unmodified lines40740840941041141241341441541657 unmodified linesstate.progress = r.progress || 0;const mb = /([\d.]+)MB fetched/.exec(r.text || '');status(state.cachedStart ? `Starting the AI assistant… ${Math.round(state.progress * 100)}%`: `Downloading the AI assistant (one time, about 1 GB): ${Math.round(state.progress * 100)}%${mb ? ` · ${Math.round(+mb[1])} MB` : ''} · you can keep chatting meanwhile`, state.progress);aiChip();};let engine, label;10 unmodified linesfunction enableAi() {try { localStorage.setItem(AI_CONSENT, 'yes'); } catch { /* ignore */ }state.consent = true;getEngine();}5 unmodified lineselse if (state.loading) { chip.textContent = `⬇ AI ${Math.round((state.progress || 0) * 100)}%`; chip.title = 'The AI assistant is getting ready'; chip.dataset.state = 'loading'; }else if (state.engine === false) { chip.textContent = '📚 Knowledge base'; chip.title = state.modelLabel; chip.dataset.state = 'off'; }else { chip.textContent = '⚡ Enable AI'; chip.title = 'Download the AI assistant (about 1 GB, one time)'; chip.dataset.state = 'off'; }}// Instant answer straight from the knowledge base, formatted for reading.function quickAnswer(passages) {if (!passages.length) return 'The Devseis knowledge base has nothing on that question. I cover device security, ISO 27001, GDPR and the EU AI Act.';82 unmodified lines// ---------- asking ----------async function ask(question) {if (state.busy || !question.trim()) return;const chat = state.current || newChat();if (chat.title === 'New conversation') chat.title = question.slice(0, 60);const history = chat.messages.filter(m => !m.pending).slice(-4).map(m => ({ role: m.role, content: m.content }));154 unmodified lines}// ---------- wiring ----------function updateSend() { $('sendBtn').disabled = state.busy || !$('input').value.trim(); }function closeSidebar() { $('sidebar').classList.remove('open'); $('overlay').classList.add('hidden'); }$('composer').addEventListener('submit', e => { e.preventDefault(); const q = $('input').value.trim(); $('input').value = ''; $('input').style.height = ''; updateSend(); ask(q); });3 unmodified lines$('auditBtn').addEventListener('click', openAuditModal);$('aiChip').addEventListener('click', () => { if (!state.engine && !state.loading && state.engine !== false) enableAi(); else if (state.engine) status(`AI assistant ready: ${state.modelLabel}`, 1) || setTimeout(() => status(''), 2500); });$('aiCardYes').addEventListener('click', () => { state.showAiCard = false; enableAi(); });$('aiCardNo').addEventListener('click', () => { state.showAiCard = false; try { localStorage.setItem(AI_CONSENT, 'later'); } catch { /* ignore */ } render(); });$('auditClose').addEventListener('click', () => $('auditModal').classList.add('hidden'));$('auditModal').addEventListener('click', e => { if (e.target === $('auditModal')) $('auditModal').classList.add('hidden'); });$('attachBtn').addEventListener('click', () => $('fileInput').click());52 unmodified lineslet consent = null; try { consent = localStorage.getItem(AI_CONSENT); } catch { /* ignore */ }modelCached().then(cached => {if (cached || consent === 'yes') { state.cachedStart = cached; getEngine(); }else if (consent !== 'later') {state.showAiCard = true;if (navigator.connection && navigator.connection.type === 'cellular') $('aiCardText').textContent += ' You seem to be on mobile data: Wi-Fi is recommended.';render();}});} else { state.engine = false; state.modelLabel = 'Not available: this browser has no WebGPU'; $('modelName').textContent = 'Knowledge base only'; aiChip(); }57 unmodified lines5859606162636410 unmodified lines757677787980815 unmodified lines8788899091929394959697989982 unmodified lines182183184185186187188154 unmodified lines3433443453463473483493503513523533543553563573 unmodified lines36136236336436536636752 unmodified lines42042142242342442542642742842943057 unmodified linesstate.progress = r.progress || 0;const mb = /([\d.]+)MB fetched/.exec(r.text || '');status(state.cachedStart ? `Starting the AI assistant… ${Math.round(state.progress * 100)}%`: `Downloading the AI assistant (one time, about 1 GB): ${Math.round(state.progress * 100)}%${mb ? ` · ${Math.round(+mb[1])} MB` : ''} · the chat opens when it is ready`, state.progress);aiChip();};let engine, label;10 unmodified linesfunction enableAi() {try { localStorage.setItem(AI_CONSENT, 'yes'); } catch { /* ignore */ }state.consent = true; state.kbOnly = false;getEngine();}5 unmodified lineselse if (state.loading) { chip.textContent = `⬇ AI ${Math.round((state.progress || 0) * 100)}%`; chip.title = 'The AI assistant is getting ready'; chip.dataset.state = 'loading'; }else if (state.engine === false) { chip.textContent = '📚 Knowledge base'; chip.title = state.modelLabel; chip.dataset.state = 'off'; }else { chip.textContent = '⚡ Enable AI'; chip.title = 'Download the AI assistant (about 1 GB, one time)'; chip.dataset.state = 'off'; }updateSend();}// With WebGPU the chat waits for the AI; the knowledge base answers alone only without WebGPU, if the AI fails to load,// or when the visitor chose "Not now".function aiPending() { return !state.kbOnly && state.engine !== false && !state.engine; }// Instant answer straight from the knowledge base, formatted for reading.function quickAnswer(passages) {if (!passages.length) return 'The Devseis knowledge base has nothing on that question. I cover device security, ISO 27001, GDPR and the EU AI Act.';82 unmodified lines// ---------- asking ----------async function ask(question) {if (state.busy || aiPending() || !question.trim()) return;const chat = state.current || newChat();if (chat.title === 'New conversation') chat.title = question.slice(0, 60);const history = chat.messages.filter(m => !m.pending).slice(-4).map(m => ({ role: m.role, content: m.content }));154 unmodified lines}// ---------- wiring ----------function updateSend() {const wait = aiPending();$('input').disabled = wait;$('input').placeholder = !wait ? 'Ask Arx about security, or add your audit report…': state.loading ? `Arx can chat once the AI assistant is ready (${Math.round((state.progress || 0) * 100)}%)…`: state.showAiCard ? 'Choose "Download now" or "Not now" above to start chatting…' : 'Tap ⚡ Enable AI at the top to start chatting…';document.querySelectorAll('.chip[data-prompt]').forEach(c => { c.disabled = wait; });$('sendBtn').disabled = wait || state.busy || !$('input').value.trim();}function closeSidebar() { $('sidebar').classList.remove('open'); $('overlay').classList.add('hidden'); }$('composer').addEventListener('submit', e => { e.preventDefault(); const q = $('input').value.trim(); $('input').value = ''; $('input').style.height = ''; updateSend(); ask(q); });3 unmodified lines$('auditBtn').addEventListener('click', openAuditModal);$('aiChip').addEventListener('click', () => { if (!state.engine && !state.loading && state.engine !== false) enableAi(); else if (state.engine) status(`AI assistant ready: ${state.modelLabel}`, 1) || setTimeout(() => status(''), 2500); });$('aiCardYes').addEventListener('click', () => { state.showAiCard = false; enableAi(); });$('aiCardNo').addEventListener('click', () => { state.showAiCard = false; state.kbOnly = true; aiChip(); try { localStorage.setItem(AI_CONSENT, 'later'); } catch { /* ignore */ } render(); });$('auditClose').addEventListener('click', () => $('auditModal').classList.add('hidden'));$('auditModal').addEventListener('click', e => { if (e.target === $('auditModal')) $('auditModal').classList.add('hidden'); });$('attachBtn').addEventListener('click', () => $('fileInput').click());52 unmodified lineslet consent = null; try { consent = localStorage.getItem(AI_CONSENT); } catch { /* ignore */ }modelCached().then(cached => {if (cached || consent === 'yes') { state.cachedStart = cached; getEngine(); }else if (consent === 'later') { state.kbOnly = true; aiChip(); }else {state.showAiCard = true;if (navigator.connection && navigator.connection.type === 'cellular') $('aiCardText').textContent += ' You seem to be on mobile data: Wi-Fi is recommended.';render(); aiChip();}});} else { state.engine = false; state.modelLabel = 'Not available: this browser has no WebGPU'; $('modelName').textContent = 'Knowledge base only'; aiChip(); }
34 unmodified lines3536373839404134 unmodified lines<h1>Hi, I'm Arx, your Devseis security assistant.</h1><p class="hero-sub">Ask me how to secure your computer or phone, or about ISO 27001, GDPR and the EU AI Act. I can also <b>audit this device</b> for free. I run on your device: nothing you type is uploaded.</p><div class="ai-card hidden" id="aiCard"><div><b>⚡ Turn on the AI assistant</b><br><span id="aiCardText">One-time download of about 1 GB; it then runs on this device, even offline. Until then I answer instantly from the Devseis knowledge base.</span></div><div class="btn-row"><button type="button" class="primary-btn" id="aiCardYes">Download now</button><button type="button" class="small-btn" id="aiCardNo">Not now</button></div></div><div class="chips">34 unmodified lines3536373839404134 unmodified lines<h1>Hi, I'm Arx, your Devseis security assistant.</h1><p class="hero-sub">Ask me how to secure your computer or phone, or about ISO 27001, GDPR and the EU AI Act. I can also <b>audit this device</b> for free. I run on your device: nothing you type is uploaded.</p><div class="ai-card hidden" id="aiCard"><div><b>⚡ Turn on the AI assistant</b><br><span id="aiCardText">One-time download of about 1 GB; it then runs on this device, even offline. The chat opens when it is ready. Choose Not now to get answers from the Devseis knowledge base instead.</span></div><div class="btn-row"><button type="button" class="primary-btn" id="aiCardYes">Download now</button><button type="button" class="small-btn" id="aiCardNo">Not now</button></div></div><div class="chips">
chat/chat.css+3-1
chat/chat.js+21-7
index.html+1-1