@burdenoff/fe-libs 2026.1114.13 → 2026.1114.14
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/conversation.d.ts +16 -0
- package/dist/shared/assistant/i18nManifest.d.ts +30 -0
- package/dist/shared/assistant/i18nManifest.js +30 -0
- package/dist/shared/assistant/index.d.ts +6 -0
- package/dist/shared/assistant/store.d.ts +7 -0
- package/dist/shared/assistant/store.js +3 -0
- package/dist/shared/assistant/ui/AssistantChatArea.js +1269 -1188
- package/dist/shared/assistant/ui/AssistantMessageList.d.ts +14 -0
- package/dist/shared/assistant/ui/AssistantMessageList.js +55 -52
- package/dist/shared/assistant/ui/composer/AssistantComposer.js +387 -395
- package/dist/shared/assistant/ui/composer/AssistantDictation.d.ts +42 -0
- package/dist/shared/assistant/ui/composer/AssistantDictation.js +127 -0
- package/dist/shared/assistant/ui/composer/AssistantMicMenu.d.ts +23 -0
- package/dist/shared/assistant/ui/composer/AssistantMicMenu.js +176 -0
- package/dist/shared/assistant/ui/composer/microphones.d.ts +13 -0
- package/dist/shared/assistant/ui/composer/microphones.js +15 -0
- package/dist/shared/assistant/ui/composer/useCompactDictation.d.ts +70 -0
- package/dist/shared/assistant/ui/composer/useCompactDictation.js +136 -0
- package/dist/shared/assistant/ui/useVoiceSession.js +166 -164
- package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.d.ts +20 -17
- package/dist/shared/assistant/ui/voice/AssistantPageVoiceBar.js +230 -123
- package/dist/shared/assistant/ui/voice/AssistantVoiceSession.d.ts +2 -0
- package/dist/shared/assistant/ui/voice/AssistantVoiceSession.js +227 -229
- package/dist/shared/assistant/ui/voice/AssistantVoiceSessionButton.d.ts +5 -0
- package/dist/shared/assistant/ui/voice/AssistantVoiceSessionButton.js +6 -6
- package/dist/shared/assistant/ui/voice/LiveWaveform.d.ts +4 -3
- package/dist/shared/assistant/ui/voice/LiveWaveform.js +1 -1
- package/dist/shared/assistant/ui/voice/VoiceTurnMarks.d.ts +15 -0
- package/dist/shared/assistant/ui/voice/VoiceTurnMarks.js +43 -0
- package/dist/shared/assistant/ui/voice/formatClock.d.ts +2 -0
- package/dist/shared/assistant/ui/voice/formatClock.js +3 -0
- package/dist/shared/assistant/ui/voice/useLiveLevel.d.ts +3 -1
- package/dist/shared/assistant/ui/voice/useLiveLevel.js +23 -19
- package/dist/shared/assistant/voice/liveLevel.d.ts +4 -3
- package/dist/shared/assistant/voice/liveLevel.js +18 -15
- package/dist/shared/assistant/voice/useVoiceInput.d.ts +27 -1
- package/dist/shared/assistant/voice/useVoiceInput.js +141 -71
- package/dist/shared-assistant.js +383 -377
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { LiveLevelSource } from '../../voice/liveLevel';
|
|
3
|
+
import { CompactDictationPhase } from './useCompactDictation';
|
|
4
|
+
/**
|
|
5
|
+
* Dictation in the compact message box (BOFF-13461; the operator's design of 14 Nov,
|
|
6
|
+
* "Dictation states"): what the box shows while the mic types for the person.
|
|
7
|
+
* The state lives in `useCompactDictation`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The box's text while dictating: the draft around the cursor, the finished words
|
|
11
|
+
* of this take, and the words still being recognised (dimmed). Typing is paused, so
|
|
12
|
+
* this stands in for the text area. Dimmed as a whole while the take is turned into
|
|
13
|
+
* text.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DictationLiveText: FC<{
|
|
16
|
+
phase: CompactDictationPhase;
|
|
17
|
+
before: string;
|
|
18
|
+
take: string;
|
|
19
|
+
interim: string;
|
|
20
|
+
after: string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* The controls row while dictating. Listening: a live dot, the live waveform and the
|
|
24
|
+
* time on the left; Cancel and Finish on the right. Turning speech into text: a
|
|
25
|
+
* spinner and those words, and nothing to press.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DictationControls: FC<{
|
|
28
|
+
phase: CompactDictationPhase;
|
|
29
|
+
seconds: number;
|
|
30
|
+
level: LiveLevelSource;
|
|
31
|
+
onCancel: () => void;
|
|
32
|
+
onFinish: () => void;
|
|
33
|
+
focusRing: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Above the box when the microphone cannot be used: what to do, and Try again.
|
|
37
|
+
* Typing and sending keep working the whole time.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MicBlockedNotice: FC<{
|
|
40
|
+
message: string;
|
|
41
|
+
onTryAgain: () => void;
|
|
42
|
+
}>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useAssistantTr as e } from "../../i18n.js";
|
|
2
|
+
import { usePrefersReducedMotion as t } from "../usePrefersReducedMotion.js";
|
|
3
|
+
import { focusWasDropped as n } from "../../../hooks/useReturnFocus.js";
|
|
4
|
+
import { formatClock as r } from "../voice/formatClock.js";
|
|
5
|
+
import { LiveWaveform as i } from "../voice/LiveWaveform.js";
|
|
6
|
+
import { useEffect as a, useRef as o } from "react";
|
|
7
|
+
import { Check as s, Loader2 as c, X as l } from "lucide-react";
|
|
8
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
+
// src/shared/assistant/ui/composer/AssistantDictation.tsx
|
|
10
|
+
var f = ({ phase: t, before: n, take: r, interim: i, after: a }) => {
|
|
11
|
+
let o = e(), s = r || i;
|
|
12
|
+
return /* @__PURE__ */ d("div", {
|
|
13
|
+
className: `min-h-10 whitespace-pre-wrap break-words px-4 pb-1 pt-3 text-base leading-6 ${t === "transcribing" ? "text-text-muted" : "text-text-primary"}`,
|
|
14
|
+
"data-testid": "assistant-dictation-text",
|
|
15
|
+
"data-phase": t,
|
|
16
|
+
children: [
|
|
17
|
+
n ? /* @__PURE__ */ d("span", { children: [n.replace(/\s+$/, ""), " "] }) : null,
|
|
18
|
+
r ? /* @__PURE__ */ u("span", {
|
|
19
|
+
"data-testid": "assistant-dictation-take",
|
|
20
|
+
children: r
|
|
21
|
+
}) : null,
|
|
22
|
+
i ? /* @__PURE__ */ d("span", {
|
|
23
|
+
className: "text-text-muted",
|
|
24
|
+
"data-testid": "assistant-dictation-interim",
|
|
25
|
+
children: [r ? " " : "", i]
|
|
26
|
+
}) : null,
|
|
27
|
+
!s && t !== "transcribing" ? /* @__PURE__ */ u("span", {
|
|
28
|
+
className: "text-text-muted",
|
|
29
|
+
"data-testid": "assistant-dictation-prompt",
|
|
30
|
+
children: t === "starting" ? o("voice.starting", "Starting the microphone…") : o("dictation.startSpeaking", "Listening. Start speaking.")
|
|
31
|
+
}) : null,
|
|
32
|
+
a ? /* @__PURE__ */ d("span", { children: [" ", a.replace(/^\s+/, "")] }) : null
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
}, p = ({ phase: n, seconds: r, level: i, onCancel: a, onFinish: o, focusRing: s }) => {
|
|
36
|
+
let l = e(), f = t();
|
|
37
|
+
return n === "transcribing" ? /* @__PURE__ */ d("div", {
|
|
38
|
+
role: "status",
|
|
39
|
+
className: "flex h-11 items-center gap-2.5 px-3 pb-1.5 text-sm text-text-secondary sm:h-10",
|
|
40
|
+
"data-testid": "assistant-composer-controls",
|
|
41
|
+
"data-dictating": "transcribing",
|
|
42
|
+
children: [/* @__PURE__ */ u(c, {
|
|
43
|
+
className: `size-4 text-status-warning-bg${f ? "" : " motion-safe:animate-spin"}`,
|
|
44
|
+
"aria-hidden": "true"
|
|
45
|
+
}), /* @__PURE__ */ u("span", { children: l("dictation.transcribing", "Turning speech into text") })]
|
|
46
|
+
}) : /* @__PURE__ */ u(m, {
|
|
47
|
+
listening: n === "listening",
|
|
48
|
+
seconds: r,
|
|
49
|
+
level: i,
|
|
50
|
+
onCancel: a,
|
|
51
|
+
onFinish: o,
|
|
52
|
+
focusRing: s
|
|
53
|
+
});
|
|
54
|
+
}, m = ({ listening: t, seconds: c, level: f, onCancel: p, onFinish: m, focusRing: h }) => {
|
|
55
|
+
let g = e(), _ = o(null);
|
|
56
|
+
return a(() => {
|
|
57
|
+
typeof document < "u" && n(document) && _.current?.focus();
|
|
58
|
+
}, []), /* @__PURE__ */ d("div", {
|
|
59
|
+
className: "flex flex-nowrap items-center gap-2 px-1.5 pb-1.5 pt-1",
|
|
60
|
+
"data-testid": "assistant-composer-controls",
|
|
61
|
+
"data-dictating": "true",
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ u("span", {
|
|
64
|
+
"aria-hidden": "true",
|
|
65
|
+
className: `ms-2.5 size-2.5 shrink-0 rounded-full ${t ? "bg-status-warning-bg" : "bg-text-muted"}`,
|
|
66
|
+
"data-testid": "assistant-dictation-dot"
|
|
67
|
+
}),
|
|
68
|
+
t ? /* @__PURE__ */ u(i, {
|
|
69
|
+
source: f,
|
|
70
|
+
tone: "listening",
|
|
71
|
+
className: "h-8 min-w-0 flex-1",
|
|
72
|
+
testId: "assistant-dictation-waveform"
|
|
73
|
+
}) : /* @__PURE__ */ u("span", { className: "min-w-0 flex-1" }),
|
|
74
|
+
/* @__PURE__ */ u("span", {
|
|
75
|
+
className: "shrink-0 text-xs tabular-nums text-text-secondary",
|
|
76
|
+
"aria-hidden": "true",
|
|
77
|
+
"data-testid": "assistant-dictation-time",
|
|
78
|
+
children: r(c)
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ u("button", {
|
|
81
|
+
ref: _,
|
|
82
|
+
type: "button",
|
|
83
|
+
onClick: p,
|
|
84
|
+
className: `flex size-11 shrink-0 items-center justify-center rounded-full border border-border-default text-text-primary transition-colors hover:bg-bg-sunken sm:size-10 ${h}`,
|
|
85
|
+
"aria-label": g("composer.dictationCancel", "Cancel dictation"),
|
|
86
|
+
title: g("composer.dictationCancel", "Cancel dictation"),
|
|
87
|
+
"data-testid": "assistant-voice-cancel",
|
|
88
|
+
children: /* @__PURE__ */ u(l, {
|
|
89
|
+
className: "size-5",
|
|
90
|
+
"aria-hidden": "true"
|
|
91
|
+
})
|
|
92
|
+
}),
|
|
93
|
+
/* @__PURE__ */ u("button", {
|
|
94
|
+
type: "button",
|
|
95
|
+
onClick: m,
|
|
96
|
+
disabled: !t,
|
|
97
|
+
className: `flex size-11 shrink-0 items-center justify-center rounded-full border border-status-warning-bg bg-status-warning-bg-subtle text-status-warning-text transition-colors hover:bg-status-warning-bg/20 disabled:cursor-default disabled:opacity-50 sm:size-10 ${h}`,
|
|
98
|
+
"aria-label": g("composer.dictationDone", "Finish dictation"),
|
|
99
|
+
title: g("composer.dictationDone", "Finish dictation"),
|
|
100
|
+
"aria-pressed": "true",
|
|
101
|
+
"data-testid": "assistant-voice",
|
|
102
|
+
"data-state": t ? "listening" : "starting",
|
|
103
|
+
children: /* @__PURE__ */ u(s, {
|
|
104
|
+
className: "size-5",
|
|
105
|
+
"aria-hidden": "true"
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
}, h = ({ message: t, onTryAgain: n }) => {
|
|
111
|
+
let r = e();
|
|
112
|
+
return /* @__PURE__ */ d("div", {
|
|
113
|
+
className: "flex items-center justify-between gap-3 px-1 text-start",
|
|
114
|
+
"data-testid": "assistant-mic-blocked",
|
|
115
|
+
children: [/* @__PURE__ */ u("p", {
|
|
116
|
+
className: "text-status-warning-text",
|
|
117
|
+
children: t
|
|
118
|
+
}), /* @__PURE__ */ u("button", {
|
|
119
|
+
type: "button",
|
|
120
|
+
onClick: n,
|
|
121
|
+
className: "h-11 shrink-0 rounded-full border border-border-default px-3 text-sm font-medium sm:h-9 text-text-primary transition-colors hover:bg-bg-sunken focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]",
|
|
122
|
+
"data-testid": "assistant-mic-try-again",
|
|
123
|
+
children: r("dictation.tryAgain", "Try again")
|
|
124
|
+
})]
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
export { p as DictationControls, f as DictationLiveText, h as MicBlockedNotice };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The mic in the message box on a page, as one split control (BOFF-13461; the
|
|
4
|
+
* operator's design of 14 Nov, "Dictation states" 1): the microphone starts
|
|
5
|
+
* dictation, and the arrow beside it opens the microphone and language options.
|
|
6
|
+
* Both choices are remembered (the assistant store) and used by dictation AND the
|
|
7
|
+
* voice chat.
|
|
8
|
+
*
|
|
9
|
+
* - **Microphone**: the system default, then each microphone the browser lists. A
|
|
10
|
+
* desktop browser only: on a phone the recogniser picks the microphone itself,
|
|
11
|
+
* and a capture of ours would take it away (see `useVoiceInput`'s `deviceId`).
|
|
12
|
+
* - **Language**: the language the person speaks (the same setting as Settings ›
|
|
13
|
+
* Assistant): "Same as interface", then each language the assistant hears.
|
|
14
|
+
*/
|
|
15
|
+
/** "{microphone} · {language}": what dictation and voice chat use now. */
|
|
16
|
+
export declare function useMicSummary(): string;
|
|
17
|
+
export declare const AssistantMicMenu: FC<{
|
|
18
|
+
/** Start dictation. */
|
|
19
|
+
onDictate: () => void;
|
|
20
|
+
/** The microphone cannot be used (blocked, or none): the mic shows it. */
|
|
21
|
+
blocked: boolean;
|
|
22
|
+
disabled: boolean;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { EscapeLayer as e } from "../../../components/EscapeLayer.js";
|
|
2
|
+
import { useAssistantTr as t } from "../../i18n.js";
|
|
3
|
+
import { useAssistantStore as n } from "../../store.js";
|
|
4
|
+
import { ASSISTANT_LANGUAGES as r, findAssistantLanguage as i } from "../../voice/languages.js";
|
|
5
|
+
import { useDropdownEscape as a } from "../useDropdownEscape.js";
|
|
6
|
+
import { listMicrophones as o, microphoneChoiceOffered as s } from "./microphones.js";
|
|
7
|
+
import { useCallback as c, useEffect as l, useRef as u, useState as d } from "react";
|
|
8
|
+
import { Check as f, ChevronDown as p, Mic as m, MicOff as h } from "lucide-react";
|
|
9
|
+
import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
|
|
10
|
+
// src/shared/assistant/ui/composer/AssistantMicMenu.tsx
|
|
11
|
+
function y() {
|
|
12
|
+
let e = t(), r = n((e) => e.micDeviceId), a = n((e) => e.assistantLanguage), [s, c] = d(null);
|
|
13
|
+
l(() => {
|
|
14
|
+
if (!r) return;
|
|
15
|
+
let t = !0;
|
|
16
|
+
return o((t) => e("dictation.unnamedMicrophone", "Microphone {{n}}", { n: t })).then((e) => {
|
|
17
|
+
t && c(e.find((e) => e.deviceId === r)?.label ?? null);
|
|
18
|
+
}), () => {
|
|
19
|
+
t = !1;
|
|
20
|
+
};
|
|
21
|
+
}, [r, e]);
|
|
22
|
+
let u = r && s ? s : e("dictation.systemDefault", "System default"), f = i(a);
|
|
23
|
+
return `${u} · ${f ? f.label : e("voice.languageFollowApp", "Same as interface")}`;
|
|
24
|
+
}
|
|
25
|
+
var b = "flex min-h-11 w-full items-center justify-between gap-3 px-3 py-2 text-start text-sm sm:min-h-0 text-text-primary transition-colors hover:bg-bg-sunken focus:outline-none focus-visible:bg-bg-sunken", x = ({ checked: e, label: t, onChoose: n, testId: r, lang: i }) => /* @__PURE__ */ v("button", {
|
|
26
|
+
type: "button",
|
|
27
|
+
role: "menuitemradio",
|
|
28
|
+
"aria-checked": e,
|
|
29
|
+
lang: i,
|
|
30
|
+
onClick: n,
|
|
31
|
+
className: b,
|
|
32
|
+
"data-testid": r,
|
|
33
|
+
children: [/* @__PURE__ */ _("span", {
|
|
34
|
+
className: "truncate",
|
|
35
|
+
children: t
|
|
36
|
+
}), e ? /* @__PURE__ */ _(f, {
|
|
37
|
+
className: "size-4 shrink-0 text-status-warning-text",
|
|
38
|
+
"aria-hidden": "true"
|
|
39
|
+
}) : null]
|
|
40
|
+
}), S = ({ title: e, children: t }) => /* @__PURE__ */ v("div", {
|
|
41
|
+
role: "group",
|
|
42
|
+
"aria-label": e,
|
|
43
|
+
children: [/* @__PURE__ */ _("p", {
|
|
44
|
+
className: "px-3 pb-1 pt-2 text-xs font-medium text-text-secondary",
|
|
45
|
+
children: e
|
|
46
|
+
}), t]
|
|
47
|
+
});
|
|
48
|
+
function C(e, n) {
|
|
49
|
+
let r = t(), [i, a] = d([]);
|
|
50
|
+
return l(() => {
|
|
51
|
+
if (!e || !n) return;
|
|
52
|
+
let t = !0, i = () => void o((e) => r("dictation.unnamedMicrophone", "Microphone {{n}}", { n: e })).then((e) => {
|
|
53
|
+
t && a(e);
|
|
54
|
+
});
|
|
55
|
+
return i(), navigator.mediaDevices?.addEventListener?.("devicechange", i), () => {
|
|
56
|
+
t = !1, navigator.mediaDevices?.removeEventListener?.("devicechange", i);
|
|
57
|
+
};
|
|
58
|
+
}, [
|
|
59
|
+
e,
|
|
60
|
+
n,
|
|
61
|
+
r
|
|
62
|
+
]), i;
|
|
63
|
+
}
|
|
64
|
+
var w = ({ open: e, onChosen: i }) => {
|
|
65
|
+
let a = t(), o = n((e) => e.micDeviceId), c = n((e) => e.setMicDeviceId), l = n((e) => e.assistantLanguage), u = n((e) => e.setAssistantLanguage), d = s(), f = C(e, d), p = (e) => () => {
|
|
66
|
+
e(), i();
|
|
67
|
+
};
|
|
68
|
+
return /* @__PURE__ */ v(g, { children: [d ? /* @__PURE__ */ v(S, {
|
|
69
|
+
title: a("dictation.microphone", "Microphone"),
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ _(x, {
|
|
72
|
+
checked: o === null,
|
|
73
|
+
label: a("dictation.systemDefault", "System default"),
|
|
74
|
+
onChoose: p(() => c(null)),
|
|
75
|
+
testId: "assistant-mic-device-default"
|
|
76
|
+
}),
|
|
77
|
+
f.map((e) => /* @__PURE__ */ _(x, {
|
|
78
|
+
checked: o === e.deviceId,
|
|
79
|
+
label: e.label,
|
|
80
|
+
onChoose: p(() => c(e.deviceId)),
|
|
81
|
+
testId: "assistant-mic-device"
|
|
82
|
+
}, e.deviceId)),
|
|
83
|
+
/* @__PURE__ */ _("div", {
|
|
84
|
+
className: "my-1 h-px bg-border-subtle",
|
|
85
|
+
"aria-hidden": "true"
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
}) : null, /* @__PURE__ */ v(S, {
|
|
89
|
+
title: a("dictation.language", "Language"),
|
|
90
|
+
children: [/* @__PURE__ */ _(x, {
|
|
91
|
+
checked: l === null,
|
|
92
|
+
label: a("voice.languageFollowApp", "Same as interface"),
|
|
93
|
+
onChoose: p(() => u(null)),
|
|
94
|
+
testId: "assistant-mic-language-default"
|
|
95
|
+
}), r.map((e) => /* @__PURE__ */ _(x, {
|
|
96
|
+
checked: l === e.code,
|
|
97
|
+
label: e.label,
|
|
98
|
+
lang: e.code,
|
|
99
|
+
onChoose: p(() => u(e.code)),
|
|
100
|
+
testId: "assistant-mic-language"
|
|
101
|
+
}, e.code))]
|
|
102
|
+
})] });
|
|
103
|
+
}, T = ({ onDictate: e, blocked: n, disabled: r }) => {
|
|
104
|
+
let i = t(), a = n ? i("dictation.blockedButton", "Dictate, microphone blocked") : i("composer.voiceStart", "Dictate a message");
|
|
105
|
+
return /* @__PURE__ */ _("button", {
|
|
106
|
+
type: "button",
|
|
107
|
+
onClick: e,
|
|
108
|
+
disabled: r,
|
|
109
|
+
className: `flex size-11 items-center justify-center ${n ? "rounded-full" : "rounded-s-full"} transition-colors hover:bg-bg-sunken focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50 sm:size-10 ${n ? "text-status-warning-text" : "text-text-secondary hover:text-text-primary"}`,
|
|
110
|
+
"aria-label": a,
|
|
111
|
+
title: a,
|
|
112
|
+
"data-testid": "assistant-voice",
|
|
113
|
+
"data-state": n ? "blocked" : "idle",
|
|
114
|
+
children: _(n ? h : m, {
|
|
115
|
+
className: "size-5",
|
|
116
|
+
"aria-hidden": "true"
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}, E = ({ disabled: n }) => {
|
|
120
|
+
let r = t(), [i, o] = d(!1), s = u(null), f = u(null), m = c(() => o(!1), []), h = a(s, m), y = c(() => {
|
|
121
|
+
o(!1), s.current?.focus();
|
|
122
|
+
}, []);
|
|
123
|
+
l(() => {
|
|
124
|
+
if (!i) return;
|
|
125
|
+
let e = (e) => {
|
|
126
|
+
let t = e.target;
|
|
127
|
+
f.current?.contains(t) || s.current?.contains(t) || o(!1);
|
|
128
|
+
};
|
|
129
|
+
return window.addEventListener("mousedown", e), () => window.removeEventListener("mousedown", e);
|
|
130
|
+
}, [i]);
|
|
131
|
+
let b = r("dictation.options", "Microphone and language options");
|
|
132
|
+
return /* @__PURE__ */ v(g, { children: [
|
|
133
|
+
/* @__PURE__ */ _("span", {
|
|
134
|
+
"aria-hidden": "true",
|
|
135
|
+
className: "h-5 w-px bg-border-default"
|
|
136
|
+
}),
|
|
137
|
+
/* @__PURE__ */ _("button", {
|
|
138
|
+
ref: s,
|
|
139
|
+
type: "button",
|
|
140
|
+
onClick: () => o((e) => !e),
|
|
141
|
+
disabled: n,
|
|
142
|
+
className: "flex h-11 w-11 items-center justify-center rounded-e-full text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50 sm:h-10 sm:w-9",
|
|
143
|
+
"aria-label": b,
|
|
144
|
+
title: b,
|
|
145
|
+
"aria-haspopup": "menu",
|
|
146
|
+
"aria-expanded": i,
|
|
147
|
+
"data-testid": "assistant-mic-options",
|
|
148
|
+
children: /* @__PURE__ */ _(p, {
|
|
149
|
+
className: "size-4",
|
|
150
|
+
"aria-hidden": "true"
|
|
151
|
+
})
|
|
152
|
+
}),
|
|
153
|
+
i ? /* @__PURE__ */ _(e, {
|
|
154
|
+
...h,
|
|
155
|
+
children: /* @__PURE__ */ _("div", {
|
|
156
|
+
ref: f,
|
|
157
|
+
role: "menu",
|
|
158
|
+
"aria-label": b,
|
|
159
|
+
className: "absolute bottom-full end-0 z-30 mb-2 max-h-[min(24rem,60vh)] min-w-60 overflow-y-auto rounded-xl border border-border-default bg-bg-elevated py-1 shadow-lg",
|
|
160
|
+
"data-testid": "assistant-mic-menu",
|
|
161
|
+
children: /* @__PURE__ */ _(w, {
|
|
162
|
+
open: i,
|
|
163
|
+
onChosen: y
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
}) : null
|
|
167
|
+
] });
|
|
168
|
+
}, D = ({ onDictate: e, blocked: t, disabled: n }) => /* @__PURE__ */ v("div", {
|
|
169
|
+
className: "relative flex shrink-0 items-center rounded-full border border-border-default",
|
|
170
|
+
children: [/* @__PURE__ */ _(T, {
|
|
171
|
+
onDictate: e,
|
|
172
|
+
blocked: t,
|
|
173
|
+
disabled: n
|
|
174
|
+
}), t ? null : /* @__PURE__ */ _(E, { disabled: n })]
|
|
175
|
+
});
|
|
176
|
+
export { D as AssistantMicMenu, y as useMicSummary };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The microphones the message box's options offer (BOFF-13461; see
|
|
3
|
+
* `AssistantMicMenu`). A desktop browser only: on a phone the recogniser picks
|
|
4
|
+
* the microphone itself, and a capture of ours would take it away.
|
|
5
|
+
*/
|
|
6
|
+
export interface MicChoice {
|
|
7
|
+
deviceId: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
/** The microphones the browser lists; unnamed ones (no permission yet) are numbered. */
|
|
11
|
+
export declare function listMicrophones(unnamed: (index: number) => string): Promise<MicChoice[]>;
|
|
12
|
+
/** May a microphone be chosen here at all (a desktop browser that can capture)? */
|
|
13
|
+
export declare const microphoneChoiceOffered: () => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { micLevelAllowed as e } from "../../voice/liveLevel.js";
|
|
2
|
+
// src/shared/assistant/ui/composer/microphones.ts
|
|
3
|
+
async function t(e) {
|
|
4
|
+
if (typeof navigator > "u" || !navigator.mediaDevices?.enumerateDevices) return [];
|
|
5
|
+
try {
|
|
6
|
+
return (await navigator.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" && e.deviceId !== "default").filter((e) => e.deviceId !== "" && e.deviceId !== "communications").map((t, n) => ({
|
|
7
|
+
deviceId: t.deviceId,
|
|
8
|
+
label: t.label || e(n + 1)
|
|
9
|
+
}));
|
|
10
|
+
} catch {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
var n = () => e(typeof navigator > "u" ? void 0 : navigator, !0);
|
|
15
|
+
export { t as listMicrophones, n as microphoneChoiceOffered };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Dispatch, RefObject, SetStateAction } from 'react';
|
|
2
|
+
import { LiveLevelSource } from '../../voice/liveLevel';
|
|
3
|
+
import { UseVoiceInputResult } from '../../voice/useVoiceInput';
|
|
4
|
+
/**
|
|
5
|
+
* Dictation in the compact message box (BOFF-13461; the operator's design of 14 Nov,
|
|
6
|
+
* "Voice input: dictation and voice assistant", Dictation states and rules).
|
|
7
|
+
*
|
|
8
|
+
* The mic TYPES for the person; nothing is ever sent by it.
|
|
9
|
+
* - **Listening**: what is heard is kept apart from the draft (`take`), shown in
|
|
10
|
+
* the box where the cursor was, and the draft cannot be edited meanwhile.
|
|
11
|
+
* - **Finish** (✓): the recogniser's last words are waited for (`finish()`), the
|
|
12
|
+
* box shows "Turning speech into text", and the take lands AT THE CURSOR as
|
|
13
|
+
* ordinary, editable text. An existing draft is never replaced. Nothing heard:
|
|
14
|
+
* "Nothing was heard…".
|
|
15
|
+
* - **Cancel** (✕, or Esc): the take is thrown away; the draft is untouched.
|
|
16
|
+
* - About 8 s without a new word finishes the take on its own, and so does the
|
|
17
|
+
* tab going to the background.
|
|
18
|
+
* - **The recogniser ends on its own** (the end of a phrase on a phone, an
|
|
19
|
+
* error): what was heard lands at the cursor as Finish would; no word is lost.
|
|
20
|
+
*/
|
|
21
|
+
/** Seconds of silence after which the take finishes on its own. */
|
|
22
|
+
export declare const DICTATION_SILENCE_MS = 8000;
|
|
23
|
+
export type CompactDictationPhase = 'idle' | 'starting' | 'listening' | 'transcribing';
|
|
24
|
+
export interface CompactDictation {
|
|
25
|
+
phase: CompactDictationPhase;
|
|
26
|
+
/** The draft before and after where the take goes. */
|
|
27
|
+
before: string;
|
|
28
|
+
after: string;
|
|
29
|
+
/** Finished phrases of this take. */
|
|
30
|
+
take: string;
|
|
31
|
+
/** Words still being recognised. */
|
|
32
|
+
interim: string;
|
|
33
|
+
/** Seconds since the microphone opened. */
|
|
34
|
+
seconds: number;
|
|
35
|
+
level: LiveLevelSource;
|
|
36
|
+
/** Shown after a take with nothing in it, until the next take or the draft changes. */
|
|
37
|
+
nothingHeard: boolean;
|
|
38
|
+
clearNothingHeard: () => void;
|
|
39
|
+
start: () => void;
|
|
40
|
+
finish: () => void;
|
|
41
|
+
cancel: () => void;
|
|
42
|
+
/** Keep what was heard (the unfinished words too) and stop at once: the box is being covered. */
|
|
43
|
+
keepAndStop: () => void;
|
|
44
|
+
/** A finished phrase from the recogniser. */
|
|
45
|
+
addFinal: (phrase: string) => void;
|
|
46
|
+
/**
|
|
47
|
+
* The recogniser went away on its own (`useVoiceInput`'s `onEnded`): what was
|
|
48
|
+
* heard lands at the cursor as Finish would, so no word is lost.
|
|
49
|
+
*/
|
|
50
|
+
recogniserEnded: () => void;
|
|
51
|
+
}
|
|
52
|
+
interface Options {
|
|
53
|
+
/** The compact presentation; everything here is idle without it. */
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
voice: UseVoiceInputResult;
|
|
56
|
+
text: string;
|
|
57
|
+
setText: Dispatch<SetStateAction<string>>;
|
|
58
|
+
textareaRef: RefObject<HTMLTextAreaElement | null>;
|
|
59
|
+
/** The draft now holds dictated words (the composer's `dictated` flag). */
|
|
60
|
+
markDictated: () => void;
|
|
61
|
+
/** The microphone chosen in the options (null: the system default), for the level bars. */
|
|
62
|
+
deviceId?: string | null;
|
|
63
|
+
}
|
|
64
|
+
/** `words` inserted into `text` at [start, end), with a space either side where needed. */
|
|
65
|
+
export declare function insertAtCursor(text: string, words: string, start: number, end: number): {
|
|
66
|
+
text: string;
|
|
67
|
+
caret: number;
|
|
68
|
+
};
|
|
69
|
+
export declare function useCompactDictation({ enabled, voice, text, setText, textareaRef, markDictated, deviceId, }: Options): CompactDictation;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useLiveLevel as e } from "../voice/useLiveLevel.js";
|
|
2
|
+
import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
|
|
3
|
+
// src/shared/assistant/ui/composer/useCompactDictation.ts
|
|
4
|
+
var a = 8e3, o = (e, t) => {
|
|
5
|
+
let n = e.trim(), r = t.trim();
|
|
6
|
+
return n ? r ? `${n} ${r}` : n : r;
|
|
7
|
+
};
|
|
8
|
+
function s(e, t, n, r) {
|
|
9
|
+
let i = Math.max(0, Math.min(n, e.length)), a = Math.max(i, Math.min(r, e.length)), o = e.slice(0, i), s = e.slice(a), c = o && !/\s$/.test(o) ? " " : "";
|
|
10
|
+
return {
|
|
11
|
+
text: `${o}${c}${t}${s && !/^\s/.test(s) ? " " : ""}${s}`,
|
|
12
|
+
caret: (o + c + t).length
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function c({ enabled: c, voice: u, text: d, setText: f, textareaRef: p, markDictated: m, deviceId: h = null }) {
|
|
16
|
+
let [g, _] = i(""), v = r(""), [y, b] = i(!1), [x, S] = i(null), C = r(""), [w, T] = i(null), E = r(null), [D, O] = i(0), k = r(!1), A = r(!1), j = t((e) => {
|
|
17
|
+
v.current = e, _(e);
|
|
18
|
+
}, []), M = t((e) => {
|
|
19
|
+
C.current = "", j(o(v.current, e));
|
|
20
|
+
}, [j]);
|
|
21
|
+
n(() => {
|
|
22
|
+
u.interim && (C.current = u.interim);
|
|
23
|
+
}, [u.interim]);
|
|
24
|
+
let N = t((e) => {
|
|
25
|
+
let t = w;
|
|
26
|
+
f((n) => {
|
|
27
|
+
let r = s(n, e, t?.start ?? n.length, t?.end ?? n.length);
|
|
28
|
+
return E.current = r.caret, r.text;
|
|
29
|
+
}), O((e) => e + 1), m();
|
|
30
|
+
}, [
|
|
31
|
+
w,
|
|
32
|
+
f,
|
|
33
|
+
m
|
|
34
|
+
]), P = t(() => {
|
|
35
|
+
A.current = !1, j(""), C.current = "", T(null), k.current = !1, b(!1);
|
|
36
|
+
}, [j]), F = t(() => {
|
|
37
|
+
let e = p.current, t = d.length, n = e ? Math.min(e.selectionEnd ?? t, t) : t;
|
|
38
|
+
T({
|
|
39
|
+
start: n,
|
|
40
|
+
end: n
|
|
41
|
+
}), A.current = !0, j(""), C.current = "", S(null), u.clearError(), u.start();
|
|
42
|
+
}, [
|
|
43
|
+
p,
|
|
44
|
+
d.length,
|
|
45
|
+
j,
|
|
46
|
+
u
|
|
47
|
+
]), I = t(() => {
|
|
48
|
+
if (k.current) return;
|
|
49
|
+
k.current = !0, b(!0);
|
|
50
|
+
let e = u.interim, t = v.current;
|
|
51
|
+
u.finish().then(() => {
|
|
52
|
+
let n = v.current === t ? o(v.current, e) : v.current;
|
|
53
|
+
n ? N(n) : (S(d), O((e) => e + 1)), P();
|
|
54
|
+
});
|
|
55
|
+
}, [
|
|
56
|
+
u,
|
|
57
|
+
N,
|
|
58
|
+
P,
|
|
59
|
+
d
|
|
60
|
+
]), L = t(() => {
|
|
61
|
+
u.stop(), P(), E.current = null, O((e) => e + 1);
|
|
62
|
+
}, [u, P]), R = t(() => {
|
|
63
|
+
if (k.current) {
|
|
64
|
+
u.stop();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let e = o(v.current, u.interim);
|
|
68
|
+
u.stop(), e && N(e), P();
|
|
69
|
+
}, [
|
|
70
|
+
u,
|
|
71
|
+
N,
|
|
72
|
+
P
|
|
73
|
+
]);
|
|
74
|
+
n(() => {
|
|
75
|
+
if (D === 0) return;
|
|
76
|
+
let e = E.current;
|
|
77
|
+
E.current = null, l(p, e);
|
|
78
|
+
}, [D, p]);
|
|
79
|
+
let z = t(() => {
|
|
80
|
+
if (!A.current || k.current) return;
|
|
81
|
+
let e = o(v.current, C.current);
|
|
82
|
+
e && N(e), P();
|
|
83
|
+
}, [N, P]), B = c && u.isListening && !y, V = r(I);
|
|
84
|
+
n(() => {
|
|
85
|
+
V.current = I;
|
|
86
|
+
}, [I]);
|
|
87
|
+
let H = `${g}|${u.interim}`;
|
|
88
|
+
n(() => {
|
|
89
|
+
if (!B) return;
|
|
90
|
+
let e = setTimeout(() => V.current(), a);
|
|
91
|
+
return () => clearTimeout(e);
|
|
92
|
+
}, [B, H]), n(() => {
|
|
93
|
+
if (!B || typeof document > "u") return;
|
|
94
|
+
let e = () => {
|
|
95
|
+
document.visibilityState === "hidden" && V.current();
|
|
96
|
+
};
|
|
97
|
+
return document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e);
|
|
98
|
+
}, [B]);
|
|
99
|
+
let [U, W] = i(0), [G, K] = i(B);
|
|
100
|
+
G !== B && (K(B), W(0)), n(() => {
|
|
101
|
+
if (!B) return;
|
|
102
|
+
let e = Date.now(), t = setInterval(() => W(Math.floor((Date.now() - e) / 1e3)), 1e3);
|
|
103
|
+
return () => clearInterval(t);
|
|
104
|
+
}, [B]);
|
|
105
|
+
let q = e({
|
|
106
|
+
active: B,
|
|
107
|
+
mic: !0,
|
|
108
|
+
pulseKey: u.interim,
|
|
109
|
+
deviceId: h
|
|
110
|
+
}), J = t(() => S(null), []), Y = c ? y ? "transcribing" : u.isListening ? "listening" : u.isStarting ? "starting" : "idle" : "idle", X = w ?? {
|
|
111
|
+
start: d.length,
|
|
112
|
+
end: d.length
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
phase: Y,
|
|
116
|
+
before: d.slice(0, X.start),
|
|
117
|
+
after: d.slice(X.end),
|
|
118
|
+
take: g,
|
|
119
|
+
interim: u.interim,
|
|
120
|
+
seconds: U,
|
|
121
|
+
level: q,
|
|
122
|
+
nothingHeard: x !== null && x === d,
|
|
123
|
+
clearNothingHeard: J,
|
|
124
|
+
start: F,
|
|
125
|
+
finish: I,
|
|
126
|
+
cancel: L,
|
|
127
|
+
keepAndStop: R,
|
|
128
|
+
addFinal: M,
|
|
129
|
+
recogniserEnded: z
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function l(e, t) {
|
|
133
|
+
let n = e.current;
|
|
134
|
+
n && (n.focus(), t !== null && typeof n.setSelectionRange == "function" && n.setSelectionRange(t, t));
|
|
135
|
+
}
|
|
136
|
+
export { a as DICTATION_SILENCE_MS, s as insertAtCursor, c as useCompactDictation };
|