@molecule/app-ide-panel-logic 1.3.1 → 1.4.0

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.
Files changed (66) hide show
  1. package/README.md +277 -1
  2. package/dist/chatTimelineOrdering.d.ts +175 -1
  3. package/dist/chatTimelineOrdering.d.ts.map +1 -1
  4. package/dist/chatTimelineOrdering.js +192 -1
  5. package/dist/chatTimelineOrdering.js.map +1 -1
  6. package/dist/components/chat-card-event-utilities.d.ts +320 -0
  7. package/dist/components/chat-card-event-utilities.d.ts.map +1 -0
  8. package/dist/components/chat-card-event-utilities.js +198 -0
  9. package/dist/components/chat-card-event-utilities.js.map +1 -0
  10. package/dist/components/chat-composer-utilities.d.ts +472 -0
  11. package/dist/components/chat-composer-utilities.d.ts.map +1 -0
  12. package/dist/components/chat-composer-utilities.js +519 -0
  13. package/dist/components/chat-composer-utilities.js.map +1 -0
  14. package/dist/components/chat-dictation-controller.d.ts +376 -0
  15. package/dist/components/chat-dictation-controller.d.ts.map +1 -0
  16. package/dist/components/chat-dictation-controller.js +559 -0
  17. package/dist/components/chat-dictation-controller.js.map +1 -0
  18. package/dist/components/chat-effort-utilities.d.ts +24 -0
  19. package/dist/components/chat-effort-utilities.d.ts.map +1 -1
  20. package/dist/components/chat-effort-utilities.js +41 -0
  21. package/dist/components/chat-effort-utilities.js.map +1 -1
  22. package/dist/components/chat-format-utilities.d.ts +71 -0
  23. package/dist/components/chat-format-utilities.d.ts.map +1 -0
  24. package/dist/components/chat-format-utilities.js +192 -0
  25. package/dist/components/chat-format-utilities.js.map +1 -0
  26. package/dist/components/chat-models-utilities.d.ts +168 -0
  27. package/dist/components/chat-models-utilities.d.ts.map +1 -1
  28. package/dist/components/chat-models-utilities.js +253 -0
  29. package/dist/components/chat-models-utilities.js.map +1 -1
  30. package/dist/components/chat-settings-utilities.d.ts +153 -1
  31. package/dist/components/chat-settings-utilities.d.ts.map +1 -1
  32. package/dist/components/chat-settings-utilities.js +204 -1
  33. package/dist/components/chat-settings-utilities.js.map +1 -1
  34. package/dist/components/chat-stream-utilities.d.ts +165 -1
  35. package/dist/components/chat-stream-utilities.d.ts.map +1 -1
  36. package/dist/components/chat-stream-utilities.js +155 -1
  37. package/dist/components/chat-stream-utilities.js.map +1 -1
  38. package/dist/components/chat-tests-controller.d.ts +249 -0
  39. package/dist/components/chat-tests-controller.d.ts.map +1 -0
  40. package/dist/components/chat-tests-controller.js +504 -0
  41. package/dist/components/chat-tests-controller.js.map +1 -0
  42. package/dist/components/chat-timeline-utilities.d.ts +90 -0
  43. package/dist/components/chat-timeline-utilities.d.ts.map +1 -0
  44. package/dist/components/chat-timeline-utilities.js +71 -0
  45. package/dist/components/chat-timeline-utilities.js.map +1 -0
  46. package/dist/components/chat-ui-constants.d.ts +98 -0
  47. package/dist/components/chat-ui-constants.d.ts.map +1 -0
  48. package/dist/components/chat-ui-constants.js +146 -0
  49. package/dist/components/chat-ui-constants.js.map +1 -0
  50. package/dist/components/chat-undo-utilities.d.ts +47 -0
  51. package/dist/components/chat-undo-utilities.d.ts.map +1 -0
  52. package/dist/components/chat-undo-utilities.js +73 -0
  53. package/dist/components/chat-undo-utilities.js.map +1 -0
  54. package/dist/components/context-usage-utilities.d.ts +25 -3
  55. package/dist/components/context-usage-utilities.d.ts.map +1 -1
  56. package/dist/components/context-usage-utilities.js +42 -2
  57. package/dist/components/context-usage-utilities.js.map +1 -1
  58. package/dist/index.d.ts +2 -0
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +2 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/panels.d.ts +6 -0
  63. package/dist/panels.d.ts.map +1 -1
  64. package/dist/panels.js +6 -0
  65. package/dist/panels.js.map +1 -1
  66. package/package.json +2 -2
