@jini-ai/desktop-host 0.6.15-rc.1 → 0.6.15
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/dist/electron/create-electron-desktop-host.d.ts +3 -0
- package/dist/electron/create-electron-desktop-host.js +1 -1
- package/dist/electron/electron-render-service.d.ts +4 -3
- package/dist/electron/electron-render-service.js +3 -3
- package/dist/electron/electron-url-capture.d.ts +20 -1
- package/dist/electron/electron-url-capture.js +53 -46
- package/dist/electron/index.d.ts +1 -0
- package/dist/electron/index.js +1 -0
- package/dist/electron/updates/instance-presence.js +6 -6
- package/dist/node-toolchain/index.js +1 -1
- package/dist/paths.js +2 -1
- package/dist/render-bridge.js +18 -13
- package/dist/sidecar.js +4 -1
- package/dist/speech/macos/mac-on-device-transcriber.js +3 -1
- package/dist/tauri/tauri-sidecar.js +2 -1
- package/dist/tauri/tauri-window-lifecycle.js +1 -0
- package/dist/tauri/testing.js +1 -3
- package/dist/url-capture.js +11 -8
- package/package.json +3 -3
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { DesktopHost, DesktopHostPorts } from '../ports.js';
|
|
2
|
+
import type { ElectronUrlCapturePoolPort } from './electron-url-capture.js';
|
|
2
3
|
import type { ElectronAppLike, ElectronBrowserWindowFactory, ElectronDialogLike, ElectronProtocolLike, ElectronShellLike } from './electron-surfaces.js';
|
|
3
4
|
export interface ElectronDesktopHostSurfaces {
|
|
4
5
|
app: ElectronAppLike;
|
|
5
6
|
createBrowserWindow: ElectronBrowserWindowFactory;
|
|
7
|
+
/** One pool created at host startup, shared with all native render services in the process. */
|
|
8
|
+
capturePool: ElectronUrlCapturePoolPort;
|
|
6
9
|
protocol: ElectronProtocolLike;
|
|
7
10
|
shell: ElectronShellLike;
|
|
8
11
|
/** Backs `ShellPort.openFolderDialog` (2026-07-22 addition — see `shell.ts`'s module doc). */
|
|
@@ -10,7 +10,7 @@ export function createElectronDesktopHost(surfaces, overrides = {}) {
|
|
|
10
10
|
windowLifecycle: overrides.windowLifecycle ?? createElectronWindowLifecyclePort({ createBrowserWindow: surfaces.createBrowserWindow }),
|
|
11
11
|
protocolHandler: overrides.protocolHandler ?? createElectronProtocolHandlerPort({ electronProtocol: surfaces.protocol }),
|
|
12
12
|
sidecarLauncher: overrides.sidecarLauncher ?? createNodeSidecarLauncher({}),
|
|
13
|
-
renderService: overrides.renderService ?? createElectronRenderService({ createBrowserWindow: surfaces.createBrowserWindow }),
|
|
13
|
+
renderService: overrides.renderService ?? createElectronRenderService({ createBrowserWindow: surfaces.createBrowserWindow, capturePool: surfaces.capturePool }),
|
|
14
14
|
shell: overrides.shell ?? createElectronShellPort({ shell: surfaces.shell, app: surfaces.app, dialog: surfaces.dialog }),
|
|
15
15
|
};
|
|
16
16
|
return { backend: 'electron', ports };
|
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type RenderService } from '../render-service.js';
|
|
10
10
|
import type { ElectronBrowserWindowFactory } from './electron-surfaces.js';
|
|
11
|
-
import { type ElectronUrlCaptureOptions } from './electron-url-capture.js';
|
|
11
|
+
import { type ElectronUrlCaptureOptions, type ElectronUrlCapturePoolPort } from './electron-url-capture.js';
|
|
12
12
|
import type { UrlCaptureRequest, UrlCaptureResult } from '../url-capture.js';
|
|
13
13
|
/** Bind HTML exports and bounded URL capture to an injected native window factory.
|
|
14
|
-
* @example const service = createElectronRenderService({ createBrowserWindow });
|
|
14
|
+
* @example const service = createElectronRenderService({ createBrowserWindow, capturePool });
|
|
15
15
|
* @complexity O(1) setup; each operation owns one temporary native window.
|
|
16
16
|
*/
|
|
17
|
-
export declare function createElectronRenderService({ createBrowserWindow }: {
|
|
17
|
+
export declare function createElectronRenderService({ createBrowserWindow, capturePool }: {
|
|
18
18
|
createBrowserWindow: ElectronBrowserWindowFactory;
|
|
19
|
+
capturePool: ElectronUrlCapturePoolPort;
|
|
19
20
|
}, _options?: {}): RenderService & {
|
|
20
21
|
captureUrl(request: UrlCaptureRequest, options?: ElectronUrlCaptureOptions): Promise<UrlCaptureResult>;
|
|
21
22
|
};
|
|
@@ -10,13 +10,13 @@ import { RenderServiceError, } from '../render-service.js';
|
|
|
10
10
|
import { withRenderWindow } from './render-window.js';
|
|
11
11
|
import { captureElectronUrl } from './electron-url-capture.js';
|
|
12
12
|
/** Bind HTML exports and bounded URL capture to an injected native window factory.
|
|
13
|
-
* @example const service = createElectronRenderService({ createBrowserWindow });
|
|
13
|
+
* @example const service = createElectronRenderService({ createBrowserWindow, capturePool });
|
|
14
14
|
* @complexity O(1) setup; each operation owns one temporary native window.
|
|
15
15
|
*/
|
|
16
|
-
export function createElectronRenderService({ createBrowserWindow }, _options = {}) {
|
|
16
|
+
export function createElectronRenderService({ createBrowserWindow, capturePool }, _options = {}) {
|
|
17
17
|
return {
|
|
18
18
|
captureUrl(request, options = {}) {
|
|
19
|
-
return captureElectronUrl({ createBrowserWindow, request }, options);
|
|
19
|
+
return captureElectronUrl({ createBrowserWindow, capturePool, request }, options);
|
|
20
20
|
},
|
|
21
21
|
async renderToPdf({ html }, options = {}) {
|
|
22
22
|
const buffer = await withRenderWindow({ createBrowserWindow, html, options, run: (win) => win.webContents.printToPDF({
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { type UrlCaptureRequest, type UrlCaptureResult } from '../url-capture.js';
|
|
2
2
|
import type { ElectronBrowserWindowFactory } from './electron-surfaces.js';
|
|
3
|
+
/** The host shares one lease pool across every render service in its Electron process. */
|
|
4
|
+
export interface ElectronUrlCapturePoolPort {
|
|
5
|
+
acquire(required: {
|
|
6
|
+
deadline: number;
|
|
7
|
+
}, options?: {
|
|
8
|
+
signal?: AbortSignal | undefined;
|
|
9
|
+
}): Promise<number>;
|
|
10
|
+
release(required: {
|
|
11
|
+
slot: number;
|
|
12
|
+
}, options?: object): void;
|
|
13
|
+
}
|
|
14
|
+
/** Create the host-owned FIFO for the two native capture partitions.
|
|
15
|
+
* Electron retains partitions for the process lifetime. The leases must therefore span every
|
|
16
|
+
* render service/bridge in this process, without a per-site partition registry.
|
|
17
|
+
* Create once at host startup and inject the same port into every render service.
|
|
18
|
+
* @complexity O(1) setup; O(w) space for w pending captures.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createElectronUrlCapturePool(_required: object, _options?: object): ElectronUrlCapturePoolPort;
|
|
3
21
|
export interface ElectronUrlCaptureOptions {
|
|
4
22
|
allowedOrigins?: readonly string[];
|
|
5
23
|
signal?: AbortSignal;
|
|
@@ -10,8 +28,9 @@ export interface ElectronUrlCaptureOptions {
|
|
|
10
28
|
* @throws RenderServiceError on refusal, timeout or native renderer failure.
|
|
11
29
|
* @complexity O(pixels), capped at 1280×8000 CSS pixels and device scale 2.
|
|
12
30
|
*/
|
|
13
|
-
export declare function captureElectronUrl({ createBrowserWindow, request: input }: {
|
|
31
|
+
export declare function captureElectronUrl({ createBrowserWindow, capturePool, request: input }: {
|
|
14
32
|
createBrowserWindow: ElectronBrowserWindowFactory;
|
|
33
|
+
capturePool: ElectronUrlCapturePoolPort;
|
|
15
34
|
request: UrlCaptureRequest;
|
|
16
35
|
}, { allowedOrigins, signal }?: ElectronUrlCaptureOptions): Promise<UrlCaptureResult>;
|
|
17
36
|
//# sourceMappingURL=electron-url-capture.d.ts.map
|
|
@@ -4,52 +4,59 @@
|
|
|
4
4
|
import { RenderServiceError, withRenderTimeout } from '../render-service.js';
|
|
5
5
|
import { isCaptureUrlAllowed, readUrlCaptureRequest, URL_CAPTURE_MAX_BYTES, URL_CAPTURE_TIMEOUT_MS } from '../url-capture.js';
|
|
6
6
|
import { withRenderWindow } from './render-window.js';
|
|
7
|
-
// Electron retains partitions for the process lifetime. The leases must therefore span every
|
|
8
|
-
// render service/bridge in this process, without a per-site partition registry.
|
|
9
|
-
const captureSlots = [false, false];
|
|
10
|
-
const captureWaiters = new Set();
|
|
11
7
|
const CAPTURE_CLEANUP_TIMEOUT_MS = 1_000;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
/** Create the host-owned FIFO for the two native capture partitions.
|
|
9
|
+
* Electron retains partitions for the process lifetime. The leases must therefore span every
|
|
10
|
+
* render service/bridge in this process, without a per-site partition registry.
|
|
11
|
+
* Create once at host startup and inject the same port into every render service.
|
|
12
|
+
* @complexity O(1) setup; O(w) space for w pending captures.
|
|
15
13
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
export function createElectronUrlCapturePool(_required, _options = {}) {
|
|
15
|
+
const captureSlots = [false, false];
|
|
16
|
+
const captureWaiters = new Set();
|
|
17
|
+
/** Lease a partition in arrival order, charging queued time to the caller's deadline.
|
|
18
|
+
* Timed-out/aborted waiters are removed; a simultaneous handoff returns its lease.
|
|
19
|
+
* @throws RenderServiceError on timeout/abort. @complexity O(1) time/space per waiter.
|
|
20
|
+
*/
|
|
21
|
+
async function acquireCaptureSlot({ deadline }, { signal } = {}) {
|
|
22
|
+
if (signal?.aborted)
|
|
23
|
+
throw new RenderServiceError({ code: 'aborted', message: 'render aborted before starting' });
|
|
24
|
+
const slot = captureSlots.indexOf(false);
|
|
25
|
+
if (slot >= 0) {
|
|
26
|
+
captureSlots[slot] = true;
|
|
27
|
+
return slot;
|
|
28
|
+
}
|
|
29
|
+
let assigned;
|
|
30
|
+
let receive;
|
|
31
|
+
const promise = new Promise(resolve => {
|
|
32
|
+
receive = ({ slot }, _options = {}) => { assigned = slot; resolve(slot); };
|
|
33
|
+
captureWaiters.add(receive);
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
return await withRenderTimeout({ promise }, { timeoutMs: Math.max(0, deadline - Date.now()), signal });
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (assigned !== undefined)
|
|
40
|
+
returnCaptureSlot({ slot: assigned });
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
captureWaiters.delete(receive);
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
|
-
|
|
47
|
+
/** Hand a clean partition straight to the oldest waiter, keeping it exclusive during handoff.
|
|
48
|
+
* @complexity O(1) time/space; the Set preserves insertion order and supports cancellation.
|
|
49
|
+
*/
|
|
50
|
+
function returnCaptureSlot({ slot }, _options = {}) {
|
|
51
|
+
const receive = captureWaiters.values().next().value;
|
|
52
|
+
if (!receive) {
|
|
53
|
+
captureSlots[slot] = false;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
39
56
|
captureWaiters.delete(receive);
|
|
57
|
+
receive({ slot });
|
|
40
58
|
}
|
|
41
|
-
}
|
|
42
|
-
/** Hand a clean partition straight to the oldest waiter, keeping it exclusive during handoff.
|
|
43
|
-
* @complexity O(1) time/space; the Set preserves insertion order and supports cancellation.
|
|
44
|
-
*/
|
|
45
|
-
function returnCaptureSlot({ slot }, _options = {}) {
|
|
46
|
-
const receive = captureWaiters.values().next().value;
|
|
47
|
-
if (!receive) {
|
|
48
|
-
captureSlots[slot] = false;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
captureWaiters.delete(receive);
|
|
52
|
-
receive({ slot });
|
|
59
|
+
return { acquire: acquireCaptureSlot, release: returnCaptureSlot };
|
|
53
60
|
}
|
|
54
61
|
/** Clear native credentials, storage and network state before reuse; failures deny capture.
|
|
55
62
|
* @throws RenderServiceError if the host cannot reset a session. @complexity O(1) native calls.
|
|
@@ -74,13 +81,13 @@ async function resetCaptureSession({ session }, _options = {}) {
|
|
|
74
81
|
* @throws RenderServiceError on refusal, timeout or native renderer failure.
|
|
75
82
|
* @complexity O(pixels), capped at 1280×8000 CSS pixels and device scale 2.
|
|
76
83
|
*/
|
|
77
|
-
export async function captureElectronUrl({ createBrowserWindow, request: input }, { allowedOrigins = [], signal } = {}) {
|
|
84
|
+
export async function captureElectronUrl({ createBrowserWindow, capturePool, request: input }, { allowedOrigins = [], signal } = {}) {
|
|
78
85
|
const request = readUrlCaptureRequest({ value: input });
|
|
79
86
|
if (!isCaptureUrlAllowed({ url: request.url, allowedOrigins })) {
|
|
80
87
|
throw new RenderServiceError({ code: 'navigation-blocked', message: 'capture URL must stay on the site origin' });
|
|
81
88
|
}
|
|
82
89
|
const deadline = Date.now() + URL_CAPTURE_TIMEOUT_MS;
|
|
83
|
-
const slot = await
|
|
90
|
+
const slot = await capturePool.acquire({ deadline }, { signal });
|
|
84
91
|
let captureSession;
|
|
85
92
|
let initialReset;
|
|
86
93
|
let blockedRequests = 0;
|
|
@@ -149,13 +156,13 @@ export async function captureElectronUrl({ createBrowserWindow, request: input }
|
|
|
149
156
|
finally {
|
|
150
157
|
// A stuck reset keeps its lease but must not hold the caller beyond the cleanup budget.
|
|
151
158
|
// Cleanup must not replace a completed capture or its original error near the render deadline.
|
|
152
|
-
await withRenderTimeout({ promise: releaseCaptureSlot({ slot, session: captureSession, initialReset }) }, { timeoutMs: CAPTURE_CLEANUP_TIMEOUT_MS }).catch(() => { });
|
|
159
|
+
await withRenderTimeout({ promise: releaseCaptureSlot({ capturePool, slot, session: captureSession, initialReset }) }, { timeoutMs: CAPTURE_CLEANUP_TIMEOUT_MS }).catch(() => { });
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
/** Return a lease only once its session is reset; the next capture resets again before use.
|
|
156
163
|
* @throws RenderServiceError when the reset fails (the lease is still returned). @complexity O(1).
|
|
157
164
|
*/
|
|
158
|
-
async function releaseCaptureSlot({ slot, session, initialReset }, _options = {}) {
|
|
165
|
+
async function releaseCaptureSlot({ capturePool, slot, session, initialReset }, _options = {}) {
|
|
159
166
|
try {
|
|
160
167
|
// Destruction stops navigation first. A timed-out preparation must settle before its
|
|
161
168
|
// cleanup or a new capture can touch the same session.
|
|
@@ -166,7 +173,7 @@ async function releaseCaptureSlot({ slot, session, initialReset }, _options = {}
|
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
175
|
finally {
|
|
169
|
-
|
|
176
|
+
capturePool.release({ slot });
|
|
170
177
|
}
|
|
171
178
|
}
|
|
172
179
|
function readPageHeight({ request, rawHeight }, _options = {}) {
|
package/dist/electron/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './electron-single-instance.js';
|
|
|
11
11
|
export * from './electron-window-lifecycle.js';
|
|
12
12
|
export * from './electron-protocol.js';
|
|
13
13
|
export * from './electron-render-service.js';
|
|
14
|
+
export { createElectronUrlCapturePool, type ElectronUrlCapturePoolPort } from './electron-url-capture.js';
|
|
14
15
|
export * from './electron-process-memory.js';
|
|
15
16
|
export * from './electron-shell.js';
|
|
16
17
|
export * from './create-electron-desktop-host.js';
|
package/dist/electron/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './electron-single-instance.js';
|
|
|
11
11
|
export * from './electron-window-lifecycle.js';
|
|
12
12
|
export * from './electron-protocol.js';
|
|
13
13
|
export * from './electron-render-service.js';
|
|
14
|
+
export { createElectronUrlCapturePool } from './electron-url-capture.js';
|
|
14
15
|
export * from './electron-process-memory.js';
|
|
15
16
|
export * from './electron-shell.js';
|
|
16
17
|
export * from './create-electron-desktop-host.js';
|
|
@@ -65,12 +65,12 @@ export function createFileInstancePresence({ directory, filesystem, isAlive, wri
|
|
|
65
65
|
}
|
|
66
66
|
// Leave unreadable/malformed records alone: a sibling may be writing on a filesystem
|
|
67
67
|
// without atomic rename. Remove confirmed dead PIDs so crashes do not linger.
|
|
68
|
-
if (record
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
if (record !== null && name === `${record.pid}.json`) {
|
|
69
|
+
if (isAlive({ pid: record.pid }))
|
|
70
|
+
live.push(record);
|
|
71
|
+
else
|
|
72
|
+
remove({ pid: record.pid });
|
|
73
|
+
}
|
|
74
74
|
}
|
|
75
75
|
return live;
|
|
76
76
|
},
|
|
@@ -91,7 +91,7 @@ export function writeNodeToolchain(input) {
|
|
|
91
91
|
}
|
|
92
92
|
/** Host-named environment contract; duplicate/invalid names fail loudly. @complexity O(n) in names. */
|
|
93
93
|
export function buildNodeToolchainEnv({ toolchainDir, npmRoot, toolchainEnvName, npmRootEnvName }) {
|
|
94
|
-
if (![toolchainEnvName, npmRootEnvName].every(name => /^[A-Za-z_]
|
|
94
|
+
if (![toolchainEnvName, npmRootEnvName].every(name => /^[A-Za-z_]\w*$/.test(name)) || toolchainEnvName === npmRootEnvName) {
|
|
95
95
|
throw new Error('node-toolchain: environment names must be valid and distinct.');
|
|
96
96
|
}
|
|
97
97
|
return { [toolchainEnvName]: toolchainDir, [npmRootEnvName]: npmRoot };
|
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { trimCharsEnd } from '@jini-ai/core/primitives';
|
|
1
2
|
/**
|
|
2
3
|
* Generalized from OD `apps/packaged/src/paths.ts`. On inspection this file
|
|
3
4
|
* was **far more OD-coupled than the task brief expected**: it hardcodes
|
|
@@ -36,7 +37,7 @@ function expandHomePrefix(raw) {
|
|
|
36
37
|
return raw;
|
|
37
38
|
}
|
|
38
39
|
function scopedNamespaceOf(raw) {
|
|
39
|
-
const parts = raw
|
|
40
|
+
const parts = trimCharsEnd({ text: raw, chars: '\\/' }).split(/[\\/]+/);
|
|
40
41
|
const last = parts.length - 1;
|
|
41
42
|
if (last < 2)
|
|
42
43
|
return null;
|
package/dist/render-bridge.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
5
5
|
import { createServer } from 'node:http';
|
|
6
6
|
import { RenderServiceError } from './render-service.js';
|
|
7
|
+
/** The error code for every capture that could not be loaded or delivered intact. */
|
|
8
|
+
const LOAD_FAILED = 'load-failed';
|
|
7
9
|
import { readUrlCaptureRequest, URL_CAPTURE_MAX_BYTES, URL_CAPTURE_TIMEOUT_MS } from './url-capture.js';
|
|
8
10
|
export const RENDER_BRIDGE_URL_ENV = 'JINI_DESKTOP_RENDER_URL';
|
|
9
11
|
export const RENDER_BRIDGE_TOKEN_ENV = 'JINI_DESKTOP_RENDER_TOKEN';
|
|
@@ -17,7 +19,7 @@ async function readBody({ stream, limit }) {
|
|
|
17
19
|
for await (const chunk of stream) {
|
|
18
20
|
size += chunk.byteLength;
|
|
19
21
|
if (size > limit)
|
|
20
|
-
throw new RenderServiceError({ code:
|
|
22
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'capture transport size limit exceeded' });
|
|
21
23
|
chunks.push(Buffer.from(chunk));
|
|
22
24
|
}
|
|
23
25
|
return Buffer.concat(chunks);
|
|
@@ -64,12 +66,12 @@ export async function startRenderBridge({ capture }, { createServer: makeServer
|
|
|
64
66
|
const request = readUrlCaptureRequest({ value: JSON.parse((await readBody({ stream: req, limit: 8192 })).toString('utf8')) });
|
|
65
67
|
const result = await capture.captureUrl(request, { signal: controller.signal });
|
|
66
68
|
if (result.png.byteLength > URL_CAPTURE_MAX_BYTES)
|
|
67
|
-
throw new RenderServiceError({ code:
|
|
69
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'capture too large' });
|
|
68
70
|
res.setHeader('Content-Type', 'application/json');
|
|
69
71
|
res.end(JSON.stringify({ ...result, png: Buffer.from(result.png).toString('base64') }));
|
|
70
72
|
}
|
|
71
73
|
catch (error) {
|
|
72
|
-
const code = error instanceof RenderServiceError ? error.code :
|
|
74
|
+
const code = error instanceof RenderServiceError ? error.code : LOAD_FAILED;
|
|
73
75
|
res.writeHead(400, { 'Content-Type': 'application/json' }).end(JSON.stringify({ error: code }));
|
|
74
76
|
}
|
|
75
77
|
finally {
|
|
@@ -87,23 +89,25 @@ export async function startRenderBridge({ capture }, { createServer: makeServer
|
|
|
87
89
|
close() { closed = true; active?.abort(); server.close(); server.closeAllConnections(); } };
|
|
88
90
|
}
|
|
89
91
|
function isPrivateCaptureEndpoint({ url }, _options = {}) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
const loopbackCapture = url.protocol === 'http:' && url.hostname === '127.0.0.1' && url.pathname === '/capture';
|
|
93
|
+
if (!loopbackCapture)
|
|
94
|
+
return false;
|
|
95
|
+
return !url.username && !url.password && !url.search && !url.hash;
|
|
92
96
|
}
|
|
93
97
|
async function readCaptureResponse({ response }, _options = {}) {
|
|
94
98
|
if (!response.body)
|
|
95
|
-
throw new RenderServiceError({ code:
|
|
99
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'empty desktop capture response' });
|
|
96
100
|
const data = JSON.parse((await readBody({ stream: response.body, limit: MAX_WIRE_BYTES })).toString('utf8'));
|
|
97
101
|
if (!response.ok) {
|
|
98
|
-
const known = ['timeout', 'aborted',
|
|
99
|
-
const code = known.includes(data.error) ? data.error :
|
|
102
|
+
const known = ['timeout', 'aborted', LOAD_FAILED, 'navigation-blocked', 'not-implemented'];
|
|
103
|
+
const code = known.includes(data.error) ? data.error : LOAD_FAILED;
|
|
100
104
|
throw new RenderServiceError({ code, message: 'desktop capture failed' });
|
|
101
105
|
}
|
|
102
106
|
if (typeof data.png !== 'string' || data.png.length > MAX_WIRE_BYTES)
|
|
103
|
-
throw new RenderServiceError({ code:
|
|
107
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'invalid desktop capture response' });
|
|
104
108
|
const png = Buffer.from(data.png, 'base64');
|
|
105
109
|
if (png.byteLength > URL_CAPTURE_MAX_BYTES)
|
|
106
|
-
throw new RenderServiceError({ code:
|
|
110
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'capture too large' });
|
|
107
111
|
return { ...data, png };
|
|
108
112
|
}
|
|
109
113
|
/** Detect a complete private bridge contract; a partial/invalid contract fails closed.
|
|
@@ -121,10 +125,10 @@ export function renderBridgeFromEnv({ env }, { fetch: send = globalThis.fetch }
|
|
|
121
125
|
url = new URL(endpoint ?? '');
|
|
122
126
|
}
|
|
123
127
|
catch {
|
|
124
|
-
throw new RenderServiceError({ code:
|
|
128
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'invalid desktop capture channel' });
|
|
125
129
|
}
|
|
126
130
|
if (!isPrivateCaptureEndpoint({ url }) || !/^[a-f0-9]{64}$/.test(token ?? '')) {
|
|
127
|
-
throw new RenderServiceError({ code:
|
|
131
|
+
throw new RenderServiceError({ code: LOAD_FAILED, message: 'invalid desktop capture channel' });
|
|
128
132
|
}
|
|
129
133
|
return { async captureUrl(request, { signal } = {}) {
|
|
130
134
|
const timeout = AbortSignal.timeout(URL_CAPTURE_TIMEOUT_MS);
|
|
@@ -139,7 +143,8 @@ export function renderBridgeFromEnv({ env }, { fetch: send = globalThis.fetch }
|
|
|
139
143
|
catch (error) {
|
|
140
144
|
if (error instanceof RenderServiceError)
|
|
141
145
|
throw error;
|
|
142
|
-
const
|
|
146
|
+
const cancelledCode = signal?.aborted ? 'aborted' : LOAD_FAILED;
|
|
147
|
+
const code = timeout.aborted ? 'timeout' : cancelledCode;
|
|
143
148
|
throw new RenderServiceError({ code, message: 'desktop capture channel unavailable' });
|
|
144
149
|
}
|
|
145
150
|
} };
|
package/dist/sidecar.js
CHANGED
|
@@ -42,7 +42,10 @@ async function waitUntilReady(child, logPath, options) {
|
|
|
42
42
|
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
43
43
|
let lastError;
|
|
44
44
|
const exitError = (code, signal) => new Error(`sidecar exited before reporting ready (code=${code}, signal=${signal ?? 'none'})${logPath == null ? '' : `; see ${logPath} for details`}`);
|
|
45
|
-
const timeoutError = () =>
|
|
45
|
+
const timeoutError = () => {
|
|
46
|
+
const detail = lastError instanceof Error ? ` (${lastError.message})` : '';
|
|
47
|
+
return new Error(`timed out waiting for sidecar to become ready${detail}`);
|
|
48
|
+
};
|
|
46
49
|
if (child.exitCode !== null || child.signalCode !== null)
|
|
47
50
|
throw exitError(child.exitCode, child.signalCode);
|
|
48
51
|
if (timeoutMs <= 0)
|
|
@@ -97,7 +97,9 @@ async function checkAvailability(deps) {
|
|
|
97
97
|
return { available: result.available, reason: result.reason ?? undefined };
|
|
98
98
|
}
|
|
99
99
|
function readSuccessfulTranscription({ result, messages }, _options = {}) {
|
|
100
|
-
|
|
100
|
+
const badText = result.text !== undefined && typeof result.text !== "string";
|
|
101
|
+
const badElapsed = result.elapsedMs !== undefined && (typeof result.elapsedMs !== "number" || !Number.isFinite(result.elapsedMs));
|
|
102
|
+
if (badText || badElapsed) {
|
|
101
103
|
throw new Error(messages.invalidOutput({ stdout: JSON.stringify(result) }));
|
|
102
104
|
}
|
|
103
105
|
return { text: result.text ?? "", elapsedMs: result.elapsedMs ?? 0 };
|
|
@@ -49,7 +49,8 @@ async function waitUntilReady({ exit, probe, isReady }, options = {}) {
|
|
|
49
49
|
}
|
|
50
50
|
await sleep(pollIntervalMs);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
const detail = lastError instanceof Error ? ` (${lastError.message})` : '';
|
|
53
|
+
throw new Error(`timed out waiting for sidecar to become ready${detail}`);
|
|
53
54
|
}
|
|
54
55
|
/** Use the host's shutdown request or SIGTERM, then bound the wait before SIGKILL. */
|
|
55
56
|
async function shutdownChild({ child, exit }, options = {}) {
|
package/dist/tauri/testing.js
CHANGED
|
@@ -101,16 +101,15 @@ export function createFakeTauriSidecarCommandApi(_requiredArgs, script = {}) {
|
|
|
101
101
|
async spawnSidecar({ binaryName, args }) {
|
|
102
102
|
spawned.push({ binaryName, args });
|
|
103
103
|
const exitListeners = [];
|
|
104
|
-
let killed = false;
|
|
105
104
|
const child = {
|
|
106
105
|
pid: 4242,
|
|
107
106
|
onExit({ listener }) {
|
|
108
107
|
exitListeners.push(listener);
|
|
109
108
|
},
|
|
110
109
|
kill(_requiredArgs, { signal } = {}) {
|
|
110
|
+
// A child that ignores graceful shutdown still accepts the signal; only SIGKILL ends it.
|
|
111
111
|
if (script.ignoresGracefulShutdown === true && signal !== 'SIGKILL')
|
|
112
112
|
return true;
|
|
113
|
-
killed = true;
|
|
114
113
|
// A macrotask, not queueMicrotask: real process exit delivery
|
|
115
114
|
// happens after the event loop's current microtask work drains
|
|
116
115
|
// (the caller's own await chains included). queueMicrotask here
|
|
@@ -137,7 +136,6 @@ export function createFakeTauriSidecarCommandApi(_requiredArgs, script = {}) {
|
|
|
137
136
|
listener({ code: exitImmediatelyWithCode, signal: null });
|
|
138
137
|
}, 0);
|
|
139
138
|
}
|
|
140
|
-
void killed;
|
|
141
139
|
return child;
|
|
142
140
|
},
|
|
143
141
|
};
|
package/dist/url-capture.js
CHANGED
|
@@ -18,20 +18,23 @@ function integerInRange({ value, min, max }, _options = {}) {
|
|
|
18
18
|
return typeof value === 'number' && Number.isInteger(value) && value >= min && value <= max;
|
|
19
19
|
}
|
|
20
20
|
function validCaptureViewport({ viewport }, _options = {}) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if (!viewport)
|
|
22
|
+
return false;
|
|
23
|
+
const sizeOk = integerInRange({ value: viewport.width, min: 1, max: 1280 }) && integerInRange({ value: viewport.height, min: 1, max: 1024 });
|
|
24
|
+
return sizeOk && [undefined, 1, 2].includes(viewport.deviceScaleFactor) && [undefined, true, false].includes(viewport.isMobile);
|
|
25
25
|
}
|
|
26
26
|
/** Parse the wire request before allocating a renderer; reject oversized images and waits.
|
|
27
27
|
* @throws RenderServiceError for invalid input. @complexity O(url length).
|
|
28
28
|
*/
|
|
29
29
|
export function readUrlCaptureRequest({ value }, _options = {}) {
|
|
30
30
|
const request = value;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (!request || typeof request.url !== 'string' || request.url.length > 2048) {
|
|
32
|
+
throw new RenderServiceError({ code: 'load-failed', message: 'invalid capture request' });
|
|
33
|
+
}
|
|
34
|
+
const viewport = request.viewport;
|
|
35
|
+
const validSize = validCaptureViewport({ viewport }) && integerInRange({ value: request.maxPageHeightPx, min: 1, max: 8000 });
|
|
36
|
+
const validWait = integerInRange({ value: request.settleMs, min: 0, max: 5000 });
|
|
37
|
+
if (!validSize || !validWait || typeof request.fullPage !== 'boolean') {
|
|
35
38
|
throw new RenderServiceError({ code: 'load-failed', message: 'invalid capture request' });
|
|
36
39
|
}
|
|
37
40
|
return { url: request.url, viewport: { ...viewport }, fullPage: request.fullPage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/desktop-host",
|
|
3
|
-
"version": "0.6.15
|
|
3
|
+
"version": "0.6.15",
|
|
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": {
|
|
@@ -113,10 +113,10 @@
|
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@vitest/coverage-v8": "^2.1.9",
|
|
116
|
-
"@jini-ai/core": "^0.6.15
|
|
116
|
+
"@jini-ai/core": "^0.6.15"
|
|
117
117
|
},
|
|
118
118
|
"dependencies": {
|
|
119
|
-
"@jini-ai/core": "^0.6.15
|
|
119
|
+
"@jini-ai/core": "^0.6.15"
|
|
120
120
|
},
|
|
121
121
|
"peerDependencies": {},
|
|
122
122
|
"peerDependenciesMeta": {},
|