@burdenoff/fe-libs 2026.1114.13 → 2026.1114.15

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 (37) hide show
  1. package/dist/shared/assistant/conversation.d.ts +16 -0
  2. package/dist/shared/assistant/i18nManifest.d.ts +30 -0
  3. package/dist/shared/assistant/i18nManifest.js +30 -0
  4. package/dist/shared/assistant/index.d.ts +6 -0
  5. package/dist/shared/assistant/store.d.ts +7 -0
  6. package/dist/shared/assistant/store.js +3 -0
  7. package/dist/shared/assistant/ui/AssistantChatArea.js +1269 -1188
  8. package/dist/shared/assistant/ui/AssistantMessageList.d.ts +14 -0
  9. package/dist/shared/assistant/ui/AssistantMessageList.js +55 -52
  10. package/dist/shared/assistant/ui/composer/AssistantComposer.js +348 -362
  11. package/dist/shared/assistant/ui/composer/AssistantDictation.d.ts +42 -0
  12. package/dist/shared/assistant/ui/composer/AssistantDictation.js +127 -0
  13. package/dist/shared/assistant/ui/composer/AssistantMicMenu.d.ts +23 -0
  14. package/dist/shared/assistant/ui/composer/AssistantMicMenu.js +176 -0
  15. package/dist/shared/assistant/ui/composer/microphones.d.ts +13 -0
  16. package/dist/shared/assistant/ui/composer/microphones.js +15 -0
  17. package/dist/shared/assistant/ui/composer/useCompactDictation.d.ts +70 -0
  18. package/dist/shared/assistant/ui/composer/useCompactDictation.js +136 -0
  19. package/dist/shared/assistant/ui/useVoiceSession.js +166 -164
  20. package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.d.ts +20 -17
  21. package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.js +230 -123
  22. package/dist/shared/assistant/ui/voice/AssistantVoiceSession.d.ts +2 -0
  23. package/dist/shared/assistant/ui/voice/AssistantVoiceSession.js +227 -229
  24. package/dist/shared/assistant/ui/voice/LiveWaveform.d.ts +4 -3
  25. package/dist/shared/assistant/ui/voice/LiveWaveform.js +1 -1
  26. package/dist/shared/assistant/ui/voice/VoiceTurnMarks.d.ts +15 -0
  27. package/dist/shared/assistant/ui/voice/VoiceTurnMarks.js +43 -0
  28. package/dist/shared/assistant/ui/voice/formatClock.d.ts +2 -0
  29. package/dist/shared/assistant/ui/voice/formatClock.js +3 -0
  30. package/dist/shared/assistant/ui/voice/useLiveLevel.d.ts +3 -1
  31. package/dist/shared/assistant/ui/voice/useLiveLevel.js +23 -19
  32. package/dist/shared/assistant/voice/liveLevel.d.ts +4 -3
  33. package/dist/shared/assistant/voice/liveLevel.js +18 -15
  34. package/dist/shared/assistant/voice/useVoiceInput.d.ts +27 -1
  35. package/dist/shared/assistant/voice/useVoiceInput.js +141 -71
  36. package/dist/shared-assistant.js +383 -377
  37. package/package.json +1 -1
