clavarium 0.2.200-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.
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/boxes.mjs +55 -8
- package/web/app.js +4 -2
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
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.
|
|
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.
|
|
764
|
-
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.
|
|
765
|
-
"integrity": "sha512-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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,13 +99,30 @@ 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
|
|
|
110
|
+
/* THE BOX'S CLOCK: its lights follow the hours of its place. The time zone is the page's that made its code
|
|
111
|
+
(its browser's), else this server's; the box is told its offset from UTC at each connection and every hour
|
|
112
|
+
after, so summer time comes by itself. */
|
|
113
|
+
export function zoneOf(zone) {
|
|
114
|
+
const z = String(zone ?? '').trim();
|
|
115
|
+
try { if (z && /^[A-Za-z_]+(?:\/[A-Za-z0-9_+-]+){0,2}$/.test(z)) { new Intl.DateTimeFormat('en', { timeZone: z }); return z; } } catch { /* unknown */ }
|
|
116
|
+
return '';
|
|
117
|
+
}
|
|
118
|
+
export function offsetOf(zone, now) {
|
|
119
|
+
const z = zoneOf(zone) || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
120
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', { timeZone: z, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }).formatToParts(new Date(now)).map((p) => [p.type, p.value]));
|
|
121
|
+
const local = Date.UTC(+parts.year, +parts.month - 1, +parts.day, +parts.hour, +parts.minute);
|
|
122
|
+
return Math.round((local - Math.floor(now / 60_000) * 60_000) / 60_000);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const RELAY_WITHIN_MS = 20_000;
|
|
109
126
|
export const DOING_WITHIN_MS = 120_000;
|
|
110
127
|
/* A LONG RECORDING (a meeting, a class): asked in words, stopped by the button or the wake word. */
|
|
111
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;
|
|
@@ -178,11 +195,11 @@ export class Boxes {
|
|
|
178
195
|
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 }));
|
|
179
196
|
}
|
|
180
197
|
|
|
181
|
-
code(conversation, name) {
|
|
198
|
+
code(conversation, name, zone = '') {
|
|
182
199
|
if (!this.#exists(conversation)) throw new Refusal(404, 'No such conversation.');
|
|
183
200
|
const code = newCode();
|
|
184
201
|
const label = String(name ?? '').trim().slice(0, NAME_MAX);
|
|
185
|
-
this.#codes.set(plainCode(code), { conversation, name: label, until: this.#now() + CODE_MINUTES * 60_000 });
|
|
202
|
+
this.#codes.set(plainCode(code), { conversation, name: label, zone: zoneOf(zone), until: this.#now() + CODE_MINUTES * 60_000 });
|
|
186
203
|
return { code, minutes: CODE_MINUTES };
|
|
187
204
|
}
|
|
188
205
|
|
|
@@ -202,6 +219,7 @@ export class Boxes {
|
|
|
202
219
|
type: String(body.type ?? '').slice(0, 40), firmware: String(body.firmware ?? '').slice(0, 20),
|
|
203
220
|
capabilities: Array.isArray(body.capabilities) ? body.capabilities.map(String).slice(0, 20) : [],
|
|
204
221
|
createdAt: new Date(now).toISOString(), seenAt: null,
|
|
222
|
+
...(wanted.zone ? { zone: wanted.zone } : {}),
|
|
205
223
|
};
|
|
206
224
|
this.#save([...this.#all(), box]);
|
|
207
225
|
this.#log(`voice box paired: ${name} (${box.conversation})`);
|
|
@@ -266,6 +284,20 @@ export class Boxes {
|
|
|
266
284
|
return this.#images.get(String(token).replace(/\.bin$/, ''))?.bytes;
|
|
267
285
|
}
|
|
268
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
|
+
|
|
269
301
|
/* LISTENING TO THE INTERNET: a radio, a podcast, a music file, a playlist, read by this server (ffmpeg,
|
|
270
302
|
any format it knows) and sent on to the box at the pace it is played, a few seconds ahead -- until it
|
|
271
303
|
ends, stop(), or the person presses the button or says the wake word (the box then starts a sentence). */
|
|
@@ -324,7 +356,13 @@ export class Boxes {
|
|
|
324
356
|
}
|
|
325
357
|
|
|
326
358
|
/* Where it is (a home, a family house): grouped by it, named with it. */
|
|
327
|
-
|
|
359
|
+
zone(id, zone) {
|
|
360
|
+
const z = zoneOf(zone);
|
|
361
|
+
if (!z) throw new Refusal(400, 'Not a time zone.');
|
|
362
|
+
this.#change(id, { zone: z });
|
|
363
|
+
this.#links.get(id)?.send({ t: 'clock', offset: offsetOf(z, this.#now()) });
|
|
364
|
+
}
|
|
365
|
+
place(id, place) { this.#change(id, { place: String(place ?? '').trim().slice(0, NAME_MAX) }); }
|
|
328
366
|
|
|
329
367
|
move(id, conversation) {
|
|
330
368
|
if (!this.#exists(conversation)) throw new Refusal(404, 'No such conversation.');
|
|
@@ -450,6 +488,8 @@ export class Boxes {
|
|
|
450
488
|
const wanted = link.box().volume ?? VOLUME_DEFAULT;
|
|
451
489
|
if (m.volume !== wanted) { send({ t: 'volume', id: randomUUID(), level: wanted }); m.volume = wanted; }
|
|
452
490
|
}
|
|
491
|
+
if (m.t === 'hello') send({ t: 'clock', offset: offsetOf(link.box().zone, this.#now()) });
|
|
492
|
+
if (m.t === 'ping' && this.#now() - (link.clockAt ?? 0) > 3_600_000) { link.clockAt = this.#now(); send({ t: 'clock', offset: offsetOf(link.box().zone, this.#now()) }); }
|
|
453
493
|
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; }
|
|
454
494
|
if (m.t === 'record.start' && this.#recordDir) {
|
|
455
495
|
mkdirSync(this.#recordDir, { recursive: true });
|
|
@@ -554,6 +594,10 @@ export class Boxes {
|
|
|
554
594
|
link.send({ t: 'record', on: true });
|
|
555
595
|
return;
|
|
556
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
|
+
}
|
|
557
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; }
|
|
558
602
|
this.#log(`voice box ${box.name}: ${seconds} s heard, said in ${box.conversation}`);
|
|
559
603
|
link.heardAt = this.#now();
|
|
@@ -584,6 +628,7 @@ export class Boxes {
|
|
|
584
628
|
* POST /api/boxes/<id>/rename {name}
|
|
585
629
|
* POST /api/boxes/<id>/move {conversation}: one conversation at a time
|
|
586
630
|
* POST /api/boxes/<id>/place {place}: where it is (a home), shown with its name
|
|
631
|
+
* POST /api/boxes/<id>/zone {zone}: its time zone (IANA), for its clock; the page gives its own
|
|
587
632
|
* POST /api/boxes/<id>/revoke
|
|
588
633
|
* POST /api/boxes/<id>/volume {level 0-100}
|
|
589
634
|
* POST /api/boxes/<id>/wifi-scan -> {networks}
|
|
@@ -602,7 +647,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
602
647
|
for await (const piece of request) { text += piece; if (text.length > 8192) return send(413, { error: 'Too long.' }); }
|
|
603
648
|
const body = text ? JSON.parse(text) : {};
|
|
604
649
|
if (pathname === '/api/boxes/code') {
|
|
605
|
-
const made = boxes.code(String(body.conversation ?? ''), body.name);
|
|
650
|
+
const made = boxes.code(String(body.conversation ?? ''), body.name, body.zone);
|
|
606
651
|
/* With this page's address: the key, and a link (its QR code) that opens the box's page filled in. */
|
|
607
652
|
const origin = /^https?:\/\/[^/\s]+$/.test(String(body.origin ?? '')) ? String(body.origin) : '';
|
|
608
653
|
if (!origin) return send(201, made);
|
|
@@ -618,6 +663,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
618
663
|
case 'rename': boxes.rename(id, body.name); return send(200, { ok: true });
|
|
619
664
|
case 'move': boxes.move(id, String(body.conversation ?? '')); return send(200, { ok: true });
|
|
620
665
|
case 'place': boxes.place(id, body.place); return send(200, { ok: true });
|
|
666
|
+
case 'zone': boxes.zone(id, body.zone); return send(200, { ok: true });
|
|
621
667
|
case 'revoke': boxes.revoke(id); return send(200, { ok: true });
|
|
622
668
|
case 'volume': return answered(await boxes.setVolume(id, body.level));
|
|
623
669
|
case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
|
|
@@ -642,6 +688,7 @@ export function voiceboxConnector(boxes) {
|
|
|
642
688
|
const id = t.config?.box;
|
|
643
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}.` }; }
|
|
644
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.' }; }
|
|
645
692
|
if (verb === 'voicebox.stop') return { text: boxes.stop(id) ? 'Stopped.' : 'Nothing was playing.' };
|
|
646
693
|
if (verb === 'voicebox.play') { const r = boxes.play(id, Buffer.from(String(a.image ?? ''), 'base64')); return { text: `Played (${r.seconds} s).` }; }
|
|
647
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.` }; }
|
package/web/app.js
CHANGED
|
@@ -4442,7 +4442,7 @@
|
|
|
4442
4442
|
row.hidden = true;
|
|
4443
4443
|
const call = async (op, args) => { try { return { ok: true, data: await post(`${API}/tether/${op}`, args) }; } catch (error) { return { ok: false, text: error.message }; } };
|
|
4444
4444
|
/* A device that pairs (a voice box): a one-use code for the conversation that asked, made here. */
|
|
4445
|
-
const pair = async (room) => { const r = await post(`${API}/boxes/code`, { conversation: String(job.agent).replace(/^conversation:/, ''), name: room }); return { url: location.origin, code: r.code }; };
|
|
4445
|
+
const pair = async (room) => { const r = await post(`${API}/boxes/code`, { conversation: String(job.agent).replace(/^conversation:/, ''), name: room, zone: Intl.DateTimeFormat().resolvedOptions().timeZone }); return { url: location.origin, code: r.code }; };
|
|
4446
4446
|
try { const { runJob } = await import('/vendor/tether/jobs.js'); await runJob(job, { call, root: place, pair }); }
|
|
4447
4447
|
catch (error) { place.textContent = `It could not start: ${error.message}`; }
|
|
4448
4448
|
setTimeout(() => { jobPlaces.delete(job.id); after?.(); }, 4000);
|
|
@@ -8864,6 +8864,8 @@
|
|
|
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
|
+
/* A box paired before it knew its time zone takes this page's: its lights follow the hours here. */
|
|
8868
|
+
if (!b.zone) void post(`${API}/boxes/${b.id}/zone`, { zone: Intl.DateTimeFormat().resolvedOptions().timeZone }).catch(() => {});
|
|
8867
8869
|
/* Louder, softer: kept here, given to the box now or when it comes back. */
|
|
8868
8870
|
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
8871
|
const volSaid = el('small', 'hint', `${vol.value} %`);
|
|
@@ -8893,7 +8895,7 @@
|
|
|
8893
8895
|
$('box-code').addEventListener('click', async () => {
|
|
8894
8896
|
if (!$('box-conversation').value) { $('box-conversation').focus(); $('box-code-minutes').textContent = 'Choose the conversation it speaks in first.'; $('box-ready').hidden = false; return; }
|
|
8895
8897
|
try {
|
|
8896
|
-
const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim(), origin: location.origin });
|
|
8898
|
+
const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim(), origin: location.origin, zone: Intl.DateTimeFormat().resolvedOptions().timeZone });
|
|
8897
8899
|
$('box-code-shown').textContent = r.code; $('box-code-minutes').textContent = `valid ${r.minutes} minutes, once`;
|
|
8898
8900
|
$('box-key').textContent = r.key ?? '';
|
|
8899
8901
|
$('box-link').href = r.link ?? '#';
|