Allow changing the gateway connection URL at runtime via a new PUT /hub/gateway endpoint and a corresponding input form in the console UI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
4.5 KiB
HTML
112 lines
4.5 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; }
|
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace; background: #0a0a0a; color: #e0e0e0; padding: 2rem; }
|
|
h1 { font-size: 1.4rem; margin-bottom: 1.5rem; color: #fff; }
|
|
h2 { font-size: 1rem; margin-bottom: 0.8rem; color: #999; text-transform: uppercase; letter-spacing: 0.05em; }
|
|
.card { background: #161616; border: 1px solid #2a2a2a; border-radius: 8px; padding: 1.2rem; margin-bottom: 1.2rem; }
|
|
.hub-info span { display: inline-block; margin-right: 2rem; color: #888; }
|
|
.hub-info span b { color: #e0e0e0; }
|
|
.agent-list { list-style: none; }
|
|
.agent-list li { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid #222; font-family: monospace; font-size: 0.85rem; }
|
|
.agent-list li:last-child { border-bottom: none; }
|
|
.gateway-form { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.8rem; }
|
|
.gateway-form input { background: #0a0a0a; color: #e0e0e0; border: 1px solid #444; border-radius: 4px; padding: 0.4rem 0.6rem; font-size: 0.85rem; font-family: monospace; flex: 1; }
|
|
.gateway-form input:focus { outline: none; border-color: #666; }
|
|
button { background: #2a2a2a; color: #e0e0e0; border: 1px solid #444; border-radius: 4px; padding: 0.4rem 0.8rem; cursor: pointer; font-size: 0.8rem; }
|
|
button:hover { background: #3a3a3a; }
|
|
.btn-create { background: #1a3a1a; border-color: #2a5a2a; }
|
|
.btn-create:hover { background: #2a4a2a; }
|
|
.btn-delete { background: #3a1a1a; border-color: #5a2a2a; }
|
|
.btn-delete:hover { background: #4a2a2a; }
|
|
.empty { color: #555; font-style: italic; font-size: 0.85rem; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Hub Console</h1>
|
|
|
|
<div class="card">
|
|
<h2>Hub Status</h2>
|
|
<div class="hub-info" id="hub-info">Loading...</div>
|
|
<div class="gateway-form">
|
|
<input type="text" id="gateway-url" placeholder="Gateway URL">
|
|
<button class="btn-create" onclick="updateGateway()">Connect</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>Agents</h2>
|
|
<div style="margin-bottom: 0.8rem;">
|
|
<button class="btn-create" onclick="createAgent()">+ Create Agent</button>
|
|
</div>
|
|
<ul class="agent-list" id="agent-list"></ul>
|
|
</div>
|
|
|
|
<script>
|
|
const API = '/api';
|
|
|
|
async function refresh() {
|
|
const [hubRes, agentsRes] = await Promise.all([
|
|
fetch(`${API}/hub`).then(r => r.json()),
|
|
fetch(`${API}/agents`).then(r => r.json()),
|
|
]);
|
|
|
|
const stateColor = hubRes.connectionState === 'registered' ? '#4a4' : hubRes.connectionState === 'connected' ? '#aa4' : '#a44';
|
|
document.getElementById('hub-info').innerHTML =
|
|
`<span>Device: <b>${hubRes.deviceId}</b></span>` +
|
|
`<span>Gateway: <b>${hubRes.url}</b></span>` +
|
|
`<span>State: <b style="color:${stateColor}">${hubRes.connectionState}</b></span>` +
|
|
`<span>Agents: <b>${hubRes.agentCount}</b></span>`;
|
|
|
|
const input = document.getElementById('gateway-url');
|
|
if (!input.dataset.edited) {
|
|
input.value = hubRes.url;
|
|
}
|
|
|
|
const list = document.getElementById('agent-list');
|
|
if (agentsRes.length === 0) {
|
|
list.innerHTML = '<li class="empty">No agents</li>';
|
|
} else {
|
|
list.innerHTML = agentsRes.map(a =>
|
|
`<li><span>${a.id}</span><button class="btn-delete" onclick="deleteAgent('${a.id}')">Delete</button></li>`
|
|
).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>
|