Spaces:
Sleeping
Sleeping
Download src/apps/templates/Judgechatbot.html from Legal-Assistant/LawBot: direct link, hf CLI and curl.
- Browser
- Download file 27.4 kB
-
https://huggingface.co/spaces/Legal-Assistant/LawBot/resolve/main/src/apps/templates/Judgechatbot.html
- Command line
-
hf download hf://spaces/Legal-Assistant/LawBot/src/apps/templates/Judgechatbot.html
-
curl -L -o Judgechatbot.html https://huggingface.co/spaces/Legal-Assistant/LawBot/resolve/main/src/apps/templates/Judgechatbot.html
27.4 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
| <title>AI Legal Assistant | Judicial Deliberation System</title> | |
| <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" | |
| rel="stylesheet"> | |
| <style> | |
| :root { | |
| --bg-dark: #030617; | |
| --sidebar-bg: #050a24; | |
| --accent-gold: #fbbf24; | |
| --accent-navy: #1e3a8a; | |
| --text-primary: #f1f5f9; | |
| --text-dim: #94a3b8; | |
| --glass-bg: rgba(255, 255, 255, 0.03); | |
| --glass-border: rgba(255, 255, 255, 0.08); | |
| } | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| font-family: 'Poppins', sans-serif; | |
| } | |
| body { | |
| background-color: var(--bg-dark); | |
| color: var(--text-primary); | |
| height: 100vh; | |
| display: flex; | |
| overflow: hidden; | |
| } | |
| /* SIDEBAR */ | |
| .sidebar { | |
| width: 300px; | |
| background: var(--sidebar-bg); | |
| border-right: 1px solid var(--glass-border); | |
| display: flex; | |
| flex-direction: column; | |
| z-index: 100; | |
| } | |
| .sidebar-header { | |
| padding: 40px 25px; | |
| } | |
| .new-chat-btn { | |
| width: 100%; | |
| padding: 16px; | |
| background: linear-gradient(135deg, var(--accent-gold), #d97706); | |
| border: none; | |
| border-radius: 12px; | |
| color: #030617; | |
| font-weight: 700; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 10px; | |
| cursor: pointer; | |
| transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); | |
| box-shadow: 0 10px 20px rgba(251, 191, 36, 0.15); | |
| } | |
| .new-chat-btn:hover { | |
| transform: translateY(-3px); | |
| box-shadow: 0 15px 30px rgba(251, 191, 36, 0.25); | |
| } | |
| .history-label { | |
| padding: 0 25px 10px; | |
| font-size: 0.7rem; | |
| text-transform: uppercase; | |
| letter-spacing: 2.5px; | |
| color: var(--text-dim); | |
| font-weight: 700; | |
| opacity: 0.8; | |
| } | |
| .history-list { | |
| flex: 1; | |
| overflow-y: auto; | |
| padding: 15px; | |
| } | |
| .history-item { | |
| padding: 14px 18px; | |
| border-radius: 10px; | |
| margin-bottom: 8px; | |
| cursor: pointer; | |
| transition: 0.2s; | |
| font-size: 0.9rem; | |
| color: var(--text-dim); | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| border: 1px solid transparent; | |
| white-space: nowrap; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| } | |
| .history-item:hover { | |
| background: rgba(251, 191, 36, 0.05); | |
| color: var(--accent-gold); | |
| border-color: rgba(251, 191, 36, 0.2); | |
| } | |
| .sidebar-footer { | |
| padding: 25px; | |
| border-top: 1px solid var(--glass-border); | |
| } | |
| .user-badge { | |
| display: flex; | |
| align-items: center; | |
| gap: 15px; | |
| padding: 12px; | |
| background: rgba(251, 191, 36, 0.05); | |
| border-radius: 14px; | |
| border: 1px solid rgba(251, 191, 36, 0.1); | |
| } | |
| .user-avatar { | |
| width: 36px; | |
| height: 36px; | |
| background: var(--accent-gold); | |
| border-radius: 10px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-weight: 800; | |
| color: #030617; | |
| font-size: 0.9rem; | |
| } | |
| /* MAIN AREA */ | |
| .main-chat { | |
| flex: 1; | |
| display: flex; | |
| flex-direction: column; | |
| position: relative; | |
| background: radial-gradient(circle at top right, rgba(251, 191, 36, 0.02), transparent); | |
| } | |
| .top-bar { | |
| height: 80px; | |
| background: rgba(3, 6, 23, 0.85); | |
| backdrop-filter: blur(25px); | |
| border-bottom: 1px solid var(--glass-border); | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| padding: 0 45px; | |
| z-index: 50; | |
| } | |
| .branding-title { | |
| font-weight: 700; | |
| color: white; | |
| letter-spacing: -0.5px; | |
| font-size: 1.1rem; | |
| } | |
| .status-pill { | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| font-size: 0.75rem; | |
| background: rgba(251, 191, 36, 0.1); | |
| color: var(--accent-gold); | |
| padding: 5px 15px; | |
| border-radius: 20px; | |
| font-weight: 700; | |
| border: 1px solid rgba(251, 191, 36, 0.2); | |
| } | |
| .status-dot { | |
| width: 7px; | |
| height: 7px; | |
| background: var(--accent-gold); | |
| border-radius: 50%; | |
| animation: pulse-dot 2s infinite; | |
| } | |
| @keyframes pulse-dot { | |
| 0%, | |
| 100% { | |
| transform: scale(1); | |
| opacity: 1; | |
| } | |
| 50% { | |
| transform: scale(1.6); | |
| opacity: 0.3; | |
| } | |
| } | |
| .messages-container { | |
| flex: 1; | |
| overflow-y: auto; | |
| padding: 50px 12%; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 40px; | |
| scroll-behavior: smooth; | |
| } | |
| .message { | |
| max-width: 900px; | |
| animation: message-slide 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; | |
| } | |
| @keyframes message-slide { | |
| from { | |
| opacity: 0; | |
| transform: translateY(25px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| .user-msg { | |
| align-self: flex-end; | |
| background: linear-gradient(135deg, var(--accent-gold), #d97706); | |
| padding: 18px 26px; | |
| border-radius: 22px 22px 4px 22px; | |
| color: #030617; | |
| font-weight: 500; | |
| max-width: 70%; | |
| box-shadow: 0 10px 30px rgba(251, 191, 36, 0.2); | |
| } | |
| .ai-msg { | |
| align-self: flex-start; | |
| background: rgba(255, 255, 255, 0.02); | |
| border: 1px solid var(--glass-border); | |
| padding: 35px; | |
| border-radius: 24px 24px 24px 6px; | |
| max-width: 88%; | |
| line-height: 1.9; | |
| color: #e2e8f0; | |
| } | |
| .ai-msg h3 { | |
| color: var(--accent-gold); | |
| font-size: 1.4rem; | |
| margin-bottom: 25px; | |
| font-weight: 700; | |
| display: flex; | |
| align-items: center; | |
| gap: 15px; | |
| } | |
| .ai-msg ul { | |
| margin: 25px 0; | |
| list-style: none; | |
| } | |
| .ai-msg li { | |
| position: relative; | |
| padding-left: 32px; | |
| margin-bottom: 18px; | |
| } | |
| .ai-msg li::before { | |
| content: "⚖️"; | |
| position: absolute; | |
| left: 0; | |
| font-size: 1rem; | |
| } | |
| .highlight { | |
| background: rgba(251, 191, 36, 0.05); | |
| border-left: 5px solid var(--accent-gold); | |
| padding: 25px; | |
| margin: 30px 0; | |
| border-radius: 0 18px 18px 0; | |
| font-weight: 600; | |
| color: #fff; | |
| } | |
| .typing { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 12px; | |
| padding: 20px 30px; | |
| background: var(--glass-bg); | |
| border-radius: 24px; | |
| width: fit-content; | |
| margin: 25px 12%; | |
| border: 1px solid var(--glass-border); | |
| animation: pulse-border-gold 2s infinite ease-in-out; | |
| } | |
| .typing-text { | |
| font-size: 0.9rem; | |
| color: var(--accent-gold); | |
| font-weight: 700; | |
| letter-spacing: 1px; | |
| text-transform: uppercase; | |
| } | |
| .typing-dots { | |
| display: flex; | |
| gap: 8px; | |
| } | |
| .typing-dots span { | |
| width: 8px; | |
| height: 8px; | |
| background: var(--accent-gold); | |
| border-radius: 50%; | |
| animation: typing-blink 1.4s infinite ease-in-out; | |
| } | |
| .typing-dots span:nth-child(2) { | |
| animation-delay: 0.22s; | |
| } | |
| .typing-dots span:nth-child(3) { | |
| animation-delay: 0.44s; | |
| } | |
| @keyframes typing-blink { | |
| 0%, | |
| 100% { | |
| opacity: 0.2; | |
| transform: scale(0.85); | |
| } | |
| 50% { | |
| opacity: 1; | |
| transform: scale(1.15); | |
| } | |
| } | |
| @keyframes pulse-border-gold { | |
| 0%, | |
| 100% { | |
| border-color: var(--glass-border); | |
| } | |
| 50% { | |
| border-color: var(--accent-gold); | |
| box-shadow: 0 0 25px rgba(251, 191, 36, 0.15); | |
| } | |
| } | |
| .input-area { | |
| padding: 40px 12%; | |
| background: linear-gradient(to top, var(--bg-dark) 60%, transparent); | |
| border-top: 1px solid var(--glass-border); | |
| z-index: 60; | |
| } | |
| .input-box { | |
| background: rgba(255, 255, 255, 0.03); | |
| border: 1px solid var(--glass-border); | |
| border-radius: 20px; | |
| padding: 8px; | |
| display: flex; | |
| align-items: center; | |
| transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| .input-box:focus-within { | |
| border-color: var(--accent-gold); | |
| box-shadow: 0 0 40px rgba(251, 191, 36, 0.1); | |
| background: rgba(255, 255, 255, 0.05); | |
| } | |
| .input-box input { | |
| flex: 1; | |
| min-width: 0; | |
| background: transparent; | |
| border: none; | |
| padding: 18px 28px; | |
| color: white; | |
| font-size: 1.1rem; | |
| outline: none; | |
| } | |
| .send-btn { | |
| background: var(--accent-gold); | |
| color: #030617; | |
| border: none; | |
| width: 55px; | |
| height: 55px; | |
| border-radius: 16px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| cursor: pointer; | |
| transition: 0.3s; | |
| margin-right: 8px; | |
| flex-shrink: 0; | |
| } | |
| .send-btn:hover { | |
| transform: scale(1.1) rotate(-5deg); | |
| filter: brightness(1.1); | |
| } | |
| .hidden { | |
| display: none ; | |
| } | |
| @keyframes float { | |
| 0%, | |
| 100% { | |
| transform: translateY(0); | |
| } | |
| 50% { | |
| transform: translateY(-20px); | |
| } | |
| } | |
| /* MOBILE RESPONSIVENESS */ | |
| .menu-toggle { | |
| display: none; | |
| background: none; | |
| border: none; | |
| color: var(--text-primary); | |
| font-size: 1.8rem; | |
| cursor: pointer; | |
| align-items: center; | |
| justify-content: center; | |
| margin-right: 15px; | |
| z-index: 101; | |
| transition: color 0.3s; | |
| } | |
| .menu-toggle:hover { | |
| color: var(--accent-gold); | |
| } | |
| .sidebar-overlay { | |
| display: none; | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100vw; | |
| height: 100vh; | |
| background: rgba(3, 6, 23, 0.6); | |
| backdrop-filter: blur(5px); | |
| -webkit-backdrop-filter: blur(5px); | |
| z-index: 99; | |
| opacity: 0; | |
| transition: opacity 0.3s ease; | |
| pointer-events: none; | |
| } | |
| .sidebar-overlay.active { | |
| display: block; | |
| opacity: 1; | |
| pointer-events: auto; | |
| } | |
| @media (max-width: 768px) { | |
| body { | |
| width: 100vw; | |
| height: 100vh; | |
| height: 100dvh; | |
| overflow: hidden; | |
| } | |
| .main-chat { | |
| width: 100vw; | |
| max-width: 100vw; | |
| height: 100%; | |
| overflow: hidden; | |
| } | |
| .menu-toggle { | |
| display: flex; | |
| } | |
| .sidebar { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| height: 100vh; | |
| height: 100dvh; | |
| width: 300px; | |
| transform: translateX(-100%) ; | |
| transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); | |
| z-index: 1000; | |
| box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5); | |
| overflow-y: auto ; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| .sidebar.active { | |
| transform: translateX(0) ; | |
| } | |
| .top-bar { | |
| padding: 0 15px; | |
| overflow: hidden; | |
| } | |
| .top-bar > div:last-child { | |
| display: none; | |
| } | |
| .status-pill { | |
| display: none ; | |
| } | |
| .branding-title, | |
| .system-branding span { | |
| font-size: 0.95rem; | |
| white-space: nowrap; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| max-width: 180px; | |
| display: inline-block; | |
| vertical-align: middle; | |
| } | |
| .messages-container { | |
| padding: 25px 15px; | |
| gap: 20px; | |
| overflow-y: auto ; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| .user-msg { | |
| max-width: 85%; | |
| padding: 12px 18px; | |
| font-size: 0.95rem; | |
| } | |
| .ai-msg { | |
| max-width: 95%; | |
| padding: 20px; | |
| font-size: 0.95rem; | |
| } | |
| .ai-msg h3 { | |
| font-size: 1.15rem; | |
| margin-bottom: 15px; | |
| } | |
| .input-area { | |
| padding: 15px 15px 25px 15px; | |
| } | |
| .input-box input { | |
| padding: 12px 15px; | |
| font-size: 16px; | |
| } | |
| .send-btn { | |
| width: 44px; | |
| height: 44px; | |
| } | |
| #welcomeScreen h1 { | |
| font-size: 1.4rem ; | |
| margin-bottom: 8px ; | |
| } | |
| #welcomeScreen p { | |
| font-size: 0.85rem ; | |
| max-width: 100% ; | |
| } | |
| #welcomeScreen div:first-child { | |
| font-size: 2.2rem ; | |
| margin-bottom: 10px ; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="sidebar-overlay" id="sidebarOverlay"></div> | |
| <aside class="sidebar"> | |
| <div class="sidebar-header"> | |
| <button class="new-chat-btn" id="newChatBtn"><span>🏛️</span> New Deliberation</button> | |
| </div> | |
| <div class="history-label">Case Files & Records</div> | |
| <div class="history-list" id="historyList"></div> | |
| <div class="sidebar-footer"> | |
| <div class="user-badge"> | |
| <div class="user-avatar" id="avatarName">JD</div> | |
| <div> | |
| <div id="usernameLabel" style="font-size: 0.9rem; font-weight: 700;">Your Honor</div> | |
| <div style="font-size: 0.75rem; color: var(--text-dim); font-weight: 500;">Judicial Authority</div> | |
| </div> | |
| </div> | |
| <div style="display: flex; flex-direction: column; gap: 10px; margin-top: 20px;"> | |
| <a href="/judgedashboard.html" | |
| style="color: var(--accent-gold); text-decoration: none; font-size: 0.85rem; text-align: center; font-weight: 700; letter-spacing: 0.5px;">Return | |
| to Chambers</a> | |
| <a href="/role" | |
| style="color: var(--text-dim); text-decoration: none; font-size: 0.8rem; text-align: center;">← | |
| Change Role</a> | |
| </div> | |
| </div> | |
| </aside> | |
| <main class="main-chat"> | |
| <header class="top-bar"> | |
| <button class="menu-toggle" id="menuToggle" aria-label="Toggle Sidebar">☰</button> | |
| <div class="system-branding"> | |
| <span class="branding-title">🏛️ Judicial Intelligence System</span> | |
| <div class="status-pill"> | |
| <div class="status-dot"></div>Secure Deliberation Active | |
| </div> | |
| </div> | |
| <div style="font-size: 0.85rem; color: var(--text-dim); font-weight: 600; letter-spacing: 1px;">JUDICIAL | |
| FRAMEWORK v5.0 PRO</div> | |
| </header> | |
| <div id="welcomeScreen" | |
| style="position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 40px; z-index: 1;"> | |
| <div style="font-size: 5rem; margin-bottom: 30px; animation: float 8s ease-in-out infinite;">⚖️</div> | |
| <h1 style="font-size: 3.2rem; font-weight: 800; margin-bottom: 15px; letter-spacing: -1.5px;">Protocol | |
| Initiated, Your Honor.</h1> | |
| <p style="color: var(--text-dim); max-width: 600px; line-height: 1.8; font-size: 1.2rem; font-weight: 300;"> | |
| Enhanced judicial support is online.</p> | |
| </div> | |
| <div class="messages-container" id="chatContainer"></div> | |
| <div class="typing hidden" id="typingIndicator"> | |
| <div class="typing-text">Law Bot is deliberating...</div> | |
| <div class="typing-dots"> | |
| <span></span><span></span><span></span> | |
| </div> | |
| </div> | |
| <div class="input-area"> | |
| <div class="input-box"> | |
| <input type="text" id="messageInput" placeholder="Initiate legal inquiry..." autocomplete="off"> | |
| <button class="send-btn" id="sendButton"> | |
| <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" | |
| stroke-linecap="round" stroke-linejoin="round"> | |
| <line x1="22" y1="2" x2="11" y2="13"></line> | |
| <polygon points="22 2 15 22 11 13 2 9 22 2"></polygon> | |
| </svg> | |
| </button> | |
| </div> | |
| <p | |
| style="text-align: center; font-size: 0.8rem; color: var(--text-dim); margin-top: 25px; font-weight: 500; opacity: 0.7; letter-spacing: 0.5px;"> | |
| 🔒 ENCRYPTED END-TO-END • JUDICIAL PRIVACY PROTECTED</p> | |
| </div> | |
| </main> | |
| <script> | |
| let ws; | |
| const chatContainer = document.getElementById('chatContainer'); | |
| const messageInput = document.getElementById('messageInput'); | |
| const sendButton = document.getElementById('sendButton'); | |
| const typingIndicator = document.getElementById('typingIndicator'); | |
| const welcomeScreen = document.getElementById('welcomeScreen'); | |
| const historyList = document.getElementById('historyList'); | |
| let currentAiMessage = ''; | |
| let currentAiMessageElement = null; | |
| let currentCaseId = crypto.randomUUID(); | |
| const activeRole = 'Judge'; | |
| function formatResponse(text) { | |
| let formatted = text; | |
| formatted = formatted.replace(/### (.*?)\s*(\n|$)/g, "<h3>🏛️ $1</h3>"); | |
| formatted = formatted.replace(/^! (.*?)$/gm, '<div class="highlight">$1</div>'); | |
| formatted = formatted.replace(/^\d+\.\s(.*?)$/gm, "<li>$1</li>"); | |
| formatted = formatted.replace(/^\*\s(.*?)$/gm, "<li>$1</li>"); | |
| formatted = formatted.replace(/- (.*?)$/gm, "<li>$1</li>"); | |
| formatted = formatted.replace(/<li>(.*?)<\/li>(?!<li>)/g, "<ul><li>$1</li></ul>"); | |
| formatted = formatted.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>"); | |
| formatted = formatted.replace(/\n/g, "<br>"); | |
| return formatted; | |
| } | |
| function connectWS() { | |
| const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; | |
| ws = new WebSocket(`${protocol}//${window.location.host}/conversational_chat?role=${activeRole}`); | |
| ws.onmessage = (event) => { | |
| typingIndicator.classList.add('hidden'); | |
| welcomeScreen.classList.add('hidden'); | |
| if (event.data === '[DONE]') { | |
| saveInteraction(currentCaseId, messageInput.value, currentAiMessage); | |
| return; | |
| } | |
| if (!currentAiMessageElement) { | |
| currentAiMessage = event.data; | |
| createNewMessage('ai', currentAiMessage); | |
| } else { | |
| currentAiMessage += event.data; | |
| currentAiMessageElement.innerHTML = formatResponse(currentAiMessage); | |
| } | |
| chatContainer.scrollTop = chatContainer.scrollHeight; | |
| }; | |
| ws.onclose = () => setTimeout(connectWS, 2000); | |
| } | |
| function createNewMessage(type, content) { | |
| welcomeScreen.classList.add('hidden'); | |
| const msgDiv = document.createElement('div'); | |
| msgDiv.className = `message ${type}-msg`; | |
| if (type === 'ai') { | |
| msgDiv.innerHTML = formatResponse(content); | |
| currentAiMessageElement = msgDiv; | |
| } else { | |
| msgDiv.textContent = content; | |
| } | |
| chatContainer.appendChild(msgDiv); | |
| chatContainer.scrollTop = chatContainer.scrollHeight; | |
| } | |
| function sendMessage() { | |
| const text = messageInput.value.trim(); | |
| if (!text || ws.readyState !== WebSocket.OPEN) return; | |
| createNewMessage('user', text); | |
| ws.send(text); | |
| messageInput.value = ''; | |
| currentAiMessage = ''; | |
| currentAiMessageElement = null; | |
| typingIndicator.classList.remove('hidden'); | |
| chatContainer.scrollTop = chatContainer.scrollHeight; | |
| } | |
| async function saveInteraction(caseId, query, response) { | |
| const token = localStorage.getItem('token'); | |
| if (!token) return; | |
| try { | |
| await fetch('/api/save-interaction', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, | |
| body: JSON.stringify({ caseId, query, response, role: activeRole }) | |
| }); | |
| loadHistory(); | |
| } catch (err) { console.error(err); } | |
| } | |
| async function loadHistory() { | |
| const token = localStorage.getItem('token'); | |
| if (!token) return; | |
| try { | |
| const res = await fetch(`/api/interactions?role=${activeRole}`, { | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| const data = await res.json(); | |
| historyList.innerHTML = ''; | |
| data.forEach(item => { | |
| const div = document.createElement('div'); | |
| div.className = 'history-item'; | |
| const preview = item.query.substring(0, 30) + "..."; | |
| div.innerHTML = `<span>📂</span> ${preview}`; | |
| div.onclick = () => loadThread(item.case_id); | |
| historyList.appendChild(div); | |
| }); | |
| } catch (err) { console.error(err); } | |
| } | |
| async function loadThread(caseId) { | |
| const token = localStorage.getItem('token'); | |
| try { | |
| const res = await fetch(`/api/interactions/${caseId}?role=${activeRole}`, { | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| const thread = await res.json(); | |
| currentCaseId = caseId; | |
| chatContainer.innerHTML = ''; | |
| welcomeScreen.classList.add('hidden'); | |
| thread.forEach(msg => { | |
| createNewMessage('user', msg.query); | |
| createNewMessage('ai', msg.response); | |
| }); | |
| currentAiMessageElement = null; | |
| if (window.innerWidth <= 768) { | |
| const sidebar = document.querySelector('.sidebar'); | |
| const sidebarOverlay = document.getElementById('sidebarOverlay'); | |
| if (sidebar) sidebar.classList.remove('active'); | |
| if (sidebarOverlay) sidebarOverlay.classList.remove('active'); | |
| } | |
| } catch (err) { console.error(err); } | |
| } | |
| async function fetchUserStatus() { | |
| const token = localStorage.getItem('token'); | |
| if (!token) return; | |
| try { | |
| const res = await fetch('/api/user-status', { | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| const status = await res.json(); | |
| document.getElementById('usernameLabel').innerText = status.username.charAt(0).toUpperCase() + status.username.slice(1); | |
| document.getElementById('avatarName').innerText = status.username.substring(0, 2).toUpperCase(); | |
| } catch (err) { console.error(err); } | |
| } | |
| sendButton.onclick = sendMessage; | |
| messageInput.onkeypress = (e) => { if (e.key === 'Enter') sendMessage(); }; | |
| document.getElementById('newChatBtn').onclick = () => { | |
| currentCaseId = crypto.randomUUID(); | |
| chatContainer.innerHTML = ''; | |
| welcomeScreen.classList.remove('hidden'); | |
| if (window.innerWidth <= 768) { | |
| const sidebar = document.querySelector('.sidebar'); | |
| const sidebarOverlay = document.getElementById('sidebarOverlay'); | |
| if (sidebar) sidebar.classList.remove('active'); | |
| if (sidebarOverlay) sidebarOverlay.classList.remove('active'); | |
| } | |
| }; | |
| connectWS(); | |
| loadHistory(); | |
| fetchUserStatus(); | |
| // Mobile Sidebar Toggling Logic | |
| const menuToggle = document.getElementById('menuToggle'); | |
| const sidebar = document.querySelector('.sidebar'); | |
| const sidebarOverlay = document.getElementById('sidebarOverlay'); | |
| function toggleSidebar() { | |
| sidebar.classList.toggle('active'); | |
| sidebarOverlay.classList.toggle('active'); | |
| } | |
| menuToggle.addEventListener('click', toggleSidebar); | |
| sidebarOverlay.addEventListener('click', toggleSidebar); | |
| </script> | |
| </body> | |
| </html> |