Spaces:
Runtime error
Runtime error
Placebo Deploy commited on
Commit ·
5f07aac
1
Parent(s): f80a101
update
Browse files3 unmodified lines4567891013 unmodified lines242526272829307 unmodified lines3839404142432 unmodified lines46474849505152535455565758596061626364659 unmodified lines7576777879808182838485868788899091929315 unmodified lines10911011111211311411511611711811928 unmodified lines1481491501511521531541551561571581591601615 unmodified lines16716816917017117217317410 unmodified lines1851861871881891901918 unmodified lines20020120220320420520662 unmodified lines2692702712722732742752762772782792802812821 unmodified line2842852862872882892904 unmodified lines29529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133214 unmodified lines34734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341433 unmodified lines44844945045145245345445545645745845946046146246346446546646746813 unmodified lines4824834844854864874888 unmodified lines4974984995005015025035045055065075081 unmodified line51051151251351451551651 unmodified lines56856957057157257357417 unmodified lines59259359459559659759859960060131 unmodified lines6336346356366376386392 unmodified lines6426436446456466476489 unmodified lines6586596606616626636642 unmodified lines6676686696706716726736746754 unmodified lines68068168268368468568653 unmodified lines74074174274374474574674774874975075175275375475575675716 unmodified lines77477577677777877978013 unmodified lines79479579679779879980080180280313 unmodified lines81781881982082182282341 unmodified lines86586686786886987087136 unmodified lines90890991091191291391447 unmodified lines9629639649659669679682 unmodified lines9719729739749759769779789799809819829835 unmodified lines98999099199299399499599699799899910001001100210032 unmodified lines10061007100810091010101111 unmodified lines102310241025102610271028102923 unmodified lines1053105410551056105710581059106010611062106310641065106618 unmodified lines10851086108710881089109010911092109310941095109610971098109911001101110260 unmodified lines116311641165116611671168116911701171117211731174117511763 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="description" content="Placebo AI is a high-performance, cloud-native medical artificial intelligence platform providing instant, medically grounded answers."><title>Placebo AI | Medical Intelligence</title><link rel="stylesheet" href="/static/style.css"><!-- Favicons -->13 unmodified lines-ms-user-select: none;-webkit-touch-callout: none;}#loader-container {position: fixed;top: 0;7 unmodified linesalign-items: center;transition: opacity 1s ease;}#main-content {opacity: 0;pointer-events: none;2 unmodified lines/* Skeleton Loader Styles */.skeleton {background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);background-size: 200% 100%;animation: shimmer 1.5s infinite;border-radius: 8px;margin-bottom: 12px;}.skeleton-text { height: 18px; width: 100%; }.skeleton-title { height: 28px; width: 60%; margin-bottom: 20px; }.skeleton-short { height: 18px; width: 40%; }@keyframes shimmer {0% { background-position: 200% 0; }100% { background-position: -200% 0; }}/* Side Drawer Styles */9 unmodified linesz-index: 2000;transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);padding: 30px;box-shadow: -10px 0 30px rgba(0,0,0,0.5);display: flex;flex-direction: column;}#side-drawer.open { right: 0; }.drawer-header {display: flex;justify-content: space-between;align-items: center;margin-bottom: 30px;border-bottom: 1px solid rgba(255,255,255,0.1);padding-bottom: 15px;}15 unmodified linestransition: opacity 0.2s;}#close-drawer:hover { opacity: 1; }.drawer-item {padding: 15px;background: rgba(255,255,255,0.05);border-radius: 12px;margin-bottom: 12px;cursor: pointer;28 unmodified linesoverflow-y: auto;padding-right: 10px;}/* Custom Scrollbar for drawer */#drawer-items::-webkit-scrollbar {width: 6px;}#drawer-items::-webkit-scrollbar-track {background: rgba(255,255,255,0.02);}#drawer-items::-webkit-scrollbar-thumb {background: rgba(16, 185, 129, 0.3);border-radius: 3px;5 unmodified lines<!-- Spider Cursor Loader --><div id="loader-container"><div style="position: absolute; text-align: center; pointer-events: none; z-index: 10;"><img src="/static/logo.png" width="80" height="80" style="filter: brightness(0) invert(1); margin-bottom: 20px; opacity: 0.8;"><div style="color: #10b981; font-family: 'Montserrat', sans-serif; letter-spacing: 4px; font-weight: 300; font-size: 14px;">INITIALIZING MEDICAL INTELLIGENCE...</div></div></div>10 unmodified lines<div class="content-layer"><nav><div class="logo-area" style="display: flex; align-items: center; gap: 12px;"><img src="/static/logo.png" width="32" height="32" alt="Logo" style="filter: brightness(0) invert(1);"><a href="#" class="logo">Placebo AI</a></div><div class="menu-items">8 unmodified lines<button class="btn-login" id="login-btn" onclick="showAuthModal()">Log In</button></div><div class="nav-buttons" id="nav-user-buttons" style="display: none; align-items: center; gap: 16px;"><span id="user-display-email" style="font-size: 13px; font-weight: 500; opacity: 0.85; color: var(--primary);">doctor@placebo.ai</span><button class="btn-login" id="logout-btn" style="width: auto; padding: 0 16px;">Log Out</button></div></nav>62 unmodified lines<div class="search-bottom"><div class="action-buttons"><button class="action-btn" id="history-btn"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10" /><path d="M12 6v6l4 2" /></svg>History</button><button class="action-btn" id="clear-btn"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 6h18" /><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" /><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" />1 unmodified lineClear</button><button class="action-btn" id="prompts-btn"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /></svg>4 unmodified lines</div></div><div class="app-disclaimer" style="text-align: center; font-size: 11px; color: rgba(255, 255, 255, 0.5); margin-top: 16px; font-family: 'Montserrat', sans-serif; max-width: 800px; margin-left: auto; margin-right: auto; line-height: 1.4;">Disclaimer: All books used in this application belong to their respective authors and publishers. The author, publisher, and copyright owner reserve all rights. No ownership of book content is claimed by this application.</div><!-- Response Panel --><div id="response-panel"><div class="response-content" id="response-text"></div><div class="source-container" id="source-list"></div><!-- Feedback Loop --><div class="response-feedback" id="response-feedback" style="display: none;"><span class="feedback-label">Was this helpful?</span><button class="feedback-btn" id="thumbs-up-btn" aria-label="Thumbs up: Helpful answer"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3" /></svg></button><button class="feedback-btn" id="thumbs-down-btn" aria-label="Thumbs down: Unhelpful answer"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm12-3h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-3" /></svg></button></div><!-- Disclaimer --><div class="response-disclaimer"><svg class="icon disclaimer-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10" /><line x1="12" y1="8" x2="12" y2="12" /><line x1="12" y1="16" x2="12.01" y2="16" /></svg><span>Placebo AI is a clinical retrieval system. Synthesized knowledge should be clinically verified.</span></div></div></main>14 unmodified lines</div><!-- Authentication Modal Overlay --><div id="auth-modal" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); backdrop-filter: blur(20px); z-index: 3000; display: none; align-items: center; justify-content: center; padding: 20px;"><div class="modal-container" style="max-width: 400px; border: 1px solid rgba(16, 185, 129, 0.2); box-shadow: 0 0 30px rgba(16, 185, 129, 0.1);"><div class="modal-header"><div class="modal-title" id="auth-modal-title" style="font-family: 'Surgena', serif; font-size: 24px; color: var(--white);">Authentication</div><button class="close-modal" id="close-auth-modal" aria-label="Close authentication modal" style="font-size: 28px;">×</button></div><div class="modal-body" style="background: transparent; display: flex; flex-direction: column; gap: 16px; padding: 24px;"><!-- Google OAuth Sign In Button --><button id="google-auth-btn" style="width: 100%; height: 48px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--white); font-family: 'Montserrat', sans-serif; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.3s; box-shadow: 0 4px 12px rgba(0,0,0,0.1);" onmouseover="this.style.background='rgba(255,255,255,0.12)'; this.style.borderColor='rgba(16, 185, 129, 0.5)'" onmouseout="this.style.background='rgba(255,255,255,0.06)'; this.style.borderColor='rgba(255,255,255,0.15)'"><svg width="20" height="20" viewBox="0 0 24 24" style="flex-shrink: 0;"><path fill="#EA4335" d="M12 5.04c1.66 0 3.2.57 4.38 1.69l3.27-3.27C17.67 1.48 14.97 1 12 1 7.35 1 3.4 3.65 1.56 7.5l3.86 3C6.34 7.55 8.94 5.04 12 5.04z"/><path fill="#4285F4" d="M23.49 12.27c0-.81-.07-1.59-.2-2.34H12v4.43h6.44c-.28 1.47-1.11 2.71-2.36 3.55l3.65 2.84c2.13-1.97 3.36-4.87 3.36-8.48z"/><path fill="#FBBC05" d="M5.42 14.5c-.25-.74-.39-1.53-.39-2.35s.14-1.61.39-2.35L1.56 6.8C.56 8.79 0 11.01 0 12.35s.56 3.56 1.56 5.55l3.86-3z"/><path fill="#34A853" d="M12 23c3.24 0 5.97-1.07 7.96-2.91l-3.65-2.84c-1.01.68-2.31 1.09-3.96 1.09-3.06 0-5.66-2.51-6.58-5.46l-3.86 3C3.4 20.35 7.35 23 12 23z"/></svg>Continue with Google</button><div style="display: flex; align-items: center; justify-content: center; width: 100%; margin: 4px 0;"><div style="flex: 1; height: 1px; background: rgba(255,255,255,0.08);"></div><span style="font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.5; color: var(--white); padding: 0 12px;">or email verification</span><div style="flex: 1; height: 1px; background: rgba(255,255,255,0.08);"></div></div><!-- OTP Step 1: Send Verification Code --><div id="otp-step-1" style="display: flex; flex-direction: column; gap: 16px; width: 100%;"><div style="display: flex; flex-direction: column; gap: 6px; width: 100%;"><label style="font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; color: var(--white); text-align: left;">Email Address</label><input type="email" id="auth-email" placeholder="doctor@placebo.ai" style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; outline: none; transition: border-color 0.3s;" onfocus="this.style.borderColor='#10b981'" onblur="this.style.borderColor='rgba(255,255,255,0.1)'"></div><button class="btn-signup" id="auth-send-otp-btn" style="width: 100%; height: 46px; font-size: 14px; margin-top: 4px;">Send Verification Code</button></div><!-- OTP Step 2: Verify 8-digit Code (Initially Hidden) --><div id="otp-step-2" style="display: none; flex-direction: column; gap: 16px; width: 100%;"><div style="display: flex; flex-direction: column; gap: 6px; width: 100%;"><label style="font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; color: var(--white); text-align: left;">8-Digit OTP Code</label><input type="text" id="auth-otp-code" placeholder="••••••••" maxlength="8" style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-size: 20px; font-weight: 700; letter-spacing: 8px; text-align: center; outline: none; transition: border-color 0.3s;" onfocus="this.style.borderColor='#10b981'" onblur="this.style.borderColor='rgba(255,255,255,0.1)'"></div><button class="btn-signup" id="auth-verify-otp-btn" style="width: 100%; height: 46px; font-size: 14px; margin-top: 4px;">Verify & Log In</button><div style="text-align: center; font-size: 12px; opacity: 0.7;"><a href="#" id="auth-back-to-step1" style="color: var(--primary); text-decoration: none; font-weight: 600;">Go back to enter email</a></div></div><!-- Unified Authentication Message Output --><div id="auth-message" style="text-align: center; font-size: 13px; font-weight: 500; margin-top: 4px; min-height: 18px; color: var(--primary); width: 100%;"></div></div></div></div><!-- Profession Selection Modal Overlay --><div id="profession-modal" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); backdrop-filter: blur(20px); z-index: 4000; display: none; align-items: center; justify-content: center; padding: 20px;"><div class="modal-container" style="max-width: 400px; border: 1px solid rgba(16, 185, 129, 0.2); box-shadow: 0 0 30px rgba(16, 185, 129, 0.1);"><div class="modal-header"><div class="modal-title" style="font-family: 'Surgena', serif; font-size: 24px; color: var(--white);">Welcome!</div></div><div class="modal-body" style="background: transparent; display: flex; flex-direction: column; gap: 16px; padding: 24px; text-align: center;"><p style="color: var(--white); opacity: 0.8; font-family: 'Montserrat', sans-serif; font-size: 14px; margin-bottom: 8px;">What best describes you?</p><button class="profession-btn" data-mode="mbbs" style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; cursor: pointer; transition: all 0.2s;" onmouseover="this.style.background='rgba(16, 185, 129, 0.2)'" onmouseout="this.style.background='rgba(255,255,255,0.05)'">MBBS Student / Doctor</button><button class="profession-btn" data-mode="pharmacy" style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; cursor: pointer; transition: all 0.2s;" onmouseover="this.style.background='rgba(16, 185, 129, 0.2)'" onmouseout="this.style.background='rgba(255,255,255,0.05)'">Pharmacy Student / Pharmacist</button><button class="profession-btn" data-mode="unified" style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; cursor: pointer; transition: all 0.2s;" onmouseover="this.style.background='rgba(16, 185, 129, 0.2)'" onmouseout="this.style.background='rgba(255,255,255,0.05)'">Unified (Both Domains)</button></div></div></div>33 unmodified lineslocalStorage.removeItem(key);}}supabaseClient = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {auth: {persistSession: false // Forces logout on every page refresh}});console.log("Supabase Client initialized with ephemeral sessions. Testing connectivity...");// Connection ping test with 2-second timeoutconst pingPromise = supabaseClient.auth.getSession();const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("Supabase connection timeout")), 2000));await Promise.race([pingPromise, timeoutPromise]);console.log("Supabase connectivity verified successfully.");supabaseClient.auth.onAuthStateChange((event, session) => {console.log("Auth State Changed Event:", event);updateAuthState();13 unmodified linesconst authButtons = document.getElementById('nav-auth-buttons');const userButtons = document.getElementById('nav-user-buttons');const displayEmail = document.getElementById('user-display-email');if (supabaseClient) {try {const { data: { session } } = await supabaseClient.auth.getSession();8 unmodified linesconsole.error("Error fetching Supabase session:", err);}}if (activeUser) {authButtons.style.display = 'none';userButtons.style.display = 'flex';displayEmail.innerText = activeUser.email;let userDefaultMode = activeUser.user_metadata?.defaultMode;if (!userDefaultMode) {document.getElementById('profession-modal').style.display = 'flex';1 unmodified lineactiveMode = userDefaultMode;updateModeButtons(activeMode);}// Dynamically update user limitsconst creditText = document.querySelector('.credit-info span');if (creditText) {51 unmodified linesconst clearBtn = document.getElementById('clear-btn');let activeMode = 'unified';function updateModeButtons(mode) {const buttons = document.querySelectorAll('.model-btn');buttons.forEach(b => {17 unmodified linesactiveMode = mode;updateModeButtons(mode);document.getElementById('profession-modal').style.display = 'none';// Reset button text in case they log out and it re-showsbtn.innerText = mode === "mbbs" ? "MBBS Student / Doctor" :(mode === "pharmacy" ? "Pharmacy Student / Pharmacist" : "Unified (Both Domains)");}}};31 unmodified linesconst drawerItems = document.getElementById('drawer-items');let PREDEFINED_PROMPTS = [];// Fetch external configuration for medical terminology / promptsfetch('/static/prompts.json').then(res => res.json())2 unmodified linesasync function saveToHistory(query, answer = '', sources = []) {if (!activeUser || !supabaseClient) return;try {await supabaseClient.from('chat_history').insert({user_id: activeUser.id,9 unmodified linesfunction displayStoredResult(item) {const sanitizedQuery = DOMPurify.sanitize(item.query);const queryHTML = `<div style="font-size: 16px; font-weight: 500; color: white; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1);"><span style="opacity: 0.5; font-size: 12px; display: block; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px;">You Asked:</span>${sanitizedQuery}</div>`;sourceList.innerHTML = '';item.sources.forEach(src => {const tag = document.createElement('span');2 unmodified linestag.style.cursor = 'default';sourceList.appendChild(tag);});responseText.innerHTML = queryHTML + DOMPurify.sanitize(marked.parse(item.answer));responsePanel.style.display = 'flex';chatInput.value = item.query;sideDrawer.classList.remove('open');4 unmodified linesdrawerItems.innerHTML = '';if (type === 'history') {drawerTitle.innerText = 'History';if (!activeUser || !supabaseClient) {drawerItems.innerHTML = '<div style="opacity: 0.5; text-align: center; margin-top: 20px;">Please log in to view history.</div>';sideDrawer.classList.add('open');53 unmodified linesconst signupBtn = document.getElementById('signup-btn');const closeAuthModal = document.getElementById('close-auth-modal');const authModalTitle = document.getElementById('auth-modal-title');const googleAuthBtn = document.getElementById('google-auth-btn');const otpStep1 = document.getElementById('otp-step-1');const authEmail = document.getElementById('auth-email');const authSendOtpBtn = document.getElementById('auth-send-otp-btn');const otpStep2 = document.getElementById('otp-step-2');const authOtpCode = document.getElementById('auth-otp-code');const authVerifyOtpBtn = document.getElementById('auth-verify-otp-btn');const authBackToStep1 = document.getElementById('auth-back-to-step1');const authMessage = document.getElementById('auth-message');const logoutBtn = document.getElementById('logout-btn');16 unmodified lines// loginBtn and signupBtn onclick handled inlinecloseAuthModal.onclick = () => authModal.style.display = 'none';// Close auth modal when clicking outside content boxauthModal.onclick = (e) => {if (e.target === authModal) {13 unmodified lines// --- DISPOSABLE EMAIL CHECK ---function isDisposableEmail(email) {const disposableDomains = ['mailinator.com', 'tempmail.com', 'temp-mail.org', '10minutemail.com','yopmail.com', 'guerrillamail.com', 'dispostable.com', 'trashmail.com','getairmail.com', 'sharklasers.com', 'guerrillamailblock.com','guerrillamail.net', 'guerrillamail.org', 'guerrillamail.biz','tempmailo.com', 'generator.email', 'maildrop.cc', 'tempmail.dev','tempmail.net', 'disposable.com', 'fakeinbox.com', 'disposablemail.com'];13 unmodified linesauthMessage.style.color = '#10b981';authMessage.innerText = 'Redirecting to Google...';try {const { error } = await supabaseClient.auth.signInWithOAuth({provider: 'google',41 unmodified lines}});if (error) throw error;authMessage.innerText = 'Verification code sent to your email!';setTimeout(() => {authMessage.innerText = '';36 unmodified linestype: 'email'});if (error) throw error;authMessage.innerText = 'Authentication successful!';setTimeout(() => {authModal.style.display = 'none';47 unmodified linesif (activeUser && supabaseClient) {let currentCredits = activeUser.user_metadata?.credits_remaining !== undefined ? activeUser.user_metadata.credits_remaining : 500;if (currentCredits > 500) currentCredits = 500; // Instantly scale legacy users down to new 500 limitif (currentCredits < 10) {responsePanel.style.display = 'flex';responseText.innerHTML = '<span style="color: #ef4444; padding: 20px; display: block; text-align: center;">Insufficient credits. You need at least 10 credits to perform a clinical search. Please upgrade your account.</span>';2 unmodified linesdocument.querySelector('.input-wrapper').classList.remove('disabled');return;}let newCredits = Math.max(0, currentCredits - 10);// Optimistic UI updateconst creditText = document.querySelector('.credit-info span');if (creditText) creditText.innerText = `${newCredits}/500 credits`;// Background sync with Supabase User MetadatasupabaseClient.auth.updateUser({data: { credits_remaining: newCredits }5 unmodified lines}responsePanel.style.display = 'flex';let modeDisplay = "Unified Library";if (activeMode === "mbbs") modeDisplay = "Dx(MBBS) Knowledge Base";if (activeMode === "pharmacy") modeDisplay = "Rx(Pharmacy) Knowledge Base";const sanitizedMessage = DOMPurify.sanitize(message);const queryHTML = `<div style="font-size: 16px; font-weight: 500; color: white; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1);"><span style="opacity: 0.5; font-size: 12px; display: block; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px;">You Asked:</span>${sanitizedMessage}</div>`;const badgeHTML = `<div style="font-size: 11px; color: var(--primary); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 12px; border-left: 2px solid var(--primary); padding-left: 8px;">Response from ${modeDisplay}</div>`;responseText.innerHTML = queryHTML + badgeHTML + `<div class="skeleton skeleton-title"></div><div class="skeleton skeleton-text"></div>2 unmodified lines`;sourceList.innerHTML = '';try {const headers = { 'Content-Type': 'application/json' };if (activeToken) {11 unmodified linesresponseText.innerHTML = '<span style="color: #ef4444;">Session expired or unauthorized. Please log out and log back in.</span>';return;}throw new Error(`HTTP Error: ${response.status}`);}const reader = response.body.getReader();23 unmodified linestag.style.cursor = 'default';sourceList.appendChild(tag);});// Manually update the view since sources arrive last in the stream nowconst finalHtml = DOMPurify.sanitize(marked.parse(fullAnswer));responseText.innerHTML = queryHTML + badgeHTML + finalHtml;window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });} else if (json.type === 'start_answer') {responseText.innerHTML = queryHTML + badgeHTML;fullAnswer = ""; // Reset buffer18 unmodified lines// Show feedback widget when streaming completes successfullyif (feedbackContainer) feedbackContainer.style.display = 'flex';} catch (error) {responseText.innerHTML = '<span style="color: #ef4444;">Connection error.</span>';} finally {// Re-enable inputschatInput.disabled = false;sendBtn.disabled = false;document.querySelector('.input-wrapper').classList.remove('disabled');chatInput.focus();}}const resetModal = () => {pageModal.style.display = 'none';modalImg.dataset.scale = 1;modalImg.style.transform = 'scale(1)';};60 unmodified lines}});}sendBtn.addEventListener('click', handleSend);chatInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleSend(); });</script><!-- Anti-Copy, Anti-Paste, and Anti-Screenshot Protections --><script>// Disable Right-Click Context Menu3 unmodified lines456789101113 unmodified lines252627282930317 unmodified lines394041424344452 unmodified lines484950515253545556575859606162636465666768697071727374757677787980818283849 unmodified lines94959697989910010110210310410510610710810911011111211311415 unmodified lines13013113213313413513613713813914014114228 unmodified lines1711721731741751761771781791801811821831841851865 unmodified lines19219319419519619719819920020120210 unmodified lines2132142152162172182192208 unmodified lines22923023123223323423523662 unmodified lines2993003013023033043053063073083093103113123133141 unmodified line3163173183193203213223234 unmodified lines32832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137214 unmodified lines38738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950033 unmodified lines53453553653753853954054154254354454554654754854955055155255355413 unmodified lines5685695705715725735748 unmodified lines5835845855865875885895905915925935941 unmodified line59659759859960060160251 unmodified lines65465565665765865966017 unmodified lines67867968068168268368468568668731 unmodified lines7197207217227237247252 unmodified lines7287297307317327337349 unmodified lines7447457467477487497502 unmodified lines7537547557567577587597607614 unmodified lines76676776876977077177253 unmodified lines82682782882983083183283383483583683783883984084184284316 unmodified lines86086186286386486586613 unmodified lines88088188288388488588688788888913 unmodified lines90390490590690790890941 unmodified lines95195295395495595695736 unmodified lines994995996997998999100047 unmodified lines10481049105010511052105310542 unmodified lines10571058105910601061106210631064106510661067106810695 unmodified lines1075107610771078107910801081108210831084108510861087108810892 unmodified lines109210931094109510961097109811 unmodified lines1110111111121113111411151116111711181119112011211122112323 unmodified lines1147114811491150115111521153115411551156115711581159116018 unmodified lines1179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122560 unmodified lines128612871288128912901291129212931294129512961297129812993 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="description"content="Placebo AI is a high-performance, cloud-native medical artificial intelligence platform providing instant, medically grounded answers."><title>Placebo AI | Medical Intelligence</title><link rel="stylesheet" href="/static/style.css"><!-- Favicons -->13 unmodified lines-ms-user-select: none;-webkit-touch-callout: none;}#loader-container {position: fixed;top: 0;7 unmodified linesalign-items: center;transition: opacity 1s ease;}#main-content {opacity: 0;pointer-events: none;2 unmodified lines/* Skeleton Loader Styles */.skeleton {background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.03) 75%);background-size: 200% 100%;animation: shimmer 1.5s infinite;border-radius: 8px;margin-bottom: 12px;}.skeleton-text {height: 18px;width: 100%;}.skeleton-title {height: 28px;width: 60%;margin-bottom: 20px;}.skeleton-short {height: 18px;width: 40%;}@keyframes shimmer {0% {background-position: 200% 0;}100% {background-position: -200% 0;}}/* Side Drawer Styles */9 unmodified linesz-index: 2000;transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);padding: 30px;box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);display: flex;flex-direction: column;}#side-drawer.open {right: 0;}.drawer-header {display: flex;justify-content: space-between;align-items: center;margin-bottom: 30px;border-bottom: 1px solid rgba(255, 255, 255, 0.1);padding-bottom: 15px;}15 unmodified linestransition: opacity 0.2s;}#close-drawer:hover {opacity: 1;}.drawer-item {padding: 15px;background: rgba(255, 255, 255, 0.05);border-radius: 12px;margin-bottom: 12px;cursor: pointer;28 unmodified linesoverflow-y: auto;padding-right: 10px;}/* Custom Scrollbar for drawer */#drawer-items::-webkit-scrollbar {width: 6px;}#drawer-items::-webkit-scrollbar-track {background: rgba(255, 255, 255, 0.02);}#drawer-items::-webkit-scrollbar-thumb {background: rgba(16, 185, 129, 0.3);border-radius: 3px;5 unmodified lines<!-- Spider Cursor Loader --><div id="loader-container"><div style="position: absolute; text-align: center; pointer-events: none; z-index: 10;"><img src="/static/logo.png" width="80" height="80"style="filter: brightness(0) invert(1); margin-bottom: 20px; opacity: 0.8;"><divstyle="color: #10b981; font-family: 'Montserrat', sans-serif; letter-spacing: 4px; font-weight: 300; font-size: 14px;">INITIALIZING MEDICAL INTELLIGENCE...</div></div></div>10 unmodified lines<div class="content-layer"><nav><div class="logo-area" style="display: flex; align-items: center; gap: 12px;"><img src="/static/logo.png" width="32" height="32" alt="Logo"style="filter: brightness(0) invert(1);"><a href="#" class="logo">Placebo AI</a></div><div class="menu-items">8 unmodified lines<button class="btn-login" id="login-btn" onclick="showAuthModal()">Log In</button></div><div class="nav-buttons" id="nav-user-buttons" style="display: none; align-items: center; gap: 16px;"><span id="user-display-email"style="font-size: 13px; font-weight: 500; opacity: 0.85; color: var(--primary);">doctor@placebo.ai</span><button class="btn-login" id="logout-btn" style="width: auto; padding: 0 16px;">Log Out</button></div></nav>62 unmodified lines<div class="search-bottom"><div class="action-buttons"><button class="action-btn" id="history-btn"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"stroke-width="2"><circle cx="12" cy="12" r="10" /><path d="M12 6v6l4 2" /></svg>History</button><button class="action-btn" id="clear-btn"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"stroke-width="2"><path d="M3 6h18" /><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" /><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" />1 unmodified lineClear</button><button class="action-btn" id="prompts-btn"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"stroke-width="2"><circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /></svg>4 unmodified lines</div></div><div class="app-disclaimer"style="text-align: center; font-size: 11px; color: rgba(255, 255, 255, 0.5); margin-top: 16px; font-family: 'Montserrat', sans-serif; max-width: 800px; margin-left: auto; margin-right: auto; line-height: 1.4;">Disclaimer: All books used in this application belong to their respective authors and publishers.The author, publisher, and copyright owner reserve all rights. No ownership of book content isclaimed by this application.</div><!-- Response Panel --><div id="response-panel"><div class="response-content" id="response-text"></div><div class="source-container" id="source-list"></div><!-- Feedback Loop --><div class="response-feedback" id="response-feedback" style="display: none;"><span class="feedback-label">Was this helpful?</span><button class="feedback-btn" id="thumbs-up-btn" aria-label="Thumbs up: Helpful answer"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><pathd="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3" /></svg></button><button class="feedback-btn" id="thumbs-down-btn" aria-label="Thumbs down: Unhelpful answer"><svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><pathd="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm12-3h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-3" /></svg></button></div><!-- Disclaimer --><div class="response-disclaimer"><svg class="icon disclaimer-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"stroke-width="2"><circle cx="12" cy="12" r="10" /><line x1="12" y1="8" x2="12" y2="12" /><line x1="12" y1="16" x2="12.01" y2="16" /></svg><span>Placebo AI is a clinical retrieval system. Synthesized knowledge should be clinicallyverified.</span></div></div></main>14 unmodified lines</div><!-- Authentication Modal Overlay --><div id="auth-modal"style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); backdrop-filter: blur(20px); z-index: 3000; display: none; align-items: center; justify-content: center; padding: 20px;"><div class="modal-container"style="max-width: 400px; border: 1px solid rgba(16, 185, 129, 0.2); box-shadow: 0 0 30px rgba(16, 185, 129, 0.1);"><div class="modal-header"><div class="modal-title" id="auth-modal-title"style="font-family: 'Surgena', serif; font-size: 24px; color: var(--white);">Authentication</div><button class="close-modal" id="close-auth-modal" aria-label="Close authentication modal"style="font-size: 28px;">×</button></div><div class="modal-body"style="background: transparent; display: flex; flex-direction: column; gap: 16px; padding: 24px;"><!-- Google OAuth Sign In Button --><button id="google-auth-btn"style="width: 100%; height: 48px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--white); font-family: 'Montserrat', sans-serif; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.3s; box-shadow: 0 4px 12px rgba(0,0,0,0.1);"onmouseover="this.style.background='rgba(255,255,255,0.12)'; this.style.borderColor='rgba(16, 185, 129, 0.5)'"onmouseout="this.style.background='rgba(255,255,255,0.06)'; this.style.borderColor='rgba(255,255,255,0.15)'"><svg width="20" height="20" viewBox="0 0 24 24" style="flex-shrink: 0;"><path fill="#EA4335"d="M12 5.04c1.66 0 3.2.57 4.38 1.69l3.27-3.27C17.67 1.48 14.97 1 12 1 7.35 1 3.4 3.65 1.56 7.5l3.86 3C6.34 7.55 8.94 5.04 12 5.04z" /><path fill="#4285F4"d="M23.49 12.27c0-.81-.07-1.59-.2-2.34H12v4.43h6.44c-.28 1.47-1.11 2.71-2.36 3.55l3.65 2.84c2.13-1.97 3.36-4.87 3.36-8.48z" /><path fill="#FBBC05"d="M5.42 14.5c-.25-.74-.39-1.53-.39-2.35s.14-1.61.39-2.35L1.56 6.8C.56 8.79 0 11.01 0 12.35s.56 3.56 1.56 5.55l3.86-3z" /><path fill="#34A853"d="M12 23c3.24 0 5.97-1.07 7.96-2.91l-3.65-2.84c-1.01.68-2.31 1.09-3.96 1.09-3.06 0-5.66-2.51-6.58-5.46l-3.86 3C3.4 20.35 7.35 23 12 23z" /></svg>Continue with Google</button><div style="display: flex; align-items: center; justify-content: center; width: 100%; margin: 4px 0;"><div style="flex: 1; height: 1px; background: rgba(255,255,255,0.08);"></div><spanstyle="font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.5; color: var(--white); padding: 0 12px;">oremail verification</span><div style="flex: 1; height: 1px; background: rgba(255,255,255,0.08);"></div></div><!-- OTP Step 1: Send Verification Code --><div id="otp-step-1" style="display: flex; flex-direction: column; gap: 16px; width: 100%;"><div style="display: flex; flex-direction: column; gap: 6px; width: 100%;"><labelstyle="font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; color: var(--white); text-align: left;">EmailAddress</label><input type="email" id="auth-email" placeholder="doctor@placebo.ai"style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; outline: none; transition: border-color 0.3s;"onfocus="this.style.borderColor='#10b981'"onblur="this.style.borderColor='rgba(255,255,255,0.1)'"></div><button class="btn-signup" id="auth-send-otp-btn"style="width: 100%; height: 46px; font-size: 14px; margin-top: 4px;">Send VerificationCode</button></div><!-- OTP Step 2: Verify 8-digit Code (Initially Hidden) --><div id="otp-step-2" style="display: none; flex-direction: column; gap: 16px; width: 100%;"><div style="display: flex; flex-direction: column; gap: 6px; width: 100%;"><labelstyle="font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; color: var(--white); text-align: left;">8-DigitOTP Code</label><input type="text" id="auth-otp-code" placeholder="••••••••" maxlength="8"style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-size: 20px; font-weight: 700; letter-spacing: 8px; text-align: center; outline: none; transition: border-color 0.3s;"onfocus="this.style.borderColor='#10b981'"onblur="this.style.borderColor='rgba(255,255,255,0.1)'"></div><button class="btn-signup" id="auth-verify-otp-btn"style="width: 100%; height: 46px; font-size: 14px; margin-top: 4px;">Verify & Log In</button><div style="text-align: center; font-size: 12px; opacity: 0.7;"><a href="#" id="auth-back-to-step1"style="color: var(--primary); text-decoration: none; font-weight: 600;">Go back to enteremail</a></div></div><!-- Unified Authentication Message Output --><div id="auth-message"style="text-align: center; font-size: 13px; font-weight: 500; margin-top: 4px; min-height: 18px; color: var(--primary); width: 100%;"></div></div></div></div><!-- Profession Selection Modal Overlay --><div id="profession-modal"style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); backdrop-filter: blur(20px); z-index: 4000; display: none; align-items: center; justify-content: center; padding: 20px;"><div class="modal-container"style="max-width: 400px; border: 1px solid rgba(16, 185, 129, 0.2); box-shadow: 0 0 30px rgba(16, 185, 129, 0.1);"><div class="modal-header"><div class="modal-title" style="font-family: 'Surgena', serif; font-size: 24px; color: var(--white);">Welcome!</div></div><div class="modal-body"style="background: transparent; display: flex; flex-direction: column; gap: 16px; padding: 24px; text-align: center;"><pstyle="color: var(--white); opacity: 0.8; font-family: 'Montserrat', sans-serif; font-size: 14px; margin-bottom: 8px;">What best describes you?</p><button class="profession-btn" data-mode="mbbs"style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; cursor: pointer; transition: all 0.2s;"onmouseover="this.style.background='rgba(16, 185, 129, 0.2)'"onmouseout="this.style.background='rgba(255,255,255,0.05)'">MBBS Student / Doctor</button><button class="profession-btn" data-mode="pharmacy"style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; cursor: pointer; transition: all 0.2s;"onmouseover="this.style.background='rgba(16, 185, 129, 0.2)'"onmouseout="this.style.background='rgba(255,255,255,0.05)'">Pharmacy Student / Pharmacist</button><button class="profession-btn" data-mode="unified"style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; cursor: pointer; transition: all 0.2s;"onmouseover="this.style.background='rgba(16, 185, 129, 0.2)'"onmouseout="this.style.background='rgba(255,255,255,0.05)'">Unified (Both Domains)</button></div></div></div>33 unmodified lineslocalStorage.removeItem(key);}}supabaseClient = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {auth: {persistSession: false // Forces logout on every page refresh}});console.log("Supabase Client initialized with ephemeral sessions. Testing connectivity...");// Connection ping test with 2-second timeoutconst pingPromise = supabaseClient.auth.getSession();const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("Supabase connection timeout")), 2000));await Promise.race([pingPromise, timeoutPromise]);console.log("Supabase connectivity verified successfully.");supabaseClient.auth.onAuthStateChange((event, session) => {console.log("Auth State Changed Event:", event);updateAuthState();13 unmodified linesconst authButtons = document.getElementById('nav-auth-buttons');const userButtons = document.getElementById('nav-user-buttons');const displayEmail = document.getElementById('user-display-email');if (supabaseClient) {try {const { data: { session } } = await supabaseClient.auth.getSession();8 unmodified linesconsole.error("Error fetching Supabase session:", err);}}if (activeUser) {authButtons.style.display = 'none';userButtons.style.display = 'flex';displayEmail.innerText = activeUser.email;let userDefaultMode = activeUser.user_metadata?.defaultMode;if (!userDefaultMode) {document.getElementById('profession-modal').style.display = 'flex';1 unmodified lineactiveMode = userDefaultMode;updateModeButtons(activeMode);}// Dynamically update user limitsconst creditText = document.querySelector('.credit-info span');if (creditText) {51 unmodified linesconst clearBtn = document.getElementById('clear-btn');let activeMode = 'unified';function updateModeButtons(mode) {const buttons = document.querySelectorAll('.model-btn');buttons.forEach(b => {17 unmodified linesactiveMode = mode;updateModeButtons(mode);document.getElementById('profession-modal').style.display = 'none';// Reset button text in case they log out and it re-showsbtn.innerText = mode === "mbbs" ? "MBBS Student / Doctor" :(mode === "pharmacy" ? "Pharmacy Student / Pharmacist" : "Unified (Both Domains)");}}};31 unmodified linesconst drawerItems = document.getElementById('drawer-items');let PREDEFINED_PROMPTS = [];// Fetch external configuration for medical terminology / promptsfetch('/static/prompts.json').then(res => res.json())2 unmodified linesasync function saveToHistory(query, answer = '', sources = []) {if (!activeUser || !supabaseClient) return;try {await supabaseClient.from('chat_history').insert({user_id: activeUser.id,9 unmodified linesfunction displayStoredResult(item) {const sanitizedQuery = DOMPurify.sanitize(item.query);const queryHTML = `<div style="font-size: 16px; font-weight: 500; color: white; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1);"><span style="opacity: 0.5; font-size: 12px; display: block; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px;">You Asked:</span>${sanitizedQuery}</div>`;sourceList.innerHTML = '';item.sources.forEach(src => {const tag = document.createElement('span');2 unmodified linestag.style.cursor = 'default';sourceList.appendChild(tag);});responseText.innerHTML = queryHTML + DOMPurify.sanitize(marked.parse(item.answer));responsePanel.style.display = 'flex';chatInput.value = item.query;sideDrawer.classList.remove('open');4 unmodified linesdrawerItems.innerHTML = '';if (type === 'history') {drawerTitle.innerText = 'History';if (!activeUser || !supabaseClient) {drawerItems.innerHTML = '<div style="opacity: 0.5; text-align: center; margin-top: 20px;">Please log in to view history.</div>';sideDrawer.classList.add('open');53 unmodified linesconst signupBtn = document.getElementById('signup-btn');const closeAuthModal = document.getElementById('close-auth-modal');const authModalTitle = document.getElementById('auth-modal-title');const googleAuthBtn = document.getElementById('google-auth-btn');const otpStep1 = document.getElementById('otp-step-1');const authEmail = document.getElementById('auth-email');const authSendOtpBtn = document.getElementById('auth-send-otp-btn');const otpStep2 = document.getElementById('otp-step-2');const authOtpCode = document.getElementById('auth-otp-code');const authVerifyOtpBtn = document.getElementById('auth-verify-otp-btn');const authBackToStep1 = document.getElementById('auth-back-to-step1');const authMessage = document.getElementById('auth-message');const logoutBtn = document.getElementById('logout-btn');16 unmodified lines// loginBtn and signupBtn onclick handled inlinecloseAuthModal.onclick = () => authModal.style.display = 'none';// Close auth modal when clicking outside content boxauthModal.onclick = (e) => {if (e.target === authModal) {13 unmodified lines// --- DISPOSABLE EMAIL CHECK ---function isDisposableEmail(email) {const disposableDomains = ['mailinator.com', 'tempmail.com', 'temp-mail.org', '10minutemail.com','yopmail.com', 'guerrillamail.com', 'dispostable.com', 'trashmail.com','getairmail.com', 'sharklasers.com', 'guerrillamailblock.com','guerrillamail.net', 'guerrillamail.org', 'guerrillamail.biz','tempmailo.com', 'generator.email', 'maildrop.cc', 'tempmail.dev','tempmail.net', 'disposable.com', 'fakeinbox.com', 'disposablemail.com'];13 unmodified linesauthMessage.style.color = '#10b981';authMessage.innerText = 'Redirecting to Google...';try {const { error } = await supabaseClient.auth.signInWithOAuth({provider: 'google',41 unmodified lines}});if (error) throw error;authMessage.innerText = 'Verification code sent to your email!';setTimeout(() => {authMessage.innerText = '';36 unmodified linestype: 'email'});if (error) throw error;authMessage.innerText = 'Authentication successful!';setTimeout(() => {authModal.style.display = 'none';47 unmodified linesif (activeUser && supabaseClient) {let currentCredits = activeUser.user_metadata?.credits_remaining !== undefined ? activeUser.user_metadata.credits_remaining : 500;if (currentCredits > 500) currentCredits = 500; // Instantly scale legacy users down to new 500 limitif (currentCredits < 10) {responsePanel.style.display = 'flex';responseText.innerHTML = '<span style="color: #ef4444; padding: 20px; display: block; text-align: center;">Insufficient credits. You need at least 10 credits to perform a clinical search. Please upgrade your account.</span>';2 unmodified linesdocument.querySelector('.input-wrapper').classList.remove('disabled');return;}let newCredits = Math.max(0, currentCredits - 10);// Optimistic UI updateconst creditText = document.querySelector('.credit-info span');if (creditText) creditText.innerText = `${newCredits}/500 credits`;// Background sync with Supabase User MetadatasupabaseClient.auth.updateUser({data: { credits_remaining: newCredits }5 unmodified lines}responsePanel.style.display = 'flex';let modeDisplay = "Unified Library";if (activeMode === "mbbs") modeDisplay = "Dx(MBBS) Knowledge Base";if (activeMode === "pharmacy") modeDisplay = "Rx(Pharmacy) Knowledge Base";const sanitizedMessage = DOMPurify.sanitize(message);const queryHTML = `<div style="font-size: 16px; font-weight: 500; color: white; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1);"><span style="opacity: 0.5; font-size: 12px; display: block; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px;">You Asked:</span>${sanitizedMessage}</div>`;const badgeHTML = `<div style="font-size: 11px; color: var(--primary); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 12px; border-left: 2px solid var(--primary); padding-left: 8px;">Response from ${modeDisplay}</div>`;responseText.innerHTML = queryHTML + badgeHTML + `<div class="skeleton skeleton-title"></div><div class="skeleton skeleton-text"></div>2 unmodified lines`;sourceList.innerHTML = '';let isRateLimited = false;try {const headers = { 'Content-Type': 'application/json' };if (activeToken) {11 unmodified linesresponseText.innerHTML = '<span style="color: #ef4444;">Session expired or unauthorized. Please log out and log back in.</span>';return;}let errorDetail = `HTTP Error: ${response.status}`;try {const errorData = await response.json();if (errorData.detail) {errorDetail = errorData.detail;}} catch(e) {}throw new Error(errorDetail);}const reader = response.body.getReader();23 unmodified linestag.style.cursor = 'default';sourceList.appendChild(tag);});// Manually update the view since sources arrive last in the stream nowconst finalHtml = DOMPurify.sanitize(marked.parse(fullAnswer));responseText.innerHTML = queryHTML + badgeHTML + finalHtml;window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });} else if (json.type === 'start_answer') {responseText.innerHTML = queryHTML + badgeHTML;fullAnswer = ""; // Reset buffer18 unmodified lines// Show feedback widget when streaming completes successfullyif (feedbackContainer) feedbackContainer.style.display = 'flex';} catch (error) {console.error("Chat error:", error);const msg = error.message === 'Failed to fetch' ? 'Connection error. The server might be offline.' : error.message;responseText.innerHTML = `<span style="color: #ef4444;">${msg}</span>`;// Restore the user's message into the input box so they don't lose itchatInput.value = message;charCount.innerText = `${message.length}/3,000`;if (msg.toLowerCase().includes('rate limit')) {isRateLimited = true;}} finally {if (isRateLimited) {let countdown = 60;chatInput.placeholder = `Wait ${countdown}s...`;const interval = setInterval(() => {countdown--;if (countdown <= 0) {clearInterval(interval);chatInput.disabled = false;sendBtn.disabled = false;document.querySelector('.input-wrapper').classList.remove('disabled');chatInput.placeholder = "Type question...";chatInput.focus();} else {chatInput.placeholder = `Wait ${countdown}s...`;}}, 1000);} else {// Re-enable inputschatInput.disabled = false;sendBtn.disabled = false;document.querySelector('.input-wrapper').classList.remove('disabled');chatInput.focus();}}}const resetModal = () => {pageModal.style.display = 'none';modalImg.dataset.scale = 1;modalImg.style.transform = 'scale(1)';};60 unmodified lines}});}sendBtn.addEventListener('click', handleSend);chatInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleSend(); });</script><!-- Anti-Copy, Anti-Paste, and Anti-Screenshot Protections --><script>// Disable Right-Click Context Menu
src/static/index.html+230-107