Spaces:
Sleeping
Sleeping
Commit Β·
3e085e1
1
Parent(s): c6aa66a
responsiveness implemented
Browse filesFiles changed (6)
- backend/db.py+35-6
- backend/main.py+3-1
- frontend/admin.html+43-7
- frontend/index.html+3-3
- frontend/script.js+6-2
- frontend/style.css+36-4
187 unmodified lines1881891901911921931941951961971981992002012023 unmodified lines20620720820921021136 unmodified lines248249250251252253254187 unmodified linesNO_ANSWER_PREFIX = "I don't have information"def analytics() -> dict:"""Aggregate usage statistics across all users."""sess = (admin().table("chat_sessions").select("id", count="exact").limit(1).execute())msgs = (admin()3 unmodified lines.limit(5000).execute()).data or []total_questions = sum(1 for m in msgs if m.get("role") == "user")answers = [m for m in msgs if m.get("role") == "assistant"]36 unmodified lines]return {"total_conversations": sess.count or 0,"total_questions": total_questions,"total_answers": len(answers),"feedback": {"up": fb_up, "down": fb_down},187 unmodified lines1881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292303 unmodified lines23423523623723823924036 unmodified lines277278279280281282283187 unmodified linesNO_ANSWER_PREFIX = "I don't have information"def _admin_user_ids() -> set[str]:"""Auth user ids of the accounts listed in ADMIN_EMAILS."""ids: set[str] = set()if not ADMIN_EMAILS:return idstry:page = 1while True:res = admin().auth.admin.list_users(page=page, per_page=200)users = res if isinstance(res, list) else getattr(res, "users", None) or []if not users:breakfor u in users:if (getattr(u, "email", "") or "").lower() in ADMIN_EMAILS:ids.add(str(u.id))if len(users) < 200:breakpage += 1except Exception:pass # if the lookup fails, stats simply include everyonereturn idsdef analytics() -> dict:"""Aggregate usage statistics for regular users (admin activity excluded)."""admin_ids = _admin_user_ids()sess_rows = (admin().table("chat_sessions").select("id, user_id").limit(10000).execute()).data or []user_session_ids = {s["id"] for s in sess_rows if str(s.get("user_id")) not in admin_ids}msgs = (admin()3 unmodified lines.limit(5000).execute()).data or []msgs = [m for m in msgs if m.get("session_id") in user_session_ids]total_questions = sum(1 for m in msgs if m.get("role") == "user")answers = [m for m in msgs if m.get("role") == "assistant"]36 unmodified lines]return {"total_conversations": len(user_session_ids),"total_questions": total_questions,"total_answers": len(answers),"feedback": {"up": fb_up, "down": fb_down},
325 unmodified lines326327328329330331332325 unmodified linesanswer = "".join(parts)saved = Noneif answer.strip():saved = db.add_message(session_id, "assistant", answer, sources)db.touch_session(session_id)yield event({"type": "done", "message_id": (saved or {}).get("id")})325 unmodified lines326327328329330331332333334325 unmodified linesanswer = "".join(parts)saved = Noneif answer.strip():# A refusal cites nothing β don't attach sources/images to itmsg_sources = [] if answer.strip().startswith(db.NO_ANSWER_PREFIX) else sourcessaved = db.add_message(session_id, "assistant", answer, msg_sources)db.touch_session(session_id)yield event({"type": "done", "message_id": (saved or {}).get("id")})
137 unmodified lines1381391401411421431441451461471481491501511521537 unmodified lines16116216316416516616716816917017124 unmodified lines19619719819920020110 unmodified lines212213214215216217218137 unmodified lines.panel-head h3 { font-size: .95rem; font-weight: 700; flex: 1; }.panel-head .hint { font-size: .72rem; color: var(--text-muted); }.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; margin-top: 20px; }.two-col .panel { margin-top: 0; }@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }/* ββ Daily activity chart ββ */.chart {display: flex; align-items: flex-end; gap: 7px; height: 170px;padding-top: 24px; border-bottom: 1px solid var(--border);}.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }.chart .bar {width: 100%; max-width: 42px; border-radius: 7px 7px 0 0;background: linear-gradient(180deg, var(--accent), var(--accent-dk));7 unmodified linesfont-size: .68rem; color: var(--text); font-weight: 700;}.chart-days { display: flex; gap: 7px; margin-top: 8px; }.chart-days span { flex: 1; text-align: center; font-size: .62rem; color: var(--text-muted); white-space: nowrap; }/* ββ Cited docs bars ββ */.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }.hbar-name { flex: 0 0 44%; font-size: .78rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.hbar-track { flex: 1; background: var(--surface2); border-radius: 8px; height: 16px; overflow: hidden; }.hbar-fill {height: 100%; background: linear-gradient(90deg, var(--accent-dk), var(--accent));24 unmodified lines}.doclist li:hover { background: var(--hover); }.hidden { display: none !important; }</style></head><body>10 unmodified lines</button><a class="btn btn-accent" href="/"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>Back to chat</a></header>137 unmodified lines1381391401411421431441451461471481491501511521531541557 unmodified lines16316416516616716816917017117217324 unmodified lines19819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623710 unmodified lines248249250251252253254137 unmodified lines.panel-head h3 { font-size: .95rem; font-weight: 700; flex: 1; }.panel-head .hint { font-size: .72rem; color: var(--text-muted); }/* minmax(0, β¦) lets tracks shrink below their content width β long PDFfilenames must ellipsize instead of stretching the page */.two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; margin-top: 20px; }.two-col .panel { margin-top: 0; min-width: 0; }@media (max-width: 860px) { .two-col { grid-template-columns: minmax(0, 1fr); } }/* ββ Daily activity chart ββ */.chart {display: flex; align-items: flex-end; gap: 7px; height: 170px;padding-top: 24px; border-bottom: 1px solid var(--border);}.chart .col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }.chart .bar {width: 100%; max-width: 42px; border-radius: 7px 7px 0 0;background: linear-gradient(180deg, var(--accent), var(--accent-dk));7 unmodified linesfont-size: .68rem; color: var(--text); font-weight: 700;}.chart-days { display: flex; gap: 7px; margin-top: 8px; }.chart-days span { flex: 1; min-width: 0; overflow: hidden; text-align: center; font-size: .62rem; color: var(--text-muted); white-space: nowrap; }/* ββ Cited docs bars ββ */.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }.hbar-name { flex: 0 0 44%; min-width: 0; font-size: .78rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.hbar-track { flex: 1; background: var(--surface2); border-radius: 8px; height: 16px; overflow: hidden; }.hbar-fill {height: 100%; background: linear-gradient(90deg, var(--accent-dk), var(--accent));24 unmodified lines}.doclist li:hover { background: var(--hover); }.hidden { display: none !important; }/* ββ Mobile ββ */@media (max-width: 640px) {.topbar { padding: 10px 12px; gap: 8px; }.topbar .sub { display: none; }.topbar h1 { font-size: .95rem; }.brand-tile { width: 36px; height: 36px; border-radius: 10px; }.btn { height: 36px; padding: 0 12px; font-size: .78rem; }.btn.icon-only { width: 36px; }.btn .btn-label { display: none; } /* back button becomes icon-only */.btn-accent { padding: 0 10px; }.wrap { padding: 18px 12px 50px; }.page-head h2 { font-size: 1.1rem; }.grid { grid-template-columns: 1fr 1fr; gap: 10px; }.card { padding: 13px; gap: 10px; border-radius: 13px; }.card .tile { width: 38px; height: 38px; font-size: 1.05rem; border-radius: 10px; }.card .value { font-size: 1.25rem; }.card .label { font-size: .62rem; }.panel { padding: 16px 14px; border-radius: 13px; margin-top: 14px; }.two-col { gap: 14px; margin-top: 14px; }.chart { height: 120px; gap: 3px; }.chart .bar .n { display: none; } /* numbers overlap on tiny bars */.chart-days { gap: 3px; }.chart-days span { font-size: .52rem; }.chart-days span:nth-child(even) { visibility: hidden; } /* every other date */.hbar-name { flex-basis: 40%; font-size: .7rem; }.hbar-count { flex-basis: 26px; font-size: .72rem; }.qlist li { font-size: .78rem; padding: 9px 11px; }}</style></head><body>10 unmodified lines</button><a class="btn btn-accent" href="/"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5M12 19l-7-7 7-7"/></svg><span class="btn-label">Back to chat</span></a></header>
10 unmodified lines11121314151617130 unmodified lines14814915015115215315431 unmodified lines18618718818919019110 unmodified linesif (t) document.documentElement.dataset.theme = t;})();</script><link rel="stylesheet" href="/static/style.css?v=11" /><script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script><script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/build/pdf.min.js"></script><script src="https://cdn.jsdelivr.net/npm/marked@12/marked.min.js"></script>130 unmodified lines<textareaid="questionInput"class="question-input"placeholder="Ask a question about your policiesβ¦"rows="1"></textarea><button type="submit" class="btn-send" id="sendBtn" aria-label="Send">31 unmodified lines</div></div><script src="/static/script.js?v=14"></script></body></html>10 unmodified lines11121314151617130 unmodified lines14814915015115215315431 unmodified lines18618718818919019110 unmodified linesif (t) document.documentElement.dataset.theme = t;})();</script><link rel="stylesheet" href="/static/style.css?v=12" /><script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script><script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/build/pdf.min.js"></script><script src="https://cdn.jsdelivr.net/npm/marked@12/marked.min.js"></script>130 unmodified lines<textareaid="questionInput"class="question-input"placeholder="Ask a question..."rows="1"></textarea><button type="submit" class="btn-send" id="sendBtn" aria-label="Send">31 unmodified lines</div></div><script src="/static/script.js?v=15"></script></body></html>
258 unmodified lines259260261262263264265431 unmodified lines697698699700701702703704258 unmodified linessetBubbleContent(bubble, role, text);row.appendChild(bubble);renderSources(row, sources);if (role === 'assistant' && info && info.id) {addFeedbackBar(row, info.id, info.feedback || null);}431 unmodified linesstopTypewriter();removeTypingIndicator();if (bubble) bubble.classList.remove('streaming');if (meta) {if (row) renderSources(row, meta.sources || []);if (wasNew) await loadSessions();highlightActiveSession();}258 unmodified lines259260261262263264265266267431 unmodified lines699700701702703704705706707708258 unmodified linessetBubbleContent(bubble, role, text);row.appendChild(bubble);// Refusals cite nothing (also covers older messages saved with sources)const refused = role === 'assistant' && (text || '').trim().startsWith("I don't have information");if (!refused) renderSources(row, sources);if (role === 'assistant' && info && info.id) {addFeedbackBar(row, info.id, info.feedback || null);}431 unmodified linesstopTypewriter();removeTypingIndicator();if (bubble) bubble.classList.remove('streaming');// A refusal cites nothing β showing sources/images would be misleadingconst refused = answerText.trim().startsWith("I don't have information");if (meta) {if (row && !refused) renderSources(row, meta.sources || []);if (wasNew) await loadSessions();highlightActiveSession();}
67 unmodified lines686970717273149 unmodified lines223224225226227228229955 unmodified lines1185118611871188118911901191119211931194119511961197119811991200120112021203120467 unmodified lines.app-shell {display: flex;height: 100vh;}/* ββ Sidebar ββ */149 unmodified linesbackground: var(--surface);}.chat-header h1 { font-size: 1.1rem; font-weight: 700; }.chat-header p { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }/* Messages */955 unmodified lines.sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }.chat-area { width: 100%; }.chat-header { padding: 14px 16px; }.chat-header h1 { font-size: 1rem; }.chat-header p { font-size: .72rem; }.messages { padding: 16px 14px; }.message { max-width: 90%; }.input-bar { padding: 12px 14px 16px; }.auth-card { padding: 26px 20px; }.ref-img { max-width: 70vw; }}@media (max-width: 420px) {.message { max-width: 95%; }.bubble { font-size: .9rem; }.chat-header p { display: none; }}67 unmodified lines68697071727374149 unmodified lines224225226227228229230231232233234235236955 unmodified lines11921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123667 unmodified lines.app-shell {display: flex;height: 100vh;height: 100dvh; /* mobile browsers: exclude the URL bar / keyboard */}/* ββ Sidebar ββ */149 unmodified linesbackground: var(--surface);}.chat-header h1 {font-size: 1.1rem;font-weight: 700;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}.chat-header p { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }/* Messages */955 unmodified lines.sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }.chat-area { width: 100%; }.chat-header { padding: 14px 16px; gap: 8px; }.chat-header h1 { font-size: 1rem; }.chat-header p { font-size: .72rem; }.header-btn { width: 36px; height: 36px; border-radius: 9px; }.messages { padding: 16px 14px; }.message { max-width: 90%; }.input-bar { padding: 12px 14px 16px; gap: 8px; }.auth-card { padding: 26px 20px; }.theme-fab { top: 12px; right: 12px; }.ref-img { max-width: 70vw; }}@media (max-width: 420px) {.message { max-width: 95%; }.bubble { font-size: .9rem; padding: 10px 13px; }.chat-header p { display: none; }/* Compact input bar: mic + textarea + send must fit a 360px screen */.input-bar { gap: 6px; padding: 10px 10px 14px; }.btn-mic, .btn-send { width: 40px; height: 40px; font-size: .95rem; }.question-input { padding: 10px 12px; font-size: .88rem; }/* Starter chips become full-width buttons */.starter-chips { flex-direction: column; }.starter-chip { width: 100%; }/* Typing indicator: allow the status text to wrap */.typing-bubble { flex-wrap: wrap; }.typing-status { font-size: .74rem; }/* Source tags + feedback stay tappable */.source-tag { font-size: .68rem; padding: 4px 9px; }.fb-btn { padding: 4px 9px; }/* PDF modal toolbar tightens up */.pdf-toolbar { padding: 8px 10px; gap: 8px; }.pdf-title { font-size: .76rem; }.pdf-page-label { min-width: 44px; font-size: .74rem; }.pdf-btn { width: 28px; height: 28px; }}
backend/db.py+35-6
backend/main.py+3-1
frontend/admin.html+43-7
frontend/index.html+3-3
frontend/script.js+6-2
frontend/style.css+36-4