@adea-ai/voice 0.0.0-stage → 0.4.0

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.
Files changed (60) hide show
  1. package/README.md +136 -2
  2. package/dist/cli/helpers-cli.d.ts +2 -0
  3. package/dist/cli/helpers-cli.js +117 -0
  4. package/dist/contract/contract.d.ts +157 -0
  5. package/dist/contract/errors.d.ts +26 -0
  6. package/dist/contract/index.d.ts +10 -0
  7. package/dist/contract/index.js +64 -0
  8. package/dist/contract/session.d.ts +71 -0
  9. package/dist/contract/turns.d.ts +91 -0
  10. package/dist/contract/wire.d.ts +279 -0
  11. package/dist/desktop/conversation.d.ts +86 -0
  12. package/dist/desktop/desktop-voice.d.ts +212 -0
  13. package/dist/desktop/helper-lock.d.ts +121 -0
  14. package/dist/desktop/helper-process.d.ts +96 -0
  15. package/dist/desktop/index.d.ts +9 -0
  16. package/dist/desktop/index.js +1454 -0
  17. package/dist/desktop/macho-digest.d.ts +9 -0
  18. package/dist/index-7n7epq1a.js +47 -0
  19. package/dist/index-a7d617zr.js +295 -0
  20. package/dist/index-ght8wwpd.js +156 -0
  21. package/dist/index-m4g2tpeq.js +522 -0
  22. package/dist/index-r4hz8gk0.js +10 -0
  23. package/dist/index-tvz9s9nz.js +77 -0
  24. package/dist/index.d.ts +7 -0
  25. package/dist/index.js +96 -0
  26. package/dist/settings/index.d.ts +5 -0
  27. package/dist/settings/index.js +34 -0
  28. package/dist/settings/settings.d.ts +163 -0
  29. package/dist/web/index.d.ts +16 -0
  30. package/dist/web/index.js +1697 -0
  31. package/dist/web/stt/speech-recognition.d.ts +226 -0
  32. package/dist/web/tts/locale-match.d.ts +40 -0
  33. package/dist/web/tts/phonon.d.ts +139 -0
  34. package/dist/web/tts/player.d.ts +115 -0
  35. package/dist/web/tts/system-voices.d.ts +162 -0
  36. package/dist/web/turns.d.ts +91 -0
  37. package/package.json +68 -4
  38. package/src/cli/helpers-cli.ts +135 -0
  39. package/src/contract/contract.ts +393 -0
  40. package/src/contract/errors.ts +98 -0
  41. package/src/contract/index.ts +10 -0
  42. package/src/contract/session.ts +77 -0
  43. package/src/contract/turns.ts +48 -0
  44. package/src/contract/wire.ts +384 -0
  45. package/src/desktop/conversation.ts +347 -0
  46. package/src/desktop/desktop-voice.ts +1129 -0
  47. package/src/desktop/helper-lock.ts +550 -0
  48. package/src/desktop/helper-process.ts +408 -0
  49. package/src/desktop/index.ts +18 -0
  50. package/src/desktop/macho-digest.ts +135 -0
  51. package/src/index.ts +7 -0
  52. package/src/settings/index.ts +5 -0
  53. package/src/settings/settings.ts +478 -0
  54. package/src/web/index.ts +16 -0
  55. package/src/web/stt/speech-recognition.ts +1013 -0
  56. package/src/web/tts/locale-match.ts +131 -0
  57. package/src/web/tts/phonon.ts +386 -0
  58. package/src/web/tts/player.ts +271 -0
  59. package/src/web/tts/system-voices.ts +510 -0
  60. package/src/web/turns.ts +235 -0
