@burdenoff/microfe-healthybowl 2026.831.6 → 2026.831.7
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/components/assistant/AssistantSpeechProvider.js +8 -8
- package/dist/healthybowl/context/HealthyBowlContext.js +28 -21
- package/dist/healthybowl/context/HealthyBowlContext.js.map +1 -1
- package/dist/services/speech/createSpeechEngine.js +13 -6
- package/dist/services/speech/createSpeechEngine.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
-
import { getSpeechEngine as n } from "../../services/speech/createSpeechEngine.js";
|
|
1
|
+
import { getSpeechEngine as e } from "../../services/speech/createSpeechEngine.js";
|
|
4
2
|
import "../../services/speech/index.js";
|
|
3
|
+
import { useAssistantStore as t } from "../../store/assistantStore.js";
|
|
4
|
+
import { useTr as n } from "../../shared/hooks/useTr.js";
|
|
5
5
|
import { chunkForSpeech as r, toSpeakableText as i } from "../../utils/speakableText.js";
|
|
6
6
|
import { speechLabelsFor as a } from "../../config/speechLabels.js";
|
|
7
7
|
import { VOICE_LIST_TIMEOUT_MS as o, languageDisplayName as s, selectVoiceForLocale as c, speechGate as ee, speechLangForLocale as l, voiceAvailability as u, voicesForLocale as d } from "../../utils/speechVoices.js";
|
|
@@ -43,10 +43,10 @@ var ue = {
|
|
|
43
43
|
function S() {
|
|
44
44
|
return g(x);
|
|
45
45
|
}
|
|
46
|
-
var C = ({ children: m, visible: g = !0, engine: S =
|
|
47
|
-
let C =
|
|
46
|
+
var C = ({ children: m, visible: g = !0, engine: S = e() }) => {
|
|
47
|
+
let C = n(), { locale: w } = ce(), [T, E] = se(ie, re), [D, O] = b(() => S.listVoices()), [k, A] = b(!1), [j, M] = b(() => /* @__PURE__ */ new Map()), N = y(0), P = y(null), F = y(() => {}), I = h(() => {
|
|
48
48
|
P.current?.(), P.current = null;
|
|
49
|
-
}, []), L =
|
|
49
|
+
}, []), L = t((e) => e.autoSpeakEnabled), R = t((e) => e.setAutoSpeak), de = t((e) => e.activeConversationId), z = v(() => S.isSupported(), [S]);
|
|
50
50
|
_(() => {
|
|
51
51
|
if (!z) return;
|
|
52
52
|
let e = () => {
|
|
@@ -54,7 +54,7 @@ var C = ({ children: m, visible: g = !0, engine: S = n() }) => {
|
|
|
54
54
|
};
|
|
55
55
|
return e(), S.subscribeVoices(e);
|
|
56
56
|
}, [S, z]);
|
|
57
|
-
let B =
|
|
57
|
+
let B = t((e) => e.assistantLanguage), V = t((e) => e.preferredVoices), H = t((e) => e.setPreferredVoice), U = v(() => ne(B, w), [B, w]), W = U.code, G = h((e) => f(e)?.tag ?? l(e), []), K = h((e) => f(e)?.rate ?? .9, []), q = v(() => u(z, D, U.tag, k), [
|
|
58
58
|
z,
|
|
59
59
|
D,
|
|
60
60
|
U,
|
|
@@ -189,7 +189,7 @@ var C = ({ children: m, visible: g = !0, engine: S = n() }) => {
|
|
|
189
189
|
_(() => {
|
|
190
190
|
me.current = Q;
|
|
191
191
|
}, [Q]), _(() => {
|
|
192
|
-
if (!(!L || !g || !z)) return
|
|
192
|
+
if (!(!L || !g || !z)) return t.subscribe((e, t) => {
|
|
193
193
|
let n = e.activeConversationId;
|
|
194
194
|
if (!n || n !== t.activeConversationId) return;
|
|
195
195
|
let r = e.processingByConversationId[n], i = t.processingByConversationId[n];
|
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
import { configureGeocoder as e } from "../utils/geocode.js";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
2
|
+
import { configureSpeechEngine as t } from "../../services/speech/createSpeechEngine.js";
|
|
3
|
+
import "../../services/speech/index.js";
|
|
4
|
+
import { createContext as n, useCallback as r, useContext as i, useRef as a } from "react";
|
|
5
|
+
import { MemoryRouter as o } from "react-router";
|
|
6
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
5
7
|
//#region src/healthybowl/context/HealthyBowlContext.tsx
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
let e =
|
|
8
|
+
var c = n(null);
|
|
9
|
+
function l() {
|
|
10
|
+
let e = i(c);
|
|
9
11
|
if (!e) throw Error("useHealthyBowl must be used within a HealthyBowlProvider");
|
|
10
12
|
return e;
|
|
11
13
|
}
|
|
12
|
-
var
|
|
13
|
-
e({ googleMapsApiKey:
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
workspaceId: c,
|
|
19
|
-
apiGatewayUrl: l,
|
|
20
|
-
globalGatewayUrl: u,
|
|
21
|
-
authToken: d
|
|
22
|
-
}, m = /* @__PURE__ */ i(a.Provider, {
|
|
23
|
-
value: p,
|
|
24
|
-
children: t
|
|
14
|
+
var u = ({ children: n, basePath: i = "/", navigate: l = () => {}, currentUser: u, workspaceId: d = "", apiGatewayUrl: f = "", globalGatewayUrl: p = "", authToken: m = "", googleMapsApiKey: h, ttsEndpoint: g }) => {
|
|
15
|
+
e({ googleMapsApiKey: h });
|
|
16
|
+
let _ = a(m);
|
|
17
|
+
_.current = m, t({
|
|
18
|
+
ttsEndpoint: g,
|
|
19
|
+
getHeaders: r(() => _.current ? { authorization: `Bearer ${_.current}` } : {}, [])
|
|
25
20
|
});
|
|
26
|
-
|
|
21
|
+
let v = {
|
|
22
|
+
basePath: i,
|
|
23
|
+
navigate: l,
|
|
24
|
+
currentUser: u,
|
|
25
|
+
workspaceId: d,
|
|
26
|
+
apiGatewayUrl: f,
|
|
27
|
+
globalGatewayUrl: p,
|
|
28
|
+
authToken: m
|
|
29
|
+
}, y = /* @__PURE__ */ s(c.Provider, {
|
|
30
|
+
value: v,
|
|
31
|
+
children: n
|
|
32
|
+
});
|
|
33
|
+
return i && i !== "/" ? y : /* @__PURE__ */ s(o, { children: y });
|
|
27
34
|
};
|
|
28
35
|
//#endregion
|
|
29
|
-
export {
|
|
36
|
+
export { u as HealthyBowlProvider, l as useHealthyBowl };
|
|
30
37
|
|
|
31
38
|
//# sourceMappingURL=HealthyBowlContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HealthyBowlContext.js","names":[],"sources":["../../../src/healthybowl/context/HealthyBowlContext.tsx"],"sourcesContent":["/**\n * HealthyBowl Context Provider\n * @module healthybowl\n */\n\nimport { createContext, useContext, type FC, type PropsWithChildren } from 'react';\nimport { MemoryRouter } from 'react-router';\nimport type { HealthyBowlRootProps } from '../types';\nimport { configureGeocoder } from '../utils/geocode';\n\ninterface HealthyBowlContextValue {\n basePath: string;\n navigate: (path: string) => void;\n currentUser: HealthyBowlRootProps['currentUser'];\n workspaceId: string;\n apiGatewayUrl: string;\n globalGatewayUrl: string;\n authToken: string;\n}\n\nconst HealthyBowlContext = createContext<HealthyBowlContextValue | null>(null);\n\nexport function useHealthyBowl(): HealthyBowlContextValue {\n const context = useContext(HealthyBowlContext);\n if (!context) {\n throw new Error('useHealthyBowl must be used within a HealthyBowlProvider');\n }\n return context;\n}\n\nexport const HealthyBowlProvider: FC<PropsWithChildren<HealthyBowlRootProps>> = ({\n children,\n basePath = '/',\n navigate = () => {},\n currentUser,\n workspaceId = '',\n apiGatewayUrl = '',\n globalGatewayUrl = '',\n authToken = '',\n googleMapsApiKey,\n}) => {\n // Inject the host app's Google Maps key into the (non-React) geocoder. Done\n // synchronously in render (not useEffect) so it's set before child map effects\n // run — child effects fire before parent effects. Idempotent module assignment.\n configureGeocoder({ googleMapsApiKey });\n\n const contextValue: HealthyBowlContextValue = {\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n globalGatewayUrl,\n authToken,\n };\n\n const content = <HealthyBowlContext.Provider value={contextValue}>{children}</HealthyBowlContext.Provider>;\n\n // If basePath is provided, we're running inside the host shell (which has BrowserRouter)\n if (basePath && basePath !== '/') return content;\n\n // Standalone mode: wrap in MemoryRouter\n return <MemoryRouter>{content}</MemoryRouter>;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HealthyBowlContext.js","names":[],"sources":["../../../src/healthybowl/context/HealthyBowlContext.tsx"],"sourcesContent":["/**\n * HealthyBowl Context Provider\n * @module healthybowl\n */\n\nimport { createContext, useCallback, useContext, useRef, type FC, type PropsWithChildren } from 'react';\nimport { MemoryRouter } from 'react-router';\nimport type { HealthyBowlRootProps } from '../types';\nimport { configureGeocoder } from '../utils/geocode';\nimport { configureSpeechEngine } from '../../services/speech';\n\ninterface HealthyBowlContextValue {\n basePath: string;\n navigate: (path: string) => void;\n currentUser: HealthyBowlRootProps['currentUser'];\n workspaceId: string;\n apiGatewayUrl: string;\n globalGatewayUrl: string;\n authToken: string;\n}\n\nconst HealthyBowlContext = createContext<HealthyBowlContextValue | null>(null);\n\nexport function useHealthyBowl(): HealthyBowlContextValue {\n const context = useContext(HealthyBowlContext);\n if (!context) {\n throw new Error('useHealthyBowl must be used within a HealthyBowlProvider');\n }\n return context;\n}\n\nexport const HealthyBowlProvider: FC<PropsWithChildren<HealthyBowlRootProps>> = ({\n children,\n basePath = '/',\n navigate = () => {},\n currentUser,\n workspaceId = '',\n apiGatewayUrl = '',\n globalGatewayUrl = '',\n authToken = '',\n googleMapsApiKey,\n ttsEndpoint,\n}) => {\n // Inject the host app's Google Maps key into the (non-React) geocoder. Done\n // synchronously in render (not useEffect) so it's set before child map effects\n // run — child effects fire before parent effects. Idempotent module assignment.\n configureGeocoder({ googleMapsApiKey });\n\n /**\n * Point the assistant's speech stack at the hosted TTS proxy.\n *\n * Wiring it HERE, rather than exporting `configureSpeechEngine` for the host\n * to call, is what makes the feature exist at all: nothing outside this graph\n * imported it, so the published bundle had the function tree-shaken away and\n * the module-level endpoint/header slots could never be assigned. The only\n * reachable switch was `window.__HB_TTS_ENDPOINT__`, which carries no headers\n * — i.e. hosted TTS could previously only have been enabled ANONYMOUSLY,\n * against a proxy that bills per character.\n *\n * The token is read through a ref rather than captured. `configureSpeechEngine`\n * is deliberately idempotent (resetting the memoised engine every render would\n * cancel playback mid-reply), so it keeps the FIRST `getHeaders` it is given —\n * and a captured token would work right up until it refreshed, then fail in\n * the hardest place to notice. A stable identity also means this call is a\n * no-op on every render after the first.\n */\n const authTokenRef = useRef(authToken);\n authTokenRef.current = authToken;\n const getHeaders = useCallback(\n (): Record<string, string> => (authTokenRef.current ? { authorization: `Bearer ${authTokenRef.current}` } : {}),\n []\n );\n configureSpeechEngine({ ttsEndpoint, getHeaders });\n\n const contextValue: HealthyBowlContextValue = {\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n globalGatewayUrl,\n authToken,\n };\n\n const content = <HealthyBowlContext.Provider value={contextValue}>{children}</HealthyBowlContext.Provider>;\n\n // If basePath is provided, we're running inside the host shell (which has BrowserRouter)\n if (basePath && basePath !== '/') return content;\n\n // Standalone mode: wrap in MemoryRouter\n return <MemoryRouter>{content}</MemoryRouter>;\n};\n"],"mappings":";;;;;;;AAqBA,IAAM,IAAqB,EAA8C,IAAI;AAE7E,SAAgB,IAA0C;CACxD,IAAM,IAAU,EAAW,CAAkB;CAC7C,IAAI,CAAC,GACH,MAAU,MAAM,0DAA0D;CAE5E,OAAO;AACT;AAEA,IAAa,KAAoE,EAC/E,aACA,cAAW,KACX,oBAAiB,CAAC,GAClB,gBACA,iBAAc,IACd,mBAAgB,IAChB,sBAAmB,IACnB,eAAY,IACZ,qBACA,qBACI;CAIJ,EAAkB,EAAE,oBAAiB,CAAC;CAoBtC,IAAM,IAAe,EAAO,CAAS;CAMrC,AALA,EAAa,UAAU,GAKvB,EAAsB;EAAE;EAAa,YAJlB,QACc,EAAa,UAAU,EAAE,eAAe,UAAU,EAAa,UAAU,IAAI,CAAC,GAC7G,CAAC,CAEkC;CAAW,CAAC;CAEjD,IAAM,IAAwC;EAC5C;EACA;EACA;EACA;EACA;EACA;EACA;CACF,GAEM,IAAU,kBAAC,EAAmB,UAApB;EAA6B,OAAO;EAAe;CAAsC,CAAA;CAMzG,OAHI,KAAY,MAAa,MAAY,IAGlC,kBAAC,GAAD,EAAA,UAAe,EAAsB,CAAA;AAC9C"}
|
|
@@ -4,7 +4,11 @@ import { createHostedTtsEngine as t } from "./hostedTtsSpeechEngine.js";
|
|
|
4
4
|
import { createRoutingSpeechEngine as n } from "./routingSpeechEngine.js";
|
|
5
5
|
//#region src/services/speech/createSpeechEngine.ts
|
|
6
6
|
var r, i;
|
|
7
|
-
function a() {
|
|
7
|
+
function a(e) {
|
|
8
|
+
let t = e.ttsEndpoint?.trim() || void 0;
|
|
9
|
+
t === r && e.getHeaders === i || (r = t, i = e.getHeaders, u());
|
|
10
|
+
}
|
|
11
|
+
function o() {
|
|
8
12
|
if (r) return {
|
|
9
13
|
endpoint: r,
|
|
10
14
|
getHeaders: i
|
|
@@ -18,7 +22,7 @@ function a() {
|
|
|
18
22
|
}
|
|
19
23
|
return { endpoint: null };
|
|
20
24
|
}
|
|
21
|
-
function
|
|
25
|
+
function s(n = o()) {
|
|
22
26
|
return {
|
|
23
27
|
device: e,
|
|
24
28
|
hosted: n.endpoint ? t({
|
|
@@ -28,11 +32,14 @@ function o(n = a()) {
|
|
|
28
32
|
}) : null
|
|
29
33
|
};
|
|
30
34
|
}
|
|
31
|
-
var
|
|
32
|
-
function
|
|
33
|
-
return
|
|
35
|
+
var c = null;
|
|
36
|
+
function l() {
|
|
37
|
+
return c ||= n(s()), c;
|
|
38
|
+
}
|
|
39
|
+
function u() {
|
|
40
|
+
c = null;
|
|
34
41
|
}
|
|
35
42
|
//#endregion
|
|
36
|
-
export {
|
|
43
|
+
export { a as configureSpeechEngine, s as createSpeechEngines, l as getSpeechEngine, o as readSpeechEngineConfig, u as resetSpeechEngine };
|
|
37
44
|
|
|
38
45
|
//# sourceMappingURL=createSpeechEngine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSpeechEngine.js","names":[],"sources":["../../../src/services/speech/createSpeechEngine.ts"],"sourcesContent":["/**\n * Which engine speaks — the single switch for the hosted-TTS rollout\n * (BOFF-7111).\n *\n * **Default is unchanged behaviour.** With no endpoint configured this returns\n * the device engine that ships today, so merging this changes nothing for\n * anyone.\n *\n * ★The endpoint MUST be resolved at RUNTIME, not from `import.meta.env`. This\n * microfe is published as a prebuilt package by its own CI, which has no such\n * variable, so a build-time constant is inlined to `undefined` and the whole\n * hosted path is eliminated before the host app ever consumes it — the flag\n * could then never be turned on at all. Verified against the published\n * `2026.829.4` bundle: `geocode.js` ships with its `import.meta.env` fallback\n * gone entirely, leaving only the runtime lookups. `configureGeocoder` exists\n * for exactly this reason and this mirrors it.\n *\n * The fallback is per-language, not global: a hosted vendor that cannot speak\n * the reply's language is worse than the device voice, not better, so\n * `resolveEngine` is asked per playback rather than once at startup.\n */\n\nimport { browserSpeechEngine } from './browserSpeechEngine';\nimport { createHostedTtsEngine } from './hostedTtsSpeechEngine';\nimport { hostedSupportsLanguage } from './hostedVoiceCatalogue';\nimport { createRoutingSpeechEngine } from './routingSpeechEngine';\nimport type { SpeechEngine } from './types';\n\nexport interface SpeechEngineConfig {\n /** Our proxy's URL. Empty/undefined keeps the device engine. */\n endpoint?: string | null;\n getHeaders?: () => Record<string, string>;\n fetchImpl?: typeof fetch;\n}\n\n/** Injected by the host app, which is the only build that knows the URL. */\nlet runtimeEndpoint: string | undefined;\nlet runtimeGetHeaders: (() => Record<string, string>) | undefined;\n\n/**\n * Point the assistant at a hosted TTS proxy.\n *\n * Called by the host shell's provider, exactly as `configureGeocoder` is. This\n * is the supported way to turn hosted speech on; the environment variable below\n * only ever works when this package is run directly (dev / standalone).\n *\n * ★ `getHeaders` is not optional in practice, only in the type. The proxy turns\n * text into audio the org is BILLED for, so an endpoint that accepts anonymous\n * POSTs is a metered API open to anyone who reads the bundle. The engine has\n * always supported per-request headers; until now nothing could reach that hook\n * from the host, which meant the only configuration this function could express\n * was an unauthenticated one. It is a function rather than a value because\n * access tokens expire and the engine outlives any one of them — reading a\n * token once at configure time would work until it rotated and then fail\n * exactly where it is hardest to notice, mid-reply.\n */\nexport function configureSpeechEngine(options: {\n ttsEndpoint?: string | null;\n getHeaders?: () => Record<string, string>;\n}): void {\n
|
|
1
|
+
{"version":3,"file":"createSpeechEngine.js","names":[],"sources":["../../../src/services/speech/createSpeechEngine.ts"],"sourcesContent":["/**\n * Which engine speaks — the single switch for the hosted-TTS rollout\n * (BOFF-7111).\n *\n * **Default is unchanged behaviour.** With no endpoint configured this returns\n * the device engine that ships today, so merging this changes nothing for\n * anyone.\n *\n * ★The endpoint MUST be resolved at RUNTIME, not from `import.meta.env`. This\n * microfe is published as a prebuilt package by its own CI, which has no such\n * variable, so a build-time constant is inlined to `undefined` and the whole\n * hosted path is eliminated before the host app ever consumes it — the flag\n * could then never be turned on at all. Verified against the published\n * `2026.829.4` bundle: `geocode.js` ships with its `import.meta.env` fallback\n * gone entirely, leaving only the runtime lookups. `configureGeocoder` exists\n * for exactly this reason and this mirrors it.\n *\n * The fallback is per-language, not global: a hosted vendor that cannot speak\n * the reply's language is worse than the device voice, not better, so\n * `resolveEngine` is asked per playback rather than once at startup.\n */\n\nimport { browserSpeechEngine } from './browserSpeechEngine';\nimport { createHostedTtsEngine } from './hostedTtsSpeechEngine';\nimport { hostedSupportsLanguage } from './hostedVoiceCatalogue';\nimport { createRoutingSpeechEngine } from './routingSpeechEngine';\nimport type { SpeechEngine } from './types';\n\nexport interface SpeechEngineConfig {\n /** Our proxy's URL. Empty/undefined keeps the device engine. */\n endpoint?: string | null;\n getHeaders?: () => Record<string, string>;\n fetchImpl?: typeof fetch;\n}\n\n/** Injected by the host app, which is the only build that knows the URL. */\nlet runtimeEndpoint: string | undefined;\nlet runtimeGetHeaders: (() => Record<string, string>) | undefined;\n\n/**\n * Point the assistant at a hosted TTS proxy.\n *\n * Called by the host shell's provider, exactly as `configureGeocoder` is. This\n * is the supported way to turn hosted speech on; the environment variable below\n * only ever works when this package is run directly (dev / standalone).\n *\n * ★ `getHeaders` is not optional in practice, only in the type. The proxy turns\n * text into audio the org is BILLED for, so an endpoint that accepts anonymous\n * POSTs is a metered API open to anyone who reads the bundle. The engine has\n * always supported per-request headers; until now nothing could reach that hook\n * from the host, which meant the only configuration this function could express\n * was an unauthenticated one. It is a function rather than a value because\n * access tokens expire and the engine outlives any one of them — reading a\n * token once at configure time would work until it rotated and then fail\n * exactly where it is hardest to notice, mid-reply.\n */\nexport function configureSpeechEngine(options: {\n ttsEndpoint?: string | null;\n getHeaders?: () => Record<string, string>;\n}): void {\n const endpoint = options.ttsEndpoint?.trim() || undefined;\n\n // ★ Idempotent because it is called from RENDER, exactly as `configureGeocoder`\n // is. That sibling gets away with an unconditional assignment; this one cannot.\n // `resetSpeechEngine()` drops the memoised engine, and the engine's identity is\n // a dependency of `AssistantSpeechProvider`'s effects (it takes\n // `engine = getSpeechEngine()` as a default prop) — so resetting on every\n // render would hand back a new object every render, re-running the voice\n // subscription continuously and cancelling playback mid-reply. Bailing out\n // when nothing changed keeps the singleton stable without asking every caller\n // to remember why.\n if (endpoint === runtimeEndpoint && options.getHeaders === runtimeGetHeaders) return;\n\n runtimeEndpoint = endpoint;\n runtimeGetHeaders = options.getHeaders;\n // The engine is memoised, so a real change must invalidate it or the setting\n // would silently not take effect.\n resetSpeechEngine();\n}\n\n/**\n * Read the rollout config.\n *\n * Order matters: explicit runtime configuration, then a global the host can set\n * before the bundle loads, and only then the build-time variable — which is\n * eliminated in the published package and therefore useful for local dev only.\n */\nexport function readSpeechEngineConfig(): SpeechEngineConfig {\n // `getHeaders` rides along with every source, not just the first: the window\n // global carries a URL only, and a host that sets it still needs its auth\n // headers to reach the engine.\n if (runtimeEndpoint) return { endpoint: runtimeEndpoint, getHeaders: runtimeGetHeaders };\n if (typeof window !== 'undefined') {\n const fromWindow = (window as unknown as { __HB_TTS_ENDPOINT__?: string }).__HB_TTS_ENDPOINT__;\n if (fromWindow) return { endpoint: fromWindow, getHeaders: runtimeGetHeaders };\n }\n const fromEnv =\n typeof import.meta !== 'undefined' ? (import.meta.env?.VITE_HB_TTS_ENDPOINT as string | undefined) : undefined;\n return { endpoint: fromEnv?.trim() || null };\n}\n\n/**\n * The engine to use, or the device engine when hosted TTS is not configured.\n *\n * Returns `null` for `hosted` when off, so callers can tell \"hosted is not\n * configured\" from \"hosted is configured but cannot speak this language\".\n */\nexport function createSpeechEngines(config: SpeechEngineConfig = readSpeechEngineConfig()): {\n device: SpeechEngine;\n hosted: SpeechEngine | null;\n} {\n const hosted = config.endpoint\n ? createHostedTtsEngine({\n endpoint: config.endpoint,\n getHeaders: config.getHeaders,\n fetchImpl: config.fetchImpl,\n })\n : null;\n return { device: browserSpeechEngine, hosted };\n}\n\n/**\n * Pick the engine for a specific language.\n *\n * Hosted wins when it is configured, usable on this platform, and actually\n * covers the language. Otherwise the device engine — which may itself have no\n * voice for the language, and the existing `voiceAvailability` / `speechGate`\n * logic explains that to the user exactly as it does today.\n */\nexport function resolveEngine(\n engines: { device: SpeechEngine; hosted: SpeechEngine | null },\n languageTag: string\n): SpeechEngine {\n const { device, hosted } = engines;\n if (!hosted) return device;\n if (!hosted.isSupported()) return device;\n // A hosted voice in the wrong language would be read with the wrong phoneme\n // model — the same \"confident nonsense\" the device path already refuses.\n if (!hostedSupportsLanguage(languageTag)) return device;\n return hosted;\n}\n\n/**\n * The engine the assistant actually uses.\n *\n * A module-level singleton on purpose: the engine's identity appears in\n * `AssistantSpeechProvider`'s dependency arrays, so producing a new object per\n * render would re-run the voice subscription on every render.\n *\n * With no endpoint configured this IS `browserSpeechEngine` — `createRoutingSpeechEngine`\n * returns the device engine unchanged rather than wrapping it — so the default\n * path keeps today's behaviour and today's object identity.\n */\nlet cached: SpeechEngine | null = null;\n\nexport function getSpeechEngine(): SpeechEngine {\n if (!cached) cached = createRoutingSpeechEngine(createSpeechEngines());\n return cached;\n}\n\n/** Test seam: drop the singleton so the next call re-reads the config. */\nexport function resetSpeechEngine(): void {\n cached = null;\n}\n"],"mappings":";;;;;AAoCA,IAAI,GACA;AAmBJ,SAAgB,EAAsB,GAG7B;CACP,IAAM,IAAW,EAAQ,aAAa,KAAK,KAAK,KAAA;CAW5C,MAAa,KAAmB,EAAQ,eAAe,MAE3D,IAAkB,GAClB,IAAoB,EAAQ,YAG5B,EAAkB;AACpB;AASA,SAAgB,IAA6C;CAI3D,IAAI,GAAiB,OAAO;EAAE,UAAU;EAAiB,YAAY;CAAkB;CACvF,IAAI,OAAO,SAAW,KAAa;EACjC,IAAM,IAAc,OAAuD;EAC3E,IAAI,GAAY,OAAO;GAAE,UAAU;GAAY,YAAY;EAAkB;CAC/E;CAGA,OAAO,EAAE,UAA6B,KAAK;AAC7C;AAQA,SAAgB,EAAoB,IAA6B,EAAuB,GAGtF;CAQA,OAAO;EAAE,QAAQ;EAAqB,QAPvB,EAAO,WAClB,EAAsB;GACpB,UAAU,EAAO;GACjB,YAAY,EAAO;GACnB,WAAW,EAAO;EACpB,CAAC,IACD;CACyC;AAC/C;AAkCA,IAAI,IAA8B;AAElC,SAAgB,IAAgC;CAE9C,OADA,AAAa,MAAS,EAA0B,EAAoB,CAAC,GAC9D;AACT;AAGA,SAAgB,IAA0B;CACxC,IAAS;AACX"}
|
package/package.json
CHANGED