Schema migrations: - users.is_admin boolean - users.password_hash text (scrypt N=16384, 16-byte salt) - users.last_login_at timestamp - organizations.suspended + suspended_reason - admin_settings table (DB-stored prompt override + future settings) Auth (@bmm/auth): - hashPassword + verifyPassword via node:crypto scrypt (no extra dep) - loginWithPassword: scrypt-verifies, issues 30-day session, updates last_login_at - seedAdmin: idempotent upsert keyed on email; creates org + membership on first run - AuthedUser now carries isAdmin flag API: - POST /v1/auth/admin/login (email + password) — 300ms throttle on failure - requireAdmin preHandler — 401 if no session, 403 if non-admin - Bootstrap: api on boot calls seedAdmin(ADMIN_EMAIL, ADMIN_PASSWORD, ADMIN_NAME) if env present. Idempotent. Admin API routes (all gated by requireAdmin): - GET /v1/admin/overview (totals, trends 7d, server-status breakdown, builds 24h, recent activity) - GET /v1/admin/users (search, per-row org + plan + serverCount) - PATCH /v1/admin/users/:id (isAdmin, name) - DELETE /v1/admin/users/:id (self-delete blocked) - GET /v1/admin/orgs (member + server counts) - PATCH /v1/admin/orgs/:id (plan, quota, suspended; cascades to mcp_servers.status=paused on suspend) - GET /v1/admin/servers (cross-org with status filter) - POST /v1/admin/servers/:id/rebuild (re-queues build using last prompt) - DELETE /v1/admin/servers/:id - GET /v1/admin/builds (status filter, error messages, prompt previews) - GET /v1/admin/builds/:id/logs - GET /v1/admin/audit (system-wide with user email join) - GET /v1/admin/system (DB ping, Redis ping, BullMQ queue depth, docker ps count) - GET /v1/admin/prompt (builtin + override + updatedAt) - PATCH /v1/admin/prompt (value: string | null) — saves DB override or drops it UI (apps/web/app/admin/*): - /admin/login — password form, separate from /login magic-link - AdminLayout — Linear-style sidebar (8 nav items), bottom panel with user email + 'user view' shortcut + logout, client-side requireAdmin guard with redirect - /admin — overview dashboard with 4 metric cards, 2 panels (status + 24h builds), recent activity table linking to full audit - /admin/users — search + admin toggle + delete (self-delete blocked) - /admin/orgs — plan/quota/suspend actions via prompts - /admin/servers — cross-org table with rebuild + delete actions, status filter - /admin/builds — every build cross-fleet with error vs prompt preview - /admin/audit — system-wide log + CSV export + filter dropdowns - /admin/system — auto-refreshing 5s health probes for Postgres, Redis, queue, Docker - /admin/prompt — live editor for the LLM system prompt with built-in baseline, override-state badge, drop-override action, diff preview, save-as-override End-to-end verified: login as marco.frangiskatos@gmail.com + Melusa112233.*, every admin page returns 200, admin login + overview tested via screenshot, docker probe returns true count of running MCP containers.
125 lines
3.7 KiB
TypeScript
125 lines
3.7 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import { apiFetch } from '@/lib/api';
|
|
import { cn } from '@/lib/cn';
|
|
|
|
interface SystemHealth {
|
|
probedAtMs: number;
|
|
db: { ok: boolean; latencyMs: number | null };
|
|
redis: { ok: boolean; latencyMs: number | null; queueDepth: number | null };
|
|
docker: { containerCount: number | null };
|
|
}
|
|
|
|
export default function AdminSystemPage() {
|
|
const [health, setHealth] = useState<SystemHealth | null>(null);
|
|
|
|
useEffect(() => {
|
|
apiFetch<SystemHealth>('/v1/admin/system').then(setHealth);
|
|
const t = setInterval(() => apiFetch<SystemHealth>('/v1/admin/system').then(setHealth), 5000);
|
|
return () => clearInterval(t);
|
|
}, []);
|
|
|
|
return (
|
|
<div className="px-8 py-8">
|
|
<header className="mb-6">
|
|
<h1 className="text-[22px] font-semibold tracking-tight">System health</h1>
|
|
<p className="mt-1 text-[13px] text-[--color-fg-muted]">
|
|
Live probes — Postgres, Redis, BullMQ queue depth, Docker container count. Refreshes
|
|
every 5 seconds.
|
|
</p>
|
|
</header>
|
|
|
|
{!health && (
|
|
<p className="mono text-[12px] text-[--color-fg-muted]">Probing…</p>
|
|
)}
|
|
|
|
{health && (
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
<ServiceCard
|
|
title="Postgres"
|
|
ok={health.db.ok}
|
|
primary={
|
|
health.db.latencyMs !== null ? `${health.db.latencyMs}ms` : '—'
|
|
}
|
|
sub="DATABASE_URL · primary store"
|
|
/>
|
|
<ServiceCard
|
|
title="Redis"
|
|
ok={health.redis.ok}
|
|
primary={
|
|
health.redis.latencyMs !== null ? `${health.redis.latencyMs}ms` : '—'
|
|
}
|
|
sub="REDIS_URL · BullMQ + pubsub + preview cache"
|
|
/>
|
|
<ServiceCard
|
|
title="Build queue"
|
|
ok={health.redis.queueDepth !== null}
|
|
primary={
|
|
health.redis.queueDepth === null
|
|
? '—'
|
|
: `${health.redis.queueDepth} pending`
|
|
}
|
|
sub="waiting + active + delayed jobs"
|
|
/>
|
|
<ServiceCard
|
|
title="Docker containers"
|
|
ok={health.docker.containerCount !== null}
|
|
primary={
|
|
health.docker.containerCount === null
|
|
? '—'
|
|
: `${health.docker.containerCount} running`
|
|
}
|
|
sub="bmm-mcp-* matching containers"
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
{health && (
|
|
<p className="mt-6 mono text-[10.5px] text-[--color-fg-subtle]">
|
|
probed in {health.probedAtMs}ms
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ServiceCard({
|
|
title,
|
|
ok,
|
|
primary,
|
|
sub,
|
|
}: {
|
|
title: string;
|
|
ok: boolean;
|
|
primary: string;
|
|
sub: string;
|
|
}) {
|
|
return (
|
|
<div className="panel p-4">
|
|
<div className="flex items-baseline justify-between">
|
|
<div className="text-[11px] uppercase tracking-wider text-[--color-fg-subtle]">{title}</div>
|
|
<span
|
|
className={cn(
|
|
'inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[10.5px] font-medium',
|
|
ok
|
|
? 'border-emerald-400/40 bg-emerald-400/10 text-emerald-300'
|
|
: 'border-red-400/40 bg-red-400/10 text-red-300',
|
|
)}
|
|
>
|
|
<span
|
|
className={cn(
|
|
'size-1.5 rounded-full',
|
|
ok ? 'bg-emerald-400' : 'bg-red-400',
|
|
)}
|
|
style={ok ? { animation: 'pulse-dot 1.6s ease-in-out infinite' } : undefined}
|
|
/>
|
|
{ok ? 'ok' : 'down'}
|
|
</span>
|
|
</div>
|
|
<div className="mt-2 mono text-[22px] font-semibold tabular-nums">{primary}</div>
|
|
<div className="mt-1 text-[12px] text-[--color-fg-muted]">{sub}</div>
|
|
</div>
|
|
);
|
|
}
|