clavarium 0.2.173-next.1 → 0.2.175-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 +6 -6
- package/package.json +2 -2
- package/server/boxes.mjs +53 -9
- package/server/main.mjs +5 -3
- package/server/setup.mjs +1 -1
- package/server/tethers.mjs +1 -1
- package/web/app.js +7 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.175-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.175-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clavarium-binder": "0.1.43-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.1",
|
|
16
16
|
"clavarium-parley": "0.17.33-next.1",
|
|
17
|
-
"clavarium-tether": "0.1.0-next.
|
|
17
|
+
"clavarium-tether": "0.1.0-next.41",
|
|
18
18
|
"mermaid": "11.17.2",
|
|
19
19
|
"node-pty": "^1.1.0",
|
|
20
20
|
"pdfjs-dist": "6.4.299",
|
|
@@ -760,9 +760,9 @@
|
|
|
760
760
|
}
|
|
761
761
|
},
|
|
762
762
|
"node_modules/clavarium-tether": {
|
|
763
|
-
"version": "0.1.0-next.
|
|
764
|
-
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.
|
|
765
|
-
"integrity": "sha512-
|
|
763
|
+
"version": "0.1.0-next.41",
|
|
764
|
+
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.41.tgz",
|
|
765
|
+
"integrity": "sha512-TYoKd13BWVdNY7yLwX6v9yqSstEXp+s2AMKR9n04aeHop6EdW0bGm1Frm5vLFGCzOlWn8gzSky/pYtJjZy9Weg==",
|
|
766
766
|
"license": "MIT",
|
|
767
767
|
"bin": {
|
|
768
768
|
"tether": "bin/cli.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.175-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"clavarium-binder": "0.1.43-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.1",
|
|
49
49
|
"clavarium-parley": "0.17.33-next.1",
|
|
50
|
-
"clavarium-tether": "0.1.0-next.
|
|
50
|
+
"clavarium-tether": "0.1.0-next.41",
|
|
51
51
|
"mermaid": "11.17.2",
|
|
52
52
|
"node-pty": "^1.1.0",
|
|
53
53
|
"pdfjs-dist": "6.4.299",
|
package/server/boxes.mjs
CHANGED
|
@@ -23,9 +23,10 @@ export const CODE_MINUTES = 10;
|
|
|
23
23
|
export const PAIR_PATH = '/c/api/box/pair';
|
|
24
24
|
export const LINK_PATH = '/c/api/box/ws';
|
|
25
25
|
export const SENTENCE_MAX = 15 * 32_000 + 32_000; /* 15 s of 16 kHz 16-bit mono, and some slack */
|
|
26
|
-
export const ANSWER_MINUTES = 5; /* after a sentence, what the tool says is spoken */
|
|
27
26
|
export const TRIES_PER_MINUTE = 10;
|
|
28
27
|
export const NAME_MAX = 40;
|
|
28
|
+
/* The volume a box is given when it connects, until someone sets another (its own default was soft). */
|
|
29
|
+
export const VOLUME_DEFAULT = 80;
|
|
29
30
|
/* Where a box in setup answers, on its own Wi-Fi: ESP-IDF's access point address, the same on
|
|
30
31
|
every box (written from its parts: it is no machine of anybody's). */
|
|
31
32
|
export const SETUP_ADDRESS = `http://${[192, 168, 4, 1].join('.')}/`;
|
|
@@ -86,7 +87,7 @@ export class Boxes {
|
|
|
86
87
|
|
|
87
88
|
/* What the operator sees: never the key, nor its hash. */
|
|
88
89
|
all() {
|
|
89
|
-
return this.#all().map(({ keyHash, ...b }) => ({ ...b, online: this.#links.has(b.id), muted: this.#links.get(b.id)?.muted ?? null, volume: this.#links.get(b.id)?.volume ??
|
|
90
|
+
return this.#all().map(({ keyHash, ...b }) => ({ ...b, online: this.#links.has(b.id), muted: this.#links.get(b.id)?.muted ?? null, volume: b.volume ?? this.#links.get(b.id)?.volume ?? VOLUME_DEFAULT }));
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
code(conversation, name) {
|
|
@@ -131,6 +132,18 @@ export class Boxes {
|
|
|
131
132
|
this.#change(id, { name: label });
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/* Louder or softer: kept, and given to the box now if it is connected. */
|
|
136
|
+
async setVolume(id, level) {
|
|
137
|
+
const n = Math.round(Number(level));
|
|
138
|
+
if (!Number.isFinite(n) || n < 0 || n > 100) throw new Refusal(400, 'A volume from 0 to 100.');
|
|
139
|
+
this.#change(id, { volume: n });
|
|
140
|
+
const link = this.#links.get(id);
|
|
141
|
+
if (!link) return { ok: true, offline: true };
|
|
142
|
+
const a = await this.command(id, { t: 'volume', level: n });
|
|
143
|
+
if (a?.ok !== false) link.volume = n;
|
|
144
|
+
return a;
|
|
145
|
+
}
|
|
146
|
+
|
|
134
147
|
/* Where it is (a home, a family house): grouped by it, named with it. */
|
|
135
148
|
place(id, place) { this.#change(id, { place: String(place ?? '').trim().slice(0, NAME_MAX) }); }
|
|
136
149
|
|
|
@@ -171,14 +184,13 @@ export class Boxes {
|
|
|
171
184
|
});
|
|
172
185
|
}
|
|
173
186
|
|
|
174
|
-
/* The tool said or asked something in a conversation
|
|
175
|
-
|
|
187
|
+
/* The tool said or asked something in a conversation: said aloud only by the boxes it is
|
|
188
|
+
addressed to (`to`: box ids, #215). Anything else stays in the thread, silent -- a box
|
|
189
|
+
read a whole technical message aloud once (31-10), which nobody wants. */
|
|
176
190
|
async agentSaid(conversation, text, to = null) {
|
|
177
191
|
const words = forSpeech(text);
|
|
178
|
-
if (!words) return;
|
|
179
|
-
const
|
|
180
|
-
const mine = [...this.#links.values()].filter((l) => l.box().conversation === conversation);
|
|
181
|
-
const boxes = Array.isArray(to) && to.length ? mine.filter((l) => to.includes(l.box().id)) : mine.filter((l) => l.heardAt > now - ANSWER_MINUTES * 60_000);
|
|
192
|
+
if (!words || !Array.isArray(to) || to.length === 0) return;
|
|
193
|
+
const boxes = [...this.#links.values()].filter((l) => l.box().conversation === conversation && to.includes(l.box().id));
|
|
182
194
|
if (boxes.length === 0) return;
|
|
183
195
|
let pcm;
|
|
184
196
|
try { pcm = await this.#speak(words); } catch (error) { this.#log(`voice box: no voice for the answer (${error.message})`); for (const l of boxes) l.send({ t: 'cue', name: 'error' }); return; }
|
|
@@ -215,6 +227,11 @@ export class Boxes {
|
|
|
215
227
|
if (!m || typeof m !== 'object') return;
|
|
216
228
|
if (m.t === 'ping') { send({ t: 'pong' }); return; }
|
|
217
229
|
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)}`);
|
|
230
|
+
if (m.t === 'hello') {
|
|
231
|
+
/* Its volume, as set here: given at each connection (a box keeps its own, softer, otherwise). */
|
|
232
|
+
const wanted = link.box().volume ?? VOLUME_DEFAULT;
|
|
233
|
+
if (m.volume !== wanted) { send({ t: 'volume', id: randomUUID(), level: wanted }); m.volume = wanted; }
|
|
234
|
+
}
|
|
218
235
|
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; }
|
|
219
236
|
if (m.t === 'listen.start') { sentence = []; size = 0; return; }
|
|
220
237
|
if (m.t === 'listen.end' && sentence) {
|
|
@@ -305,7 +322,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
305
322
|
case 'move': boxes.move(id, String(body.conversation ?? '')); return send(200, { ok: true });
|
|
306
323
|
case 'place': boxes.place(id, body.place); return send(200, { ok: true });
|
|
307
324
|
case 'revoke': boxes.revoke(id); return send(200, { ok: true });
|
|
308
|
-
case 'volume': return answered(await boxes.
|
|
325
|
+
case 'volume': return answered(await boxes.setVolume(id, body.level));
|
|
309
326
|
case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
|
|
310
327
|
case 'wifi-join': return answered(await boxes.command(id, { t: 'wifi.join', ssid: String(body.ssid ?? ''), password: String(body.password ?? '') }, 90_000));
|
|
311
328
|
case 'alert': return answered(await boxes.command(id, { t: 'alert', text: String(body.text ?? '').slice(0, 300) }, 10 * 60_000));
|
|
@@ -316,3 +333,30 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
316
333
|
return send(error.status ?? (error instanceof SyntaxError ? 400 : 500), { error: error instanceof SyntaxError ? 'Not JSON.' : error.message });
|
|
317
334
|
}
|
|
318
335
|
}
|
|
336
|
+
|
|
337
|
+
/* VOICE BOXES AS TETHER TARGETS (kind voicebox): what an assistant may do to the boxes of its
|
|
338
|
+
own conversation -- louder, softer, an alert -- through Tether's rights and journal. One
|
|
339
|
+
target per box, given to its conversation at "free" (nothing in it is risky), taken back when
|
|
340
|
+
the box moves or goes. */
|
|
341
|
+
export const targetOf = (box) => `voicebox-${box.id.slice(0, 8)}`;
|
|
342
|
+
export function voiceboxConnector(boxes) {
|
|
343
|
+
return {
|
|
344
|
+
async run(verb, t, a = {}) {
|
|
345
|
+
const id = t.config?.box;
|
|
346
|
+
if (verb === 'voicebox.volume') { const r = await boxes.setVolume(id, a.level); return { text: r?.offline ? `Volume ${a.level} kept: the box is offline, it gets it when it comes back.` : `Volume set to ${a.level}.` }; }
|
|
347
|
+
if (verb === 'voicebox.alert') { await boxes.command(id, { t: 'alert', text: String(a.text ?? '').slice(0, 300) }, 10 * 60_000); return { text: 'The alert was seen: someone pressed its button.' }; }
|
|
348
|
+
throw new Error(`${verb} is not for a voice box`);
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
export function syncTargets(store, list) {
|
|
353
|
+
const wanted = new Map(list.map((b) => [targetOf(b), b]));
|
|
354
|
+
for (const t of store.targets()) if (t.kind === 'voicebox' && !wanted.has(t.id)) store.removeTarget(t.id);
|
|
355
|
+
for (const [id, b] of wanted) {
|
|
356
|
+
const before = store.target(id);
|
|
357
|
+
store.putTarget({ id, title: `Voice box ${b.name}${b.place ? ` (${b.place})` : ''}`, kind: 'voicebox', connector: 'voicebox', config: { box: b.id } });
|
|
358
|
+
const agent = `conversation:${b.conversation}`;
|
|
359
|
+
for (const who of Object.keys(store.target(id)?.grants ?? {})) if (who !== agent) store.grant(id, who, null);
|
|
360
|
+
if (!before || !store.target(id)?.grants?.[agent]) store.grant(id, agent, 'free');
|
|
361
|
+
}
|
|
362
|
+
}
|
package/server/main.mjs
CHANGED
|
@@ -76,7 +76,7 @@ import { Events } from './events.mjs';
|
|
|
76
76
|
import { Bundles } from './bundle.mjs';
|
|
77
77
|
import { migrateData } from './dataformat.mjs';
|
|
78
78
|
import { VmWatch } from './vmwatch.mjs';
|
|
79
|
-
import { Boxes, handleBoxes, PAIR_PATH as BOX_PAIR_PATH } from './boxes.mjs';
|
|
79
|
+
import { Boxes, handleBoxes, voiceboxConnector, syncTargets, PAIR_PATH as BOX_PAIR_PATH } from './boxes.mjs';
|
|
80
80
|
import { Speech } from './speech.mjs';
|
|
81
81
|
import { WebSocketServer } from 'ws';
|
|
82
82
|
|
|
@@ -426,7 +426,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
426
426
|
/* The accesses an agent was given -- a machine over SSH, an online folder, a
|
|
427
427
|
mailbox, a calendar, an address book -- held here with their secrets read from
|
|
428
428
|
the vault by name, never in a machine: see tethers.mjs. */
|
|
429
|
-
|
|
429
|
+
/* Voice boxes are Tether targets too (boxes.mjs): their connector reaches them through `boxes`, made below. */
|
|
430
|
+
const tethers = new Tethers({ dataDir, resources: folders, conversations: () => all.list().map((c) => c.name), secrets, connectors: { voicebox: { run: (...a) => voiceboxConnector(boxes).run(...a) } } });
|
|
430
431
|
const stopTethers = tethers.start();
|
|
431
432
|
/* Connecting a mailbox, calendar or address book by token: the consent happens
|
|
432
433
|
in the owner's browser, the refresh token is kept host-only (never in a
|
|
@@ -601,7 +602,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
601
602
|
/* Said as the person's own message, the room named (one speaker for now). */
|
|
602
603
|
say: (name, text, by) => talk.say(name, text, undefined, undefined, 'voice', { by }),
|
|
603
604
|
/* Each conversation's thread knows its boxes: their names, and the ids its agent answers. */
|
|
604
|
-
changed: () => { for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name)); },
|
|
605
|
+
changed: () => { for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name)); try { syncTargets(tethers.store(), boxes.all()); } catch (error) { console.error(`voice boxes in Tether: ${error.message}`); } },
|
|
605
606
|
speak: (text) => speech.speak(text),
|
|
606
607
|
log: (line) => events.add({ kind: 'server', text: line }) });
|
|
607
608
|
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
@@ -609,6 +610,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
609
610
|
let closing = false;
|
|
610
611
|
boxes.attach(server, WebSocketServer);
|
|
611
612
|
for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name));
|
|
613
|
+
try { syncTargets(tethers.store(), boxes.all()); } catch (error) { console.error(`voice boxes in Tether: ${error.message}`); }
|
|
612
614
|
bridge = attachBridge(server, {
|
|
613
615
|
onRejoin: (name) => all.rejoin(name),
|
|
614
616
|
onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); typingWatch.typed(name, data); },
|
package/server/setup.mjs
CHANGED
|
@@ -305,7 +305,7 @@ export class Setup {
|
|
|
305
305
|
const TCAT = { mail: 'mailbox', calendar: 'agenda', contacts: 'contacts' };
|
|
306
306
|
for (const t of p.tethers?.store?.().targets() ?? []) {
|
|
307
307
|
/* The USB device of the owner's browser is not an asset: nothing of it to show or carry. */
|
|
308
|
-
if (t.kind === 'device') continue;
|
|
308
|
+
if (t.kind === 'device' || t.kind === 'voicebox') continue;
|
|
309
309
|
const kind = TCAT[t.kind] ?? 'mailbox';
|
|
310
310
|
nodes.push({ id: `connexion:${t.id}`, kind, name: t.title, sub: `${t.kind} (live)`, tether: true, record: t });
|
|
311
311
|
for (const [agent, grant] of Object.entries(t.grants ?? {})) {
|
package/server/tethers.mjs
CHANGED
|
@@ -155,7 +155,7 @@ export class Tethers {
|
|
|
155
155
|
given() {
|
|
156
156
|
const out = {};
|
|
157
157
|
for (const t of this.#keeper.store.targets()) {
|
|
158
|
-
if (t.kind === 'device') continue; /* offered
|
|
158
|
+
if (t.kind === 'device' || t.kind === 'voicebox') continue; /* offered with a conversation or a box: not an access worth counting */
|
|
159
159
|
for (const id of Object.keys(t.grants ?? {})) if (id.startsWith(AGENT)) out[id.slice(AGENT.length)] = (out[id.slice(AGENT.length)] ?? 0) + 1;
|
|
160
160
|
}
|
|
161
161
|
return out;
|
package/web/app.js
CHANGED
|
@@ -8864,7 +8864,13 @@
|
|
|
8864
8864
|
/* Where it is (a home): typed once, then offered for the next ones. */
|
|
8865
8865
|
const place = el('input'); place.value = b.place ?? ''; place.maxLength = 40; place.placeholder = 'Place (a home)'; place.setAttribute('list', 'box-places'); place.setAttribute('aria-label', `Place of ${b.name}`);
|
|
8866
8866
|
place.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/place`, { place: place.value.trim() }).catch(() => {}); await paintBoxes(); });
|
|
8867
|
-
|
|
8867
|
+
/* Louder, softer: kept here, given to the box now or when it comes back. */
|
|
8868
|
+
const vol = el('input'); vol.type = 'range'; vol.min = '0'; vol.max = '100'; vol.step = '5'; vol.value = String(b.volume ?? 80); vol.setAttribute('aria-label', `Volume of ${b.name}`);
|
|
8869
|
+
const volSaid = el('small', 'hint', `${vol.value} %`);
|
|
8870
|
+
vol.addEventListener('input', () => { volSaid.textContent = `${vol.value} %`; });
|
|
8871
|
+
vol.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/volume`, { level: Number(vol.value) }).catch((error) => { volSaid.textContent = error.message; }); });
|
|
8872
|
+
const volRow = el('label', 'box-volume'); volRow.append('Volume ', vol, volSaid);
|
|
8873
|
+
const acts = el('div', 'action-row'); acts.append(whereRow, place, volRow, rename, remove);
|
|
8868
8874
|
card.append(head, acts);
|
|
8869
8875
|
rows.append(card);
|
|
8870
8876
|
}
|