shadok-ai 0.20.35 → 0.20.37

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/README.md CHANGED
@@ -118,7 +118,8 @@ Enter to skip; you can add it later from the web UI).
118
118
  (under *+ new agent*) makes one in the group on screen, its + makes a
119
119
  sub-folder, and folders nest up to 8 levels. Drag an agent onto a folder to put
120
120
  it inside, or onto another agent to sit beside it; drag a folder onto a folder
121
- to nest it. A click folds a folder (folded, it shows the mood and agent count of
121
+ to nest it, or between agents and chats to place it there — a folder no longer
122
+ has to sit above them. A click folds a folder (folded, it shows the mood and agent count of
122
123
  all it holds); × removes it and what it held moves up a level. Folders are only
123
124
  an arrangement: they change nothing about who sees an agent or where it runs —
124
125
  a folder belongs to its group and is seen exactly by those who see the group.
@@ -355,7 +356,9 @@ Enter to skip; you can add it later from the web UI).
355
356
  browser's maker. To keep it on your server, an admin picks version menu →
356
357
  *Web dictation* → *On this server (whisper)*: the clip is transcribed by the
357
358
  local model, after a wait. Other browsers and Telegram/WhatsApp voice notes
358
- always use the local model.
359
+ always use the local model, and so does a browser whose recogniser fails
360
+ (a network that cannot reach its speech service, say): the same click
361
+ switches to recording for the server, and says so.
359
362
  - **Dictate a prompt on the web** — a 🎙 button beside *Send* records your
360
363
  microphone and transcribes it with the **same local whisper.cpp** the voice
361
364
  notes use (nothing leaves the machine). The text drops into the composer
@@ -6,6 +6,14 @@ export interface Folder {
6
6
  parent: string | null;
7
7
  /** The group the folder lives in; null = Main (the commons). */
8
8
  group: string | null;
9
+ /**
10
+ * What the folder sits right after, among its level's items: an agent
11
+ * (`a:<sessionId>`), a chat room (`r:<roomId>`) or another folder
12
+ * (`f:<id>`). Absent = first, where every folder sat before folders could be
13
+ * placed among agents. An anchor that is gone is resolved by the client
14
+ * (public/agent-folders.js `levelOrder`), so it is stored as given.
15
+ */
16
+ after?: string;
9
17
  }
10
18
  /** An agent as far as folders care: its id and the folder it is filed in. */
