clavarium 0.2.461-next.1 → 0.2.463-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,17 +1,17 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.461-next.1",
3
+ "version": "0.2.463-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.461-next.1",
9
+ "version": "0.2.463-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
- "clavarium-binder": "0.1.62-next.1",
14
+ "clavarium-binder": "0.1.63-next.1",
15
15
  "clavarium-docket": "0.1.2-next.2",
16
16
  "clavarium-parley": "0.17.95-next.1",
17
17
  "clavarium-tether": "0.1.0-next.67",
@@ -761,9 +761,9 @@
761
761
  }
762
762
  },
763
763
  "node_modules/clavarium-binder": {
764
- "version": "0.1.62-next.1",
765
- "resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.62-next.1.tgz",
766
- "integrity": "sha512-YhBt+k29zbASU931T5kPAnsZwo5JVgGw94HRs4UoKL2WHK4WVvmn54RCzTBSnHCWuvo4Lc27eLcxl0rNb+6Yug==",
764
+ "version": "0.1.63-next.1",
765
+ "resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.63-next.1.tgz",
766
+ "integrity": "sha512-+zk4f8JRnF7D3z2g17QkeoUIlBYooQZ5arSDsMNF4MtmyBeLQ429ou97bMb2zslCwCwxv9QgrbIbUQF8AnsSzg==",
767
767
  "license": "MIT",
768
768
  "bin": {
769
769
  "binder": "bin/binder.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.461-next.1",
3
+ "version": "0.2.463-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.",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@xterm/addon-fit": "^0.11.0",
47
47
  "@xterm/xterm": "^6.0.0",
48
- "clavarium-binder": "0.1.62-next.1",
48
+ "clavarium-binder": "0.1.63-next.1",
49
49
  "clavarium-docket": "0.1.2-next.2",
50
50
  "clavarium-parley": "0.17.95-next.1",
51
51
  "clavarium-tether": "0.1.0-next.67",
package/server/api.mjs CHANGED
@@ -6,7 +6,7 @@
6
6
  * POST /api/conversations {name, tool, memoryMb?}
7
7
  * POST /api/conversations/<name>/sleep
8
8
  * POST /api/conversations/<name>/restart a clean stop (by force if it hangs), then a start
9
- * GET /api/conversations/<name>/export[?all=1] its tool's state, or everything of it, one archive (#351) POST .../import[?replaceWork=1] put back (same tool)
9
+ * GET /api/conversations/<name>/export[?all=1] its tool's state, or everything of it, one archive (#351) POST .../import[?replaceWork=1&reminders=1] put back (same tool)
10
10
  * POST /api/conversations/<name>/machine {memoryMb?, diskGb?, cpus?}: stopped, set, started again (202);
11
11
  * asleep: checked and kept for its wake, as `sizeAtWake` (200)
12
12
  * POST /api/conversations/<name>/machine {action: start|stop|restart|sleep|force|force-now}: done on its machine,
@@ -321,7 +321,7 @@ export async function handleApi(request, response, conversations, headers, resou
321
321
  if (carry && request.method === 'POST' && carry[2] === 'import') {
322
322
  if (!originOk(request.headers) || request.headers['content-type'] !== 'application/octet-stream') return send(403, { error: 'This request does not come from this site.' }), true;
323
323
  /* ?replaceWork=1: a whole export may replace the work folder that holds files (asked first, on the page). */
324
- return send(200, await conversations.importState(decodeURIComponent(carry[1]), request, { replaceWork: query.get('replaceWork') === '1' })), true;
324
+ return send(200, await conversations.importState(decodeURIComponent(carry[1]), request, { replaceWork: query.get('replaceWork') === '1', reminders: query.get('reminders') === '1' })), true;
325
325
  }
326
326
  if (pathname.startsWith('/api/files/')) {
327
327
  if (request.method === 'POST' && !originOk(request.headers)) return send(403, { error: 'This request does not come from this site.' }), true;
package/server/carry.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  machine's part (its home) is in conversations.mjs (exportWhole, importState).
5
5
 
6
6
  The archive, in this order:
7
- clavarium-conversation.json its manifest (version 2, `whole`): its tool, its title, its sizes, its accesses
7
+ clavarium-conversation.json its manifest (version 2, `whole`): its tool, its title, its sizes, its accesses, its wake-ups
8
8
  home/... its home, without what is rebuilt or thrown away (HOME_LEFT_OUT)
9
9
  work/... its work folder, read here (it is kept on this server) */
10
10
  import { spawn } from 'node:child_process';
@@ -92,12 +92,14 @@ export function unpackHere(file, into) {
92
92
  }
93
93
 
94
94
  /* ITS WORK PUT BACK, here: what it holds now thrown away only when asked (`replace`), then each entry of the
95
- export's work/ moved in (the same disk: a rename). */
95
+ export's work/ moved in (the same disk: a rename). Its docket (.docket) is neither: the one here stays its
96
+ own, and the export's reminders come only when asked (`reminders`, conversations.mjs importState). */
97
+ const DOCKET_DIR = '.docket';
96
98
  export function restoreWork(from, workDir, replace) {
97
- if (replace) for (const e of readdirSync(workDir)) if (e !== CARRY) rmSync(join(workDir, e), { recursive: true, force: true });
99
+ if (replace) for (const e of readdirSync(workDir)) if (e !== CARRY && e !== DOCKET_DIR) rmSync(join(workDir, e), { recursive: true, force: true });
98
100
  let entries = [];
99
101
  try { entries = readdirSync(from); } catch { return; }
100
- for (const e of entries) if (e !== CARRY) renameSync(join(from, e), join(workDir, e));
102
+ for (const e of entries) if (e !== CARRY && e !== DOCKET_DIR) renameSync(join(from, e), join(workDir, e));
101
103
  }
102
104
 
103
105
  /* WHAT IT WAS GIVEN, for a whole export, each by its id: a folder, a repository or a mailbox by its asset
@@ -160,6 +160,10 @@ export class Conversations {
160
160
  only (never its value); and the same given again on an import, where it exists here -> { linked, missing }. */
161
161
  accessesOf = async () => ({});
162
162
  relink = async () => ({ linked: [], missing: [] });
163
+ /* Set by the server: its wake-ups, for a whole export; and on its import, when asked, its reminders (from the
164
+ export's work folder) and those wake-ups given again (15-11, as a copy does). */
165
+ wakeupsOf = () => undefined;
166
+ importReminders = async () => {};
163
167
 
164
168
  /* `uid`/`gid`: the account this server runs as; files the tool writes in
165
169
  its kept work folder belong to it on the host. */
@@ -989,7 +993,7 @@ export class Conversations {
989
993
  if ((await this.#vms.state(name).catch(() => undefined)) !== 'Running') throw new Refusal(409, 'Its machine is not running: open the conversation first.', { retry: false });
990
994
  const tool = this.#tools.find((t) => t.id === c.tool);
991
995
  const accesses = await this.accessesOf(name);
992
- const manifest = JSON.stringify({ kind: 'clavarium-conversation', version: 2, whole: true, tool: c.tool, name: c.name, ...(c.title ? { title: c.title } : {}), memoryMb: c.memoryMb, cpus: c.cpus ?? 1, diskGb: c.diskGb ?? DISK_GB, at: new Date().toISOString(), accesses });
996
+ const manifest = JSON.stringify({ kind: 'clavarium-conversation', version: 2, whole: true, tool: c.tool, name: c.name, ...(c.title ? { title: c.title } : {}), memoryMb: c.memoryMb, cpus: c.cpus ?? 1, diskGb: c.diskGb ?? DISK_GB, at: new Date().toISOString(), accesses, wakeups: this.wakeupsOf(name) });
993
997
  const id = `whole-${Date.now()}`;
994
998
  /* In its machine: the manifest, then its home as home/ (a link's target left as it is), one block per record
995
999
  so that its work can follow it (carry.mjs). Globs off: the words left out are given to tar as they are. */
@@ -1014,8 +1018,9 @@ export class Conversations {
1014
1018
  /* PUT BACK an exported state in this conversation (same tool): its tool stopped, the archive unpacked in
1015
1019
  its home, its tool started again, taking up its last session. -> { tool, from } */
1016
1020
  /* A WHOLE export (exportWhole) puts back its home, its work folder and its accesses: its work only into an empty
1017
- one, unless `replaceWork` -- what is there is never thrown away silently. -> { tool, from, whole, linked, toLink } */
1018
- async importState(name, input, { replaceWork = false } = {}) {
1021
+ one, unless `replaceWork` -- what is there is never thrown away silently; its reminders and wake-ups only when
1022
+ asked (`reminders`). -> { tool, from, whole, linked, toLink } */
1023
+ async importState(name, input, { replaceWork = false, reminders = false } = {}) {
1019
1024
  const c = this.#busyCheck(name);
1020
1025
  const tool = this.#tools.find((t) => t.id === c.tool);
1021
1026
  if ((await this.#vms.state(name).catch(() => undefined)) !== 'Running') throw new Refusal(409, 'Its machine is not running: open the conversation first.', { retry: false });
@@ -1049,6 +1054,7 @@ export class Conversations {
1049
1054
  if (r.code !== 0) throw new Refusal(502, `Not imported: ${firstLine(r.stderr) || `exit ${r.code}`}`);
1050
1055
  restoreWork(join(stage, 'work'), workDir, replaceWork);
1051
1056
  const { linked, missing } = await this.relink(name, manifest.accesses ?? {});
1057
+ if (reminders) await Promise.resolve().then(() => this.importReminders(name, join(stage, 'work'), manifest.wakeups)).catch(() => {});
1052
1058
  return { tool: c.tool, from: { name: manifest.name, at: manifest.at }, whole: true, linked, toLink: missing };
1053
1059
  } finally { this.ready(name); }
1054
1060
  } finally {
package/server/main.mjs CHANGED
@@ -721,6 +721,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
721
721
  mailbox by its asset, a secret by its name only (never its value), its Tether targets and its lists by theirs. */
722
722
  all.accessesOf = async (name) => accessesOf({ folders, secrets, tethers, binders, talk, guide }, name);
723
723
  /* ITS IMPORT: each given again where the same id exists here, with the same level (as copyRights does). */
724
+ all.wakeupsOf = (name) => wakeups.exportOf(name);
725
+ all.importReminders = (name, work, given) => { copyPlans(work, folders.workFolder(name)); wakeups.importTo(name, given); };
724
726
  all.relink = (name, given) => relinkAccesses({ folders, secrets, tethers, binders, talk, guide, gitKeeper }, name, given);
725
727
  /* A tool that ended cut for lack of memory: said in the events, to the owner, and in its chat. */
726
728
  all.onToolExit = (name, report) => {
@@ -186,7 +186,7 @@ export const SETTINGS_WORDS_FR = {
186
186
  'set-carry': 'Exporter / Importer', 'set-carry-hint': 'Mémoire de son IA, ou tout : à emporter.',
187
187
  'set-carry-export': 'Mémoire de son IA', 'set-carry-all': 'Tout (dossier perso, travail, accès)', 'set-carry-all-off': 'Son travail doit être gardé ici.',
188
188
  'set-carry-replace': 'Son travail a des fichiers. Tout remplacer ?', 'set-carry-replace-go': 'Remplacer son travail',
189
- 'set-carry-tolink': 'À relier à la main :', 'set-carry-import': 'Importer…', 'set-carry-go': 'Importer',
189
+ 'set-carry-tolink': 'À relier à la main :', 'set-carry-import': 'Importer…', 'set-carry-reminders': 'Importer aussi ses rappels et réveils', 'set-carry-go': 'Importer',
190
190
  'set-carry-ask': '« {file} » dans « {name} » ? Mémoire remplacée.', 'set-carry-done': 'Importé depuis « {from} ».',
191
191
  'set-mcp-drop': 'Collez ici la configuration du service', 'set-mcp-drop-hint': 'le bloc { "mcpServers": … } de sa page d\'aide',
192
192
  'set-mcp-hand': 'Remplir à la main', 'set-mcp-add-n': 'Ajouter les {n}', 'set-mcp-nokey': 'aucune',
@@ -28,6 +28,7 @@
28
28
  import { createHash } from 'node:crypto';
29
29
  import { readFileSync, writeFileSync, readdirSync, renameSync, rmSync, existsSync, mkdirSync } from 'node:fs';
30
30
  import { join } from 'node:path';
31
+ import { NODE_STEPS } from './tools.mjs';
31
32
  import { fileURLToPath } from 'node:url';
32
33
  import { APP, ARCHIVES, MACHINE_TOOLS, archiveName, locked, packageDir, packageVersion } from './parley.mjs';
33
34
 
@@ -58,6 +59,7 @@ export const parleySource = (options = {}) => toolSource(MACHINE_TOOLS.find((t)
58
59
 
59
60
  /* "sha512-<base64>", as npm writes an integrity. */
60
61
  const NO_NPM = 'there is no npm in this machine';
62
+ const NODE_STEP_MS = 15 * 60_000;
61
63
  export const integrityOf = (bytes) => `sha512-${createHash('sha512').update(bytes).digest('base64')}`;
62
64
 
63
65
  const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) ?? '';
@@ -192,8 +194,13 @@ export class Toolbox {
192
194
  const exec = (argv, timeoutMs = 30_000) => this.#vms.exec(conversation, argv, { timeoutMs }).catch(() => ({ code: 1, stdout: '', stderr: '' }));
193
195
  const there = async () => { const v = await exec([tool.name, '--version']); return v.code === 0 && v.stdout.trim() === tool.version; };
194
196
  if (await there()) return '';
195
- /* A machine without node (a plain shell): said once, until it is built again or restarted. */
196
- if ((await exec(['which', 'npm'])).code !== 0) return NO_NPM;
197
+ /* A machine without node (a plain shell, a tool whose recipe has none): node first, as a tool's "node"
198
+ step gives it; still none, said once, until it is built again or restarted. */
199
+ if ((await exec(['which', 'npm'])).code !== 0) {
200
+ const why = await this.#node(conversation);
201
+ if (why) return why;
202
+ if ((await exec(['which', 'npm'])).code !== 0) return NO_NPM;
203
+ }
197
204
  /* The archive as the machine reads it, against the index; /tools mounted again once if it is not there. */
198
205
  const sum = async () => /^([0-9a-f]{64})\s/.exec((await exec(['sha256sum', '--', tool.path], 60_000)).stdout ?? '')?.[1];
199
206
  let seen = await sum();
@@ -206,6 +213,15 @@ export class Toolbox {
206
213
  return '';
207
214
  }
208
215
 
216
+ /* NODE IN A MACHINE WITHOUT IT: the steps of tools.mjs (its checksum checked before it is unpacked). '' or why not. */
217
+ async #node(conversation) {
218
+ for (const [i, step] of NODE_STEPS.entries()) {
219
+ const r = await this.#vms.exec(conversation, step.argv, { input: step.input, timeoutMs: NODE_STEP_MS }).catch(() => ({ code: 1, stdout: '', stderr: '' }));
220
+ if (r.code !== 0) return `node could not be installed (step ${i + 1}): ${firstLine(r.stderr) || firstLine(r.stdout) || `exit ${r.code}`}`;
221
+ }
222
+ return '';
223
+ }
224
+
209
225
  /* THE LAUNCHER OF A TOOL, there in its machine before the tool starts: when /tools is
210
226
  missing or came loose, it is repaired (below) and looked at again. '' or why not --
211
227
  then the tool does not start: never a start in a half-made state. */
@@ -246,6 +246,27 @@ export class Wakeups {
246
246
  return this.of(to);
247
247
  }
248
248
 
249
+ /* A WHOLE EXPORT'S WAKE-UPS (15-11): what each is, never its id, its clock or a call from outside (its address
250
+ is the original's). Given again on its import when asked, each through add(): checked as one written here;
251
+ one that is not (its folder not attached here) is left out. -> how many */
252
+ exportOf(name) {
253
+ const r = this.#record(name);
254
+ return { perHour: r.perHour, items: r.items.filter((i) => i.kind !== 'call').map(({ kind, on, message, resource, onlyNew, quiet, minutes, at, line }) => ({ kind, on, message, resource, onlyNew, quiet, minutes, at, line })) };
255
+ }
256
+ importTo(name, given) {
257
+ let n = 0;
258
+ try { if (given?.perHour !== undefined) this.setLimit(name, given.perHour); } catch { /* not a cap */ }
259
+ for (const i of (Array.isArray(given?.items) ? given.items : []).slice(0, ITEMS_MAX)) {
260
+ if (!i || typeof i !== 'object' || i.kind === 'call') continue;
261
+ try {
262
+ const made = this.add(name, i).items.at(-1);
263
+ if (i.on === false) this.turn(name, made.id, false);
264
+ n++;
265
+ } catch { /* not one this conversation can have */ }
266
+ }
267
+ return n;
268
+ }
269
+
249
270
  #change(name, id, change) {
250
271
  this.#known(name);
251
272
  const r = this.#record(name);
package/web/app.js CHANGED
@@ -2695,6 +2695,7 @@
2695
2695
  $('carry-export-all').title = here?.work !== 'kept' ? uiSaid('set-carry-all-off', 'Its work must be kept here.') : '';
2696
2696
  $('carry-export-all').onclick = allOff ? (event) => { event.preventDefault(); } : null;
2697
2697
  $('carry-import').disabled = down;
2698
+ $('carry-reminders').checked = false; $('carry-reminders').disabled = down;
2698
2699
  $('carry-said').hidden = !down;
2699
2700
  if (down) {
2700
2701
  const start = Object.assign(document.createElement('button'), { type: 'button', className: 'inline', textContent: here.asleep === true ? uiSaid('set-wake-it', 'Wake it') : uiSaid('set-m-start', 'Start') });
@@ -2704,13 +2705,14 @@
2704
2705
  $('carry-import').onclick = () => $('carry-file').click();
2705
2706
  /* Sent; a whole export into a work folder that holds files asks first, then is sent again to replace it.
2706
2707
  What it was given that does not exist here is listed after, to link by hand. */
2707
- const carryImport = async (name, file, replaceWork) => {
2708
+ const carryImport = async (name, file, replaceWork, reminders) => {
2708
2709
  try {
2709
- const r = await fetch(`${API}/conversations/${encodeURIComponent(name)}/import${replaceWork ? '?replaceWork=1' : ''}`, { method: 'POST', headers: { 'content-type': 'application/octet-stream' }, body: file });
2710
+ const query = [replaceWork ? 'replaceWork=1' : '', reminders ? 'reminders=1' : ''].filter(Boolean).join('&');
2711
+ const r = await fetch(`${API}/conversations/${encodeURIComponent(name)}/import${query ? `?${query}` : ''}`, { method: 'POST', headers: { 'content-type': 'application/octet-stream' }, body: file });
2710
2712
  const said = await r.json().catch(() => ({}));
2711
2713
  if (!r.ok && said.kind === 'work-not-empty') {
2712
2714
  show(uiSaid('set-carry-replace', 'Its work folder has files. Replace them all?'), uiSaid('set-carry-replace-go', 'Replace its work'),
2713
- () => carryImport(name, file, true), () => { notice.hidden = true; focusTerminal(); });
2715
+ () => carryImport(name, file, true, reminders), () => { notice.hidden = true; focusTerminal(); });
2714
2716
  return;
2715
2717
  }
2716
2718
  if (!r.ok) throw new Error(said.error ?? `HTTP ${r.status}`);
@@ -2722,10 +2724,10 @@
2722
2724
  $('carry-file').onchange = () => {
2723
2725
  const file = $('carry-file').files?.[0]; $('carry-file').value = '';
2724
2726
  if (!file) return;
2725
- const name = current;
2727
+ const name = current; const reminders = $('carry-reminders').checked;
2726
2728
  leavePanel();
2727
2729
  show(uiSaid('set-carry-ask', '« {file} » into « {name} »? Its memory is replaced.', { file: file.name, name }),
2728
- uiSaid('set-carry-go', 'Import'), () => carryImport(name, file, false), () => { notice.hidden = true; focusTerminal(); });
2730
+ uiSaid('set-carry-go', 'Import'), () => carryImport(name, file, false, reminders), () => { notice.hidden = true; focusTerminal(); });
2729
2731
  };
2730
2732
  void paintAnswerer(); paintWakeups(); void paintTalkBox(); void paintShareHere();
2731
2733
  paintMachine(here);
package/web/index.html CHANGED
@@ -247,6 +247,7 @@
247
247
  <div class="panel-top"><b data-said="set-carry">Export / Import</b></div>
248
248
  <p class="hint" data-said="set-carry-hint">Its AI's memory, or everything: to take elsewhere.</p>
249
249
  <div class="row"><a id="carry-export" class="button" download data-said="set-carry-export">Its AI's memory</a><a id="carry-export-all" class="button" download data-said="set-carry-all">Everything (home, work, accesses)</a><button type="button" id="carry-import" data-said="set-carry-import">Import...</button><input type="file" id="carry-file" accept=".gz,application/gzip" hidden></div>
250
+ <label class="cm-tick"><input type="checkbox" id="carry-reminders"> <span data-said="set-carry-reminders">Import its reminders and wake-ups too</span></label>
250
251
  <p id="carry-said" class="hint" role="status" hidden></p>
251
252
  </div>
252
253
  <!-- WHEN ITS MACHINE IS SHORT (server/healthreact.mjs): you are told either way. -->
package/web/voice-core.js CHANGED
@@ -144,3 +144,26 @@ export function toWav(blocks, rate = RATE) {
144
144
  }
145
145
  return new Uint8Array(bytes);
146
146
  }
147
+
148
+ /* PHRASES IN THE ORDER THEY WERE SPOKEN: each is transcribed on its own, and a short one comes back before a
149
+ long one said before it. `order()` takes a place when a phrase ends; that place is later given what to do
150
+ with its result (or nothing: failed, empty), and runs only once every place before it was given its own. */
151
+ export function inOrder() {
152
+ let taken = 0;
153
+ let next = 0;
154
+ const held = new Map();
155
+ return () => {
156
+ const place = taken++;
157
+ let given = false;
158
+ return (run) => {
159
+ if (given) return;
160
+ given = true;
161
+ held.set(place, run);
162
+ while (held.has(next)) {
163
+ const done = held.get(next);
164
+ held.delete(next); next++;
165
+ try { done?.(); } catch { /* one that throws never holds the rest */ }
166
+ }
167
+ };
168
+ };
169
+ }
package/web/voice.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* DICTATION IN THE PAGE: the microphone stays open, each spoken phrase is
2
2
  transcribed and handed to whoever listens. The page types it into the
3
3
  terminal. See voice-core.js for how a phrase is found. */
4
- import { RATE, BLOCK, BLOCK_MS, Detector, Segmenter, loudness, levelOf, levelBars, toWav } from './voice-core.js';
4
+ import { RATE, BLOCK, BLOCK_MS, Detector, Segmenter, loudness, levelOf, levelBars, toWav, inOrder } from './voice-core.js';
5
5
 
6
6
  /* The operator's pages ask /api; a paired device asks /c/api/<its pairing>,
7
7
  known once it has signed in (the page writes it on the document). */
@@ -28,17 +28,19 @@ async function listen(on, { to } = {}) {
28
28
  const detector = new Detector();
29
29
  let pending = 0;
30
30
  let closed = false;
31
+ const order = inOrder();
31
32
  const tell = () => { if (!closed) on.state(pending > 0 ? 'transcribing' : segmenter.speaking ? 'hearing' : detector.ready() ? 'listening' : 'calibrating'); };
32
33
  const segmenter = new Segmenter({
33
34
  onStart: () => { on.speech?.(); tell(); },
34
35
  onPhrase: async (blocks) => {
35
36
  pending++; tell();
37
+ const place = order();
36
38
  try {
37
39
  const r = await fetch(withLanguage(to ?? `${api()}/voice`), { method: 'POST', headers: { 'content-type': 'audio/wav' }, body: toWav(blocks) });
38
40
  const j = await r.json().catch(() => ({}));
39
41
  if (!r.ok) throw new Error(j.error || 'The phrase could not be transcribed.');
40
- if (!closed && j.text) on.phrase(j.text);
41
- } catch (error) { if (!closed) on.error(error.message); }
42
+ place(j.text ? () => { if (!closed) on.phrase(j.text); } : null);
43
+ } catch (error) { place(null); if (!closed) on.error(error.message); }
42
44
  pending--; tell();
43
45
  },
44
46
  });