@jini-ai/desktop-host 0.4.0 → 0.4.1

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # @jini-ai/desktop-host
2
2
 
3
+ ## 0.4.1 — 2026-10-04
4
+
5
+ - The macOS speech helper compiles asynchronously.
6
+ - Internal `@jini-ai/*` dependencies are caret ranges (`workspace:^`) instead of exact pins, so a host on a newer patch resolves a single copy without an override.
7
+
3
8
  ## 0.4.0 — 2026-10-02
4
9
 
5
10
  ### BREAKING
@@ -9,6 +14,8 @@
9
14
 
10
15
  ## Unreleased
11
16
 
17
+ - Compile the macOS speech helper through the asynchronous `execFileAsync` port, and await it in availability/transcription. Concurrent first-use calls share compilation so Electron's main thread stays responsive while Swift builds the helper.
18
+ - **BREAKING:** `ensureHelperCompiled` now returns `Promise<CompileResult>` and requires `execFileAsync`. Its optional legacy `spawnSync` dependency is accepted for source compatibility but never invoked.
12
19
  - Repair desktop-host test fixture types for filesystem options, legacy popup registration, mutable updater flags, single-instance notifications, IPC rejections and native toolchain errors without changing their assertions.
13
20
  - **BREAKING:** Replace `HostLogger` with core `Logger`; import the type from `@jini-ai/core/primitives`. File logging accepts the optional `error` bag and records its normalized value.
14
21
  - Accept native Electron navigation and electron-updater callback ABIs directly. Keep the existing object registrations as union members (`LegacyNavigableContents`, `LegacyUpdaterLike`) while hosts remove their glue.
@@ -40,10 +40,17 @@ interface TranscriberFs {
40
40
  }