11
19
  export interface FiledItem {
@@ -15,6 +15,7 @@ import { MAIN_GROUP_ID } from "./groups.js";
15
15
  export const MAX_FOLDER_DEPTH = 8;
16
16
  const ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
17
17
  const NAME_MAX = 60;
18
+ const AFTER_RE = /^[afr]:[A-Za-z0-9_.:-]{1,100}$/;
18
19
  /** null and "main" both mean the commons — one spelling on disk. */
19
20
  export function folderGroupKey(g) {
20
21
  if (typeof g !== "string" || !g || g === MAIN_GROUP_ID)
@@ -59,6 +60,8 @@ export function sanitizeFolders(raw) {
59
60
  const icon = cleanIcon(row.icon);
60
61
  if (icon)
61
62
  f.icon = icon;
63
+ if (typeof row.after === "string" && AFTER_RE.test(row.after) && row.after !== "f:" + id)
64
+ f.after = row.after;
62
65
  out.push(f);
63
66
  }
64
67
  const byId = new Map(out.map((f) => [f.id, f]));
@@ -132,6 +135,10 @@ export function mergeFoldersPut(stored, incoming, visibleGroups) {
132
135
  merged.icon = next.icon;
133
136
  else
134
137
  delete merged.icon;
138
+ if (next.after)
139
+ merged.after = next.after;
140
+ else
141
+ delete merged.after;
135
142
  out.push(merged);
136
143
  }
137
144
  for (const r of rows) {
@@ -1 +1 @@
1
- {"version":3,"file":"agent-folders.js","sourceRoot":"","sources":["../src/agent-folders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAkB5C;gFACgF;AAChF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,KAAK,GAAG,uBAAuB,CAAC;AACtC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,oEAAoE;AACpE,MAAM,UAAU,cAAc,CAAC,CAAU;IACvC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,aAAa;QAAE,OAAO,IAAI,CAAC;IACpE,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,SAAS,CAAC,C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5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",
@@ -96,3 +96,63 @@ export function removeFolder(folders, items, id) {
96
96
  for (const it of items || []) if (it.folder != null && String(it.folder) === sid) refile.set(String(it.id), up);
97
97
  return { folders: next, refile };
98
98
  }
99
+
100
+ /** The anchor that names a folder, as another folder's `after`. */
101
+ export const folderAnchor = (id) => "f:" + id;
102
+
103
+ /**
104
+ * One level of the agents column, in order: its root items interleaved with its
105
+ * folders. `items` are the anchors of the level's root tabs in their own order
106
+ * (`a:<sessionId>`, `r:<roomId>`, null for a tab not yet keyed); `kids` are the
107
+ * level's folders, sorted by name. A folder sits right after its `after`; one
108
+ * with no anchor, or an anchor that is not at this level (an agent closed or
109
+ * moved elsewhere, an agent this viewer cannot see, a loop of folders) goes
110
+ * first — where every folder sat before they could be placed among agents, so
111
+ * nothing is ever hidden. Returns `{folder}` / `{item: index}` entries.
112
+ */
113
+ export function levelOrder(items, kids) {
114
+ const present = new Set((items || []).filter((k) => k != null));
115
+ for (const f of kids || []) present.add(folderAnchor(f.id));
116
+ const byAnchor = new Map();
117
+ const first = [];
118
+ for (const f of kids || []) {
119
+ const a = f.after ?? null;
120
+ if (a == null || a === folderAnchor(f.id) || !present.has(a)) first.push(f);
121
+ else (byAnchor.get(a) || byAnchor.set(a, []).get(a)).push(f);
122
+ }
123
+ const done = new Set();
124
+ const emitFolder = (out, f) => {
125
+ if (done.has(f.id)) return;
126
+ done.add(f.id);
127
+ out.push({ folder: f });
128
+ for (const g of byAnchor.get(folderAnchor(f.id)) || []) emitFolder(out, g);
129
+ };
130
+ const out = [];
131
+ for (const f of first) emitFolder(out, f);
132
+ (items || []).forEach((k, i) => {
133
+ out.push({ item: i });
134
+ if (k != null) for (const g of byAnchor.get(k) || []) emitFolder(out, g);
135
+ });
136
+ // Folders anchored on each other in a loop are reached from nothing: first.
137
+ const lost = [];
138
+ for (const f of kids || []) if (!done.has(f.id)) emitFolder(lost, f);
139
+ return lost.length ? [...lost, ...out] : out;
140
+ }
141
+
142
+ /**
143
+ * The anchors a level's folders get from where they sit on screen — the DOM is
144
+ * the source of the order, as for agents. `entries` in screen order are
145
+ * `{folder: id}` / `{item: anchor|null}`; each folder anchors on the nearest
146
+ * KEYED entry above it, or nothing when it leads the level.
147
+ */
148
+ export function anchorsFromOrder(entries) {
149
+ const out = new Map();
150
+ let prev = null;
151
+ for (const e of entries || []) {
152
+ if (e.folder != null) {
153
+ out.set(String(e.folder), prev);
154
+ prev = folderAnchor(e.folder);
155
+ } else if (e.item != null) prev = e.item;
156
+ }
157
+ return out;
158
+ }
package/public/index.html CHANGED
@@ -4948,8 +4948,10 @@
4948
4948
  window.focusTarget = focusTarget;
4949
4949
  window.groupMoveRefusal = groupMoveRefusal;
4950
4950
  import { searchEmoji, looksLikeEmoji } from "/emoji-search.js?v=__ASSET_V__";
4951
- import { newFolderId, canMoveFolder, folderChildren, effectiveFolder, removeFolder } from "/agent-folders.js?v=__ASSET_V__";
4951
+ import { newFolderId, canMoveFolder, folderChildren, effectiveFolder, removeFolder, levelOrder, anchorsFromOrder } from "/agent-folders.js?v=__ASSET_V__";
4952
4952
  window.newFolderId = newFolderId;
4953
+ window.levelOrder = levelOrder;
4954
+ window.anchorsFromOrder = anchorsFromOrder;
4953
4955
  window.canMoveFolder = canMoveFolder;
4954
4956
  window.folderChildren = folderChildren;
4955
4957
  window.effectiveFolder = effectiveFolder;
@@ -5325,6 +5327,10 @@
5325
5327
  folderChildren: () => () => [],
5326
5328
  effectiveFolder: () => null,
5327
5329
  removeFolder: (folders) => ({ folders, refile: new Map() }),
5330
+ // Folders first, as before they could sit among agents; and no anchor read
5331
+ // off the screen, so nothing is rewritten until the module is in.
5332
+ levelOrder: (items, kids) => [...(kids || []).map((folder) => ({ folder })), ...(items || []).map((_, item) => ({ item }))],
5333
+ anchorsFromOrder: () => new Map(),
5328
5334
  // Families before the module lands: a flat column, every agent a root.
5329
5335
  familyParents: () => new Map(),
5330
5336
  familyChildren: () => () => [],
@@ -6822,6 +6828,7 @@
6822
6828
  if (tab.roomId) return closeRoom(tab);
6823
6829
  if (tab.isMain) return; // the environment's main channel is never closed
6824
6830
  if (!confirmEndAgent(tab)) return;
6831
+ releaseFolderAnchor(tab);
6825
6832
  // Full close: end the channel everywhere (stop the agent, delete its
6826
6833
  // Telegram topic, drop it from the registry). Use the HTTP endpoint so it
6827
6834
  // works even when the session is dead (no live WebSocket) — a zombie channel
@@ -7057,7 +7064,7 @@
7057
7064
  fetch("/agent-folders", {
7058
7065
  method: "PUT",
7059
7066
  headers: { "Content-Type": "application/json", "x-shadok-instance": instanceKey },
7060
- body: JSON.stringify(folders.map(({ id, name, icon, parent, group }) => ({ id, name, icon, parent, group }))),
7067
+ body: JSON.stringify(folders.map(({ id, name, icon, parent, group, after }) => ({ id, name, icon, parent, group, after }))),
7061
7068
  }).then((r) => {
7062
7069
  if (r.status === 409) return handleSwap();
7063
7070
  foldersDirtyUntil = 0;
@@ -7070,7 +7077,7 @@
7070
7077
  if (tabbar.querySelector(".folder-head input.rename")) return;
7071
7078
  folders = list
7072
7079
  .filter((f) => f && f.id != null)
7073
- .map((f) => ({ id: String(f.id), name: f.name || "folder", icon: f.icon, parent: f.parent ?? null, group: f.group ?? null }));
7080
+ .map((f) => ({ id: String(f.id), name: f.name || "folder", icon: f.icon, parent: f.parent ?? null, group: f.group ?? null, after: f.after ?? undefined }));
7074
7081
  layoutFolders();
7075
7082
  }
7076
7083
  const folderById = (id) => folders.find((f) => f.id === String(id)) || null;
@@ -7159,8 +7166,10 @@
7159
7166
  /**
7160
7167
  * Put every agent of every group in its folder. The DOM stays the source of
7161
7168
  * the ORDER (as for groups and tabs); this only nests it: at each level the
7162
- * sub-folders (by name) come first, then the agents in their own order. A
7163
- * no-op when the column already matches, so it can run on every repaint.
7169
+ * agents keep their own order and each sub-folder sits right after the item
7170
+ * it was dropped below (its `after`, public/agent-folders.js `levelOrder`) —
7171
+ * first when it has none. A no-op when the column already matches, so it can
7172
+ * run on every repaint.
7164
7173
  */
7165
7174
  function layoutFolders() {
7166
7175
  if (dragTabEl || dragFolderId != null) return;
@@ -7197,9 +7206,13 @@
7197
7206
  const k = kidEls(b);
7198
7207
  return "t" + (b._tab?.id ?? "") + (k.length ? ",[" + k.map(tabSig).join(",") + "]" : "");
7199
7208
  };
7209
+ // A level, in order: its root agents interleaved with its folders.
7210
+ const level = (parent) => {
7211
+ const roots = tabEls.filter((b) => place(b) === parent && isRoot(b));
7212
+ return window.levelOrder(roots.map(tabAnchor), kids(parent)).map((e) => (e.folder ? e : { tab: roots[e.item] }));
7213
+ };
7200
7214
  const desired = (parent) =>
7201
- [...kids(parent).map((f) => "f" + f.id + "(" + desired(f.id) + ")"),
7202
- ...tabEls.filter((b) => place(b) === parent && isRoot(b)).map(tabSig)].join(",");
7215
+ level(parent).map((e) => (e.folder ? "f" + e.folder.id + "(" + desired(e.folder.id) + ")" : tabSig(e.tab))).join(",");
7203
7216
  const actual = (box) =>
7204
7217
  [...box.children].map((ch) =>
7205
7218
  ch.classList.contains("agent-folder") ? "f" + ch.dataset.folder + "(" + actual(ch._folderBody) + ")"
@@ -7218,12 +7231,12 @@
7218
7231
  for (const c of k) putTab(body, c);
7219
7232
  };
7220
7233
  const build = (box, parent) => {
7221
- for (const f of kids(parent)) {
7222
- const rec = folderEl(f);
7234
+ for (const e of level(parent)) {
7235
+ if (!e.folder) { putTab(box, e.tab); continue; }
7236
+ const rec = folderEl(e.folder);
7223
7237
  box.appendChild(rec.el);
7224
- build(rec.body, f.id);
7238
+ build(rec.body, e.folder.id);
7225
7239
  }
7226
- for (const b of tabEls) if (place(b) === parent && isRoot(b)) putTab(box, b);
7227
7240
  };
7228
7241
  const keep = new Set();
7229
7242
  const mark = (parent) => { for (const f of kids(parent)) { keep.add(f.id); mark(f.id); } };
@@ -7236,6 +7249,61 @@
7236
7249
  for (const el of [...scope.querySelectorAll(".kin-body")]) if (!usedKin.has(el)) el.remove();
7237
7250
  }
7238
7251
 
7252
+ /** What a folder can sit right after: an agent, or a chat room (null: a tab
7253
+ * not keyed yet, which nothing can anchor on). */
7254
+ function tabAnchor(b) {
7255
+ const t = b && b._tab;
7256
+ if (!t) return null;
7257
+ if (t.roomId) return "r:" + t.roomId;
7258
+ return t.sessionId ? "a:" + t.sessionId : null;
7259
+ }
7260
+ /** A level box's entries in screen order: its folders and its root tabs
7261
+ * (a family body only nests children, it is not an entry). */
7262
+ function levelEntries(box) {
7263
+ const out = [];
7264
+ for (const ch of box.children) {
7265
+ if (ch.classList.contains("agent-folder")) out.push({ folder: ch.dataset.folder });
7266
+ else if (ch.classList.contains("tab")) out.push({ item: tabAnchor(ch) });
7267
+ }
7268
+ return out;
7269
+ }
7270
+ /**
7271
+ * Read every folder's place back off the screen after a drag — the DOM is the
7272
+ * source of the order. A folder whose stored anchor already lands it where it
7273
+ * shows is left alone, even when the screen would name another anchor: a
7274
+ * viewer who cannot see the agent a folder follows must not rewrite it.
7275
+ */
7276
+ function syncFolderAnchors() {
7277
+ let changed = false;
7278
+ const boxes = [ungroupedEl, ...groups.map((g) => g.bodyEl), ...[...folderEls.values()].map((r) => r.body)];
7279
+ for (const box of boxes) {
7280
+ const entries = levelEntries(box);
7281
+ const shownAnchors = new Set(entries.map((e) => (e.folder != null ? "f:" + e.folder : e.item)).filter(Boolean));
7282
+ for (const [id, anchor] of window.anchorsFromOrder(entries)) {
7283
+ const f = folderById(id);
7284
+ if (!f) continue;
7285
+ const effective = f.after && shownAnchors.has(f.after) ? f.after : null;
7286
+ if (effective === anchor) continue;
7287
+ if (anchor) f.after = anchor; else delete f.after;
7288
+ changed = true;
7289
+ }
7290
+ }
7291
+ if (changed) persistFolders();
7292
+ }
7293
+ /** An agent about to close hands its followers to what sits above it, so a
7294
+ * folder below it stays put instead of jumping to the top of its level. */
7295
+ function releaseFolderAnchor(tab) {
7296
+ const key = tabAnchor(tab.btnEl);
7297
+ const box = tab.btnEl.parentNode;
7298
+ if (!key || !box || !folders.some((f) => f.after === key)) return;
7299
+ const entries = levelEntries(box);
7300
+ const at = entries.findIndex((e) => e.item === key);
7301
+ let prev = null;
7302
+ for (let i = at - 1; i >= 0 && prev == null; i--) prev = entries[i].folder != null ? "f:" + entries[i].folder : entries[i].item;
7303
+ for (const f of folders) if (f.after === key) { if (prev) f.after = prev; else delete f.after; }
7304
+ persistFolders();
7305
+ }
7306
+
7239
7307
  /** The fold toggle of every parent: caret + count, and — folded — the mood of
7240
7308
  * the agents it hides. Guarded writes, for the same reason as the folders'. */
7241
7309
  function paintKin() {
@@ -7477,7 +7545,19 @@
7477
7545
  // The folder an agent was dropped in is read off where it landed. A room is
7478
7546
  // not an agent: it has no folder, and the next layout puts it back at its root.
7479
7547
  if (dragTabEl && dragTabEl._tab && !draggedRoom) dragTabEl._tab.folder = domFolderOf(dragTabEl);
7480
- if (dragFolderId != null) folderEls.get(dragFolderId)?.el.classList.remove("dragging");
7548
+ if (dragFolderId != null) {
7549
+ // Same for a folder: its parent is wherever it was left on screen (only a
7550
+ // valid target ever moves it there, see the dragover).
7551
+ const rec = folderEls.get(dragFolderId);
7552
+ const f = folderById(dragFolderId);
7553
+ if (rec) rec.el.classList.remove("dragging");
7554
+ if (rec && f) {
7555
+ const parent = domFolderOf(rec.el);
7556
+ // A new level: the old anchor means nothing there (syncFolderAnchors,
7557
+ // below, reads the new one off the screen).
7558
+ if ((f.parent ?? null) !== parent) { f.parent = parent; delete f.after; persistFolders(); }
7559
+ }
7560
+ }
7481
7561
  document.querySelectorAll(".folder-head.drop-target").forEach((h) => h.classList.remove("drop-target"));
7482
7562
  if (dragTabEl) dragTabEl.classList.remove("dragging");
7483
7563
  if (dragGroupEl) dragGroupEl.classList.remove("dragging");
@@ -7487,6 +7567,7 @@
7487
7567
  document.querySelectorAll(".rail-item.drop-target, .rail-item.dragging").forEach((r) => r.classList.remove("drop-target", "dragging"));
7488
7568
  persistChannels();
7489
7569
  if (wasGroup) persistGroups();
7570
+ if (!wasGroup) syncFolderAnchors();
7490
7571
  layoutFolders();
7491
7572
  railSig = "";
7492
7573
  renderRail();
@@ -7515,6 +7596,29 @@
7515
7596
  e.preventDefault();
7516
7597
  e.dataTransfer.dropEffect = "move";
7517
7598
  if (target != null) folderEls.get(target)?.head.classList.add("drop-target");
7599
+ // Live-sort, as for agents: the folder moves where it would land, so it
7600
+ // can sit above, between or below the agents of its level. What the
7601
+ // screen shows on release is what is kept (endDrag reads it back).
7602
+ const moving = folderEls.get(dragFolderId)?.el;
7603
+ if (!moving) return;
7604
+ const overHead = e.target.closest(".folder-head");
7605
+ const overTab = e.target.closest(".tab");
7606
+ const overFolder = !overHead && e.target.closest(".agent-folder");
7607
+ if (overHead) {
7608
+ const rec = folderEls.get(target);
7609
+ // Unfolded, so the folder stays in sight once it is inside.
7610
+ if (rec && foldedFolders.delete(String(target))) { saveFolded(); paintFolderHeads(); }
7611
+ if (rec && moving.parentNode !== rec.body) rec.body.appendChild(moving);
7612
+ } else if (overTab && overTab.parentNode && !overTab.parentNode.classList.contains("kin-body") && !overTab.classList.contains("tweak")) {
7613
+ const r = overTab.getBoundingClientRect();
7614
+ const after = e.clientY > r.top + r.height / 2;
7615
+ // A tab with a family body: "after" means after its children too.
7616
+ const next = after ? (overTab.nextElementSibling?.classList.contains("kin-body") ? overTab.nextElementSibling.nextSibling : overTab.nextSibling) : overTab;
7617
+ if (next !== moving && moving.nextSibling !== next) overTab.parentNode.insertBefore(moving, next);
7618
+ } else if (!overFolder) {
7619
+ const zone = e.target.closest("#ungrouped, .group-body, .folder-body");
7620
+ if (zone && moving.parentNode !== zone && !moving.contains(zone)) zone.appendChild(moving);
7621
+ }
7518
7622
  return;
7519
7623
  }
7520
7624
  e.preventDefault();
@@ -13082,7 +13186,7 @@
13082
13186
  const cur = promptInput.value;
13083
13187
  const at = promptInput.selectionStart ?? cur.length;
13084
13188
  const before = cur.slice(0, at), after = cur.slice(promptInput.selectionEnd ?? at);
13085
- let heard = false;
13189
+ let heard = false, lastError = null;
13086
13190
  rec.onresult = (e) => {
13087
13191
  if (liveRec !== rec) return;
13088
13192
  const t = ld.liveTranscript(Array.from(e.results, (r) => ({ final: r.isFinal, text: r[0] ? r[0].transcript : "" })));
@@ -13095,18 +13199,31 @@
13095
13199
  autosizePrompt();
13096
13200
  updateSendDisabled();
13097
13201
  };
13202
+ // The verdict waits for `end`, which always follows an `error`: that is
13203
+ // where a recogniser that failed WITHOUT naming an error shows up too.
13098
13204
  rec.onerror = (e) => {
13099
13205
  if (liveRec !== rec) return;
13100
- const f = ld.recognitionFailure(e.error);
13101
- // A recogniser that refuses here will refuse again: the next click records
13102
- // for the server instead.
13103
- if (f.fallback) liveBroken = true;
13104
- if (f.message && !(e.error === "no-speech" && heard)) micMsg(f.message);
13206
+ lastError = e.error || "unknown";
13207
+ // Kept in the console: the one trace there is when a browser refuses.
13208
+ console.warn("live dictation: recogniser error", lastError);
13105
13209
  };
13106
13210
  rec.onend = () => {
13107
13211
  if (liveRec !== rec) return;
13212
+ const f = ld.recognitionEnd({ requested: rec.shadokStopRequested === true, heard, error: lastError });
13108
13213
  liveRec = null;
13109
13214
  endRecordingUI();
13215
+ if (f.fallback) {
13216
+ // A recogniser that refuses here will refuse again: record for the
13217
+ // server now, in the same click, rather than leave the person to
13218
+ // guess that a second one would work.
13219
+ liveBroken = true;
13220
+ if (!lastError) console.warn("live dictation: recogniser ended with no result and no error");
13221
+ // Said only once the recording runs: a refused microphone keeps
13222
+ // startRecording's own message.
13223
+ startRecording().then(() => { if (micRec) micMsg(f.message); });
13224
+ return;
13225
+ }
13226
+ if (f.message && !(lastError === "no-speech" && heard)) micMsg(f.message);
13110
13227
  promptInput.focus();
13111
13228
  };
13112
13229
  try { rec.start(); } catch { liveBroken = true; return startRecording(); }
@@ -13132,6 +13249,9 @@
13132
13249
  endRecordingUI();
13133
13250
  try { rec.abort(); } catch { /* already over */ }
13134
13251
  } else {
13252
+ // Asked to finish: an end with nothing heard is then the person's own
13253
+ // stop, not a recogniser that gave up (`recognitionEnd`).
13254
+ rec.shadokStopRequested = true;
13135
13255
  try { rec.stop(); } catch { /* already over: onend clears the button */ }
13136
13256
  }
13137
13257
  }
@@ -62,8 +62,9 @@ export function spliceDictation(before, spoken, after) {
62
62
 
63
63
  /**
64
64
  * What a recognition error means for the person. `message` is shown (null: say
65
- * nothing); `fallback` means the browser cannot do this at all here — the next
66
- * click should record for the server instead of failing the same way again.
65
+ * nothing); `fallback` means the browser cannot do this at all here — the page
66
+ * records for the server at once, and every later click does too, instead of
67
+ * failing the same way again.
67
68
  */
68
69
  export function recognitionFailure(error) {
69
70
  switch (error) {
@@ -74,6 +75,23 @@ export function recognitionFailure(error) {
74
75
  default:
75
76
  // network, service-not-allowed, language-not-supported, or a name this
76
77
  // list does not know: the recogniser is not usable in this browser.
77
- return { message: "Browser dictation is unavailable here — click again to use the server's", fallback: true };
78
+ return { message: FALLBACK_MESSAGE, fallback: true };
78
79
  }
79
80
  }
81
+
82
+ const FALLBACK_MESSAGE = "Browser dictation is unavailable here — recording for the server instead, speak again";
83
+
84
+ /**
85
+ * What a recogniser that ENDED means, once its error (if any) is known. Most
86
+ * failures name themselves through `error`; this adds the one that does not.
87
+ * A recogniser that stops by itself having produced nothing and reported no
88
+ * error is just as unusable as one saying `network` — nothing obliges a browser
89
+ * to name its failure — and, read as "nothing to report", it left the button
90
+ * blinking back to idle with not a word said: the shape a person reports as
91
+ * "it does not work".
92
+ */
93
+ export function recognitionEnd({ requested, heard, error }) {
94
+ if (error) return recognitionFailure(error);
95
+ if (requested || heard) return { message: null, fallback: false };
96
+ return { message: FALLBACK_MESSAGE, fallback: true };
97
+ }