clavarium 0.2.206-next.1 → 0.2.210-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 +38 -3
- package/server/main.mjs +1 -0
- package/server/voice.mjs +24 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.210-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.210-next.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.
|
|
16
|
+
"clavarium-parley": "0.17.35-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.46",
|
|
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.
|
|
751
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.
|
|
752
|
-
"integrity": "sha512-
|
|
750
|
+
"version": "0.17.35-next.1",
|
|
751
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.35-next.1.tgz",
|
|
752
|
+
"integrity": "sha512-bUR/1I9ZqEXWJ7SoxPYdkjlOHJ8dnML5A0ZQGfuEOl4YNuB6ULT4PoWqHfj0fVhY2j6BjDLvHJKZJ8WouEGXig==",
|
|
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.
|
|
3
|
+
"version": "0.2.210-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.",
|
|
@@ -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.
|
|
49
|
+
"clavarium-parley": "0.17.35-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.46",
|
|
51
51
|
"mermaid": "11.17.2",
|
|
52
52
|
"node-pty": "^1.1.0",
|
package/server/boxes.mjs
CHANGED
|
@@ -132,6 +132,18 @@ export function sentencesOf(text) {
|
|
|
132
132
|
return out.filter(Boolean);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
export const THINKING_AFTER_MS = 3_500;
|
|
136
|
+
export const LONGER_AFTER_MS = 12_000;
|
|
137
|
+
export const THINKING = ['Hmm…', 'Voyons…', 'Hmm, voyons voir…'];
|
|
138
|
+
/* WHY A BOX LISTENED, in a few words beside the message (01-11): what woke it (and the wake word's score), and
|
|
139
|
+
what it cut short. */
|
|
140
|
+
export function whyOf(m) {
|
|
141
|
+
const reason = { wake: 'mot d\'éveil', button: 'bouton', follow: 'suite de la conversation', knock: 'toc-toc' }[m?.reason] ?? (m?.reason ? String(m.reason).slice(0, 30) : 'inconnu');
|
|
142
|
+
const score = Number.isFinite(m?.score) ? ` (${Math.round(m.score * 100)} %)` : '';
|
|
143
|
+
const cut = m?.cut ? ` ; a interrompu ${String(m.cut) === 'its own speech' ? 'sa propre phrase' : 'un son'}` : '';
|
|
144
|
+
return `réveil : ${reason}${score}${cut}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
135
147
|
export const DOING_WITHIN_MS = 120_000;
|
|
136
148
|
/* A LONG RECORDING (a meeting, a class): asked in words, stopped by the button or the wake word. */
|
|
137
149
|
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;
|
|
@@ -200,11 +212,12 @@ export function piecesOf(pcm, { least = 8, most = 14 } = {}) {
|
|
|
200
212
|
|
|
201
213
|
export class Boxes {
|
|
202
214
|
#file; #codes = new Map(); #links = new Map(); #tries = []; #now;
|
|
203
|
-
#exists; #hear; #say; #speak; #log; #changed; #images = new Map(); #origin; #spawn; #fetch; #streams = new Map(); #recordDir; #parts; #keep;
|
|
215
|
+
#exists; #hear; #say; #speak; #log; #changed; #images = new Map(); #origin; #spawn; #fetch; #streams = new Map(); #recordDir; #parts; #keep; #react;
|
|
204
216
|
|
|
205
217
|
/* file: a JsonFile holding [{ id, name, conversation, keyHash, firmware, createdAt, seenAt }].
|
|
206
218
|
exists(conversation), hear(wav) -> text, say(conversation, text, room), speak(text) -> PCM 16 kHz. */
|
|
207
|
-
constructor({ file, exists = () => true, hear, say, speak, changed = () => {}, origin = () => null, now = () => Date.now(), log = () => {}, spawn = spawnProcess, fetcher = fetch, recordDir = null, parts = null, keep = null }) {
|
|
219
|
+
constructor({ file, exists = () => true, hear, say, speak, changed = () => {}, origin = () => null, now = () => Date.now(), log = () => {}, spawn = spawnProcess, fetcher = fetch, recordDir = null, parts = null, keep = null, react = async () => null }) {
|
|
220
|
+
this.#react = react;
|
|
208
221
|
this.#spawn = spawn; this.#fetch = fetcher; this.#recordDir = recordDir; this.#parts = parts; this.#keep = keep;
|
|
209
222
|
this.#file = file; this.#changed = changed; this.#origin = origin; this.#exists = exists; this.#hear = hear; this.#say = say; this.#speak = speak; this.#now = now; this.#log = log;
|
|
210
223
|
}
|
|
@@ -429,6 +442,23 @@ export class Boxes {
|
|
|
429
442
|
/* The tool said or asked something in a conversation: said aloud only by the boxes it is
|
|
430
443
|
addressed to (`to`: box ids, #215). Anything else stays in the thread, silent -- a box
|
|
431
444
|
read a whole technical message aloud once (31-10), which nobody wants. */
|
|
445
|
+
/* WHILE THE ANSWER IS THOUGHT (01-11): no long silence after a sentence. A short « hmm » if nothing has
|
|
446
|
+
come after a little while, then a word that it takes longer; whatever the assistant says first (an answer,
|
|
447
|
+
what it is doing) ends the wait. A longer question (many words) is told sooner that it takes a moment. */
|
|
448
|
+
#waitFor(link, text = '') {
|
|
449
|
+
clearTimeout(link.thinkingA); clearTimeout(link.thinkingB);
|
|
450
|
+
const said = link.heardAt;
|
|
451
|
+
const still = () => link.heardAt === said && !((link.answeredAt ?? 0) >= said);
|
|
452
|
+
const long = String(text).length > 160; /* a long question: told sooner that it takes a moment */
|
|
453
|
+
const say = async (words) => { if (!still() || link.recording || this.#streams.has(link.box().id)) return; try { link.play(await this.#speak(words)); } catch { /* the light says it */ } };
|
|
454
|
+
/* Made at once, used if the answer is still not there: a reaction to THIS sentence, in its language. */
|
|
455
|
+
let made = null;
|
|
456
|
+
this.#react(text).then((t) => { made = t; }).catch(() => {});
|
|
457
|
+
link.thinkingA = setTimeout(() => { void say(made || THINKING[Math.floor(Math.random() * THINKING.length)]); }, THINKING_AFTER_MS);
|
|
458
|
+
link.thinkingB = setTimeout(() => { void say(long ? 'Ta question est riche, je regarde, un instant.' : 'Ça me demande un peu plus de temps, je regarde.'); }, long ? LONGER_AFTER_MS * 0.6 : LONGER_AFTER_MS);
|
|
459
|
+
link.thinkingA.unref?.(); link.thinkingB.unref?.();
|
|
460
|
+
}
|
|
461
|
+
|
|
432
462
|
async agentSaid(conversation, text, to = null, { doing = false, asked = false } = {}) {
|
|
433
463
|
/* What it is doing is written for a screen ("Tâche de fond : bêta 0.2.113…"): read aloud, it was words
|
|
434
464
|
from nowhere (31-10). Aloud, only a short plain one; otherwise a word that it is at work. */
|
|
@@ -449,6 +479,7 @@ export class Boxes {
|
|
|
449
479
|
asked for ("mode conversation"), or by itself after two sentences within three minutes (31-10);
|
|
450
480
|
it ends when nobody answers, or on "fin de la conversation". */
|
|
451
481
|
const question = !doing && (asked || /\?\s*$/.test(words));
|
|
482
|
+
for (const l of boxes) { l.answeredAt = this.#now(); clearTimeout(l.thinkingA); clearTimeout(l.thinkingB); }
|
|
452
483
|
for (const l of boxes) {
|
|
453
484
|
/* An answer -- to a sentence heard within a minute -- may open the conversation; something said
|
|
454
485
|
of itself (a news item, a reminder) does not: the box listened after it for nothing (31-10). */
|
|
@@ -535,6 +566,9 @@ export class Boxes {
|
|
|
535
566
|
r.out.end(() => { void this.#recorded(link, r); });
|
|
536
567
|
return;
|
|
537
568
|
}
|
|
569
|
+
if (m.t === 'event' && m.name === 'wake.own') { this.#log(`voice box ${box.name}: heard its own voice say the wake word, ignored`); return; }
|
|
570
|
+
if (m.t === 'event' && m.name === 'noise.dropped') { this.#log(`voice box ${box.name}: a sound near full scale was cut by its noise guard`); return; }
|
|
571
|
+
if (m.t === 'listen.start') link.why = whyOf(m);
|
|
538
572
|
if (m.t === 'listen.start') { if (this.stop(box.id)) this.#log(`voice box ${box.name}: stopped playing, someone speaks`); sentence = []; size = 0; return; }
|
|
539
573
|
if (m.t === 'listen.end' && sentence && m.reason === 'nobody') {
|
|
540
574
|
/* Listened again, nobody spoke: a conversation ends there, in silence. */
|
|
@@ -630,9 +664,10 @@ export class Boxes {
|
|
|
630
664
|
link.relay = 0;
|
|
631
665
|
text = `(réponse entendue de l'appareil, pas de la personne) ${text}`;
|
|
632
666
|
}
|
|
633
|
-
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; }
|
|
667
|
+
try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}), ...(link.why ? { why: link.why } : {}) }); } 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; }
|
|
634
668
|
this.#log(`voice box ${box.name}: ${seconds} s heard, said in ${box.conversation}`);
|
|
635
669
|
link.heardAt = this.#now();
|
|
670
|
+
this.#waitFor(link, text);
|
|
636
671
|
link.recent = [...(link.recent ?? []), link.heardAt];
|
|
637
672
|
if (/\bmode conversation\b/i.test(text)) link.chat = true;
|
|
638
673
|
if (/\b(?:fin|arr[eê]te|stop)\w*\b.{0,20}\b(?:conversation|[ée]couter)\b/i.test(text)) { link.chat = false; link.recent = []; }
|
package/server/main.mjs
CHANGED
|
@@ -606,6 +606,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
606
606
|
boxes = new Boxes({ file: new JsonFile(`${dataDir}/boxes.json`, []),
|
|
607
607
|
exists: (name) => all.list().some((c) => c.name === name),
|
|
608
608
|
/* A long recording (a meeting): transcribed in parts, kept beside the conversation for its assistant. */
|
|
609
|
+
react: (said) => voice.reaction(said),
|
|
609
610
|
recordDir: `${dataDir}/recordings`, parts: (wav) => voice.transcribeParts(wav), keep: (name, file, text) => talk.keepText(name, file, text),
|
|
610
611
|
hear: (wav) => voice.transcribe(wav, undefined, { oneVoice: true }), /* the language of the dictation settings, or found by the engine: no language is assumed (a box has no browser to tell one) */
|
|
611
612
|
/* Said as the person's own message, the room named (one speaker for now). */
|
package/server/voice.mjs
CHANGED
|
@@ -191,6 +191,26 @@ export async function transcribeParts(config, audio, fetcher = fetch) {
|
|
|
191
191
|
return text ? [{ speaker: null, start: 0, text }] : [];
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/* A SHORT REACTION while the answer is thought (a voice box, 01-11): a few words in the person's language that
|
|
195
|
+
acknowledge what was said without answering it -- « bonne question, voyons… ». Only where the dictation's
|
|
196
|
+
service also offers a fast chat model (OVH AI Endpoints); null otherwise, or when it is not quick. */
|
|
197
|
+
export const REACTION_MODEL = 'Mistral-Small-3.2-24B-Instruct-2506';
|
|
198
|
+
export async function quickReaction(config, said, fetcher = fetch) {
|
|
199
|
+
if (!config?.key || !DIARIZES.test(String(config.url))) return null;
|
|
200
|
+
const base = String(config.url).replace(/\/audio\/transcriptions\/?$/, '');
|
|
201
|
+
try {
|
|
202
|
+
const r = await fetcher(`${base}/chat/completions`, {
|
|
203
|
+
method: 'POST', redirect: 'error', headers: { 'content-type': 'application/json', authorization: `Bearer ${config.key}` }, signal: AbortSignal.timeout(3000),
|
|
204
|
+
body: JSON.stringify({ model: REACTION_MODEL, temperature: 0.8, max_tokens: 24, messages: [
|
|
205
|
+
{ role: 'system', content: 'Someone just spoke to a voice assistant, which needs a few seconds to answer. Write ONE very short spoken reaction (2 to 7 words) in the SAME language as what they said, natural and warm, that acknowledges it without answering it and without promising anything: e.g. "Bonne question, voyons…", "Ah, intéressant, je regarde.", "Hmm, let me see…". No quotes, no emoji. Answer with the reaction only.' },
|
|
206
|
+
{ role: 'user', content: String(said).slice(0, 600) }] }),
|
|
207
|
+
});
|
|
208
|
+
if (!r.ok) return null;
|
|
209
|
+
const t = String((await r.json())?.choices?.[0]?.message?.content ?? '').replace(/["«»]/g, '').trim();
|
|
210
|
+
return t && t.length <= 60 && !/\n/.test(t) ? t : null;
|
|
211
|
+
} catch { return null; }
|
|
212
|
+
}
|
|
213
|
+
|
|
194
214
|
/* ---------- THE ENGINE CHOSEN IN SETTINGS ----------
|
|
195
215
|
* Settings > Dictation: a provider fills in the address and the model (both
|
|
196
216
|
* may be changed); the key is one of the SECRETS already kept (Assets >
|
|
@@ -324,6 +344,10 @@ export class Dictation {
|
|
|
324
344
|
/* An expired key is never sent: said in one line instead (still offered, so the line is seen). */
|
|
325
345
|
#fresh(c) { if (c?.secret && this.#expired(c.secret)) throw new Refusal(409, KEY_EXPIRED); }
|
|
326
346
|
/* `device`: the language of the device that dictates (a tag such as fr-FR), if it said. */
|
|
347
|
+
async reaction(said) {
|
|
348
|
+
const config = this.current();
|
|
349
|
+
return config ? quickReaction(config, said, this.#fetcher) : null;
|
|
350
|
+
}
|
|
327
351
|
async transcribeParts(audio) {
|
|
328
352
|
this.#fresh(this.#saved());
|
|
329
353
|
const config = this.current();
|