@duanluan/codex-plus-plus-launcher 1.2.18 → 1.2.19
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/npm/launcher.js
CHANGED
|
@@ -447,10 +447,12 @@ function exitSoon(code) {
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
|
|
450
|
+
const HTTP_HOSTS = ['localhost', '127.0.0.1', '::1'];
|
|
451
|
+
|
|
452
|
+
function readJsonFromHost(host, pathname) {
|
|
451
453
|
return new Promise((resolve, reject) => {
|
|
452
454
|
const request = http.get({
|
|
453
|
-
host
|
|
455
|
+
host,
|
|
454
456
|
port: debugPort,
|
|
455
457
|
path: pathname,
|
|
456
458
|
timeout: 1500,
|
|
@@ -471,13 +473,30 @@ function readJson(pathname) {
|
|
|
471
473
|
});
|
|
472
474
|
}
|
|
473
475
|
|
|
476
|
+
async function readJson(pathname) {
|
|
477
|
+
let lastError = null;
|
|
478
|
+
for (const host of HTTP_HOSTS) {
|
|
479
|
+
try {
|
|
480
|
+
return await readJsonFromHost(host, pathname);
|
|
481
|
+
} catch (error) {
|
|
482
|
+
lastError = error;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
throw lastError || new Error('CDP HTTP unavailable');
|
|
486
|
+
}
|
|
487
|
+
|
|
474
488
|
function parseWebSocketTarget(webSocketDebuggerUrl) {
|
|
475
489
|
const parsed = new URL(webSocketDebuggerUrl);
|
|
476
490
|
if (parsed.protocol !== 'ws:') {
|
|
477
491
|
throw new Error('unsupported websocket protocol');
|
|
478
492
|
}
|
|
493
|
+
const host = parsed.hostname.startsWith('[') && parsed.hostname.endsWith(']')
|
|
494
|
+
? parsed.hostname.slice(1, -1)
|
|
495
|
+
: parsed.hostname;
|
|
496
|
+
const hostHeader = host.includes(':') ? '[' + host + ']' : host;
|
|
479
497
|
return {
|
|
480
|
-
host
|
|
498
|
+
host,
|
|
499
|
+
hostHeader,
|
|
481
500
|
port: Number(parsed.port || 80),
|
|
482
501
|
path: (parsed.pathname || '/') + (parsed.search || ''),
|
|
483
502
|
};
|
|
@@ -617,7 +636,7 @@ function evaluateMenuState(webSocketDebuggerUrl) {
|
|
|
617
636
|
const key = crypto.randomBytes(16).toString('base64');
|
|
618
637
|
socket.write([
|
|
619
638
|
'GET ' + target.path + ' HTTP/1.1',
|
|
620
|
-
'Host: ' + target.
|
|
639
|
+
'Host: ' + target.hostHeader + ':' + target.port,
|
|
621
640
|
'Upgrade: websocket',
|
|
622
641
|
'Connection: Upgrade',
|
|
623
642
|
'Sec-WebSocket-Key: ' + key,
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|