@@ -0,0 +1,559 @@
1
+ /**
2
+ * The chat panel's voice region (dictation) as framework-neutral behaviour.
3
+ *
4
+ * Every framework's chat panel drives the same dictation paths: the browser's
5
+ * Web Speech service when it works, the bonded on-device provider when it does
6
+ * not, and (when the app registers an engine catalog) whichever engine the
7
+ * person chose in the `/mic` picker. This controller owns that machinery — the
8
+ * recognition session, the restart/watchdog timers, the engine choice and the
9
+ * give-up detection — and reads every browser API it needs from its options:
10
+ * the Web Speech constructor, the ai-voice provider, the engine catalog lookup,
11
+ * storage, the clock and the timers. It performs no I/O when it is constructed;
12
+ * the host starts its work from the effects it already keeps in place.
13
+ *
14
+ * The host keeps the values it renders (the listening flag, the error/notice
15
+ * text, the dead-service flag, the picker and the chosen engine id) in its own
16
+ * state and passes the setters in, so the controller never owns view state and
17
+ * the rendered output does not move.
18
+ *
19
+ * @module
20
+ */
21
+ /** Session-storage key remembering that the browser's Web Speech service proved dead. */
22
+ export const WEB_SPEECH_DEAD_STORAGE_KEY = 'molecule.ide.webSpeechDead';
23
+ /** Local-storage key holding the user's chosen dictation engine id. */
24
+ export const MIC_ENGINE_STORAGE_KEY = 'molecule.ide.voiceEngine';
25
+ /** How long an error message stays visible, in milliseconds. */
26
+ const VOICE_ERROR_MS = 8000;
27
+ /** How long a started-but-silent Web Speech session waits before it is declared dead. */
28
+ const WEB_SPEECH_WATCHDOG_MS = 5000;
29
+ /** How long a no-result session waits before it restarts. */
30
+ const WEB_SPEECH_RESTART_MS = 300;
31
+ /** Consecutive rapid no-result failures before the service is declared dead. */
32
+ const VOICE_FAIL_LIMIT = 3;
33
+ /**
34
+ * The voice region's behaviour (see the module docs). The host subscribes to
35
+ * nothing: it keeps the values it renders in its own state, hands the controller
36
+ * its setters, and calls {@link ChatDictationController.mount},
37
+ * {@link ChatDictationController.restoreSavedEngine} and
38
+ * {@link ChatDictationController.dispose} from the effects it already keeps in
39
+ * place, so the order of the host's requests and timers cannot move.
40
+ */
41
+ export class ChatDictationController {
42
+ translate;
43
+ speechRecognitionConstructor;
44
+ hasSpeechRecognition;
45
+ engines;
46
+ selectEngine;
47
+ engineCoversLanguage;
48
+ getVoiceProvider;
49
+ readInput;
50
+ writeInput;
51
+ pushDictatedSnippet;
52
+ onTranscriptInserted;
53
+ onDictationStart;
54
+ closeSiblingPopups;
55
+ openMicPicker;
56
+ closeMicPicker;
57
+ setListening;
58
+ setVoiceError;
59
+ setVoiceNotice;
60
+ setWebSpeechDead;
61
+ setCurrentVoiceEngineId;
62
+ now;
63
+ setTimer;
64
+ clearTimer;
65
+ getLanguage;
66
+ sessionStore;
67
+ localStore;
68
+ recognition = null;
69
+ voiceErrorTimer = null;
70
+ voiceRestartTimer = null;
71
+ voiceWatchdogTimer = null;
72
+ voiceIntent = false;
73
+ voiceDiscard = false;
74
+ voiceFailCount = 0;
75
+ voiceLastStart = 0;
76
+ useLocalVoice = false;
77
+ webSpeechDead = false;
78
+ engine = null;
79
+ /**
80
+ * Wires the controller. Performs no I/O: every API it needs is stored, not
81
+ * called, and the host's effects start the work.
82
+ *
83
+ * @param options - The host callbacks and the browser APIs the controller uses.
84
+ */
85
+ constructor(options) {
86
+ this.translate = options.translate;
87
+ this.speechRecognitionConstructor = options.speechRecognitionConstructor;
88
+ this.hasSpeechRecognition = Boolean(options.speechRecognitionConstructor);
89
+ this.engines = options.engines ?? [];
90
+ this.selectEngine = options.selectEngine;
91
+ this.engineCoversLanguage = options.engineCoversLanguage;
92
+ this.getVoiceProvider = options.getVoiceProvider;
93
+ this.readInput = options.readInput;
94
+ this.writeInput = options.writeInput;
95
+ this.pushDictatedSnippet = options.pushDictatedSnippet;
96
+ this.onTranscriptInserted = options.onTranscriptInserted;
97
+ this.onDictationStart = options.onDictationStart;
98
+ this.closeSiblingPopups = options.closeSiblingPopups;
99
+ this.openMicPicker = options.openMicPicker;
100
+ this.closeMicPicker = options.closeMicPicker;
101
+ this.setListening = options.setListening;
102
+ this.setVoiceError = options.setVoiceError;
103
+ this.setVoiceNotice = options.setVoiceNotice;
104
+ this.setWebSpeechDead = options.setWebSpeechDead;
105
+ this.setCurrentVoiceEngineId = options.setCurrentVoiceEngineId;
106
+ this.now = options.now ?? (() => Date.now());
107
+ this.setTimer = options.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
108
+ this.clearTimer = options.clearTimer ?? ((timer) => clearTimeout(timer));
109
+ this.getLanguage =
110
+ options.getLanguage ??
111
+ (() => (typeof navigator === 'undefined' ? '' : navigator.language) || 'en-US');
112
+ this.sessionStore = options.sessionStore ?? (() => globalThis.sessionStorage);
113
+ this.localStore = options.localStore ?? (() => globalThis.localStorage);
114
+ }
115
+ /**
116
+ * Restores the session-scoped dead-service flag from storage. Called from the
117
+ * host's mount effect.
118
+ */
119
+ mount() {
120
+ try {
121
+ this.webSpeechDead = this.sessionStore()?.getItem(WEB_SPEECH_DEAD_STORAGE_KEY) === '1';
122
+ }
123
+ catch (_error) {
124
+ // sessionStorage unavailable — the watchdog re-detects within one session
125
+ }
126
+ }
127
+ /**
128
+ * Restores the user's saved engine choice. Called from the host's
129
+ * engine-restore effect (a no-op when the app registers no catalog).
130
+ */
131
+ restoreSavedEngine() {
132
+ if (this.engines.length === 0)
133
+ return;
134
+ try {
135
+ const savedId = this.localStore()?.getItem(MIC_ENGINE_STORAGE_KEY);
136
+ if (savedId) {
137
+ const def = this.selectEngine(savedId);
138
+ if (def)
139
+ this.engine = def;
140
+ }
141
+ }
142
+ catch (_error) {
143
+ // localStorage unavailable — the picker simply reopens on first use
144
+ }
145
+ }
146
+ /**
147
+ * Why an engine can't be used here, or null when it can: 'browser' = the
148
+ * native speech service is missing/proven dead in this browser; 'language'
149
+ * = the engine doesn't cover the UI language.
150
+ *
151
+ * @param def - The engine to check.
152
+ * @param webSpeechDead - Whether the rendered dead-service flag is set.
153
+ * @returns The reason, or null when the engine can be used.
154
+ */
155
+ voiceEngineDisabledReason(def, webSpeechDead) {
156
+ if (def.kind === 'native' && (!this.hasSpeechRecognition || webSpeechDead)) {
157
+ return 'browser';
158
+ }
159
+ if (!this.engineCoversLanguage(def, this.getLanguage()))
160
+ return 'language';
161
+ return null;
162
+ }
163
+ /**
164
+ * Shows an error message, replacing any current one and clearing it after
165
+ * {@link VOICE_ERROR_MS}.
166
+ *
167
+ * @param message - The message to show.
168
+ */
169
+ showVoiceError(message) {
170
+ this.setVoiceError(message);
171
+ if (this.voiceErrorTimer)
172
+ this.clearTimer(this.voiceErrorTimer);
173
+ this.voiceErrorTimer = this.setTimer(() => {
174
+ this.voiceErrorTimer = null;
175
+ this.setVoiceError(null);
176
+ }, VOICE_ERROR_MS);
177
+ }
178
+ /**
179
+ * Starts dictation through the bonded on-device provider. Returns false when
180
+ * no usable provider is wired, so the caller can fall through to the
181
+ * "dictation unavailable" path.
182
+ *
183
+ * @returns True when the provider started listening.
184
+ */
185
+ startLocalVoice() {
186
+ const localVoice = this.getVoiceProvider();
187
+ if (!localVoice || !localVoice.isRecognitionSupported())
188
+ return false;
189
+ this.useLocalVoice = true;
190
+ // Shown until the provider reaches 'listening' (model may need a download)
191
+ this.setVoiceNotice(this.translate('ide.chat.voicePreparing', undefined, {
192
+ defaultValue: 'Preparing dictation — this can take a moment on first use.',
193
+ }));
194
+ localVoice.startListening({
195
+ language: this.getLanguage(),
196
+ continuous: true,
197
+ interimResults: false,
198
+ }, {
199
+ onTranscript: (event) => {
200
+ if (this.voiceDiscard || !event.isFinal || !event.transcript)
201
+ return;
202
+ const prev = this.readInput();
203
+ this.writeInput(prev ? `${prev} ${event.transcript}` : event.transcript);
204
+ this.pushDictatedSnippet(event.transcript);
205
+ this.onTranscriptInserted();
206
+ },
207
+ onStateChange: (state) => {
208
+ if (state === 'listening')
209
+ this.setVoiceNotice(null);
210
+ },
211
+ onError: (event) => {
212
+ if (event.code === 'not-allowed') {
213
+ this.voiceIntent = false;
214
+ this.setListening(false);
215
+ this.setVoiceNotice(null);
216
+ this.showVoiceError(this.translate('ide.chat.voiceMicBlocked', undefined, {
217
+ defaultValue: 'Microphone access is blocked.',
218
+ }));
219
+ return;
220
+ }
221
+ if (event.code === 'transcription-failed') {
222
+ // One chunk failed; the session keeps listening
223
+ this.showVoiceError(this.translate('ide.chat.voiceTranscribeFailed', undefined, {
224
+ defaultValue: 'Transcription failed.',
225
+ }));
226
+ return;
227
+ }
228
+ // not-supported / start-failed — the fallback itself is unusable
229
+ this.voiceIntent = false;
230
+ this.setListening(false);
231
+ this.setVoiceNotice(null);
232
+ this.showVoiceError(this.translate('ide.chat.voiceUnavailable', undefined, {
233
+ defaultValue: 'Dictation is not available in this browser.',
234
+ }));
235
+ },
236
+ });
237
+ return true;
238
+ }
239
+ /**
240
+ * Starts one Web Speech session, restarting it after a healthy end and giving
241
+ * up (delegating to the on-device provider or the unavailable path) when the
242
+ * service never answers or fails repeatedly.
243
+ */
244
+ startRecognition() {
245
+ // One attempt; a healthy session that ends (or a short-lived failure) starts the
246
+ // next attempt through `start`, with this same render's values.
247
+ const start = () => {
248
+ const Ctor = this.speechRecognitionConstructor;
249
+ if (!Ctor || !this.voiceIntent)
250
+ return;
251
+ const recognition = new Ctor();
252
+ recognition.continuous = true;
253
+ recognition.interimResults = true;
254
+ recognition.lang = this.getLanguage();
255
+ let gotResult = false;
256
+ const clearWatchdog = () => {
257
+ if (this.voiceWatchdogTimer) {
258
+ this.clearTimer(this.voiceWatchdogTimer);
259
+ this.voiceWatchdogTimer = null;
260
+ }
261
+ };
262
+ // The Web Speech service itself is broken (not just this session): stop
263
+ // retrying it for good — instead of flicker-restarting forever. If an
264
+ // on-device provider is bonded, hand the same gesture over to it
265
+ // seamlessly; otherwise turn the button off and say so.
266
+ const giveUp = () => {
267
+ clearWatchdog();
268
+ this.voiceFailCount = 0;
269
+ this.recognition = null;
270
+ this.webSpeechDead = true;
271
+ this.setWebSpeechDead(true);
272
+ try {
273
+ this.sessionStore()?.setItem(WEB_SPEECH_DEAD_STORAGE_KEY, '1');
274
+ }
275
+ catch (_error) {
276
+ // sessionStorage unavailable — the watchdog re-detects next time
277
+ }
278
+ try {
279
+ recognition.abort();
280
+ }
281
+ catch (_error) {
282
+ // abort() on a never-started/already-ended session throws harmlessly
283
+ }
284
+ // With an engine catalog, the native engine just proved dead: clear the
285
+ // user's (native) choice and reopen the picker so THEY pick a fallback —
286
+ // the native row now shows as disabled with the reason.
287
+ if (this.engines.length > 0) {
288
+ this.engine = null;
289
+ this.setCurrentVoiceEngineId(null);
290
+ try {
291
+ this.localStore()?.removeItem(MIC_ENGINE_STORAGE_KEY);
292
+ }
293
+ catch (_error) {
294
+ // localStorage unavailable — the stale choice re-fails harmlessly
295
+ }
296
+ this.voiceIntent = false;
297
+ this.setListening(false);
298
+ this.closeSiblingPopups();
299
+ this.openMicPicker();
300
+ return;
301
+ }
302
+ if (this.voiceIntent && this.startLocalVoice()) {
303
+ return;
304
+ }
305
+ this.voiceIntent = false;
306
+ this.setListening(false);
307
+ this.showVoiceError(this.translate('ide.chat.voiceUnavailable', undefined, {
308
+ defaultValue: 'Dictation is not available in this browser.',
309
+ }));
310
+ };
311
+ recognition.onstart = () => {
312
+ clearWatchdog();
313
+ };
314
+ recognition.onresult = (e) => {
315
+ gotResult = true;
316
+ this.voiceFailCount = 0;
317
+ const event = e;
318
+ let transcript = '';
319
+ for (let i = event.resultIndex; i < event.results.length; i++) {
320
+ if (event.results[i].isFinal) {
321
+ transcript += event.results[i][0].transcript;
322
+ }
323
+ }
324
+ if (transcript) {
325
+ const prev = this.readInput();
326
+ this.writeInput(prev ? `${prev} ${transcript}` : transcript);
327
+ this.pushDictatedSnippet(transcript);
328
+ this.onTranscriptInserted();
329
+ }
330
+ };
331
+ recognition.onend = () => {
332
+ clearWatchdog();
333
+ this.recognition = null;
334
+ if (!this.voiceIntent) {
335
+ this.setListening(false);
336
+ return;
337
+ }
338
+ // If we got results, the session was healthy — restart immediately
339
+ if (gotResult) {
340
+ this.voiceFailCount = 0;
341
+ start();
342
+ return;
343
+ }
344
+ // No results — could be a rapid failure loop. Track it.
345
+ const elapsed = this.now() - this.voiceLastStart;
346
+ if (elapsed < 1000) {
347
+ this.voiceFailCount++;
348
+ }
349
+ else {
350
+ this.voiceFailCount = 0;
351
+ }
352
+ // Too many rapid no-result failures — the service is not working
353
+ if (this.voiceFailCount >= VOICE_FAIL_LIMIT) {
354
+ giveUp();
355
+ return;
356
+ }
357
+ // Restart after a short delay so we don't spin
358
+ this.voiceRestartTimer = this.setTimer(() => {
359
+ this.voiceRestartTimer = null;
360
+ if (this.voiceIntent)
361
+ start();
362
+ }, WEB_SPEECH_RESTART_MS);
363
+ };
364
+ recognition.onerror = (e) => {
365
+ const error = e.error;
366
+ // In the Chromium family a 'network' error means the browser has no
367
+ // reachable speech backend (Brave, ungoogled builds) — it will fail
368
+ // identically every session, so retrying just flickers.
369
+ if (error === 'network' || error === 'language-not-supported') {
370
+ giveUp();
371
+ return;
372
+ }
373
+ if (error === 'not-allowed' || error === 'service-not-allowed') {
374
+ clearWatchdog();
375
+ this.voiceIntent = false;
376
+ this.recognition = null;
377
+ this.setListening(false);
378
+ this.showVoiceError(this.translate('ide.chat.voiceMicBlocked', undefined, {
379
+ defaultValue: 'Microphone access is blocked.',
380
+ }));
381
+ }
382
+ // Other errors (no-speech, audio-capture, aborted) — onend will handle restart
383
+ };
384
+ this.recognition = recognition;
385
+ this.voiceLastStart = this.now();
386
+ try {
387
+ recognition.start();
388
+ }
389
+ catch (_error) {
390
+ // start() throws InvalidStateError if a previous session is still tearing
391
+ // down — treat it like any other dead session rather than crash the click
392
+ giveUp();
393
+ return;
394
+ }
395
+ // Watchdog: some broken implementations accept start() and then never fire a
396
+ // single event (verified in Brave: no onstart, no onerror, no onend).
397
+ this.voiceWatchdogTimer = this.setTimer(() => {
398
+ this.voiceWatchdogTimer = null;
399
+ giveUp();
400
+ }, WEB_SPEECH_WATCHDOG_MS);
401
+ };
402
+ start();
403
+ }
404
+ /** Begins a dictation session on whatever engine/path is active. */
405
+ beginDictation() {
406
+ this.voiceIntent = true;
407
+ this.voiceDiscard = false;
408
+ this.voiceFailCount = 0;
409
+ this.setVoiceError(null);
410
+ if (this.voiceErrorTimer) {
411
+ this.clearTimer(this.voiceErrorTimer);
412
+ this.voiceErrorTimer = null;
413
+ }
414
+ this.setListening(true);
415
+ this.onDictationStart();
416
+ if (this.engines.length > 0) {
417
+ // Catalog mode: the chosen engine decides the path
418
+ if (this.engine?.kind === 'native') {
419
+ this.startRecognition();
420
+ }
421
+ else {
422
+ this.useLocalVoice = true;
423
+ if (!this.startLocalVoice()) {
424
+ this.voiceIntent = false;
425
+ this.setListening(false);
426
+ this.showVoiceError(this.translate('ide.chat.voiceUnavailable', undefined, {
427
+ defaultValue: 'Dictation is not available in this browser.',
428
+ }));
429
+ }
430
+ }
431
+ return;
432
+ }
433
+ // Legacy (no catalog): Web Speech first, on-device fallback automatic
434
+ if (!this.hasSpeechRecognition || this.webSpeechDead || this.useLocalVoice) {
435
+ if (this.startLocalVoice())
436
+ return;
437
+ this.voiceIntent = false;
438
+ this.setListening(false);
439
+ this.showVoiceError(this.translate('ide.chat.voiceUnavailable', undefined, {
440
+ defaultValue: 'Dictation is not available in this browser.',
441
+ }));
442
+ return;
443
+ }
444
+ this.startRecognition();
445
+ }
446
+ /**
447
+ * Applies a picker choice: wires the engine, persists it, and (for a
448
+ * mic-click-initiated pick) starts dictating immediately.
449
+ *
450
+ * @param def - The engine the person chose.
451
+ * @param autoStart - Whether to start dictating right after choosing.
452
+ */
453
+ chooseVoiceEngine(def, autoStart) {
454
+ this.closeMicPicker();
455
+ const selected = this.selectEngine(def.id);
456
+ if (!selected)
457
+ return;
458
+ this.engine = selected;
459
+ this.setCurrentVoiceEngineId(selected.id);
460
+ this.useLocalVoice = selected.kind !== 'native';
461
+ try {
462
+ this.localStore()?.setItem(MIC_ENGINE_STORAGE_KEY, selected.id);
463
+ }
464
+ catch (_error) {
465
+ // localStorage unavailable — the picker reopens next session
466
+ }
467
+ if (autoStart)
468
+ this.beginDictation();
469
+ }
470
+ /**
471
+ * Turns dictation on or off from the mic button.
472
+ *
473
+ * @param isListening - Whether a session is currently active (the host's state).
474
+ */
475
+ toggleVoice(isListening) {
476
+ if (isListening) {
477
+ this.voiceIntent = false;
478
+ if (this.voiceRestartTimer) {
479
+ this.clearTimer(this.voiceRestartTimer);
480
+ this.voiceRestartTimer = null;
481
+ }
482
+ if (this.voiceWatchdogTimer) {
483
+ this.clearTimer(this.voiceWatchdogTimer);
484
+ this.voiceWatchdogTimer = null;
485
+ }
486
+ // Don't wait for onend — a hung session (dead service) never fires it
487
+ this.setListening(false);
488
+ this.setVoiceNotice(null);
489
+ if (this.useLocalVoice) {
490
+ // On-device provider: trailing speech is still transcribed + inserted
491
+ this.getVoiceProvider()?.stopListening();
492
+ }
493
+ else {
494
+ this.recognition?.stop();
495
+ }
496
+ return;
497
+ }
498
+ // With an engine catalog and no choice made yet, the first mic click asks
499
+ // the user which engine to use (and download) instead of picking for them.
500
+ if (this.engines.length > 0 && !this.engine) {
501
+ // Popups are one-at-a-time — close any sibling before opening the picker
502
+ this.closeSiblingPopups();
503
+ this.openMicPicker();
504
+ return;
505
+ }
506
+ this.beginDictation();
507
+ }
508
+ /**
509
+ * Stops recognition when the composer submits: clears the intent and timers,
510
+ * and drops any trailing transcript from the provider so it does not land in
511
+ * the freshly-cleared composer. Called from the host's submit handler.
512
+ */
513
+ stopForSubmit() {
514
+ // Stop voice recognition on submit
515
+ this.voiceIntent = false;
516
+ if (this.voiceWatchdogTimer) {
517
+ this.clearTimer(this.voiceWatchdogTimer);
518
+ this.voiceWatchdogTimer = null;
519
+ }
520
+ this.setListening(false);
521
+ this.setVoiceNotice(null);
522
+ if (this.useLocalVoice) {
523
+ // Discard any trailing transcript — it belongs to the message just sent,
524
+ // not the freshly-cleared composer
525
+ this.voiceDiscard = true;
526
+ this.getVoiceProvider()?.stopListening();
527
+ }
528
+ else {
529
+ this.recognition?.stop();
530
+ }
531
+ }
532
+ /**
533
+ * Stops recognition and every timer on unmount. Called from the host's
534
+ * cleanup effect.
535
+ */
536
+ dispose() {
537
+ this.voiceIntent = false;
538
+ if (this.voiceRestartTimer) {
539
+ this.clearTimer(this.voiceRestartTimer);
540
+ this.voiceRestartTimer = null;
541
+ }
542
+ if (this.voiceWatchdogTimer) {
543
+ this.clearTimer(this.voiceWatchdogTimer);
544
+ this.voiceWatchdogTimer = null;
545
+ }
546
+ if (this.voiceErrorTimer) {
547
+ this.clearTimer(this.voiceErrorTimer);
548
+ this.voiceErrorTimer = null;
549
+ }
550
+ this.recognition?.abort();
551
+ if (this.useLocalVoice) {
552
+ // stopListening, not dispose — the bonded provider is an app-wide
553
+ // singleton other consumers may use after this panel unmounts
554
+ this.voiceDiscard = true;
555
+ this.getVoiceProvider()?.stopListening();
556
+ }
557
+ }
558
+ }
559
+ //# sourceMappingURL=chat-dictation-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-dictation-controller.js","sourceRoot":"","sources":["../../src/components/chat-dictation-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AA0IH,yFAAyF;AACzF,MAAM,CAAC,MAAM,2BAA2B,GAAG,4BAA4B,CAAA;AAEvE,uEAAuE;AACvE,MAAM,CAAC,MAAM,sBAAsB,GAAG,0BAA0B,CAAA;AAEhE,gEAAgE;AAChE,MAAM,cAAc,GAAG,IAAI,CAAA;AAE3B,yFAAyF;AACzF,MAAM,sBAAsB,GAAG,IAAI,CAAA;AAEnC,6DAA6D;AAC7D,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAEjC,gFAAgF;AAChF,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAgH1B;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAuB;IACjB,SAAS,CAAmB;IAC5B,4BAA4B,CAA0C;IACtE,oBAAoB,CAAS;IAC7B,OAAO,CAA4B;IACnC,YAAY,CAAwC;IACpD,oBAAoB,CAAwD;IAC5E,gBAAgB,CAAqC;IACrD,SAAS,CAAc;IACvB,UAAU,CAAyB;IACnC,mBAAmB,CAA8B;IACjD,oBAAoB,CAAY;IAChC,gBAAgB,CAAY;IAC5B,kBAAkB,CAAY;IAC9B,aAAa,CAAY;IACzB,cAAc,CAAY;IAC1B,YAAY,CAA8B;IAC1C,aAAa,CAAkC;IA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elDefinition, EffortLevel, EffortOption } from '@molecule/app-ai-models';
26
+ import type { TranslateFunction } from '@molecule/app-i18n';
26
27
  export type { EffortLevel, EffortOption };
