@jini-ai/desktop-host 0.1.1 → 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 (185) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +194 -0
  3. package/dist/bridge-testing.d.ts +2 -2
  4. package/dist/bridge-testing.js +3 -3
  5. package/dist/bridge.d.ts +33 -9
  6. package/dist/bridge.js +18 -17
  7. package/dist/config.d.ts +1 -1
  8. package/dist/config.js +2 -1
  9. package/dist/electron/create-electron-desktop-host.js +5 -5
  10. package/dist/electron/electron-protocol.d.ts +3 -1
  11. package/dist/electron/electron-protocol.js +7 -7
  12. package/dist/electron/electron-render-service.d.ts +3 -1
  13. package/dist/electron/electron-render-service.js +21 -20
  14. package/dist/electron/electron-shell.js +8 -8
  15. package/dist/electron/electron-single-instance.d.ts +3 -1
  16. package/dist/electron/electron-single-instance.js +3 -3
  17. package/dist/electron/electron-surfaces.d.ts +71 -32
  18. package/dist/electron/electron-surfaces.js +3 -10
  19. package/dist/electron/electron-window-lifecycle.d.ts +3 -1
  20. package/dist/electron/electron-window-lifecycle.js +17 -16
  21. package/dist/electron/index.d.ts +17 -0
  22. package/dist/electron/index.js +17 -0
  23. package/dist/electron/navigation-policy/index.d.ts +3 -0
  24. package/dist/electron/navigation-policy/index.js +3 -0
  25. package/dist/electron/navigation-policy/webview-guest-policy.d.ts +32 -0
  26. package/dist/electron/navigation-policy/webview-guest-policy.js +31 -0
  27. package/dist/electron/navigation-policy/window-navigation-policy.d.ts +125 -0
  28. package/dist/electron/navigation-policy/window-navigation-policy.js +138 -0
  29. package/dist/electron/testing.d.ts +8 -6
  30. package/dist/electron/testing.js +22 -22
  31. package/dist/electron/updates/auto-update-controller.d.ts +146 -0
  32. package/dist/electron/updates/auto-update-controller.js +222 -0
  33. package/dist/electron/updates/index.d.ts +4 -0
  34. package/dist/electron/updates/index.js +4 -0
  35. package/dist/electron/updates/instance-presence.d.ts +68 -0
  36. package/dist/electron/updates/instance-presence.js +79 -0
  37. package/dist/electron/updates/update-policy.d.ts +66 -0
  38. package/dist/electron/updates/update-policy.js +65 -0
  39. package/dist/electron/usability/find-in-page-ipc.d.ts +88 -0
  40. package/dist/electron/usability/find-in-page-ipc.js +22 -0
  41. package/dist/electron/usability/find-menu.d.ts +43 -0
  42. package/dist/electron/usability/find-menu.js +22 -0
  43. package/dist/electron/usability/index.d.ts +6 -0
  44. package/dist/electron/usability/index.js +6 -0
  45. package/dist/electron/usability/spellcheck-menu.d.ts +92 -0
  46. package/dist/electron/usability/spellcheck-menu.js +52 -0
  47. package/dist/electron/usability/window-bounds-store.d.ts +76 -0
  48. package/dist/electron/usability/window-bounds-store.js +44 -0
  49. package/dist/electron/usability/zoom-menu.d.ts +41 -0
  50. package/dist/electron/usability/zoom-menu.js +19 -0
  51. package/dist/index.d.ts +8 -16
  52. package/dist/index.js +8 -16
  53. package/dist/logging.d.ts +26 -12
  54. package/dist/logging.js +21 -21
  55. package/dist/node-toolchain/index.d.ts +76 -0
  56. package/dist/node-toolchain/index.js +96 -0
  57. package/dist/paths.d.ts +4 -2
  58. package/dist/paths.js +5 -4
  59. package/dist/protocol.d.ts +20 -5
  60. package/dist/protocol.js +5 -5
  61. package/dist/render-service.d.ts +31 -7
  62. package/dist/render-service.js +10 -10
  63. package/dist/shell.d.ts +15 -7
  64. package/dist/shell.js +3 -3
  65. package/dist/shutdown/index.d.ts +4 -0
  66. package/dist/shutdown/index.js +4 -0
  67. package/dist/shutdown/quit-drain-gate.d.ts +19 -0
  68. package/dist/shutdown/quit-drain-gate.js +15 -0
  69. package/dist/shutdown/quit-signals.d.ts +36 -0
  70. package/dist/shutdown/quit-signals.js +27 -0
  71. package/dist/shutdown/shutdown-tracker.d.ts +19 -0
  72. package/dist/shutdown/shutdown-tracker.js +26 -0
  73. package/dist/sidecar.d.ts +20 -8
  74. package/dist/sidecar.js +39 -22
  75. package/dist/single-instance.d.ts +13 -4
  76. package/dist/single-instance.js +4 -4
  77. package/dist/speech/channels.d.ts +8 -0
  78. package/dist/speech/channels.js +5 -0
  79. package/dist/speech/index.d.ts +5 -0
  80. package/dist/speech/index.js +5 -0
  81. package/dist/speech/macos/index.d.ts +2 -0
  82. package/dist/speech/macos/index.js +2 -0
  83. package/dist/speech/macos/mac-on-device-transcriber.d.ts +97 -0
  84. package/dist/speech/macos/mac-on-device-transcriber.js +95 -0
  85. package/dist/speech/macos/speech-helper.swift +157 -0
  86. package/dist/speech/pcm-wav-encoder.d.ts +22 -0
  87. package/dist/speech/pcm-wav-encoder.js +50 -0
  88. package/dist/speech/speech-bridge.d.ts +33 -0
  89. package/dist/speech/speech-bridge.js +14 -0
  90. package/dist/speech/speech-ipc.d.ts +44 -0
  91. package/dist/speech/speech-ipc.js +50 -0
  92. package/dist/speech/transcription-port.d.ts +42 -0
  93. package/dist/speech/transcription-port.js +14 -0
  94. package/dist/tauri/create-tauri-desktop-host.js +5 -5
  95. package/dist/tauri/index.d.ts +19 -0
  96. package/dist/tauri/index.js +19 -0
  97. package/dist/tauri/not-implemented.d.ts +3 -1
  98. package/dist/tauri/not-implemented.js +1 -1
  99. package/dist/tauri/tauri-protocol.d.ts +1 -1
  100. package/dist/tauri/tauri-protocol.js +2 -2
  101. package/dist/tauri/tauri-render-service.d.ts +1 -1
  102. package/dist/tauri/tauri-render-service.js +2 -2
  103. package/dist/tauri/tauri-shell.js +8 -8
  104. package/dist/tauri/tauri-sidecar.d.ts +3 -1
  105. package/dist/tauri/tauri-sidecar.js +17 -16
  106. package/dist/tauri/tauri-single-instance.d.ts +3 -1
  107. package/dist/tauri/tauri-single-instance.js +3 -3
  108. package/dist/tauri/tauri-surfaces.d.ts +50 -14
  109. package/dist/tauri/tauri-surfaces.js +2 -1
  110. package/dist/tauri/tauri-window-lifecycle.d.ts +3 -1
  111. package/dist/tauri/tauri-window-lifecycle.js +33 -20
  112. package/dist/tauri/testing.d.ts +10 -7
  113. package/dist/tauri/testing.js +30 -23
  114. package/dist/tokens.js +6 -6
  115. package/dist/window-lifecycle.d.ts +10 -4
  116. package/dist/window-lifecycle.js +7 -7
  117. package/dist/windows-registry.d.ts +16 -6
  118. package/dist/windows-registry.js +8 -7
  119. package/package.json +73 -6
  120. package/dist/bridge-testing.d.ts.map +0 -1
  121. package/dist/bridge-testing.js.map +0 -1
  122. package/dist/bridge.d.ts.map +0 -1
  123. package/dist/bridge.js.map +0 -1
  124. package/dist/config.d.ts.map +0 -1
  125. package/dist/config.js.map +0 -1
  126. package/dist/electron/create-electron-desktop-host.d.ts.map +0 -1
  127. package/dist/electron/create-electron-desktop-host.js.map +0 -1
  128. package/dist/electron/electron-protocol.d.ts.map +0 -1
  129. package/dist/electron/electron-protocol.js.map +0 -1
  130. package/dist/electron/electron-render-service.d.ts.map +0 -1
  131. package/dist/electron/electron-render-service.js.map +0 -1
  132. package/dist/electron/electron-shell.d.ts.map +0 -1
  133. package/dist/electron/electron-shell.js.map +0 -1
  134. package/dist/electron/electron-single-instance.d.ts.map +0 -1
  135. package/dist/electron/electron-single-instance.js.map +0 -1
  136. package/dist/electron/electron-surfaces.d.ts.map +0 -1
  137. package/dist/electron/electron-surfaces.js.map +0 -1
  138. package/dist/electron/electron-window-lifecycle.d.ts.map +0 -1
  139. package/dist/electron/electron-window-lifecycle.js.map +0 -1
  140. package/dist/electron/testing.d.ts.map +0 -1
  141. package/dist/electron/testing.js.map +0 -1
  142. package/dist/index.d.ts.map +0 -1
  143. package/dist/index.js.map +0 -1
  144. package/dist/logging.d.ts.map +0 -1
  145. package/dist/logging.js.map +0 -1
  146. package/dist/paths.d.ts.map +0 -1
  147. package/dist/paths.js.map +0 -1
  148. package/dist/ports.d.ts.map +0 -1
  149. package/dist/ports.js.map +0 -1
  150. package/dist/protocol.d.ts.map +0 -1
  151. package/dist/protocol.js.map +0 -1
  152. package/dist/render-service.d.ts.map +0 -1
  153. package/dist/render-service.js.map +0 -1
  154. package/dist/shell.d.ts.map +0 -1
  155. package/dist/shell.js.map +0 -1
  156. package/dist/sidecar.d.ts.map +0 -1
  157. package/dist/sidecar.js.map +0 -1
  158. package/dist/single-instance.d.ts.map +0 -1
  159. package/dist/single-instance.js.map +0 -1
  160. package/dist/tauri/create-tauri-desktop-host.d.ts.map +0 -1
  161. package/dist/tauri/create-tauri-desktop-host.js.map +0 -1
  162. package/dist/tauri/not-implemented.d.ts.map +0 -1
  163. package/dist/tauri/not-implemented.js.map +0 -1
  164. package/dist/tauri/tauri-protocol.d.ts.map +0 -1
  165. package/dist/tauri/tauri-protocol.js.map +0 -1
  166. package/dist/tauri/tauri-render-service.d.ts.map +0 -1
  167. package/dist/tauri/tauri-render-service.js.map +0 -1
  168. package/dist/tauri/tauri-shell.d.ts.map +0 -1
  169. package/dist/tauri/tauri-shell.js.map +0 -1
  170. package/dist/tauri/tauri-sidecar.d.ts.map +0 -1
  171. package/dist/tauri/tauri-sidecar.js.map +0 -1
  172. package/dist/tauri/tauri-single-instance.d.ts.map +0 -1
  173. package/dist/tauri/tauri-single-instance.js.map +0 -1
  174. package/dist/tauri/tauri-surfaces.d.ts.map +0 -1
  175. package/dist/tauri/tauri-surfaces.js.map +0 -1
  176. package/dist/tauri/tauri-window-lifecycle.d.ts.map +0 -1
  177. package/dist/tauri/tauri-window-lifecycle.js.map +0 -1
  178. package/dist/tauri/testing.d.ts.map +0 -1
  179. package/dist/tauri/testing.js.map +0 -1
  180. package/dist/tokens.d.ts.map +0 -1
  181. package/dist/tokens.js.map +0 -1
  182. package/dist/window-lifecycle.d.ts.map +0 -1
  183. package/dist/window-lifecycle.js.map +0 -1
  184. package/dist/windows-registry.d.ts.map +0 -1
  185. package/dist/windows-registry.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,106 @@
