clavarium 0.2.194-next.1 → 0.2.196-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/boxes.mjs +7 -2
- package/server/files.mjs +14 -5
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.196-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.196-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/boxes.mjs
CHANGED
|
@@ -97,6 +97,7 @@ export function forSpeech(text) {
|
|
|
97
97
|
.replace(/\b([01]?\d|2[0-3])\s?[hH](?:\s?([0-5]\d))?\b/g, (_, h, m) => `${h} heure${h === '1' || h === '0' ? '' : 's'}${m ? ` ${m}` : ''}`)
|
|
98
98
|
/* Never its own wake word aloud: the box heard itself and cut its own sentence (31-10). */
|
|
99
99
|
.replace(/\b(?:hey|hé|eh)[\s,]+jarvis\b/giu, 'le mot d\'éveil')
|
|
100
|
+
.replace(/(?<![\p{L}])m[ée]sange(?![\p{L}])/giu, 'le mot d\'éveil')
|
|
100
101
|
.replace(/\s+/g, ' ')
|
|
101
102
|
.trim()
|
|
102
103
|
.slice(0, 1500);
|
|
@@ -128,6 +129,7 @@ export function mix(stream, chunk) {
|
|
|
128
129
|
return out;
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
export const ANSWER_WITHIN_MS = 90_000;
|
|
131
133
|
export const CHAT_WITHIN_MS = 3 * 60_000;
|
|
132
134
|
export const LISTEN_AHEAD = 3 * 32_000; /* bytes: what a box is sent ahead of what it plays (its buffer holds 16 s) */
|
|
133
135
|
|
|
@@ -382,12 +384,15 @@ export class Boxes {
|
|
|
382
384
|
it ends when nobody answers, or on "fin de la conversation". */
|
|
383
385
|
const question = !doing && (asked || /\?\s*$/.test(words));
|
|
384
386
|
for (const l of boxes) {
|
|
385
|
-
|
|
387
|
+
/* An answer -- to a sentence heard within a minute -- may open the conversation; something said
|
|
388
|
+
of itself (a news item, a reminder) does not: the box listened after it for nothing (31-10). */
|
|
389
|
+
const answering = l.heardAt && this.#now() - l.heardAt < ANSWER_WITHIN_MS;
|
|
390
|
+
const chatting = !doing && answering && this.#chatting(l);
|
|
386
391
|
const opening = chatting && !l.chat;
|
|
387
392
|
if (chatting) l.chat = true;
|
|
388
393
|
let pcm;
|
|
389
394
|
try { pcm = await this.#speak(opening ? `Je passe en mode conversation : je reste à l'écoute. ${words}` : words); } catch (error) { this.#log(`voice box: no voice for the answer (${error.message})`); l.send({ t: 'cue', name: 'error' }); continue; }
|
|
390
|
-
l.play(pcm, question || chatting ? 'listen' : null);
|
|
395
|
+
l.play(pcm, question || chatting ? 'listen' : null); /* a question is always listened after: an answer is expected */
|
|
391
396
|
}
|
|
392
397
|
}
|
|
393
398
|
#chatting(link) {
|
package/server/files.mjs
CHANGED
|
@@ -162,6 +162,8 @@ export async function importFile(root, relative, name, request, { exists = 'keep
|
|
|
162
162
|
*/
|
|
163
163
|
export const EDIT_MAX = 1024 * 1024;
|
|
164
164
|
export const THUMB_MAX = 8 * 1024 * 1024;
|
|
165
|
+
/* A sound played in the thread: a few minutes of speech or music. */
|
|
166
|
+
export const SOUND_MAX = 40 * 1024 * 1024;
|
|
165
167
|
/* One drop of files or of a folder: as a whole, this many bytes and files at most. */
|
|
166
168
|
export const BATCH_MAX = 2 * 1024 * 1024 * 1024;
|
|
167
169
|
export const BATCH_FILES = 2000;
|
|
@@ -391,6 +393,11 @@ const SIGNATURES = [
|
|
|
391
393
|
['image/jpeg', (b) => b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff],
|
|
392
394
|
['image/gif', (b) => b.length >= 6 && /^GIF8[79]a$/.test(b.subarray(0, 6).toString('latin1'))],
|
|
393
395
|
['image/webp', (b) => b.length >= 12 && b.subarray(0, 4).toString('latin1') === 'RIFF' && b.subarray(8, 12).toString('latin1') === 'WEBP'],
|
|
396
|
+
/* Sounds, played in the thread as the pictures are shown (Parley's player): proved by their bytes too. */
|
|
397
|
+
['audio/wav', (b) => b.length >= 12 && b.subarray(0, 4).toString('latin1') === 'RIFF' && b.subarray(8, 12).toString('latin1') === 'WAVE'],
|
|
398
|
+
['audio/mpeg', (b) => b.length >= 3 && (b.subarray(0, 3).toString('latin1') === 'ID3' || (b[0] === 0xff && (b[1] & 0xe0) === 0xe0))],
|
|
399
|
+
['audio/ogg', (b) => b.length >= 4 && b.subarray(0, 4).toString('latin1') === 'OggS'],
|
|
400
|
+
['audio/mp4', (b) => b.length >= 12 && b.subarray(4, 8).toString('latin1') === 'ftyp'],
|
|
394
401
|
];
|
|
395
402
|
export const IMAGE_HEADERS = Object.freeze({
|
|
396
403
|
'content-security-policy': "default-src 'none'; sandbox",
|
|
@@ -401,15 +408,17 @@ export const IMAGE_HEADERS = Object.freeze({
|
|
|
401
408
|
});
|
|
402
409
|
export async function picture(root, relative) {
|
|
403
410
|
const at = await regular(root, relative);
|
|
404
|
-
|
|
405
|
-
if (
|
|
411
|
+
const sound = /\.(wav|mp3|ogg|oga|opus|m4a)$/i.test(at.name);
|
|
412
|
+
if (!sound && !/\.(png|jpe?g|gif|webp)$/i.test(at.name)) throw new Refusal(415, 'Only a PNG, JPEG, GIF or WebP picture, or a WAV, MP3, Ogg or M4A sound, is shown in the thread.');
|
|
413
|
+
const most = sound ? SOUND_MAX : THUMB_MAX;
|
|
414
|
+
if (at.info.size > most) throw new Refusal(413, sound ? 'This sound is too large to play here.' : 'This picture is too large for a thumbnail.');
|
|
406
415
|
const handle = await open(at.path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
407
416
|
try {
|
|
408
417
|
const info = await handle.stat();
|
|
409
|
-
if (!info.isFile() || info.size >
|
|
418
|
+
if (!info.isFile() || info.size > most) throw new Refusal(413, 'This file is too large to show here.');
|
|
410
419
|
const bytes = await readAll(handle, info.size);
|
|
411
|
-
const type = SIGNATURES.find(([, is]) => is(bytes))?.[0];
|
|
412
|
-
if (!type) throw new Refusal(415,
|
|
420
|
+
const type = SIGNATURES.find(([kind, is]) => kind.startsWith(sound ? 'audio/' : 'image/') && is(bytes))?.[0];
|
|
421
|
+
if (!type) throw new Refusal(415, `This file is not the ${sound ? 'sound' : 'picture'} its name says.`);
|
|
413
422
|
return { type, bytes, version: versionOf(info) };
|
|
414
423
|
} finally { await handle.close(); }
|
|
415
424
|
}
|