@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,121 @@
1
+ export declare const HELPER_LOCK_SCHEMA = 1;
2
+ export declare const HELPER_NAMES: readonly ["adea-voice-helper", "adea-transcribe-helper", "adea-tts-helper"];
3
+ export type HelperName = (typeof HELPER_NAMES)[number];
4
+ export declare const HELPER_TARGETS: readonly ["macos-arm64", "macos-x64", "linux-x64", "linux-arm64", "windows-x64"];
5
+ export type HelperTarget = (typeof HELPER_TARGETS)[number];
6
+ /** A pinned artifact can never be larger than this; a bigger body is refused while streaming. */
7
+ export declare const MAX_HELPER_ARCHIVE_BYTES: number;
8
+ export interface HelperArtifactPin {
9
+ readonly file: string;
10
+ readonly sha256: string;
11
+ readonly executableSha256: string;
12
+ /** The executable's `machoCodeDigest` (0.2.1+): what a re-signed packaged copy still matches. */
13
+ readonly codeSha256?: string;
14
+ readonly bytes?: number;
15
+ }
16
+ export interface HelperLock {
17
+ readonly schema: 1;
18
+ readonly version: string;
19
+ readonly base: string;
20
+ readonly helpers: Readonly<Partial<Record<HelperName, Readonly<Partial<Record<HelperTarget, HelperArtifactPin>>>>>>;
21
+ }
22
+ /** One staged helper: the pins it was staged from and the code digest of what was staged. */
23
+ export interface StagedHelperEntry {
24
+ readonly sha256: string;
25
+ readonly executableSha256: string;
26
+ /** `machoCodeDigest` of the staged executable (absent in records staged before 0.2.1). */
27
+ readonly codeSha256?: string;
28
+ }
29
+ /** What a staged directory records about itself, written next to the helpers. */
30
+ export interface StagedHelperRecord {
31
+ readonly schema: 1;
32
+ readonly version: string;
33
+ readonly target: HelperTarget;
34
+ readonly helpers: Readonly<Partial<Record<HelperName, StagedHelperEntry>>>;
35
+ /**
36
+ * Every other staged file (the helpers' `Frameworks/`), relative path → digest: the code digest
37
+ * for Mach-O files (they are re-signed when packaged), the sha256 otherwise. Signature
38
+ * directories (`_CodeSignature/`) are left out. Absent in records staged before 0.2.1.
39
+ */
40
+ readonly files?: Readonly<Record<string, string>>;
41
+ }
42
+ export declare const STAGED_RECORD_FILE = "voice-helpers.json";
43
+ export declare class HelperLockError extends Error {
44
+ constructor(message: string);
45
+ }
46
+ /** Validates a parsed lock. Every problem is a `HelperLockError`: a build must stop on it. */
47
+ export declare function validateHelperLock(value: unknown): HelperLock;
48
+ export declare function readHelperLock(path: string): HelperLock;
49
+ export declare function helperPin(lock: HelperLock, helper: HelperName, target: HelperTarget): HelperArtifactPin | undefined;
50
+ export declare function helperArtifactUrl(lock: HelperLock, helper: HelperName, target: HelperTarget): string;
51
+ /** The lock target for this machine (or `undefined` where no helper is published). */
52
+ export declare function currentHelperTarget(platform?: string, arch?: string): HelperTarget | undefined;
53
+ export declare function sha256File(path: string): string;
54
+ export interface StageHelpersOptions {
55
+ readonly lock: HelperLock;
56
+ readonly target: HelperTarget;
57
+ /** The directory the app bundles (each helper lands at `<outDir>/<helper>`). */
58
+ readonly outDir: string;
59
+ /** Which helpers must be staged; a pin missing for one is an error. */
60
+ readonly helpers: readonly HelperName[];
61
+ /** A cache of verified archives, keyed by sha256 (default: none). */
62
+ readonly cacheDir?: string;
63
+ /**
64
+ * A directory holding locally built helpers (`scripts/package-helper.sh` output) to use instead
65
+ * of downloading, for developing the helper itself. Its binaries are still checked for a
66
+ * compatible handshake, and the staged record says `local` so a release check refuses it.
67
+ */
68
+ readonly localDir?: string;
69
+ readonly fetch?: typeof fetch;
70
+ /** Run `--version` on the staged executable (default: when the target matches this machine). */
71
+ readonly handshake?: boolean;
72
+ readonly log?: (message: string) => void;
73
+ }
74
+ /**
75
+ * Downloads, verifies and unpacks the pinned helpers into `outDir`, then records what was staged.
76
+ * Reuses an already staged helper whose digests match. Throws `HelperLockError` on any mismatch;
77
+ * a partially staged directory is removed so a build never packages it.
78
+ */
79
+ export declare function stageVoiceHelpers(options: StageHelpersOptions): Promise<StagedHelperRecord>;
80
+ export interface VerifyStagedOptions {
81
+ readonly lock: HelperLock;
82
+ readonly target: HelperTarget;
83
+ readonly dir: string;
84
+ readonly helpers: readonly HelperName[];
85
+ /**
86
+ * Launch each helper with `--version` and require the lock's release and this SDK's wire and
87
+ * contract (only possible on a matching machine; default: when the target matches this one).
88
+ */
89
+ readonly handshake?: boolean;
90
+ /** How long one `--version` may take. Default 10 s. */
91
+ readonly handshakeTimeoutMs?: number;
92
+ /**
93
+ * Run `codesign --verify --strict` on a helper that was signed again after staging (default: on
94
+ * macOS for a macOS target).
95
+ */
96
+ readonly codesign?: boolean;
97
+ }
98
+ /**
99
+ * The release gate: the packaged directory holds exactly the pinned helpers. Throws
100
+ * `HelperLockError` naming the first difference; a local (unpinned) staging is refused.
101
+ *
102
+ * The directory may be the staged one or the copy inside a packaged, re-signed app. A helper whose
103
+ * file sha256 is not the pinned one must still have the pinned code (`machoCodeDigest`): the
104
+ * lock's `codeSha256`, or, for a lock written before it, the digest the staging recorded for the
105
+ * pinned executable, plus a valid signature. Every other staged file (`Frameworks/`) must still be
106
+ * a regular file with the staged digest: a copy that flattened or dropped a symlink fails here.
107
+ * Then each helper must start and report the lock's release.
108
+ */
109
+ export declare function verifyStagedVoiceHelpers(options: VerifyStagedOptions): void;
110
+ export declare function readStagedRecord(dir: string): StagedHelperRecord | undefined;
111
+ export interface HandshakeExpectations {
112
+ /** The release the helper must report (`version.release`), e.g. the lock's version. */
113
+ readonly release?: string;
114
+ /** How long `--version` may take before the helper counts as hung. Default 10 s. */
115
+ readonly timeoutMs?: number;
116
+ }
117
+ /**
118
+ * Runs `<helper> --version` and refuses a helper that does not start (a missing library is a dyld
119
+ * abort here), hangs, or speaks another wire, contract or release.
120
+ */
121
+ export declare function assertHandshake(executable: string, expect?: HandshakeExpectations): void;
@@ -0,0 +1,96 @@
1
+ import { VoiceError } from "../contract/errors";
2
+ import { type VersionEvent, type WireCommand, type WireEvent } from "../contract/wire";
3
+ /** The few process operations the connection needs; injectable for tests. */
4
+ export interface HelperChild {
5
+ /** Writes one line (the connection adds the newline). Throws once input is closed. */
6
+ write(data: string): void;
7
+ closeInput(): void;
8
+ onStdout(listener: (chunk: string) => void): void;
9
+ onStderr?(listener: (chunk: string) => void): void;
10
+ onExit(listener: (code: number | null, signal: string | null) => void): void;
11
+ kill(signal?: "SIGTERM" | "SIGKILL"): void;
12
+ }
13
+ export interface HelperSpawnOptions {
14
+ readonly env?: Readonly<Record<string, string | undefined>>;
15
+ }
16
+ export type HelperSpawner = (path: string, args: readonly string[], options: HelperSpawnOptions) => HelperChild;
17
+ export interface HelperConnectionOptions {
18
+ readonly path: string;
19
+ /** Names the helper in errors and logs, e.g. `adea-transcribe-helper`. Default "voice helper". */
20
+ readonly name?: string;
21
+ readonly spawn: HelperSpawner;
22
+ readonly env?: Readonly<Record<string, string | undefined>>;
23
+ /** How long `--version` may take. Default 5 s. */
24
+ readonly handshakeTimeoutMs?: number;
25
+ /** How long a plain request (status, voices) may take. Default 15 s. */
26
+ readonly requestTimeoutMs?: number;
27
+ /** After `quit`/stdin close, how long the process gets to exit before SIGKILL. Default 2 s. */
28
+ readonly exitGraceMs?: number;
29
+ /** Crashes tolerated inside `crashWindowMs` before the helper is reported unavailable. */
30
+ readonly maxCrashes?: number;
31
+ readonly crashWindowMs?: number;
32
+ readonly log?: (message: string) => void;
33
+ readonly now?: () => number;
34
+ }
35
+ type Listener = (event: WireEvent) => void;
36
+ /** A helper on another wire or contract major: refused for the life of the connection. */
37
+ export declare class IncompatibleHelperError extends VoiceError {
38
+ constructor(message: string);
39
+ }
40
+ /** Splits a stream of text chunks into lines with a hard bound per line. */
41
+ export declare class LineSplitter {
42
+ private readonly limit;
43
+ private buffer;
44
+ private discarding;
45
+ constructor(limit?: number);
46
+ push(chunk: string): string[];
47
+ }
48
+ /** A process-unique request id. */
49
+ export declare function nextRequestId(prefix?: string): string;
50
+ export declare class HelperConnection {
51
+ private readonly options;
52
+ private child;
53
+ private starting;
54
+ private handshake;
55
+ private readonly pending;
56
+ private readonly broadcast;
57
+ private crashes;
58
+ private disposed;
59
+ private incompatible;
60
+ constructor(options: HelperConnectionOptions);
61
+ /** "the voice helper", or the configured helper name. */
62
+ private get label();
63
+ /** The handshake the running helper answered, once it has started. */
64
+ get version(): VersionEvent | undefined;
65
+ /** Receives every event, correlated or not (speech-state, route changes). */
66
+ onEvent(listener: Listener): () => void;
67
+ /**
68
+ * Sends a command and resolves with the first event `isDone` accepts (also delivering every
69
+ * correlated event to `onEvent`). Rejects with a typed `VoiceError` on a helper `error` event
70
+ * (unless `isDone` accepts it), a crash, the timeout, or `signal`.
71
+ */
72
+ request<T extends WireEvent>(command: WireCommand, isDone: (event: WireEvent) => event is T, options?: {
73
+ readonly timeoutMs?: number | null;
74
+ readonly onEvent?: Listener;
75
+ readonly signal?: AbortSignal;
76
+ }): Promise<T>;
77
+ /** Sends a command that has no correlated answer (speech-stop). */
78
+ send(command: WireCommand): Promise<void>;
79
+ /** Whether a process is running now. */
80
+ get running(): boolean;
81
+ /**
82
+ * Stops the helper: `quit`, close stdin, then SIGTERM/SIGKILL after the grace period. Requests
83
+ * still waiting on this process are failed (`cancelled`): its exit is not reported as a crash,
84
+ * so nothing else would ever settle them.
85
+ */
86
+ stop(): Promise<void>;
87
+ dispose(): Promise<void>;
88
+ private ensureStarted;
89
+ private start;
90
+ private versionHandshake;
91
+ private dispatch;
92
+ private failAll;
93
+ }
94
+ /** The default spawner: `node:child_process`, which Bun implements. */
95
+ export declare const nodeSpawner: HelperSpawner;
96
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@adea-ai/voice/desktop`: the Bun/Node client for the pinned desktop speech helpers. Import it
3
+ * from a desktop shell process only (it spawns processes); a renderer talks to the shell.
4
+ */
5
+ export * from "./desktop-voice";
6
+ export type { ConversationRespondOptions, DesktopConversation } from "./conversation";
7
+ export { HelperConnection, IncompatibleHelperError, LineSplitter, nodeSpawner, type HelperChild, type HelperConnectionOptions, type HelperSpawnOptions, type HelperSpawner, } from "./helper-process";
8
+ export * from "./helper-lock";
9
+ export { isMachO, machoCodeDigest, machoCodeDigestFile } from "./macho-digest";