... keep your authGate as is ...
👤 MY ACCOUNT
🎵 Continue with TikTok 🎬 UPLOAD REELS
🧠 AGENCY NEW
Manage shops you help • Earn 400 UGX
🔍
◆ SANNLAS
UGANDA • MARKETPLACE
🚚 Transport - Bus/Taxi/Boda 🏭 Manufacturers 📦 Delivery Tracking 🔴 Live Streaming 📞 Phone Calls System 🧠 AGENCY DASHBOARD
◆ SANNLAS UGANDA
◆ SANNLAS UGANDA • MARKETPLACE
Liquid Glass • iOS 26 • Sannlas Uganda 2026
let aiHistoryIndex = []; let voiceEnabledIndex = true; let recognitionIndex = null; function openSannlasAIIndex(){ document.getElementById('sannlasAIModalIndex').style.display='flex'; document.getElementById('aiInputIndex').focus(); } function closeSannlasAIIndex(){ document.getElementById('sannlasAIModalIndex').style.display='none'; window.speechSynthesis.cancel(); } // ===== 🔊 VOICE OUTPUT ===== function speakTextIndex(text, lang='en') { if (!voiceEnabledIndex || !('speechSynthesis' in window)) return; window.speechSynthesis.cancel(); const utterance = new SpeechSynthesisUtterance(text); let tl = text.toLowerCase(); if (lang === 'lg' || tl.includes('oli otya') || tl.includes('engatto') || tl.includes('nzudde') || tl.includes('wasuze')) { utterance.lang = 'en-UG'; utterance.rate = 0.9; } else if (lang === 'sw' || tl.includes('habari') || tl.includes('viatu') || tl.includes('nimepata')) { utterance.lang = 'sw-KE'; utterance.rate = 0.9; } else { utterance.lang = 'en-US'; utterance.rate = 1.0; } utterance.pitch = 1; utterance.volume = 1; let cleanText = text.replace(/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{2600}-\u{26FF}]/gu, '').replace(/
/g,' ').substring(0, 200); utterance.text = cleanText; window.speechSynthesis.speak(utterance); } function toggleVoiceIndex() { voiceEnabledIndex = !voiceEnabledIndex; const btn = document.getElementById('speakerBtnIndex'); btn.innerHTML = voiceEnabledIndex ? '🔊' : '🔇'; btn.style.background = voiceEnabledIndex ? '#FFCC02' : '#ccc'; if (!voiceEnabledIndex) window.speechSynthesis.cancel(); } // ===== 🎤 VOICE INPUT ===== function startVoiceIndex() { const micBtn = document.getElementById('micBtnIndex'); if (!('webkitSpeechRecognition' in window || 'SpeechRecognition' in window)) { alert('Voice needs Chrome browser Boss! Use Chrome!'); return; } const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; recognitionIndex = new SpeechRecognition(); recognitionIndex.lang = 'en-US'; recognitionIndex.interimResults = false; micBtn.style.background = '#ff0000'; micBtn.innerHTML = '🔴'; micBtn.style.color = '#fff'; recognitionIndex.onstart = () => { console.log('Listening...'); }; recognitionIndex.onresult = (event) => { const text = event.results[0][0].transcript; document.getElementById('aiInputIndex').value = text; micBtn.style.background = '#000'; micBtn.innerHTML = '🎤'; micBtn.style.color = '#FFCC02'; sendToAIIndex(); }; recognitionIndex.onerror = () => { micBtn.style.background = '#000'; micBtn.innerHTML = '🎤'; micBtn.style.color = '#FFCC02'; }; recognitionIndex.onend = () => { micBtn.style.background = '#000'; micBtn.innerHTML = '🎤'; micBtn.style.color = '#FFCC02'; }; recognitionIndex.start(); } async function sendToAIIndex(){ let input=document.getElementById('aiInputIndex'); let msg=input.value.trim(); if(!msg) return; let box=document.getElementById('aiMessagesIndex'); box.innerHTML+=`
${msg}
`; input.value=''; box.scrollTop=box.scrollHeight; aiHistoryIndex.push({role:'user',content:msg}); box.innerHTML+=`
🧠 Sannlas AI typing...
`; box.scrollTop=box.scrollHeight; try{ let r=await fetch('/api/ai/chat',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({message:msg,history:aiHistoryIndex})}); let data=await r.json(); document.getElementById('aiTypingIndex')?.remove(); box.innerHTML+=`
${data.reply.replace(/\n/g,'
')}
`; aiHistoryIndex.push({role:'assistant',content:data.reply}); // 🔊 SPEAK! speakTextIndex(data.reply, data.detected_lang || 'en'); if(data.products && data.products.length){ let pBox=document.getElementById('aiProductsIndex'); pBox.style.display='flex'; pBox.innerHTML=data.products.map(p=>`
${p.name||p.title}
UGX ${(p.price||0).toLocaleString()}
`).join(''); } box.scrollTop=box.scrollHeight; }catch(e){document.getElementById('aiTypingIndex')?.remove(); box.innerHTML+=`
Network issue Boss! Try again 🚀
`;} }