feat(ui): add browser console served by the daemon
Introduce a minimal operations console reachable on a dedicated UI port (default 8081), kept separate from the OpenAI-compatible API port. - ts_web/ holds the SPA shell (index.html, app.css, vanilla app.js) with sidebar navigation for all views from readme.ui.md and a working Overview page backed by a new /_ui/overview JSON endpoint. - scripts/bundle-ui.ts walks ts_web/ and emits ts_bundled/bundle.ts, a single generated module exporting every asset as base64. Mirrors the @stack.gallery/registry pattern so deno compile binaries embed the entire UI with no external filesystem dependency at runtime. - ts/ui/server.ts (UiServer) serves assets from either the bundled map (default, prod) or directly from ts_web/ on disk (dev). The source is chosen per-config and can be overridden by UI_ASSET_SOURCE=disk|bundle. SPA fallback routes unknown extensionless paths to index.html. - IModelGridConfig.ui block with enabled/port/host/assetSource defaults; config init writes the block, the normalizer fills in defaults on load, and the daemon starts/stops the UI server alongside the API. - deno.json gains a bundle:ui task; compile:all now depends on it so released binaries always contain an up-to-date bundle. dev task sets UI_ASSET_SOURCE=disk for hot edits. - ts_bundled/ is gitignored (generated on build). - test/ui-server.smoke.ts exercises bundle and disk modes end to end (index, app.js, SPA fallback, /_ui/overview, 404).
This commit is contained in:
+187
@@ -0,0 +1,187 @@
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #000;
|
||||
--bg-1: #0b0b0d;
|
||||
--bg-2: #14141a;
|
||||
--fg: #e6e6ea;
|
||||
--fg-dim: #8a8a92;
|
||||
--border: #23232b;
|
||||
--accent: #4357d9;
|
||||
--ok: #2ecc71;
|
||||
--warn: #f1c40f;
|
||||
--err: #e74c3c;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
body {
|
||||
display: grid;
|
||||
grid-template-columns: 220px 1fr;
|
||||
}
|
||||
|
||||
a { color: inherit; text-decoration: none; }
|
||||
|
||||
.dim { color: var(--fg-dim); }
|
||||
|
||||
.nav {
|
||||
background: var(--bg-1);
|
||||
border-right: 1px solid var(--border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.nav-brand {
|
||||
padding: 20px 16px 12px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.nav-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 8px 0;
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.nav-items a {
|
||||
padding: 8px 16px;
|
||||
color: var(--fg-dim);
|
||||
border-left: 2px solid transparent;
|
||||
transition: color 0.1s, background 0.1s, border-color 0.1s;
|
||||
}
|
||||
|
||||
.nav-items a:hover {
|
||||
color: var(--fg);
|
||||
background: var(--bg-2);
|
||||
}
|
||||
|
||||
.nav-items a.active {
|
||||
color: var(--fg);
|
||||
background: var(--bg-2);
|
||||
border-left-color: var(--accent);
|
||||
}
|
||||
|
||||
.nav-footer {
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 24px 32px;
|
||||
overflow-y: auto;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 20px;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--bg-1);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.card-label {
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--fg-dim);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-value {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.card-sub {
|
||||
font-size: 12px;
|
||||
color: var(--fg-dim);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.status-dot.ok { background: var(--ok); }
|
||||
.status-dot.warn{ background: var(--warn); }
|
||||
.status-dot.err { background: var(--err); }
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: var(--bg-1);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
th, td {
|
||||
text-align: left;
|
||||
padding: 10px 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
th {
|
||||
color: var(--fg-dim);
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
background: var(--bg-2);
|
||||
}
|
||||
|
||||
tr:last-child td { border-bottom: none; }
|
||||
|
||||
.placeholder {
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
color: var(--fg-dim);
|
||||
background: var(--bg-1);
|
||||
border: 1px dashed var(--border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: var(--bg-1);
|
||||
border: 1px solid var(--err);
|
||||
color: var(--err);
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
// ModelGrid UI — vanilla client. Bundled into ts_bundled/bundle.ts for
|
||||
// the single-binary build, or served from disk in dev mode.
|
||||
|
||||
const VIEWS = [
|
||||
'overview',
|
||||
'cluster',
|
||||
'gpus',
|
||||
'deployments',
|
||||
'models',
|
||||
'access',
|
||||
'logs',
|
||||
'metrics',
|
||||
'settings',
|
||||
];
|
||||
|
||||
const view = document.getElementById('view');
|
||||
const nodeIdent = document.getElementById('node-ident');
|
||||
const nodeVersion = document.getElementById('node-version');
|
||||
|
||||
function parseHash() {
|
||||
const raw = location.hash.replace(/^#\/?/, '');
|
||||
const [top = 'overview'] = raw.split('/').filter(Boolean);
|
||||
return VIEWS.includes(top) ? top : 'overview';
|
||||
}
|
||||
|
||||
function setActive(current) {
|
||||
document.querySelectorAll('.nav-items a').forEach((el) => {
|
||||
el.classList.toggle('active', el.dataset.view === current);
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchHealth() {
|
||||
const res = await fetch('/_ui/overview', { headers: { accept: 'application/json' } });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function statusDot(status) {
|
||||
const ok = status === 'ok';
|
||||
const warn = status === 'degraded';
|
||||
const cls = ok ? 'ok' : warn ? 'warn' : 'err';
|
||||
return `<span class="status-dot ${cls}"></span>`;
|
||||
}
|
||||
|
||||
async function renderOverview() {
|
||||
view.innerHTML = `<h1>Overview</h1><div id="ovstate" class="placeholder">Loading…</div>`;
|
||||
try {
|
||||
const data = await fetchHealth();
|
||||
const health = data.health;
|
||||
const containers = health.containers || 0;
|
||||
const models = health.models || 0;
|
||||
const gpus = health.gpus || 0;
|
||||
const uptime = health.uptime || 0;
|
||||
const detailEntries = Object.entries(health.details?.containers || {});
|
||||
const runningContainers = detailEntries.filter(([, v]) => v === 'healthy').length;
|
||||
|
||||
view.innerHTML = `
|
||||
<h1>Overview</h1>
|
||||
<div class="cards">
|
||||
<div class="card">
|
||||
<div class="card-label">Fleet</div>
|
||||
<div class="card-value">${statusDot(health.status)}${health.status}</div>
|
||||
<div class="card-sub">v${health.version} · up ${formatUptime(uptime)}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-label">Deployments</div>
|
||||
<div class="card-value">${runningContainers} / ${containers}</div>
|
||||
<div class="card-sub">${containers === 0 ? 'no deployments' : `${runningContainers} healthy`}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-label">GPUs</div>
|
||||
<div class="card-value">${gpus}</div>
|
||||
<div class="card-sub">${gpus === 0 ? 'no GPU detected' : 'detected'}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-label">Models</div>
|
||||
<div class="card-value">${models}</div>
|
||||
<div class="card-sub">served via OpenAI API</div>
|
||||
</div>
|
||||
</div>
|
||||
<h1 style="margin-top:24px">Deployments</h1>
|
||||
${renderContainerTable(detailEntries)}
|
||||
`;
|
||||
if (data.node) {
|
||||
nodeIdent.textContent = `${data.node.name} · ${data.node.role}`;
|
||||
nodeVersion.textContent = `v${data.node.version}`;
|
||||
}
|
||||
} catch (err) {
|
||||
view.innerHTML = `<h1>Overview</h1><div class="error">Failed to load: ${escapeHtml(String(err.message || err))}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderContainerTable(entries) {
|
||||
if (entries.length === 0) {
|
||||
return `<div class="placeholder">No deployments configured. Add one with <code>modelgrid run <model></code>.</div>`;
|
||||
}
|
||||
const rows = entries.map(([id, state]) => `
|
||||
<tr>
|
||||
<td>${escapeHtml(id)}</td>
|
||||
<td>${statusDot(state === 'healthy' ? 'ok' : 'err')}${escapeHtml(state)}</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
return `<table><thead><tr><th>Container</th><th>Health</th></tr></thead><tbody>${rows}</tbody></table>`;
|
||||
}
|
||||
|
||||
function renderPlaceholder(name) {
|
||||
view.innerHTML = `
|
||||
<h1>${name}</h1>
|
||||
<div class="placeholder">
|
||||
This view is part of the UI concept (see <code>readme.ui.md</code>) but is not implemented yet.
|
||||
Use the CLI for now: <code>modelgrid ${cliHint(name)}</code>.
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function cliHint(view) {
|
||||
const map = {
|
||||
Cluster: 'cluster status',
|
||||
GPUs: 'gpu list',
|
||||
Deployments: 'ps',
|
||||
Models: 'model list',
|
||||
Access: 'config apikey list',
|
||||
Logs: 'service logs',
|
||||
Metrics: 'service status',
|
||||
Settings: 'config show',
|
||||
};
|
||||
return map[view] || '--help';
|
||||
}
|
||||
|
||||
function formatUptime(s) {
|
||||
if (s < 60) return `${s}s`;
|
||||
if (s < 3600) return `${Math.floor(s / 60)}m`;
|
||||
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
||||
return `${Math.floor(s / 86400)}d`;
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return s.replace(/[&<>"']/g, (c) => ({
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
||||
}[c]));
|
||||
}
|
||||
|
||||
function route() {
|
||||
const current = parseHash();
|
||||
setActive(current);
|
||||
switch (current) {
|
||||
case 'overview': return renderOverview();
|
||||
case 'cluster': return renderPlaceholder('Cluster');
|
||||
case 'gpus': return renderPlaceholder('GPUs');
|
||||
case 'deployments': return renderPlaceholder('Deployments');
|
||||
case 'models': return renderPlaceholder('Models');
|
||||
case 'access': return renderPlaceholder('Access');
|
||||
case 'logs': return renderPlaceholder('Logs');
|
||||
case 'metrics': return renderPlaceholder('Metrics');
|
||||
case 'settings': return renderPlaceholder('Settings');
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', route);
|
||||
if (!location.hash) location.hash = '#/overview';
|
||||
route();
|
||||
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#000000">
|
||||
<title>ModelGrid</title>
|
||||
<link rel="stylesheet" href="/app.css">
|
||||
</head>
|
||||
<body>
|
||||
<aside class="nav">
|
||||
<div class="nav-brand">ModelGrid</div>
|
||||
<nav class="nav-items">
|
||||
<a href="#/overview" data-view="overview">Overview</a>
|
||||
<a href="#/cluster" data-view="cluster">Cluster</a>
|
||||
<a href="#/gpus" data-view="gpus">GPUs</a>
|
||||
<a href="#/deployments" data-view="deployments">Deployments</a>
|
||||
<a href="#/models" data-view="models">Models</a>
|
||||
<a href="#/access" data-view="access">Access</a>
|
||||
<a href="#/logs" data-view="logs">Logs</a>
|
||||
<a href="#/metrics" data-view="metrics">Metrics</a>
|
||||
<a href="#/settings" data-view="settings">Settings</a>
|
||||
</nav>
|
||||
<div class="nav-footer">
|
||||
<div id="node-ident">—</div>
|
||||
<div id="node-version" class="dim">—</div>
|
||||
</div>
|
||||
</aside>
|
||||
<main id="view"></main>
|
||||
<script src="/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user