366 lines
19 KiB
HTML
366 lines
19 KiB
HTML
{{define "layout"}}
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>LLM Gateway</title>
|
|
<script>
|
|
// Prevent flash of wrong theme
|
|
(function() {
|
|
var pref = localStorage.getItem('theme') || 'auto';
|
|
var effective = pref;
|
|
if (pref === 'auto') effective = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
if (effective === 'light') document.documentElement.setAttribute('data-theme', 'light');
|
|
})();
|
|
</script>
|
|
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
|
|
<script src="https://unpkg.com/htmx-ext-json-enc@2.0.3/json-enc.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
|
|
<style>
|
|
:root {
|
|
--bg-primary: #0f172a;
|
|
--bg-secondary: #1e293b;
|
|
--bg-tertiary: #334155;
|
|
--border-color: #334155;
|
|
--text-primary: #e2e8f0;
|
|
--text-secondary: #94a3b8;
|
|
--text-muted: #64748b;
|
|
--text-heading: #f8fafc;
|
|
--text-subheading: #cbd5e1;
|
|
--accent-blue: #3b82f6;
|
|
--accent-blue-hover: #2563eb;
|
|
--accent-blue-bg: #3b82f620;
|
|
--accent-green: #4ade80;
|
|
--accent-green-bg: #4ade8020;
|
|
--accent-red: #f87171;
|
|
--accent-red-bg: #7f1d1d40;
|
|
--accent-red-border: #991b1b;
|
|
--accent-red-text: #fca5a5;
|
|
--accent-yellow: #fbbf24;
|
|
--accent-yellow-bg: #92400e40;
|
|
--accent-purple: #a78bfa;
|
|
--accent-purple-bg: #a78bfa20;
|
|
--success-bg: #14532d40;
|
|
--success-border: #166534;
|
|
--success-text: #86efac;
|
|
--modal-overlay: #00000080;
|
|
--chart-grid: #1e293b;
|
|
}
|
|
[data-theme="light"] {
|
|
--bg-primary: #f8fafc;
|
|
--bg-secondary: #ffffff;
|
|
--bg-tertiary: #e2e8f0;
|
|
--border-color: #cbd5e1;
|
|
--text-primary: #1e293b;
|
|
--text-secondary: #475569;
|
|
--text-muted: #94a3b8;
|
|
--text-heading: #0f172a;
|
|
--text-subheading: #334155;
|
|
--accent-blue: #2563eb;
|
|
--accent-blue-hover: #1d4ed8;
|
|
--accent-blue-bg: #dbeafe;
|
|
--accent-green: #16a34a;
|
|
--accent-green-bg: #dcfce7;
|
|
--accent-red: #dc2626;
|
|
--accent-red-bg: #fef2f2;
|
|
--accent-red-border: #fca5a5;
|
|
--accent-red-text: #991b1b;
|
|
--accent-yellow: #d97706;
|
|
--accent-yellow-bg: #fef3c7;
|
|
--accent-purple: #7c3aed;
|
|
--accent-purple-bg: #ede9fe;
|
|
--success-bg: #f0fdf4;
|
|
--success-border: #86efac;
|
|
--success-text: #166534;
|
|
--modal-overlay: #00000040;
|
|
--chart-grid: #e2e8f0;
|
|
}
|
|
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg-primary); color: var(--text-primary); min-height: 100vh; display: flex; }
|
|
|
|
/* Sidebar */
|
|
.sidebar { width: 220px; background: var(--bg-secondary); border-right: 1px solid var(--border-color); min-height: 100vh; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; }
|
|
.sidebar-brand { padding: 20px 16px; font-size: 1.1rem; font-weight: 700; color: var(--text-heading); border-bottom: 1px solid var(--border-color); }
|
|
.sidebar-nav { flex: 1; padding: 12px 0; }
|
|
.sidebar-nav a { display: block; padding: 10px 20px; color: var(--text-secondary); text-decoration: none; font-size: 0.9rem; transition: all 0.15s; }
|
|
.sidebar-nav a:hover { background: var(--bg-tertiary); color: var(--text-primary); }
|
|
.sidebar-nav a.active { background: var(--accent-blue-bg); color: var(--accent-blue); border-right: 3px solid var(--accent-blue); }
|
|
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border-color); }
|
|
.sidebar-footer .user-info { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; }
|
|
.sidebar-footer a { display: block; padding: 6px 0; color: var(--text-secondary); text-decoration: none; font-size: 0.85rem; }
|
|
.sidebar-footer a:hover { color: var(--accent-red); }
|
|
.theme-toggle { cursor: pointer; background: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-secondary); padding: 6px 12px; border-radius: 6px; font-size: 0.8rem; width: 100%; margin-bottom: 8px; }
|
|
.theme-toggle:hover { color: var(--text-primary); }
|
|
|
|
/* Main content */
|
|
.main { flex: 1; margin-left: 220px; padding: 24px; min-height: 100vh; max-width: calc(100vw - 220px); overflow-x: hidden; }
|
|
|
|
/* Cards & tables */
|
|
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; max-width: 100%; }
|
|
.card { background: var(--bg-secondary); border-radius: 8px; padding: 16px; }
|
|
.card .label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
|
|
.card .value { font-size: 1.5rem; font-weight: 700; margin-top: 4px; }
|
|
.card .sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
|
|
.section { background: var(--bg-secondary); border-radius: 8px; padding: 16px; margin-bottom: 16px; overflow-x: auto; }
|
|
.section h2 { font-size: 1.1rem; margin-bottom: 12px; color: var(--text-subheading); }
|
|
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
|
|
.tabs button { background: var(--bg-secondary); border: 1px solid var(--border-color); color: var(--text-secondary); padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; }
|
|
.tabs button.active { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
|
|
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
|
|
th { text-align: left; padding: 8px; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); font-weight: 500; }
|
|
td { padding: 8px; border-bottom: 1px solid var(--border-color); }
|
|
.green { color: var(--accent-green); }
|
|
.red { color: var(--accent-red); }
|
|
.blue { color: var(--accent-blue); }
|
|
.yellow { color: var(--accent-yellow); }
|
|
|
|
/* Buttons */
|
|
.btn { display: inline-block; padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; font-size: 0.9rem; font-weight: 500; text-decoration: none; }
|
|
.btn-primary { background: var(--accent-blue); color: #fff; }
|
|
.btn-primary:hover { background: var(--accent-blue-hover); }
|
|
.btn-danger { background: #ef4444; color: #fff; }
|
|
.btn-danger:hover { background: #dc2626; }
|
|
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
|
|
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); }
|
|
.btn-outline:hover { border-color: var(--text-muted); color: var(--text-primary); }
|
|
|
|
/* Forms */
|
|
.form-group { margin-bottom: 16px; }
|
|
.form-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 4px; }
|
|
.form-group input, .form-group select { width: 100%; padding: 10px 12px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-primary); font-size: 0.95rem; }
|
|
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent-blue); }
|
|
.error-msg { background: var(--accent-red-bg); border: 1px solid var(--accent-red-border); color: var(--accent-red-text); padding: 10px; border-radius: 6px; margin-bottom: 16px; font-size: 0.85rem; }
|
|
.success-msg { background: var(--success-bg); border: 1px solid var(--success-border); color: var(--success-text); padding: 10px; border-radius: 6px; margin-bottom: 16px; font-size: 0.85rem; }
|
|
|
|
/* Modal */
|
|
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--modal-overlay); display: none; align-items: center; justify-content: center; z-index: 100; }
|
|
.modal-overlay.show { display: flex; }
|
|
.modal { background: var(--bg-secondary); border-radius: 12px; padding: 24px; width: 100%; max-width: 440px; }
|
|
.modal h2 { margin-bottom: 16px; color: var(--text-subheading); }
|
|
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
|
|
|
|
/* Token display */
|
|
.token-key { background: var(--bg-primary); padding: 8px 12px; border-radius: 6px; font-family: monospace; font-size: 0.85rem; word-break: break-all; margin: 8px 0; display: flex; align-items: center; gap: 8px; }
|
|
.token-key code { flex: 1; }
|
|
.copy-btn { background: var(--bg-tertiary); border: none; color: var(--text-secondary); padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 0.75rem; }
|
|
.copy-btn:hover { color: var(--text-primary); }
|
|
|
|
/* Badge */
|
|
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: 600; }
|
|
.badge-admin { background: var(--accent-blue-bg); color: var(--accent-blue); }
|
|
.badge-user { background: var(--accent-green-bg); color: var(--accent-green); }
|
|
.badge-totp { background: var(--accent-purple-bg); color: var(--accent-purple); }
|
|
.badge-healthy { background: var(--accent-green-bg); color: var(--accent-green); }
|
|
.badge-degraded { background: var(--accent-yellow-bg); color: var(--accent-yellow); }
|
|
.badge-down { background: var(--accent-red-bg); color: var(--accent-red); }
|
|
.badge-success { background: var(--accent-green-bg); color: var(--accent-green); }
|
|
.badge-error { background: var(--accent-red-bg); color: var(--accent-red); }
|
|
.badge-cached { background: var(--accent-blue-bg); color: var(--accent-blue); }
|
|
.badge-priority { background: var(--bg-tertiary); color: var(--text-secondary); }
|
|
.badge-open { background: var(--accent-red-bg); color: var(--accent-red); }
|
|
.badge-half-open { background: var(--accent-yellow-bg); color: var(--accent-yellow); }
|
|
|
|
/* Toggle switch */
|
|
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
|
|
.toggle-switch input { opacity: 0; width: 0; height: 0; }
|
|
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg-tertiary); border-radius: 24px; transition: 0.2s; }
|
|
.toggle-slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: var(--text-secondary); border-radius: 50%; transition: 0.2s; }
|
|
.toggle-switch input:checked + .toggle-slider { background: var(--accent-blue); }
|
|
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(20px); background: #fff; }
|
|
|
|
/* Code block for debug bodies */
|
|
.code-block { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 6px; padding: 12px; font-family: monospace; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow-y: auto; }
|
|
|
|
/* Export button inline */
|
|
.export-links { display: inline-flex; gap: 6px; margin-left: 12px; }
|
|
.export-links a { font-size: 0.7rem; color: var(--text-muted); text-decoration: none; padding: 2px 6px; border: 1px solid var(--border-color); border-radius: 4px; }
|
|
.export-links a:hover { color: var(--text-primary); border-color: var(--text-muted); }
|
|
|
|
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
|
|
.page-header h1 { font-size: 1.3rem; color: var(--text-heading); }
|
|
|
|
/* Filter bar */
|
|
.filter-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
|
|
.filter-bar select { padding: 6px 10px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-primary); font-size: 0.85rem; }
|
|
.filter-bar select:focus { outline: none; border-color: var(--accent-blue); }
|
|
|
|
/* Pagination */
|
|
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; justify-content: center; }
|
|
.pagination button, .pagination span { padding: 6px 12px; border-radius: 6px; font-size: 0.8rem; border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-secondary); cursor: pointer; }
|
|
.pagination button:hover { background: var(--bg-tertiary); color: var(--text-primary); }
|
|
.pagination button.active { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
|
|
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
.pagination .page-info { border: none; background: none; cursor: default; color: var(--text-muted); font-size: 0.8rem; }
|
|
|
|
/* Progress bar */
|
|
.progress-bar { width: 100%; height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
|
|
.progress-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
|
|
.budget-info { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
|
|
|
|
/* Expandable row */
|
|
.expandable { cursor: pointer; }
|
|
.expand-content { display: none; padding: 8px 12px; background: var(--bg-primary); border-radius: 6px; margin: 4px 0; font-size: 0.8rem; font-family: monospace; white-space: pre-wrap; word-break: break-all; }
|
|
.expand-content.show { display: block; }
|
|
|
|
/* Health status row */
|
|
.health-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
|
|
.health-item { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg-secondary); border-radius: 8px; }
|
|
.health-item .provider-name { font-weight: 600; font-size: 0.85rem; }
|
|
|
|
/* Mobile menu button */
|
|
.mobile-menu-btn { display: none; position: fixed; top: 12px; left: 12px; z-index: 300; background: var(--bg-secondary); border: 1px solid var(--border-color); color: var(--text-primary); width: 40px; height: 40px; border-radius: 8px; cursor: pointer; align-items: center; justify-content: center; }
|
|
.mobile-menu-btn svg { width: 20px; height: 20px; }
|
|
|
|
/* Sidebar overlay */
|
|
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--modal-overlay); z-index: 150; }
|
|
.sidebar-overlay.show { display: block; }
|
|
|
|
/* Responsive: tablet & mobile */
|
|
@media (max-width: 768px) {
|
|
.mobile-menu-btn { display: flex; }
|
|
.sidebar { left: -220px; z-index: 200; transition: left 0.25s ease; }
|
|
.sidebar.open { left: 0; }
|
|
.main { margin-left: 0; max-width: 100vw; padding: 60px 12px 12px; }
|
|
.cards { grid-template-columns: repeat(2, 1fr); }
|
|
.card .value { font-size: 1.2rem; }
|
|
table { min-width: 500px; font-size: 0.8rem; }
|
|
.modal { max-width: calc(100vw - 32px); padding: 20px; }
|
|
.filter-bar select { flex: 1; min-width: 120px; }
|
|
.page-header h1 { font-size: 1.1rem; }
|
|
}
|
|
|
|
/* Responsive: small phone */
|
|
@media (max-width: 480px) {
|
|
.cards { grid-template-columns: 1fr; }
|
|
.card .value { font-size: 1rem; }
|
|
.main { padding: 56px 8px 8px; }
|
|
.section { padding: 12px; }
|
|
.modal { padding: 16px; }
|
|
.page-header h1 { font-size: 1rem; }
|
|
table { font-size: 0.75rem; }
|
|
th, td { padding: 6px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
function getThemePref() { return localStorage.getItem('theme') || 'auto'; }
|
|
function applyTheme(pref) {
|
|
var effective = pref;
|
|
if (pref === 'auto') effective = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
if (effective === 'light') document.documentElement.setAttribute('data-theme', 'light');
|
|
else document.documentElement.removeAttribute('data-theme');
|
|
}
|
|
function themeLabel(pref) {
|
|
if (pref === 'light') return 'Light';
|
|
if (pref === 'dark') return 'Dark';
|
|
return 'Auto';
|
|
}
|
|
function toggleTheme() {
|
|
var order = ['dark', 'light', 'auto'];
|
|
var cur = getThemePref();
|
|
var next = order[(order.indexOf(cur) + 1) % order.length];
|
|
localStorage.setItem('theme', next);
|
|
applyTheme(next);
|
|
var btn = document.getElementById('theme-btn');
|
|
if (btn) btn.textContent = 'Theme: ' + themeLabel(next);
|
|
}
|
|
// Follow system changes when set to auto
|
|
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', function() {
|
|
if (getThemePref() === 'auto') applyTheme('auto');
|
|
});
|
|
</script>
|
|
<button class="mobile-menu-btn" onclick="toggleMobileSidebar()" aria-label="Menu">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
|
|
</button>
|
|
<div class="sidebar-overlay" onclick="toggleMobileSidebar()"></div>
|
|
<div class="sidebar">
|
|
<div class="sidebar-brand">LLM Gateway</div>
|
|
<nav class="sidebar-nav">
|
|
<a href="/dashboard" hx-get="/dashboard" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "dashboard"}}class="active"{{end}}>Dashboard</a>
|
|
<a href="/logs" hx-get="/logs" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "logs"}}class="active"{{end}}>Logs</a>
|
|
<a href="/models" hx-get="/models" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "models"}}class="active"{{end}}>Models</a>
|
|
<a href="/tokens" hx-get="/tokens" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "tokens"}}class="active"{{end}}>API Tokens</a>
|
|
{{if .User.IsAdmin}}
|
|
<a href="/users" hx-get="/users" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "users"}}class="active"{{end}}>Users</a>
|
|
<a href="/audit" hx-get="/audit" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "audit"}}class="active"{{end}}>Audit Log</a>
|
|
<a href="/debug" hx-get="/debug" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "debug"}}class="active"{{end}}>Debug</a>
|
|
{{end}}
|
|
<a href="/settings" hx-get="/settings" hx-target="#content" hx-push-url="true" {{if eq .ActivePage "settings"}}class="active"{{end}}>Settings</a>
|
|
</nav>
|
|
<div class="sidebar-footer">
|
|
<button class="theme-toggle" onclick="toggleTheme()" id="theme-btn">Switch Theme</button>
|
|
<div class="user-info">{{.User.Username}}</div>
|
|
<a href="#" hx-post="/api/auth/logout" hx-swap="none">Logout</a>
|
|
</div>
|
|
</div>
|
|
<div class="main">
|
|
<div id="sse-source" style="display:none;"></div>
|
|
<div id="content">
|
|
{{template "content" .}}
|
|
</div>
|
|
</div>
|
|
<script>
|
|
// SSE auto-refresh: reload current page content when server sends refresh event
|
|
(function() {
|
|
var refreshable = ['/dashboard', '/logs', '/models', '/debug', '/audit'];
|
|
var source = null;
|
|
var retryDelay = 1000;
|
|
|
|
function connect() {
|
|
if (source) { source.close(); source = null; }
|
|
source = new EventSource('/api/events');
|
|
source.addEventListener('refresh', function() {
|
|
var path = window.location.pathname;
|
|
for (var i = 0; i < refreshable.length; i++) {
|
|
if (path === refreshable[i]) {
|
|
htmx.ajax('GET', path + window.location.search, {target: '#content', swap: 'innerHTML'});
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
source.onopen = function() { retryDelay = 1000; };
|
|
source.onerror = function() {
|
|
source.close();
|
|
source = null;
|
|
setTimeout(connect, retryDelay);
|
|
retryDelay = Math.min(retryDelay * 2, 30000);
|
|
};
|
|
}
|
|
|
|
// Close cleanly on page unload to avoid browser "interrupted" errors
|
|
window.addEventListener('beforeunload', function() {
|
|
if (source) { source.close(); source = null; }
|
|
});
|
|
|
|
connect();
|
|
})();
|
|
// Update active sidebar link on HTMX navigation
|
|
document.body.addEventListener('htmx:pushedIntoHistory', function(e) {
|
|
document.querySelectorAll('.sidebar-nav a').forEach(function(a) {
|
|
a.classList.toggle('active', a.getAttribute('href') === window.location.pathname);
|
|
});
|
|
});
|
|
// Set initial theme button label
|
|
(function() {
|
|
var btn = document.getElementById('theme-btn');
|
|
if (btn) btn.textContent = 'Theme: ' + themeLabel(getThemePref());
|
|
})();
|
|
// Mobile sidebar toggle
|
|
function toggleMobileSidebar() {
|
|
document.querySelector('.sidebar').classList.toggle('open');
|
|
document.querySelector('.sidebar-overlay').classList.toggle('show');
|
|
}
|
|
// Close sidebar on nav link click (mobile)
|
|
document.querySelectorAll('.sidebar-nav a').forEach(function(a) {
|
|
a.addEventListener('click', function() {
|
|
document.querySelector('.sidebar').classList.remove('open');
|
|
document.querySelector('.sidebar-overlay').classList.remove('show');
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
{{end}}
|