clavarium 0.2.171-next.1 → 0.2.173-next.1
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.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +1 -1
- package/server/boxes.mjs +1 -0
- package/server/serverlogs.mjs +27 -2
- package/web/app.js +9 -2
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.173-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.173-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -310,7 +310,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
310
310
|
}));
|
|
311
311
|
return send(200, history.together(query.get('span') ?? '1h', machines, { memoryMb: a?.memory?.totalMb, cores: room?.cpu?.cores, diskMb: a?.disk?.sizeMb })), true;
|
|
312
312
|
}
|
|
313
|
-
if (pathname === '/api/server/logs' && serverLogs)
|
|
313
|
+
if (pathname === '/api/server/logs' && serverLogs) { const r = await serverLogs.start(query.get('source') ?? 'clavarium', query.get('span') ?? '10m'); return send(r.pending ? 202 : 200, r), true; }
|
|
314
314
|
if (pathname === '/api/machines/disks' && machinesMove) return send(200, await machinesMove.disks()), true;
|
|
315
315
|
if (pathname === '/api/machines/places' && machinesMove) return send(200, await machinesMove.places()), true;
|
|
316
316
|
if (pathname === '/api/machines/moving' && machinesMove) return send(200, await machinesMove.moving()), true;
|
package/server/boxes.mjs
CHANGED
|
@@ -214,6 +214,7 @@ export class Boxes {
|
|
|
214
214
|
try { m = JSON.parse(String(data)); } catch { return; }
|
|
215
215
|
if (!m || typeof m !== 'object') return;
|
|
216
216
|
if (m.t === 'ping') { send({ t: 'pong' }); return; }
|
|
217
|
+
if (m.t === 'hello' && typeof m.problem === 'string' && m.problem) this.#log(`voice box ${box.name}: back online after ${Number(m.tries) || '?'} tries; it had: ${m.problem.slice(0, 160)}`);
|
|
217
218
|
if (m.t === 'hello') { link.muted = m.muted === true; link.volume = Number.isFinite(m.volume) ? m.volume : null; this.#change(box.id, { firmware: String(m.firmware ?? '').slice(0, 20) }); seen(); return; }
|
|
218
219
|
if (m.t === 'listen.start') { sentence = []; size = 0; return; }
|
|
219
220
|
if (m.t === 'listen.end' && sentence) {
|
package/server/serverlogs.mjs
CHANGED
|
@@ -22,9 +22,34 @@ export function mask(text) {
|
|
|
22
22
|
return String(text).replace(NAMED, (all, word, between) => `${word}${between}[masked]`).replace(LONG, '[masked]');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/* A read longer than this is answered "still reading": the front cuts a request that waits
|
|
26
|
+
much longer (found 31-10 on a big journal: even 10 minutes took too long there). */
|
|
27
|
+
export const WAIT_MS = 12_000;
|
|
28
|
+
export const KEPT_MS = 120_000;
|
|
29
|
+
|
|
25
30
|
export class ServerLogs {
|
|
26
|
-
#host;
|
|
27
|
-
constructor({ host }) { this.#host = host; }
|
|
31
|
+
#host; #reads = new Map(); #now;
|
|
32
|
+
constructor({ host, now = () => Date.now() }) { this.#host = host; this.#now = now; }
|
|
33
|
+
|
|
34
|
+
/* The same read asked again while it runs is the same read; once done, kept a moment for
|
|
35
|
+
the page that comes back for it. Resolves { pending: true } past `wait`. */
|
|
36
|
+
async start(source, span, wait = WAIT_MS) {
|
|
37
|
+
const key = `${source}:${span}`;
|
|
38
|
+
const now = this.#now();
|
|
39
|
+
for (const [k, r] of this.#reads) if (r.done && now - r.done > KEPT_MS) this.#reads.delete(k);
|
|
40
|
+
let r = this.#reads.get(key);
|
|
41
|
+
if (!r) {
|
|
42
|
+
r = { done: 0 };
|
|
43
|
+
r.promise = this.read(source, span).then((v) => { r.value = v; }, (e) => { r.error = e; }).finally(() => { r.done = this.#now(); });
|
|
44
|
+
this.#reads.set(key, r);
|
|
45
|
+
}
|
|
46
|
+
await Promise.race([r.promise, new Promise((ok) => { setTimeout(ok, wait).unref?.(); })]);
|
|
47
|
+
if (!r.done) return { pending: true, source, span: String(span) };
|
|
48
|
+
this.#reads.delete(key);
|
|
49
|
+
if (r.error) throw r.error;
|
|
50
|
+
return r.value;
|
|
51
|
+
}
|
|
52
|
+
|
|
28
53
|
async read(source, span) {
|
|
29
54
|
if (!SOURCES.includes(source)) throw new Refusal(400, `Not a source of logs: say one of ${SOURCES.join(', ')}.`);
|
|
30
55
|
if (!SPANS.includes(String(span))) throw new Refusal(400, 'Not a span: 10 minutes (10m), 1, 6, 24 or 168 hours, or since the server started (boot).');
|
package/web/app.js
CHANGED
|
@@ -6075,8 +6075,15 @@
|
|
|
6075
6075
|
const source = $('logs-source').value; const span = $('logs-span').value;
|
|
6076
6076
|
$('logs-said').textContent = 'Reading...'; $('logs-show').disabled = true;
|
|
6077
6077
|
try {
|
|
6078
|
-
|
|
6079
|
-
|
|
6078
|
+
/* A big journal takes a while: the server says "still reading" (202), and is asked again. */
|
|
6079
|
+
let r; let body = {};
|
|
6080
|
+
for (let i = 0; i < 30; i++) {
|
|
6081
|
+
r = await fetch(`${API}/server/logs?source=${encodeURIComponent(source)}&span=${encodeURIComponent(span)}`);
|
|
6082
|
+
body = await r.json().catch(() => ({}));
|
|
6083
|
+
if (r.status === 202 || (r.status === 503 && body.down === true)) { $('logs-said').textContent = `Reading... (a big journal: ${(i + 1) * 12} s)`; continue; }
|
|
6084
|
+
break;
|
|
6085
|
+
}
|
|
6086
|
+
if (r.status === 202) throw new Error('The logs take too long to read: try a shorter span.');
|
|
6080
6087
|
if (!r.ok) throw new Error(body.error ?? `The logs could not be read (${r.status}).`);
|
|
6081
6088
|
logsShown = body;
|
|
6082
6089
|
$('logs-text').textContent = body.text || '';
|