1
+ # @jini-ai/desktop-host
2
+
3
+ ## 0.4.0 — 2026-10-02
4
+
5
+ ### BREAKING
6
+
7
+ - Desktop clocks/logging adopt core ports; native updater/navigation ABIs replace custom wrappers. Native macOS speech source remains an explicit runtime export.
8
+ - Distribution includes runtime output, release documentation and required assets only. Process records and per-job neutrality checks are no longer part of the package surface.
9
+
10
+ ## Unreleased
11
+
12
+ - 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
+ - **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
+ - 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.
15
+ - Controller clocks use core `Clock`, with the legacy `now` callback retained. Export `createElectronUpdaterAdapter`, `createNodeUpdateTimers`, `defaultUpdateMessages` and `defaultUpdateTiming`. Node timers and reference timing/copy are defaults; hosts may override them in parameter two. Reference timeout values are unchanged.
16
+
17
+
18
+ ### Desktop host integration
19
+
20
+ - Publish `./electron/usability`, `./speech`, and `./speech/macos` alongside
21
+ `./shutdown`, `./electron/navigation-policy`, `./electron/updates`, and
22
+ `./node-toolchain`. Declare all subpath runtimes and ship the native Swift helper
23
+ at `./speech/macos/speech-helper.swift`; the build copies it into `dist`.
24
+ - **BREAKING:** Existing functions, factories, constructors, and injected
25
+ Electron/Tauri/filesystem/timer ports now take a required-arguments object and
26
+ an optional-arguments object. Optional-only APIs take `{}` first; zero-input
27
+ lifecycle methods remain parameterless. Export names are preserved and only the updater/navigation migration above retains legacy registration unions. Bridge validation narrows `args.value`;
28
+ file loggers accept an optional object-argument append port.
29
+ - **BREAKING:** Usability and speech ports, menu callbacks, sender guards, path
30
+ joiners, and native transcriber process/filesystem bindings use object arguments
31
+ too. Host adapters translate native callbacks and preserve IPC channel payloads.
32
+ Add package integration contracts and adapt the generalized characterization
33
+ fixtures without changing their behavioral assertions.
34
+ - No version or dependency changes. Verification is not run by owner directive.
35
+
36
+
37
+ - Add `./shutdown`, `./electron/navigation-policy`, `./electron/updates`, and
38
+ `./node-toolchain` with required input objects and injected host ports. Updates
39
+ permit multiple running instances and install only when no sibling remains.
40
+ Existing exports and version remain unchanged.
41
+ - Add generalized policy and adapter tests, deterministic timer/failure cases,
42
+ and a runtime-source neutrality guard.
43
+
44
+ ## 0.1.2
45
+
46
+ ### Patch Changes
47
+
48
+ - Add top-level `main`/`types` fields alongside the existing `exports` map. A consumer on
49
+ TypeScript's classic `moduleResolution: "node"` (node10) — which ignores `package.json#exports`
50
+ entirely — could not resolve this package's types at all (`TS2307: Cannot find module`) even
51
+ after the previous exports-map fix restored `require()` at runtime; type resolution and runtime
52
+ resolution are separate algorithms. Verified against a real external consumer (whose
53
+ tsconfig uses this legacy resolution mode): adding these two fields, with its tsconfig completely
54
+ unchanged, made the error disappear. Also fixes absolute-path `require()` (distinct from a bare
55
+ specifier, which already worked) for the same reason — `main` was previously absent.
56
+
57
+ Purely additive: every modern resolver (Node's own runtime `exports` resolution, TypeScript's
58
+ `bundler`/`node16`/`nodenext`) prefers `exports` over `main`/`types` when both are present, so
59
+ this changes nothing for a consumer already on a modern resolver.
60
+
61
+ - Updated dependencies
62
+ - @jini-ai/core@0.1.2
63
+
64
+ ## 0.1.1
65
+
66
+ ### Patch Changes
67
+
68
+ - Add a `"default"` export condition to every published package's `exports` map — every one of
69
+ them lacked it, which meant `require()` failed with `ERR_PACKAGE_PATH_NOT_EXPORTED` for any
70
+ CommonJS consumer (found via a real external integration attempt; Node needs `require(esm)`
71
+ support, i.e. Node >=22.12, for this to resolve).
72
+
73
+ `@jini-ai/agent-runtime`:
74
+
75
+ - **New**: `RuntimeBuildOptions.permissionMode` (`'bypass' | 'restricted'`) lets a caller opt a
76
+ run OUT of the auto-approve-every-permission-prompt flag every def with one
77
+ (`bypassPermissions` / `--yolo` / `--dangerously-skip-permissions`) previously pushed
78
+ unconditionally, with no way to turn it off. Omitting it keeps today's default (bypass)
79
+ behavior unchanged.
80
+ - **New**: `ClaudeStreamEvent`, `CopilotStreamEvent`, and `QoderEvent` are now real exported
81
+ discriminated unions instead of `Record<string, unknown>` — a real external consumer guessed a
82
+ nonexistent field name (`event.text` instead of the actual `event.delta`) against the old
83
+ untyped sink and silently lost every streamed token with no compile or runtime error.
84
+ - Fixed a doc/implementation mismatch in `claude-stream.ts`: the module doc claimed `tool_result`
85
+ events carry `{ tool_use_id, content, is_error }`; the actual emitted shape is
86
+ `{ toolUseId, content, isError }`.
87
+
88
+ `@jini-ai/daemon`: `AgentExecutorRunInput.permissionMode` forwards the new
89
+ `RuntimeBuildOptions.permissionMode` through to `buildArgs`, so a host can actually reach the new
90
+ opt-out from the daemon's real run-input surface, not just from `@jini-ai/agent-runtime` in
91
+ isolation.
92
+
93
+ `@jini-ai/agentic`: `setAtPointer` no longer throws on a malformed (e.g. missing leading `/`)
94
+ `updateDataModel` path — degrades to a no-op like its sibling `getAtPointer`, matching this
95
+ package's own "a bad binding must not crash the renderer" contract. That path is agent-authored
96
+ wire data with no error boundary above it in any host, so the uncaught throw could unmount an
97
+ entire chat UI from ~40 bytes of malformed input.
98
+
99
+ `@jini-ai/chat-react`: a local (client-resolved) A2UI button action is no longer a silent no-op —
100
+ `A2uiSurfaceCard` now surfaces the resolved value. New `ExtEventErrorBoundary` confines a
101
+ `kind: 'ext'` event group's renderer to its own card instead of letting a render/effect-phase
102
+ throw from agent-controlled content unmount the whole chat root (there was no error boundary
103
+ anywhere in this package or its hosts before this).
104
+
105
+ - Updated dependencies
106
+ - @jini-ai/core@0.1.1
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # `@jini-ai/desktop-host`
2
+
3
+ The shell-agnostic half of a desktop app: six ports covering the things every Electron or Tauri
4
+ wrapper has to do — hold a single-instance lock, track the main window's lifecycle, handle a custom
5
+ URL scheme, launch and supervise a sidecar process, run a headless render service, and open external
6
+ URLs/paths/folder pickers. The root entry point is the port set plus shared utilities (paths, config
7
+ loading, logging, the `window.__jini__` host bridge). The concrete assemblies live behind `./electron`
8
+ and `./tauri`, so an Electron app never statically imports the Tauri implementation it will never
9
+ call. Note that the Tauri side is genuinely partial — its render service throws
10
+ `NotImplementedError`.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @jini-ai/desktop-host
16
+ ```
17
+
18
+ No peer dependencies, and — importantly — **no dependency on `electron` or `@tauri-apps/api`**. Both
19
+ assemblies take object-argument bindings for their native surfaces as injected objects (`ElectronAppLike`,
20
+ `ElectronBrowserWindowFactory`, `TauriWindowFactory`, …), so this package installs and typechecks with
21
+ neither framework present, and the whole shell is testable without launching one. `@jini-ai/core` is a
22
+ regular dependency, for the DI tokens.
23
+
24
+ ## What you get
25
+
26
+ **The port set** — `DesktopHostPorts` (`singleInstance`, `windowLifecycle`, `protocolHandler`,
27
+ `sidecarLauncher`, `renderService`, `shell`) and `DesktopHost` (`{ backend, ports }`), with the
28
+ individual port types `SingleInstanceLockPort`, `WindowLifecyclePort`, `ProtocolHandlerPort`,
29
+ `SidecarLauncherPort`, `RenderService`, `ShellPort`, plus their DI tokens
30
+ (`SingleInstanceLockToken`, `WindowLifecycleToken`, `ProtocolHandlerToken`, `SidecarLauncherToken`,
31
+ `RenderServiceToken`, `ShellToken`).
32
+
33
+ **Shell-agnostic implementations you can use directly** — `createNodeSidecarLauncher({})` and
34
+ `appendSidecarLifecycleLog` (a sidecar launcher needs no Electron at all),
35
+ `claimSingleInstanceLock` / `createSingleInstanceLockPort`, and `withMainWindowTracking`.
36
+
37
+ **Protocol handling** — `buildProtocolProxyTargetUrl`, `handleProtocolProxyRequest`,
38
+ `schemeEntryUrl` — the custom-scheme-to-local-daemon proxy every packaged app needs.
39
+
40
+ **Paths and config** — `resolveDesktopHostPathRoots(requiredArgs, optionalArgs?)` → `DesktopHostPathRoots`,
41
+ `DesktopHostPathError`, and `loadHostConfigFile<T>(...)`.
42
+
43
+ **Logging** — `createFileLogger`, `appendLogLine`, `installFatalExceptionHandlers`, and
44
+ `isHarmlessSocketOptionError` (the socket-teardown noise you do not want paging anyone).
45
+
46
+ **The host bridge** — the `window.__jini__` contract a renderer uses to detect and call its host:
47
+ `JINI_HOST_GLOBAL`, `JINI_HOST_VERSION`, `JINI_HOST_CLIENT_TYPES`, `JiniHostBridge`,
48
+ `isJiniHostBridge`, `getJiniHost`, `isJiniHostAvailable`, `detectJiniHostClientType` (returns
49
+ `'web'` when there is no host), `openHostExternalUrl`, `openHostPath`, and
50
+ `checkJiniHostUpdaterAvailability`. A separate `./bridge-testing` entry point provides
51
+ `createMockJiniHost` / `installMockJiniHost` for renderer tests.
52
+
53
+ **Windows integration** — `syncWindowsUninstallDisplayVersion`,
54
+ `windowsUninstallRegistryQueryArgs`, `windowsUninstallDisplayVersionRegistryArgs`.
55
+
56
+ **`./electron`** — `createElectronDesktopHost(surfaces, overrides?)` plus each port factory
57
+ individually (`createElectronSingleInstanceLockPort`, `createElectronWindowLifecyclePort`,
58
+ `createElectronProtocolHandlerPort`, `createElectronRenderService`, `createElectronShellPort`), the
59
+ `ElectronAppLike` / `ElectronBrowserWindowFactory` / `ElectronProtocolLike` / `ElectronShellLike` /
60
+ `ElectronDialogLike` surface interfaces, and fakes for all of them (`createFakeElectronApp`,
61
+ `createFakeBrowserWindowFactory`, `createFakeElectronProtocol`, `createFakeElectronShell`,
62
+ `createFakeElectronDialog`).
63
+
64
+ **`./tauri`** — `createTauriDesktopHost` and the matching per-port factories and fakes.
65
+ `createTauriRenderService` throws `NotImplementedError` — the Tauri backend is a real but incomplete
66
+ sibling, not a drop-in equal of the Electron one.
67
+
68
+ ## Argument convention
69
+
70
+ Public functions and constructors take a required-arguments object, followed by an optional-arguments object when needed. Functions with only optional values receive `{}` first. Port methods use the same convention. Existing export names stay the same; there are no compatibility overloads. Native Electron/Tauri modules must be bound to the exported object-argument interfaces before injection. Event callbacks deliver payloads in the object shapes documented by those interfaces.
71
+
72
+ See [API-CONVENTION.md](./API-CONVENTION.md) for the full before/after inventory and consumer ledger.
73
+
74
+ ## Usage
75
+
76
+ ```ts
77
+ import { createElectronDesktopHost } from '@jini-ai/desktop-host/electron';
78
+ import { createFileLogger, installFatalExceptionHandlers } from '@jini-ai/desktop-host';
79
+
80
+ const logger = createFileLogger({ logPath: '/Users/me/Library/Logs/example/main.log' }, { echoToConsole: true });
81
+ installFatalExceptionHandlers({ logger });
82
+
83
+ // Supply object-argument bindings around native Electron operations. See the
84
+ // exported Electron* interfaces for each binding's full contract.
85
+ const host = createElectronDesktopHost(electronPorts);
86
+
87
+ if (!host.ports.singleInstance.claim({ onSecondInstance: () => host.ports.windowLifecycle.showMainWindow() })) {
88
+ electronPorts.app.quit();
89
+ }
90
+
91
+ const window = await host.ports.windowLifecycle.createWindow({ url: 'https://example.test/' }, { width: 1024 });
92
+ const sidecar = await host.ports.sidecarLauncher.launch({ command: '/absolute/sidecar' }, { args: ['--port', '0'] });
93
+ ```
94
+
95
+ In the renderer, detect and call the host without importing any Electron code:
96
+
97
+ ```ts
98
+ import { detectJiniHostClientType, openHostExternalUrl } from '@jini-ai/desktop-host';
99
+
100
+ if (detectJiniHostClientType({}) !== 'web') {
101
+ await openHostExternalUrl({ url: 'https://example.com' });
102
+ }
103
+ ```
104
+
105
+ Read `DesktopHostPorts` and each port interface in `src/` for the full method sets and option shapes
106
+ before calling through. The ports are small: `SingleInstanceLockPort` is just `claim`,
107
+ `WindowLifecyclePort` is `createWindow` / `getMainWindow` / `showMainWindow`, and
108
+ `SidecarLauncherPort` is `launch`.
109
+
110
+ ## Entry points
111
+
112
+ | subpath | what's behind it | extra dep it pulls in |
113
+ |---|---|---|
114
+ | `.` | The six port interfaces + DI tokens, the shell-agnostic implementations (sidecar launcher, single-instance, protocol proxy), paths, config, logging, Windows registry helpers, and the `window.__jini__` bridge. | none |
115
+ | `./bridge-testing` | `createMockJiniHost` / `installMockJiniHost` for testing renderer code against the host bridge. | none |
116
+ | `./electron` | The full Electron assembly + per-port factories + fakes. | none — `electron` is injected, not imported |
117
+ | `./tauri` | The full Tauri assembly + per-port factories + fakes. `createTauriRenderService` throws `NotImplementedError`. | none — the Tauri API is injected, not imported |
118
+ | `./shutdown` | Pending teardown tracking, quit/drain decisions and signal routing. | none |
119
+ | `./electron/navigation-policy` | Window/renderer origin boundaries and guest admission. | none |
120
+ | `./electron/updates` | Updater policy/controller and file-backed multi-instance presence. | none |
121
+ | `./node-toolchain` | Node/npm/npx shims and caller-named environment variables. | none |
122
+ | `./electron/usability` | Find, zoom, spelling menus and remembered bounds through host ports. | none |
123
+ | `./speech` | Transcription contracts, mono PCM/WAV encoding, validated IPC and preload bridge. | none |
124
+ | `./speech/macos` | On-device helper compilation and transcription through filesystem/process ports. | none; host supplies Swift compiler |
125
+ | `./speech/macos/speech-helper.swift` | Native Swift source asset copied into the published dist tree. | none |
126
+
127
+
128
+ ## What's swappable
129
+
130
+ Nearly all of it. Every one of the six ports is an interface with a DI token, and
131
+ `createElectronDesktopHost(surfaces, overrides)` takes a `Partial<DesktopHostPorts>` second argument
132
+ so any single port can be replaced without abandoning the assembly. One level down, the *native
133
+ surfaces* are injected too — `ElectronAppLike`, `ElectronBrowserWindowFactory`, `TauriWindowFactory`
134
+ and friends are structural interfaces, which is why the shipped fakes can drive a complete host in a
135
+ plain unit test. `createFileLogger` returns core `Logger` that `installFatalExceptionHandlers`
136
+ accepts, so logging is replaceable too. Fixed: the `window.__jini__` bridge contract itself (that is a
137
+ wire contract between host and renderer), the protocol-proxy URL construction, and the path-root
138
+ resolution rules.
139
+
140
+ ## Runtime
141
+
142
+ `jini.runtime: "desktop"` — Node built-ins (`node:fs`, `node:child_process`, `node:path`) in the host
143
+ half; the bridge helpers are the exception and read only `globalThis`, so they run in a renderer.
144
+ ESM only — ships `"type": "module"` with no CommonJS `require` build. Electron's main process must be
145
+ configured for ESM to import it.
146
+
147
+ ## Provenance
148
+
149
+ See the archived provenance ledger for per-file provenance and scope decisions. Apache-2.0,
150
+ inherited from Open Design — see the repo `NOTICE`.
151
+
152
+ ## Desktop policies and speech
153
+
154
+ All additional entries keep application channels, labels, paths, locale, messages
155
+ and persistence keys in required objects supplied by the host. No dependency was
156
+ added. [API-USABILITY-SPEECH.md](./API-USABILITY-SPEECH.md) documents each usability
157
+ and speech function, injected port, native binding and asset location. The four
158
+ policy/toolchain subpaths are documented in [API.md](./API.md).
159
+
160
+ The root and native shell entry points retain their existing export names. The
161
+ object-argument conversion is a breaking caller change: bind native methods to the
162
+ exported port interfaces, including usability and speech callbacks, before injecting
163
+ SDK objects. Find/zoom renderer hooks remain application-owned pending a separate
164
+ React entry; the current additions cover main-process behavior and the speech bridge.
165
+
166
+ Verification for this integration is not run by owner directive. The exact per-file
167
+ commands and later consumer rewiring requests are in
168
+ [INTEGRATION-desktop-host.md](./INTEGRATION-desktop-host.md).
169
+
170
+ ## Native updater and navigation callbacks
171
+
172
+ `./electron/updates` accepts the structural native electron-updater surface directly: `on(event, listener)` and `quitAndInstall(isSilent?, isForceRunAfter?)`. `createElectronUpdaterAdapter({ updater })` forwards mutable flags and retains the native receiver without importing Electron. Controllers take a core `Clock` in `clock`; effects remain required. Timer, timing and message overrides go in the second options object:
173
+
174
+ ```ts
175
+ import { createSystemClock } from '@jini-ai/core/primitives';
176
+ import { createAutoUpdateController } from '@jini-ai/desktop-host/electron/updates';
177
+
178
+ const controller = createAutoUpdateController({
179
+ updater, platform, pid, presence, clock: createSystemClock(),
180
+ promptUpdateReady, explainOthersOpen, quit, log,
181
+ }, { timing: { firstCheckDelayMs: 30_000 } });
182
+ ```
183
+
184
+ The default Node timer adapter is also exported as `createNodeUpdateTimers()`. Default timing is 30 seconds before the first check, 15-minute ticks, four-hour checks, 45-minute stale presence and a two-minute install fallback. Partial timing overrides inherit the other values. `defaultUpdateMessages` is the single exported controller copy object; a host can replace it as a whole through `options.messages`. Options override legacy settings in the dependency object.
185
+
186
+ `./electron/navigation-policy` accepts raw `webContents`, including `setWindowOpenHandler(handler)` and native navigation/redirect listeners. Origin and scheme checks stay the same.
187
+
188
+ `UpdaterLike` and `NavigableContents` are unions with the existing object registration types, exported as `LegacyUpdaterLike` and `LegacyNavigableContents`. The legacy controller `now` callback and dependency-object timers/timing/messages also remain accepted during migration. Native `on` implementations have two parameters (or a rest tuple); the old object registration has one. Custom one-parameter native updater facades should use `createElectronUpdaterAdapter`. Popup-only contents receive a callable handler that also supports the old `{ handler }` destructuring ABI. Hosts can remove their registration wrappers when ready.
189
+
190
+ File logging uses core `Logger`; `error` in the optional bag is normalized into the JSON metadata alongside `meta`, consistently across all three levels.
191
+
192
+ ## Native speech runtime asset
193
+
194
+ `@jini-ai/desktop-host/speech/macos/speech-helper.swift` exports the Swift source used by the macOS speech adapter. The build copies it into `dist/speech/macos`; desktop hosts bundle or compile that source on macOS alongside the adapter. It is a required runtime asset, not a TypeScript entry.
@@ -11,6 +11,6 @@ export interface MockJiniHostOptions {
11
11
  host?: MockJiniHost;
12
12
  scope?: JiniHostGlobalScope;
13
13
  }
14
- export declare function createMockJiniHost(overrides?: MockJiniHost): JiniHostBridge;
15
- export declare function installMockJiniHost(options?: MockJiniHostOptions): () => void;
14
+ export declare function createMockJiniHost(_requiredArgs: Record<string, never>, overrides?: MockJiniHost): JiniHostBridge;
15
+ export declare function installMockJiniHost(_requiredArgs: Record<string, never>, options?: MockJiniHostOptions): () => void;
16
16
  //# sourceMappingURL=bridge-testing.d.ts.map
@@ -13,7 +13,7 @@ function defaultHost() {
13
13
  },
14
14
  };
15
15
  }
16
- export function createMockJiniHost(overrides = {}) {
16
+ export function createMockJiniHost(_requiredArgs, overrides = {}) {
17
17
  const base = defaultHost();
18
18
  return {
19
19
  ...base,
@@ -22,9 +22,9 @@ export function createMockJiniHost(overrides = {}) {
22
22
  shell: { ...base.shell, ...overrides.shell },
23
23
  };
24
24
  }
25
- export function installMockJiniHost(options = {}) {
25
+ export function installMockJiniHost(_requiredArgs, options = {}) {
26
26
  const scope = (options.scope ?? globalThis);
27
- const host = createMockJiniHost(options.host);
27
+ const host = createMockJiniHost({}, options.host);
28
28
  const windowValue = scope.window;
29
29
  const targets = [
30
30
  scope,
package/dist/bridge.d.ts CHANGED
@@ -65,19 +65,43 @@ export interface JiniHostBridge {
65
65
  version: typeof JINI_HOST_VERSION;
66
66
  client: JiniHostClient;
67
67
  shell: {
68
- openExternal(url: string): Promise<JiniHostActionResult>;
69
- openPath(path: string): Promise<JiniHostActionResult>;
68
+ openExternal({ url }: {
69
+ url: string;
70
+ }): Promise<JiniHostActionResult>;
71
+ openPath({ path }: {
72
+ path: string;
73
+ }): Promise<JiniHostActionResult>;
70
74
  };
71
75
  updater?: JiniHostUpdaterNamespace;
72
76
  }
73
77
  export type JiniHostGlobalScope = Record<string, unknown> & {
74
78
  window?: unknown;
75
79
  };
76
- export declare function isJiniHostBridge(value: unknown): value is JiniHostBridge;
77
- export declare function getJiniHost(scope?: JiniHostGlobalScope): JiniHostBridge | null;
78
- export declare function isJiniHostAvailable(scope?: JiniHostGlobalScope): boolean;
79
- export declare function detectJiniHostClientType(scope?: JiniHostGlobalScope): JiniHostClientType | 'web';
80
- export declare function openHostExternalUrl(url: string, scope?: JiniHostGlobalScope): Promise<JiniHostActionResult>;
81
- export declare function openHostPath(path: string, scope?: JiniHostGlobalScope): Promise<JiniHostActionResult>;
82
- export declare function checkJiniHostUpdaterAvailability(scope?: JiniHostGlobalScope): Promise<JiniHostUpdaterAvailability | JiniHostFailure>;
80
+ export declare function isJiniHostBridge(requiredArgs: {
81
+ value: unknown;
82
+ }): requiredArgs is {
83
+ value: JiniHostBridge;
84
+ };
85
+ export declare function getJiniHost(_requiredArgs: Record<string, never>, { scope }?: {
86
+ scope?: JiniHostGlobalScope;
87
+ }): JiniHostBridge | null;
88
+ export declare function isJiniHostAvailable(_requiredArgs: Record<string, never>, { scope }?: {
89
+ scope?: JiniHostGlobalScope;
90
+ }): boolean;
91
+ export declare function detectJiniHostClientType(_requiredArgs: Record<string, never>, { scope }?: {
92
+ scope?: JiniHostGlobalScope;
93
+ }): JiniHostClientType | 'web';
94
+ export declare function openHostExternalUrl({ url }: {
95
+ url: string;
96
+ }, { scope }?: {
97
+ scope?: JiniHostGlobalScope;
98
+ }): Promise<JiniHostActionResult>;
99
+ export declare function openHostPath({ path }: {
100
+ path: string;
101
+ }, { scope }?: {
102
+ scope?: JiniHostGlobalScope;
103
+ }): Promise<JiniHostActionResult>;
104
+ export declare function checkJiniHostUpdaterAvailability(_requiredArgs: Record<string, never>, { scope }?: {
105
+ scope?: JiniHostGlobalScope;
106
+ }): Promise<JiniHostUpdaterAvailability | JiniHostFailure>;
83
107
  //# sourceMappingURL=bridge.d.ts.map
package/dist/bridge.js CHANGED
@@ -47,14 +47,15 @@ function hasFunction(record, key) {
47
47
  // that file (and every call site here) only ever supplies `reason` — the
48
48
  // `details` plumbing is exercised solely by OD's `normalize.ts` (a
49
49
  // project-import-result normalizer, an explicitly out-of-scope OD product
50
- // concept per source-map.md). With no caller in this file ever passing
50
+ // concept per archived provenance ledger). With no caller in this file ever passing
51
51
  // `details`, keeping the parameter here would be untestable dead code, so
52
52
  // it's dropped; `JiniHostFailure.details` remains part of the public type
53
53
  // for any external implementer that wants to populate it directly.
54
54
  function failure(reason) {
55
55
  return { ok: false, reason };
56
56
  }
57
- export function isJiniHostBridge(value) {
57
+ export function isJiniHostBridge(requiredArgs) {
58
+ const { value } = requiredArgs;
58
59
  if (!isRecord(value))
59
60
  return false;
60
61
  if (value.version !== JINI_HOST_VERSION)
@@ -87,43 +88,43 @@ function candidateFromScope(scope) {
87
88
  return windowValue[JINI_HOST_GLOBAL];
88
89
  return undefined;
89
90
  }
90
- export function getJiniHost(scope = globalThis) {
91
- const candidate = candidateFromScope(scope);
92
- return isJiniHostBridge(candidate) ? candidate : null;
91
+ export function getJiniHost(_requiredArgs, { scope = globalThis } = {}) {
92
+ const candidate = { value: candidateFromScope(scope) };
93
+ return isJiniHostBridge(candidate) ? candidate.value : null;
93
94
  }
94
- export function isJiniHostAvailable(scope = globalThis) {
95
- return getJiniHost(scope) != null;
95
+ export function isJiniHostAvailable(_requiredArgs, { scope = globalThis } = {}) {
96
+ return getJiniHost({}, { scope }) != null;
96
97
  }
97
- export function detectJiniHostClientType(scope = globalThis) {
98
- return getJiniHost(scope)?.client.type ?? 'web';
98
+ export function detectJiniHostClientType(_requiredArgs, { scope = globalThis } = {}) {
99
+ return getJiniHost({}, { scope })?.client.type ?? 'web';
99
100
  }
100
101
  function unavailable(reason = 'jini host is not available') {
101
102
  return failure(reason);
102
103
  }
103
- export async function openHostExternalUrl(url, scope = globalThis) {
104
- const host = getJiniHost(scope);
104
+ export async function openHostExternalUrl({ url }, { scope = globalThis } = {}) {
105
+ const host = getJiniHost({}, { scope });
105
106
  if (host == null)
106
107
  return unavailable();
107
108
  try {
108
- return await host.shell.openExternal(url);
109
+ return await host.shell.openExternal({ url });
109
110
  }
110
111
  catch (error) {
111
112
  return unavailable(error instanceof Error ? error.message : String(error));
112
113
  }
113
114
  }
114
- export async function openHostPath(path, scope = globalThis) {
115
- const host = getJiniHost(scope);
115
+ export async function openHostPath({ path }, { scope = globalThis } = {}) {
116
+ const host = getJiniHost({}, { scope });
116
117
  if (host == null)
117
118
  return unavailable();
118
119
  try {
119
- return await host.shell.openPath(path);
120
+ return await host.shell.openPath({ path });
120
121
  }
121
122
  catch (error) {
122
123
  return unavailable(error instanceof Error ? error.message : String(error));
123
124
  }
124
125
  }
125
- export async function checkJiniHostUpdaterAvailability(scope = globalThis) {
126
- const host = getJiniHost(scope);
126
+ export async function checkJiniHostUpdaterAvailability(_requiredArgs, { scope = globalThis } = {}) {
127
+ const host = getJiniHost({}, { scope });
127
128
  if (host == null)
128
129
  return unavailable();
129
130
  if (host.updater == null)
package/dist/config.d.ts CHANGED
@@ -3,5 +3,5 @@ export interface LoadHostConfigFileOptions {
3
3
  candidatePaths: string[];
4
4
  env?: NodeJS.ProcessEnv;
5
5
  }
6
- export declare function loadHostConfigFile<T extends Record<string, unknown>>(options: LoadHostConfigFileOptions): Promise<T>;
6
+ export declare function loadHostConfigFile<T extends Record<string, unknown>>(requiredArgs: Pick<LoadHostConfigFileOptions, 'candidatePaths'>, optionalArgs?: Omit<LoadHostConfigFileOptions, 'candidatePaths'>): Promise<T>;
7
7
  //# sourceMappingURL=config.d.ts.map
package/dist/config.js CHANGED
@@ -25,7 +25,8 @@ async function readJsonIfExists(filePath) {
25
25
  return null;
26
26
  return JSON.parse(await readFile(filePath, 'utf8'));
27
27
  }
28
- export async function loadHostConfigFile(options) {
28
+ export async function loadHostConfigFile(requiredArgs, optionalArgs = {}) {
29
+ const options = { ...optionalArgs, ...requiredArgs };
29
30
  const env = options.env ?? process.env;
30
31
  const explicit = options.explicitPathEnvVar == null ? undefined : env[options.explicitPathEnvVar];
31
32
  if (explicit != null && explicit.length > 0) {
@@ -6,11 +6,11 @@ import { createElectronRenderService } from './electron-render-service.js';
6
6
  import { createElectronShellPort } from './electron-shell.js';
7
7
  export function createElectronDesktopHost(surfaces, overrides = {}) {
8
8
  const ports = {
9
- singleInstance: overrides.singleInstance ?? createElectronSingleInstanceLockPort(surfaces.app),
10
- windowLifecycle: overrides.windowLifecycle ?? createElectronWindowLifecyclePort(surfaces.createBrowserWindow),
11
- protocolHandler: overrides.protocolHandler ?? createElectronProtocolHandlerPort(surfaces.protocol),
12
- sidecarLauncher: overrides.sidecarLauncher ?? createNodeSidecarLauncher(),
13
- renderService: overrides.renderService ?? createElectronRenderService(surfaces.createBrowserWindow),
9
+ singleInstance: overrides.singleInstance ?? createElectronSingleInstanceLockPort({ app: surfaces.app }),
10
+ windowLifecycle: overrides.windowLifecycle ?? createElectronWindowLifecyclePort({ createBrowserWindow: surfaces.createBrowserWindow }),
11
+ protocolHandler: overrides.protocolHandler ?? createElectronProtocolHandlerPort({ electronProtocol: surfaces.protocol }),
12
+ sidecarLauncher: overrides.sidecarLauncher ?? createNodeSidecarLauncher({}),
13
+ renderService: overrides.renderService ?? createElectronRenderService({ createBrowserWindow: surfaces.createBrowserWindow }),
14
14
  shell: overrides.shell ?? createElectronShellPort({ shell: surfaces.shell, app: surfaces.app, dialog: surfaces.dialog }),
15
15
  };
16
16
  return { backend: 'electron', ports };
@@ -1,4 +1,6 @@
1
1
  import { type ProtocolHandlerPort } from '../protocol.js';
2
2
  import type { ElectronProtocolLike } from './electron-surfaces.js';
3
- export declare function createElectronProtocolHandlerPort(electronProtocol: ElectronProtocolLike): ProtocolHandlerPort;
3
+ export declare function createElectronProtocolHandlerPort({ electronProtocol }: {
4
+ electronProtocol: ElectronProtocolLike;
5
+ }): ProtocolHandlerPort;
4
6
  //# sourceMappingURL=electron-protocol.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import { handleProtocolProxyRequest, schemeEntryUrl } from '../protocol.js';
2
- export function createElectronProtocolHandlerPort(electronProtocol) {
2
+ export function createElectronProtocolHandlerPort({ electronProtocol }) {
3
3
  return {
4
- registerSchemeProxy(scheme, targetBaseUrl) {
5
- electronProtocol.registerSchemesAsPrivileged([
6
- { scheme, privileges: { standard: true, secure: true, corsEnabled: true, supportFetchAPI: true, stream: true } },
7
- ]);
8
- electronProtocol.handle(scheme, async (request) => handleProtocolProxyRequest(request, targetBaseUrl));
9
- return { scheme, entryUrl: schemeEntryUrl(scheme) };
4
+ registerSchemeProxy({ scheme, targetBaseUrl }) {
5
+ electronProtocol.registerSchemesAsPrivileged({ schemes: [
6
+ { scheme, privileges: { standard: true, secure: true, corsEnabled: true, supportFetchAPI: true, stream: true } },
7
+ ] });
8
+ electronProtocol.handle({ scheme, handler: async ({ request }) => handleProtocolProxyRequest({ request, targetBaseUrl }) });
9
+ return { scheme, entryUrl: schemeEntryUrl({ scheme }) };
10
10
  },
11
11
  };
12
12
  }
@@ -8,5 +8,7 @@
8
8
  */
9
9
  import { type RenderService } from '../render-service.js';
10
10
  import type { ElectronBrowserWindowFactory } from './electron-surfaces.js';
11
- export declare function createElectronRenderService(createBrowserWindow: ElectronBrowserWindowFactory): RenderService;
11
+ export declare function createElectronRenderService({ createBrowserWindow }: {
12
+ createBrowserWindow: ElectronBrowserWindowFactory;
13
+ }): RenderService;
12
14
  //# sourceMappingURL=electron-render-service.d.ts.map
@@ -9,25 +9,26 @@
9
9
  import { RenderServiceError, htmlToDataUrl, isOriginAllowed, withRenderTimeout, } from '../render-service.js';
10
10
  function waitForLoad(webContents) {
11
11
  return new Promise((resolve, reject) => {
12
- webContents.once('did-finish-load', () => resolve());
13
- webContents.once('did-fail-load', (_event, errorCode, errorDescription) => {
14
- reject(new RenderServiceError(`failed to load render document: ${errorDescription} (${errorCode})`, 'load-failed'));
15
- });
12
+ webContents.once({ event: 'did-finish-load', listener: () => resolve() });
13
+ webContents.once({ event: 'did-fail-load', listener: ({ errorCode, errorDescription }) => {
14
+ reject(new RenderServiceError({ message: `failed to load render document: ${errorDescription} (${errorCode})`, code: 'load-failed' }));
15
+ } });
16
16
  });
17
17
  }
18
18
  function attachResourcePolicy(webContents, policy) {
19
19
  if (policy?.allowNavigation !== true) {
20
- webContents.on('will-navigate', (event) => event.preventDefault());
21
- }
22
- if (policy?.allowedOrigins != null) {
23
- const allowedOrigins = policy.allowedOrigins;
24
- webContents.session.webRequest.onBeforeRequest((details, callback) => {
25
- callback({ cancel: !isOriginAllowed(details.url, allowedOrigins) });
26
- });
20
+ webContents.on({ event: 'will-navigate', listener: ({ event }) => event.preventDefault() });
27
21
  }
22
+ // Omitted origins are an empty allowlist. Permissive rendering requires an explicit opt-out.
23
+ webContents.session.webRequest.onBeforeRequest({ listener: ({ details, callback }) => {
24
+ callback({ cancel: !isOriginAllowed({ url: details.url }, {
25
+ allowedOrigins: policy?.allowedOrigins,
26
+ allowUnrestrictedNetwork: policy?.allowUnrestrictedNetwork,
27
+ }) });
28
+ } });
28
29
  }
29
30
  async function withRenderWindow(createBrowserWindow, html, options, run) {
30
- const win = createBrowserWindow({
31
+ const win = createBrowserWindow({}, {
31
32
  show: false,
32
33
  width: options.viewport?.width ?? 1024,
33
34
  height: options.viewport?.height ?? 768,
@@ -37,20 +38,20 @@ async function withRenderWindow(createBrowserWindow, html, options, run) {
37
38
  const task = (async () => {
38
39
  attachResourcePolicy(win.webContents, options.resourcePolicy);
39
40
  const loaded = waitForLoad(win.webContents);
40
- await win.loadURL(htmlToDataUrl(html));
41
+ await win.loadURL({ url: htmlToDataUrl({ html }) });
41
42
  await loaded;
42
43
  return await run(win);
43
44
  })();
44
- return await withRenderTimeout(task, options.timeoutMs, options.signal);
45
+ return await withRenderTimeout({ promise: task }, { timeoutMs: options.timeoutMs, signal: options.signal });
45
46
  }
46
47
  finally {
47
48
  if (!win.isDestroyed())
48
49
  win.destroy();
49
50
  }
50
51
  }
51
- export function createElectronRenderService(createBrowserWindow) {
52
+ export function createElectronRenderService({ createBrowserWindow }) {
52
53
  return {
53
- async renderToPdf(html, options = {}) {
54
+ async renderToPdf({ html }, options = {}) {
54
55
  const buffer = await withRenderWindow(createBrowserWindow, html, options, (win) => win.webContents.printToPDF({
55
56
  landscape: options.landscape ?? false,
56
57
  printBackground: options.printBackground ?? true,
@@ -61,12 +62,12 @@ export function createElectronRenderService(createBrowserWindow) {
61
62
  }));
62
63
  return new Uint8Array(buffer);
63
64
  },
64
- async capture(html, options = {}) {
65
- const image = await withRenderWindow(createBrowserWindow, html, options, (win) => win.webContents.capturePage(options.clip));
65
+ async capture({ html }, options = {}) {
66
+ const image = await withRenderWindow(createBrowserWindow, html, options, (win) => win.webContents.capturePage({}, { rect: options.clip }));
66
67
  return new Uint8Array(image.toPNG());
67
68
  },
68
- async exportArtifact(_html, options) {
69
- throw new RenderServiceError(`exportArtifact format "${options.format}" is not implemented by the Electron adapter`, 'not-implemented');
69
+ async exportArtifact({ format }) {
70
+ throw new RenderServiceError({ message: `exportArtifact format "${format}" is not implemented by the Electron adapter`, code: 'not-implemented' });
70
71
  },
71
72
  };
72
73
  }