clavarium 0.2.102-beta.1 → 0.2.103-beta.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.
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.102-beta.1",
3
+ "version": "0.2.103-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.102-beta.1",
9
+ "version": "0.2.103-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
13
13
  "@xterm/xterm": "^6.0.0",
14
14
  "clavarium-binder": "0.1.43-next.1",
15
15
  "clavarium-docket": "0.1.1",
16
- "clavarium-parley": "0.17.31-next.1",
16
+ "clavarium-parley": "0.17.33-next.1",
17
17
  "clavarium-tether": "0.1.0-next.40",
18
18
  "mermaid": "11.17.2",
19
19
  "node-pty": "^1.1.0",
@@ -747,9 +747,9 @@
747
747
  }
748
748
  },
749
749
  "node_modules/clavarium-parley": {
750
- "version": "0.17.31-next.1",
751
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.31-next.1.tgz",
752
- "integrity": "sha512-UN3s3ciAXkWcEKWjoilsM7dI61vvoh7SuonvbA9KJ13cl6VUATmOmmY/o0r/i2/P0y3/avNvCLholFSumrPg0A==",
750
+ "version": "0.17.33-next.1",
751
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.33-next.1.tgz",
752
+ "integrity": "sha512-pJ+YFWKZgiVvrzRHpsruciTHt5R3tOzo4XbHsEWmCqlXYEKCLWI29TnyR3nJ63X0qM1AJFACfiNl7DDOrXFK5w==",
753
753
  "license": "MIT",
754
754
  "bin": {
755
755
  "parley": "bin/parley.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.102-beta.1",
3
+ "version": "0.2.103-beta.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.",
@@ -46,7 +46,7 @@
46
46
  "@xterm/xterm": "^6.0.0",
47
47
  "clavarium-binder": "0.1.43-next.1",
48
48
  "clavarium-docket": "0.1.1",
49
- "clavarium-parley": "0.17.31-next.1",
49
+ "clavarium-parley": "0.17.33-next.1",
50
50
  "clavarium-tether": "0.1.0-next.40",
51
51
  "mermaid": "11.17.2",
52
52
  "node-pty": "^1.1.0",
package/server/boxes.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * A press on its button, a sentence: the box streams it here, the dictation
4
4
  * engine (voice.mjs) turns it into text, and the text is said in the box's
5
- * conversation as the person's own message, the room named. What the tool
5
+ * conversation by the box itself, in its own name (Parley's speakers, #215). What the tool
6
6
  * then says or asks there is read aloud (speech.mjs) and played by the box.
7
7
  * Protocol v1: DEVICES.md.
8
8
  *
@@ -70,16 +70,19 @@ export function forSpeech(text) {
70
70
 
71
71
  export class Boxes {
72
72
  #file; #codes = new Map(); #links = new Map(); #tries = []; #now;
73
- #exists; #hear; #say; #speak; #log;
73
+ #exists; #hear; #say; #speak; #log; #changed;
74
74
 
75
75
  /* file: a JsonFile holding [{ id, name, conversation, keyHash, firmware, createdAt, seenAt }].
76
76
  exists(conversation), hear(wav) -> text, say(conversation, text, room), speak(text) -> PCM 16 kHz. */
77
- constructor({ file, exists = () => true, hear, say, speak, now = () => Date.now(), log = () => {} }) {
78
- this.#file = file; this.#exists = exists; this.#hear = hear; this.#say = say; this.#speak = speak; this.#now = now; this.#log = log;
77
+ constructor({ file, exists = () => true, hear, say, speak, changed = () => {}, now = () => Date.now(), log = () => {} }) {
78
+ this.#file = file; this.#changed = changed; this.#exists = exists; this.#hear = hear; this.#say = say; this.#speak = speak; this.#now = now; this.#log = log;
79
79
  }
80
80
 
81
81
  #all() { const v = this.#file.get(); return Array.isArray(v) ? v : []; }
82
- #save(list) { this.#file.set(list); }
82
+ #save(list) { this.#file.set(list); try { this.#changed(); } catch { /* the caller's */ } }
83
+
84
+ /* The boxes of one conversation, as its thread names them: { id, name, place }. */
85
+ speakersOf(conversation) { return this.#all().filter((b) => b.conversation === conversation).map((b) => ({ id: b.id, name: b.name, ...(b.place ? { place: b.place } : {}) })); }
83
86
 
84
87
  /* What the operator sees: never the key, nor its hash. */
85
88
  all() {
@@ -128,6 +131,9 @@ export class Boxes {
128
131
  this.#change(id, { name: label });
129
132
  }
130
133
 
134
+ /* Where it is (a home, a family house): grouped by it, named with it. */
135
+ place(id, place) { this.#change(id, { place: String(place ?? '').trim().slice(0, NAME_MAX) }); }
136
+
131
137
  move(id, conversation) {
132
138
  if (!this.#exists(conversation)) throw new Refusal(404, 'No such conversation.');
133
139
  this.#change(id, { conversation });
@@ -165,12 +171,14 @@ export class Boxes {
165
171
  });
166
172
  }
167
173
 
168
- /* The tool said or asked something in a conversation: spoken by its boxes that were just talked to. */
169
- async agentSaid(conversation, text) {
174
+ /* The tool said or asked something in a conversation. Addressed (`to`: box ids, #215): said by
175
+ those boxes of this conversation. Not addressed: said by its boxes that were just talked to. */
176
+ async agentSaid(conversation, text, to = null) {
170
177
  const words = forSpeech(text);
171
178
  if (!words) return;
172
179
  const now = this.#now();
173
- const boxes = [...this.#links.values()].filter((l) => l.box().conversation === conversation && l.heardAt > now - ANSWER_MINUTES * 60_000);
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);
174
182
  if (boxes.length === 0) return;
175
183
  let pcm;
176
184
  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; }
@@ -231,7 +239,7 @@ export class Boxes {
231
239
  try { text = String(await this.#hear(wavOf(pcm)) ?? '').trim(); } catch (error) { this.#log(`voice box: dictation failed (${error.message})`); link.send({ t: 'cue', name: 'error' }); return; }
232
240
  if (!text) { link.send({ t: 'cue', name: 'error' }); return; }
233
241
  const box = link.box();
234
- try { await this.#say(box.conversation, text, box.name); } catch (error) { this.#log(`voice box: not said in ${box.conversation} (${error.message})`); link.send({ t: 'cue', name: 'error' }); return; }
242
+ try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}) }); } catch (error) { this.#log(`voice box: not said in ${box.conversation} (${error.message})`); link.send({ t: 'cue', name: 'error' }); return; }
235
243
  link.heardAt = this.#now();
236
244
  }
237
245
 
@@ -254,7 +262,8 @@ export class Boxes {
254
262
  * GET /api/boxes the boxes, online or not
255
263
  * POST /api/boxes/code {conversation, name?, origin?} -> {code, minutes, key?, link?, qr?}
256
264
  * POST /api/boxes/<id>/rename {name}
257
- * POST /api/boxes/<id>/move {conversation}
265
+ * POST /api/boxes/<id>/move {conversation}: one conversation at a time
266
+ * POST /api/boxes/<id>/place {place}: where it is (a home), shown with its name
258
267
  * POST /api/boxes/<id>/revoke
259
268
  * POST /api/boxes/<id>/volume {level 0-100}
260
269
  * POST /api/boxes/<id>/wifi-scan -> {networks}
@@ -288,6 +297,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
288
297
  switch (what) {
289
298
  case 'rename': boxes.rename(id, body.name); return send(200, { ok: true });
290
299
  case 'move': boxes.move(id, String(body.conversation ?? '')); return send(200, { ok: true });
300
+ case 'place': boxes.place(id, body.place); return send(200, { ok: true });
291
301
  case 'revoke': boxes.revoke(id); return send(200, { ok: true });
292
302
  case 'volume': return answered(await boxes.command(id, { t: 'volume', level: Math.round(Number(body.level)) }));
293
303
  case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
package/server/main.mjs CHANGED
@@ -468,7 +468,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
468
468
  /* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
469
469
  /* Voice boxes: what the tool says in their conversation is read aloud (boxes.mjs). */
470
470
  let boxes;
471
- const talk = new Talk({ spoke: (name, text) => { void boxes?.agentSaid(name, text); }, store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
471
+ const talk = new Talk({ spoke: (name, text, to) => { void boxes?.agentSaid(name, text, to); }, store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
472
472
  ...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
473
473
  /* A line typed down the terminal already open when there is one, and
474
474
  what is already known of a machine used instead of asking (talk.mjs). */
@@ -599,13 +599,16 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
599
599
  exists: (name) => all.list().some((c) => c.name === name),
600
600
  hear: (wav) => voice.transcribe(wav),
601
601
  /* Said as the person's own message, the room named (one speaker for now). */
602
- say: (name, text, room) => talk.say(name, `[${room}] ${text}`, undefined, undefined, 'voice'),
602
+ say: (name, text, by) => talk.say(name, text, undefined, undefined, 'voice', { by }),
603
+ /* 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)); },
603
605
  speak: (text) => speech.speak(text),
604
606
  log: (line) => events.add({ kind: 'server', text: line }) });
605
607
  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) });
606
608
  server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
607
609
  let closing = false;
608
610
  boxes.attach(server, WebSocketServer);
611
+ for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name));
609
612
  bridge = attachBridge(server, {
610
613
  onRejoin: (name) => all.rejoin(name),
611
614
  onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); typingWatch.typed(name, data); },
package/server/talk.mjs CHANGED
@@ -290,7 +290,7 @@ export class Talk {
290
290
  if (event.type === 'person-reacted') { reacted(event); return; }
291
291
  if (event.type === 'person-wrote') { this.#want(name); return; }
292
292
  /* What the tool says or asks: a voice box of this conversation may read it aloud (boxes.mjs). */
293
- if (event.type === 'agent-said' || event.type === 'agent-asked') this.#spoke(name, event.message?.text ?? '');
293
+ if (event.type === 'agent-said' || event.type === 'agent-asked') this.#spoke(name, event.message?.text ?? '', Array.isArray(event.message?.to) ? event.message.to : null);
294
294
  const words = texts(this.#lastLang, this.settings().own);
295
295
  if (event.type === 'agent-asked') this.#alert({ title: fill(words['alert-asks'], { name }), body: event.message.text ?? '', url: `/?c=${name}` });
296
296
  if (event.type === 'agent-status' && event.message.state === 'waiting') this.#alert({ title: fill(words['alert-waits'], { name }), body: event.message.text ?? '', url: `/?c=${name}` });
@@ -444,6 +444,9 @@ export class Talk {
444
444
  return { ...this.of(name), invited: text };
445
445
  }
446
446
 
447
+ /* The voice boxes of a conversation, as Parley names them to its agent and its screen (#215). */
448
+ speakers(name, list) { try { this.#parley(name).setSpeakers(list); } catch { /* its folder is not there yet */ } }
449
+
447
450
  async say(name, text, answers, files, via, extra) {
448
451
  if (!this.of(name).on) throw new Refusal(409, 'Talking through the app is not turned on for this conversation.');
449
452
  const given = files === undefined || files === null ? [] : files;
@@ -465,7 +468,7 @@ export class Talk {
465
468
  never lose a message: on any trouble the text is sent as it came. */
466
469
  let said = text ?? '';
467
470
  if (this.#screen && said) { try { said = await this.#screen(name, said); } catch { said = text ?? ''; } }
468
- try { this.#parley(name).say(said, answers, attached, { via: via === 'voice' ? 'voice' : undefined, ...(extra && typeof extra === 'object' ? { picked: extra.picked, replies: extra.replies, about: extra.about } : {}) }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
471
+ try { this.#parley(name).say(said, answers, attached, { via: via === 'voice' ? 'voice' : undefined, ...(extra && typeof extra === 'object' ? { picked: extra.picked, replies: extra.replies, about: extra.about, by: extra.by } : {}) }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
469
472
  const told = await this.#wake(name);
470
473
  return { ...this.of(name), told };
471
474
  }
package/web/app.js CHANGED
@@ -8801,12 +8801,15 @@
8801
8801
  async function paintBoxes() {
8802
8802
  const list = await getJson('/boxes', []);
8803
8803
  const rows = $('box-list'); rows.replaceChildren();
8804
+ const places = el('datalist'); places.id = 'box-places';
8805
+ for (const p of [...new Set(list.map((b) => b.place).filter(Boolean))]) { const o = el('option'); o.value = p; places.append(o); }
8806
+ rows.append(places);
8804
8807
  if (!list.length) rows.append(el('p', 'hint', 'No voice box yet.'));
8805
8808
  for (const b of list) {
8806
8809
  const card = el('div', 'device card box-card'); card.dataset.box = b.id;
8807
8810
  const head = el('div', 'device-head');
8808
8811
  const conv = conversations.find((c) => c.name === b.conversation);
8809
- head.append(el('b', '', b.name), el('small', b.online ? '' : 'warn', `${b.online ? 'online' : 'offline'} · ${conv ? shownName(conv) : b.conversation}${b.firmware ? ` · firmware ${b.firmware}` : ''}${b.muted ? ' · muted' : ''}`));
8812
+ head.append(el('b', '', b.place ? `${b.name} \u00b7 ${b.place}` : b.name), el('small', b.online ? '' : 'warn', `${b.online ? 'online' : 'offline'} · ${conv ? shownName(conv) : b.conversation}${b.firmware ? ` · firmware ${b.firmware}` : ''}${b.muted ? ' · muted' : ''}`));
8810
8813
  const rename = el('button', '', 'Rename'); rename.type = 'button';
8811
8814
  rename.addEventListener('click', () => {
8812
8815
  const field = el('input'); field.value = b.name; field.maxLength = 40; field.setAttribute('aria-label', 'Name of this voice box');
@@ -8824,7 +8827,10 @@
8824
8827
  where.value = b.conversation;
8825
8828
  where.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/move`, { conversation: where.value }).catch(() => {}); await paintBoxes(); });
8826
8829
  const whereRow = el('label', 'box-where'); whereRow.append('Speaks in ', where);
8827
- const acts = el('div', 'action-row'); acts.append(whereRow, rename, remove);
8830
+ /* Where it is (a home): typed once, then offered for the next ones. */
8831
+ 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}`);
8832
+ place.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/place`, { place: place.value.trim() }).catch(() => {}); await paintBoxes(); });
8833
+ const acts = el('div', 'action-row'); acts.append(whereRow, place, rename, remove);
8828
8834
  card.append(head, acts);
8829
8835
  rows.append(card);
8830
8836
  }