@myagentroam/node 0.10.13 → 0.10.14
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { request as httpRequest } from 'node:http';
|
|
2
2
|
import { request as httpsRequest } from 'node:https';
|
|
3
|
+
import { TLSSocket } from 'node:tls';
|
|
3
4
|
import { createBrotliDecompress, createGunzip, createInflate } from 'node:zlib';
|
|
4
5
|
import { pipeline } from 'node:stream/promises';
|
|
5
6
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
@@ -48,7 +49,7 @@ export class WebFetchService {
|
|
|
48
49
|
throw new WebFetchError('MAR_AGENT_WEB_FETCH_CANCELLED', 503, 'Web fetch was cancelled.');
|
|
49
50
|
if (error instanceof WebFetchError)
|
|
50
51
|
throw error;
|
|
51
|
-
throw
|
|
52
|
+
throw upstreamFailure(error, parsed.data.mode, parsed.data.mode === 'http' ? 'response' : 'browser');
|
|
52
53
|
});
|
|
53
54
|
this.#active.add(task);
|
|
54
55
|
void task.then(() => this.#active.delete(task), () => this.#active.delete(task));
|
|
@@ -322,6 +323,21 @@ export class WebFetchService {
|
|
|
322
323
|
function readableContentType(contentType) {
|
|
323
324
|
return /^(?:text\/|application\/(?:[\w.+-]+\+)?(?:json|xml)(?:[;\s]|$))/iu.test(contentType);
|
|
324
325
|
}
|
|
326
|
+
function upstreamFailure(error, mode, phase) {
|
|
327
|
+
const upstreamCode = error instanceof Error &&
|
|
328
|
+
'code' in error &&
|
|
329
|
+
typeof error.code === 'string' &&
|
|
330
|
+
/^[A-Z][A-Z0-9_]{0,79}$/u.test(error.code)
|
|
331
|
+
? error.code
|
|
332
|
+
: undefined;
|
|
333
|
+
const operation = {
|
|
334
|
+
tls: 'TLS negotiation',
|
|
335
|
+
request: 'the HTTP request',
|
|
336
|
+
response: 'the HTTP response read',
|
|
337
|
+
browser: 'the browser read'
|
|
338
|
+
}[phase];
|
|
339
|
+
return new WebFetchError('MAR_AGENT_WEB_FETCH_UPSTREAM_FAILED', 502, `Web fetch upstream failed during ${operation}${upstreamCode ? ` (${upstreamCode})` : ''}.`, { mode, phase, ...(upstreamCode ? { upstreamCode } : {}) });
|
|
340
|
+
}
|
|
325
341
|
function validateResponse(status, contentType) {
|
|
326
342
|
if (status < 200 || status >= 300)
|
|
327
343
|
throw new WebFetchError('MAR_AGENT_WEB_FETCH_UPSTREAM_FAILED', 502, 'Web fetch upstream returned an HTTP error.', { upstreamStatus: status });
|
|
@@ -330,6 +346,7 @@ function validateResponse(status, contentType) {
|
|
|
330
346
|
}
|
|
331
347
|
function requestHttp(url, signal, allowUntrustedTls) {
|
|
332
348
|
return new Promise((resolve, reject) => {
|
|
349
|
+
let phase = 'request';
|
|
333
350
|
const request = (url.protocol === 'https:' ? httpsRequest : httpRequest)(url, {
|
|
334
351
|
signal,
|
|
335
352
|
headers: {
|
|
@@ -339,7 +356,17 @@ function requestHttp(url, signal, allowUntrustedTls) {
|
|
|
339
356
|
},
|
|
340
357
|
...(url.protocol === 'https:' ? { rejectUnauthorized: !allowUntrustedTls } : {})
|
|
341
358
|
}, resolve);
|
|
342
|
-
request.once('
|
|
359
|
+
request.once('socket', (socket) => {
|
|
360
|
+
if (socket instanceof TLSSocket && !request.reusedSocket) {
|
|
361
|
+
socket.once('connect', () => {
|
|
362
|
+
phase = 'tls';
|
|
363
|
+
});
|
|
364
|
+
socket.once('secureConnect', () => {
|
|
365
|
+
phase = 'request';
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
request.once('error', (error) => reject(upstreamFailure(error, 'http', phase)));
|
|
343
370
|
request.end();
|
|
344
371
|
});
|
|
345
372
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myagentroam/node",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.14",
|
|
4
4
|
"description": "MyAgentRoam Node runtime CLI.",
|
|
5
5
|
"license": "Apache-2.0 AND GPL-2.0-or-later",
|
|
6
6
|
"type": "module",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"playwright": "1.62.1",
|
|
38
38
|
"ws": "^8.21.3",
|
|
39
39
|
"zod": "4.4.3",
|
|
40
|
-
"@myagentroam/agent": "0.10.
|
|
40
|
+
"@myagentroam/agent": "0.10.14",
|
|
41
41
|
"@myagentroam/code-navigation": "0.10.1",
|
|
42
42
|
"@myagentroam/marctl": "0.10.2",
|
|
43
|
-
"@myagentroam/protocol": "0.10.
|
|
43
|
+
"@myagentroam/protocol": "0.10.14"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/ws": "^8.18.1"
|