@@ -0,0 +1,478 @@
1
+ /**
2
+ * The unified Voice settings (#32), one model for web, desktop and mobile.
3
+ *
4
+ * Settings are the only place a host stores what a person chose: which provider serves each kind,
5
+ * the language, the model or voice, the consents (a model download, a network speech service), the
6
+ * offline-only switch, the folders of models they brought themselves, and whether a dictation is
7
+ * sent as soon as it finishes. Everything defaults to the conservative answer: offline only, no
8
+ * download, no network, no provider override.
9
+ *
10
+ * Settings are **per device**: a model folder is an absolute path on one machine, and a provider
11
+ * available on a Mac means nothing on a phone. Persist them in device-local storage
12
+ * (`createVoiceSettingsStore`), never in a synced profile.
13
+ *
14
+ * The module is pure: it validates and serialises a plain object, derives the routing policy, and
15
+ * never touches storage. A host persists `serializeVoiceSettings()` and reads it back through
16
+ * `readVoiceSettings()`, which reports what it had to ignore instead of silently keeping a value
17
+ * it did not understand.
18
+ */
19
+ import { WEB_ROUTING_POLICY, type VoiceProviderKind, type VoiceRoutingPolicy } from "../contract/contract";
20
+ import { VoiceError } from "../contract/errors";
21
+
22
+ export const SETTINGS_SCHEMA_VERSION = 2;
23
+ /** Older versions this reader migrates instead of resetting. */
24
+ const MIGRATABLE_VERSIONS = [1] as const;
25
+
26
+ export interface SpeechToTextSettings {
27
+ /** An explicit provider id, or undefined to follow the routing chain. */
28
+ readonly provider?: string;
29
+ /** A BCP-47 tag the person chose, or undefined for the browser's language. */
30
+ readonly locale?: string;
31
+ /** Whether the host may send audio to the browser's speech service. Default false. */
32
+ readonly networkConsent: boolean;
33
+ /**
34
+ * A model or engine variant within the provider (`analyzer`/`legacy` for Apple, a model id for
35
+ * transcribe.cpp), or undefined for the provider's own choice.
36
+ */
37
+ readonly model?: string;
38
+ }
39
+
40
+ export interface TextToSpeechSettings {
41
+ readonly provider?: string;
42
+ readonly locale?: string;
43
+ readonly voice?: string;
44
+ /** Whether the host may use a remote platform voice. Default false. */
45
+ readonly networkConsent: boolean;
46
+ /** Speaking rate, 0.5 (slow) to 2 (fast); undefined is the voice's natural rate. */
47
+ readonly rate?: number;
48
+ }
49
+
50
+ export interface ModelSettings {
51
+ /** A standing permission to install models the person has already agreed to. Default false. */
52
+ readonly allowDownload: boolean;
53
+ /** Keep model files in the browser cache. Default true. */
54
+ readonly cache: boolean;
55
+ /**
56
+ * Folders of models the person brought (BYOM), as absolute paths on this device. Models are
57
+ * read in place, never moved or copied, and removing a folder here never deletes a file.
58
+ */
59
+ readonly folders: readonly string[];
60
+ }
61
+
62
+ export interface PrivacySettings {
63
+ /**
64
+ * A hard switch: no network speech service and no model download start, whatever the consents
65
+ * say. Default false, because the consents themselves already default to "no": this is for a
66
+ * person who wants a guarantee that survives a later consent click.
67
+ */
68
+ readonly offlineOnly: boolean;
69
+ }
70
+
71
+ export interface DictationSettings {
72
+ /** Send the message as soon as a dictation finishes. Default false. */
73
+ readonly autoSend: boolean;
74
+ }
75
+
76
+ export interface VoiceSettings {
77
+ readonly schemaVersion: number;
78
+ readonly stt: SpeechToTextSettings;
79
+ readonly tts: TextToSpeechSettings;
80
+ readonly models: ModelSettings;
81
+ readonly privacy: PrivacySettings;
82
+ readonly dictation: DictationSettings;
83
+ }
84
+
85
+ /** The defaults, deep-frozen. Functions here hand out copies, so a caller can never mutate them. */
86
+ export const DEFAULT_VOICE_SETTINGS: VoiceSettings = Object.freeze({
87
+ schemaVersion: SETTINGS_SCHEMA_VERSION,
88
+ stt: Object.freeze({ networkConsent: false }),
89
+ tts: Object.freeze({ networkConsent: false }),
90
+ models: Object.freeze({ allowDownload: false, cache: true, folders: Object.freeze([]) as readonly string[] }),
91
+ privacy: Object.freeze({ offlineOnly: false }),
92
+ dictation: Object.freeze({ autoSend: false }),
93
+ });
94
+
95
+ /** A fresh, mutable copy of the defaults. */
96
+ function defaultSettings(): VoiceSettings {
97
+ return {
98
+ schemaVersion: DEFAULT_VOICE_SETTINGS.schemaVersion,
99
+ stt: { ...DEFAULT_VOICE_SETTINGS.stt },
100
+ tts: { ...DEFAULT_VOICE_SETTINGS.tts },
101
+ models: { ...DEFAULT_VOICE_SETTINGS.models, folders: [] },
102
+ privacy: { ...DEFAULT_VOICE_SETTINGS.privacy },
103
+ dictation: { ...DEFAULT_VOICE_SETTINGS.dictation },
104
+ };
105
+ }
106
+
107
+ /** Longest accepted string per field; anything longer is a corrupt or hostile store. */
108
+ const MAX_LENGTH = { provider: 128, locale: 64, voice: 256, model: 256, folder: 1024 } as const;
109
+ const MAX_FOLDERS = 16;
110
+ const RATE_RANGE = { min: 0.5, max: 2 } as const;
111
+
112
+ const KNOWN_KEYS = {
113
+ root: ["schemaVersion", "stt", "tts", "models", "privacy", "dictation"],
114
+ stt: ["provider", "locale", "networkConsent", "model"],
115
+ tts: ["provider", "locale", "voice", "networkConsent", "rate"],
116
+ models: ["allowDownload", "cache", "folders"],
117
+ privacy: ["offlineOnly"],
118
+ dictation: ["autoSend"],
119
+ } as const;
120
+
121
+ export interface ReadSettingsResult {
122
+ readonly settings: VoiceSettings;
123
+ /** What was rejected or ignored, for a settings screen to show. Empty means a clean read. */
124
+ readonly issues: readonly string[];
125
+ }
126
+
127
+ /** Parses stored settings. A missing value is the default; anything malformed is reported. */
128
+ export function readVoiceSettings(raw: string | null | undefined): ReadSettingsResult {
129
+ if (raw === null || raw === undefined || raw.trim() === "") {
130
+ return { settings: defaultSettings(), issues: [] };
131
+ }
132
+ let parsed: unknown;
133
+ try {
134
+ parsed = JSON.parse(raw);
135
+ } catch (error) {
136
+ return {
137
+ settings: defaultSettings(),
138
+ issues: [`stored settings are not JSON: ${error instanceof Error ? error.message : String(error)}`],
139
+ };
140
+ }
141
+ return validateVoiceSettings(parsed);
142
+ }
143
+
144
+ /** Validates a value (from storage or a settings form) field by field. */
145
+ export function validateVoiceSettings(raw: unknown): ReadSettingsResult {
146
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
147
+ return { settings: defaultSettings(), issues: ["settings must be an object"] };
148
+ }
149
+ const issues: string[] = [];
150
+ const object = raw as Record<string, unknown>;
151
+ const version = object.schemaVersion;
152
+ const migrating = (MIGRATABLE_VERSIONS as readonly unknown[]).includes(version);
153
+ if (version !== undefined && version !== SETTINGS_SCHEMA_VERSION && !migrating) {
154
+ issues.push(`schemaVersion ${String(version)} is not ${SETTINGS_SCHEMA_VERSION}; using defaults`);
155
+ return { settings: defaultSettings(), issues };
156
+ }
157
+ // Version 1 had no privacy or dictation sections and no folders; its fields keep their meaning.
158
+ unknownKeys(object, KNOWN_KEYS.root, "", issues);
159
+
160
+ const stt = section(object.stt, "stt", issues);
161
+ const tts = section(object.tts, "tts", issues);
162
+ const models = section(object.models, "models", issues);
163
+ const privacy = section(object.privacy, "privacy", issues);
164
+ const dictation = section(object.dictation, "dictation", issues);
165
+ unknownKeys(stt, KNOWN_KEYS.stt, "stt.", issues);
166
+ unknownKeys(tts, KNOWN_KEYS.tts, "tts.", issues);
167
+ unknownKeys(models, KNOWN_KEYS.models, "models.", issues);
168
+ unknownKeys(privacy, KNOWN_KEYS.privacy, "privacy.", issues);
169
+ unknownKeys(dictation, KNOWN_KEYS.dictation, "dictation.", issues);
170
+ const sttConsent = boolean(stt.networkConsent, "stt.networkConsent", issues, false);
171
+ const ttsConsent = boolean(tts.networkConsent, "tts.networkConsent", issues, false);
172
+
173
+ return {
174
+ settings: {
175
+ schemaVersion: SETTINGS_SCHEMA_VERSION,
176
+ stt: {
177
+ networkConsent: sttConsent,
178
+ ...optionalString(stt.provider, "stt.provider", issues, "provider", MAX_LENGTH.provider),
179
+ ...optionalLocale(stt.locale, "stt.locale", issues),
180
+ ...optionalString(stt.model, "stt.model", issues, "model", MAX_LENGTH.model),
181
+ },
182
+ tts: {
183
+ networkConsent: ttsConsent,
184
+ ...optionalString(tts.provider, "tts.provider", issues, "provider", MAX_LENGTH.provider),
185
+ ...optionalLocale(tts.locale, "tts.locale", issues),
186
+ ...optionalString(tts.voice, "tts.voice", issues, "voice", MAX_LENGTH.voice),
187
+ ...optionalRate(tts.rate, "tts.rate", issues),
188
+ },
189
+ models: {
190
+ allowDownload: boolean(models.allowDownload, "models.allowDownload", issues, false),
191
+ cache: boolean(models.cache, "models.cache", issues, true),
192
+ folders: folderList(models.folders, "models.folders", issues),
193
+ },
194
+ privacy: {
195
+ offlineOnly: boolean(privacy.offlineOnly, "privacy.offlineOnly", issues, false),
196
+ },
197
+ dictation: {
198
+ autoSend: boolean(dictation.autoSend, "dictation.autoSend", issues, false),
199
+ },
200
+ },
201
+ issues,
202
+ };
203
+ }
204
+
205
+ export function serializeVoiceSettings(settings: VoiceSettings): string {
206
+ return JSON.stringify(settings);
207
+ }
208
+
209
+ /**
210
+ * The routing policy these settings imply. An explicit provider becomes an override (the caller
211
+ * gets that provider's truth, including "unavailable"); `allowDownload` is the only thing that
212
+ * opens the install path. A network consent does **not** add the service recognizer to a chain:
213
+ * chains stay local, and the host selects a network provider itself.
214
+ */
215
+ export interface RoutingPolicyOptions {
216
+ /**
217
+ * The platform's routing table the settings apply to. Default `WEB_ROUTING_POLICY`; a desktop or
218
+ * Capacitor host passes its own table so the person's choices layer over the right chains.
219
+ */
220
+ readonly base?: VoiceRoutingPolicy;
221
+ }
222
+
223
+ /**
224
+ * The routing policy these settings imply, layered over `base` (by default the web table). An
225
+ * explicit provider becomes an override (the caller gets that provider's truth, including
226
+ * "unavailable") and wins over an override already in `base`; `allowDownload` is the only thing
227
+ * that opens the install path. A network consent does **not** add the service recognizer to a
228
+ * chain: chains stay local, and the host selects a network provider itself.
229
+ *
230
+ * `base` may be passed directly (`routingPolicyFor(settings, desktopPolicy)`) or as `{ base }`.
231
+ */
232
+ export function routingPolicyFor(
233
+ settings: VoiceSettings,
234
+ baseOrOptions: VoiceRoutingPolicy | RoutingPolicyOptions = {},
235
+ ): VoiceRoutingPolicy {
236
+ const base = isRoutingPolicy(baseOrOptions) ? baseOrOptions : baseOrOptions.base ?? WEB_ROUTING_POLICY;
237
+ const overrides: Partial<Record<VoiceProviderKind, string>> = { ...base.overrides };
238
+ if (settings.stt.provider) overrides.speechToText = settings.stt.provider;
239
+ if (settings.tts.provider) overrides.textToSpeech = settings.tts.provider;
240
+ return {
241
+ chains: { ...base.chains },
242
+ ...(Object.keys(overrides).length > 0 ? { overrides } : {}),
243
+ // Offline only also closes the install path: a download is a network use.
244
+ allowsOptInModelInstallation:
245
+ !settings.privacy.offlineOnly && (base.allowsOptInModelInstallation || settings.models.allowDownload),
246
+ };
247
+ }
248
+
249
+ function isRoutingPolicy(value: VoiceRoutingPolicy | RoutingPolicyOptions): value is VoiceRoutingPolicy {
250
+ return "chains" in value;
251
+ }
252
+
253
+ /** The locale to probe and start sessions with: the person's choice, else the browser's. */
254
+ export function resolveLocale(settings: VoiceSettings, kind: VoiceProviderKind, fallback: string): string {
255
+ const chosen = kind === "speechToText" ? settings.stt.locale : settings.tts.locale;
256
+ return chosen ?? fallback;
257
+ }
258
+
259
+ /** Whether the host may construct a session with the service provider. */
260
+ export function allowsNetworkSpeechToText(settings: VoiceSettings): boolean {
261
+ return !settings.privacy.offlineOnly && settings.stt.networkConsent;
262
+ }
263
+
264
+ /** Whether the host may pick a remote platform voice. */
265
+ export function allowsNetworkSynthesis(settings: VoiceSettings): boolean {
266
+ return !settings.privacy.offlineOnly && settings.tts.networkConsent;
267
+ }
268
+
269
+ /** Whether a model download may start (the person allowed it and is not offline-only). */
270
+ export function allowsModelDownload(settings: VoiceSettings): boolean {
271
+ return !settings.privacy.offlineOnly && settings.models.allowDownload;
272
+ }
273
+
274
+ /** A changed copy: `update(settings, { stt: { locale: "es-419" } })`. Sections merge shallowly. */
275
+ export function updateVoiceSettings(settings: VoiceSettings, patch: VoiceSettingsPatch): VoiceSettings {
276
+ const merged = {
277
+ schemaVersion: SETTINGS_SCHEMA_VERSION,
278
+ stt: { ...settings.stt, ...patch.stt },
279
+ tts: { ...settings.tts, ...patch.tts },
280
+ models: { ...settings.models, ...patch.models },
281
+ privacy: { ...settings.privacy, ...patch.privacy },
282
+ dictation: { ...settings.dictation, ...patch.dictation },
283
+ };
284
+ // Re-validate so an update can never store what a read would reject; `undefined` clears a field.
285
+ return validateVoiceSettings(JSON.parse(JSON.stringify(merged))).settings;
286
+ }
287
+
288
+ type Writable<T> = { -readonly [K in keyof T]?: T[K] | undefined };
289
+
290
+ export interface VoiceSettingsPatch {
291
+ readonly stt?: Writable<SpeechToTextSettings>;
292
+ readonly tts?: Writable<TextToSpeechSettings>;
293
+ readonly models?: Writable<ModelSettings>;
294
+ readonly privacy?: Writable<PrivacySettings>;
295
+ readonly dictation?: Writable<DictationSettings>;
296
+ }
297
+
298
+ /** The subset of `Storage` (localStorage, a desktop preferences file) the store needs. */
299
+ export interface VoiceSettingsStorage {
300
+ getItem(key: string): string | null;
301
+ setItem(key: string, value: string): void;
302
+ }
303
+
304
+ export const VOICE_SETTINGS_STORAGE_KEY = "adea:voice-settings:v2";
305
+
306
+ export interface VoiceSettingsStore {
307
+ /** The current settings and what the last read had to drop. */
308
+ read(): ReadSettingsResult;
309
+ /** Validates and persists; returns what was stored. */
310
+ write(settings: VoiceSettings): VoiceSettings;
311
+ update(patch: VoiceSettingsPatch): VoiceSettings;
312
+ /** Called after every write from this store. Returns an unsubscribe. */
313
+ subscribe(listener: (settings: VoiceSettings) => void): () => void;
314
+ }
315
+
316
+ /**
317
+ * A per-device settings store over any `getItem`/`setItem` storage. Reads never throw (a broken
318
+ * or blocked storage reads as defaults with an issue); writes that fail report through `onError`
319
+ * and keep the in-memory value, so the UI stays consistent for this session.
320
+ */
321
+ export function createVoiceSettingsStore(
322
+ storage: VoiceSettingsStorage | undefined,
323
+ options: { readonly key?: string; readonly onError?: (error: unknown) => void } = {},
324
+ ): VoiceSettingsStore {
325
+ const key = options.key ?? VOICE_SETTINGS_STORAGE_KEY;
326
+ const listeners = new Set<(settings: VoiceSettings) => void>();
327
+ let cached: ReadSettingsResult | undefined;
328
+ const load = (): ReadSettingsResult => {
329
+ if (cached) return cached;
330
+ let raw: string | null = null;
331
+ try {
332
+ raw = storage?.getItem(key) ?? null;
333
+ } catch (error) {
334
+ cached = { settings: defaultSettings(), issues: [`voice settings could not be read: ${String(error)}`] };
335
+ return cached;
336
+ }
337
+ cached = readVoiceSettings(raw);
338
+ return cached;
339
+ };
340
+ const store: VoiceSettingsStore = {
341
+ read: load,
342
+ write(settings) {
343
+ const validated = validateVoiceSettings(JSON.parse(JSON.stringify(settings)));
344
+ cached = { settings: validated.settings, issues: [] };
345
+ try {
346
+ storage?.setItem(key, serializeVoiceSettings(validated.settings));
347
+ } catch (error) {
348
+ options.onError?.(error);
349
+ }
350
+ for (const listener of listeners) listener(validated.settings);
351
+ return validated.settings;
352
+ },
353
+ update(patch) {
354
+ return store.write(updateVoiceSettings(load().settings, patch));
355
+ },
356
+ subscribe(listener) {
357
+ listeners.add(listener);
358
+ return () => listeners.delete(listener);
359
+ },
360
+ };
361
+ return store;
362
+ }
363
+
364
+ /**
365
+ * Folds an app's pre-Voice dictation preferences (a dictation language, an auto-send switch) into
366
+ * fresh settings, once: a value already in `settings` wins.
367
+ */
368
+ export function withLegacyDictationPreferences(
369
+ settings: VoiceSettings,
370
+ legacy: { readonly locale?: string | undefined; readonly autoSend?: boolean | undefined },
371
+ ): VoiceSettings {
372
+ return updateVoiceSettings(settings, {
373
+ stt: { locale: settings.stt.locale ?? (legacy.locale?.trim() || undefined) },
374
+ dictation: { autoSend: settings.dictation.autoSend || legacy.autoSend === true },
375
+ });
376
+ }
377
+
378
+ /** A settings file that cannot be used at all, rather than one field being dropped. */
379
+ export function assertUsableSettings(result: ReadSettingsResult): VoiceSettings {
380
+ if (result.issues.length > 0) {
381
+ throw new VoiceError("failed", `voice settings: ${result.issues.join("; ")}`);
382
+ }
383
+ return result.settings;
384
+ }
385
+
386
+ function section(value: unknown, name: string, issues: string[]): Record<string, unknown> {
387
+ if (value === undefined) return {};
388
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
389
+ issues.push(`${name} must be an object; using its defaults`);
390
+ return {};
391
+ }
392
+ return value as Record<string, unknown>;
393
+ }
394
+
395
+ function boolean(value: unknown, path: string, issues: string[], fallback: boolean): boolean {
396
+ if (value === undefined) return fallback;
397
+ if (typeof value !== "boolean") {
398
+ issues.push(`${path} must be a boolean; using ${fallback}`);
399
+ return fallback;
400
+ }
401
+ return value;
402
+ }
403
+
404
+ function unknownKeys(object: Record<string, unknown>, known: readonly string[], prefix: string, issues: string[]): void {
405
+ for (const key of Object.keys(object)) {
406
+ if (!known.includes(key)) issues.push(`${prefix}${key} is not a known setting; ignoring it`);
407
+ }
408
+ }
409
+
410
+ function optionalString<K extends string>(
411
+ value: unknown,
412
+ path: string,
413
+ issues: string[],
414
+ key: K,
415
+ maxLength: number,
416
+ ): Partial<Record<K, string>> {
417
+ if (value === undefined) return {};
418
+ if (typeof value !== "string" || value.trim() === "") {
419
+ issues.push(`${path} must be a non-empty string; ignoring it`);
420
+ return {};
421
+ }
422
+ const trimmed = value.trim();
423
+ if (trimmed.length > maxLength) {
424
+ issues.push(`${path} is longer than ${maxLength} characters; ignoring it`);
425
+ return {};
426
+ }
427
+ return { [key]: trimmed } as Partial<Record<K, string>>;
428
+ }
429
+
430
+ /** A BCP-47 tag, stored in its canonical form (`en-us` becomes `en-US`). */
431
+ function optionalLocale(value: unknown, path: string, issues: string[]): { locale?: string } {
432
+ const read = optionalString(value, path, issues, "locale", MAX_LENGTH.locale);
433
+ if (read.locale === undefined) return {};
434
+ try {
435
+ const [canonical] = Intl.getCanonicalLocales(read.locale);
436
+ if (canonical !== undefined) return { locale: canonical };
437
+ } catch {
438
+ // RangeError: not a well-formed language tag
439
+ }
440
+ issues.push(`${path} "${read.locale}" is not a valid BCP-47 language tag; ignoring it`);
441
+ return {};
442
+ }
443
+
444
+ function optionalRate(value: unknown, path: string, issues: string[]): { rate?: number } {
445
+ if (value === undefined) return {};
446
+ if (typeof value !== "number" || !Number.isFinite(value) || value < RATE_RANGE.min || value > RATE_RANGE.max) {
447
+ issues.push(`${path} must be a number from ${RATE_RANGE.min} to ${RATE_RANGE.max}; ignoring it`);
448
+ return {};
449
+ }
450
+ return { rate: value };
451
+ }
452
+
453
+ /** Absolute paths only (POSIX or Windows), deduplicated, bounded. */
454
+ function folderList(value: unknown, path: string, issues: string[]): readonly string[] {
455
+ if (value === undefined) return [];
456
+ if (!Array.isArray(value)) {
457
+ issues.push(`${path} must be a list of folders; ignoring it`);
458
+ return [];
459
+ }
460
+ const folders: string[] = [];
461
+ for (const entry of value) {
462
+ if (typeof entry !== "string" || entry.trim() === "" || entry.length > MAX_LENGTH.folder) {
463
+ issues.push(`${path} has an entry that is not a folder path; ignoring it`);
464
+ continue;
465
+ }
466
+ const trimmed = entry.trim();
467
+ if (!/^(\/|[A-Za-z]:[\\/]|\\\\)/.test(trimmed) || trimmed.includes("\0")) {
468
+ issues.push(`${path} "${trimmed}" is not an absolute path; ignoring it`);
469
+ continue;
470
+ }
471
+ if (!folders.includes(trimmed)) folders.push(trimmed);
472
+ }
473
+ if (folders.length > MAX_FOLDERS) {
474
+ issues.push(`${path} keeps the first ${MAX_FOLDERS} folders`);
475
+ return folders.slice(0, MAX_FOLDERS);
476
+ }
477
+ return folders;
478
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@adea-ai/voice/web`: the browser providers. Every browser global is injectable, so the policy,
3
+ * routing and session lifecycles run under `bun test` with no browser at all.
4
+ *
5
+ * - on-device dictation with an explicit local/network policy (`browserRecognitionLocal`,
6
+ * `browserRecognitionService`);
7
+ * - Phonon TTS on the visitor's device (`PhononProvider`), English only;
8
+ * - platform voices as the multilingual fallback (`SystemVoiceProvider`);
9
+ * - the engine-agnostic turn manager (`VoiceTurnManager`).
10
+ */
11
+ export * from "./stt/speech-recognition";
12
+ export * from "./tts/phonon";
13
+ export * from "./tts/locale-match";
14
+ export * from "./tts/player";
15
+ export * from "./tts/system-voices";
16
+ export * from "./turns";