clavarium 0.2.201-next.1 → 0.2.203-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.201-next.1",
3
+ "version": "0.2.203-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.201-next.1",
9
+ "version": "0.2.203-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.45",
17
+ "clavarium-tether": "0.1.0-next.46",
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.45",
764
- "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.45.tgz",
765
- "integrity": "sha512-3lZT2MHeQWcfF8241K2+N+/ZX8wluFe0HqlrUPbTgSMws+RqQh61mEzk0Z9vlHSoG5aGhQ5b8CwK1QqBwGp9nQ==",
763
+ "version": "0.1.0-next.46",
764
+ "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.46.tgz",
765
+ "integrity": "sha512-p6B9kM1A4CUN/OyLWf5IpsKvQ5SiTir7P+X2BcnRQBml+S9z/1nS0Xs7vxhk4ekDui/x0Dh5xMOO4IvaCLhaeA==",
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.201-next.1",
3
+ "version": "0.2.203-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.45",
50
+ "clavarium-tether": "0.1.0-next.46",
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
@@ -86,8 +86,8 @@ export function pcmOfWav(wav) {
86
86
  }
87
87
 
88
88
  /* Text for the ear: what a written message holds and a voice should not read. */
89
- export function forSpeech(text) {
90
- return String(text ?? '')
89
+ export function forSpeech(text, { callOthers = false } = {}) {
90
+ const said = String(text ?? '')
91
91
  .replace(/```[\s\S]*?```/g, ' ')
92
92
  .replace(/`([^`]*)`/g, '$1')
93
93
  .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
@@ -99,11 +99,12 @@ export function forSpeech(text) {
99
99
  .replace(/\b(?:hey|hé|eh)[\s,]+jarvis\b/giu, 'le mot d\'éveil')
100
100
  .replace(/(?<![\p{L}])m[ée]sanges?(?![\p{L}])/giu, 'le mot d\'éveil')
101
101
  .replace(/(?<![\p{L}])m[eéè]s[\s-]+anges?(?![\p{L}])/giu, 'le mot d\'éveil') /* what sounds like it: « mes anges » woke it (31-10) */
102
- /* Nor another assistant's call: « OK Google » said in an example woke the Google Home beside it (31-10). */
103
- .replace(/\b(?:ok|okay|hey|dis)[\s,]+(?:google|siri|alexa)\b/giu, 'l\'appel de l\'enceinte')
104
102
  .replace(/\s+/g, ' ')
105
103
  .trim()
106
104
  .slice(0, 1500);
105
+ /* Nor another assistant's call: « OK Google » said in an example woke the Google Home beside it (31-10).
106
+ Only speakTo() calls it, on purpose. */
107
+ return callOthers ? said : said.replace(/\b(?:ok|okay|hey|dis)[\s,]+(?:google|siri|alexa)\b/giu, 'l\'appel de l\'enceinte');
107
108
  }
108
109
 
109
110
  /* THE BOX'S CLOCK: its lights follow the hours of its place. The time zone is the page's that made its code
@@ -121,6 +122,7 @@ export function offsetOf(zone, now) {
121
122
  return Math.round((local - Math.floor(now / 60_000) * 60_000) / 60_000);
122
123
  }
123
124
 
125
+ export const RELAY_WITHIN_MS = 20_000;
124
126
  export const DOING_WITHIN_MS = 120_000;
125
127
  /* A LONG RECORDING (a meeting, a class): asked in words, stopped by the button or the wake word. */
126
128
  export const RECORD_ASKED = /\b(?:lance|d[ée]marre|commence|d[ée]bute)\w*\b.{0,25}\benregistrement\b|\benregistre\b.{0,20}\b(?:r[ée]union|conversation|cours|discussion|consultation)\b/i;
@@ -282,6 +284,20 @@ export class Boxes {
282
284
  return this.#images.get(String(token).replace(/\.bin$/, ''))?.bytes;
283
285
  }
284
286
 
287
+ /* SPEAKING TO ANOTHER DEVICE in the room (a Google Home: « OK Google, baisse la clim »): said as given, its
288
+ call included, then the box listens; what it hears within twenty seconds comes back to the conversation as
289
+ that device's answer, not as the person's words (31-10: the box set the heating that way). */
290
+ async speakTo(id, text) {
291
+ const link = this.#links.get(id);
292
+ if (!link) throw new Refusal(409, 'This voice box is not connected.');
293
+ const words = forSpeech(text, { callOthers: true });
294
+ if (!words) throw new Refusal(400, 'Nothing to say.');
295
+ link.play(await this.#speak(words), 'listen');
296
+ link.relay = this.#now();
297
+ this.#log(`voice box ${link.box().name}: spoke to a device in the room`);
298
+ return { ok: true };
299
+ }
300
+
285
301
  /* LISTENING TO THE INTERNET: a radio, a podcast, a music file, a playlist, read by this server (ffmpeg,
286
302
  any format it knows) and sent on to the box at the pace it is played, a few seconds ahead -- until it
287
303
  ends, stop(), or the person presses the button or says the wake word (the box then starts a sentence). */
@@ -578,6 +594,10 @@ export class Boxes {
578
594
  link.send({ t: 'record', on: true });
579
595
  return;
580
596
  }
597
+ if (link.relay && this.#now() - link.relay < RELAY_WITHIN_MS) {
598
+ link.relay = 0;
599
+ text = `(réponse entendue de l'appareil, pas de la personne) ${text}`;
600
+ }
581
601
  try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}) }); } catch (error) { this.#log(`voice box ${box.name}: ${seconds} s heard and dictated, but not said in ${box.conversation} (${error.message})`); await lost("Pardon, je n'ai pas pu transmettre ta phrase. Tu peux répéter ?"); return; }
582
602
  this.#log(`voice box ${box.name}: ${seconds} s heard, said in ${box.conversation}`);
583
603
  link.heardAt = this.#now();
@@ -668,6 +688,7 @@ export function voiceboxConnector(boxes) {
668
688
  const id = t.config?.box;
669
689
  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}.` }; }
670
690
  if (verb === 'voicebox.listen') { await boxes.listen(id, String(a.url), String(a.name ?? '')); return { text: `Playing ${a.name || a.url}: it goes on until it ends, voicebox-stop, or the person presses the button or says the wake word.` }; }
691
+ if (verb === 'voicebox.speak') { await boxes.speakTo(id, String(a.text ?? '')); return { text: 'Said aloud; the box listens now: what it hears in the next 20 s comes back in the conversation, marked as the device\'s answer.' }; }
671
692
  if (verb === 'voicebox.stop') return { text: boxes.stop(id) ? 'Stopped.' : 'Nothing was playing.' };
672
693
  if (verb === 'voicebox.play') { const r = boxes.play(id, Buffer.from(String(a.image ?? ''), 'base64')); return { text: `Played (${r.seconds} s).` }; }
673
694
  if (verb === 'voicebox.update') { await boxes.update(id, a.image, a.version); return { text: `Installed${a.version ? ` (${a.version})` : ''}: the box restarts and comes back in a moment.` }; }