@burdenoff/microfe-healthybowl 2026.904.2 → 2026.904.4
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,76 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
en: {
|
|
4
|
-
codeBlock: "Code block",
|
|
5
|
-
image: "image",
|
|
6
|
-
link: "link",
|
|
7
|
-
largeTable: "Table with {{rows}} rows and {{columns}} columns",
|
|
8
|
-
truncated: "The rest of this message is not read aloud",
|
|
9
|
-
nestedItem: "Sub-item {{ordinal}}",
|
|
10
|
-
emailAt: "at",
|
|
11
|
-
emailDot: "dot"
|
|
12
|
-
},
|
|
13
|
-
ta: {
|
|
14
|
-
codeBlock: "நிரல் தொகுதி",
|
|
15
|
-
image: "படம்",
|
|
16
|
-
link: "இணைப்பு",
|
|
17
|
-
largeTable: "{{rows}} வரிசைகள் மற்றும் {{columns}} நெடுவரிசைகள் கொண்ட அட்டவணை",
|
|
18
|
-
truncated: "இந்தச் செய்தியின் மீதமுள்ள பகுதி வாசிக்கப்படவில்லை",
|
|
19
|
-
nestedItem: "துணை உருப்படி {{ordinal}}",
|
|
20
|
-
emailAt: "அட்",
|
|
21
|
-
emailDot: "புள்ளி"
|
|
22
|
-
},
|
|
23
|
-
hi: {
|
|
24
|
-
codeBlock: "कोड ब्लॉक",
|
|
25
|
-
image: "छवि",
|
|
26
|
-
link: "लिंक",
|
|
27
|
-
largeTable: "{{rows}} पंक्तियों और {{columns}} स्तंभों वाली तालिका",
|
|
28
|
-
truncated: "इस संदेश का शेष भाग नहीं पढ़ा जाता",
|
|
29
|
-
nestedItem: "उप-आइटम {{ordinal}}",
|
|
30
|
-
emailAt: "ऐट",
|
|
31
|
-
emailDot: "डॉट"
|
|
32
|
-
},
|
|
33
|
-
ar: {
|
|
34
|
-
codeBlock: "كتلة برمجية",
|
|
35
|
-
image: "صورة",
|
|
36
|
-
link: "رابط",
|
|
37
|
-
largeTable: "جدول من {{rows}} صفوف و {{columns}} أعمدة",
|
|
38
|
-
truncated: "لا تتم قراءة بقية هذه الرسالة بصوت عالٍ",
|
|
39
|
-
nestedItem: "عنصر فرعي {{ordinal}}",
|
|
40
|
-
emailAt: "أت",
|
|
41
|
-
emailDot: "نقطة"
|
|
42
|
-
},
|
|
43
|
-
es: {
|
|
44
|
-
codeBlock: "Bloque de código",
|
|
45
|
-
image: "imagen",
|
|
46
|
-
link: "enlace",
|
|
47
|
-
largeTable: "Tabla con {{rows}} filas y {{columns}} columnas",
|
|
48
|
-
truncated: "El resto de este mensaje no se lee en voz alta",
|
|
49
|
-
nestedItem: "Subelemento {{ordinal}}",
|
|
50
|
-
emailAt: "arroba",
|
|
51
|
-
emailDot: "punto"
|
|
52
|
-
},
|
|
53
|
-
zh: {
|
|
54
|
-
codeBlock: "代码块",
|
|
55
|
-
image: "图片",
|
|
56
|
-
link: "链接",
|
|
57
|
-
largeTable: "包含 {{rows}} 行 {{columns}} 列的表格",
|
|
58
|
-
truncated: "此消息的其余部分不会朗读",
|
|
59
|
-
nestedItem: "子项 {{ordinal}}",
|
|
60
|
-
emailAt: "at",
|
|
61
|
-
emailDot: "点"
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
function t(t, n) {
|
|
65
|
-
let r = t.trim().toLowerCase().split(/[-_]/)[0];
|
|
66
|
-
if (!r) return n;
|
|
67
|
-
let i = e[r];
|
|
68
|
-
return i ? {
|
|
69
|
-
...n,
|
|
70
|
-
...i
|
|
71
|
-
} : n;
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
export { t as speechLabelsFor };
|
|
75
|
-
|
|
76
|
-
//# sourceMappingURL=speechLabels.js.map
|
|
1
|
+
import { speechLabelsFor as e } from "@burdenoff/fe-libs/shared/assistant";
|
|
2
|
+
export { e as speechLabelsFor };
|
|
@@ -1,114 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
{
|
|
4
|
-
locale: "ja",
|
|
5
|
-
pattern: /[\p{Script=Hiragana}\p{Script=Katakana}]/u
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
locale: "ko",
|
|
9
|
-
pattern: /\p{Script=Hangul}/u
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
locale: "zh",
|
|
13
|
-
pattern: /\p{Script=Han}/u
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
locale: "ta",
|
|
17
|
-
pattern: /\p{Script=Tamil}/u
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
locale: "hi",
|
|
21
|
-
pattern: /\p{Script=Devanagari}/u
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
locale: "bn",
|
|
25
|
-
pattern: /\p{Script=Bengali}/u
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
locale: "te",
|
|
29
|
-
pattern: /\p{Script=Telugu}/u
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
locale: "kn",
|
|
33
|
-
pattern: /\p{Script=Kannada}/u
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
locale: "ml",
|
|
37
|
-
pattern: /\p{Script=Malayalam}/u
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
locale: "gu",
|
|
41
|
-
pattern: /\p{Script=Gujarati}/u
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
locale: "pa",
|
|
45
|
-
pattern: /\p{Script=Gurmukhi}/u
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
locale: "ar",
|
|
49
|
-
pattern: /\p{Script=Arabic}/u
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
locale: "he",
|
|
53
|
-
pattern: /\p{Script=Hebrew}/u
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
locale: "ru",
|
|
57
|
-
pattern: /\p{Script=Cyrillic}/u
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
locale: "el",
|
|
61
|
-
pattern: /\p{Script=Greek}/u
|
|
62
|
-
}
|
|
63
|
-
], t = {
|
|
64
|
-
zh: ["zh", "ja"],
|
|
65
|
-
ar: [
|
|
66
|
-
"ar",
|
|
67
|
-
"ur",
|
|
68
|
-
"fa",
|
|
69
|
-
"ps",
|
|
70
|
-
"sd"
|
|
71
|
-
],
|
|
72
|
-
hi: [
|
|
73
|
-
"hi",
|
|
74
|
-
"mr",
|
|
75
|
-
"ne",
|
|
76
|
-
"sa",
|
|
77
|
-
"kok"
|
|
78
|
-
],
|
|
79
|
-
ru: [
|
|
80
|
-
"ru",
|
|
81
|
-
"uk",
|
|
82
|
-
"bg",
|
|
83
|
-
"sr",
|
|
84
|
-
"mk",
|
|
85
|
-
"be"
|
|
86
|
-
]
|
|
87
|
-
}, n = .3, r = .2, i = /\p{L}/u;
|
|
88
|
-
function a(t) {
|
|
89
|
-
if (!t) return null;
|
|
90
|
-
let a = 0, o = /* @__PURE__ */ new Map();
|
|
91
|
-
for (let n of t) if (i.test(n)) {
|
|
92
|
-
a += 1;
|
|
93
|
-
for (let { locale: t, pattern: r } of e) if (r.test(n)) {
|
|
94
|
-
o.set(t, (o.get(t) ?? 0) + 1);
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (a === 0) return null;
|
|
99
|
-
let s = o.get("ja") ?? 0, c = o.get("zh") ?? 0;
|
|
100
|
-
s > 0 && s >= (s + c) * r && (o.set("ja", s + c), o.delete("zh"));
|
|
101
|
-
let l = null, u = 0;
|
|
102
|
-
for (let [e, t] of o) t > u && (l = e, u = t);
|
|
103
|
-
return l !== null && u / a >= n ? l : null;
|
|
104
|
-
}
|
|
105
|
-
function o(e, n) {
|
|
106
|
-
let r = a(e);
|
|
107
|
-
if (r === null) return n;
|
|
108
|
-
let i = t[r];
|
|
109
|
-
return i && i.includes(n) ? n : r;
|
|
110
|
-
}
|
|
111
|
-
//#endregion
|
|
112
|
-
export { o as resolveSpeechLocale };
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=replyLanguage.js.map
|
|
1
|
+
import { resolveSpeechLocale as e } from "@burdenoff/fe-libs/shared/assistant";
|
|
2
|
+
export { e as resolveSpeechLocale };
|
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function t(t, n) {
|
|
4
|
-
switch (n.type) {
|
|
5
|
-
case "start": return {
|
|
6
|
-
status: "speaking",
|
|
7
|
-
messageId: n.messageId,
|
|
8
|
-
requestId: n.requestId
|
|
9
|
-
};
|
|
10
|
-
case "toggle": return t.status === "speaking" && t.messageId === n.messageId ? e : {
|
|
11
|
-
status: "speaking",
|
|
12
|
-
messageId: n.messageId,
|
|
13
|
-
requestId: n.requestId
|
|
14
|
-
};
|
|
15
|
-
case "stop": return t.status === "idle" ? t : e;
|
|
16
|
-
case "finished":
|
|
17
|
-
case "failed": return t.status !== "speaking" || t.requestId !== n.requestId ? t : e;
|
|
18
|
-
default: return t;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function n(e, t) {
|
|
22
|
-
return e.status === "speaking" && e.messageId === t;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { e as IDLE_PLAYBACK, n as isSpeakingMessage, t as speechPlaybackReducer };
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=speechPlayback.js.map
|
|
1
|
+
import { IDLE_PLAYBACK as e, isSpeakingMessage as t, speechPlaybackReducer as n } from "@burdenoff/fe-libs/shared/assistant";
|
|
2
|
+
export { e as IDLE_PLAYBACK, t as isSpeakingMessage, n as speechPlaybackReducer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@burdenoff/microfe-healthybowl",
|
|
3
|
-
"version": "2026.904.
|
|
3
|
+
"version": "2026.904.4",
|
|
4
4
|
"description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apollo/client": "^4.0.11",
|
|
51
|
-
"@burdenoff/fe-libs": "2026.904.
|
|
51
|
+
"@burdenoff/fe-libs": "2026.904.2",
|
|
52
52
|
"@burdenoff/planmagnet-fe-sdk": "2026.831.1",
|
|
53
53
|
"@tanstack/react-query": "^5.90.16",
|
|
54
54
|
"clsx": "^2.1.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"speechLabels.js","names":[],"sources":["../../src/config/speechLabels.ts"],"sourcesContent":["import type { SpeakableLabels } from '../utils/speakableText';\n\n/**\n * The spoken stand-ins, in the language of the REPLY (BOFF-7120).\n *\n * When a reply contains something that cannot be read aloud — an image, a link,\n * a fenced code block, a wide table — the reader substitutes a word. Those words\n * used to come from `tr()`, which resolves against the INTERFACE language. So an\n * English interface reading a Tamil answer said \"Code block\" and \"image\" in\n * English, dropped into the middle of a Tamil sentence. Exactly the complaint\n * that produced the translatable `at`/`dot` for email addresses; that fix was\n * applied there and nowhere else.\n *\n * ★ Why a static table rather than `tr()` with a locale argument: the i18n\n * provider only ever FETCHES the active locale. `I18nContextValue.translations`\n * holds that one dictionary, so there is nothing to ask for Tamil while the\n * interface is English — the strings simply are not in the client. These eight\n * are short, stable, and needed synchronously mid-utterance, so they are carried\n * here instead.\n *\n * Anything not listed falls back to the interface-language label, which is what\n * happens today — so this can only improve on the current behaviour, never\n * regress it.\n */\ntype PartialLabels = Partial<SpeakableLabels>;\n\n/** Keyed by primary language subtag, since the reply locale may carry a region. */\nconst LABELS_BY_LANGUAGE: Record<string, PartialLabels> = {\n /**\n * ★ English is carried explicitly, and it is not redundant.\n *\n * The fallback below is the INTERFACE language, so a language with no table of\n * its own inherits whatever the menu is set to. That is right for an unlisted\n * language, and exactly wrong for English: with a Tamil interface and an\n * English reply, `tr()` returned the Tamil words and spliced \"நிரல் தொகுதி\"\n * into an English sentence — the very defect this table exists to prevent,\n * running the other way. Naming English pins it regardless of the menu.\n *\n * These are the same strings as the English defaults in `speakableText.ts`;\n * unlike the others they need no translator, which is why this one entry is\n * here while the remaining locales are not.\n */\n en: {\n codeBlock: 'Code block',\n image: 'image',\n link: 'link',\n largeTable: 'Table with {{rows}} rows and {{columns}} columns',\n truncated: 'The rest of this message is not read aloud',\n nestedItem: 'Sub-item {{ordinal}}',\n emailAt: 'at',\n emailDot: 'dot',\n },\n ta: {\n codeBlock: 'நிரல் தொகுதி',\n image: 'படம்',\n link: 'இணைப்பு',\n largeTable: '{{rows}} வரிசைகள் மற்றும் {{columns}} நெடுவரிசைகள் கொண்ட அட்டவணை',\n truncated: 'இந்தச் செய்தியின் மீதமுள்ள பகுதி வாசிக்கப்படவில்லை',\n nestedItem: 'துணை உருப்படி {{ordinal}}',\n emailAt: 'அட்',\n emailDot: 'புள்ளி',\n },\n hi: {\n codeBlock: 'कोड ब्लॉक',\n image: 'छवि',\n link: 'लिंक',\n largeTable: '{{rows}} पंक्तियों और {{columns}} स्तंभों वाली तालिका',\n truncated: 'इस संदेश का शेष भाग नहीं पढ़ा जाता',\n nestedItem: 'उप-आइटम {{ordinal}}',\n emailAt: 'ऐट',\n emailDot: 'डॉट',\n },\n ar: {\n codeBlock: 'كتلة برمجية',\n image: 'صورة',\n link: 'رابط',\n largeTable: 'جدول من {{rows}} صفوف و {{columns}} أعمدة',\n truncated: 'لا تتم قراءة بقية هذه الرسالة بصوت عالٍ',\n nestedItem: 'عنصر فرعي {{ordinal}}',\n emailAt: 'أت',\n emailDot: 'نقطة',\n },\n es: {\n codeBlock: 'Bloque de código',\n image: 'imagen',\n link: 'enlace',\n largeTable: 'Tabla con {{rows}} filas y {{columns}} columnas',\n truncated: 'El resto de este mensaje no se lee en voz alta',\n nestedItem: 'Subelemento {{ordinal}}',\n emailAt: 'arroba',\n emailDot: 'punto',\n },\n zh: {\n codeBlock: '代码块',\n image: '图片',\n link: '链接',\n largeTable: '包含 {{rows}} 行 {{columns}} 列的表格',\n truncated: '此消息的其余部分不会朗读',\n nestedItem: '子项 {{ordinal}}',\n emailAt: 'at',\n emailDot: '点',\n },\n};\n\n/**\n * Labels to read a reply in `locale` with.\n *\n * `uiLabels` is the interface-language set, used both as the base and as the\n * fallback for any language not carried here — so English replies, and any\n * language we have no table for, behave exactly as before.\n */\nexport function speechLabelsFor(locale: string, uiLabels: SpeakableLabels): SpeakableLabels {\n const primary = locale.trim().toLowerCase().split(/[-_]/)[0];\n if (!primary) return uiLabels;\n const overrides = LABELS_BY_LANGUAGE[primary];\n return overrides ? { ...uiLabels, ...overrides } : uiLabels;\n}\n\n/** Exposed for tests: which languages have their own spoken labels. */\nexport const SPOKEN_LABEL_LANGUAGES = Object.keys(LABELS_BY_LANGUAGE);\n"],"mappings":";AA2BA,IAAM,IAAoD;CAexD,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;AACF;AASA,SAAgB,EAAgB,GAAgB,GAA4C;CAC1F,IAAM,IAAU,EAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,EAAE;CAC1D,IAAI,CAAC,GAAS,OAAO;CACrB,IAAM,IAAY,EAAmB;CACrC,OAAO,IAAY;EAAE,GAAG;EAAU,GAAG;CAAU,IAAI;AACrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replyLanguage.js","names":[],"sources":["../../src/utils/replyLanguage.ts"],"sourcesContent":["/**\n * Which language is this reply actually in? (BOFF-7107)\n *\n * The assistant reads replies aloud by choosing a voice for `useI18n().locale` —\n * the UI language. That is the wrong signal the moment the model answers in the\n * language the USER wrote in rather than the one the chrome is set to, which is\n * exactly what the language directive in `assistantPrompt` now asks it to do.\n * A Tamil reply read by an English voice is confident nonsense, and it is the\n * one failure the speech module is built to make impossible.\n *\n * So playback keys on the reply text instead. Deliberately by SCRIPT, not by a\n * statistical language detector:\n *\n * - it is deterministic, dependency-free and costs no bundle;\n * - for the languages HealthyBowl actually serves beyond English — Tamil,\n * Hindi, Arabic, Chinese — the script IS the language, unambiguously;\n * - a detector that can separate en/es/fr/de (`franc` and friends) is ~40KB and\n * still guesses on short strings.\n *\n * The honest limitation: **Latin-script languages cannot be told apart this\n * way.** A Spanish reply in an English UI still gets an English voice. That is a\n * far smaller failure than the cross-script one (an English voice reading\n * Spanish is accented but intelligible; an English voice reading Tamil is\n * noise), and closing it needs a real detector — a deliberate later choice, not\n * an oversight.\n */\n\n/**\n * Script → the app locale whose voice should read it.\n *\n * Ordered most-specific-first: Japanese text mixes Han with Kana, so Kana must\n * be tested before Han or every Japanese reply reads as Chinese.\n */\nconst SCRIPT_LOCALES: ReadonlyArray<{ locale: string; pattern: RegExp }> = [\n // Kana before Han — Japanese prose contains both.\n { locale: 'ja', pattern: /[\\p{Script=Hiragana}\\p{Script=Katakana}]/u },\n { locale: 'ko', pattern: /\\p{Script=Hangul}/u },\n { locale: 'zh', pattern: /\\p{Script=Han}/u },\n { locale: 'ta', pattern: /\\p{Script=Tamil}/u },\n { locale: 'hi', pattern: /\\p{Script=Devanagari}/u },\n { locale: 'bn', pattern: /\\p{Script=Bengali}/u },\n { locale: 'te', pattern: /\\p{Script=Telugu}/u },\n { locale: 'kn', pattern: /\\p{Script=Kannada}/u },\n { locale: 'ml', pattern: /\\p{Script=Malayalam}/u },\n { locale: 'gu', pattern: /\\p{Script=Gujarati}/u },\n { locale: 'pa', pattern: /\\p{Script=Gurmukhi}/u },\n { locale: 'ar', pattern: /\\p{Script=Arabic}/u },\n { locale: 'he', pattern: /\\p{Script=Hebrew}/u },\n { locale: 'ru', pattern: /\\p{Script=Cyrillic}/u },\n { locale: 'el', pattern: /\\p{Script=Greek}/u },\n];\n\n/**\n * Scripts written by MORE THAN ONE of the languages we offer.\n *\n * A script identifies a language only when it is used by one. Arabic script is\n * also Urdu and Persian; Devanagari is also Marathi; Cyrillic is many languages.\n * Mapping those to a single locale would pick an Arabic voice for Urdu text — or\n * announce that an Arabic voice is missing while the user's Urdu voice sits\n * installed and unused.\n *\n * So for these, the language the user ASKED for wins whenever it is written in\n * the detected script. The script still tells us the reply is not English; the\n * request tells us which of that script's languages it is.\n */\nconst SHARED_SCRIPTS: Readonly<Record<string, readonly string[]>> = {\n // Han is shared too: Japanese kanji is Han. A kana-free Japanese reply — a\n // short heading like `小麦収穫量` — has no kana evidence to trigger the\n // Japanese branch, so it lands here as `zh` and needs the request to correct it.\n zh: ['zh', 'ja'],\n ar: ['ar', 'ur', 'fa', 'ps', 'sd'],\n hi: ['hi', 'mr', 'ne', 'sa', 'kok'],\n ru: ['ru', 'uk', 'bg', 'sr', 'mk', 'be'],\n};\n\n/**\n * Share of letters that must belong to one non-Latin script before we treat the\n * whole reply as that language.\n *\n * Not 1 character: an otherwise English answer that quotes a crop name in Tamil\n * must not flip the whole reply to a Tamil voice. Not a majority either: replies\n * in Indic languages routinely carry English technical terms, units and product\n * names, and those legitimately sit well below half. Measured against real\n * shapes, a genuine Tamil answer lands far above this line and an English answer\n * quoting Tamil lands far below it.\n */\nconst DOMINANT_SCRIPT_RATIO = 0.3;\n\n/**\n * How much of the CJK text must be kana before Han is read as Japanese.\n *\n * Japanese prose runs roughly 40-70% kana; a Chinese sentence quoting one\n * Japanese word is far below this. Set low enough to catch Han-heavy Japanese\n * (`小麦の作物は元気です` is 40%) and high enough to reject an incidental quote.\n */\nconst KANA_EVIDENCE_RATIO = 0.2;\n\n/** Letters only — digits, punctuation, whitespace and emoji say nothing about language. */\nconst LETTER = /\\p{L}/u;\n\n/**\n * The locale whose voice should read `text`, or `null` when the script does not\n * decide it (empty, no letters, or Latin — see the module note).\n */\nexport function detectScriptLocale(text: string): string | null {\n if (!text) return null;\n\n let letters = 0;\n const counts = new Map<string, number>();\n\n for (const char of text) {\n if (!LETTER.test(char)) continue;\n letters += 1;\n for (const { locale, pattern } of SCRIPT_LOCALES) {\n if (pattern.test(char)) {\n counts.set(locale, (counts.get(locale) ?? 0) + 1);\n break;\n }\n }\n }\n\n if (letters === 0) return null;\n\n // Japanese prose is mostly Han by character count — `小麦の作物は元気です` is\n // 6 Han to 4 kana — so a raw count hands every Japanese reply to a Chinese\n // voice. Testing kana FIRST per character is not enough; the tie has to be\n // broken here.\n //\n // But kana PRESENCE is too weak a signal on its own: a Chinese reply that\n // quotes the Japanese particle `の` would have every one of its Han characters\n // reassigned to Japanese and be read by a Japanese voice. Require the kana to\n // be a real share of the CJK text before folding Han in — genuine Japanese\n // prose is dense with kana (particles, inflections), a Chinese quotation is not.\n const kana = counts.get('ja') ?? 0;\n const han = counts.get('zh') ?? 0;\n if (kana > 0 && kana >= (kana + han) * KANA_EVIDENCE_RATIO) {\n counts.set('ja', kana + han);\n counts.delete('zh');\n }\n\n let best: string | null = null;\n let bestCount = 0;\n for (const [locale, count] of counts) {\n if (count > bestCount) {\n best = locale;\n bestCount = count;\n }\n }\n\n return best !== null && bestCount / letters >= DOMINANT_SCRIPT_RATIO ? best : null;\n}\n\n/**\n * The locale to speak `text` in: the script when it decides, else the app locale.\n *\n * Falling back to the app locale (rather than refusing) keeps every Latin-script\n * reply behaving exactly as it did before this existed.\n */\n/**\n * ⚠️ `appLocale` is the caller's best available signal for \"which language did\n * the user mean\", and it is only as good as that signal.\n *\n * With the interface language alone it is a weak proxy: an English-UI user who\n * writes in Urdu produces an Urdu reply, but `appLocale` says `en`, so a shared\n * Arabic script falls back to the family default and picks an Arabic voice.\n * BOFF-7108 is what fixes this properly — it lets the user state the language\n * they are speaking, independently of the interface, and passes THAT here.\n *\n * Callers should therefore hand in the most specific language they know: the\n * user's declared conversation language if there is one, the UI locale only as a\n * last resort.\n */\nexport function resolveSpeechLocale(text: string, appLocale: string): string {\n const detected = detectScriptLocale(text);\n if (detected === null) return appLocale;\n\n // Shared script: the script narrowed it to a family, and the language the user\n // asked for picks the member. Without this, an Urdu reply gets an Arabic voice.\n const family = SHARED_SCRIPTS[detected];\n if (family && family.includes(appLocale)) return appLocale;\n\n return detected;\n}\n"],"mappings":";AAiCA,IAAM,IAAqE;CAEzE;EAAE,QAAQ;EAAM,SAAS;CAA4C;CACrE;EAAE,QAAQ;EAAM,SAAS;CAAqB;CAC9C;EAAE,QAAQ;EAAM,SAAS;CAAkB;CAC3C;EAAE,QAAQ;EAAM,SAAS;CAAoB;CAC7C;EAAE,QAAQ;EAAM,SAAS;CAAyB;CAClD;EAAE,QAAQ;EAAM,SAAS;CAAsB;CAC/C;EAAE,QAAQ;EAAM,SAAS;CAAqB;CAC9C;EAAE,QAAQ;EAAM,SAAS;CAAsB;CAC/C;EAAE,QAAQ;EAAM,SAAS;CAAwB;CACjD;EAAE,QAAQ;EAAM,SAAS;CAAuB;CAChD;EAAE,QAAQ;EAAM,SAAS;CAAuB;CAChD;EAAE,QAAQ;EAAM,SAAS;CAAqB;CAC9C;EAAE,QAAQ;EAAM,SAAS;CAAqB;CAC9C;EAAE,QAAQ;EAAM,SAAS;CAAuB;CAChD;EAAE,QAAQ;EAAM,SAAS;CAAoB;AAC/C,GAeM,IAA8D;CAIlE,IAAI,CAAC,MAAM,IAAI;CACf,IAAI;EAAC;EAAM;EAAM;EAAM;EAAM;CAAI;CACjC,IAAI;EAAC;EAAM;EAAM;EAAM;EAAM;CAAK;CAClC,IAAI;EAAC;EAAM;EAAM;EAAM;EAAM;EAAM;CAAI;AACzC,GAaM,IAAwB,IASxB,IAAsB,IAGtB,IAAS;AAMf,SAAgB,EAAmB,GAA6B;CAC9D,IAAI,CAAC,GAAM,OAAO;CAElB,IAAI,IAAU,GACR,oBAAS,IAAI,IAAoB;CAEvC,KAAK,IAAM,KAAQ,GACZ,MAAO,KAAK,CAAI,GACrB;OAAW;EACX,KAAK,IAAM,EAAE,WAAQ,gBAAa,GAChC,IAAI,EAAQ,KAAK,CAAI,GAAG;GACtB,EAAO,IAAI,IAAS,EAAO,IAAI,CAAM,KAAK,KAAK,CAAC;GAChD;EACF;CALS;CASb,IAAI,MAAY,GAAG,OAAO;CAY1B,IAAM,IAAO,EAAO,IAAI,IAAI,KAAK,GAC3B,IAAM,EAAO,IAAI,IAAI,KAAK;CAChC,AAAI,IAAO,KAAK,MAAS,IAAO,KAAO,MACrC,EAAO,IAAI,MAAM,IAAO,CAAG,GAC3B,EAAO,OAAO,IAAI;CAGpB,IAAI,IAAsB,MACtB,IAAY;CAChB,KAAK,IAAM,CAAC,GAAQ,MAAU,GAC5B,AAAI,IAAQ,MACV,IAAO,GACP,IAAY;CAIhB,OAAO,MAAS,QAAQ,IAAY,KAAW,IAAwB,IAAO;AAChF;AAsBA,SAAgB,EAAoB,GAAc,GAA2B;CAC3E,IAAM,IAAW,EAAmB,CAAI;CACxC,IAAI,MAAa,MAAM,OAAO;CAI9B,IAAM,IAAS,EAAe;CAG9B,OAFI,KAAU,EAAO,SAAS,CAAS,IAAU,IAE1C;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"speechPlayback.js","names":[],"sources":["../../src/utils/speechPlayback.ts"],"sourcesContent":["/**\n * Playback state for the assistant's spoken reply (BOFF-6290).\n *\n * A reducer rather than a pile of `useState` calls, because the awkward part of\n * speech playback is not \"is it speaking\" — it is that the engine's `end` and\n * `error` events arrive AFTER the state has already moved on:\n *\n * - tapping speak on message B while A is talking cancels A, and A's `end`\n * event lands a tick later. Without a guard it would clear B's speaking state\n * and leave a button that says \"stop\" next to silence — or worse, silence\n * next to a button that says \"speak\" while the voice keeps going;\n * - closing the panel cancels playback, and the cancellation itself fires\n * `error` on every queued utterance.\n *\n * Every transition therefore carries a monotonically increasing `requestId`, and\n * a terminal event is only honoured when it belongs to the CURRENT request. That\n * is the whole trick, and it is pure, so it is tested directly (the audio around\n * it is not testable in this repo's node-environment vitest).\n */\n\nexport type SpeechPlaybackState =\n { readonly status: 'idle' } | { readonly status: 'speaking'; readonly messageId: string; readonly requestId: number };\n\nexport type SpeechPlaybackAction =\n /** User pressed speak on a message (or auto-speak fired). */\n | { readonly type: 'start'; readonly messageId: string; readonly requestId: number }\n /** User pressed the control on `messageId`: stop if it is the one talking. */\n | { readonly type: 'toggle'; readonly messageId: string; readonly requestId: number }\n /** Explicit stop: the stop button, panel close, conversation switch, unmount. */\n | { readonly type: 'stop' }\n /** The engine finished the queue for `requestId`. */\n | { readonly type: 'finished'; readonly requestId: number }\n /** The engine failed (or was cancelled) on `requestId`. */\n | { readonly type: 'failed'; readonly requestId: number };\n\nexport const IDLE_PLAYBACK: SpeechPlaybackState = { status: 'idle' };\n\nexport function speechPlaybackReducer(state: SpeechPlaybackState, action: SpeechPlaybackAction): SpeechPlaybackState {\n switch (action.type) {\n case 'start':\n return { status: 'speaking', messageId: action.messageId, requestId: action.requestId };\n\n case 'toggle':\n if (state.status === 'speaking' && state.messageId === action.messageId) return IDLE_PLAYBACK;\n return { status: 'speaking', messageId: action.messageId, requestId: action.requestId };\n\n case 'stop':\n return state.status === 'idle' ? state : IDLE_PLAYBACK;\n\n case 'finished':\n case 'failed':\n // Stale terminal event from a request that was already superseded or\n // cancelled — the newer playback owns the state now.\n if (state.status !== 'speaking' || state.requestId !== action.requestId) return state;\n return IDLE_PLAYBACK;\n\n default:\n return state;\n }\n}\n\n/** Is THIS message the one currently being spoken? Drives one button's state. */\nexport function isSpeakingMessage(state: SpeechPlaybackState, messageId: string): boolean {\n return state.status === 'speaking' && state.messageId === messageId;\n}\n\n/**\n * Does acting on `messageId` require cancelling what the engine is doing now?\n *\n * True whenever anything is playing — including the same message, where the tap\n * means \"stop\". The caller cancels first, then speaks; that ordering is what\n * makes \"starting a new playback cancels the previous one\" hold with a queue of\n * utterances rather than a single one.\n */\nexport function requiresCancel(state: SpeechPlaybackState): boolean {\n return state.status === 'speaking';\n}\n"],"mappings":";AAmCA,IAAa,IAAqC,EAAE,QAAQ,OAAO;AAEnE,SAAgB,EAAsB,GAA4B,GAAmD;CACnH,QAAQ,EAAO,MAAf;EACE,KAAK,SACH,OAAO;GAAE,QAAQ;GAAY,WAAW,EAAO;GAAW,WAAW,EAAO;EAAU;EAExF,KAAK,UAEH,OADI,EAAM,WAAW,cAAc,EAAM,cAAc,EAAO,YAAkB,IACzE;GAAE,QAAQ;GAAY,WAAW,EAAO;GAAW,WAAW,EAAO;EAAU;EAExF,KAAK,QACH,OAAO,EAAM,WAAW,SAAS,IAAQ;EAE3C,KAAK;EACL,KAAK,UAIH,OADI,EAAM,WAAW,cAAc,EAAM,cAAc,EAAO,YAAkB,IACzE;EAET,SACE,OAAO;CACX;AACF;AAGA,SAAgB,EAAkB,GAA4B,GAA4B;CACxF,OAAO,EAAM,WAAW,cAAc,EAAM,cAAc;AAC5D"}
|