@burdenoff/fe-libs 2026.1117.4 → 2026.1117.6

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 (23) hide show
  1. package/dist/shared/assistant/liveDeltas.d.ts +6 -0
  2. package/dist/shared/assistant/liveDeltas.js +4 -3
  3. package/dist/shared/assistant/ui/AssistantChatArea.js +1159 -1158
  4. package/dist/shared/assistant/ui/useVoiceSession.js +312 -301
  5. package/dist/shared/assistant/voice/handsFree.d.ts +16 -0
  6. package/dist/shared/assistant/voice/handsFree.js +2 -2
  7. package/dist/shared/assistant/voice/handsfree/audioTrackTransport.js +1 -0
  8. package/dist/shared/assistant/voice/handsfree/backendStreamTransport.d.ts +11 -0
  9. package/dist/shared/assistant/voice/handsfree/backendStreamTransport.js +118 -63
  10. package/dist/shared/assistant/voice/handsfree/bargeIn.d.ts +20 -1
  11. package/dist/shared/assistant/voice/handsfree/bargeIn.js +3 -3
  12. package/dist/shared/assistant/voice/handsfree/handsFreeController.d.ts +10 -1
  13. package/dist/shared/assistant/voice/handsfree/handsFreeController.js +103 -83
  14. package/dist/shared/assistant/voice/handsfree/sttTransport.d.ts +20 -0
  15. package/dist/shared/assistant/voice/handsfree/useHandsFreeInterrupt.d.ts +8 -0
  16. package/dist/shared/assistant/voice/handsfree/useHandsFreeInterrupt.js +31 -26
  17. package/dist/shared/assistant/voice/handsfree/webSpeechTransport.js +1 -0
  18. package/dist/shared/assistant/voice/livePhraseSpeech.d.ts +29 -0
  19. package/dist/shared/assistant/voice/livePhraseSpeech.js +50 -39
  20. package/dist/shared/assistant/voice/phraseSpeechConfig.d.ts +44 -2
  21. package/dist/shared/assistant/voice/phraseSpeechConfig.js +9 -6
  22. package/dist/shared-assistant.js +399 -399
  23. package/package.json +1 -1
