@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,9 @@
1
+ /** True when `bytes` starts like a Mach-O image or a universal file. */
2
+ export declare function isMachO(bytes: Uint8Array): boolean;
3
+ /**
4
+ * The sha256 (hex) of a Mach-O file with its code signature left out, or `undefined` for a file
5
+ * this cannot digest (not Mach-O, 32-bit, big-endian, or malformed).
6
+ */
7
+ export declare function machoCodeDigest(bytes: Uint8Array): string | undefined;
8
+ /** `machoCodeDigest` of a file on disk. */
9
+ export declare function machoCodeDigestFile(path: string): string | undefined;
@@ -0,0 +1,47 @@
1
+ import {
2
+ normalizeVoiceErrorCode2
3
+ } from "./index-tvz9s9nz.js";
4
+
5
+ // src/contract/wire.ts
6
+ var WIRE_VERSION2 = 1;
7
+ var TURN_WIRE_MINOR2 = 2;
8
+ var RELEASE_ASSETS_WIRE_MINOR2 = 3;
9
+ var CONTRACT_MAJOR2 = 1;
10
+ var MAX_WIRE_LINE_BYTES2 = 1e6;
11
+ function isTurnTerminal2(event) {
12
+ return event.event === "turn-error" || event.event === "turn-state" && event.state === "ended";
13
+ }
14
+ function parseWireLine2(line) {
15
+ if (line.length === 0 || line.length > MAX_WIRE_LINE_BYTES2)
16
+ return;
17
+ let value;
18
+ try {
19
+ value = JSON.parse(line);
20
+ } catch {
21
+ return;
22
+ }
23
+ if (value === null || typeof value !== "object" || Array.isArray(value))
24
+ return;
25
+ const object = value;
26
+ if (typeof object.event !== "string")
27
+ return;
28
+ if (object.event === "error" || object.event === "speech-error" || object.event === "turn-error") {
29
+ return { ...object, code: normalizeVoiceErrorCode2(object.code) };
30
+ }
31
+ return object;
32
+ }
33
+ function encodeWireCommand2(command) {
34
+ return JSON.stringify({ ...command, command: command.cmd });
35
+ }
36
+ function correlationId2(event) {
37
+ if (event.event === "voice")
38
+ return event.requestId;
39
+ if ("id" in event && typeof event.id === "string")
40
+ return event.id;
41
+ return;
42
+ }
43
+ function isCompatibleHandshake2(event) {
44
+ return event.wire === WIRE_VERSION2 && event.contractMajor === CONTRACT_MAJOR2;
45
+ }
46
+
47
+ export { WIRE_VERSION2, TURN_WIRE_MINOR2, RELEASE_ASSETS_WIRE_MINOR2, CONTRACT_MAJOR2, MAX_WIRE_LINE_BYTES2, isTurnTerminal2, parseWireLine2, encodeWireCommand2, correlationId2, isCompatibleHandshake2 };
@@ -0,0 +1,295 @@
1
+ import {
2
+ WEB_ROUTING_POLICY2
3
+ } from "./index-ght8wwpd.js";
4
+ import {
5
+ VoiceError2
6
+ } from "./index-tvz9s9nz.js";
7
+
8
+ // src/settings/settings.ts
9
+ var SETTINGS_SCHEMA_VERSION2 = 2;
10
+ var MIGRATABLE_VERSIONS = [1];
11
+ var DEFAULT_VOICE_SETTINGS2 = Object.freeze({
12
+ schemaVersion: SETTINGS_SCHEMA_VERSION2,
13
+ stt: Object.freeze({ networkConsent: false }),
14
+ tts: Object.freeze({ networkConsent: false }),
15
+ models: Object.freeze({ allowDownload: false, cache: true, folders: Object.freeze([]) }),
16
+ privacy: Object.freeze({ offlineOnly: false }),
17
+ dictation: Object.freeze({ autoSend: false })
18
+ });
19
+ function defaultSettings() {
20
+ return {
21
+ schemaVersion: DEFAULT_VOICE_SETTINGS2.schemaVersion,
22
+ stt: { ...DEFAULT_VOICE_SETTINGS2.stt },
23
+ tts: { ...DEFAULT_VOICE_SETTINGS2.tts },
24
+ models: { ...DEFAULT_VOICE_SETTINGS2.models, folders: [] },
25
+ privacy: { ...DEFAULT_VOICE_SETTINGS2.privacy },
26
+ dictation: { ...DEFAULT_VOICE_SETTINGS2.dictation }
27
+ };
28
+ }
29
+ var MAX_LENGTH = { provider: 128, locale: 64, voice: 256, model: 256, folder: 1024 };
30
+ var MAX_FOLDERS = 16;
31
+ var RATE_RANGE = { min: 0.5, max: 2 };
32
+ var KNOWN_KEYS = {
33
+ root: ["schemaVersion", "stt", "tts", "models", "privacy", "dictation"],
34
+ stt: ["provider", "locale", "networkConsent", "model"],
35
+ tts: ["provider", "locale", "voice", "networkConsent", "rate"],
36
+ models: ["allowDownload", "cache", "folders"],
37
+ privacy: ["offlineOnly"],
38
+ dictation: ["autoSend"]
39
+ };
40
+ function readVoiceSettings2(raw) {
41
+ if (raw === null || raw === undefined || raw.trim() === "") {
42
+ return { settings: defaultSettings(), issues: [] };
43
+ }
44
+ let parsed;
45
+ try {
46
+ parsed = JSON.parse(raw);
47
+ } catch (error) {
48
+ return {
49
+ settings: defaultSettings(),
50
+ issues: [`stored settings are not JSON: ${error instanceof Error ? error.message : String(error)}`]
51
+ };
52
+ }
53
+ return validateVoiceSettings2(parsed);
54
+ }
55
+ function validateVoiceSettings2(raw) {
56
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
57
+ return { settings: defaultSettings(), issues: ["settings must be an object"] };
58
+ }
59
+ const issues = [];
60
+ const object = raw;
61
+ const version = object.schemaVersion;
62
+ const migrating = MIGRATABLE_VERSIONS.includes(version);
63
+ if (version !== undefined && version !== SETTINGS_SCHEMA_VERSION2 && !migrating) {
64
+ issues.push(`schemaVersion ${String(version)} is not ${SETTINGS_SCHEMA_VERSION2}; using defaults`);
65
+ return { settings: defaultSettings(), issues };
66
+ }
67
+ unknownKeys(object, KNOWN_KEYS.root, "", issues);
68
+ const stt = section(object.stt, "stt", issues);
69
+ const tts = section(object.tts, "tts", issues);
70
+ const models = section(object.models, "models", issues);
71
+ const privacy = section(object.privacy, "privacy", issues);
72
+ const dictation = section(object.dictation, "dictation", issues);
73
+ unknownKeys(stt, KNOWN_KEYS.stt, "stt.", issues);
74
+ unknownKeys(tts, KNOWN_KEYS.tts, "tts.", issues);
75
+ unknownKeys(models, KNOWN_KEYS.models, "models.", issues);
76
+ unknownKeys(privacy, KNOWN_KEYS.privacy, "privacy.", issues);
77
+ unknownKeys(dictation, KNOWN_KEYS.dictation, "dictation.", issues);
78
+ const sttConsent = boolean(stt.networkConsent, "stt.networkConsent", issues, false);
79
+ const ttsConsent = boolean(tts.networkConsent, "tts.networkConsent", issues, false);
80
+ return {
81
+ settings: {
82
+ schemaVersion: SETTINGS_SCHEMA_VERSION2,
83
+ stt: {
84
+ networkConsent: sttConsent,
85
+ ...optionalString(stt.provider, "stt.provider", issues, "provider", MAX_LENGTH.provider),
86
+ ...optionalLocale(stt.locale, "stt.locale", issues),
87
+ ...optionalString(stt.model, "stt.model", issues, "model", MAX_LENGTH.model)
88
+ },
89
+ tts: {
90
+ networkConsent: ttsConsent,
91
+ ...optionalString(tts.provider, "tts.provider", issues, "provider", MAX_LENGTH.provider),
92
+ ...optionalLocale(tts.locale, "tts.locale", issues),
93
+ ...optionalString(tts.voice, "tts.voice", issues, "voice", MAX_LENGTH.voice),
94
+ ...optionalRate(tts.rate, "tts.rate", issues)
95
+ },
96
+ models: {
97
+ allowDownload: boolean(models.allowDownload, "models.allowDownload", issues, false),
98
+ cache: boolean(models.cache, "models.cache", issues, true),
99
+ folders: folderList(models.folders, "models.folders", issues)
100
+ },
101
+ privacy: {
102
+ offlineOnly: boolean(privacy.offlineOnly, "privacy.offlineOnly", issues, false)
103
+ },
104
+ dictation: {
105
+ autoSend: boolean(dictation.autoSend, "dictation.autoSend", issues, false)
106
+ }
107
+ },
108
+ issues
109
+ };
110
+ }
111
+ function serializeVoiceSettings2(settings) {
112
+ return JSON.stringify(settings);
113
+ }
114
+ function routingPolicyFor2(settings, baseOrOptions = {}) {
115
+ const base = isRoutingPolicy(baseOrOptions) ? baseOrOptions : baseOrOptions.base ?? WEB_ROUTING_POLICY2;
116
+ const overrides = { ...base.overrides };
117
+ if (settings.stt.provider)
118
+ overrides.speechToText = settings.stt.provider;
119
+ if (settings.tts.provider)
120
+ overrides.textToSpeech = settings.tts.provider;
121
+ return {
122
+ chains: { ...base.chains },
123
+ ...Object.keys(overrides).length > 0 ? { overrides } : {},
124
+ allowsOptInModelInstallation: !settings.privacy.offlineOnly && (base.allowsOptInModelInstallation || settings.models.allowDownload)
125
+ };
126
+ }
127
+ function isRoutingPolicy(value) {
128
+ return "chains" in value;
129
+ }
130
+ function resolveLocale2(settings, kind, fallback) {
131
+ const chosen = kind === "speechToText" ? settings.stt.locale : settings.tts.locale;
132
+ return chosen ?? fallback;
133
+ }
134
+ function allowsNetworkSpeechToText2(settings) {
135
+ return !settings.privacy.offlineOnly && settings.stt.networkConsent;
136
+ }
137
+ function allowsNetworkSynthesis2(settings) {
138
+ return !settings.privacy.offlineOnly && settings.tts.networkConsent;
139
+ }
140
+ function allowsModelDownload2(settings) {
141
+ return !settings.privacy.offlineOnly && settings.models.allowDownload;
142
+ }
143
+ function updateVoiceSettings2(settings, patch) {
144
+ const merged = {
145
+ schemaVersion: SETTINGS_SCHEMA_VERSION2,
146
+ stt: { ...settings.stt, ...patch.stt },
147
+ tts: { ...settings.tts, ...patch.tts },
148
+ models: { ...settings.models, ...patch.models },
149
+ privacy: { ...settings.privacy, ...patch.privacy },
150
+ dictation: { ...settings.dictation, ...patch.dictation }
151
+ };
152
+ return validateVoiceSettings2(JSON.parse(JSON.stringify(merged))).settings;
153
+ }
154
+ var VOICE_SETTINGS_STORAGE_KEY2 = "adea:voice-settings:v2";
155
+ function createVoiceSettingsStore2(storage, options = {}) {
156
+ const key = options.key ?? VOICE_SETTINGS_STORAGE_KEY2;
157
+ const listeners = new Set;
158
+ let cached;
159
+ const load = () => {
160
+ if (cached)
161
+ return cached;
162
+ let raw = null;
163
+ try {
164
+ raw = storage?.getItem(key) ?? null;
165
+ } catch (error) {
166
+ cached = { settings: defaultSettings(), issues: [`voice settings could not be read: ${String(error)}`] };
167
+ return cached;
168
+ }
169
+ cached = readVoiceSettings2(raw);
170
+ return cached;
171
+ };
172
+ const store = {
173
+ read: load,
174
+ write(settings) {
175
+ const validated = validateVoiceSettings2(JSON.parse(JSON.stringify(settings)));
176
+ cached = { settings: validated.settings, issues: [] };
177
+ try {
178
+ storage?.setItem(key, serializeVoiceSettings2(validated.settings));
179
+ } catch (error) {
180
+ options.onError?.(error);
181
+ }
182
+ for (const listener of listeners)
183
+ listener(validated.settings);
184
+ return validated.settings;
185
+ },
186
+ update(patch) {
187
+ return store.write(updateVoiceSettings2(load().settings, patch));
188
+ },
189
+ subscribe(listener) {
190
+ listeners.add(listener);
191
+ return () => listeners.delete(listener);
192
+ }
193
+ };
194
+ return store;
195
+ }
196
+ function withLegacyDictationPreferences2(settings, legacy) {
197
+ return updateVoiceSettings2(settings, {
198
+ stt: { locale: settings.stt.locale ?? (legacy.locale?.trim() || undefined) },
199
+ dictation: { autoSend: settings.dictation.autoSend || legacy.autoSend === true }
200
+ });
201
+ }
202
+ function assertUsableSettings2(result) {
203
+ if (result.issues.length > 0) {
204
+ throw new VoiceError2("failed", `voice settings: ${result.issues.join("; ")}`);
205
+ }
206
+ return result.settings;
207
+ }
208
+ function section(value, name, issues) {
209
+ if (value === undefined)
210
+ return {};
211
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
212
+ issues.push(`${name} must be an object; using its defaults`);
213
+ return {};
214
+ }
215
+ return value;
216
+ }
217
+ function boolean(value, path, issues, fallback) {
218
+ if (value === undefined)
219
+ return fallback;
220
+ if (typeof value !== "boolean") {
221
+ issues.push(`${path} must be a boolean; using ${fallback}`);
222
+ return fallback;
223
+ }
224
+ return value;
225
+ }
226
+ function unknownKeys(object, known, prefix, issues) {
227
+ for (const key of Object.keys(object)) {
228
+ if (!known.includes(key))
229
+ issues.push(`${prefix}${key} is not a known setting; ignoring it`);
230
+ }
231
+ }
232
+ function optionalString(value, path, issues, key, maxLength) {
233
+ if (value === undefined)
234
+ return {};
235
+ if (typeof value !== "string" || value.trim() === "") {
236
+ issues.push(`${path} must be a non-empty string; ignoring it`);
237
+ return {};
238
+ }
239
+ const trimmed = value.trim();
240
+ if (trimmed.length > maxLength) {
241
+ issues.push(`${path} is longer than ${maxLength} characters; ignoring it`);
242
+ return {};
243
+ }
244
+ return { [key]: trimmed };
245
+ }
246
+ function optionalLocale(value, path, issues) {
247
+ const read = optionalString(value, path, issues, "locale", MAX_LENGTH.locale);
248
+ if (read.locale === undefined)
249
+ return {};
250
+ try {
251
+ const [canonical] = Intl.getCanonicalLocales(read.locale);
252
+ if (canonical !== undefined)
253
+ return { locale: canonical };
254
+ } catch {}
255
+ issues.push(`${path} "${read.locale}" is not a valid BCP-47 language tag; ignoring it`);
256
+ return {};
257
+ }
258
+ function optionalRate(value, path, issues) {
259
+ if (value === undefined)
260
+ return {};
261
+ if (typeof value !== "number" || !Number.isFinite(value) || value < RATE_RANGE.min || value > RATE_RANGE.max) {
262
+ issues.push(`${path} must be a number from ${RATE_RANGE.min} to ${RATE_RANGE.max}; ignoring it`);
263
+ return {};
264
+ }
265
+ return { rate: value };
266
+ }
267
+ function folderList(value, path, issues) {
268
+ if (value === undefined)
269
+ return [];
270
+ if (!Array.isArray(value)) {
271
+ issues.push(`${path} must be a list of folders; ignoring it`);
272
+ return [];
273
+ }
274
+ const folders = [];
275
+ for (const entry of value) {
276
+ if (typeof entry !== "string" || entry.trim() === "" || entry.length > MAX_LENGTH.folder) {
277
+ issues.push(`${path} has an entry that is not a folder path; ignoring it`);
278
+ continue;
279
+ }
280
+ const trimmed = entry.trim();
281
+ if (!/^(\/|[A-Za-z]:[\\/]|\\\\)/.test(trimmed) || trimmed.includes("\x00")) {
282
+ issues.push(`${path} "${trimmed}" is not an absolute path; ignoring it`);
283
+ continue;
284
+ }
285
+ if (!folders.includes(trimmed))
286
+ folders.push(trimmed);
287
+ }
288
+ if (folders.length > MAX_FOLDERS) {
289
+ issues.push(`${path} keeps the first ${MAX_FOLDERS} folders`);
290
+ return folders.slice(0, MAX_FOLDERS);
291
+ }
292
+ return folders;
293
+ }
294
+
295
+ export { SETTINGS_SCHEMA_VERSION2, DEFAULT_VOICE_SETTINGS2, readVoiceSettings2, validateVoiceSettings2, serializeVoiceSettings2, routingPolicyFor2, resolveLocale2, allowsNetworkSpeechToText2, allowsNetworkSynthesis2, allowsModelDownload2, updateVoiceSettings2, VOICE_SETTINGS_STORAGE_KEY2, createVoiceSettingsStore2, withLegacyDictationPreferences2, assertUsableSettings2 };
@@ -0,0 +1,156 @@
1
+ // src/contract/contract.ts
2
+ var VOICE_CONTRACT2 = { major: 1, minor: 0 };
3
+ function isCompatibleContract2(candidate, supported = VOICE_CONTRACT2) {
4
+ return candidate.major === supported.major;
5
+ }
6
+ var VOICE_CAPABILITY_BITS2 = [
7
+ "streamingPartials",
8
+ "trueCancellation",
9
+ "modelInstallation",
10
+ "localeSelection",
11
+ "voiceSelection",
12
+ "utteranceQueueing",
13
+ "wordBoundaryPause"
14
+ ];
15
+ function capabilitiesToMask2(capabilities) {
16
+ let mask = 0;
17
+ VOICE_CAPABILITY_BITS2.forEach((name, bit) => {
18
+ if (capabilities[name] === true)
19
+ mask |= 1 << bit;
20
+ });
21
+ return mask;
22
+ }
23
+ function capabilitiesFromMask2(mask) {
24
+ const value = Number.isInteger(mask) && mask > 0 ? mask : 0;
25
+ const capabilities = {};
26
+ VOICE_CAPABILITY_BITS2.forEach((name, bit) => {
27
+ capabilities[name] = (value & 1 << bit) !== 0;
28
+ });
29
+ return capabilities;
30
+ }
31
+ var AVAILABLE2 = { status: "available" };
32
+ function availableWithMatch2(match, message) {
33
+ return message === undefined ? { status: "available", match } : { status: "available", match, message };
34
+ }
35
+ function isLanguageOnly2(availability) {
36
+ return availability.status === "available" && availability.match === "language";
37
+ }
38
+ function unavailable2(reason, message, remedy) {
39
+ return { status: "unavailable", unavailable: remedy ? { reason, message, remedy } : { reason, message } };
40
+ }
41
+ function isAvailable2(availability) {
42
+ return availability.status === "available";
43
+ }
44
+ function requiresModelInstallation2(route) {
45
+ const reason = route.availability.status === "unavailable" ? route.availability.unavailable.reason : undefined;
46
+ return reason === "modelNotInstalled" || reason === "modelDownloadDisabled";
47
+ }
48
+ var ACTIONABILITY = {
49
+ modelNotInstalled: 100,
50
+ modelDownloadDisabled: 95,
51
+ unsupportedLocale: 90,
52
+ unsupportedOperatingSystem: 80,
53
+ unsupportedDevice: 70,
54
+ permissionDenied: 60,
55
+ licenseNotAccepted: 50,
56
+ contractIncompatible: 40,
57
+ engineFailed: 30,
58
+ networkRequired: 20,
59
+ providerNotRegistered: 10,
60
+ unsupportedPlatform: 0
61
+ };
62
+ var WEB_ROUTING_POLICY2 = {
63
+ chains: {
64
+ speechToText: ["web.speech-recognition-local"],
65
+ textToSpeech: ["web.phonon", "web.system-voices"]
66
+ },
67
+ allowsOptInModelInstallation: false
68
+ };
69
+ async function route2(request) {
70
+ const policy = request.policy ?? WEB_ROUTING_POLICY2;
71
+ const override = policy.overrides?.[request.kind];
72
+ const configured = override ? [override] : policy.chains[request.kind];
73
+ if (configured === undefined) {
74
+ return {
75
+ kind: request.kind,
76
+ locale: request.locale,
77
+ route: null,
78
+ candidates: [],
79
+ missing: [],
80
+ availability: unavailable2("unsupportedPlatform", `no ${request.kind} provider is defined for this platform`, {
81
+ kind: "chooseAnotherProvider",
82
+ detail: "run on a platform the Voice SDK has a provider for"
83
+ })
84
+ };
85
+ }
86
+ const chain = configured;
87
+ const byId = new Map(request.providers.map((provider) => [provider.descriptor.id, provider]));
88
+ const candidates = [];
89
+ const missing = [];
90
+ for (const id of chain) {
91
+ const provider = byId.get(id);
92
+ if (!provider) {
93
+ missing.push(id);
94
+ continue;
95
+ }
96
+ candidates.push({
97
+ kind: request.kind,
98
+ locale: request.locale,
99
+ descriptor: provider.descriptor,
100
+ availability: await evaluate(provider, request.locale, policy)
101
+ });
102
+ }
103
+ const selection = candidates.find((candidate) => isAvailable2(candidate.availability) || policy.allowsOptInModelInstallation && requiresModelInstallation2(candidate));
104
+ const availability = selection ? selection.availability : mostActionable(candidates) ?? unavailable2("providerNotRegistered", `this build registers no ${request.kind} provider from its routing chain (${chain.join(", ")})`, { kind: "chooseAnotherProvider", detail: "install a build that includes the provider" });
105
+ return {
106
+ kind: request.kind,
107
+ locale: request.locale,
108
+ route: selection ?? null,
109
+ candidates,
110
+ missing,
111
+ availability
112
+ };
113
+ }
114
+ async function evaluate(provider, locale, policy) {
115
+ const descriptor = provider.descriptor;
116
+ if (descriptor.execution === "network") {
117
+ return unavailable2("networkRequired", `${descriptor.displayName} requires a network path; the Voice SDK is offline-only`);
118
+ }
119
+ if (!isCompatibleContract2(descriptor.contract)) {
120
+ return unavailable2("contractIncompatible", `${descriptor.displayName} speaks contract ${descriptor.contract.major}.${descriptor.contract.minor}; this SDK speaks ${VOICE_CONTRACT2.major}.${VOICE_CONTRACT2.minor}`, { kind: "chooseAnotherProvider", detail: "update the provider or the SDK" });
121
+ }
122
+ let reported;
123
+ try {
124
+ reported = await provider.availability(locale);
125
+ } catch (error) {
126
+ return unavailable2("engineFailed", `${descriptor.displayName} failed while being probed: ${error instanceof Error ? error.message : String(error)}`);
127
+ }
128
+ if (reported.status === "unavailable" && reported.unavailable.reason === "modelNotInstalled" && !policy.allowsOptInModelInstallation) {
129
+ return unavailable2("modelDownloadDisabled", reported.unavailable.message, {
130
+ kind: "installModel",
131
+ detail: "Download the language in Voice settings."
132
+ });
133
+ }
134
+ return reported;
135
+ }
136
+ function mostActionable(candidates) {
137
+ let best;
138
+ for (const candidate of candidates) {
139
+ if (best === undefined) {
140
+ best = candidate;
141
+ continue;
142
+ }
143
+ const current = actionability(candidate.availability);
144
+ const incumbent = actionability(best.availability);
145
+ if (current > incumbent)
146
+ best = candidate;
147
+ }
148
+ return best?.availability;
149
+ }
150
+ function actionability(availability) {
151
+ if (availability.status === "available")
152
+ return Number.MAX_SAFE_INTEGER;
153
+ return ACTIONABILITY[availability.unavailable.reason] ?? -1;
154
+ }
155
+
156
+ export { VOICE_CONTRACT2, isCompatibleContract2, VOICE_CAPABILITY_BITS2, capabilitiesToMask2, capabilitiesFromMask2, AVAILABLE2, availableWithMatch2, isLanguageOnly2, unavailable2, isAvailable2, requiresModelInstallation2, WEB_ROUTING_POLICY2, route2 };