@jini-ai/desktop-host 0.1.2 → 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.
- package/CHANGELOG.md +106 -0
- package/README.md +194 -0
- package/dist/bridge-testing.d.ts +2 -2
- package/dist/bridge-testing.js +3 -3
- package/dist/bridge.d.ts +33 -9
- package/dist/bridge.js +18 -17
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -1
- package/dist/electron/create-electron-desktop-host.js +5 -5
- package/dist/electron/electron-protocol.d.ts +3 -1
- package/dist/electron/electron-protocol.js +7 -7
- package/dist/electron/electron-render-service.d.ts +3 -1
- package/dist/electron/electron-render-service.js +21 -20
- package/dist/electron/electron-shell.js +8 -8
- package/dist/electron/electron-single-instance.d.ts +3 -1
- package/dist/electron/electron-single-instance.js +3 -3
- package/dist/electron/electron-surfaces.d.ts +71 -32
- package/dist/electron/electron-surfaces.js +3 -10
- package/dist/electron/electron-window-lifecycle.d.ts +3 -1
- package/dist/electron/electron-window-lifecycle.js +17 -16
- package/dist/electron/index.d.ts +17 -0
- package/dist/electron/index.js +17 -0
- package/dist/electron/navigation-policy/index.d.ts +3 -0
- package/dist/electron/navigation-policy/index.js +3 -0
- package/dist/electron/navigation-policy/webview-guest-policy.d.ts +32 -0
- package/dist/electron/navigation-policy/webview-guest-policy.js +31 -0
- package/dist/electron/navigation-policy/window-navigation-policy.d.ts +125 -0
- package/dist/electron/navigation-policy/window-navigation-policy.js +138 -0
- package/dist/electron/testing.d.ts +8 -6
- package/dist/electron/testing.js +22 -22
- package/dist/electron/updates/auto-update-controller.d.ts +146 -0
- package/dist/electron/updates/auto-update-controller.js +222 -0
- package/dist/electron/updates/index.d.ts +4 -0
- package/dist/electron/updates/index.js +4 -0
- package/dist/electron/updates/instance-presence.d.ts +68 -0
- package/dist/electron/updates/instance-presence.js +79 -0
- package/dist/electron/updates/update-policy.d.ts +66 -0
- package/dist/electron/updates/update-policy.js +65 -0
- package/dist/electron/usability/find-in-page-ipc.d.ts +88 -0
- package/dist/electron/usability/find-in-page-ipc.js +22 -0
- package/dist/electron/usability/find-menu.d.ts +43 -0
- package/dist/electron/usability/find-menu.js +22 -0
- package/dist/electron/usability/index.d.ts +6 -0
- package/dist/electron/usability/index.js +6 -0
- package/dist/electron/usability/spellcheck-menu.d.ts +92 -0
- package/dist/electron/usability/spellcheck-menu.js +52 -0
- package/dist/electron/usability/window-bounds-store.d.ts +76 -0
- package/dist/electron/usability/window-bounds-store.js +44 -0
- package/dist/electron/usability/zoom-menu.d.ts +41 -0
- package/dist/electron/usability/zoom-menu.js +19 -0
- package/dist/index.d.ts +8 -16
- package/dist/index.js +8 -16
- package/dist/logging.d.ts +26 -12
- package/dist/logging.js +21 -21
- package/dist/node-toolchain/index.d.ts +76 -0
- package/dist/node-toolchain/index.js +96 -0
- package/dist/paths.d.ts +4 -2
- package/dist/paths.js +5 -4
- package/dist/protocol.d.ts +20 -5
- package/dist/protocol.js +5 -5
- package/dist/render-service.d.ts +31 -7
- package/dist/render-service.js +10 -10
- package/dist/shell.d.ts +15 -7
- package/dist/shell.js +3 -3
- package/dist/shutdown/index.d.ts +4 -0
- package/dist/shutdown/index.js +4 -0
- package/dist/shutdown/quit-drain-gate.d.ts +19 -0
- package/dist/shutdown/quit-drain-gate.js +15 -0
- package/dist/shutdown/quit-signals.d.ts +36 -0
- package/dist/shutdown/quit-signals.js +27 -0
- package/dist/shutdown/shutdown-tracker.d.ts +19 -0
- package/dist/shutdown/shutdown-tracker.js +26 -0
- package/dist/sidecar.d.ts +20 -8
- package/dist/sidecar.js +39 -22
- package/dist/single-instance.d.ts +13 -4
- package/dist/single-instance.js +4 -4
- package/dist/speech/channels.d.ts +8 -0
- package/dist/speech/channels.js +5 -0
- package/dist/speech/index.d.ts +5 -0
- package/dist/speech/index.js +5 -0
- package/dist/speech/macos/index.d.ts +2 -0
- package/dist/speech/macos/index.js +2 -0
- package/dist/speech/macos/mac-on-device-transcriber.d.ts +97 -0
- package/dist/speech/macos/mac-on-device-transcriber.js +95 -0
- package/dist/speech/macos/speech-helper.swift +157 -0
- package/dist/speech/pcm-wav-encoder.d.ts +22 -0
- package/dist/speech/pcm-wav-encoder.js +50 -0
- package/dist/speech/speech-bridge.d.ts +33 -0
- package/dist/speech/speech-bridge.js +14 -0
- package/dist/speech/speech-ipc.d.ts +44 -0
- package/dist/speech/speech-ipc.js +50 -0
- package/dist/speech/transcription-port.d.ts +42 -0
- package/dist/speech/transcription-port.js +14 -0
- package/dist/tauri/create-tauri-desktop-host.js +5 -5
- package/dist/tauri/index.d.ts +19 -0
- package/dist/tauri/index.js +19 -0
- package/dist/tauri/not-implemented.d.ts +3 -1
- package/dist/tauri/not-implemented.js +1 -1
- package/dist/tauri/tauri-protocol.d.ts +1 -1
- package/dist/tauri/tauri-protocol.js +2 -2
- package/dist/tauri/tauri-render-service.d.ts +1 -1
- package/dist/tauri/tauri-render-service.js +2 -2
- package/dist/tauri/tauri-shell.js +8 -8
- package/dist/tauri/tauri-sidecar.d.ts +3 -1
- package/dist/tauri/tauri-sidecar.js +17 -16
- package/dist/tauri/tauri-single-instance.d.ts +3 -1
- package/dist/tauri/tauri-single-instance.js +3 -3
- package/dist/tauri/tauri-surfaces.d.ts +50 -14
- package/dist/tauri/tauri-surfaces.js +2 -1
- package/dist/tauri/tauri-window-lifecycle.d.ts +3 -1
- package/dist/tauri/tauri-window-lifecycle.js +33 -20
- package/dist/tauri/testing.d.ts +10 -7
- package/dist/tauri/testing.js +30 -23
- package/dist/tokens.js +6 -6
- package/dist/window-lifecycle.d.ts +10 -4
- package/dist/window-lifecycle.js +7 -7
- package/dist/windows-registry.d.ts +16 -6
- package/dist/windows-registry.js +8 -7
- package/package.json +71 -6
- package/dist/bridge-testing.d.ts.map +0 -1
- package/dist/bridge-testing.js.map +0 -1
- package/dist/bridge.d.ts.map +0 -1
- package/dist/bridge.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/electron/create-electron-desktop-host.d.ts.map +0 -1
- package/dist/electron/create-electron-desktop-host.js.map +0 -1
- package/dist/electron/electron-protocol.d.ts.map +0 -1
- package/dist/electron/electron-protocol.js.map +0 -1
- package/dist/electron/electron-render-service.d.ts.map +0 -1
- package/dist/electron/electron-render-service.js.map +0 -1
- package/dist/electron/electron-shell.d.ts.map +0 -1
- package/dist/electron/electron-shell.js.map +0 -1
- package/dist/electron/electron-single-instance.d.ts.map +0 -1
- package/dist/electron/electron-single-instance.js.map +0 -1
- package/dist/electron/electron-surfaces.d.ts.map +0 -1
- package/dist/electron/electron-surfaces.js.map +0 -1
- package/dist/electron/electron-window-lifecycle.d.ts.map +0 -1
- package/dist/electron/electron-window-lifecycle.js.map +0 -1
- package/dist/electron/testing.d.ts.map +0 -1
- package/dist/electron/testing.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logging.d.ts.map +0 -1
- package/dist/logging.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/ports.d.ts.map +0 -1
- package/dist/ports.js.map +0 -1
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js.map +0 -1
- package/dist/render-service.d.ts.map +0 -1
- package/dist/render-service.js.map +0 -1
- package/dist/shell.d.ts.map +0 -1
- package/dist/shell.js.map +0 -1
- package/dist/sidecar.d.ts.map +0 -1
- package/dist/sidecar.js.map +0 -1
- package/dist/single-instance.d.ts.map +0 -1
- package/dist/single-instance.js.map +0 -1
- package/dist/tauri/create-tauri-desktop-host.d.ts.map +0 -1
- package/dist/tauri/create-tauri-desktop-host.js.map +0 -1
- package/dist/tauri/not-implemented.d.ts.map +0 -1
- package/dist/tauri/not-implemented.js.map +0 -1
- package/dist/tauri/tauri-protocol.d.ts.map +0 -1
- package/dist/tauri/tauri-protocol.js.map +0 -1
- package/dist/tauri/tauri-render-service.d.ts.map +0 -1
- package/dist/tauri/tauri-render-service.js.map +0 -1
- package/dist/tauri/tauri-shell.d.ts.map +0 -1
- package/dist/tauri/tauri-shell.js.map +0 -1
- package/dist/tauri/tauri-sidecar.d.ts.map +0 -1
- package/dist/tauri/tauri-sidecar.js.map +0 -1
- package/dist/tauri/tauri-single-instance.d.ts.map +0 -1
- package/dist/tauri/tauri-single-instance.js.map +0 -1
- package/dist/tauri/tauri-surfaces.d.ts.map +0 -1
- package/dist/tauri/tauri-surfaces.js.map +0 -1
- package/dist/tauri/tauri-window-lifecycle.d.ts.map +0 -1
- package/dist/tauri/tauri-window-lifecycle.js.map +0 -1
- package/dist/tauri/testing.d.ts.map +0 -1
- package/dist/tauri/testing.js.map +0 -1
- package/dist/tokens.d.ts.map +0 -1
- package/dist/tokens.js.map +0 -1
- package/dist/window-lifecycle.d.ts.map +0 -1
- package/dist/window-lifecycle.js.map +0 -1
- package/dist/windows-registry.d.ts.map +0 -1
- package/dist/windows-registry.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { TranscriptionAvailability, TranscriptionPort, TranscriptionResult } from "../transcription-port.js";
|
|
2
|
+
export interface MacTranscriberMessages {
|
|
3
|
+
compilerMissing: string;
|
|
4
|
+
compilerFailed(args: {
|
|
5
|
+
stderr: string;
|
|
6
|
+
}): string;
|
|
7
|
+
invalidOutput(args: {
|
|
8
|
+
stdout: string;
|
|
9
|
+
}): string;
|
|
10
|
+
cannotTranscribe(args: {
|
|
11
|
+
reason: string;
|
|
12
|
+
}): string;
|
|
13
|
+
recognitionFailed(args: {
|
|
14
|
+
reason: string;
|
|
15
|
+
}): string;
|
|
16
|
+
}
|
|
17
|
+
interface SpawnResult {
|
|
18
|
+
status: number | null;
|
|
19
|
+
stderr?: Buffer | string;
|
|
20
|
+
error?: NodeJS.ErrnoException;
|
|
21
|
+
}
|
|
22
|
+
interface TranscriberFs {
|
|
23
|
+
existsSync(args: {
|
|
24
|
+
path: string;
|
|
25
|
+
}): boolean;
|
|
26
|
+
mkdirSync(args: {
|
|
27
|
+
path: string;
|
|
28
|
+
}, options?: {
|
|
29
|
+
recursive?: boolean;
|
|
30
|
+
}): unknown;
|
|
31
|
+
writeFileSync(args: {
|
|
32
|
+
path: string;
|
|
33
|
+
data: Buffer;
|
|
34
|
+
}): void;
|
|
35
|
+
rmSync(args: {
|
|
36
|
+
path: string;
|
|
37
|
+
}, options?: {
|
|
38
|
+
force?: boolean;
|
|
39
|
+
}): void;
|
|
40
|
+
}
|
|
41
|
+
interface CompileDeps {
|
|
42
|
+
fs: Pick<TranscriberFs, "existsSync" | "mkdirSync">;
|
|
43
|
+
spawnSync: (args: {
|
|
44
|
+
command: string;
|
|
45
|
+
args: string[];
|
|
46
|
+
}) => SpawnResult;
|
|
47
|
+
sourcePath: string;
|
|
48
|
+
binaryPath: string;
|
|
49
|
+
compilerPath: string;
|
|
50
|
+
messages: MacTranscriberMessages;
|
|
51
|
+
}
|
|
52
|
+
type CompileResult = {
|
|
53
|
+
ok: true;
|
|
54
|
+
error?: undefined;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
error: string;
|
|
58
|
+
};
|
|
59
|
+
interface AvailabilityDeps extends CompileDeps {
|
|
60
|
+
locale: string;
|
|
61
|
+
execFileAsync: (args: {
|
|
62
|
+
file: string;
|
|
63
|
+
args: string[];
|
|
64
|
+
}) => Promise<{
|
|
65
|
+
stdout: string;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
interface MacTranscriberDeps extends AvailabilityDeps {
|
|
69
|
+
fs: TranscriberFs;
|
|
70
|
+
tempFilePath: () => string;
|
|
71
|
+
}
|
|
72
|
+
interface HelperPayload {
|
|
73
|
+
available?: unknown;
|
|
74
|
+
reason?: string | null;
|
|
75
|
+
ok?: boolean;
|
|
76
|
+
text?: string;
|
|
77
|
+
elapsedMs?: number;
|
|
78
|
+
error?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Compile once at the caller-supplied source and binary paths. */
|
|
81
|
+
declare function ensureHelperCompiled({ fs, spawnSync, sourcePath, binaryPath, compilerPath, messages }: CompileDeps): CompileResult;
|
|
82
|
+
/** Parse structured helper output and report malformed payloads with host wording. */
|
|
83
|
+
declare function parseHelperJson({ stdout, invalidOutput }: {
|
|
84
|
+
stdout: string;
|
|
85
|
+
invalidOutput: MacTranscriberMessages["invalidOutput"];
|
|
86
|
+
}): HelperPayload;
|
|
87
|
+
/** Probe compiled helper capability without recording audio. */
|
|
88
|
+
declare function checkAvailability(deps: AvailabilityDeps): Promise<TranscriptionAvailability>;
|
|
89
|
+
/** Transcribe scratch WAV input and remove the recording on every completion path. */
|
|
90
|
+
declare function transcribeWav({ wavBuffer, ...deps }: MacTranscriberDeps & {
|
|
91
|
+
wavBuffer: Buffer;
|
|
92
|
+
}): Promise<TranscriptionResult>;
|
|
93
|
+
/** Construct a native port with explicit filesystem, process and temp-file dependencies. */
|
|
94
|
+
declare function createMacOnDeviceTranscriptionPort(deps: MacTranscriberDeps): TranscriptionPort;
|
|
95
|
+
export { createMacOnDeviceTranscriptionPort, ensureHelperCompiled, checkAvailability, transcribeWav, parseHelperJson, };
|
|
96
|
+
export type { AvailabilityDeps, CompileDeps, CompileResult, HelperPayload, MacTranscriberDeps, SpawnResult, TranscriberFs };
|
|
97
|
+
//# sourceMappingURL=mac-on-device-transcriber.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use the OS-provided Speech models without a separate recognition-model download; a
|
|
3
|
+
* roughly 75 MB bundled-model alternative was deliberately avoided. The native helper
|
|
4
|
+
* requires on-device recognition: missing locale assets are an unavailable/rejected result,
|
|
5
|
+
* never a silent network fallback that uploads private recordings. Compile lazily so a
|
|
6
|
+
* checkout without swiftc can report unavailable instead of failing installation.
|
|
7
|
+
*/
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
// An existing binary is a cache hit, not a rebuild check; remove the cached output after
|
|
10
|
+
// editing the Swift source to force recompilation.
|
|
11
|
+
/** Compile once at the caller-supplied source and binary paths. */
|
|
12
|
+
function ensureHelperCompiled({ fs, spawnSync, sourcePath, binaryPath, compilerPath, messages }) {
|
|
13
|
+
if (fs.existsSync({ path: binaryPath }))
|
|
14
|
+
return { ok: true };
|
|
15
|
+
fs.mkdirSync({ path: path.dirname(binaryPath) }, { recursive: true });
|
|
16
|
+
const result = spawnSync({ command: compilerPath, args: ["-O", sourcePath, "-o", binaryPath] });
|
|
17
|
+
if (result.error && result.error.code === "ENOENT") {
|
|
18
|
+
return { ok: false, error: messages.compilerMissing };
|
|
19
|
+
}
|
|
20
|
+
if (result.status !== 0) {
|
|
21
|
+
const stderr = result.stderr ? result.stderr.toString() : "";
|
|
22
|
+
return { ok: false, error: messages.compilerFailed({ stderr: stderr.trim() }) };
|
|
23
|
+
}
|
|
24
|
+
return { ok: true };
|
|
25
|
+
}
|
|
26
|
+
// Include the raw helper stdout in malformed-output errors so the payload is debuggable
|
|
27
|
+
// without separately collecting a child-process log.
|
|
28
|
+
/** Parse structured helper output and report malformed payloads with host wording. */
|
|
29
|
+
function parseHelperJson({ stdout, invalidOutput }) {
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(stdout.trim());
|
|
32
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
33
|
+
throw new TypeError();
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error(invalidOutput({ stdout }));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The helper prints structured failures and exits nonzero for both subcommands.
|
|
42
|
+
* execFile attaches stdout to its rejection, so recover that JSON rather than losing the
|
|
43
|
+
* native failure reason behind a generic process-exit error.
|
|
44
|
+
*/
|
|
45
|
+
async function runHelperJson({ execFileAsync, binaryPath, args, messages }) {
|
|
46
|
+
try {
|
|
47
|
+
const { stdout } = await execFileAsync({ file: binaryPath, args });
|
|
48
|
+
return parseHelperJson({ stdout, invalidOutput: messages.invalidOutput });
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error !== null && typeof error === "object" && typeof error.stdout === "string" && error.stdout.trim().length > 0) {
|
|
52
|
+
return parseHelperJson({ stdout: error.stdout, invalidOutput: messages.invalidOutput });
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Probe compiled helper capability without recording audio. */
|
|
58
|
+
async function checkAvailability(deps) {
|
|
59
|
+
const compiled = ensureHelperCompiled(deps);
|
|
60
|
+
if (!compiled.ok)
|
|
61
|
+
return { available: false, reason: compiled.error };
|
|
62
|
+
const result = await runHelperJson({ execFileAsync: deps.execFileAsync, binaryPath: deps.binaryPath, args: ["check", deps.locale], messages: deps.messages });
|
|
63
|
+
if (typeof result.available !== "boolean" || (result.reason != null && typeof result.reason !== "string"))
|
|
64
|
+
throw new Error(deps.messages.invalidOutput({ stdout: JSON.stringify(result) }));
|
|
65
|
+
return { available: result.available, reason: result.reason ?? undefined };
|
|
66
|
+
}
|
|
67
|
+
/** Transcribe scratch WAV input and remove the recording on every completion path. */
|
|
68
|
+
async function transcribeWav({ wavBuffer, ...deps }) {
|
|
69
|
+
const compiled = ensureHelperCompiled(deps);
|
|
70
|
+
if (!compiled.ok)
|
|
71
|
+
throw new Error(deps.messages.cannotTranscribe({ reason: compiled.error }));
|
|
72
|
+
const tempPath = deps.tempFilePath();
|
|
73
|
+
try {
|
|
74
|
+
deps.fs.writeFileSync({ path: tempPath, data: wavBuffer });
|
|
75
|
+
const result = await runHelperJson({ execFileAsync: deps.execFileAsync, binaryPath: deps.binaryPath, args: ["transcribe", tempPath, deps.locale], messages: deps.messages });
|
|
76
|
+
if (result.ok !== true)
|
|
77
|
+
throw new Error(deps.messages.recognitionFailed({ reason: result.error ?? "" }));
|
|
78
|
+
if ((result.text !== undefined && typeof result.text !== "string") || (result.elapsedMs !== undefined && (typeof result.elapsedMs !== "number" || !Number.isFinite(result.elapsedMs)))) {
|
|
79
|
+
throw new Error(deps.messages.invalidOutput({ stdout: JSON.stringify(result) }));
|
|
80
|
+
}
|
|
81
|
+
return { text: result.text ?? "", elapsedMs: result.elapsedMs ?? 0 };
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
deps.fs.rmSync({ path: tempPath }, { force: true });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Construct a native port with explicit filesystem, process and temp-file dependencies. */
|
|
88
|
+
function createMacOnDeviceTranscriptionPort(deps) {
|
|
89
|
+
return {
|
|
90
|
+
isAvailable: () => checkAvailability(deps),
|
|
91
|
+
transcribe: ({ wavBuffer }) => transcribeWav({ ...deps, wavBuffer }),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export { createMacOnDeviceTranscriptionPort, ensureHelperCompiled, checkAvailability, transcribeWav, parseHelperJson, };
|
|
95
|
+
//# sourceMappingURL=mac-on-device-transcriber.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Native helper protocol: check <locale>; transcribe <audio-path> <locale>.
|
|
2
|
+
// Stdout contains structured JSON. Recognition always stays on-device.
|
|
3
|
+
// The capability probe reads current authorization without prompting; a real
|
|
4
|
+
// transcription request can request Speech authorization. CLI callbacks need
|
|
5
|
+
// the main run loop pumped rather than a blocking semaphore.
|
|
6
|
+
import Foundation
|
|
7
|
+
import Speech
|
|
8
|
+
// Keep Speech in a small native subprocess so the JavaScript desktop host need not link Swift
|
|
9
|
+
// or a speech framework. JSON-only stdout gives it a stable machine protocol instead of prose.
|
|
10
|
+
// On-device recognition is a privacy requirement: missing locale assets must fail, never cause
|
|
11
|
+
// a transparent retry that uploads the recorded audio for network recognition.
|
|
12
|
+
|
|
13
|
+
/// Speech callbacks arrive via XPC onto the main queue. A bare CLI has no application loop;
|
|
14
|
+
/// blocking that thread on a semaphore starves its own callbacks and repeatedly hits the 30s
|
|
15
|
+
/// recognition timeout. Pumping the run loop keeps the queue alive between completion checks.
|
|
16
|
+
func spinRunLoop(until isDone: () -> Bool, timeoutSeconds: TimeInterval) -> Bool {
|
|
17
|
+
let deadline = Date().addingTimeInterval(timeoutSeconds)
|
|
18
|
+
while !isDone() {
|
|
19
|
+
if Date() > deadline { return false }
|
|
20
|
+
RunLoop.current.run(mode: .default, before: Date().addingTimeInterval(0.1))
|
|
21
|
+
}
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
func resolveSpeechAuthorization() -> SFSpeechRecognizerAuthorizationStatus {
|
|
25
|
+
var status: SFSpeechRecognizerAuthorizationStatus = .notDetermined
|
|
26
|
+
var received = false
|
|
27
|
+
SFSpeechRecognizer.requestAuthorization { result in
|
|
28
|
+
status = result
|
|
29
|
+
received = true
|
|
30
|
+
}
|
|
31
|
+
_ = spinRunLoop(until: { received }, timeoutSeconds: 15)
|
|
32
|
+
return status
|
|
33
|
+
}
|
|
34
|
+
// Authorization prose is for human diagnostics; the host branches on available/ok, not these labels.
|
|
35
|
+
func describeAuthStatus(_ status: SFSpeechRecognizerAuthorizationStatus) -> String {
|
|
36
|
+
switch status {
|
|
37
|
+
case .authorized: return "authorized"
|
|
38
|
+
case .denied: return "denied"
|
|
39
|
+
case .restricted: return "restricted"
|
|
40
|
+
case .notDetermined: return "not-determined"
|
|
41
|
+
@unknown default: return "unknown"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Fixed-shape JSON payloads with one variable string need escaping, without a heavier JSON dependency.
|
|
45
|
+
func jsonEscape(_ text: String) -> String {
|
|
46
|
+
var result = ""
|
|
47
|
+
for scalar in text.unicodeScalars {
|
|
48
|
+
switch scalar {
|
|
49
|
+
case "\"": result += "\\\""
|
|
50
|
+
case "\\": result += "\\\\"
|
|
51
|
+
case "\n": result += "\\n"
|
|
52
|
+
case "\r": result += "\\r"
|
|
53
|
+
case "\t": result += "\\t"
|
|
54
|
+
default:
|
|
55
|
+
if scalar.value < 0x20 {
|
|
56
|
+
result += String(format: "\\u%04x", scalar.value)
|
|
57
|
+
} else {
|
|
58
|
+
result.unicodeScalars.append(scalar)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result
|
|
63
|
+
}
|
|
64
|
+
// A capability check reads authorization/assets without a microphone or audio file, letting the
|
|
65
|
+
// host decide whether to offer recording before starting recognition or prompting the user.
|
|
66
|
+
func runCheck(locale: String) -> Never {
|
|
67
|
+
let status = SFSpeechRecognizer.authorizationStatus()
|
|
68
|
+
guard status == .authorized else {
|
|
69
|
+
print("{\"available\":false,\"reason\":\"speech-recognition-not-authorized:\(describeAuthStatus(status))\"}")
|
|
70
|
+
exit(0)
|
|
71
|
+
}
|
|
72
|
+
guard let recognizer = SFSpeechRecognizer(locale: Locale(identifier: locale)) else {
|
|
73
|
+
print("{\"available\":false,\"reason\":\"no-recognizer-for-locale\"}")
|
|
74
|
+
exit(0)
|
|
75
|
+
}
|
|
76
|
+
if !recognizer.supportsOnDeviceRecognition {
|
|
77
|
+
print("{\"available\":false,\"reason\":\"on-device-recognition-unavailable\"}")
|
|
78
|
+
exit(0)
|
|
79
|
+
}
|
|
80
|
+
print("{\"available\":true,\"reason\":null}")
|
|
81
|
+
exit(0)
|
|
82
|
+
}
|
|
83
|
+
func runTranscribe(path: String, locale: String) -> Never {
|
|
84
|
+
let status = resolveSpeechAuthorization()
|
|
85
|
+
guard status == .authorized else {
|
|
86
|
+
print("{\"ok\":false,\"error\":\"speech-recognition-not-authorized:\(describeAuthStatus(status))\"}")
|
|
87
|
+
exit(1)
|
|
88
|
+
}
|
|
89
|
+
guard let recognizer = SFSpeechRecognizer(locale: Locale(identifier: locale)) else {
|
|
90
|
+
print("{\"ok\":false,\"error\":\"no-recognizer-for-locale\"}")
|
|
91
|
+
exit(1)
|
|
92
|
+
}
|
|
93
|
+
guard recognizer.supportsOnDeviceRecognition else {
|
|
94
|
+
print("{\"ok\":false,\"error\":\"on-device-recognition-unavailable\"}")
|
|
95
|
+
exit(1)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let request = SFSpeechURLRecognitionRequest(url: URL(fileURLWithPath: path))
|
|
99
|
+
request.requiresOnDeviceRecognition = true
|
|
100
|
+
request.shouldReportPartialResults = false
|
|
101
|
+
|
|
102
|
+
let start = Date()
|
|
103
|
+
var finalText: String?
|
|
104
|
+
var finalError: Error?
|
|
105
|
+
var finished = false
|
|
106
|
+
let task = recognizer.recognitionTask(with: request) { result, error in
|
|
107
|
+
if let error = error {
|
|
108
|
+
finalError = error
|
|
109
|
+
finished = true
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
if let result = result, result.isFinal {
|
|
113
|
+
finalText = result.bestTranscription.formattedString
|
|
114
|
+
finished = true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_ = task
|
|
118
|
+
|
|
119
|
+
let completed = spinRunLoop(until: { finished }, timeoutSeconds: 30)
|
|
120
|
+
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
|
121
|
+
|
|
122
|
+
if !completed {
|
|
123
|
+
task.cancel()
|
|
124
|
+
print("{\"ok\":false,\"error\":\"timed-out-after-\(elapsedMs)ms\"}")
|
|
125
|
+
exit(1)
|
|
126
|
+
}
|
|
127
|
+
if let error = finalError {
|
|
128
|
+
print("{\"ok\":false,\"error\":\"\(jsonEscape(error.localizedDescription))\"}")
|
|
129
|
+
exit(1)
|
|
130
|
+
}
|
|
131
|
+
print("{\"ok\":true,\"text\":\"\(jsonEscape(finalText ?? ""))\",\"elapsedMs\":\(elapsedMs)}")
|
|
132
|
+
exit(0)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let arguments = CommandLine.arguments
|
|
136
|
+
guard arguments.count > 1 else {
|
|
137
|
+
print("{\"ok\":false,\"error\":\"usage: speech-helper check|transcribe <path>\"}")
|
|
138
|
+
exit(2)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
switch arguments[1] {
|
|
142
|
+
case "check":
|
|
143
|
+
guard arguments.count > 2 else {
|
|
144
|
+
print("{\"available\":false,\"reason\":\"locale-required\"}")
|
|
145
|
+
exit(2)
|
|
146
|
+
}
|
|
147
|
+
runCheck(locale: arguments[2])
|
|
148
|
+
case "transcribe":
|
|
149
|
+
guard arguments.count > 3 else {
|
|
150
|
+
print("{\"ok\":false,\"error\":\"usage: speech-helper transcribe <path-to-audio-file> <locale>\"}")
|
|
151
|
+
exit(2)
|
|
152
|
+
}
|
|
153
|
+
runTranscribe(path: arguments[2], locale: arguments[3])
|
|
154
|
+
default:
|
|
155
|
+
print("{\"ok\":false,\"error\":\"unknown subcommand: \(arguments[1])\"}")
|
|
156
|
+
exit(2)
|
|
157
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mono 16-bit PCM WAV needs only a fixed 44-byte header and raw samples. An external encoder or
|
|
3
|
+
* ffmpeg would add install size, license review and supply-chain surface for this small format.
|
|
4
|
+
* Capture happens in the renderer's Web Audio API; this module only encodes those samples.
|
|
5
|
+
*/
|
|
6
|
+
declare const WAV_HEADER_BYTES = 44;
|
|
7
|
+
/** Clamp and quantize mono samples to signed 16-bit PCM. */
|
|
8
|
+
declare function float32ToInt16Pcm({ samples: float32Samples }: {
|
|
9
|
+
samples: Float32Array;
|
|
10
|
+
}): Int16Array;
|
|
11
|
+
/** Build the canonical mono PCM RIFF header. */
|
|
12
|
+
declare function buildWavHeader({ sampleCount, sampleRate }: {
|
|
13
|
+
sampleCount: number;
|
|
14
|
+
sampleRate: number;
|
|
15
|
+
}): Buffer;
|
|
16
|
+
/** Encode a complete mono WAV with the caller-provided capture rate. */
|
|
17
|
+
declare function encodeMonoWav({ samples, sampleRate }: {
|
|
18
|
+
samples: Float32Array | number[];
|
|
19
|
+
sampleRate: number;
|
|
20
|
+
}): Buffer;
|
|
21
|
+
export { encodeMonoWav, float32ToInt16Pcm, buildWavHeader, WAV_HEADER_BYTES };
|
|
22
|
+
//# sourceMappingURL=pcm-wav-encoder.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mono 16-bit PCM WAV needs only a fixed 44-byte header and raw samples. An external encoder or
|
|
3
|
+
* ffmpeg would add install size, license review and supply-chain surface for this small format.
|
|
4
|
+
* Capture happens in the renderer's Web Audio API; this module only encodes those samples.
|
|
5
|
+
*/
|
|
6
|
+
const WAV_HEADER_BYTES = 44;
|
|
7
|
+
const BYTES_PER_SAMPLE = 2; // 16-bit PCM
|
|
8
|
+
const PCM_FORMAT_CODE = 1;
|
|
9
|
+
const CHANNEL_COUNT = 1; // mono — matches the recognizer's own expectation and halves upload size
|
|
10
|
+
/** Clamp and quantize mono samples to signed 16-bit PCM. */
|
|
11
|
+
function float32ToInt16Pcm({ samples: float32Samples }) {
|
|
12
|
+
const int16Samples = new Int16Array(float32Samples.length);
|
|
13
|
+
for (let i = 0; i < float32Samples.length; i += 1) {
|
|
14
|
+
const clamped = Math.max(-1, Math.min(1, float32Samples[i]));
|
|
15
|
+
int16Samples[i] = clamped < 0 ? clamped * 0x8000 : clamped * 0x7fff;
|
|
16
|
+
}
|
|
17
|
+
return int16Samples;
|
|
18
|
+
}
|
|
19
|
+
/** Build the canonical mono PCM RIFF header. */
|
|
20
|
+
function buildWavHeader({ sampleCount, sampleRate }) {
|
|
21
|
+
const dataBytes = sampleCount * BYTES_PER_SAMPLE;
|
|
22
|
+
const byteRate = sampleRate * CHANNEL_COUNT * BYTES_PER_SAMPLE;
|
|
23
|
+
const blockAlign = CHANNEL_COUNT * BYTES_PER_SAMPLE;
|
|
24
|
+
const header = Buffer.alloc(WAV_HEADER_BYTES);
|
|
25
|
+
header.write("RIFF", 0, "ascii");
|
|
26
|
+
header.writeUInt32LE(36 + dataBytes, 4);
|
|
27
|
+
header.write("WAVE", 8, "ascii");
|
|
28
|
+
header.write("fmt ", 12, "ascii");
|
|
29
|
+
header.writeUInt32LE(16, 16); // fmt chunk size
|
|
30
|
+
header.writeUInt16LE(PCM_FORMAT_CODE, 20);
|
|
31
|
+
header.writeUInt16LE(CHANNEL_COUNT, 22);
|
|
32
|
+
header.writeUInt32LE(sampleRate, 24);
|
|
33
|
+
header.writeUInt32LE(byteRate, 28);
|
|
34
|
+
header.writeUInt16LE(blockAlign, 32);
|
|
35
|
+
header.writeUInt16LE(BYTES_PER_SAMPLE * 8, 34); // bits per sample
|
|
36
|
+
header.write("data", 36, "ascii");
|
|
37
|
+
header.writeUInt32LE(dataBytes, 40);
|
|
38
|
+
return header;
|
|
39
|
+
}
|
|
40
|
+
/** Encode a complete mono WAV with the caller-provided capture rate. */
|
|
41
|
+
// The recognizer accepts any rate; 16000 Hz keeps the renderer-to-main IPC payload small.
|
|
42
|
+
function encodeMonoWav({ samples, sampleRate }) {
|
|
43
|
+
const float32Samples = samples instanceof Float32Array ? samples : Float32Array.from(samples);
|
|
44
|
+
const pcm = float32ToInt16Pcm({ samples: float32Samples });
|
|
45
|
+
const header = buildWavHeader({ sampleCount: pcm.length, sampleRate });
|
|
46
|
+
const body = Buffer.from(pcm.buffer, pcm.byteOffset, pcm.byteLength);
|
|
47
|
+
return Buffer.concat([header, body]);
|
|
48
|
+
}
|
|
49
|
+
export { encodeMonoWav, float32ToInt16Pcm, buildWavHeader, WAV_HEADER_BYTES };
|
|
50
|
+
//# sourceMappingURL=pcm-wav-encoder.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TranscriptionAvailability, TranscriptionResult } from "./transcription-port.js";
|
|
2
|
+
export interface SpeechRendererIpcPort {
|
|
3
|
+
invoke(requiredArgs: {
|
|
4
|
+
channel: string;
|
|
5
|
+
}, optionalArgs?: {
|
|
6
|
+
args?: unknown[];
|
|
7
|
+
}): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface SpeechBridge {
|
|
10
|
+
isAvailable(): Promise<TranscriptionAvailability>;
|
|
11
|
+
transcribe(args: {
|
|
12
|
+
samples: Float32Array | readonly number[];
|
|
13
|
+
sampleRate: number;
|
|
14
|
+
}): Promise<TranscriptionResult>;
|
|
15
|
+
}
|
|
16
|
+
/** Build a narrow renderer bridge. Bundle into sandboxed preloads before loading. */
|
|
17
|
+
export declare function createSpeechBridge({ ipcRenderer, channelNamespace }: {
|
|
18
|
+
ipcRenderer: SpeechRendererIpcPort;
|
|
19
|
+
channelNamespace: string;
|
|
20
|
+
}): SpeechBridge;
|
|
21
|
+
/** Expose only the speech capability under a caller-owned renderer global. */
|
|
22
|
+
export declare function exposeSpeechBridge({ contextBridge, ipcRenderer, channelNamespace, globalName }: {
|
|
23
|
+
contextBridge: {
|
|
24
|
+
exposeInMainWorld(args: {
|
|
25
|
+
name: string;
|
|
26
|
+
bridge: SpeechBridge;
|
|
27
|
+
}): void;
|
|
28
|
+
};
|
|
29
|
+
ipcRenderer: SpeechRendererIpcPort;
|
|
30
|
+
channelNamespace: string;
|
|
31
|
+
globalName: string;
|
|
32
|
+
}): void;
|
|
33
|
+
//# sourceMappingURL=speech-bridge.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { speechChannels } from "./channels.js";
|
|
2
|
+
/** Build a narrow renderer bridge. Bundle into sandboxed preloads before loading. */
|
|
3
|
+
export function createSpeechBridge({ ipcRenderer, channelNamespace }) {
|
|
4
|
+
const channels = speechChannels({ channelNamespace });
|
|
5
|
+
return {
|
|
6
|
+
isAvailable: () => ipcRenderer.invoke({ channel: channels.isAvailable }),
|
|
7
|
+
transcribe: ({ samples, sampleRate }) => ipcRenderer.invoke({ channel: channels.transcribe }, { args: [samples, sampleRate] }),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** Expose only the speech capability under a caller-owned renderer global. */
|
|
11
|
+
export function exposeSpeechBridge({ contextBridge, ipcRenderer, channelNamespace, globalName }) {
|
|
12
|
+
contextBridge.exposeInMainWorld({ name: globalName, bridge: createSpeechBridge({ ipcRenderer, channelNamespace }) });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=speech-bridge.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export { speechChannels } from "./channels.js";
|
|
2
|
+
import type { TranscriptionPort } from "./transcription-port.js";
|
|
3
|
+
export declare const MAX_TRANSCRIBE_SAMPLES: number;
|
|
4
|
+
export interface SpeechIpcEvent {
|
|
5
|
+
senderFrame?: {
|
|
6
|
+
url: string;
|
|
7
|
+
} | null;
|
|
8
|
+
}
|
|
9
|
+
export interface SpeechIpcPort {
|
|
10
|
+
handle(args: {
|
|
11
|
+
channel: string;
|
|
12
|
+
handler: (args: {
|
|
13
|
+
event: SpeechIpcEvent | undefined;
|
|
14
|
+
samples?: unknown;
|
|
15
|
+
sampleRate?: unknown;
|
|
16
|
+
}) => unknown;
|
|
17
|
+
}): unknown;
|
|
18
|
+
removeHandler?(args: {
|
|
19
|
+
channel: string;
|
|
20
|
+
}): unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface SpeechIpcMessages {
|
|
23
|
+
senderRefused: string;
|
|
24
|
+
invalidRate: string;
|
|
25
|
+
invalidSamples: string;
|
|
26
|
+
missingSenderGuard: string;
|
|
27
|
+
tooManySamples(args: {
|
|
28
|
+
maxSamples: number;
|
|
29
|
+
}): string;
|
|
30
|
+
}
|
|
31
|
+
export interface RegisterSpeechIpcArgs {
|
|
32
|
+
ipcMain: SpeechIpcPort;
|
|
33
|
+
port: TranscriptionPort;
|
|
34
|
+
channelNamespace: string;
|
|
35
|
+
isTrustedSender: (args: {
|
|
36
|
+
senderUrl: string;
|
|
37
|
+
}) => boolean;
|
|
38
|
+
messages: SpeechIpcMessages;
|
|
39
|
+
}
|
|
40
|
+
/** Register trusted speech handlers; preserve positional IPC payloads and return a disposer. */
|
|
41
|
+
export declare function registerSpeechIpc({ ipcMain, port, channelNamespace, isTrustedSender, messages }: RegisterSpeechIpcArgs, { maxSamples }?: {
|
|
42
|
+
maxSamples?: number;
|
|
43
|
+
}): () => void;
|
|
44
|
+
//# sourceMappingURL=speech-ipc.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { speechChannels } from "./channels.js";
|
|
2
|
+
export { speechChannels } from "./channels.js";
|
|
3
|
+
import { encodeMonoWav } from "./pcm-wav-encoder.js";
|
|
4
|
+
export const MAX_TRANSCRIBE_SAMPLES = 48_000 * 60 * 5;
|
|
5
|
+
function assertTrustedSender(event, guard, message) {
|
|
6
|
+
const url = event?.senderFrame?.url;
|
|
7
|
+
if (typeof url !== "string" || !guard({ senderUrl: url }))
|
|
8
|
+
throw new Error(message);
|
|
9
|
+
}
|
|
10
|
+
function readSamples(samples, maxSamples, messages) {
|
|
11
|
+
// Structured clone does not make input trustworthy. An array-like {length: 2_000_000_000}
|
|
12
|
+
// once reached Float32Array.from and requested 8 GB; reject shape/length before copying anything.
|
|
13
|
+
if (!(samples instanceof Float32Array) && !Array.isArray(samples))
|
|
14
|
+
throw new TypeError(messages.invalidSamples);
|
|
15
|
+
if (samples.length > maxSamples)
|
|
16
|
+
throw new RangeError(messages.tooManySamples({ maxSamples }));
|
|
17
|
+
// Check every indexed element, including sparse holes, before allocating the converted array.
|
|
18
|
+
for (let i = 0; i < samples.length; i += 1) {
|
|
19
|
+
if (!Number.isFinite(samples[i]))
|
|
20
|
+
throw new TypeError(messages.invalidSamples);
|
|
21
|
+
}
|
|
22
|
+
if (samples instanceof Float32Array)
|
|
23
|
+
return samples;
|
|
24
|
+
return Float32Array.from(samples);
|
|
25
|
+
}
|
|
26
|
+
/** Register trusted speech handlers; preserve positional IPC payloads and return a disposer. */
|
|
27
|
+
export function registerSpeechIpc({ ipcMain, port, channelNamespace, isTrustedSender, messages }, { maxSamples = MAX_TRANSCRIBE_SAMPLES } = {}) {
|
|
28
|
+
// A missing sender predicate must fail closed: a trust-all default silently exposes recognition
|
|
29
|
+
// to every page with the preload. Register before opening windows so no bridge races setup.
|
|
30
|
+
if (typeof isTrustedSender !== "function")
|
|
31
|
+
throw new Error(messages.missingSenderGuard);
|
|
32
|
+
if (!Number.isSafeInteger(maxSamples) || maxSamples < 0)
|
|
33
|
+
throw new RangeError(messages.tooManySamples({ maxSamples }));
|
|
34
|
+
const channels = speechChannels({ channelNamespace });
|
|
35
|
+
ipcMain.handle({ channel: channels.isAvailable, handler: ({ event }) => {
|
|
36
|
+
assertTrustedSender(event, isTrustedSender, messages.senderRefused);
|
|
37
|
+
return port.isAvailable();
|
|
38
|
+
} });
|
|
39
|
+
ipcMain.handle({ channel: channels.transcribe, handler: ({ event, samples, sampleRate }) => {
|
|
40
|
+
assertTrustedSender(event, isTrustedSender, messages.senderRefused);
|
|
41
|
+
if (!Number.isInteger(sampleRate) || sampleRate < 8_000 || sampleRate > 192_000)
|
|
42
|
+
throw new RangeError(messages.invalidRate);
|
|
43
|
+
// Carry the capture hardware's whole-Hz rate (telephone band through high-end interfaces);
|
|
44
|
+
// forcing browser resampling to a fixed rate adds a failure mode without helping the WAV encoder.
|
|
45
|
+
const wavBuffer = encodeMonoWav({ samples: readSamples(samples, maxSamples, messages), sampleRate: sampleRate });
|
|
46
|
+
return port.transcribe({ wavBuffer });
|
|
47
|
+
} });
|
|
48
|
+
return () => { ipcMain.removeHandler?.({ channel: channels.isAvailable }); ipcMain.removeHandler?.({ channel: channels.transcribe }); };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=speech-ipc.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** The recognizer is swappable without coupling IPC handlers or composer UI to a native backend.
|
|
2
|
+
* Platform selection is injected so capability policy can be checked without native I/O. */
|
|
3
|
+
/** Successful recognition of silence returns empty text, never null; elapsedMs supports latency logs. */
|
|
4
|
+
export interface TranscriptionResult {
|
|
5
|
+
text: string;
|
|
6
|
+
elapsedMs: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TranscriptionAvailability {
|
|
9
|
+
available: boolean;
|
|
10
|
+
reason?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface TranscriptionPort {
|
|
13
|
+
/** Probe capability without capturing audio or prompting for authorization. */
|
|
14
|
+
isAvailable(): Promise<TranscriptionAvailability>;
|
|
15
|
+
/** Transcribe one complete WAV; implementations must not silently fall back to the network. */
|
|
16
|
+
transcribe(args: {
|
|
17
|
+
wavBuffer: Buffer;
|
|
18
|
+
}): Promise<TranscriptionResult>;
|
|
19
|
+
}
|
|
20
|
+
export interface TranscriptionMessages {
|
|
21
|
+
unsupportedPlatform(args: {
|
|
22
|
+
platform: string;
|
|
23
|
+
}): string;
|
|
24
|
+
unavailable(args: {
|
|
25
|
+
reason: string;
|
|
26
|
+
}): string;
|
|
27
|
+
}
|
|
28
|
+
export interface ResolveTranscriptionPortDeps {
|
|
29
|
+
platform: string;
|
|
30
|
+
createMacPort: () => TranscriptionPort;
|
|
31
|
+
messages: TranscriptionMessages;
|
|
32
|
+
}
|
|
33
|
+
/** Return a port that reports a host-owned reason and rejects transcription. */
|
|
34
|
+
export declare function unavailablePort({ reason, message }: {
|
|
35
|
+
reason: string;
|
|
36
|
+
message: (args: {
|
|
37
|
+
reason: string;
|
|
38
|
+
}) => string;
|
|
39
|
+
}): TranscriptionPort;
|
|
40
|
+
/** Select lazily so unsupported platforms never construct the native implementation. */
|
|
41
|
+
export declare function resolveTranscriptionPort({ platform, createMacPort, messages }: ResolveTranscriptionPortDeps): TranscriptionPort;
|
|
42
|
+
//# sourceMappingURL=transcription-port.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Return a port that reports a host-owned reason and rejects transcription. */
|
|
2
|
+
export function unavailablePort({ reason, message }) {
|
|
3
|
+
return {
|
|
4
|
+
isAvailable: async () => ({ available: false, reason }),
|
|
5
|
+
transcribe: async () => { throw new Error(message({ reason })); },
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
/** Select lazily so unsupported platforms never construct the native implementation. */
|
|
9
|
+
export function resolveTranscriptionPort({ platform, createMacPort, messages }) {
|
|
10
|
+
if (platform !== "darwin")
|
|
11
|
+
return unavailablePort({ reason: messages.unsupportedPlatform({ platform }), message: messages.unavailable });
|
|
12
|
+
return createMacPort();
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=transcription-port.js.map
|
|
@@ -13,11 +13,11 @@ import { createTauriShellPort } from './tauri-shell.js';
|
|
|
13
13
|
*/
|
|
14
14
|
export function createTauriDesktopHost(surfaces, overrides = {}) {
|
|
15
15
|
const ports = {
|
|
16
|
-
singleInstance: overrides.singleInstance ?? createTauriSingleInstanceLockPort(surfaces.singleInstance),
|
|
17
|
-
windowLifecycle: overrides.windowLifecycle ?? createTauriWindowLifecyclePort(surfaces.createWindow),
|
|
18
|
-
protocolHandler: overrides.protocolHandler ?? createTauriProtocolHandlerPort(),
|
|
19
|
-
sidecarLauncher: overrides.sidecarLauncher ?? createTauriSidecarLauncher(surfaces.sidecarCommands),
|
|
20
|
-
renderService: overrides.renderService ?? createTauriRenderService(),
|
|
16
|
+
singleInstance: overrides.singleInstance ?? createTauriSingleInstanceLockPort({ api: surfaces.singleInstance }),
|
|
17
|
+
windowLifecycle: overrides.windowLifecycle ?? createTauriWindowLifecyclePort({ createTauriWindow: surfaces.createWindow }),
|
|
18
|
+
protocolHandler: overrides.protocolHandler ?? createTauriProtocolHandlerPort({}),
|
|
19
|
+
sidecarLauncher: overrides.sidecarLauncher ?? createTauriSidecarLauncher({ api: surfaces.sidecarCommands }),
|
|
20
|
+
renderService: overrides.renderService ?? createTauriRenderService({}),
|
|
21
21
|
shell: overrides.shell ?? createTauriShellPort({ shell: surfaces.shell, fs: surfaces.fs, dialog: surfaces.dialog }),
|
|
22
22
|
};
|
|
23
23
|
return { backend: 'tauri', ports };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/desktop-host/tauri` — the full Tauri shell assembly. Split from the package's main
|
|
3
|
+
* `.` entry point (2026-07-29) so a Tauri app doesn't statically import the equally-full Electron
|
|
4
|
+
* assembly it will never call, and vice versa — mirrors `@jini-ai/agentic`'s `.`/`./dom` subpath
|
|
5
|
+
* precedent. The shared, shell-agnostic port types/utilities
|
|
6
|
+
* (`single-instance.ts`/`window-lifecycle.ts`/`protocol.ts`/`sidecar.ts`/`shell.ts`/`ports.ts`/etc.)
|
|
7
|
+
* stay at the package's main entry point; only the concrete Tauri implementation lives here.
|
|
8
|
+
*/
|
|
9
|
+
export * from './tauri-surfaces.js';
|
|
10
|
+
export * from './tauri-single-instance.js';
|
|
11
|
+
export * from './tauri-window-lifecycle.js';
|
|
12
|
+
export * from './tauri-protocol.js';
|
|
13
|
+
export * from './tauri-render-service.js';
|
|
14
|
+
export * from './tauri-shell.js';
|
|
15
|
+
export * from './tauri-sidecar.js';
|
|
16
|
+
export * from './create-tauri-desktop-host.js';
|
|
17
|
+
export * from './not-implemented.js';
|
|
18
|
+
export * from './testing.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|