@burdenoff/microfe-healthybowl 2026.831.5 → 2026.831.6
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.
|
@@ -3,16 +3,22 @@ import "./hostedVoiceCatalogue.js";
|
|
|
3
3
|
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
|
-
var r;
|
|
7
|
-
function
|
|
8
|
-
if (r) return {
|
|
6
|
+
var r, i;
|
|
7
|
+
function a() {
|
|
8
|
+
if (r) return {
|
|
9
|
+
endpoint: r,
|
|
10
|
+
getHeaders: i
|
|
11
|
+
};
|
|
9
12
|
if (typeof window < "u") {
|
|
10
13
|
let e = window.__HB_TTS_ENDPOINT__;
|
|
11
|
-
if (e) return {
|
|
14
|
+
if (e) return {
|
|
15
|
+
endpoint: e,
|
|
16
|
+
getHeaders: i
|
|
17
|
+
};
|
|
12
18
|
}
|
|
13
19
|
return { endpoint: null };
|
|
14
20
|
}
|
|
15
|
-
function
|
|
21
|
+
function o(n = a()) {
|
|
16
22
|
return {
|
|
17
23
|
device: e,
|
|
18
24
|
hosted: n.endpoint ? t({
|
|
@@ -22,11 +28,11 @@ function a(n = i()) {
|
|
|
22
28
|
}) : null
|
|
23
29
|
};
|
|
24
30
|
}
|
|
25
|
-
var
|
|
26
|
-
function
|
|
27
|
-
return
|
|
31
|
+
var s = null;
|
|
32
|
+
function c() {
|
|
33
|
+
return s ||= n(o()), s;
|
|
28
34
|
}
|
|
29
35
|
//#endregion
|
|
30
|
-
export {
|
|
36
|
+
export { o as createSpeechEngines, c as getSpeechEngine, a as readSpeechEngineConfig };
|
|
31
37
|
|
|
32
38
|
//# 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;\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 */\nexport function configureSpeechEngine(options: {
|
|
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 runtimeEndpoint = options.ttsEndpoint?.trim() || undefined;\n runtimeGetHeaders = options.getHeaders;\n // The engine is memoised, so a later configure call must invalidate it or the\n // setting 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;AAqCJ,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostedTtsProtocol.js","names":[],"sources":["../../../src/services/speech/hostedTtsProtocol.ts"],"sourcesContent":["/**\n * The wire contract for the hosted TTS proxy, kept pure so it can be tested\n * (BOFF-7111).\n *\n * `browserSpeechEngine` carries a note explaining that it is untestable in this\n * repo — vitest runs in the `node` environment with no DOM and no audio — and\n * that the testable logic was deliberately kept out of it. Same discipline\n * here: request building, response decoding and error classification live in\n * this file with no `window`, `Audio` or `fetch` reference, and the engine file\n * holds only the parts that genuinely need a browser.\n *\n * The browser never talks to the vendor directly. A Google Cloud service-account\n * key cannot be shipped to a client, so every request goes to our own proxy,\n * which holds the credential and does the vendor call.\n */\n\nimport type { SpeechErrorReason } from './types';\n\n/** What the client sends per chunk. */\nexport interface HostedTtsRequest {\n text: string;\n /** BCP-47, e.g. `ta-IN`. The vendor needs the region, not a bare subtag. */\n languageCode: string;\n /** Vendor voice id, e.g. `ta-IN-Chirp3-HD-Kore`. Omitted = server default. */\n voiceName?: string;\n /** Vendor voice tier, so the backend need not infer it from the name. */\n tier: string;\n /**\n * The same knob the device engine calls `rate`.\n *\n * ★
|
|
1
|
+
{"version":3,"file":"hostedTtsProtocol.js","names":[],"sources":["../../../src/services/speech/hostedTtsProtocol.ts"],"sourcesContent":["/**\n * The wire contract for the hosted TTS proxy, kept pure so it can be tested\n * (BOFF-7111).\n *\n * `browserSpeechEngine` carries a note explaining that it is untestable in this\n * repo — vitest runs in the `node` environment with no DOM and no audio — and\n * that the testable logic was deliberately kept out of it. Same discipline\n * here: request building, response decoding and error classification live in\n * this file with no `window`, `Audio` or `fetch` reference, and the engine file\n * holds only the parts that genuinely need a browser.\n *\n * The browser never talks to the vendor directly. A Google Cloud service-account\n * key cannot be shipped to a client, so every request goes to our own proxy,\n * which holds the credential and does the vendor call.\n */\n\nimport type { SpeechErrorReason } from './types';\n\n/** What the client sends per chunk. */\nexport interface HostedTtsRequest {\n text: string;\n /** BCP-47, e.g. `ta-IN`. The vendor needs the region, not a bare subtag. */\n languageCode: string;\n /** Vendor voice id, e.g. `ta-IN-Chirp3-HD-Kore`. Omitted = server default. */\n voiceName?: string;\n /** Vendor voice tier, so the backend need not infer it from the name. */\n tier: string;\n /**\n * The same knob the device engine calls `rate`.\n *\n * ★ The accepted range depends on which vendor ENDPOINT the proxy calls, not\n * on the voice tier — see `SPEAKING_RATE_MAX_SYNC` below. Values in use are\n * 0.9, and 0.85 for Indic scripts and Arabic, comfortably inside every\n * variant, so this has never affected playback.\n */\n speakingRate?: number;\n}\n\n/**\n * Google's synthesize response is `{ audioContent: <base64 mp3> }`. We accept\n * that shape directly so the proxy can be a thin pass-through, but the proxy is\n * also free to return raw audio bytes — see `decodeAudioResponse`.\n */\nexport interface HostedTtsJsonResponse {\n audioContent?: string;\n error?: { message?: string };\n}\n\n/**\n * The accepted speaking-rate bounds, for any caller that clamps.\n *\n * ★ The ceiling is a property of the ENDPOINT, not of the voice tier, and the\n * vendor's own rejection message says both numbers out loud:\n *\n * \"Unable to adjust speaking rate. Please ensure that speaking_rate is in the\n * range [0.25, 4.0] for sync synthesis and in the range [0.25, 2.0] for\n * streaming synthesis.\"\n *\n * Measured against the live API on 2026-08-31 with `en-IN-Chirp3-HD-Puck` and a\n * fixed sentence, reading the returned LINEAR16 duration rather than trusting\n * the HTTP status — 4.0 synthesises and is genuinely ~4x faster (21.93s at 0.25\n * down to 1.37s at 4.0); 4.1, 5.0 and 0.2 are all rejected with the message\n * above.\n *\n * This corrects a previous edit of this file which narrowed the ceiling to 2.0\n * and attributed 4.0 to \"the older Standard/WaveNet tiers\". That reading was\n * wrong: 2.0 is the STREAMING limit, and the tier has nothing to do with it.\n *\n * `SPEAKING_RATE_MAX` is the sync ceiling because the proxy calls\n * `v1/text:synthesize`. Moving it to `v1/text:streamingSynthesize` — tempting,\n * since that is how you cut time-to-first-audio — halves the ceiling, and rates\n * the client had treated as valid would start returning 400. That switch has to\n * change this alias in the same commit, which is why both bounds are named\n * rather than one being a magic number.\n */\nexport const SPEAKING_RATE_MIN = 0.25;\nexport const SPEAKING_RATE_MAX_SYNC = 4.0;\nexport const SPEAKING_RATE_MAX_STREAMING = 2.0;\nexport const SPEAKING_RATE_MAX = SPEAKING_RATE_MAX_SYNC;\n\n/** Vendor limit is 5000 bytes per request; stay well inside it. */\nexport const HOSTED_TTS_MAX_CHARS = 2000;\n\nexport function buildRequest(\n text: string,\n languageCode: string,\n tier: string,\n voiceName?: string | null,\n speakingRate?: number\n): HostedTtsRequest {\n const request: HostedTtsRequest = { text, languageCode, tier };\n // A voice name from ANOTHER language must never be forwarded: the vendor\n // would either error or, worse, read the text with the wrong phoneme model.\n // The caller resolves the voice, but this is the last line of defence.\n if (voiceName && voiceName.toLowerCase().startsWith(languageCode.toLowerCase())) {\n request.voiceName = voiceName;\n }\n if (speakingRate !== undefined) request.speakingRate = speakingRate;\n return request;\n}\n\n/**\n * Map a transport failure onto the reasons the UI already knows how to explain.\n *\n * `cancelled` is deliberately NOT produced here — an aborted request is the\n * caller's own doing and the engine reports it, exactly as the browser engine\n * swallows its own `canceled` utterance errors.\n */\nexport function classifyHttpFailure(status: number): SpeechErrorReason {\n // 401/403 mean the proxy rejected us; there is nothing the user can do and\n // \"unsupported\" is what disables the control rather than showing a retry\n // that will fail identically.\n if (status === 401 || status === 403) return 'not-allowed';\n if (status === 404 || status === 501) return 'unsupported';\n return 'unknown';\n}\n\n/** Base64 → bytes, without assuming a DOM (`atob` is not in node). */\nexport function base64ToBytes(base64: string): Uint8Array {\n // `Buffer` only exists under node (the test environment); typed rather than\n // cast through `any`, which this repo's conventions forbid.\n const nodeBuffer = (\n globalThis as unknown as {\n Buffer?: { from(input: string, encoding: string): { toString(encoding: string): string } };\n }\n ).Buffer;\n const binary =\n typeof atob === 'function' ? atob(base64) : (nodeBuffer?.from(base64, 'base64').toString('binary') ?? '');\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);\n return bytes;\n}\n\n/**\n * Accept either shape the proxy may return: a JSON body carrying base64\n * (the vendor's own shape, so the proxy can pass it straight through) or raw\n * audio bytes.\n *\n * Returns null when the payload carries no audio at all — which must be treated\n * as a failure, not as silence. A zero-byte \"success\" that plays nothing is the\n * dead-button bug this feature already fixed once.\n */\nexport function decodeAudioResponse(\n contentType: string | null,\n body: ArrayBuffer | HostedTtsJsonResponse\n): Uint8Array | null {\n if (body instanceof ArrayBuffer) {\n return body.byteLength > 0 ? new Uint8Array(body) : null;\n }\n if (contentType?.includes('json') || typeof body === 'object') {\n const encoded = body.audioContent;\n if (!encoded) return null;\n const bytes = base64ToBytes(encoded);\n return bytes.length > 0 ? bytes : null;\n }\n return null;\n}\n\n/**\n * Split text the hosted vendor would reject for length.\n *\n * `chunkForSpeech` already splits for the browser engine's ~15s utterance\n * ceiling, and those chunks are normally far under the vendor limit — this is a\n * backstop for a single pathological sentence, and it splits on whitespace so a\n * word is never cut in half.\n */\nexport function splitForVendor(text: string, limit = HOSTED_TTS_MAX_CHARS): string[] {\n if (text.length <= limit) return [text];\n const out: string[] = [];\n let rest = text;\n while (rest.length > limit) {\n const window = rest.slice(0, limit);\n const cut = window.lastIndexOf(' ');\n // No space at all (CJK, or one enormous token): hard-cut at the limit\n // rather than sending something the vendor will reject outright.\n const at = cut > limit * 0.5 ? cut : limit;\n out.push(rest.slice(0, at).trim());\n rest = rest.slice(at).trim();\n }\n if (rest) out.push(rest);\n return out.filter((part) => part.length > 0);\n}\n"],"mappings":";AAiFA,IAAa,IAAuB;AAEpC,SAAgB,EACd,GACA,GACA,GACA,GACA,GACkB;CAClB,IAAM,IAA4B;EAAE;EAAM;EAAc;CAAK;CAQ7D,OAJI,KAAa,EAAU,YAAY,EAAE,WAAW,EAAa,YAAY,CAAC,MAC5E,EAAQ,YAAY,IAElB,MAAiB,KAAA,MAAW,EAAQ,eAAe,IAChD;AACT;AASA,SAAgB,EAAoB,GAAmC;CAMrE,OAFI,MAAW,OAAO,MAAW,MAAY,gBACzC,MAAW,OAAO,MAAW,MAAY,gBACtC;AACT;AAGA,SAAgB,EAAc,GAA4B;CAGxD,IAAM,IACJ,WAGA,QACI,IACJ,OAAO,QAAS,aAAa,KAAK,CAAM,IAAK,GAAY,KAAK,GAAQ,QAAQ,EAAE,SAAS,QAAQ,KAAK,IAClG,IAAQ,IAAI,WAAW,EAAO,MAAM;CAC1C,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KAAK,GAAG,EAAM,KAAK,EAAO,WAAW,CAAC;CACzE,OAAO;AACT;AAWA,SAAgB,EACd,GACA,GACmB;CACnB,IAAI,aAAgB,aAClB,OAAO,EAAK,aAAa,IAAI,IAAI,WAAW,CAAI,IAAI;CAEtD,IAAI,GAAa,SAAS,MAAM,KAAK,OAAO,KAAS,UAAU;EAC7D,IAAM,IAAU,EAAK;EACrB,IAAI,CAAC,GAAS,OAAO;EACrB,IAAM,IAAQ,EAAc,CAAO;EACnC,OAAO,EAAM,SAAS,IAAI,IAAQ;CACpC;CACA,OAAO;AACT;AAUA,SAAgB,EAAe,GAAc,IAAQ,GAAgC;CACnF,IAAI,EAAK,UAAU,GAAO,OAAO,CAAC,CAAI;CACtC,IAAM,IAAgB,CAAC,GACnB,IAAO;CACX,OAAO,EAAK,SAAS,IAAO;EAE1B,IAAM,IADS,EAAK,MAAM,GAAG,CACjB,EAAO,YAAY,GAAG,GAG5B,IAAK,IAAM,IAAQ,KAAM,IAAM;EAErC,AADA,EAAI,KAAK,EAAK,MAAM,GAAG,CAAE,EAAE,KAAK,CAAC,GACjC,IAAO,EAAK,MAAM,CAAE,EAAE,KAAK;CAC7B;CAEA,OADI,KAAM,EAAI,KAAK,CAAI,GAChB,EAAI,QAAQ,MAAS,EAAK,SAAS,CAAC;AAC7C"}
|
package/package.json
CHANGED