@agent-custody/receipts 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,342 @@
1
+ // The console's one page. The data it shows is written into the document with textContent only, never as markup, and the
2
+ // content-security-policy allows exactly this script and this style by hash, so a value that reaches the page cannot run.
3
+ import { createHash } from "node:crypto";
4
+ const STYLE = String.raw `
5
+ :root { --bg: #fafaf9; --panel: #ffffff; --ink: #1c1917; --muted: #78716c; --line: #e7e5e4; --accent: #b45309; --accent-ink: #ffffff; --ok: #15803d; --warn: #b45309; --bad: #b91c1c; --code: #f5f5f4; color-scheme: light dark; }
6
+ @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #1c1917; --panel: #292524; --ink: #fafaf9; --muted: #a8a29e; --line: #44403c; --accent: #f59e0b; --accent-ink: #1c1917; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --code: #1c1917; } }
7
+ :root[data-theme="dark"] { --bg: #1c1917; --panel: #292524; --ink: #fafaf9; --muted: #a8a29e; --line: #44403c; --accent: #f59e0b; --accent-ink: #1c1917; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --code: #1c1917; }
8
+ * { box-sizing: border-box; }
9
+ body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
10
+ header { display: flex; align-items: center; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
11
+ header h1 { font-size: 15px; margin: 0; font-weight: 650; }
12
+ nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
13
+ nav button { background: none; border: 0; padding: 6px 12px; border-radius: 6px; color: var(--muted); cursor: pointer; font: inherit; }
14
+ nav button[aria-current="page"] { background: var(--code); color: var(--ink); font-weight: 600; }
15
+ main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
16
+ h2 { font-size: 18px; margin: 0 0 12px; }
17
+ h3 { font-size: 14px; margin: 0 0 8px; }
18
+ .card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
19
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
20
+ .grid .card { margin: 0; }
21
+ table { width: 100%; border-collapse: collapse; }
22
+ th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
23
+ th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; overflow-wrap: normal; }
24
+ table.kv th { width: 9em; white-space: nowrap; overflow-wrap: normal; }
25
+ tr.click { cursor: pointer; } tr.click:hover { background: var(--code); }
26
+ code, pre, textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
27
+ pre { background: var(--code); padding: 10px; border-radius: 6px; overflow: auto; max-height: 420px; margin: 8px 0 0; }
28
+ textarea { width: 100%; min-height: 280px; background: var(--code); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 10px; resize: vertical; }
29
+ input[type=password], input[type=text], select { background: var(--code); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font: inherit; }
30
+ button.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; }
31
+ button.secondary { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; font: inherit; cursor: pointer; }
32
+ button.danger { background: var(--bad); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; }
33
+ button:disabled { opacity: .5; cursor: default; }
34
+ .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
35
+ .muted { color: var(--muted); }
36
+ .ok { color: var(--ok); } .warn { color: var(--warn); } .error, .bad { color: var(--bad); }
37
+ .pill { display: inline-block; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; }
38
+ .banner { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--panel); border-radius: 6px; padding: 10px 14px; margin-bottom: 16px; }
39
+ .banner.bad { border-left-color: var(--bad); }
40
+ .finding { display: grid; grid-template-columns: 56px 130px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
41
+ #login { max-width: 420px; margin: 96px auto; }
42
+ [hidden] { display: none !important; }
43
+ .mt { margin-top: 16px; }
44
+ textarea.short { min-height: 140px; }
45
+ @media (max-width: 600px) { .finding { grid-template-columns: 56px 1fr; } .finding .check { display: none; } }
46
+ `;
47
+ const SCRIPT = String.raw `
48
+ (function () {
49
+ 'use strict';
50
+ var KEY = 'agent-custody-console-token';
51
+ var THEME = 'agent-custody-theme';
52
+ try { var t = localStorage.getItem(THEME); if (t) document.documentElement.setAttribute('data-theme', t); } catch (e) {}
53
+ var token = '';
54
+ try { token = sessionStorage.getItem(KEY) || ''; } catch (e) {}
55
+ var view = document.getElementById('view');
56
+ var tabs = ['Overview', 'Check', 'Policy', 'Grants', 'Receipts', 'Audit'];
57
+ var current = 'Overview';
58
+ var policyDigest = '';
59
+
60
+ function h(tag, attrs) {
61
+ var e = document.createElement(tag);
62
+ if (attrs) Object.keys(attrs).forEach(function (k) {
63
+ var v = attrs[k];
64
+ if (k === 'class') e.className = v;
65
+ else if (k === 'text') e.textContent = v;
66
+ else if (k.slice(0, 2) === 'on') e.addEventListener(k.slice(2), v);
67
+ else if (v === true) e.setAttribute(k, '');
68
+ else if (v !== false && v != null) e.setAttribute(k, v);
69
+ });
70
+ for (var i = 2; i < arguments.length; i++) {
71
+ var c = arguments[i];
72
+ if (c == null || c === false) continue;
73
+ e.appendChild(typeof c === 'string' || typeof c === 'number' ? document.createTextNode(String(c)) : c);
74
+ }
75
+ return e;
76
+ }
77
+ function clear(e) { while (e.firstChild) e.removeChild(e.firstChild); return e; }
78
+ function say(text, bad) {
79
+ var m = document.getElementById('msg');
80
+ clear(m);
81
+ if (text) m.appendChild(h('div', { class: 'banner' + (bad ? ' bad' : ''), role: bad ? 'alert' : 'status', text: text }));
82
+ }
83
+ function api(method, path, body) {
84
+ return fetch(path, { method: method, headers: { 'authorization': 'Bearer ' + token, 'content-type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) })
85
+ .then(function (r) {
86
+ return r.json().then(function (data) {
87
+ if (r.status === 401 || r.status === 429) { signOut(); throw new Error(data.error || 'sign in again'); }
88
+ if (!r.ok) throw new Error(data.error || ('request failed: ' + r.status));
89
+ return data;
90
+ });
91
+ });
92
+ }
93
+ function fail(e) { say(e.message || String(e), true); }
94
+ function signOut() {
95
+ token = '';
96
+ try { sessionStorage.removeItem(KEY); } catch (e) {}
97
+ document.getElementById('app').hidden = true;
98
+ document.getElementById('login').hidden = false;
99
+ }
100
+ function kv(rows) {
101
+ var t = h('table', { class: 'kv' });
102
+ rows.forEach(function (r) { t.appendChild(h('tr', null, h('th', { text: r[0] }), h('td', null, r[1] == null ? '-' : r[1]))); });
103
+ return t;
104
+ }
105
+ function mark(level) { return h('span', { class: level, text: level === 'ok' ? 'ok' : level === 'warn' ? 'warn' : 'ERROR' }); }
106
+ function findings(list) {
107
+ var box = h('div');
108
+ list.forEach(function (f) { box.appendChild(h('div', { class: 'finding' }, mark(f.level), h('span', { class: 'muted check', text: f.check }), h('span', { text: f.message }))); });
109
+ return box;
110
+ }
111
+ function short(s) { return s ? String(s).slice(0, 12) + '…' : '-'; }
112
+
113
+ var renderers = {
114
+ Overview: function () {
115
+ return api('GET', '/api/overview').then(function (o) {
116
+ var g = o.gateway;
117
+ var gw = g == null ? h('span', { class: 'muted', text: 'not configured (start the console with --gateway-url)' })
118
+ : g.reachable ? h('span', { class: 'ok', text: 'running, ' + g.sessions + ' open session' + (g.sessions === 1 ? '' : 's') }) : h('span', { class: 'bad', text: 'not reachable' + (g.error ? ': ' + g.error : '') });
119
+ var up = h('table', null, h('tr', null, h('th', { text: 'name' }), h('th', { text: 'kind' }), h('th', { text: 'target' }), h('th', { text: 'tools' })));
120
+ o.upstreams.forEach(function (u) { up.appendChild(h('tr', null, h('td', { text: u.name }), h('td', { text: u.kind }), h('td', { text: u.target }), h('td', { text: u.tools ? u.tools.join(', ') : 'offered by the server; use Check and connect' }))); });
121
+ var errs = o.findings.filter(function (f) { return f.level === 'error'; }).length;
122
+ var warns = o.findings.filter(function (f) { return f.level === 'warn'; }).length;
123
+ return h('div', null,
124
+ h('h2', { text: 'Overview' }),
125
+ h('div', { class: 'grid' },
126
+ h('div', { class: 'card' }, h('h3', { text: 'Gateway' }), kv([['status', gw], ['key id', o.gatewayKeyid ? short(o.gatewayKeyid) : 'not created yet'], ['mode', o.mode], ['config', o.configFile]])),
127
+ h('div', { class: 'card' }, h('h3', { text: 'Evidence' }), kv([['receipts', String(o.receiptCount)], ['last receipt', o.lastReceiptAt], ['log', o.log.kind === 'remote' ? 'remote ' + o.log.url + (o.log.hashOnly ? ' (hashes only)' : '') : 'local ' + o.log.file], ['precommit', o.precommit.length ? o.precommit.join(', ') : 'none']])),
128
+ h('div', { class: 'card' }, h('h3', { text: 'Who is trusted' }), kv([['principal keys', String(o.principals.length)], ['key ids', o.principals.map(short).join(', ') || 'none'], ['revoked grants', String(o.revokedCount)]])),
129
+ h('div', { class: 'card' }, h('h3', { text: 'Config check' }), h('p', null, h('span', { class: errs ? 'bad' : 'ok', text: errs + ' error' + (errs === 1 ? '' : 's') }), ', ', h('span', { class: warns ? 'warn' : 'muted', text: warns + ' warning' + (warns === 1 ? '' : 's') })), h('button', { class: 'secondary', onclick: function () { show('Check'); } }, 'See the findings'))),
130
+ o.keyProblems.length ? h('div', { class: 'banner bad' }, o.keyProblems.join('. ')) : null,
131
+ h('div', { class: 'card mt' }, h('h3', { text: 'Upstreams' }), up),
132
+ o.facts.length ? h('div', { class: 'card' }, h('h3', { text: 'Fact lookups the gateway makes itself' }), kv(o.facts.map(function (f) { return [f.name, f.tool + ' for ' + f.forTools.join(', ')]; }))) : null);
133
+ });
134
+ },
135
+
136
+ Check: function () {
137
+ var out = h('div');
138
+ function run(connect) {
139
+ say(connect ? 'Starting the upstreams to list their tools…' : '');
140
+ clear(out);
141
+ return api('POST', '/api/check', { connect: connect }).then(function (r) { say(''); out.appendChild(h('div', { class: 'card' }, findings(r.findings))); }).catch(fail);
142
+ }
143
+ var box = h('div', null, h('h2', { text: 'Config check' }),
144
+ h('p', { class: 'muted', text: 'What the gateway would fail on at startup, found before it starts. Connecting starts your stdio upstreams and lists the tools every upstream offers.' }),
145
+ h('div', { class: 'row' }, h('button', { class: 'primary', onclick: function () { run(false); } }, 'Run check'), h('button', { class: 'secondary', onclick: function () { run(true); } }, 'Run check and connect to the upstreams')), out);
146
+ run(false);
147
+ return Promise.resolve(box);
148
+ },
149
+
150
+ Policy: function () {
151
+ return api('GET', '/api/policy').then(function (p) {
152
+ policyDigest = p.digest;
153
+ var area = h('textarea', { 'aria-label': 'Cedar policy', spellcheck: 'false' });
154
+ area.value = p.text;
155
+ var out = h('div');
156
+ function validate() {
157
+ return api('POST', '/api/policy/validate', { text: area.value }).then(function (r) {
158
+ clear(out);
159
+ if (r.ok) {
160
+ out.appendChild(h('p', { class: 'ok', text: 'The policy parses.' }));
161
+ r.issues.forEach(function (m) { out.appendChild(h('p', { class: 'warn', text: m })); });
162
+ } else r.errors.forEach(function (m) { out.appendChild(h('p', { class: 'bad', text: m })); });
163
+ return r;
164
+ });
165
+ }
166
+ function simulate() {
167
+ return validate().then(function (v) {
168
+ if (!v.ok) return;
169
+ say('Replaying recorded calls against this policy…');
170
+ return api('POST', '/api/policy/simulate', { text: area.value }).then(function (s) {
171
+ say('');
172
+ var r = s.report;
173
+ out.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Replay of recorded calls' }),
174
+ h('p', { class: 'muted', text: 'A replay re-decides calls that already happened. A limit that no recorded call reached, and an argument value that was never sent, are not covered, so a change that widens what is allowed can show no change here.' }),
175
+ h('p', { text: s.replayed + ' verified receipts replayed (' + s.unverified + ' skipped because they did not verify). ' + r.evaluated + ' evaluated, ' + r.unchanged + ' unchanged, ' + r.changeCount + ' would change.' + (r.complete ? '' : ' The replay is incomplete: ' + r.skipped.length + ' calls could not be replayed.') }),
176
+ r.changes.length ? (function () {
177
+ var t = h('table', null, h('tr', null, h('th', { text: 'receipt' }), h('th', { text: 'tool' }), h('th', { text: 'was' }), h('th', { text: 'would be' })));
178
+ r.changes.forEach(function (c) { t.appendChild(h('tr', null, h('td', { text: short(c.receiptId) }), h('td', { text: c.tool }), h('td', { text: c.from }), h('td', { class: c.to === 'deny' ? 'bad' : 'warn', text: c.to }))); });
179
+ return t;
180
+ })() : h('p', { class: 'muted', text: 'No recorded decision would change.' })));
181
+ });
182
+ });
183
+ }
184
+ function save() {
185
+ return validate().then(function (v) {
186
+ if (!v.ok) return;
187
+ var ask = 'Save this policy?\n\nThe gateway reads the policy when it starts, so restart it to apply the change.';
188
+ if (v.issues.length) ask = 'Confirm before saving:\n\n' + v.issues.join('\n\n') + '\n\nSave this policy anyway?';
189
+ if (!window.confirm(ask)) return;
190
+ return api('PUT', '/api/policy', { text: area.value, expectDigest: policyDigest, confirm: v.issues.length > 0 }).then(function (r) {
191
+ policyDigest = r.digest;
192
+ say('Saved (' + short(r.digest) + '). ' + r.note);
193
+ });
194
+ });
195
+ }
196
+ return h('div', null, h('h2', { text: 'Policy' }),
197
+ h('div', { class: 'banner' }, 'The gateway reads the policy when it starts. A saved change applies after the gateway restarts; every save is recorded in the audit trail, and the previous version is kept.'),
198
+ h('p', { class: 'muted' }, p.path + ' · ' + short(p.digest)),
199
+ area, h('div', { class: 'row' },
200
+ h('button', { class: 'secondary', onclick: function () { validate().catch(fail); } }, 'Validate'),
201
+ h('button', { class: 'secondary', onclick: function () { simulate().catch(fail); } }, 'Replay recorded calls'),
202
+ h('button', { class: 'primary', onclick: function () { save().catch(fail); } }, 'Save')),
203
+ out,
204
+ p.history.length ? h('div', { class: 'card' }, h('h3', { text: 'Earlier versions kept' }), h('p', { class: 'muted', text: p.history.join(', ') })) : null);
205
+ });
206
+ },
207
+
208
+ Grants: function () {
209
+ var area = h('textarea', { 'aria-label': 'Grant', placeholder: 'Paste a grant (the JSON of a grant file)', spellcheck: 'false', class: 'short' });
210
+ var out = h('div');
211
+ var last = null;
212
+ function inspect() {
213
+ return api('POST', '/api/grants/inspect', { grant: area.value }).then(function (g) {
214
+ last = g;
215
+ clear(out);
216
+ out.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Grant' }), kv([
217
+ ['status', h('span', { class: g.status === 'valid' ? 'ok' : 'bad', text: g.status })],
218
+ ['agent', g.agent], ['principal', g.principal], ['scopes', g.scopes.join(', ')], ['issued', g.issuedAt], ['expires', g.expiresAt],
219
+ ['delegated from another grant', g.delegated ? 'yes' : 'no'], ['can delegate', g.canDelegate ? 'yes' : 'no'], ['digest', g.digest], ['why not valid', g.error]]),
220
+ h('div', { class: 'row' }, g.revoked ? h('span', { class: 'pill', text: 'already revoked' }) : h('button', { class: 'danger', onclick: function () { revoke().catch(fail); } }, 'Revoke this grant'))));
221
+ });
222
+ }
223
+ function revoke() {
224
+ if (!last || !window.confirm('Revoke the grant for ' + last.agent + '?\n\nIt, and every grant delegated from it, is refused on its next call. This cannot be undone here.')) return Promise.resolve();
225
+ return api('POST', '/api/grants/revoke', { grant: area.value }).then(function (r) { say('Revoked the grant for ' + r.agent + '. ' + r.note); return inspect().then(list); });
226
+ }
227
+ var revoked = h('div');
228
+ function list() {
229
+ return api('GET', '/api/revocations').then(function (r) {
230
+ clear(revoked);
231
+ revoked.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Revoked grants (' + r.digests.length + ')' }), r.digests.length ? h('table', null, r.digests.map(function (d) { return h('tr', null, h('td', null, h('code', { text: d }))); })) : h('p', { class: 'muted', text: 'None.' })));
232
+ });
233
+ }
234
+ list().catch(fail);
235
+ return Promise.resolve(h('div', null, h('h2', { text: 'Grants' }),
236
+ h('p', { class: 'muted', text: 'The gateway does not store grants: each agent presents its own. Paste one to see whether the gateway would accept it, and to revoke it. The console never holds a principal key and cannot issue a grant.' }),
237
+ area, h('div', { class: 'row' }, h('button', { class: 'primary', onclick: function () { inspect().catch(fail); } }, 'Inspect')), out, revoked));
238
+ },
239
+
240
+ Receipts: function () {
241
+ return api('GET', '/api/receipts?limit=100').then(function (r) {
242
+ var detail = h('div');
243
+ var filter = h('select', { 'aria-label': 'Filter by status' }, h('option', { value: '' }, 'all'), h('option', { value: 'executed' }, 'executed'), h('option', { value: 'denied' }, 'denied'), h('option', { value: 'withheld' }, 'withheld'), h('option', { value: 'failed' }, 'failed'));
244
+ var body = h('table');
245
+ function draw() {
246
+ clear(body);
247
+ body.appendChild(h('tr', null, h('th', { text: 'time' }), h('th', { text: 'agent' }), h('th', { text: 'tool' }), h('th', { text: 'decision' }), h('th', { text: 'outcome' }), h('th', { text: 'verifies' })));
248
+ r.receipts.filter(function (x) { return !filter.value || x.status === filter.value; }).forEach(function (x) {
249
+ body.appendChild(h('tr', { class: 'click', onclick: function () { open(x.id); } },
250
+ h('td', { text: x.timestamp || '-' }), h('td', { text: x.agent || '-' }), h('td', { text: x.tool || '-' }),
251
+ h('td', { class: x.decision === 'deny' ? 'bad' : '', text: x.decision ? x.decision + (x.enforced ? '' : ' (not enforced)') : '-' }),
252
+ h('td', { text: x.status ? x.status + (x.reason ? ': ' + x.reason : '') : '-' }),
253
+ h('td', { class: x.verified ? 'ok' : 'bad', text: x.verified ? 'yes' : 'NO: ' + (x.failing || []).join(', ') })));
254
+ });
255
+ }
256
+ function open(id) {
257
+ api('GET', '/api/receipts/' + encodeURIComponent(id)).then(function (d) {
258
+ clear(detail);
259
+ detail.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Receipt ' + id }), h('pre', { text: JSON.stringify(d.statement, null, 2) })));
260
+ detail.scrollIntoView();
261
+ }).catch(fail);
262
+ }
263
+ filter.addEventListener('change', draw);
264
+ draw();
265
+ return h('div', null, h('h2', { text: 'Receipts' }),
266
+ h('p', { class: 'muted', text: r.total + ' receipts on disk, the newest ' + r.receipts.length + ' shown. Each is verified against the gateway key, the trusted principals, and the local log.' }),
267
+ r.problems.length ? h('div', { class: 'banner bad' }, r.problems.join('. ')) : null,
268
+ h('div', { class: 'row' }, h('label', null, 'Outcome ', filter)), h('div', { class: 'card' }, body), detail);
269
+ });
270
+ },
271
+
272
+ Audit: function () {
273
+ return api('GET', '/api/audit').then(function (a) {
274
+ var t = h('table', null, h('tr', null, h('th', { text: 'when' }), h('th', { text: 'by' }), h('th', { text: 'action' }), h('th', { text: 'detail' })));
275
+ a.entries.forEach(function (e) {
276
+ var rest = {}; Object.keys(e).forEach(function (k) { if (k !== 'at' && k !== 'by' && k !== 'action') rest[k] = e[k]; });
277
+ t.appendChild(h('tr', null, h('td', { text: e.at }), h('td', { text: e.by }), h('td', { text: e.action }), h('td', null, h('code', { text: JSON.stringify(rest) }))));
278
+ });
279
+ return h('div', null, h('h2', { text: 'Audit trail' }), h('p', { class: 'muted', text: 'Every change made here: who, when, and what.' }), h('div', { class: 'card' }, a.entries.length ? t : h('p', { class: 'muted', text: 'No changes yet.' })));
280
+ });
281
+ }
282
+ };
283
+
284
+ function show(name) {
285
+ current = name;
286
+ say('');
287
+ Array.prototype.forEach.call(document.querySelectorAll('nav button'), function (b) { if (b.textContent === name) b.setAttribute('aria-current', 'page'); else b.removeAttribute('aria-current'); });
288
+ clear(view).appendChild(h('p', { class: 'muted', text: 'Loading…' }));
289
+ renderers[name]().then(function (el) { clear(view).appendChild(el); }).catch(function (e) { clear(view); fail(e); });
290
+ }
291
+
292
+ var nav = document.getElementById('nav');
293
+ tabs.forEach(function (n) { nav.appendChild(h('button', { type: 'button', onclick: function () { show(n); } }, n)); });
294
+ document.getElementById('signout').addEventListener('click', signOut);
295
+ document.getElementById('theme').addEventListener('click', function () {
296
+ var dark = document.documentElement.getAttribute('data-theme') === 'dark' || (!document.documentElement.getAttribute('data-theme') && window.matchMedia('(prefers-color-scheme: dark)').matches);
297
+ var next = dark ? 'light' : 'dark';
298
+ document.documentElement.setAttribute('data-theme', next);
299
+ try { localStorage.setItem(THEME, next); } catch (e) {}
300
+ });
301
+ document.getElementById('login-form').addEventListener('submit', function (ev) {
302
+ ev.preventDefault();
303
+ token = document.getElementById('token').value.trim();
304
+ document.getElementById('token').value = '';
305
+ api('GET', '/api/audit').then(function () {
306
+ try { sessionStorage.setItem(KEY, token); } catch (e) {}
307
+ document.getElementById('login').hidden = true;
308
+ document.getElementById('app').hidden = false;
309
+ show(current);
310
+ }).catch(function (e) { clear(document.getElementById('login-msg')).appendChild(h('p', { class: 'bad', role: 'alert', text: e.message })); });
311
+ });
312
+ if (token) {
313
+ api('GET', '/api/audit').then(function () { document.getElementById('login').hidden = true; document.getElementById('app').hidden = false; show(current); }).catch(function () { signOut(); });
314
+ }
315
+ })();
316
+ `;
317
+ const sha = (s) => `'sha256-${createHash("sha256").update(s).digest("base64")}'`;
318
+ export const CONSOLE_CSP = `default-src 'none'; style-src ${sha(STYLE)}; script-src ${sha(SCRIPT)}; connect-src 'self'; img-src data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`;
319
+ export const CONSOLE_HTML = `<!doctype html>
320
+ <html lang="en">
321
+ <head>
322
+ <meta charset="utf-8">
323
+ <meta name="viewport" content="width=device-width, initial-scale=1">
324
+ <title>agent-custody console</title>
325
+ <style>${STYLE}</style>
326
+ </head>
327
+ <body>
328
+ <section id="login" class="card">
329
+ <h2>agent-custody console</h2>
330
+ <p class="muted">Sign in with the console's token. It is kept for this browser tab only.</p>
331
+ <form id="login-form"><div class="row"><label for="token">Token</label><input id="token" type="password" autocomplete="off" required><button class="primary" type="submit">Sign in</button></div></form>
332
+ <div id="login-msg"></div>
333
+ </section>
334
+ <div id="app" hidden>
335
+ <header><h1>agent-custody console</h1><nav id="nav" aria-label="Sections"></nav><button id="theme" type="button" class="secondary">Theme</button><button id="signout" type="button" class="secondary">Sign out</button></header>
336
+ <main><div id="msg"></div><div id="view"></div></main>
337
+ </div>
338
+ <script>${SCRIPT}</script>
339
+ </body>
340
+ </html>
341
+ `;
342
+ export { SCRIPT as CONSOLE_SCRIPT };
@@ -0,0 +1,20 @@
1
+ export interface ConsoleOptions {
2
+ /** the gateway's config file; read again on every request, so an edit shows at once */
3
+ configFile: string;
4
+ /** the shared secret every API request must present as `Authorization: Bearer`; read from the environment by the CLI */
5
+ token: string;
6
+ port?: number;
7
+ host?: string;
8
+ /** the running gateway's base URL, for its health; omitted means the console does not look */
9
+ gatewayUrl?: string;
10
+ /** where the console keeps its audit file and the history of saved policies; default beside the receipts directory */
11
+ stateDir?: string;
12
+ /** how long a --connect check may take before it is stopped and the upstreams it started are closed; default 60 seconds */
13
+ checkTimeoutMs?: number;
14
+ log?: (message: string) => void;
15
+ }
16
+ export interface RunningConsole {
17
+ url: string;
18
+ close(): Promise<void>;
19
+ }
20
+ export declare function serveConsole(options: ConsoleOptions): Promise<RunningConsole>;