@adea-ai/app-framework 0.47.0 → 0.48.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.
@@ -0,0 +1,127 @@
1
+ /**
2
+ * The framework's voice service boundary: the names, inputs and events a renderer and a desktop
3
+ * shell exchange, whatever transport carries them (the framework service registry in Cortana,
4
+ * Adea's own command channel). The speech engines, routing, error vocabulary and privacy rules
5
+ * are `@adea-ai/voice`'s; this file only fixes the shape of the conversation and validates every
6
+ * value that crosses it.
7
+ */
8
+ import { type VoiceErrorCode } from '@adea-ai/voice/contract';
9
+ import { type VoiceSettings } from '@adea-ai/voice/settings';
10
+ export declare const VOICE_SERVICES: {
11
+ readonly capabilities: 'voice.capabilities';
12
+ readonly permission: 'voice.permission';
13
+ readonly dictateStart: 'voice.dictate-start';
14
+ readonly dictateEnd: 'voice.dictate-end';
15
+ readonly dictateCancel: 'voice.dictate-cancel';
16
+ readonly speak: 'voice.speak';
17
+ readonly speakStop: 'voice.speak-stop';
18
+ readonly voices: 'voice.voices';
19
+ readonly locales: 'voice.locales';
20
+ readonly installAssets: 'voice.install-assets';
21
+ readonly installCancel: 'voice.install-cancel';
22
+ readonly releaseAssets: 'voice.release-assets';
23
+ readonly events: 'voice.events';
24
+ };
25
+ export type VoiceServiceName = (typeof VOICE_SERVICES)[keyof typeof VOICE_SERVICES];
26
+ /** The system voice reading an utterance aloud, as the helper resolved it. */
27
+ export type VoiceSpeechVoice = Readonly<{
28
+ /** The voice identifier (what the settings' `tts.voice` can pin). */
29
+ id: string;
30
+ name: string;
31
+ /** The voice's own locale, e.g. `es-MX` when `es-419` was asked for. */
32
+ language: string;
33
+ /** The same value as `language`, as the voice list items name it (helpers after 0.3.0). */
34
+ locale?: string;
35
+ quality: 'default' | 'enhanced' | 'premium' | 'unknown';
36
+ }>;
37
+ /** Pushed from the shell to the renderer through `voice.events` (a long poll with a cursor). */
38
+ export type VoiceEvent = {
39
+ readonly type: 'dictation-partial';
40
+ readonly id: string;
41
+ readonly text: string;
42
+ } | {
43
+ readonly type: 'dictation-final';
44
+ readonly id: string;
45
+ readonly text: string;
46
+ } | {
47
+ readonly type: 'dictation-failed';
48
+ readonly id: string;
49
+ readonly code: VoiceErrorCode;
50
+ readonly message: string;
51
+ } | {
52
+ readonly type: 'dictation-cancelled';
53
+ readonly id: string;
54
+ } | {
55
+ readonly type: 'speech-started';
56
+ readonly id: string;
57
+ /** The voice speaking, when the helper reports it (helpers after 0.2.0). */
58
+ readonly voice?: VoiceSpeechVoice;
59
+ } | {
60
+ readonly type: 'speech-finished';
61
+ readonly id: string;
62
+ } | {
63
+ readonly type: 'speech-cancelled';
64
+ readonly id: string;
65
+ } | {
66
+ readonly type: 'speech-failed';
67
+ readonly id: string;
68
+ readonly code: VoiceErrorCode;
69
+ readonly message: string;
70
+ } | {
71
+ readonly type: 'install-progress';
72
+ readonly id: string;
73
+ readonly fraction: number | null;
74
+ } | {
75
+ readonly type: 'install-finished';
76
+ readonly id: string;
77
+ } | {
78
+ readonly type: 'install-failed';
79
+ readonly id: string;
80
+ readonly code: VoiceErrorCode;
81
+ readonly message: string;
82
+ };
83
+ export type VoiceEventBatch = Readonly<{
84
+ cursor: number;
85
+ events: readonly VoiceEvent[];
86
+ }>;
87
+ /** Largest text one read-aloud request may carry (about 30 minutes of speech). */
88
+ export declare const MAX_SPEAK_CHARACTERS = 20000;
89
+ /** A long poll returns after this long with no events, so a transport never idles out. */
90
+ export declare const EVENTS_WAIT_MS = 25000;
91
+ export declare const parseVoiceInput: {
92
+ capabilities(value: unknown): {
93
+ settings: VoiceSettings;
94
+ locale?: string;
95
+ };
96
+ permission(value: unknown): {
97
+ request: boolean;
98
+ };
99
+ dictateStart(value: unknown): {
100
+ settings: VoiceSettings;
101
+ locale?: string;
102
+ };
103
+ dictation(value: unknown): {
104
+ id: string;
105
+ };
106
+ speak(value: unknown): {
107
+ settings: VoiceSettings;
108
+ text: string;
109
+ locale?: string;
110
+ queue: 'replace' | 'after-current';
111
+ };
112
+ none(value: unknown): null;
113
+ voices(value: unknown): {
114
+ settings: VoiceSettings;
115
+ locale?: string;
116
+ };
117
+ installAssets(value: unknown): {
118
+ locale: string;
119
+ };
120
+ /** Removing a model names one locale, like an install. */
121
+ releaseAssets(value: unknown): {
122
+ locale: string;
123
+ };
124
+ events(value: unknown): {
125
+ after: number;
126
+ };
127
+ };
@@ -0,0 +1,120 @@
1
+ import { VoiceError } from "@adea-ai/voice/contract";
2
+ import { validateVoiceSettings } from "@adea-ai/voice/settings";
3
+ // src/voice/voice-protocol.ts
4
+ /**
5
+ * The framework's voice service boundary: the names, inputs and events a renderer and a desktop
6
+ * shell exchange, whatever transport carries them (the framework service registry in Cortana,
7
+ * Adea's own command channel). The speech engines, routing, error vocabulary and privacy rules
8
+ * are `@adea-ai/voice`'s; this file only fixes the shape of the conversation and validates every
9
+ * value that crosses it.
10
+ */
11
+ var VOICE_SERVICES = {
12
+ capabilities: "voice.capabilities",
13
+ permission: "voice.permission",
14
+ dictateStart: "voice.dictate-start",
15
+ dictateEnd: "voice.dictate-end",
16
+ dictateCancel: "voice.dictate-cancel",
17
+ speak: "voice.speak",
18
+ speakStop: "voice.speak-stop",
19
+ voices: "voice.voices",
20
+ locales: "voice.locales",
21
+ installAssets: "voice.install-assets",
22
+ installCancel: "voice.install-cancel",
23
+ releaseAssets: "voice.release-assets",
24
+ events: "voice.events"
25
+ };
26
+ /** Largest text one read-aloud request may carry (about 30 minutes of speech). */
27
+ var MAX_SPEAK_CHARACTERS = 2e4;
28
+ /** A long poll returns after this long with no events, so a transport never idles out. */
29
+ var EVENTS_WAIT_MS = 25e3;
30
+ /** Malformed input is the caller's mistake: a typed `bad_request`, never a bare failure. */
31
+ var bad = (message) => new VoiceError("bad_request", message);
32
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
33
+ function onlyKeys(value, allowed) {
34
+ for (const key of Object.keys(value)) if (!allowed.includes(key)) throw bad(`Unexpected field ${key}`);
35
+ }
36
+ function optionalLocale(value) {
37
+ if (value === void 0) return void 0;
38
+ if (typeof value !== "string" || value.length === 0 || value.length > 64) throw bad("Invalid locale");
39
+ const [canonical] = Intl.getCanonicalLocales(value);
40
+ if (!canonical) throw bad("Invalid locale");
41
+ return canonical;
42
+ }
43
+ /** Settings always cross the boundary whole and are re-validated on the shell side. */
44
+ function settings(value) {
45
+ const read = validateVoiceSettings(value);
46
+ if (read.issues.length > 0) throw bad(`Invalid voice settings: ${read.issues.join("; ")}`);
47
+ return read.settings;
48
+ }
49
+ var id = (value) => {
50
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(value)) throw bad("Invalid id");
51
+ return value;
52
+ };
53
+ var parseVoiceInput = {
54
+ capabilities(value) {
55
+ if (!isRecord(value)) throw bad("Invalid request");
56
+ onlyKeys(value, ["settings", "locale"]);
57
+ const locale = optionalLocale(value.locale);
58
+ return {
59
+ settings: settings(value.settings),
60
+ ...locale ? { locale } : {}
61
+ };
62
+ },
63
+ permission(value) {
64
+ if (!isRecord(value)) throw bad("Invalid request");
65
+ onlyKeys(value, ["request"]);
66
+ if (value.request !== void 0 && typeof value.request !== "boolean") throw bad("Invalid request");
67
+ return { request: value.request === true };
68
+ },
69
+ dictateStart(value) {
70
+ return parseVoiceInput.capabilities(value);
71
+ },
72
+ dictation(value) {
73
+ if (!isRecord(value)) throw bad("Invalid request");
74
+ onlyKeys(value, ["id"]);
75
+ return { id: id(value.id) };
76
+ },
77
+ speak(value) {
78
+ if (!isRecord(value)) throw bad("Invalid request");
79
+ onlyKeys(value, [
80
+ "settings",
81
+ "text",
82
+ "locale",
83
+ "queue"
84
+ ]);
85
+ if (typeof value.text !== "string" || value.text.trim().length === 0 || value.text.length > 2e4) throw bad("Invalid text");
86
+ if (value.queue !== void 0 && value.queue !== "replace" && value.queue !== "after-current") throw bad("Invalid queue");
87
+ const locale = optionalLocale(value.locale);
88
+ return {
89
+ settings: settings(value.settings),
90
+ text: value.text,
91
+ ...locale ? { locale } : {},
92
+ queue: value.queue ?? "replace"
93
+ };
94
+ },
95
+ none(value) {
96
+ if (value !== null && value !== void 0 && !(isRecord(value) && Object.keys(value).length === 0)) throw bad("Invalid request");
97
+ return null;
98
+ },
99
+ voices(value) {
100
+ return parseVoiceInput.capabilities(value);
101
+ },
102
+ installAssets(value) {
103
+ if (!isRecord(value)) throw bad("Invalid request");
104
+ onlyKeys(value, ["locale"]);
105
+ const locale = optionalLocale(value.locale);
106
+ if (!locale) throw bad("Invalid locale");
107
+ return { locale };
108
+ },
109
+ /** Removing a model names one locale, like an install. */
110
+ releaseAssets(value) {
111
+ return parseVoiceInput.installAssets(value);
112
+ },
113
+ events(value) {
114
+ if (!isRecord(value)) throw bad("Invalid request");
115
+ onlyKeys(value, ["after"]);
116
+ if (!Number.isSafeInteger(value.after) || value.after < 0) throw bad("Invalid cursor");
117
+ return { after: value.after };
118
+ }
119
+ };
120
+ export { EVENTS_WAIT_MS, MAX_SPEAK_CHARACTERS, VOICE_SERVICES, parseVoiceInput };
@@ -0,0 +1,15 @@
1
+ import type { JSX } from '@solidjs/web';
2
+ import type { ApplicationSettingsSection } from '../shell/settings-sections';
3
+ import type { VoiceClient } from './voice-client';
4
+ /** Languages offered everywhere, besides the system default and the device's own list. */
5
+ export declare const VOICE_COMMON_LOCALES: readonly ['en-US', 'es-419', 'es-ES', 'fr-FR', 'de-DE', 'pt-BR', 'it-IT', 'ja-JP', 'zh-CN'];
6
+ export type VoiceSettingsPanelProps = {
7
+ client: VoiceClient;
8
+ };
9
+ /** The Voice settings section's content. */
10
+ export declare function VoiceSettingsPanel(props: VoiceSettingsPanelProps): JSX.Element;
11
+ /** The Voice section for the shared settings dialog. */
12
+ export declare function voiceSettingsSection(options: {
13
+ client: VoiceClient;
14
+ group?: string;
15
+ }): ApplicationSettingsSection;