multica/apps/server/public/index.html
Naiyuan Qing 6ef58a0cab refactor: restructure to monorepo architecture
- Move core agent engine to packages/core/
- Add packages/types/ for shared TypeScript types
- Add packages/utils/ for utility functions
- Add apps/cli/ for command-line interface
- Add apps/gateway/ for NestJS WebSocket gateway
- Add apps/server/ for REST API server
- Restructure desktop app (electron/ → src/main/, src/preload/)
- Update pnpm workspace configuration
- Remove legacy src/ directory

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 18:00:23 +08:00

499 lines
14 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hub Console</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg: #0f172a;
--surface: #1e293b;
--surface-2: #334155;
--border: rgba(148,163,184,0.1);
--text: #f1f5f9;
--text-dim: #94a3b8;
--text-muted: #64748b;
--accent: #6366f1;
--accent-light: #818cf8;
--green: #34d399;
--yellow: #fbbf24;
--red: #f87171;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", Roboto, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
}
/* ── Header ── */
.header {
background: var(--surface);
border-bottom: 1px solid var(--border);
padding: 0 32px;
height: 56px;
display: flex;
align-items: center;
gap: 12px;
}
.header-logo {
width: 28px;
height: 28px;
border-radius: 7px;
}
.header h1 {
font-size: 1rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.header-subtitle {
font-size: 0.78rem;
color: var(--text-muted);
margin-left: 4px;
}
/* ── Container ── */
.container {
max-width: 960px;
margin: 0 auto;
padding: 28px 32px;
}
/* ── Stat cards ── */
.stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 14px;
margin-bottom: 24px;
}
.stat-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
padding: 16px 18px;
display: flex;
flex-direction: column;
gap: 6px;
}
.stat-label {
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--text-muted);
}
.stat-value {
font-size: 0.88rem;
font-weight: 600;
color: var(--text);
font-family: "SF Mono", "Fira Code", monospace;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: flex;
align-items: center;
gap: 6px;
}
.stat-value .copy-btn {
opacity: 0;
transition: opacity 0.15s;
}
.stat-card:hover .copy-btn {
opacity: 1;
}
/* ── State badge ── */
.state-badge {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 0.82rem;
font-weight: 600;
}
.state-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--text-muted);
}
.state-dot.registered {
background: var(--green);
box-shadow: 0 0 8px rgba(52,211,153,0.5);
}
.state-dot.connected {
background: var(--yellow);
}
.state-dot.disconnected {
background: var(--red);
}
/* ── Gateway form ── */
.gateway-section {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
padding: 18px 20px;
margin-bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
}
.gateway-section label {
font-size: 0.72rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--text-muted);
flex-shrink: 0;
}
.gateway-section input {
flex: 1;
background: var(--bg);
border: 1px solid rgba(148,163,184,0.12);
border-radius: 8px;
padding: 9px 12px;
color: var(--text);
font-size: 0.88rem;
font-family: "SF Mono", "Fira Code", monospace;
transition: border-color 0.2s;
}
.gateway-section input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
/* ── Buttons ── */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
border: none;
border-radius: 8px;
font-size: 0.82rem;
font-weight: 600;
font-family: inherit;
cursor: pointer;
padding: 8px 16px;
transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-accent {
background: linear-gradient(135deg, #6366f1, #8b5cf6);
color: white;
box-shadow: 0 2px 8px rgba(99,102,241,0.25);
}
.btn-accent:hover {
box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}
.btn-ghost {
background: transparent;
color: var(--text-dim);
padding: 6px 10px;
}
.btn-ghost:hover {
background: var(--surface-2);
color: var(--text);
}
.btn-danger-ghost {
background: transparent;
color: var(--text-muted);
padding: 6px 10px;
}
.btn-danger-ghost:hover {
background: rgba(248,113,113,0.1);
color: var(--red);
}
/* ── Copy button ── */
.copy-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
border-radius: 6px;
border: none;
background: transparent;
color: var(--text-muted);
cursor: pointer;
flex-shrink: 0;
transition: background 0.15s, color 0.15s;
}
.copy-btn:hover {
background: var(--surface-2);
color: var(--text);
}
.copy-btn.copied {
color: var(--green);
}
/* ── Agents section ── */
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.section-title {
font-size: 0.72rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--text-muted);
}
.agent-table {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
}
.agent-table-head {
display: grid;
grid-template-columns: 1fr auto;
padding: 10px 20px;
border-bottom: 1px solid var(--border);
font-size: 0.68rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--text-muted);
}
.agent-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
padding: 12px 20px;
border-bottom: 1px solid var(--border);
transition: background 0.1s;
}
.agent-row:last-child { border-bottom: none; }
.agent-row:hover { background: rgba(148,163,184,0.04); }
.agent-id {
font-family: "SF Mono", "Fira Code", monospace;
font-size: 0.85rem;
color: var(--text-dim);
display: flex;
align-items: center;
gap: 6px;
}
.agent-id .copy-btn { opacity: 0; transition: opacity 0.15s; }
.agent-row:hover .copy-btn { opacity: 1; }
.agent-actions {
display: flex;
align-items: center;
gap: 4px;
}
.agent-actions .btn-danger-ghost { opacity: 0; transition: opacity 0.15s; }
.agent-row:hover .btn-danger-ghost { opacity: 1; }
.empty-state {
padding: 40px 20px;
text-align: center;
color: var(--text-muted);
font-size: 0.85rem;
}
/* ── Toast ── */
.toast {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%) translateY(80px);
background: var(--surface-2);
color: var(--text);
padding: 8px 16px;
border-radius: 8px;
font-size: 0.82rem;
font-weight: 500;
box-shadow: 0 4px 16px rgba(0,0,0,0.3);
opacity: 0;
transition: transform 0.3s ease, opacity 0.3s ease;
pointer-events: none;
z-index: 100;
}
.toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
</style>
</head>
<body>
<!-- Header -->
<div class="header">
<h1>Hub Console</h1>
<span class="header-subtitle">Multica</span>
</div>
<div class="container">
<!-- Stats -->
<div class="stats" id="stats">
<div class="stat-card">
<div class="stat-label">Hub ID</div>
<div class="stat-value" id="stat-device"></div>
</div>
<div class="stat-card">
<div class="stat-label">Gateway</div>
<div class="stat-value" id="stat-gateway"></div>
</div>
<div class="stat-card">
<div class="stat-label">State</div>
<div class="stat-value" id="stat-state"></div>
</div>
<div class="stat-card">
<div class="stat-label">Agents</div>
<div class="stat-value" id="stat-agents"></div>
</div>
</div>
<!-- Gateway URL -->
<div class="gateway-section">
<label>Gateway URL</label>
<input type="text" id="gateway-url" placeholder="https://gateway.example.com">
<button class="btn btn-accent" onclick="updateGateway()">Connect</button>
</div>
<!-- Agents -->
<div class="section-header">
<span class="section-title">Agents</span>
<button class="btn btn-accent" onclick="createAgent()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
Create Agent
</button>
</div>
<div class="agent-table" id="agent-table">
<div class="agent-table-head">
<span>Agent ID</span>
<span>Actions</span>
</div>
<div id="agent-list"></div>
</div>
</div>
<!-- Toast -->
<div class="toast" id="toast"></div>
<script>
const API = '/api';
function copyIcon() {
return '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>';
}
function checkIcon() {
return '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>';
}
function trashIcon() {
return '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/></svg>';
}
function showToast(msg) {
const el = document.getElementById('toast');
el.textContent = msg;
el.classList.add('show');
setTimeout(() => el.classList.remove('show'), 2000);
}
function copyText(text, btnEl) {
navigator.clipboard.writeText(text).then(() => {
btnEl.innerHTML = checkIcon();
btnEl.classList.add('copied');
showToast('Copied to clipboard');
setTimeout(() => {
btnEl.innerHTML = copyIcon();
btnEl.classList.remove('copied');
}, 1500);
});
}
function truncateId(id) {
if (!id || id.length <= 12) return id || '—';
return id.slice(0, 8) + '...' + id.slice(-4);
}
async function refresh() {
const [hubRes, agentsRes] = await Promise.all([
fetch(`${API}/hub`).then(r => r.json()),
fetch(`${API}/agents`).then(r => r.json()),
]);
// Stats
const deviceId = hubRes.hubId || '—';
document.getElementById('stat-device').innerHTML =
`<span title="${deviceId}">${truncateId(deviceId)}</span>` +
(deviceId !== '—' ? `<button class="copy-btn" onclick="copyText('${deviceId}', this)">${copyIcon()}</button>` : '');
document.getElementById('stat-gateway').innerHTML =
`<span title="${hubRes.url || ''}" style="overflow:hidden;text-overflow:ellipsis">${hubRes.url || '—'}</span>`;
const state = hubRes.connectionState || 'disconnected';
const stateLabel = state.charAt(0).toUpperCase() + state.slice(1);
document.getElementById('stat-state').innerHTML =
`<span class="state-badge"><span class="state-dot ${state}"></span>${stateLabel}</span>`;
document.getElementById('stat-agents').textContent = hubRes.agentCount ?? 0;
// Gateway input
const input = document.getElementById('gateway-url');
if (!input.dataset.edited) {
input.value = hubRes.url || '';
}
// Agent list
const list = document.getElementById('agent-list');
if (agentsRes.length === 0) {
list.innerHTML = '<div class="empty-state">No agents yet. Create one to get started.</div>';
} else {
list.innerHTML = agentsRes.map(a =>
`<div class="agent-row">` +
`<div class="agent-id">` +
`<span title="${a.id}">${a.id}</span>` +
`<button class="copy-btn" onclick="copyText('${a.id}', this)">${copyIcon()}</button>` +
`</div>` +
`<div class="agent-actions">` +
`<button class="btn-danger-ghost btn" onclick="deleteAgent('${a.id}')" title="Delete">${trashIcon()}</button>` +
`</div>` +
`</div>`
).join('');
}
}
document.getElementById('gateway-url').addEventListener('input', function() {
this.dataset.edited = '1';
});
async function updateGateway() {
const input = document.getElementById('gateway-url');
const url = input.value.trim();
if (!url) return;
await fetch(`${API}/hub/gateway`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url }),
});
input.dataset.edited = '';
refresh();
}
async function createAgent() {
await fetch(`${API}/agents`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
refresh();
}
async function deleteAgent(id) {
await fetch(`${API}/agents/${id}`, { method: 'DELETE' });
refresh();
}
refresh();
setInterval(refresh, 3000);
</script>
</body>
</html>