-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry-panel.js
More file actions
64 lines (57 loc) · 1.9 KB
/
Copy pathregistry-panel.js
File metadata and controls
64 lines (57 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
(function () {
function esc(s) {
return String(s)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
}
function section(title, count, emptyMessage, rowsHtml) {
const header = '<div class="registry-section-header">' +
esc(title) + ' (' + count + ')</div>';
const body = count === 0
? '<div class="registry-empty">' + esc(emptyMessage) + '</div>'
: rowsHtml;
return '<div class="registry-section">' + header + body + '</div>';
}
function permsLine(perms) {
if (!perms || perms.length === 0) return '<div class="registry-perms">(no permissions)</div>';
return '<div class="registry-perms">' + esc(perms.join(', ')) + '</div>';
}
function humanRow(h) {
return '<div class="registry-row">' +
'<span class="registry-id">' + esc(h.id) + '</span>' +
permsLine(h.permissions) +
'</div>';
}
function agentRow(a) {
const meta = a.created_by
? '<div class="registry-meta">authorized by ' + esc(a.created_by) + '</div>'
: '';
return '<div class="registry-row">' +
'<span class="registry-id">' + esc(a.id) + '</span>' +
meta +
permsLine(a.permissions) +
'</div>';
}
function renderRegistryHtml(snapshot, state) {
state = state || {};
let out = '';
if (state.error) {
out += '<div class="registry-error">' + esc(state.error) + '</div>';
}
if (snapshot) {
out += section('Humans', snapshot.humans.length, 'No humans registered',
snapshot.humans.map(humanRow).join(''));
out += section('Agents', snapshot.agents.length, 'No agents running',
snapshot.agents.map(agentRow).join(''));
}
return out;
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = { renderRegistryHtml };
} else {
globalThis.renderRegistryHtml = renderRegistryHtml;
}
})();