@@ -35,6 +35,13 @@ export interface SttTransportError {
35
35
  export interface SttTransportHandlers {
36
36
  onTranscript(transcript: TransportTranscript): void;
37
37
  onError(error: SttTransportError): void;
38
+ /**
39
+ * The recogniser is finished with this utterance: the stream said `done`, or
40
+ * dropped it (a retryable error naming it). Transports whose words arrive
41
+ * `after-utterance` call it; for them the controller judges "nothing heard"
42
+ * here (see `SttTransport.wordsArrive`).
43
+ */
44
+ onUtteranceDone(utteranceId: string): void;
38
45
  }
39
46
  export interface SttAudioGraph {
40
47
  context: AudioContext;
@@ -58,6 +65,19 @@ export interface SttTransport {
58
65
  readonly recognitionOwner: 'transport' | 'session-hook';
59
66
  /** Whether the words spoken BEFORE the onset was confirmed reach the recogniser. */
60
67
  readonly keepsOpeningWords: boolean;
68
+ /**
69
+ * When an utterance's first words can arrive (read only when
70
+ * `recognitionOwner` is `transport`):
71
+ * - `while-speaking`: the recogniser sends partial text as the person talks
72
+ * (Chrome's, with `interimResults`), so no words for `NOTHING_HEARD_MS`
73
+ * after a barge-in means nothing was heard;
74
+ * - `after-utterance`: the first words may come only once the utterance is
75
+ * finalised. Our stream on Google's `chirp_3` sends no partial text (alpha,
76
+ * 17 Nov: one final, 1.0 s after `end`), so a fixed timer would call every
77
+ * real interruption "nothing heard". The controller waits for
78
+ * `onUtteranceDone` instead.
79
+ */
80
+ readonly wordsArrive: 'while-speaking' | 'after-utterance';
61
81
  start(graph: SttAudioGraph | null, language: string, handlers: SttTransportHandlers): Promise<void>;
62
82
  openUtterance(utterance: OpenUtterance): void;
63
83
  /** A live 16 kHz frame while an utterance is open. */
@@ -51,5 +51,13 @@ export interface HandsFreeState {
51
51
  nothingHeard: boolean;
52
52
  /** Non-null exactly while `mode` is `notice`: what the notice's buttons do. */
53
53
  privacyNotice: HandsFreePrivacyNoticeActions | null;
54
+ /**
55
+ * The running transport sends an utterance's words only once it is finalised
56
+ * (our stream on chirp_3, BOFF-12936): the session times its pause from the
57
+ * last voiced frame instead of from the words.
58
+ */
59
+ wordsAfterUtterance: boolean;
60
+ /** On such a transport: words of this turn are still to come; nothing may be sent yet. */
61
+ wordsPending: boolean;
54
62
  }
55
63
  export declare function useHandsFreeInterrupt(options: UseHandsFreeInterruptOptions): HandsFreeState;
@@ -17,39 +17,41 @@ var y = (e) => e === "listening" || e === "thinking" || e === "speaking";
17
17
  function b(t) {
18
18
  let { enabled: r, phase: i, muted: b, language: x, streamNoticeAccepted: S } = t, C = m(t);
19
19
  C.current = t;
20
- let [w, T] = h(null), [E, D] = h(!1), [O, k] = h(!1), [A, j] = h(!1), M = m(!1), [N, P] = h(!1), F = g(u, l, l), I = p(() => v(x, F), [x, F]), L = I.kind;
20
+ let [w, T] = h(null), [E, D] = h(!1), [O, k] = h(!1), [A, j] = h(!1), [M, N] = h(!1), [P, F] = h(!1), I = m(!1), [L, R] = h(!1), z = g(u, l, l), B = p(() => v(x, z), [x, z]), V = B.kind;
21
21
  f(() => {
22
- S !== "google-stt-eu-1" && P(!1);
22
+ S !== "google-stt-eu-1" && R(!1);
23
23
  }, [S]), f(() => {
24
24
  (i === "idle" || i === "ended") && (T(null), D(!1));
25
25
  }, [i]), f(() => {
26
26
  if (!r || typeof document > "u") return;
27
27
  let e = null, t = () => {
28
- e !== null && clearTimeout(e), e = null, document.visibilityState === "hidden" ? e = setTimeout(() => k(!0), _) : k(!1);
28
+ e !== null && clearTimeout(e), e = null, document.visibilityState === "hidden" ? e = setTimeout(() => N(!0), _) : N(!1);
29
29
  };
30
30
  return document.addEventListener("visibilitychange", t), () => {
31
31
  document.removeEventListener("visibilitychange", t), e !== null && clearTimeout(e);
32
32
  };
33
33
  }, [r]);
34
- let R = r && I.supported && y(i) && !b && w === null && !O, z = L === "backend-stream" && !N && S !== "google-stt-eu-1", B = R && z, V = R && !z, H = d(() => {
35
- P(!0), C.current.onAcceptStreamNotice?.(c);
36
- }, []), U = d(() => {
34
+ let H = r && B.supported && y(i) && !b && w === null && !M, U = V === "backend-stream" && !L && S !== "google-stt-eu-1", W = H && U, G = H && !U, K = d(() => {
35
+ R(!0), C.current.onAcceptStreamNotice?.(c);
36
+ }, []), q = d(() => {
37
37
  T("notice-declined");
38
- }, []), W = p(() => ({
39
- accept: H,
40
- decline: U
41
- }), [H, U]);
38
+ }, []), J = p(() => ({
39
+ accept: K,
40
+ decline: q
41
+ }), [K, q]);
42
42
  f(() => {
43
- if (!V) return;
44
- let t = e({
43
+ if (!G) return;
44
+ let t = n(V);
45
+ k(t.recognitionOwner === "transport" && t.wordsArrive === "after-utterance");
46
+ let r = e({
45
47
  startCapture: o,
46
- transport: n(L),
48
+ transport: t,
47
49
  getSession: () => ({
48
50
  phase: C.current.phase,
49
51
  muted: C.current.muted
50
52
  }),
51
53
  getPlaybackSource: s,
52
- getHeadsetHint: () => M.current,
54
+ getHeadsetHint: () => I.current,
53
55
  language: () => C.current.language,
54
56
  onBargeIn: () => {
55
57
  D(!1), C.current.onBargeIn();
@@ -60,24 +62,27 @@ function b(t) {
60
62
  onSpeechFrame: (e) => C.current.onSpeechFrame?.(e),
61
63
  onFallback: T,
62
64
  onNothingHeard: () => D(!0),
65
+ onWordsPending: j,
63
66
  isEnabled: () => C.current.enabled
64
- }), r = !1;
65
- return t.start().then(() => {
66
- r || j(!0);
67
+ }), i = !1;
68
+ return r.start().then(() => {
69
+ i || F(!0);
67
70
  }), navigator.mediaDevices?.enumerateDevices().then((e) => {
68
- M.current = a(e.filter((e) => e.kind === "audiooutput").map((e) => e.label));
71
+ I.current = a(e.filter((e) => e.kind === "audiooutput").map((e) => e.label));
69
72
  }).catch(() => void 0), () => {
70
- r = !0, t.stop(), j(!1);
73
+ i = !0, r.stop(), F(!1), k(!1), j(!1);
71
74
  };
72
- }, [V, L]);
73
- let G = "off";
74
- return r && !I.supported ? G = "unavailable" : w === null ? B ? G = "notice" : V && (G = A ? "active" : "starting") : G = "fallback", {
75
- mode: G,
76
- transportKind: I.supported ? L : null,
77
- suppressWebSpeech: r && I.supported && L !== "web-speech" && w === null && y(i),
75
+ }, [G, V]);
76
+ let Y = "off";
77
+ return r && !B.supported ? Y = "unavailable" : w === null ? W ? Y = "notice" : G && (Y = P ? "active" : "starting") : Y = "fallback", {
78
+ mode: Y,
79
+ transportKind: B.supported ? V : null,
80
+ suppressWebSpeech: r && B.supported && V !== "web-speech" && w === null && y(i),
78
81
  fallbackReason: w,
79
82
  nothingHeard: E,
80
- privacyNotice: G === "notice" ? W : null
83
+ privacyNotice: Y === "notice" ? J : null,
84
+ wordsAfterUtterance: O,
85
+ wordsPending: A
81
86
  };
82
87
  }
83
88
  export { _ as HIDDEN_RELEASE_MS, b as useHandsFreeInterrupt };
@@ -4,6 +4,7 @@ function e() {
4
4
  kind: "web-speech",
5
5
  recognitionOwner: "session-hook",
6
6
  keepsOpeningWords: !1,
7
+ wordsArrive: "while-speaking",
7
8
  async start() {},
8
9
  openUtterance() {},
9
10
  pushFrame() {},
@@ -9,6 +9,35 @@ export interface LivePhraseSpeech {
9
9
  export declare function createLivePhraseSpeech(options: {
10
10
  append(phrases: readonly string[], visible: string): void;
11
11
  retract(): void;
12
+ /**
13
+ * ★ BOFF-12936 (production): speak ONLY text known to be part of the final
14
+ * answer, and nothing while a tool step may still follow.
15
+ *
16
+ * Alpha's release rules are a bet that a sentence followed by a tool call is
17
+ * rare: the first of two completed sentences is spoken, and a lone sentence
18
+ * after `NARRATION_HOLD_MS`. Narration of two sentences before a tool, or a
19
+ * tool frame that arrives after the hold, is spoken and then withdrawn (a
20
+ * phrase that has started sounding cannot be taken back), and the recogniser
21
+ * has been stopped for it while the model is still working.
22
+ *
23
+ * With this on there is no bet. The stream cannot say that a step is the last
24
+ * one while its text is being written: a tool call may follow the text, in
25
+ * the same step, and the step's finish reason arrives only with the frame
26
+ * that ends it. So nothing is released until EVERY text part of the step has
27
+ * ended AND the step has completed, with no tool frame after any of the text
28
+ * and a finish reason that is not a tool call (or an error). Then the phrases
29
+ * of all the step's text parts are released at once, in the order the parts
30
+ * were written: a step may write its answer in more than one text part
31
+ * (reasoning between them), and the newest part alone is not the answer. A
32
+ * step that ended in a tool call is never spoken.
33
+ *
34
+ * A part that cannot be vouched for (not live from its start, gapped, frozen,
35
+ * from an older stream, or followed by a tool) withholds the WHOLE step.
36
+ * Speaking only the parts that can be would leave a hole in the middle of the
37
+ * answer that the final reconciliation cannot fill (it resumes after the last
38
+ * sentence spoken); withheld, the answer is read whole when the turn is done.
39
+ */
40
+ holdForFinalAnswer?: boolean;
12
41
  setTimer?: (run: () => void, ms: number) => unknown;
13
42
  clearTimer?: (timer: unknown) => void;
14
43
  }): LivePhraseSpeech;
@@ -1,59 +1,70 @@
1
1
  import { phraseCandidates as e } from "./phraseGate.js";
2
2
  import { toSpeakableText as t } from "./speakableText.js";
3
3
  // src/shared/assistant/voice/livePhraseSpeech.ts
4
- var n = 700;
5
- function r(n) {
6
- let r = n.setTimer ?? ((e, t) => setTimeout(e, t)), i = n.clearTimer ?? ((e) => {
4
+ var n = 700, r = /* @__PURE__ */ new Set(["tool-calls", "error"]);
5
+ function i(n) {
6
+ let i = n.holdForFinalAnswer === !0, a = n.setTimer ?? ((e, t) => setTimeout(e, t)), o = n.clearTimer ?? ((e) => {
7
7
  clearTimeout(e);
8
- }), a = null, o = "", s = [], c = [], l = "", u = !1, d = !1, f = () => {
9
- a !== null && i(a), a = null;
10
- }, p = () => {
11
- f(), n.retract(), u = !0;
12
- }, m = (e) => {
13
- if (d || u || e <= s.length) return;
14
- let t = c.slice(s.length, e);
15
- s = c.slice(0, e), n.append(t, l);
16
- }, h = (e, t) => {
8
+ }), s = null, c = "", l = [], u = [], d = "", f = !1, p = !1, m = () => {
9
+ s !== null && o(s), s = null;
10
+ }, h = () => {
11
+ m(), n.retract(), f = !0;
12
+ }, g = (e) => {
13
+ if (p || f || e <= l.length) return;
14
+ let t = u.slice(l.length, e);
15
+ l = u.slice(0, e), n.append(t, d);
16
+ }, _ = (e, t) => {
17
17
  let n = [...e.messages].filter(([, e]) => (e.created ?? 0) > t);
18
18
  n.sort((e, t) => (e[1].created ?? 0) - (t[1].created ?? 0));
19
19
  let r = n.at(-1)?.[0];
20
- return [...e.parts].filter(([, e]) => e.messageId === r).at(-1);
21
- };
20
+ if (r === void 0) return;
21
+ let a = [...e.parts].filter(([, e]) => e.messageId === r), o = a.at(-1);
22
+ if (o) return i ? {
23
+ key: r,
24
+ messageId: r,
25
+ parts: a
26
+ } : {
27
+ key: `${r}/${o[0]}/${o[1].generation}`,
28
+ messageId: r,
29
+ parts: [o]
30
+ };
31
+ }, v = (e, t) => e.parts.some(([, e]) => !e.live || e.gapped || e.frozen || e.toolAfter || e.generation !== t.generation);
22
32
  return {
23
33
  invalidate(e, t) {
24
- if (d || !o) return;
25
- let n = h(e, t);
26
- if (!n) {
27
- p();
28
- return;
29
- }
30
- let [r, i] = n;
31
- (`${i.messageId}/${r}/${i.generation}` !== o || !i.live || i.gapped || i.frozen || i.toolAfter || i.generation !== e.generation) && p();
34
+ if (p || !c) return;
35
+ let n = _(e, t);
36
+ (!n || n.key !== c || v(n, e)) && h();
32
37
  },
33
- update(i, g, _) {
34
- if (d) return;
35
- let v = h(g, _);
36
- if (!v) return;
37
- let [y, b] = v, x = `${b.messageId}/${y}/${b.generation}`;
38
- if (x !== o && (f(), o && n.retract(), o = x, s = [], u = !1), !b.live || b.gapped || b.frozen || b.toolAfter || b.generation !== g.generation) {
39
- p();
38
+ update(o, y, b) {
39
+ if (p) return;
40
+ let x = _(y, b);
41
+ if (!x) return;
42
+ if (x.key !== c && (m(), c && n.retract(), c = x.key, l = [], f = !1), v(x, y)) {
43
+ h();
40
44
  return;
41
45
  }
42
- if (u) return;
43
- let S = b.ended && g.messages.get(b.messageId)?.completed !== void 0;
44
- if (c = e(b.text, S), s.some((e, t) => c[t] !== e)) {
45
- p();
46
+ if (f) return;
47
+ let S = y.messages.get(x.messageId), C = x.parts.every(([, e]) => e.ended) && S?.completed !== void 0;
48
+ if (i) {
49
+ if (C && S?.finish !== void 0 && r.has(S.finish)) {
50
+ h();
51
+ return;
52
+ }
53
+ if (!C) return;
54
+ }
55
+ if (u = x.parts.flatMap(([, t]) => e(t.text, C)), l.some((e, t) => u[t] !== e)) {
56
+ h();
46
57
  return;
47
58
  }
48
- l = i;
49
- let C = t(i).replace(/\s+/g, " ");
50
- c.some((e) => !C.includes(e.replace(/\s+/g, " "))) ? p() : S ? (f(), m(c.length)) : (m(Math.max(0, c.length - 1)), s.length === c.length ? f() : a === null && (a = r(() => {
51
- a = null, m(c.length);
59
+ d = o;
60
+ let w = t(o).replace(/\s+/g, " ");
61
+ u.some((e) => !w.includes(e.replace(/\s+/g, " "))) ? h() : C ? (m(), g(u.length)) : (g(Math.max(0, u.length - 1)), l.length === u.length ? m() : s === null && (s = a(() => {
62
+ s = null, g(u.length);
52
63
  }, 700)));
53
64
  },
54
65
  close() {
55
- d = !0, f();
66
+ p = !0, m();
56
67
  }
57
68
  };
58
69
  }
59
- export { n as NARRATION_HOLD_MS, r as createLivePhraseSpeech };
70
+ export { n as NARRATION_HOLD_MS, i as createLivePhraseSpeech };
@@ -1,5 +1,47 @@
1
- export declare function configurePhraseSpeech(options: {
1
+ /**
2
+ * Per-app S7 opt-in (BOFF-8062): a voice reply spoken sentence by sentence as
3
+ * it is written, instead of whole once it is done. Runtime configuration only;
4
+ * never persisted or inferred.
5
+ *
6
+ * ★ Alpha takes `enabled: true` with `environment: 'alpha'`, as before.
7
+ * Production takes a second, explicit word from the app as well:
8
+ * `allowProduction: true` (BOFF-12936). Without it a production build keeps
9
+ * whole-answer speech, and every other environment (local, dev, anything
10
+ * unknown) stays off whatever it passes.
11
+ *
12
+ * ★ Production speaks LESS than alpha, on purpose. Alpha releases a sentence as
13
+ * soon as a second one has been written, and a lone sentence after 700 ms,
14
+ * betting that a sentence followed by a tool call is rare. Production does not
15
+ * bet: nothing is spoken while a tool step may still follow. The stream cannot
16
+ * say that a step is the last one while it is being written (a step's finish
17
+ * reason arrives with its end, and a tool call may follow its text), so
18
+ * production holds every phrase until the step that wrote the text has
19
+ * finished, without a tool call (`phraseSpeechEnvironment() === 'production'`,
20
+ * read by the narrator as `holdForFinalAnswer`).
21
+ *
22
+ * ★ On or off, phrases come from the turn's LIVE STREAM only. The narrator
23
+ * (`createLivePhraseSpeech`) reads text parts the SSE stream carried from their
24
+ * start, and nothing else: no poll text, no reasoning part, no tool part. A
25
+ * turn on the poll transport (a relay that refuses the stream, a browser
26
+ * without EventSource, the `transport=poll` override) is read whole once it is
27
+ * done, exactly as it is today.
28
+ */
29
+ export interface PhraseSpeechOptions {
30
+ /** The app's own switch for this build. */
2
31
  enabled: boolean;
32
+ /** The app's deploy environment (`VITE_DEPLOY_ENV`). */
3
33
  environment: string;
4
- } | null): void;
34
+ /** Production as well as alpha. Off unless the app passes `true`. */
35
+ allowProduction?: boolean;
36
+ }
37
+ /** The environment whose opt-in is on. */
38
+ export type PhraseSpeechEnvironment = 'alpha' | 'production';
39
+ export declare function configurePhraseSpeech(options: PhraseSpeechOptions | null): void;
5
40
  export declare function phraseSpeechEnabled(): boolean;
41
+ /**
42
+ * Which opt-in is on, or null when phrase speech is off. It decides how the
43
+ * narrator releases phrases: alpha keeps its lone-sentence hold, production
44
+ * holds every phrase until the step that wrote it has finished without a tool
45
+ * (`createLivePhraseSpeech`'s `holdForFinalAnswer`).
46
+ */
47
+ export declare function phraseSpeechEnvironment(): PhraseSpeechEnvironment | null;
@@ -1,9 +1,12 @@
1
1
  // src/shared/assistant/voice/phraseSpeechConfig.ts
2
- var e = !1;
3
- function t(t) {
4
- e = t?.enabled === !0 && t.environment === "alpha";
2
+ var e = /* @__PURE__ */ new Set(["prod", "production"]), t = null;
3
+ function n(n) {
4
+ t = n?.enabled === !0 ? n.environment === "alpha" ? "alpha" : n.allowProduction === !0 && e.has(n.environment) ? "production" : null : null;
5
5
  }
6
- function n() {
7
- return e;
6
+ function r() {
7
+ return t !== null;
8
8
  }
9
- export { t as configurePhraseSpeech, n as phraseSpeechEnabled };
9
+ function i() {
10
+ return t;
11
+ }
12
+ export { n as configurePhraseSpeech, r as phraseSpeechEnabled, i as phraseSpeechEnvironment };