feat: 2.0.0-alpha.11 — DB-backed service registry + LAN auto-discovery

- monitored_services table (mig 015) replaces config/services.json (now a boot seed)
- owner CRUD over /api/health/services; GET is DB-backed; cron+worker read the DB
- discover.lan worker: pure-Node TCP sweep + HTTP-title probe -> disabled 'discovered'
  candidates (never clobbers curated entries); POST /api/health/discover + GET .../discovered
- dashboard: Scan button + Discovered(N) section with one-click promote

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-04 07:55:08 +10:00
parent b728696020
commit ce26895d8e
17 changed files with 466 additions and 46 deletions

View File

@@ -4,7 +4,36 @@ import { littleblueAvatar } from '../components/littleblue_avatar.js';
import { serviceTile } from '../components/service_tile.js';
const TITLE = { agents: 'Agents', infrastructure: 'Infrastructure', media: 'Media', other: 'Other' };
let host, timer;
let host, timer, scanning = false;
async function promote(id) {
try { await api.patch('/api/health/services/' + id, { enabled: true }); load(); } catch { /* */ }
}
function scan() {
if (scanning) return;
scanning = true; load(); // reflect "Scanning…"
api.post('/api/health/discover', {}).catch(() => { /* */ });
setTimeout(() => { scanning = false; load(); }, 30000); // LAN sweep ~25s
}
// Owner-only; returns a section element or null (skipped for non-owner / none).
async function discoveredSection() {
let cand;
try { cand = await api.get('/api/health/services/discovered'); } catch { return null; }
if (!cand || !cand.length) return null;
return el('div', { class: 'lb-section' },
el('div', { class: 'lb-group' },
el('span', { class: 'gname' }, 'Discovered'),
el('span', { class: 'gcount' }, `${cand.length} new`),
el('span', { class: 'line' })),
el('div', { class: 'tiles' }, cand.map(c =>
el('div', { class: 'tile disc' },
el('div', { class: 'tile-main' },
el('div', { class: 'tile-nm' }, c.name),
el('div', { class: 'tile-host' }, c.url)),
el('button', { class: 'disc-add', title: 'Add to the band', onclick: () => promote(c.id) }, '+')))));
}
async function load() {
if (!host) return;
try {
@@ -16,11 +45,15 @@ async function load() {
el('span', { class: 'gcount' }, `${g.healthy}/${g.total} healthy`),
el('span', { class: 'line' })),
el('div', { class: 'tiles' }, g.services.map(serviceTile))));
const disc = await discoveredSection();
mount(host,
el('div', { class: 'lbwrap' }, littleblueAvatar(),
el('div', {}, el('div', { class: 'lb-name' }, 'Little Blue'),
el('div', { class: 'lb-sub' }, 'Health & Uptime of the lab'))),
sections);
el('div', { style: { flex: 1 } },
el('div', { class: 'lb-name' }, 'Little Blue'),
el('div', { class: 'lb-sub' }, 'Health & Uptime of the lab')),
el('button', { class: 'lb-scan', title: 'Scan the LAN for services', onclick: scan }, scanning ? 'Scanning…' : 'Scan')),
sections,
disc);
} catch { mount(host, el('span', { class: 'muted' }, 'Health band unavailable')); }
}
export function renderHealthBand(el_) { host = el_; load(); timer = setInterval(load, 60000); }