27
28
  export { defaultEffortForModel, effortOptionsForModel, nativeEffortName, } from '@molecule/app-ai-models';
28
29
  /**
@@ -101,4 +102,27 @@ export declare function modelsSupportingEffort(models: readonly AppModelDefiniti
101
102
  * @returns The model's effort levels in ascending order (empty when it has none).
102
103
  */
103
104
  export declare function effortLevelsForModel(model: AppModelDefinition | undefined): readonly string[];
105
+ /**
106
+ * The effort levels the open `/effort` picker lists, narrowed by any typed
107
+ * filter: the text after `/effort` (minus a mode flag) matches case-insensitively
108
+ * against each level's native value, so `/effort xh` narrows to `xhigh`. With no
109
+ * typed query every option is listed.
110
+ *
111
+ * @param text - The picker's raw input text.
112
+ * @param options - The scoped mode's model's options (see {@link effortOptionsForModel}).
113
+ * @returns The options matching the typed query (the whole list when empty).
114
+ */
115
+ export declare function effortPickerVisibleOptions(text: string, options: readonly EffortOption[]): EffortOption[];
116
+ /**
117
+ * The localized one-line status of a mode's reasoning effort — the `/effort ?`
118
+ * view's per-mode line. States whether the mode's model is fixed (one reasoning
119
+ * mode) or lists its current level and every available one.
120
+ *
121
+ * @param t - The caller's translate function (React passes `useTranslation()`'s `t`).
122
+ * @param mode - The conversation mode to describe.
123
+ * @param model - The model the mode will actually run, or `undefined`.
124
+ * @param currentEffort - The persisted per-mode value (or the legacy fallback).
125
+ * @returns The localized status line.
126
+ */
127
+ export declare function effortModeStatusLine(t: TranslateFunction, mode: EffortMode, model: AppModelDefinition | undefined, currentEffort: EffortLevel | undefined): string;
104
128
  //# sourceMappingURL=chat-effort-utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-effort-utilities.d.ts","sourceRoot":"","sources":["../../src/components/chat-effort-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EA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