@burdenoff/fe-libs 2026.1115.10 → 2026.1115.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  import "./captureWorklet.js";
2
2
  import { NOTHING_HEARD_MS as e, createEpochGuard as t, planOnset as n, shouldFallBackToTap as r } from "./bargeIn.js";
3
- import { EchoGate as i } from "./echoGate.js";
4
- import { MicCaptureError as a } from "./micCapture.js";
5
- import { PreRollRing as o } from "./preRollRing.js";
6
- import { DEFAULT_VAD_PARAMS as s, createVad as c } from "./vad.js";
3
+ import { DEFAULT_ECHO_GATE_PARAMS as i, EchoGate as a } from "./echoGate.js";
4
+ import { MicCaptureError as o } from "./micCapture.js";
5
+ import { PreRollRing as s } from "./preRollRing.js";
6
+ import { DEFAULT_VAD_PARAMS as c, createVad as l } from "./vad.js";
7
7
  // src/shared/assistant/voice/handsfree/handsFreeController.ts
8
- var l = {
8
+ var u = i.referenceSilentDb, d = i.tailFrames, f = {
9
9
  unavailable: "transport-unavailable",
10
10
  auth: "transport-auth",
11
11
  quota: "transport-quota",
@@ -13,113 +13,113 @@ var l = {
13
13
  closed: "transport-upstream",
14
14
  "not-allowed": "mic-denied"
15
15
  };
16
- function u(u) {
17
- let d = u.setTimer ?? ((e, t) => setTimeout(e, t)), f = u.clearTimer ?? ((e) => clearTimeout(e)), p = new i(), m = c(), h = new o(u.prerollMs ?? 700, 20), g = t(), _ = null, v = !1, y = 0, b = null, x = null, S = 0, C = null, w = 0, T = null, E = !1, D = (e) => u.onTelemetry?.(e), O = (e) => {
18
- E || (E = !0, D({
16
+ function p(i) {
17
+ let p = i.setTimer ?? ((e, t) => setTimeout(e, t)), m = i.clearTimer ?? ((e) => clearTimeout(e)), h = new a(), g = l(), _ = new s(i.prerollMs ?? 700, 20), v = t(), y = null, b = !1, x = 0, S = null, C = null, w = 0, T = null, E = -1, D = 0, O = null, k = !1, A = (e) => i.onTelemetry?.(e), j = (e) => {
18
+ k || (k = !0, A({
19
19
  type: "fallback",
20
20
  reason: e
21
- }), P(), u.onFallback(e));
22
- }, k = () => {
23
- T !== null && f(T), T = null;
24
- }, A = (e) => {
25
- if (e === C) return;
26
- let t = C;
27
- C = e, e === null ? p.playbackStopped() : (t === null || t !== e) && p.playbackStarted(e === "hosted"), m.setOnsetFrames(e === "device" ? 6 : s.onsetFrames);
28
- }, j = () => {
29
- b &&= (u.transport.closeUtterance(b.id), null);
30
- }, M = (t) => {
31
- let i = u.getSession(), a = n({
32
- enabled: u.isEnabled(),
33
- muted: i.muted,
34
- phase: i.phase,
35
- playbackAudible: C !== null
21
+ }), R(), i.onFallback(e));
22
+ }, M = () => {
23
+ O !== null && m(O), O = null;
24
+ }, N = (e, t) => e === "avatar" ? (t > u && (E = x + d), x <= E ? "avatar" : null) : (E = -1, e === "avatar-unrouted" ? i.getSession().phase === "speaking" ? "device" : null : e), P = (e) => {
25
+ if (e === T) return;
26
+ let t = T;
27
+ T = e, e === null ? h.playbackStopped() : (t === null || t !== e) && h.playbackStarted(e === "hosted" || e === "avatar"), g.setOnsetFrames(e === "device" ? 6 : c.onsetFrames);
28
+ }, F = () => {
29
+ S &&= (i.transport.closeUtterance(S.id), null);
30
+ }, I = (t) => {
31
+ let a = i.getSession(), o = n({
32
+ enabled: i.isEnabled(),
33
+ muted: a.muted,
34
+ phase: a.phase,
35
+ playbackAudible: T !== null
36
36
  });
37
- if (D({
37
+ if (A({
38
38
  type: "onset",
39
- plan: a.kind,
40
- atFrame: y,
41
- playbackSource: C,
39
+ plan: o.kind,
40
+ atFrame: x,
41
+ playbackSource: T,
42
42
  gate: t,
43
- calibration: p.calibration
44
- }), a.kind === "ignore") return;
45
- a.kind === "barge-in" && (u.onBargeIn(), D({
43
+ calibration: h.calibration
44
+ }), o.kind === "ignore") return;
45
+ o.kind === "barge-in" && (i.onBargeIn(), A({
46
46
  type: "stopped-playback",
47
- frame: y
48
- }), p.playbackStopped(), C = null, k(), u.transport.recognitionOwner === "transport" && (T = d(() => {
49
- T = null, w += 1, D({ type: "nothing-heard" }), u.onNothingHeard?.(), r(w) && O("phantom-barge-ins");
50
- }, e))), x && u.transport.cancelUtterance(x);
51
- let o = g.open();
52
- S += 1, b = {
53
- id: `u${S}`,
54
- epoch: o
55
- }, x = b.id, u.transport.openUtterance({
56
- utteranceId: b.id,
57
- epoch: o,
58
- preRoll: h.snapshot()
47
+ frame: x
48
+ }), h.playbackStopped(), T = null, M(), i.transport.recognitionOwner === "transport" && (O = p(() => {
49
+ O = null, D += 1, A({ type: "nothing-heard" }), i.onNothingHeard?.(), r(D) && j("phantom-barge-ins");
50
+ }, e))), C && i.transport.cancelUtterance(C);
51
+ let s = v.open();
52
+ w += 1, S = {
53
+ id: `u${w}`,
54
+ epoch: s
55
+ }, C = S.id, i.transport.openUtterance({
56
+ utteranceId: S.id,
57
+ epoch: s,
58
+ preRoll: _.snapshot()
59
59
  });
60
- }, N = (e) => {
61
- if (!v) return;
62
- y += 1, A(u.getPlaybackSource()), u.getHeadsetHint && p.setHeadset(u.getHeadsetHint());
63
- let t = p.pushFrame(e.rmsDb, e.refDb), n = new Int16Array(e.pcm);
64
- h.push(n);
65
- let r = m.push({
60
+ }, L = (e) => {
61
+ if (!b) return;
62
+ x += 1, P(N(i.getPlaybackSource(), e.refDb)), i.getHeadsetHint && h.setHeadset(i.getHeadsetHint());
63
+ let t = h.pushFrame(e.rmsDb, e.refDb), n = new Int16Array(e.pcm);
64
+ _.push(n);
65
+ let r = g.push({
66
66
  rmsDb: e.rmsDb,
67
67
  zcr: e.zcr
68
68
  }, t.pass);
69
- if (r.event === "onset" && M(t.reason), b && r.voiced && t.pass) {
70
- let t = u.now?.() ?? performance.now(), n = _?.context ? Math.max(0, (_.context.currentTime - e.ctxTime) * 1e3) : 0;
71
- u.onSpeechFrame?.(t - n);
69
+ if (r.event === "onset" && I(t.reason), S && r.voiced && t.pass) {
70
+ let t = i.now?.() ?? performance.now(), n = y?.context ? Math.max(0, (y.context.currentTime - e.ctxTime) * 1e3) : 0;
71
+ i.onSpeechFrame?.(t - n);
72
72
  }
73
- r.event !== "onset" && b && r.inSegment && u.transport.pushFrame(n), r.event === "end" && j();
74
- }, P = () => {
75
- if (!v && !_) return;
76
- v = !1, k(), b && u.transport.cancelUtterance(b.id), b = null, g.invalidate(), u.transport.stop(), h.clear(), p.reset(), m.reset();
77
- let e = _;
78
- _ = null, e?.stop();
73
+ r.event !== "onset" && S && r.inSegment && i.transport.pushFrame(n), r.event === "end" && F();
74
+ }, R = () => {
75
+ if (!b && !y) return;
76
+ b = !1, M(), S && i.transport.cancelUtterance(S.id), S = null, v.invalidate(), i.transport.stop(), _.clear(), h.reset(), g.reset();
77
+ let e = y;
78
+ y = null, e?.stop();
79
79
  };
80
80
  return {
81
81
  async start() {
82
- if (v || E) return;
83
- let e = u.getSession();
84
- if (!u.isEnabled() || e.muted || e.phase === "ended" || e.phase === "idle") return;
85
- v = !0;
82
+ if (b || k) return;
83
+ let e = i.getSession();
84
+ if (!i.isEnabled() || e.muted || e.phase === "ended" || e.phase === "idle") return;
85
+ b = !0;
86
86
  try {
87
- _ = await u.startCapture(N);
87
+ y = await i.startCapture(L);
88
88
  } catch (e) {
89
- v = !1, O(e instanceof a && e.reason === "not-allowed" ? "mic-denied" : "mic-unavailable");
89
+ b = !1, j(e instanceof o && e.reason === "not-allowed" ? "mic-denied" : "mic-unavailable");
90
90
  return;
91
91
  }
92
- if (!v) {
93
- _.stop(), _ = null;
92
+ if (!b) {
93
+ y.stop(), y = null;
94
94
  return;
95
95
  }
96
- let t = _ && "context" in _ && _.context && _.micSource && _.track ? {
97
- context: _.context,
98
- micSource: _.micSource,
99
- track: _.track
96
+ let t = y && "context" in y && y.context && y.micSource && y.track ? {
97
+ context: y.context,
98
+ micSource: y.micSource,
99
+ track: y.track
100
100
  } : null;
101
- await u.transport.start(t, u.language(), {
101
+ await i.transport.start(t, i.language(), {
102
102
  onTranscript(e) {
103
- g.accepts(e.epoch) ? (k(), u.onTranscript(e.text, e.final, e.language)) : D({
103
+ v.accepts(e.epoch) ? (M(), i.onTranscript(e.text, e.final, e.language)) : A({
104
104
  type: "stale-transcript-dropped",
105
105
  epoch: e.epoch,
106
- current: g.current()
106
+ current: v.current()
107
107
  });
108
108
  },
109
109
  onError(e) {
110
- O(l[e.code]);
110
+ j(f[e.code]);
111
111
  }
112
112
  });
113
113
  },
114
- stop: P,
114
+ stop: R,
115
115
  get frames() {
116
- return y;
116
+ return x;
117
117
  },
118
- feed: N,
119
- epoch: g,
118
+ feed: L,
119
+ epoch: v,
120
120
  get running() {
121
- return v;
121
+ return b;
122
122
  }
123
123
  };
124
124
  }
125
- export { u as createHandsFreeController };
125
+ export { p as createHandsFreeController };
@@ -24,8 +24,13 @@ export declare function resolveStoredHandsFree(value: unknown): boolean;
24
24
  * override included (`useLiveAvatarHandsFreeGuard`). Its voice plays on the
25
25
  * speakers, where the microphone hears it, and hands-free would take it for
26
26
  * the person speaking over the reply. Without an avatar, as before.
27
+ *
28
+ * ★ P5 (BOFF-12936) lifts that rule only where `avatarEchoReference` is true:
29
+ * the host opted in (`AssistantLiveAvatarSeam.handsFreeWithAvatar`) and this
30
+ * browser can route the avatar's received voice into the echo gate's reference
31
+ * (`isAvatarVoiceReferenceSupported`). The person's own setting still decides.
27
32
  */
28
- export declare function resolveHandsFreeEnabled(stored: unknown, override: unknown, avatarOn?: boolean): boolean;
33
+ export declare function resolveHandsFreeEnabled(stored: unknown, override: unknown, avatarOn?: boolean, avatarEchoReference?: boolean): boolean;
29
34
  export declare function readHandsFreeOverride(): HandsFreeOverride | undefined;
30
35
  export type TransportOverride = 'web-speech' | 'audio-track' | 'backend-stream';
31
36
  export declare function readTransportOverride(): TransportOverride | undefined;
@@ -3,8 +3,8 @@ var e = "__boffHandsFreeInterrupt", t = "__boffHandsFreeTransport";
3
3
  function n(e) {
4
4
  return e === !0;
5
5
  }
6
- function r(e, t, r = !1) {
7
- return r ? !1 : t === "on" || t !== "off" && n(e);
6
+ function r(e, t, r = !1, i = !1) {
7
+ return r && !i ? !1 : t === "on" || t !== "off" && n(e);
8
8
  }
9
9
  function i(e) {
10
10
  try {
@@ -18,13 +18,48 @@
18
18
  * The device `speechSynthesis` voice does not pass through the browser's output
19
19
  * graph and cannot be tapped. It reports itself through `setDeviceVoice` so the
20
20
  * gate can switch to its no-reference mode; the browser engine calls it.
21
+ *
22
+ * ★ P5, the live avatar's voice (BOFF-12936). The avatar does not speak through
23
+ * an element made here: its voice arrives on a WebRTC track that the avatar room
24
+ * plays in its own element. While the avatar is connected its controller
25
+ * registers here (`registerAvatarVoice`) and hands over the received track once
26
+ * the room has it (`setTrack`). While a capture graph is attached the track is
27
+ * routed
28
+ * track -> MediaStreamSource -> reference bus
29
+ * and NOT to the speakers (the room's element already plays it), so the echo
30
+ * gate meters the avatar's voice on the microphone's clock exactly as it meters
31
+ * the hosted voice. FAIL CLOSED: while an avatar is registered and its voice is
32
+ * not routed (no track yet, no MediaStreamSource, a routing error), the source
33
+ * is 'avatar-unrouted': there is no reference, so the controller treats the
34
+ * avatar like the device voice while a reply is spoken, and tap-to-interrupt
35
+ * stays the fallback.
36
+ */
37
+ export type PlaybackSource = 'hosted' | 'avatar' | 'avatar-unrouted' | 'device' | null;
38
+ /** The avatar controller's handle on its voice reference (P5). */
39
+ export interface AvatarVoiceRegistration {
40
+ /** The avatar's received audio track, once the room has it; null when it has none to give. */
41
+ setTrack(track: MediaStreamTrack | null): void;
42
+ /** The avatar disconnected: stop referencing its voice. Idempotent. */
43
+ release(): void;
44
+ }
45
+ /**
46
+ * Whether this browser can route a received audio track into the reference bus
47
+ * so that the gate hears the avatar. Without it the avatar's voice can never be
48
+ * referenced, so the avatar pilot rule (hands-free OFF while the avatar is ON)
49
+ * must hold. WebKit is excluded until proven (see `isWebKitEngine`).
21
50
  */
22
- export type PlaybackSource = 'hosted' | 'device' | null;
51
+ export declare function isAvatarVoiceReferenceSupported(): boolean;
52
+ /**
53
+ * Register a connected live avatar (P5). Until `setTrack` gives a track that is
54
+ * routed, the playback source reads 'avatar-unrouted' (fail closed).
55
+ */
56
+ export declare function registerAvatarVoice(): AvatarVoiceRegistration;
23
57
  export declare function attachPlaybackReference(context: AudioContext, referenceBus: AudioNode): void;
24
58
  /**
25
59
  * Stop referencing. `closeContext` is run now, or - if a tapped element is
26
60
  * still playing through the context - when the last one ends, so muting the
27
- * microphone never cuts a reply off mid-word.
61
+ * microphone never cuts a reply off mid-word. An avatar's voice route belongs to
62
+ * the closing context, so it is dropped now; the next attach routes it again.
28
63
  */
29
64
  export declare function detachPlaybackReference(closeContext: () => void): void;
30
65
  /**
@@ -42,7 +77,14 @@ export declare function tapPlaybackElement(element: HTMLMediaElement): void;
42
77
  /** Cut every tapped element's output at once (a barge-in). */
43
78
  export declare function silencePlaybackReference(): void;
44
79
  export declare function setDeviceVoice(speaking: boolean): void;
45
- /** What is making sound right now, if anything. */
80
+ /**
81
+ * What is making sound right now, if anything. A connected avatar is reported
82
+ * the whole time it is connected, silent or not ('avatar' when its voice is
83
+ * routed, 'avatar-unrouted' when not): the controller decides from the
84
+ * reference level when it is audible, and from the session when an unrouted
85
+ * one may be speaking. The device voice wins over a connected avatar: it has no
86
+ * reference, so while it speaks nothing on the reference bus can explain it.
87
+ */
46
88
  export declare function activePlaybackSource(): PlaybackSource;
47
89
  /** Test seam: forget everything. */
48
90
  export declare function resetPlaybackReferenceForTest(): void;
@@ -1,23 +1,70 @@
1
1
  // src/shared/assistant/voice/handsfree/playbackReference.ts
2
- var e = null, t = null, n = [], r = !1;
3
- function i(t, n) {
2
+ var e = null, t = null, n = [], r = !1, i = [];
3
+ function a(t) {
4
+ let n = e;
5
+ if (!(n === null || t.track === null || t.node !== null || t.released)) try {
6
+ let e = n.context.createMediaStreamSource(new MediaStream([t.track]));
7
+ e.connect(n.referenceBus), t.node = e;
8
+ } catch {
9
+ t.node = null;
10
+ }
11
+ }
12
+ function o(e) {
13
+ let t = e.node;
14
+ if (e.node = null, t !== null) try {
15
+ t.disconnect();
16
+ } catch {}
17
+ }
18
+ function s() {
19
+ try {
20
+ let e = globalThis.navigator, t = e?.userAgent;
21
+ return typeof t != "string" || /\b(iPhone|iPad|iPod)\b/.test(t) || /\bMacintosh\b/.test(t) && (e?.maxTouchPoints ?? 0) > 1 ? !0 : /AppleWebKit/.test(t) && !/(Chrome|Chromium|Edg|OPR|Firefox|Android)/.test(t);
22
+ } catch {
23
+ return !0;
24
+ }
25
+ }
26
+ function c() {
27
+ try {
28
+ return typeof MediaStream == "function" && typeof AudioContext == "function" && typeof AudioContext.prototype.createMediaStreamSource == "function" && !s();
29
+ } catch {
30
+ return !1;
31
+ }
32
+ }
33
+ function l() {
34
+ let e = {
35
+ track: null,
36
+ node: null,
37
+ released: !1
38
+ };
39
+ return i.push(e), {
40
+ setTrack(t) {
41
+ e.released || e.track === t || (o(e), e.track = t, a(e));
42
+ },
43
+ release() {
44
+ e.released || (e.released = !0, o(e), i = i.filter((t) => t !== e));
45
+ }
46
+ };
47
+ }
48
+ function u(t, n) {
4
49
  e = {
5
50
  context: t,
6
51
  referenceBus: n
7
52
  };
53
+ for (let e of i) a(e);
8
54
  }
9
- function a(r) {
55
+ function d(r) {
56
+ for (let e of i) o(e);
10
57
  e = null, n.some((e) => e.active) ? t = r : (n = [], r());
11
58
  }
12
- function o(e, r) {
59
+ function f(e, r) {
13
60
  if (e.active = r, r || !t || n.some((e) => e.active)) return;
14
61
  let i = t;
15
62
  t = null, n = [], i();
16
63
  }
17
- function s() {
64
+ function p() {
18
65
  return e !== null;
19
66
  }
20
- function c(t) {
67
+ function m(t) {
21
68
  let r = e;
22
69
  if (r) try {
23
70
  let e = r.context.createMediaElementSource(t), i = r.context.createGain();
@@ -27,27 +74,27 @@ function c(t) {
27
74
  gain: i,
28
75
  active: !1
29
76
  };
30
- n.push(a), t.addEventListener("playing", () => o(a, !0));
77
+ n.push(a), t.addEventListener("playing", () => f(a, !0));
31
78
  for (let e of [
32
79
  "pause",
33
80
  "ended",
34
81
  "error",
35
82
  "emptied"
36
- ]) t.addEventListener(e, () => o(a, !1));
83
+ ]) t.addEventListener(e, () => f(a, !1));
37
84
  } catch {}
38
85
  }
39
- function l() {
86
+ function h() {
40
87
  for (let e of n) try {
41
88
  e.gain.gain.value = 0;
42
89
  } catch {}
43
90
  }
44
- function u(e) {
91
+ function g(e) {
45
92
  r = e;
46
93
  }
47
- function d() {
48
- return n.some((e) => e.active) ? "hosted" : r ? "device" : null;
94
+ function _() {
95
+ return n.some((e) => e.active) ? "hosted" : r ? "device" : i.length > 0 ? i.every((e) => e.node !== null) ? "avatar" : "avatar-unrouted" : null;
49
96
  }
50
- function f() {
51
- e = null, t = null, n = [], r = !1;
97
+ function v() {
98
+ e = null, t = null, n = [], r = !1, i = [];
52
99
  }
53
- export { d as activePlaybackSource, i as attachPlaybackReference, a as detachPlaybackReference, s as isPlaybackReferenceAttached, f as resetPlaybackReferenceForTest, u as setDeviceVoice, l as silencePlaybackReference, c as tapPlaybackElement };
100
+ export { _ as activePlaybackSource, u as attachPlaybackReference, d as detachPlaybackReference, c as isAvatarVoiceReferenceSupported, p as isPlaybackReferenceAttached, l as registerAvatarVoice, v as resetPlaybackReferenceForTest, g as setDeviceVoice, h as silencePlaybackReference, m as tapPlaybackElement };