@@ -19,9 +19,10 @@ interface Props {
19
19
  * runs.
20
20
  *
21
21
  * Colours are the theme's: the canvas reads its own CSS `color`, which the tone's
22
- * semantic token class sets (`text-text-secondary` for the person,
23
- * `text-action-primary-bg` for the assistant), so it follows light, dark and any
24
- * product theme without a colour value in code.
22
+ * semantic token class sets, so it follows light, dark and any product theme
23
+ * without a colour value in code. The operator's design (14 Nov): amber
24
+ * (`status-warning`) always means "we are hearing you", blue (`accent-blue`)
25
+ * always means "the assistant is talking".
25
26
  *
26
27
  * ★ Under either reduced-motion signal (BOFF-8566) nothing scrolls: the bars stay
27
28
  * a still, short line. The words next to it (the status, or the words appearing
@@ -45,7 +45,7 @@ var a = 3, o = 2, s = 2, c = ({ source: c, tone: l, className: u = "", testId: d
45
45
  "data-tone": l,
46
46
  children: /* @__PURE__ */ i("canvas", {
47
47
  ref: m,
48
- className: `absolute inset-0 ${l === "speaking" ? "text-action-primary-bg" : "text-text-secondary"}`
48
+ className: `absolute inset-0 ${l === "speaking" ? "text-status-info-bg" : "text-status-warning-bg"}`
49
49
  })
50
50
  });
51
51
  };
@@ -0,0 +1,15 @@
1
+ import { FC } from 'react';
2
+ /**
3
+ * What the page's thread says about voice turns (BOFF-13461; the operator's design
4
+ * of 14 Nov, "How the answer reaches the chat"): the voice chat's turns are the
5
+ * thread's own, and each says how it happened.
6
+ */
7
+ export type VoiceTurnMark = 'spoken' | 'spokenAloud' | 'interrupted';
8
+ /** Under a voice turn: "Spoken", "Spoken aloud", or "Interrupted…". */
9
+ export declare const VoiceTurnTag: FC<{
10
+ mark: VoiceTurnMark;
11
+ }>;
12
+ /** After a voice chat's last turn: "Voice chat ended", with its length when known. */
13
+ export declare const VoiceChatEnded: FC<{
14
+ seconds?: number;
15
+ }>;
@@ -0,0 +1,43 @@
1
+ import { useAssistantTr as e } from "../../i18n.js";
2
+ import { formatClock as t } from "./formatClock.js";
3
+ import { AudioLines as n, Mic as r } from "lucide-react";
4
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
5
+ // src/shared/assistant/ui/voice/VoiceTurnMarks.tsx
6
+ var o = ({ mark: t }) => {
7
+ let o = e(), s = t === "spoken", c = t === "spoken" ? o("voiceTurn.spoken", "Spoken") : t === "interrupted" ? o("voiceTurn.interrupted", "Interrupted. Only the spoken part is kept.") : o("voiceTurn.spokenAloud", "Spoken aloud");
8
+ return /* @__PURE__ */ i("div", {
9
+ className: `-mt-2 flex px-1 ${s ? "justify-end" : "justify-start ps-10"}`,
10
+ "data-testid": "assistant-voice-turn-tag",
11
+ "data-mark": t,
12
+ children: /* @__PURE__ */ a("span", {
13
+ className: "inline-flex items-center gap-1 text-xs text-text-muted",
14
+ children: [/* @__PURE__ */ i(s ? r : n, {
15
+ className: "size-3",
16
+ "aria-hidden": "true"
17
+ }), c]
18
+ })
19
+ });
20
+ }, s = ({ seconds: n }) => {
21
+ let r = e(), o = n !== void 0 && n > 0 ? r("voiceTurn.endedAfter", "Voice chat ended · {{duration}}", { duration: t(n) }) : r("voiceTurn.ended", "Voice chat ended");
22
+ return /* @__PURE__ */ a("div", {
23
+ role: "separator",
24
+ "aria-label": o,
25
+ className: "flex items-center gap-3 py-1 text-xs text-text-muted",
26
+ "data-testid": "assistant-voice-chat-ended",
27
+ children: [
28
+ /* @__PURE__ */ i("span", {
29
+ "aria-hidden": "true",
30
+ className: "h-px flex-1 bg-border-subtle"
31
+ }),
32
+ /* @__PURE__ */ i("span", {
33
+ "aria-hidden": "true",
34
+ children: o
35
+ }),
36
+ /* @__PURE__ */ i("span", {
37
+ "aria-hidden": "true",
38
+ className: "h-px flex-1 bg-border-subtle"
39
+ })
40
+ ]
41
+ });
42
+ };
43
+ export { s as VoiceChatEnded, o as VoiceTurnTag };
@@ -0,0 +1,2 @@
1
+ /** m:ss, for a dictation take's time, a voice chat's time and its length (BOFF-13461). */
2
+ export declare const formatClock: (seconds: number) => string;
@@ -0,0 +1,3 @@
1
+ // src/shared/assistant/ui/voice/formatClock.ts
2
+ var e = (e) => `${Math.floor(e / 60)}:${String(e % 60).padStart(2, "0")}`;
3
+ export { e as formatClock };
@@ -12,10 +12,12 @@ export interface UseLiveLevelOptions {
12
12
  pulseKey?: string;
13
13
  /** The assistant is speaking: a steady, speech-like motion, never the microphone. */
14
14
  speaking?: boolean;
15
+ /** The microphone chosen in the options (absent or null: the system default). */
16
+ deviceId?: string | null;
15
17
  }
16
18
  /**
17
19
  * The level a `LiveWaveform` draws (BOFF-13461). Stable for the component's
18
20
  * life; the frames run only while `active`. See `voice/liveLevel.ts` for the two
19
21
  * sources and why a phone never gets the microphone's own level.
20
22
  */
21
- export declare function useLiveLevel({ active, mic, pulseKey, speaking, }: UseLiveLevelOptions): LiveLevelSource;
23
+ export declare function useLiveLevel({ active, mic, pulseKey, speaking, deviceId, }: UseLiveLevelOptions): LiveLevelSource;
@@ -2,33 +2,37 @@ import { createSpeechPulse as e, micLevelAllowed as t, openMicLevel as n, smooth
2
2
  import { useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
3
3
  // src/shared/assistant/ui/voice/useLiveLevel.ts
4
4
  var c = 33;
5
- function l({ active: l, mic: u = !1, pulseKey: d = "", speaking: f = !1 }) {
6
- let [p] = s(() => /* @__PURE__ */ new Set()), [m] = s(e), h = o(null), g = o(f);
5
+ function l({ active: l, mic: u = !1, pulseKey: d = "", speaking: f = !1, deviceId: p = null }) {
6
+ let [m] = s(() => /* @__PURE__ */ new Set()), [h] = s(e), g = o(null), _ = o(f);
7
7
  i(() => {
8
- g.current = f;
8
+ _.current = f;
9
9
  }, [f]);
10
- let _ = a(() => ({ subscribe(e) {
11
- return p.add(e), () => {
12
- p.delete(e);
10
+ let v = a(() => ({ subscribe(e) {
11
+ return m.add(e), () => {
12
+ m.delete(e);
13
13
  };
14
- } }), [p]);
14
+ } }), [m]);
15
15
  return i(() => {
16
- l && d !== "" && m.pulse();
16
+ l && d !== "" && h.pulse();
17
17
  }, [
18
18
  l,
19
19
  d,
20
- m
20
+ h
21
21
  ]), i(() => {
22
22
  if (!l || !u || !t(typeof navigator > "u" ? void 0 : navigator, typeof AudioContext < "u")) return;
23
23
  let e = !1;
24
- return n().then((t) => {
25
- e ? t?.close() : h.current = t;
24
+ return n(p).then((t) => {
25
+ e ? t?.close() : g.current = t;
26
26
  }), () => {
27
- e = !0, h.current?.close(), h.current = null;
27
+ e = !0, g.current?.close(), g.current = null;
28
28
  };
29
- }, [l, u]), i(() => {
29
+ }, [
30
+ l,
31
+ u,
32
+ p
33
+ ]), i(() => {
30
34
  let e = (e) => {
31
- for (let t of p) t(e);
35
+ for (let t of m) t(e);
32
36
  };
33
37
  if (!l || typeof requestAnimationFrame > "u") {
34
38
  e(0);
@@ -36,8 +40,8 @@ function l({ active: l, mic: u = !1, pulseKey: d = "", speaking: f = !1 }) {
36
40
  }
37
41
  let t = 0, n = 0, i = 0, a = 0, o = (s) => {
38
42
  if (t = requestAnimationFrame(o), s - n < c) return;
39
- n = s, g.current && s - i > 170 && (i = s, m.pulse(.45 + .45 * Math.abs(Math.sin(s / 53))));
40
- let l = h.current, u = l && !g.current ? l.read() : m.next(s);
43
+ n = s, _.current && s - i > 170 && (i = s, h.pulse(.45 + .45 * Math.abs(Math.sin(s / 53))));
44
+ let l = g.current, u = l && !_.current ? l.read() : h.next(s);
41
45
  a = r(a, u), e(a);
42
46
  };
43
47
  return t = requestAnimationFrame(o), () => {
@@ -45,8 +49,8 @@ function l({ active: l, mic: u = !1, pulseKey: d = "", speaking: f = !1 }) {
45
49
  };
46
50
  }, [
47
51
  l,
48
- p,
49
- m
50
- ]), _;
52
+ m,
53
+ h
54
+ ]), v;
51
55
  }
52
56
  export { l as useLiveLevel };
@@ -78,7 +78,8 @@ export interface MicLevelHandle {
78
78
  /**
79
79
  * Open a capture of our own and an analyser on it. Echo cancellation, noise
80
80
  * suppression and auto gain are asked for (plain `true`, never `exact`): the
81
- * assistant's own voice must not drive the person's bars. Resolves null when the
82
- * browser refuses; the caller then falls back to the recogniser's pulses.
81
+ * assistant's own voice must not drive the person's bars. `deviceId`: the chosen
82
+ * microphone (absent or null: the system default). Resolves null when the browser
83
+ * refuses; the caller then falls back to the recogniser's pulses.
83
84
  */
84
- export declare function openMicLevel(): Promise<MicLevelHandle | null>;
85
+ export declare function openMicLevel(deviceId?: string | null): Promise<MicLevelHandle | null>;
@@ -42,33 +42,36 @@ function a() {
42
42
  }
43
43
  };
44
44
  }
45
- async function o() {
45
+ async function o(n) {
46
46
  if (typeof navigator > "u" || typeof AudioContext > "u") return null;
47
- let n;
47
+ let r = {
48
+ echoCancellation: !0,
49
+ noiseSuppression: !0,
50
+ autoGainControl: !0
51
+ }, i;
48
52
  try {
49
- n = await navigator.mediaDevices.getUserMedia({ audio: {
50
- echoCancellation: !0,
51
- noiseSuppression: !0,
52
- autoGainControl: !0
53
- } });
53
+ i = await navigator.mediaDevices.getUserMedia({ audio: n ? {
54
+ ...r,
55
+ deviceId: { exact: n }
56
+ } : r });
54
57
  } catch {
55
58
  return null;
56
59
  }
57
- let r;
60
+ let a;
58
61
  try {
59
- r = new AudioContext();
62
+ a = new AudioContext();
60
63
  } catch {
61
- return n.getTracks().forEach((e) => e.stop()), null;
64
+ return i.getTracks().forEach((e) => e.stop()), null;
62
65
  }
63
- let i = r.createMediaStreamSource(n), a = r.createAnalyser();
64
- a.fftSize = 512, a.smoothingTimeConstant = .2, i.connect(a);
65
- let o = new Uint8Array(a.fftSize), s = !1;
66
+ let o = a.createMediaStreamSource(i), s = a.createAnalyser();
67
+ s.fftSize = 512, s.smoothingTimeConstant = .2, o.connect(s);
68
+ let c = new Uint8Array(s.fftSize), l = !1;
66
69
  return {
67
70
  read() {
68
- return s ? 0 : (a.getByteTimeDomainData(o), t(e(o)));
71
+ return l ? 0 : (s.getByteTimeDomainData(c), t(e(c)));
69
72
  },
70
73
  close() {
71
- s || (s = !0, i.disconnect(), n.getTracks().forEach((e) => e.stop()), r.close().catch(() => void 0));
74
+ l || (l = !0, o.disconnect(), i.getTracks().forEach((e) => e.stop()), a.close().catch(() => void 0));
72
75
  }
73
76
  };
74
77
  }
@@ -105,7 +105,25 @@ export interface UseVoiceInputOptions {
105
105
  * only way to dictate Tamil was to translate the entire app.
106
106
  */
107
107
  language?: string;
108
+ /**
109
+ * ★ BOFF-13461: the microphone to listen to (a `deviceId`); absent or null is
110
+ * the system default, which is exactly the behaviour before this option.
111
+ * Honoured on a desktop browser only, by handing the recogniser a track of that
112
+ * device (`start(audioTrack)`, Chrome 135+; an older engine ignores the track
113
+ * and listens to the default). Never on a phone or tablet: the recogniser there
114
+ * may be a system service a capture of ours would take the microphone from.
115
+ */
116
+ deviceId?: string | null;
117
+ /**
118
+ * ★ BOFF-13461: the recogniser went away on its own, with no `finish()` waiting:
119
+ * its own end (the end of a phrase on a phone, an error) or a start that failed.
120
+ * Not called by `stop()`. Dictation lands what it heard so far here, so no
121
+ * word is lost.
122
+ */
123
+ onEnded?: () => void;
108
124
  }
125
+ /** How long `finish()` waits for the recogniser's last words before it gives up. */
126
+ export declare const FINISH_WAIT_MS = 1500;
109
127
  export interface UseVoiceInputResult {
110
128
  isSupported: boolean;
111
129
  isListening: boolean;
@@ -135,8 +153,16 @@ export interface UseVoiceInputResult {
135
153
  */
136
154
  start: (source?: StartSource) => void;
137
155
  stop: () => void;
156
+ /**
157
+ * ★ BOFF-13461: stop listening, but WAIT for the recogniser's last words: the
158
+ * phrase it was still working on arrives through `onFinalize` before this
159
+ * resolves (or after `FINISH_WAIT_MS`, whichever is first). `stop()` drops it.
160
+ */
161
+ finish: () => Promise<void>;
162
+ /** `finish()` is waiting for the last words. */
163
+ isFinishing: boolean;
138
164
  /** Start if idle, stop if listening — what the mic button binds to. */
139
165
  toggle: () => void;
140
166
  clearError: () => void;
141
167
  }
142
- export declare function useVoiceInput({ onFinalize, onSpeechEnd, language: requested, }: UseVoiceInputOptions): UseVoiceInputResult;
168
+ export declare function useVoiceInput({ onFinalize, onSpeechEnd, language: requested, deviceId, onEnded, }: UseVoiceInputOptions): UseVoiceInputResult;
@@ -1,7 +1,8 @@
1
- import { useI18n as e } from "../../providers/shell/I18nProvider.js";
2
- import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
1
+ import { micLevelAllowed as e } from "./liveLevel.js";
2
+ import { useI18n as t } from "../../providers/shell/I18nProvider.js";
3
+ import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
3
4
  // src/shared/assistant/voice/useVoiceInput.ts
4
- var a = {
5
+ var o = {
5
6
  en: "en-US",
6
7
  es: "es-ES",
7
8
  fr: "fr-FR",
@@ -12,19 +13,19 @@ var a = {
12
13
  hi: "hi-IN",
13
14
  ar: "ar-SA"
14
15
  };
15
- function o() {
16
+ function s() {
16
17
  if (typeof window > "u") return null;
17
18
  let e = window;
18
19
  return e.SpeechRecognition ?? e.webkitSpeechRecognition ?? null;
19
20
  }
20
- function s() {
21
- return o() !== null;
21
+ function c() {
22
+ return s() !== null;
22
23
  }
23
- var c = 2e3, l = 2;
24
- function u(e, t) {
25
- return t - e < c;
24
+ var l = 2e3, u = 2;
25
+ function d(e, t) {
26
+ return t - e < l;
26
27
  }
27
- function d(e) {
28
+ function f(e) {
28
29
  switch (e) {
29
30
  case "not-allowed":
30
31
  case "service-not-allowed": return "not-allowed";
@@ -35,78 +36,147 @@ function d(e) {
35
36
  default: return "unknown";
36
37
  }
37
38
  }
38
- function f({ onFinalize: s, onSpeechEnd: c, language: f }) {
39
- let { locale: p } = e(), [m, h] = i(!1), [g, _] = i(!1), [v, y] = i(""), [b, x] = i(null), S = r(null), C = r(0), w = r(-Infinity), T = r(0), E = r(c);
40
- n(() => {
41
- E.current = c;
42
- }, [c]);
43
- let D = r(s);
44
- n(() => {
45
- D.current = s;
46
- }, [s]);
47
- let O = o() !== null, k = f ?? a[p] ?? "en-US";
48
- n(() => () => {
49
- S.current?.abort(), S.current = null;
39
+ var p = 1500;
40
+ function m({ onFinalize: e, onSpeechEnd: c, language: l, deviceId: m = null, onEnded: _ }) {
41
+ let { locale: v } = t(), [y, b] = a(!1), [x, S] = a(!1), [C, w] = a(""), [T, E] = a(null), D = i(null), O = i(0), k = i(-Infinity), A = i(0), [j, M] = a(!1), N = i(null), P = i(null), F = i(null), I = i(m), L = n(() => {
42
+ P.current?.stop(), P.current = null;
50
43
  }, []);
51
- let A = t((e = "manual") => {
52
- let t = o();
53
- if (!t || S.current || e === "auto" && u(w.current, performance.now())) return;
54
- let n = new t();
55
- n.continuous = !0, n.interimResults = !0, n.lang = k;
56
- let r = C.current;
57
- n.onspeechend = () => {
58
- r === C.current && E.current?.(performance.now());
59
- }, n.onresult = (e) => {
60
- if (r !== C.current) return;
44
+ r(() => {
45
+ I.current = m, L();
46
+ }, [m, L]);
47
+ let R = i(c);
48
+ r(() => {
49
+ R.current = c;
50
+ }, [c]);
51
+ let z = i(e);
52
+ r(() => {
53
+ z.current = e;
54
+ }, [e]);
55
+ let B = i(_);
56
+ r(() => {
57
+ B.current = _;
58
+ }, [_]);
59
+ let V = s() !== null, H = l ?? o[v] ?? "en-US";
60
+ r(() => () => {
61
+ let e = D.current;
62
+ D.current = null, O.current += 1, e?.abort(), N.current?.complete(), L();
63
+ }, [L]);
64
+ let U = n((e = "manual", t) => {
65
+ let n = s();
66
+ if (!n || D.current || e === "auto" && d(k.current, performance.now())) return;
67
+ let r = new n();
68
+ r.continuous = !0, r.interimResults = !0, r.lang = H;
69
+ let i = O.current;
70
+ r.onspeechend = () => {
71
+ i === O.current && R.current?.(performance.now());
72
+ }, r.onresult = (e) => {
73
+ if (i !== O.current) return;
61
74
  let t = "", n = "";
62
75
  for (let r = e.resultIndex; r < e.results.length; r += 1) {
63
76
  let i = e.results[r], a = i[0]?.transcript ?? "";
64
77
  i.isFinal ? t += a : n += a;
65
78
  }
66
- t.trim() && D.current(t.trim()), y(n.trim());
67
- }, n.onerror = (e) => {
68
- if (r !== C.current) return;
69
- let t = d(e.error);
70
- t !== "no-speech" && x(t);
71
- }, n.onend = () => {
72
- r === C.current && (S.current = null, _(!1), h(!1), y(""));
73
- }, n.onstart = () => {
74
- r === C.current && (_(!1), h(!0));
75
- }, _(!0);
79
+ t.trim() && z.current(t.trim()), w(n.trim());
80
+ }, r.onerror = (e) => {
81
+ if (i !== O.current) return;
82
+ let t = f(e.error);
83
+ t !== "no-speech" && E(t);
84
+ }, r.onend = () => {
85
+ i === O.current && (N.current?.session === i ? N.current.complete() : (D.current = null, L(), S(!1), b(!1), w(""), B.current?.()));
86
+ }, r.onstart = () => {
87
+ i === O.current && (S(!1), b(!0));
88
+ }, S(!0);
76
89
  try {
77
- n.start();
90
+ t ? r.start(t) : r.start();
78
91
  } catch {
79
- w.current = performance.now(), T.current += 1, T.current >= l && x("unknown"), S.current = null, _(!1), h(!1);
92
+ k.current = performance.now(), A.current += 1, A.current >= u && E("unknown"), D.current = null, L(), S(!1), b(!1), B.current?.();
93
+ return;
94
+ }
95
+ D.current = r, A.current = 0, E(null), w("");
96
+ }, [H, L]), W = n((e = "manual") => {
97
+ if (!s() || D.current || F.current === O.current) return;
98
+ let t = I.current;
99
+ if (!t || !h()) {
100
+ U(e);
80
101
  return;
81
102
  }
82
- S.current = n, T.current = 0, x(null), y("");
83
- }, [k]), j = t(() => {
84
- let e = S.current;
85
- S.current = null, C.current += 1, e?.stop(), _(!1), h(!1), y("");
86
- }, []), M = r(k);
87
- n(() => {
88
- M.current !== k && (M.current = k, j(), x(null));
89
- }, [k, j]);
90
- let N = t(() => {
91
- m || g ? j() : A();
103
+ let n = P.current;
104
+ if (n && n.deviceId === t && n.track.readyState === "live") {
105
+ U(e, n.track);
106
+ return;
107
+ }
108
+ let r = O.current;
109
+ F.current = r, S(!0), g(t).then((t) => {
110
+ F.current === r && (F.current = null), r === O.current ? (t && (P.current = t), U(e, t?.track)) : t?.stop();
111
+ });
112
+ }, [U]), G = n(() => {
113
+ let e = D.current;
114
+ D.current = null, O.current += 1, e?.stop(), L(), N.current?.complete(), S(!1), b(!1), w("");
115
+ }, [L]), K = n(() => {
116
+ let e = D.current;
117
+ if (!e) return G(), Promise.resolve();
118
+ if (N.current) return new Promise((e) => setTimeout(e, p));
119
+ let t = O.current;
120
+ return M(!0), new Promise((n) => {
121
+ let r = !1, i = () => {
122
+ r || (r = !0, clearTimeout(a), N.current = null, t === O.current && (D.current = null, O.current += 1), L(), M(!1), S(!1), b(!1), w(""), n());
123
+ }, a = setTimeout(i, p);
124
+ N.current = {
125
+ session: t,
126
+ complete: i
127
+ };
128
+ try {
129
+ e.stop();
130
+ } catch {
131
+ i();
132
+ }
133
+ });
134
+ }, [G, L]), q = i(H);
135
+ r(() => {
136
+ q.current !== H && (q.current = H, G(), E(null));
137
+ }, [H, G]);
138
+ let J = n(() => {
139
+ y || x ? G() : W();
92
140
  }, [
93
- m,
94
- g,
95
- A,
96
- j
97
- ]), P = t(() => x(null), []);
141
+ y,
142
+ x,
143
+ W,
144
+ G
145
+ ]), Y = n(() => E(null), []);
98
146
  return {
99
- isSupported: O,
100
- isListening: m,
101
- isStarting: g,
102
- isActive: m || g,
103
- interim: v,
104
- error: b,
105
- language: k,
106
- start: A,
107
- stop: j,
108
- toggle: N,
109
- clearError: P
147
+ isSupported: V,
148
+ isListening: y,
149
+ isStarting: x,
150
+ isActive: y || x,
151
+ interim: C,
152
+ error: T,
153
+ language: H,
154
+ start: W,
155
+ stop: G,
156
+ finish: K,
157
+ isFinishing: j,
158
+ toggle: J,
159
+ clearError: Y
110
160
  };
111
161
  }
112
- export { c as START_RETRY_COOLDOWN_MS, s as isSpeechRecognitionSupported, u as startIsCoolingDown, f as useVoiceInput };
162
+ function h() {
163
+ return e(typeof navigator > "u" ? void 0 : navigator, !0);
164
+ }
165
+ async function g(e) {
166
+ try {
167
+ let t = await navigator.mediaDevices.getUserMedia({ audio: {
168
+ deviceId: { exact: e },
169
+ echoCancellation: !0,
170
+ noiseSuppression: !0,
171
+ autoGainControl: !0
172
+ } }), n = t.getAudioTracks()[0];
173
+ return n ? {
174
+ deviceId: e,
175
+ track: n,
176
+ stop: () => t.getTracks().forEach((e) => e.stop())
177
+ } : (t.getTracks().forEach((e) => e.stop()), null);
178
+ } catch {
179
+ return null;
180
+ }
181
+ }
182
+ export { p as FINISH_WAIT_MS, l as START_RETRY_COOLDOWN_MS, c as isSpeechRecognitionSupported, d as startIsCoolingDown, m as useVoiceInput };