@sovovs/bycli 2.1.3 → 2.1.5
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/src/daemon.js +28 -1
- package/package.json +1 -1
package/dist/src/daemon.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* - Listens on 127.0.0.1:19825 by default; isolated sandboxes may opt into 0.0.0.0
|
|
21
21
|
*/
|
|
22
22
|
import { createServer } from 'node:http';
|
|
23
|
+
import { spawn } from 'node:child_process';
|
|
23
24
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
24
25
|
import { DEFAULT_DAEMON_PORT } from './constants.js';
|
|
25
26
|
import { EXIT_CODES } from './errors.js';
|
|
@@ -40,6 +41,7 @@ import { buildCommandDispatchFailure, buildExtensionDisconnectFailure, getRespon
|
|
|
40
41
|
import { resolveDaemonHost } from './daemon-config.js';
|
|
41
42
|
const PORT = parseInt(process.env.BYCLI_DAEMON_PORT ?? String(DEFAULT_DAEMON_PORT), 10);
|
|
42
43
|
const HOST = resolveDaemonHost();
|
|
44
|
+
const BROWSER_RECOVERY_COMMAND = process.env.BYCLI_BROWSER_RECOVERY_COMMAND?.trim();
|
|
43
45
|
// The verify runner (M6b) spawns child processes that connect back to THIS daemon for a
|
|
44
46
|
// browser Page. Hand them our port (→ BYCLI_DAEMON_PORT in the child env) so the child's
|
|
45
47
|
// Page reaches us, not a freshly-spawned daemon. Must run before the first /v1/verify
|
|
@@ -359,6 +361,31 @@ async function handleRequest(req, res) {
|
|
|
359
361
|
jsonResponse(res, 200, { ok: true, data: { requestId, status: runStatus.status, result: runStatus.summary } });
|
|
360
362
|
return;
|
|
361
363
|
}
|
|
364
|
+
if (req.method === 'POST' && pathname === '/v1/browser/recover') {
|
|
365
|
+
if (!BROWSER_RECOVERY_COMMAND) {
|
|
366
|
+
jsonResponse(res, 503, {
|
|
367
|
+
ok: false,
|
|
368
|
+
errorCode: 'browser_recovery_unavailable',
|
|
369
|
+
error: 'Browser recovery is not configured.',
|
|
370
|
+
});
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const child = spawn(BROWSER_RECOVERY_COMMAND, [], { detached: true, stdio: 'ignore' });
|
|
375
|
+
child.on('error', () => logger.warn('daemon.browser_recover', { errorCode: 'browser_recovery_spawn_failed' }));
|
|
376
|
+
child.unref();
|
|
377
|
+
jsonResponse(res, 202, { ok: true, data: { started: true } });
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
logger.warn('daemon.browser_recover', { errorCode: 'browser_recovery_spawn_failed' });
|
|
381
|
+
jsonResponse(res, 503, {
|
|
382
|
+
ok: false,
|
|
383
|
+
errorCode: 'browser_recovery_unavailable',
|
|
384
|
+
error: 'Browser recovery could not be started.',
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
362
389
|
if (req.method === 'GET' && pathname === '/status') {
|
|
363
390
|
const uptime = process.uptime();
|
|
364
391
|
const mem = process.memoryUsage();
|
|
@@ -420,7 +447,7 @@ async function handleRequest(req, res) {
|
|
|
420
447
|
setTimeout(() => shutdown(), 100);
|
|
421
448
|
return;
|
|
422
449
|
}
|
|
423
|
-
if (req.method === 'POST' &&
|
|
450
|
+
if (req.method === 'POST' && pathname === '/command') {
|
|
424
451
|
try {
|
|
425
452
|
const body = JSON.parse(await readBody(req));
|
|
426
453
|
if (!body.id) {
|