@burdenoff/fe-libs 2026.1114.12 → 2026.1114.13
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/dist/shared/assistant/i18nManifest.d.ts +2 -0
- package/dist/shared/assistant/i18nManifest.js +2 -0
- package/dist/shared/assistant/index.d.ts +4 -0
- package/dist/shared/assistant/ui/AssistantChatArea.js +290 -277
- package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts +6 -0
- package/dist/shared/assistant/ui/composer/AssistantComposer.js +425 -328
- package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.d.ts +64 -0
- package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.js +183 -0
- package/dist/shared/assistant/ui/voice/AssistantVoiceSession.d.ts +9 -1
- package/dist/shared/assistant/ui/voice/AssistantVoiceSession.js +233 -187
- package/dist/shared/assistant/ui/voice/LiveWaveform.d.ts +31 -0
- package/dist/shared/assistant/ui/voice/LiveWaveform.js +52 -0
- package/dist/shared/assistant/ui/voice/useLiveLevel.d.ts +21 -0
- package/dist/shared/assistant/ui/voice/useLiveLevel.js +52 -0
- package/dist/shared/assistant/voice/liveLevel.d.ts +84 -0
- package/dist/shared/assistant/voice/liveLevel.js +75 -0
- package/dist/shared-assistant.js +387 -383
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { LiveLevelSource } from '../../voice/liveLevel';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The level to draw (`useLiveLevel`). */
|
|
5
|
+
source: LiveLevelSource;
|
|
6
|
+
/** `listening`: the person's voice. `speaking`: the assistant's. */
|
|
7
|
+
tone: 'listening' | 'speaking';
|
|
8
|
+
/** Sizes the waveform; it fills its box. */
|
|
9
|
+
className?: string;
|
|
10
|
+
testId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A live, scrolling waveform (BOFF-13461, the operator, 14 Nov: "the mic for
|
|
14
|
+
* listening… animation is good [on claude.ai], make it in ours").
|
|
15
|
+
*
|
|
16
|
+
* Each frame's level enters as a bar on the right and the bars move left, so
|
|
17
|
+
* speech draws as a moving trace and a pause as a quiet line. Drawn on a canvas,
|
|
18
|
+
* outside React's render, at about 30 frames a second, and only while its source
|
|
19
|
+
* runs.
|
|
20
|
+
*
|
|
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.
|
|
25
|
+
*
|
|
26
|
+
* ★ Under either reduced-motion signal (BOFF-8566) nothing scrolls: the bars stay
|
|
27
|
+
* a still, short line. The words next to it (the status, or the words appearing
|
|
28
|
+
* in the box) carry the meaning; the waveform is decoration and `aria-hidden`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const LiveWaveform: FC<Props>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { pushLevel as e } from "../../voice/liveLevel.js";
|
|
2
|
+
import { usePrefersReducedMotion as t } from "../usePrefersReducedMotion.js";
|
|
3
|
+
import { useEffect as n, useRef as r } from "react";
|
|
4
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
5
|
+
// src/shared/assistant/ui/voice/LiveWaveform.tsx
|
|
6
|
+
var a = 3, o = 2, s = 2, c = ({ source: c, tone: l, className: u = "", testId: d }) => {
|
|
7
|
+
let f = t(), p = r(null), m = r(null);
|
|
8
|
+
return n(() => {
|
|
9
|
+
let t = p.current, n = m.current;
|
|
10
|
+
if (!t || !n) return;
|
|
11
|
+
let r = typeof n.getContext == "function" ? n.getContext("2d") : null;
|
|
12
|
+
if (!r) return;
|
|
13
|
+
let i = 0, l = 0, u = 0, d = [], h = "", g = () => {
|
|
14
|
+
if (i === 0 || l === 0) return;
|
|
15
|
+
let e = typeof window > "u" ? 1 : window.devicePixelRatio || 1;
|
|
16
|
+
r.setTransform(e, 0, 0, e, 0, 0), r.clearRect(0, 0, i, l), r.fillStyle = h;
|
|
17
|
+
let t = u * 5 - o, n = i - t;
|
|
18
|
+
for (let e = 0; e < u; e += 1) {
|
|
19
|
+
let t = f ? 0 : d[e] ?? 0, i = Math.max(s, t * l), o = n + e * 5, c = (l - i) / 2, u = Math.min(a / 2, i / 2);
|
|
20
|
+
typeof r.roundRect == "function" ? (r.beginPath(), r.roundRect(o, c, a, i, u), r.fill()) : r.fillRect(o, c, a, i);
|
|
21
|
+
}
|
|
22
|
+
}, _ = () => {
|
|
23
|
+
let e = t.getBoundingClientRect(), r = typeof window > "u" ? 1 : window.devicePixelRatio || 1;
|
|
24
|
+
for (i = Math.max(0, Math.floor(e.width)), l = Math.max(0, Math.floor(e.height)), n.width = Math.round(i * r), n.height = Math.round(l * r), n.style.width = `${i}px`, n.style.height = `${l}px`, u = Math.max(0, Math.floor((i + o) / 5)), d = d.length > u ? d.slice(d.length - u) : d; d.length < u;) d.unshift(0);
|
|
25
|
+
h = typeof getComputedStyle == "function" ? getComputedStyle(n).color : "", g();
|
|
26
|
+
};
|
|
27
|
+
_();
|
|
28
|
+
let v = typeof ResizeObserver > "u" ? null : new ResizeObserver(_);
|
|
29
|
+
v?.observe(t);
|
|
30
|
+
let y = c.subscribe((t) => {
|
|
31
|
+
f || (d = e(d, t, u), g());
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
y(), v?.disconnect();
|
|
35
|
+
};
|
|
36
|
+
}, [
|
|
37
|
+
c,
|
|
38
|
+
l,
|
|
39
|
+
f
|
|
40
|
+
]), /* @__PURE__ */ i("div", {
|
|
41
|
+
ref: p,
|
|
42
|
+
className: `relative min-w-0 overflow-hidden ${u}`,
|
|
43
|
+
"aria-hidden": "true",
|
|
44
|
+
"data-testid": d,
|
|
45
|
+
"data-tone": l,
|
|
46
|
+
children: /* @__PURE__ */ i("canvas", {
|
|
47
|
+
ref: m,
|
|
48
|
+
className: `absolute inset-0 ${l === "speaking" ? "text-action-primary-bg" : "text-text-secondary"}`
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export { c as LiveWaveform };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LiveLevelSource } from '../../voice/liveLevel';
|
|
2
|
+
export interface UseLiveLevelOptions {
|
|
3
|
+
/** Levels are produced while true, and a 0 is sent once when it turns false. */
|
|
4
|
+
active: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Read the person's microphone where a second capture is harmless (a desktop
|
|
7
|
+
* browser, `micLevelAllowed`). Elsewhere, and if the browser refuses, the
|
|
8
|
+
* level follows `pulseKey`.
|
|
9
|
+
*/
|
|
10
|
+
mic?: boolean;
|
|
11
|
+
/** Changes whenever new words are heard (the interim text): each change is a pulse. */
|
|
12
|
+
pulseKey?: string;
|
|
13
|
+
/** The assistant is speaking: a steady, speech-like motion, never the microphone. */
|
|
14
|
+
speaking?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The level a `LiveWaveform` draws (BOFF-13461). Stable for the component's
|
|
18
|
+
* life; the frames run only while `active`. See `voice/liveLevel.ts` for the two
|
|
19
|
+
* sources and why a phone never gets the microphone's own level.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useLiveLevel({ active, mic, pulseKey, speaking, }: UseLiveLevelOptions): LiveLevelSource;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createSpeechPulse as e, micLevelAllowed as t, openMicLevel as n, smoothLevel as r } from "../../voice/liveLevel.js";
|
|
2
|
+
import { useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
3
|
+
// src/shared/assistant/ui/voice/useLiveLevel.ts
|
|
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);
|
|
7
|
+
i(() => {
|
|
8
|
+
g.current = f;
|
|
9
|
+
}, [f]);
|
|
10
|
+
let _ = a(() => ({ subscribe(e) {
|
|
11
|
+
return p.add(e), () => {
|
|
12
|
+
p.delete(e);
|
|
13
|
+
};
|
|
14
|
+
} }), [p]);
|
|
15
|
+
return i(() => {
|
|
16
|
+
l && d !== "" && m.pulse();
|
|
17
|
+
}, [
|
|
18
|
+
l,
|
|
19
|
+
d,
|
|
20
|
+
m
|
|
21
|
+
]), i(() => {
|
|
22
|
+
if (!l || !u || !t(typeof navigator > "u" ? void 0 : navigator, typeof AudioContext < "u")) return;
|
|
23
|
+
let e = !1;
|
|
24
|
+
return n().then((t) => {
|
|
25
|
+
e ? t?.close() : h.current = t;
|
|
26
|
+
}), () => {
|
|
27
|
+
e = !0, h.current?.close(), h.current = null;
|
|
28
|
+
};
|
|
29
|
+
}, [l, u]), i(() => {
|
|
30
|
+
let e = (e) => {
|
|
31
|
+
for (let t of p) t(e);
|
|
32
|
+
};
|
|
33
|
+
if (!l || typeof requestAnimationFrame > "u") {
|
|
34
|
+
e(0);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let t = 0, n = 0, i = 0, a = 0, o = (s) => {
|
|
38
|
+
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);
|
|
41
|
+
a = r(a, u), e(a);
|
|
42
|
+
};
|
|
43
|
+
return t = requestAnimationFrame(o), () => {
|
|
44
|
+
cancelAnimationFrame(t), e(0);
|
|
45
|
+
};
|
|
46
|
+
}, [
|
|
47
|
+
l,
|
|
48
|
+
p,
|
|
49
|
+
m
|
|
50
|
+
]), _;
|
|
51
|
+
}
|
|
52
|
+
export { l as useLiveLevel };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live level behind the assistant's waveforms (BOFF-13461: dictation and the
|
|
3
|
+
* page's voice conversation, the operator, 14 Nov: "like claude.ai/new").
|
|
4
|
+
*
|
|
5
|
+
* A level is a number from 0 (silence) to 1 (loud), produced about 30 times a
|
|
6
|
+
* second while a waveform is on screen. Two sources:
|
|
7
|
+
*
|
|
8
|
+
* - **The microphone itself** (`openMicLevel`): an `AnalyserNode` on a capture of
|
|
9
|
+
* our own, so the bars follow the person's real voice. Only where a second
|
|
10
|
+
* capture is harmless (`micLevelAllowed`): a desktop browser. On a phone the
|
|
11
|
+
* recogniser may be a separate system service (Chrome on Android hands Web
|
|
12
|
+
* Speech to Android's recogniser; iOS to its dictation), and a page capture
|
|
13
|
+
* running beside it can take the microphone from it, which would cost the very
|
|
14
|
+
* words being dictated. A bar meter is never worth that.
|
|
15
|
+
* - **What the recogniser reports** (`createSpeechPulse`): where the microphone
|
|
16
|
+
* cannot be read, each new word heard (an interim result) is a pulse that
|
|
17
|
+
* decays, over a quiet idle ripple. It moves when the person speaks and settles
|
|
18
|
+
* when they stop, which is what the bars are there to say: "I hear you".
|
|
19
|
+
*
|
|
20
|
+
* Pure apart from `openMicLevel`; the hook (`ui/voice/useLiveLevel.ts`) runs the
|
|
21
|
+
* frames and picks the source.
|
|
22
|
+
*/
|
|
23
|
+
/** Something that produces levels; `subscribe` returns the unsubscribe. */
|
|
24
|
+
export interface LiveLevelSource {
|
|
25
|
+
subscribe(listener: (level: number) => void): () => void;
|
|
26
|
+
}
|
|
27
|
+
/** RMS of a time-domain frame (bytes centred on 128), 0..1. */
|
|
28
|
+
export declare function rmsOfFrame(frame: ArrayLike<number>): number;
|
|
29
|
+
/**
|
|
30
|
+
* RMS → a level that reads well as bar heights. Speech RMS sits around
|
|
31
|
+
* 0.02–0.2, so a linear map would leave every bar near the floor: a gentle
|
|
32
|
+
* logarithmic curve between a noise floor (about -46 dBFS) and a loud voice
|
|
33
|
+
* (about -10 dBFS), clamped to 0..1.
|
|
34
|
+
*/
|
|
35
|
+
export declare function levelFromRms(rms: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* One step of a level that rises quickly and falls slowly, like a VU meter, so
|
|
38
|
+
* the bars follow syllables without flickering.
|
|
39
|
+
*/
|
|
40
|
+
export declare function smoothLevel(previous: number, next: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* The bars' history: the newest level enters at the end and the oldest leaves,
|
|
43
|
+
* so the waveform scrolls from right to left. Never longer than `size`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function pushLevel(history: readonly number[], level: number, size: number): number[];
|
|
46
|
+
/** What `micLevelAllowed` reads (a `Navigator` satisfies it). */
|
|
47
|
+
export interface NavigatorLike {
|
|
48
|
+
userAgent?: string;
|
|
49
|
+
maxTouchPoints?: number;
|
|
50
|
+
mediaDevices?: {
|
|
51
|
+
getUserMedia?: unknown;
|
|
52
|
+
} | undefined;
|
|
53
|
+
userAgentData?: {
|
|
54
|
+
mobile?: boolean;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* May the waveform open a capture of its own beside the recogniser? Only on a
|
|
59
|
+
* desktop browser that can capture at all; never on a phone or a tablet (see the
|
|
60
|
+
* header). An iPad presents itself as a Mac, so a Mac with touch is a tablet.
|
|
61
|
+
*/
|
|
62
|
+
export declare function micLevelAllowed(nav: NavigatorLike | undefined, hasAudioContext: boolean): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The recogniser-driven level: an idle ripple, raised by `pulse()` for each word
|
|
65
|
+
* heard and decaying back. `next(now)` is called once per frame.
|
|
66
|
+
*/
|
|
67
|
+
export interface SpeechPulse {
|
|
68
|
+
pulse(strength?: number): void;
|
|
69
|
+
next(nowMs: number): number;
|
|
70
|
+
}
|
|
71
|
+
export declare function createSpeechPulse(): SpeechPulse;
|
|
72
|
+
/** A capture of our own and its analyser (`openMicLevel`). */
|
|
73
|
+
export interface MicLevelHandle {
|
|
74
|
+
/** The current level, read once per frame. */
|
|
75
|
+
read(): number;
|
|
76
|
+
close(): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Open a capture of our own and an analyser on it. Echo cancellation, noise
|
|
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.
|
|
83
|
+
*/
|
|
84
|
+
export declare function openMicLevel(): Promise<MicLevelHandle | null>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/shared/assistant/voice/liveLevel.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
if (e.length === 0) return 0;
|
|
4
|
+
let t = 0;
|
|
5
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
6
|
+
let r = ((e[n] ?? 128) - 128) / 128;
|
|
7
|
+
t += r * r;
|
|
8
|
+
}
|
|
9
|
+
return Math.sqrt(t / e.length);
|
|
10
|
+
}
|
|
11
|
+
function t(e) {
|
|
12
|
+
if (!(e > 0)) return 0;
|
|
13
|
+
let t = 20 * Math.log10(e);
|
|
14
|
+
return t <= -46 ? 0 : t >= -10 ? 1 : (t - -46) / 36;
|
|
15
|
+
}
|
|
16
|
+
function n(e, t) {
|
|
17
|
+
let n = t > e ? .6 : .18;
|
|
18
|
+
return e + (t - e) * n;
|
|
19
|
+
}
|
|
20
|
+
function r(e, t, n) {
|
|
21
|
+
if (n <= 0) return [];
|
|
22
|
+
let r = e.length >= n ? e.slice(e.length - n + 1) : e.slice();
|
|
23
|
+
for (r.push(Math.max(0, Math.min(1, t))); r.length < n;) r.unshift(0);
|
|
24
|
+
return r;
|
|
25
|
+
}
|
|
26
|
+
function i(e, t) {
|
|
27
|
+
if (!e || !t || typeof e.mediaDevices?.getUserMedia != "function" || e.userAgentData?.mobile === !0) return !1;
|
|
28
|
+
let n = e.userAgent ?? "";
|
|
29
|
+
return !(/Android|iPhone|iPad|iPod|Mobile/i.test(n) || /Macintosh/i.test(n) && (e.maxTouchPoints ?? 0) > 1);
|
|
30
|
+
}
|
|
31
|
+
function a() {
|
|
32
|
+
let e = 0, t = null;
|
|
33
|
+
return {
|
|
34
|
+
pulse(t = .85) {
|
|
35
|
+
e = Math.min(1, Math.max(e, t));
|
|
36
|
+
},
|
|
37
|
+
next(n) {
|
|
38
|
+
let r = t === null ? 0 : Math.max(0, n - t);
|
|
39
|
+
t = n, e *= .5 ** (r / 220);
|
|
40
|
+
let i = .65 + .35 * Math.abs(Math.sin(n / 97) * Math.cos(n / 61)), a = .05 + .03 * Math.abs(Math.sin(n / 420));
|
|
41
|
+
return Math.max(a, e * i);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function o() {
|
|
46
|
+
if (typeof navigator > "u" || typeof AudioContext > "u") return null;
|
|
47
|
+
let n;
|
|
48
|
+
try {
|
|
49
|
+
n = await navigator.mediaDevices.getUserMedia({ audio: {
|
|
50
|
+
echoCancellation: !0,
|
|
51
|
+
noiseSuppression: !0,
|
|
52
|
+
autoGainControl: !0
|
|
53
|
+
} });
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
let r;
|
|
58
|
+
try {
|
|
59
|
+
r = new AudioContext();
|
|
60
|
+
} catch {
|
|
61
|
+
return n.getTracks().forEach((e) => e.stop()), null;
|
|
62
|
+
}
|
|
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
|
+
return {
|
|
67
|
+
read() {
|
|
68
|
+
return s ? 0 : (a.getByteTimeDomainData(o), t(e(o)));
|
|
69
|
+
},
|
|
70
|
+
close() {
|
|
71
|
+
s || (s = !0, i.disconnect(), n.getTracks().forEach((e) => e.stop()), r.close().catch(() => void 0));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export { a as createSpeechPulse, t as levelFromRms, i as micLevelAllowed, o as openMicLevel, r as pushLevel, e as rmsOfFrame, n as smoothLevel };
|