@burdenoff/microfe-healthybowl 2026.901.6 → 2026.901.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.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { browserSpeechEngine as e } from "./browserSpeechEngine.js";
|
|
2
|
-
import "./hostedVoiceCatalogue.js";
|
|
3
2
|
import { createHostedTtsEngine as t } from "./hostedTtsSpeechEngine.js";
|
|
4
3
|
import { createRoutingSpeechEngine as n } from "./routingSpeechEngine.js";
|
|
5
4
|
//#region src/services/speech/createSpeechEngine.ts
|
|
@@ -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 *
|
|
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 * the routing engine decides per playback rather than once at startup.\n */\n\nimport { browserSpeechEngine } from './browserSpeechEngine';\nimport { createHostedTtsEngine } from './hostedTtsSpeechEngine';\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 * 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":";;;;AAmCA,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;AAaA,IAAI,IAA8B;AAElC,SAAgB,IAAgC;CAE9C,OADA,AAAa,MAAS,EAA0B,EAAoB,CAAC,GAC9D;AACT;AAGA,SAAgB,IAA0B;CACxC,IAAS;AACX"}
|
package/package.json
CHANGED