@burdenoff/microfe-healthybowl 2026.831.4 → 2026.831.5
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 +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
|
|
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 * ★ Chirp 3: HD accepts **0.25–2.0**. This comment previously said 0.25–4.0,\n * which is the range for the older Standard/WaveNet tiers and is wrong for\n * the tier we actually use. Nothing breaks today — the values in use are 0.9,\n * and 0.85 for Indic scripts and Arabic, well inside both — but a proxy that\n * clamped to 4.0 on the strength of that comment would send a value the\n * vendor rejects.\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/** The tier's accepted speaking-rate bounds, for any caller that clamps. */\nexport const SPEAKING_RATE_MIN = 0.25;\nexport const SPEAKING_RATE_MAX = 2.0;\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":";AAuDA,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