@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
@@ -0,0 +1,76 @@
1
+ /** Electron does not persist or clamp window geometry itself. A remembered position can point
2
+ * into empty space after undocking or unplugging a display, leaving the window unreachable.
3
+ * Validate meaningful overlap against the current display list on every launch, not the saved one. */
4
+ export interface WindowBounds {
5
+ x: number;
6
+ y: number;
7
+ width: number;
8
+ height: number;
9
+ }
10
+ export interface DisplayLike {
11
+ bounds: WindowBounds;
12
+ }
13
+ export interface DisplayPort {
14
+ getAllDisplays(): readonly DisplayLike[];
15
+ }
16
+ export interface BoundsStorePort {
17
+ read(args: {
18
+ key: string;
19
+ }): unknown;
20
+ write(args: {
21
+ key: string;
22
+ bounds: WindowBounds;
23
+ }): void;
24
+ }
25
+ /** Resolve a caller-owned filename without introducing a fixed persistence key. */
26
+ export declare function windowBoundsFilePath({ userDataDir, fileName, joinPath }: {
27
+ userDataDir: string;
28
+ fileName: string;
29
+ joinPath: (args: {
30
+ directory: string;
31
+ filename: string;
32
+ }) => string;
33
+ }): string;
34
+ /** Treat missing, unreadable or malformed persisted rectangles as absent. */
35
+ export declare function readWindowBounds({ store, key }: {
36
+ store: BoundsStorePort;
37
+ key: string;
38
+ }): WindowBounds | null;
39
+ /** Store geometry using the host's persistence adapter. Write failures propagate. */
40
+ export declare function writeWindowBounds({ store, key, bounds }: {
41
+ store: BoundsStorePort;
42
+ key: string;
43
+ bounds: WindowBounds;
44
+ }): void;
45
+ /** Require a meaningful overlap with at least one current display. */
46
+ export declare function boundsOnScreen({ bounds, displays }: {
47
+ bounds: WindowBounds;
48
+ displays: readonly DisplayLike[];
49
+ }, { minOnscreenPx }?: {
50
+ minOnscreenPx?: number;
51
+ }): boolean;
52
+ export interface ResolveWindowBoundsInput {
53
+ stored: WindowBounds | null;
54
+ displays: readonly DisplayLike[];
55
+ fallback: {
56
+ width: number;
57
+ height: number;
58
+ };
59
+ }
60
+ /** Restore visible geometry; omit position so the shell centers the safe fallback. */
61
+ export declare function resolveWindowBounds(input: ResolveWindowBoundsInput, options?: {
62
+ minOnscreenPx?: number;
63
+ }): Partial<WindowBounds>;
64
+ /** Read stored geometry and current displays through the host's ports. */
65
+ export declare function restoreWindowBounds({ store, display, key, fallback }: {
66
+ store: BoundsStorePort;
67
+ display: DisplayPort;
68
+ key: string;
69
+ fallback: {
70
+ width: number;
71
+ height: number;
72
+ };
73
+ }, options?: {
74
+ minOnscreenPx?: number;
75
+ }): Partial<WindowBounds>;
76
+ //# sourceMappingURL=window-bounds-store.d.ts.map
@@ -0,0 +1,44 @@
1
+ /** Resolve a caller-owned filename without introducing a fixed persistence key. */
2
+ export function windowBoundsFilePath({ userDataDir, fileName, joinPath }) { return joinPath({ directory: userDataDir, filename: fileName }); }
3
+ /** Treat missing, unreadable or malformed persisted rectangles as absent. */
4
+ export function readWindowBounds({ store, key }) {
5
+ // Geometry is a cache: a corrupt or unreadable entry must degrade to the safe centered default,
6
+ // not prevent application startup.
7
+ try {
8
+ const parsed = store.read({ key });
9
+ if (parsed === null || typeof parsed !== "object")
10
+ return null;
11
+ const { x, y, width, height } = parsed;
12
+ if (![x, y, width, height].every((n) => typeof n === "number" && Number.isFinite(n)))
13
+ return null;
14
+ return { x: x, y: y, width: width, height: height };
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ /** Store geometry using the host's persistence adapter. Write failures propagate. */
21
+ export function writeWindowBounds({ store, key, bounds }) {
22
+ store.write({ key, bounds });
23
+ }
24
+ /** Require a meaningful overlap with at least one current display. */
25
+ export function boundsOnScreen({ bounds, displays }, { minOnscreenPx = 100 } = {}) {
26
+ // The 100px default rejects a stray visible sliver yet permits a window partly dragged off-screen.
27
+ // Both dimensions must overlap enough for the remembered rectangle to be useful.
28
+ return displays.some((display) => {
29
+ const width = Math.min(bounds.x + bounds.width, display.bounds.x + display.bounds.width) - Math.max(bounds.x, display.bounds.x);
30
+ const height = Math.min(bounds.y + bounds.height, display.bounds.y + display.bounds.height) - Math.max(bounds.y, display.bounds.y);
31
+ return width >= minOnscreenPx && height >= minOnscreenPx;
32
+ });
33
+ }
34
+ /** Restore visible geometry; omit position so the shell centers the safe fallback. */
35
+ export function resolveWindowBounds(input, options = {}) {
36
+ if (input.stored && boundsOnScreen({ bounds: input.stored, displays: input.displays }, options))
37
+ return input.stored;
38
+ return { width: input.fallback.width, height: input.fallback.height };
39
+ }
40
+ /** Read stored geometry and current displays through the host's ports. */
41
+ export function restoreWindowBounds({ store, display, key, fallback }, options = {}) {
42
+ return resolveWindowBounds({ stored: readWindowBounds({ store, key }), displays: display.getAllDisplays(), fallback }, options);
43
+ }
44
+ //# sourceMappingURL=window-bounds-store.js.map
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Send commands to the renderer so it can route zoom to the visible surface. Electron's built-in
3
+ * zoom roles target the focused window's top-level webContents, which is wrong when a guest tab
4
+ * is visible. Keep native menu construction outside this module to avoid a runtime Electron dependency.
5
+ */
6
+ type ZoomCommandDirection = "in" | "out" | "reset";
7
+ interface ZoomCommandWindow {
8
+ isDestroyed(): boolean;
9
+ webContents?: {
10
+ send(args: {
11
+ channel: string;
12
+ direction: ZoomCommandDirection;
13
+ }): void;
14
+ };
15
+ }
16
+ interface ZoomMenuItem {
17
+ label: string;
18
+ accelerator: string;
19
+ visible?: boolean;
20
+ click: (args: {
21
+ window: ZoomCommandWindow | undefined;
22
+ }) => void;
23
+ }
24
+ /** Send one zoom direction to a live focused window. */
25
+ declare function sendZoomCommand({ window, direction, channel }: {
26
+ window: ZoomCommandWindow | undefined;
27
+ direction: ZoomCommandDirection;
28
+ channel: string;
29
+ }): boolean;
30
+ /** Build zoom menu commands, including the hidden unshifted plus alias. */
31
+ declare function zoomMenuItems({ channel, labels }: {
32
+ channel: string;
33
+ labels: {
34
+ reset: string;
35
+ in: string;
36
+ out: string;
37
+ };
38
+ }): ZoomMenuItem[];
39
+ export { sendZoomCommand, zoomMenuItems };
40
+ export type { ZoomCommandDirection, ZoomCommandWindow, ZoomMenuItem };
41
+ //# sourceMappingURL=zoom-menu.d.ts.map
@@ -0,0 +1,19 @@
1
+ /** Send one zoom direction to a live focused window. */
2
+ function sendZoomCommand({ window, direction, channel }) {
3
+ if (!window || window.isDestroyed() || !window.webContents)
4
+ return false;
5
+ window.webContents.send({ channel, direction });
6
+ return true;
7
+ }
8
+ /** Build zoom menu commands, including the hidden unshifted plus alias. */
9
+ function zoomMenuItems({ channel, labels }) {
10
+ return [
11
+ { label: labels.reset, accelerator: "CmdOrCtrl+0", click: ({ window }) => void sendZoomCommand({ window, direction: "reset", channel }) },
12
+ { label: labels.in, accelerator: "CmdOrCtrl+Plus", click: ({ window }) => void sendZoomCommand({ window, direction: "in", channel }) },
13
+ // Plus needs Shift on most keyboards; the hidden '=' alias supports its unshifted key too.
14
+ { label: labels.in, accelerator: "CmdOrCtrl+=", visible: false, click: ({ window }) => void sendZoomCommand({ window, direction: "in", channel }) },
15
+ { label: labels.out, accelerator: "CmdOrCtrl+-", click: ({ window }) => void sendZoomCommand({ window, direction: "out", channel }) },
16
+ ];
17
+ }
18
+ export { sendZoomCommand, zoomMenuItems };
19
+ //# sourceMappingURL=zoom-menu.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * `@jini-ai/desktop-host` — shared, shell-agnostic desktop-host ports and utilities (single-instance
3
+ * locking, window lifecycle, protocol handling, sidecar launching, shell operations, paths, config,
4
+ * logging, the host-bridge global). The concrete Electron and Tauri shell assemblies live at the
5
+ * separate `@jini-ai/desktop-host/electron` and `@jini-ai/desktop-host/tauri` entry points (split
6
+ * 2026-07-29, mirroring `@jini-ai/agentic`'s `.`/`./dom` precedent) — a real app only ever ships
7
+ * one shell, so importing this root entry point never statically pulls in the other one.
8
+ */
1
9
  export * from './single-instance.js';
2
10
  export * from './window-lifecycle.js';
3
11
  export * from './protocol.js';
@@ -11,20 +19,4 @@ export * from './render-service.js';
11
19
  export * from './shell.js';
12
20
  export * from './ports.js';
13
21
  export * from './tokens.js';
14
- export * from './electron/electron-surfaces.js';
15
- export * from './electron/electron-single-instance.js';
16
- export * from './electron/electron-window-lifecycle.js';
17
- export * from './electron/electron-protocol.js';
18
- export * from './electron/electron-render-service.js';
19
- export * from './electron/electron-shell.js';
20
- export * from './electron/create-electron-desktop-host.js';
21
- export * from './tauri/tauri-surfaces.js';
22
- export * from './tauri/tauri-single-instance.js';
23
- export * from './tauri/tauri-window-lifecycle.js';
24
- export * from './tauri/tauri-protocol.js';
25
- export * from './tauri/tauri-render-service.js';
26
- export * from './tauri/tauri-shell.js';
27
- export * from './tauri/tauri-sidecar.js';
28
- export * from './tauri/create-tauri-desktop-host.js';
29
- export * from './tauri/not-implemented.js';
30
22
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * `@jini-ai/desktop-host` — shared, shell-agnostic desktop-host ports and utilities (single-instance
3
+ * locking, window lifecycle, protocol handling, sidecar launching, shell operations, paths, config,
4
+ * logging, the host-bridge global). The concrete Electron and Tauri shell assemblies live at the
5
+ * separate `@jini-ai/desktop-host/electron` and `@jini-ai/desktop-host/tauri` entry points (split
6
+ * 2026-07-29, mirroring `@jini-ai/agentic`'s `.`/`./dom` precedent) — a real app only ever ships
7
+ * one shell, so importing this root entry point never statically pulls in the other one.
8
+ */
1
9
  export * from './single-instance.js';
2
10
  export * from './window-lifecycle.js';
3
11
  export * from './protocol.js';
@@ -11,20 +19,4 @@ export * from './render-service.js';
11
19
  export * from './shell.js';
12
20
  export * from './ports.js';
13
21
  export * from './tokens.js';
14
- export * from './electron/electron-surfaces.js';
15
- export * from './electron/electron-single-instance.js';
16
- export * from './electron/electron-window-lifecycle.js';
17
- export * from './electron/electron-protocol.js';
18
- export * from './electron/electron-render-service.js';
19
- export * from './electron/electron-shell.js';
20
- export * from './electron/create-electron-desktop-host.js';
21
- export * from './tauri/tauri-surfaces.js';
22
- export * from './tauri/tauri-single-instance.js';
23
- export * from './tauri/tauri-window-lifecycle.js';
24
- export * from './tauri/tauri-protocol.js';
25
- export * from './tauri/tauri-render-service.js';
26
- export * from './tauri/tauri-shell.js';
27
- export * from './tauri/tauri-sidecar.js';
28
- export * from './tauri/create-tauri-desktop-host.js';
29
- export * from './tauri/not-implemented.js';
30
22
  //# sourceMappingURL=index.js.map
package/dist/logging.d.ts CHANGED
@@ -1,22 +1,34 @@
1
- export interface HostLogger {
2
- error(message: string, meta?: Record<string, unknown>): void;
3
- info(message: string, meta?: Record<string, unknown>): void;
4
- warn(message: string, meta?: Record<string, unknown>): void;
5
- }
6
- export type LogAppend = (path: string, data: string, encoding: BufferEncoding) => void;
7
- export declare function appendLogLine(logPath: string, line: string, append?: LogAppend): boolean;
8
- export declare function createFileLogger(logPath: string, options?: {
1
+ import type { Logger } from '@jini-ai/core/primitives';
2
+ export type LogAppend = (args: {
3
+ path: string;
4
+ data: string;
5
+ encoding: BufferEncoding;
6
+ }) => void;
7
+ export declare function appendLogLine({ logPath, line }: {
8
+ logPath: string;
9
+ line: string;
10
+ }, { append }?: {
11
+ append?: LogAppend;
12
+ }): boolean;
13
+ export declare function createFileLogger({ logPath }: {
14
+ logPath: string;
15
+ }, options?: {
9
16
  echoToConsole?: boolean;
10
- }): HostLogger;
17
+ append?: LogAppend;
18
+ }): Logger;
11
19
  /**
12
20
  * Matches the known-harmless undici `setTypeOfService EINVAL` shape (see
13
21
  * OD issue #895): certain macOS/VPN configurations refuse to let the
14
22
  * kernel set the outbound socket's IP_TOS byte, which has no functional
15
23
  * effect on the request. `code` is authoritative when present.
16
24
  */
17
- export declare function isHarmlessSocketOptionError(value: unknown): boolean;
25
+ export declare function isHarmlessSocketOptionError({ value }: {
26
+ value: unknown;
27
+ }): boolean;
18
28
  export interface InstallFatalExceptionHandlersOptions {
19
- isHarmless?: (error: unknown) => boolean;
29
+ isHarmless?: (args: {
30
+ value: unknown;
31
+ }) => boolean;
20
32
  }
21
33
  /**
22
34
  * Installs `uncaughtException`/`unhandledRejection` handlers that log and
@@ -26,5 +38,7 @@ export interface InstallFatalExceptionHandlersOptions {
26
38
  * Node's default crash path (and Electron's native error dialog) take
27
39
  * over. Returns a function that uninstalls both handlers.
28
40
  */
29
- export declare function installFatalExceptionHandlers(logger: HostLogger, options?: InstallFatalExceptionHandlersOptions): () => void;
41
+ export declare function installFatalExceptionHandlers({ logger }: {
42
+ logger: Logger;
43
+ }, options?: InstallFatalExceptionHandlersOptions): () => void;
30
44
  //# sourceMappingURL=logging.d.ts.map
package/dist/logging.js CHANGED
@@ -39,35 +39,35 @@ function serializeMessage(level, message, meta) {
39
39
  })}\n`;
40
40
  }
41
41
  }
42
- export function appendLogLine(logPath, line, append = appendFileSync) {
42
+ export function appendLogLine({ logPath, line }, { append = ({ path, data, encoding }) => appendFileSync(path, data, encoding) } = {}) {
43
43
  try {
44
- append(logPath, line, 'utf8');
44
+ append({ path: logPath, data: line, encoding: 'utf8' });
45
45
  return true;
46
46
  }
47
47
  catch {
48
48
  return false;
49
49
  }
50
50
  }
51
- export function createFileLogger(logPath, options = {}) {
51
+ export function createFileLogger({ logPath }, options = {}) {
52
52
  const echo = options.echoToConsole ?? true;
53
53
  const write = (level, message, meta) => {
54
- appendLogLine(logPath, serializeMessage(level, message, meta));
54
+ appendLogLine({ logPath, line: serializeMessage(level, message, meta) }, options.append === undefined ? {} : { append: options.append });
55
55
  };
56
56
  const logger = {
57
- error(message, meta) {
58
- write('error', message, meta);
57
+ error({ message }, { meta, error } = {}) {
58
+ write('error', message, error === undefined ? meta : { ...meta, error });
59
59
  if (echo)
60
- console.error(message, meta ?? '');
60
+ console.error(message, error === undefined ? meta ?? '' : { ...meta, error });
61
61
  },
62
- info(message, meta) {
63
- write('info', message, meta);
62
+ info({ message }, { meta, error } = {}) {
63
+ write('info', message, error === undefined ? meta : { ...meta, error });
64
64
  if (echo)
65
- console.info(message, meta ?? '');
65
+ console.info(message, error === undefined ? meta ?? '' : { ...meta, error });
66
66
  },
67
- warn(message, meta) {
68
- write('warn', message, meta);
67
+ warn({ message }, { meta, error } = {}) {
68
+ write('warn', message, error === undefined ? meta : { ...meta, error });
69
69
  if (echo)
70
- console.warn(message, meta ?? '');
70
+ console.warn(message, error === undefined ? meta ?? '' : { ...meta, error });
71
71
  },
72
72
  };
73
73
  return logger;
@@ -78,7 +78,7 @@ export function createFileLogger(logPath, options = {}) {
78
78
  * kernel set the outbound socket's IP_TOS byte, which has no functional
79
79
  * effect on the request. `code` is authoritative when present.
80
80
  */
81
- export function isHarmlessSocketOptionError(value) {
81
+ export function isHarmlessSocketOptionError({ value }) {
82
82
  if (!(value instanceof Error))
83
83
  return false;
84
84
  const message = typeof value.message === 'string' ? value.message : '';
@@ -97,25 +97,25 @@ export function isHarmlessSocketOptionError(value) {
97
97
  * Node's default crash path (and Electron's native error dialog) take
98
98
  * over. Returns a function that uninstalls both handlers.
99
99
  */
100
- export function installFatalExceptionHandlers(logger, options = {}) {
100
+ export function installFatalExceptionHandlers({ logger }, options = {}) {
101
101
  const isHarmless = options.isHarmless ?? isHarmlessSocketOptionError;
102
102
  const onUncaughtException = (error) => {
103
- if (isHarmless(error)) {
104
- logger.warn('swallowed harmless uncaught exception', { error });
103
+ if (isHarmless({ value: error })) {
104
+ logger.warn({ message: 'swallowed harmless uncaught exception' }, { meta: { error } });
105
105
  return;
106
106
  }
107
- logger.error('fatal uncaught exception', { error });
107
+ logger.error({ message: 'fatal uncaught exception' }, { meta: { error } });
108
108
  process.removeListener('uncaughtException', onUncaughtException);
109
109
  setImmediate(() => {
110
110
  throw error;
111
111
  });
112
112
  };
113
113
  const onUnhandledRejection = (reason) => {
114
- if (isHarmless(reason)) {
115
- logger.warn('swallowed harmless unhandled rejection', { reason });
114
+ if (isHarmless({ value: reason })) {
115
+ logger.warn({ message: 'swallowed harmless unhandled rejection' }, { meta: { reason } });
116
116
  return;
117
117
  }
118
- logger.error('fatal unhandled rejection', { reason });
118
+ logger.error({ message: 'fatal unhandled rejection' }, { meta: { reason } });
119
119
  process.removeListener('unhandledRejection', onUnhandledRejection);
120
120
  setImmediate(() => {
121
121
  throw reason;
@@ -0,0 +1,76 @@
1
+ export interface ToolchainFilesystemPort {
2
+ mkdirSync(requiredArgs: {
3
+ path: string;
4
+ }, optionalArgs?: {
5
+ recursive?: boolean;
6
+ mode?: number;
7
+ }): unknown;
8
+ chmodSync(requiredArgs: {
9
+ path: string;
10
+ mode: number;
11
+ }): void;
12
+ writeFileSync(requiredArgs: {
13
+ path: string;
14
+ data: string;
15
+ }, optionalArgs?: {
16
+ mode?: number;
17
+ }): void;
18
+ renameSync(requiredArgs: {
19
+ oldPath: string;
20
+ newPath: string;
21
+ }): void;
22
+ unlinkSync(requiredArgs: {
23
+ path: string;
24
+ }): void;
25
+ }
26
+ export interface NodeToolchainPaths {
27
+ toolchainDir: string;
28
+ binDir: string;
29
+ npmCacheDir: string;
30
+ npmPrefixDir: string;
31
+ }
32
+ export interface BuildNodeToolchainShimsInput {
33
+ electronPath: string;
34
+ npmRoot: string;
35
+ platform: NodeJS.Platform;
36
+ /** A single shell comment line, including its leading #. Host wording is never defaulted. */
37
+ generatedComment: string;
38
+ joinPath: (args: {
39
+ parts: string[];
40
+ }) => string;
41
+ }
42
+ export interface WriteNodeToolchainInput extends BuildNodeToolchainShimsInput {
43
+ paths: NodeToolchainPaths;
44
+ filesystem: ToolchainFilesystemPort;
45
+ writerPid: number;
46
+ isTransientPath: (args: {
47
+ executablePath: string;
48
+ }) => boolean;
49
+ launcherNamesDurableInstall: (args: {
50
+ launcherPath: string;
51
+ }) => boolean;
52
+ }
53
+ export interface BuildNodeToolchainEnvInput {
54
+ toolchainDir: string;
55
+ npmRoot: string;
56
+ toolchainEnvName: string;
57
+ npmRootEnvName: string;
58
+ }
59
+ /** Reject batch metacharacters without echoing the untrusted value. @complexity O(n) in value length. */
60
+ export declare function assertCmdQuotable({ value, field }: {
61
+ value: unknown;
62
+ field: string;
63
+ }): string;
64
+ /** Exact Node/npm/npx launchers; the executable, path joiner and header are caller supplied.
65
+ * No I/O. Throws before writing when a value cannot be safely quoted. @complexity O(n) in path lengths.
66
+ */
67
+ export declare function buildNodeToolchainShims({ electronPath, npmRoot, platform, generatedComment, joinPath }: BuildNodeToolchainShimsInput): Record<string, string>;
68
+ /** Atomically replace each executable shim in caller-selected directories, with owner-only modes.
69
+ * A transient launch preserves an existing durable launcher or returns null without writing.
70
+ * Filesystem/probe errors propagate; temporary files are cleaned up after a failed replacement.
71
+ * @complexity O(n) shim bytes, with three writes and renames.
72
+ */
73
+ export declare function writeNodeToolchain(input: WriteNodeToolchainInput): NodeToolchainPaths | null;
74
+ /** Host-named environment contract; duplicate/invalid names fail loudly. @complexity O(n) in names. */
75
+ export declare function buildNodeToolchainEnv({ toolchainDir, npmRoot, toolchainEnvName, npmRootEnvName }: BuildNodeToolchainEnvInput): Record<string, string>;
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,96 @@
1
+ /** Reject batch metacharacters without echoing the untrusted value. @complexity O(n) in value length. */
2
+ export function assertCmdQuotable({ value, field }) {
3
+ // Double quotes do not stop cmd.exe expansion: % expands variables, a quote ends the literal,
4
+ // ^ escapes, and & chains commands. Refuse metacharacters instead of attempting unsafe quoting.
5
+ if (typeof value !== 'string' || value === '')
6
+ throw new Error(`node-toolchain: ${field} must be a non-empty string.`);
7
+ if (/[%"^&|<>!\r\n]/.test(value))
8
+ throw new Error(`node-toolchain: ${field} contains a character a .cmd launcher cannot quote and cannot be used.`);
9
+ return value;
10
+ }
11
+ /** Single-quoted POSIX arguments cannot contain a quote or newline. @complexity O(n). */
12
+ function assertShellQuotable(value, field) {
13
+ if (typeof value !== 'string' || value === '')
14
+ throw new Error(`node-toolchain: ${field} must be a non-empty string.`);
15
+ if (/'|[\r\n]/.test(value))
16
+ throw new Error(`node-toolchain: ${field} contains a quote or newline and cannot be used in the launcher script.`);
17
+ return value;
18
+ }
19
+ /** Exact Node/npm/npx launchers; the executable, path joiner and header are caller supplied.
20
+ * No I/O. Throws before writing when a value cannot be safely quoted. @complexity O(n) in path lengths.
21
+ */
22
+ export function buildNodeToolchainShims({ electronPath, npmRoot, platform, generatedComment, joinPath }) {
23
+ // Reuse Electron's bundled Node/npm without requiring a system install. ELECTRON_RUN_AS_NODE
24
+ // prevents a second GUI process; npm/npx use the bundled CLI entry points.
25
+ if (!generatedComment.startsWith('#') || /[\r\n]/.test(generatedComment))
26
+ throw new Error('node-toolchain: generatedComment must be one shell comment line.');
27
+ if (platform === 'win32') {
28
+ const exe = assertCmdQuotable({ value: electronPath, field: 'electronPath' });
29
+ const npm = assertCmdQuotable({ value: joinPath({ parts: [npmRoot, 'bin', 'npm-cli.js'] }), field: 'npmRoot' });
30
+ const npx = assertCmdQuotable({ value: joinPath({ parts: [npmRoot, 'bin', 'npx-cli.js'] }), field: 'npmRoot' });
31
+ const header = ['@echo off', 'set ELECTRON_RUN_AS_NODE=1'];
32
+ return {
33
+ 'node.cmd': [...header, `"${exe}" %*`, ''].join('\r\n'),
34
+ 'npm.cmd': [...header, `"${exe}" "${npm}" %*`, ''].join('\r\n'),
35
+ 'npx.cmd': [...header, `"${exe}" "${npx}" %*`, ''].join('\r\n'),
36
+ };
37
+ }
38
+ const exe = assertShellQuotable(electronPath, 'electronPath');
39
+ const npm = assertShellQuotable(joinPath({ parts: [npmRoot, 'bin', 'npm-cli.js'] }), 'npmRoot');
40
+ const npx = assertShellQuotable(joinPath({ parts: [npmRoot, 'bin', 'npx-cli.js'] }), 'npmRoot');
41
+ const header = ['#!/bin/sh', generatedComment, 'ELECTRON_RUN_AS_NODE=1', 'export ELECTRON_RUN_AS_NODE'];
42
+ return {
43
+ node: [...header, `exec '${exe}' "$@"`, ''].join('\n'),
44
+ npm: [...header, `exec '${exe}' '${npm}' "$@"`, ''].join('\n'),
45
+ npx: [...header, `exec '${exe}' '${npx}' "$@"`, ''].join('\n'),
46
+ };
47
+ }
48
+ /** Atomically replace each executable shim in caller-selected directories, with owner-only modes.
49
+ * A transient launch preserves an existing durable launcher or returns null without writing.
50
+ * Filesystem/probe errors propagate; temporary files are cleaned up after a failed replacement.
51
+ * @complexity O(n) shim bytes, with three writes and renames.
52
+ */
53
+ export function writeNodeToolchain(input) {
54
+ // These paths are shared by every running copy. A transient disk-image/translocated executable
55
+ // must not overwrite durable shims or pin the mounted image through another copy's child process.
56
+ // Durable launches rewrite every time because moving/updating the app changes its executable path.
57
+ const { paths, filesystem, writerPid, joinPath, isTransientPath, launcherNamesDurableInstall } = input;
58
+ if (isTransientPath({ executablePath: input.electronPath })) {
59
+ return launcherNamesDurableInstall({ launcherPath: joinPath({ parts: [paths.binDir, input.platform === 'win32' ? 'node.cmd' : 'node'] }) }) ? paths : null;
60
+ }
61
+ // Validate all launchers before touching a directory or file.
62
+ const shims = buildNodeToolchainShims(input);
63
+ filesystem.mkdirSync({ path: paths.binDir }, { recursive: true, mode: 0o700 });
64
+ filesystem.chmodSync({ path: paths.binDir, mode: 0o700 });
65
+ // bin goes first on child PATH: only the owner may write it. chmod is needed even after mkdir,
66
+ // which leaves existing permissions alone and applies umask to newly created directories.
67
+ filesystem.mkdirSync({ path: paths.npmCacheDir }, { recursive: true });
68
+ filesystem.mkdirSync({ path: paths.npmPrefixDir }, { recursive: true });
69
+ for (const [name, contents] of Object.entries(shims)) {
70
+ const target = joinPath({ parts: [paths.binDir, name] });
71
+ const temporary = `${target}.${writerPid}.tmp`;
72
+ // Same-directory rename publishes a complete executable atomically; a crash must not leave a
73
+ // half-written executable shim visible to another launcher.
74
+ try {
75
+ filesystem.writeFileSync({ path: temporary, data: contents }, { mode: 0o700 });
76
+ filesystem.chmodSync({ path: temporary, mode: 0o700 });
77
+ filesystem.renameSync({ oldPath: temporary, newPath: target });
78
+ }
79
+ catch (error) {
80
+ try {
81
+ filesystem.unlinkSync({ path: temporary });
82
+ }
83
+ catch { /* Preserve the original write error. */ }
84
+ throw error;
85
+ }
86
+ }
87
+ return paths;
88
+ }
89
+ /** Host-named environment contract; duplicate/invalid names fail loudly. @complexity O(n) in names. */
90
+ export function buildNodeToolchainEnv({ toolchainDir, npmRoot, toolchainEnvName, npmRootEnvName }) {
91
+ if (![toolchainEnvName, npmRootEnvName].every(name => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) || toolchainEnvName === npmRootEnvName) {
92
+ throw new Error('node-toolchain: environment names must be valid and distinct.');
93
+ }
94
+ return { [toolchainEnvName]: toolchainDir, [npmRootEnvName]: npmRoot };
95
+ }
96
+ //# sourceMappingURL=index.js.map
package/dist/paths.d.ts CHANGED
@@ -8,7 +8,9 @@ export interface DesktopHostPathRoots {
8
8
  sessionDataRoot: string;
9
9
  }
10
10
  export declare class DesktopHostPathError extends Error {
11
- constructor(message: string);
11
+ constructor({ message }: {
12
+ message: string;
13
+ });
12
14
  }
13
15
  export interface ResolvePathRootsOptions {
14
16
  namespace: string;
@@ -16,5 +18,5 @@ export interface ResolvePathRootsOptions {
16
18
  dataDirOverrideEnvVar?: string;
17
19
  env?: NodeJS.ProcessEnv;
18
20
  }
19
- export declare function resolveDesktopHostPathRoots(options: ResolvePathRootsOptions): DesktopHostPathRoots;
21
+ export declare function resolveDesktopHostPathRoots(requiredArgs: Pick<ResolvePathRootsOptions, 'namespace' | 'namespaceBaseRoot'>, optionalArgs?: Omit<ResolvePathRootsOptions, 'namespace' | 'namespaceBaseRoot'>): DesktopHostPathRoots;
20
22
  //# sourceMappingURL=paths.d.ts.map
package/dist/paths.js CHANGED
@@ -16,7 +16,7 @@
16
16
  import { homedir } from 'node:os';
17
17
  import { isAbsolute, join, win32 } from 'node:path';
18
18
  export class DesktopHostPathError extends Error {
19
- constructor(message) {
19
+ constructor({ message }) {
20
20
  super(message);
21
21
  this.name = 'DesktopHostPathError';
22
22
  }
@@ -54,17 +54,18 @@ function resolveDataRoot(namespaceRoot, namespace, dataDirOverrideEnvVar, env) {
54
54
  const expanded = expandHomePrefix(override);
55
55
  const isAbs = process.platform === 'win32' ? win32.isAbsolute(expanded) : isAbsolute(expanded);
56
56
  if (!isAbs) {
57
- throw new DesktopHostPathError(`${dataDirOverrideEnvVar} must be an absolute path; got: ${override}`);
57
+ throw new DesktopHostPathError({ message: `${dataDirOverrideEnvVar} must be an absolute path; got: ${override}` });
58
58
  }
59
59
  const scopedNamespace = scopedNamespaceOf(expanded);
60
60
  if (scopedNamespace != null && scopedNamespace !== namespace) {
61
- throw new DesktopHostPathError(`${dataDirOverrideEnvVar} targets namespace "${scopedNamespace}" but the active namespace is "${namespace}"`);
61
+ throw new DesktopHostPathError({ message: `${dataDirOverrideEnvVar} targets namespace "${scopedNamespace}" but the active namespace is "${namespace}"` });
62
62
  }
63
63
  return scopedNamespace != null ? expanded : join(expanded, 'namespaces', namespace, 'data');
64
64
  }
65
65
  return join(namespaceRoot, 'data');
66
66
  }
67
- export function resolveDesktopHostPathRoots(options) {
67
+ export function resolveDesktopHostPathRoots(requiredArgs, optionalArgs = {}) {
68
+ const options = { ...optionalArgs, ...requiredArgs };
68
69
  const env = options.env ?? process.env;
69
70
  const namespaceRoot = join(options.namespaceBaseRoot, options.namespace);
70
71
  return {
@@ -14,15 +14,30 @@ export interface ProtocolProxyErrorBody {
14
14
  code?: string;
15
15
  target: string;
16
16
  }
17
- export declare function buildProtocolProxyTargetUrl(targetBaseUrl: string, requestUrl: string): string;
18
- export type ProtocolFetch = (request: Request) => Promise<Response>;
19
- export declare function handleProtocolProxyRequest(request: Request, targetBaseUrl: string, fetchImpl?: ProtocolFetch): Promise<Response>;
17
+ export declare function buildProtocolProxyTargetUrl({ targetBaseUrl, requestUrl }: {
18
+ targetBaseUrl: string;
19
+ requestUrl: string;
20
+ }): string;
21
+ export type ProtocolFetch = (args: {
22
+ request: Request;
23
+ }) => Promise<Response>;
24
+ export declare function handleProtocolProxyRequest({ request, targetBaseUrl }: {
25
+ request: Request;
26
+ targetBaseUrl: string;
27
+ }, { fetchImpl }?: {
28
+ fetchImpl?: ProtocolFetch;
29
+ }): Promise<Response>;
20
30
  export interface ProtocolSchemeRegistration {
21
31
  scheme: string;
22
32
  entryUrl: string;
23
33
  }
24
34
  export interface ProtocolHandlerPort {
25
- registerSchemeProxy(scheme: string, targetBaseUrl: string): ProtocolSchemeRegistration;
35
+ registerSchemeProxy({ scheme, targetBaseUrl }: {
36
+ scheme: string;
37
+ targetBaseUrl: string;
38
+ }): ProtocolSchemeRegistration;
26
39
  }
27
- export declare function schemeEntryUrl(scheme: string): string;
40
+ export declare function schemeEntryUrl({ scheme }: {
41
+ scheme: string;
42
+ }): string;
28
43
  //# sourceMappingURL=protocol.d.ts.map