41
41
  interface CompileDeps {
42
42
  fs: Pick<TranscriberFs, "existsSync" | "mkdirSync">;
43
- spawnSync: (args: {
43
+ /** @deprecated Accepted for host compatibility; never called. Use execFileAsync. */
44
+ spawnSync?: (args: {
44
45
  command: string;
45
46
  args: string[];
46
47
  }) => SpawnResult;
48
+ execFileAsync: (args: {
49
+ file: string;
50
+ args: string[];
51
+ }) => Promise<{
52
+ stdout: string;
53
+ }>;
47
54
  sourcePath: string;
48
55
  binaryPath: string;
49
56
  compilerPath: string;
@@ -58,12 +65,6 @@ type CompileResult = {
58
65
  };
59
66
  interface AvailabilityDeps extends CompileDeps {
60
67
  locale: string;
61
- execFileAsync: (args: {
62
- file: string;
63
- args: string[];
64
- }) => Promise<{
65
- stdout: string;
66
- }>;
67
68
  }
68
69
  interface MacTranscriberDeps extends AvailabilityDeps {
69
70
  fs: TranscriberFs;
@@ -77,8 +78,8 @@ interface HelperPayload {
77
78
  elapsedMs?: number;
78
79
  error?: string;
79
80
  }
80
- /** Compile once at the caller-supplied source and binary paths. */
81
- declare function ensureHelperCompiled({ fs, spawnSync, sourcePath, binaryPath, compilerPath, messages }: CompileDeps): CompileResult;
81
+ /** Compile once at the caller-supplied source and binary paths; retry after a failed attempt. */
82
+ declare function ensureHelperCompiled(deps: CompileDeps, _optionalArgs?: Record<string, never>): Promise<CompileResult>;
82
83
  /** Parse structured helper output and report malformed payloads with host wording. */
83
84
  declare function parseHelperJson({ stdout, invalidOutput }: {
84
85
  stdout: string;
@@ -8,20 +8,52 @@
8
8
  import path from "node:path";
9
9
  // An existing binary is a cache hit, not a rebuild check; remove the cached output after
10
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 };
11
+ // Availability and transcription can arrive together on first use. Share the compiler by output
12
+ // path within one filesystem port; separate injected filesystems must not share fake/cache state.
13
+ const compilations = new WeakMap();
14
+ /** Compile asynchronously so swiftc's first-use work cannot freeze an Electron main thread. */
15
+ async function compileHelper({ fs, execFileAsync, sourcePath, binaryPath, compilerPath, messages }) {
15
16
  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 };
17
+ try {
18
+ await execFileAsync({ file: compilerPath, args: ["-O", sourcePath, "-o", binaryPath] });
19
+ return { ok: true };
19
20
  }
20
- if (result.status !== 0) {
21
- const stderr = result.stderr ? result.stderr.toString() : "";
22
- return { ok: false, error: messages.compilerFailed({ stderr: stderr.trim() }) };
21
+ catch (error) {
22
+ const failure = error !== null && typeof error === "object"
23
+ ? error
24
+ : null;
25
+ if (failure?.code === "ENOENT")
26
+ return { ok: false, error: messages.compilerMissing };
27
+ const diagnostic = failure?.stderr;
28
+ const stderr = typeof diagnostic === "string" || Buffer.isBuffer(diagnostic)
29
+ ? diagnostic.toString().trim()
30
+ : "";
31
+ return { ok: false, error: messages.compilerFailed({ stderr }) };
32
+ }
33
+ }
34
+ /** Compile once at the caller-supplied source and binary paths; retry after a failed attempt. */
35
+ async function ensureHelperCompiled(deps, _optionalArgs = {}) {
36
+ let pendingByPath = compilations.get(deps.fs);
37
+ const key = path.resolve(deps.binaryPath);
38
+ const pending = pendingByPath?.get(key);
39
+ // swiftc may create its output before it exits. In-flight work takes precedence over existsSync,
40
+ // or a second caller could execute a partially linked binary while the first still compiles.
41
+ if (pending)
42
+ return pending;
43
+ if (deps.fs.existsSync({ path: deps.binaryPath }))
44
+ return { ok: true };
45
+ if (!pendingByPath) {
46
+ pendingByPath = new Map();
47
+ compilations.set(deps.fs, pendingByPath);
48
+ }
49
+ const compiling = compileHelper(deps);
50
+ pendingByPath.set(key, compiling);
51
+ try {
52
+ return await compiling;
53
+ }
54
+ finally {
55
+ pendingByPath.delete(key);
23
56
  }
24
- return { ok: true };
25
57
  }
26
58
  // Include the raw helper stdout in malformed-output errors so the payload is debuggable
27
59
  // without separately collecting a child-process log.
@@ -56,7 +88,7 @@ async function runHelperJson({ execFileAsync, binaryPath, args, messages }) {
56
88
  }
57
89
  /** Probe compiled helper capability without recording audio. */
58
90
  async function checkAvailability(deps) {
59
- const compiled = ensureHelperCompiled(deps);
91
+ const compiled = await ensureHelperCompiled(deps);
60
92
  if (!compiled.ok)
61
93
  return { available: false, reason: compiled.error };
62
94
  const result = await runHelperJson({ execFileAsync: deps.execFileAsync, binaryPath: deps.binaryPath, args: ["check", deps.locale], messages: deps.messages });
@@ -66,7 +98,7 @@ async function checkAvailability(deps) {
66
98
  }
67
99
  /** Transcribe scratch WAV input and remove the recording on every completion path. */
68
100
  async function transcribeWav({ wavBuffer, ...deps }) {
69
- const compiled = ensureHelperCompiled(deps);
101
+ const compiled = await ensureHelperCompiled(deps);
70
102
  if (!compiled.ok)
71
103
  throw new Error(deps.messages.cannotTranscribe({ reason: compiled.error }));
72
104
  const tempPath = deps.tempFilePath();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/desktop-host",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Shell-agnostic desktop-host ports: single-instance lock, window lifecycle, protocol handling, sidecar launch, paths, and config. Electron and Tauri assemblies live behind ./electron and ./tauri.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -106,7 +106,7 @@
106
106
  "registry": "https://registry.npmjs.org"
107
107
  },
108
108
  "dependencies": {
109
- "@jini-ai/core": "0.4.0"
109
+ "@jini-ai/core": "^0.4.0"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@vitest/coverage-v8": "^2.1.9"