maka-agent 0.2.0-dev.64.20260929 → 0.2.0-dev.67.20261002

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 (94) hide show
  1. package/LICENSE +1 -1
  2. package/THIRD_PARTY_NOTICES.txt +3 -3
  3. package/dist/pi-tui-runner.js +26 -29
  4. package/dist/tui-copy-catalog.js +9 -9
  5. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  6. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  7. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  8. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  9. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  10. package/node_modules/@maka/core/dist/settings.js +2 -2
  11. package/node_modules/@maka/core/dist/tool-ledger-scanner.js +53 -150
  12. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +8 -1
  13. package/node_modules/@maka/runtime/dist/conversation-copy.js +6 -0
  14. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +17 -0
  15. package/node_modules/@maka/runtime/dist/session-manager.js +25 -40
  16. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +79 -13
  17. package/node_modules/@maka/runtime/dist/stream-graph-projection.js +64 -0
  18. package/node_modules/@maka/runtime/dist/stream-graph-read-model.js +138 -20
  19. package/node_modules/@maka/runtime/dist/tool-availability.js +10 -3
  20. package/node_modules/@maka/runtime-host/dist/candidate-entry.js +15 -0
  21. package/node_modules/@maka/runtime-host/dist/candidate-startup-failure.js +5 -0
  22. package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
  23. package/node_modules/@maka/runtime-host/dist/client/startup-error.js +5 -0
  24. package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +46 -1
  25. package/node_modules/@maka/runtime-host/dist/protocol/index.js +14 -1
  26. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
  27. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +12 -0
  28. package/node_modules/@maka/runtime-host/dist/protocol/session-retirement.js +46 -10
  29. package/node_modules/@maka/runtime-host/dist/protocol/storage-usage.js +155 -0
  30. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +23 -0
  31. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +5 -0
  32. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +27 -6
  33. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +2 -0
  34. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +6 -0
  35. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +112 -36
  36. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +27 -1
  37. package/node_modules/@maka/runtime-host/dist/server/storage-usage-coordinator.js +67 -0
  38. package/node_modules/@maka/runtime-host/dist/server/workhub-inspection-tool.js +208 -0
  39. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +3 -1
  40. package/node_modules/@maka/storage/dist/operational-state-store.js +0 -13
  41. package/node_modules/@maka/storage/dist/session-store.js +9 -6
  42. package/node_modules/@maka/storage/dist/sqlite-file-set.js +22 -0
  43. package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +1 -3
  44. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +10 -260
  45. package/node_modules/@maka/storage/dist/sqlite-session-catalog-query.js +1 -0
  46. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +18 -6
  47. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +28 -6
  48. package/node_modules/@maka/storage/dist/storage-footprint.js +239 -0
  49. package/node_modules/@maka/storage/dist/storage-writer-composition.js +10 -1
  50. package/node_modules/axios/CHANGELOG.md +62 -0
  51. package/node_modules/axios/README.md +297 -5
  52. package/node_modules/axios/dist/axios.js +728 -170
  53. package/node_modules/axios/dist/axios.min.js +3 -3
  54. package/node_modules/axios/dist/browser/axios.cjs +871 -188
  55. package/node_modules/axios/dist/esm/axios.js +871 -188
  56. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  57. package/node_modules/axios/dist/node/axios.cjs +1037 -225
  58. package/node_modules/axios/lib/adapters/fetch.js +64 -11
  59. package/node_modules/axios/lib/adapters/http.js +140 -67
  60. package/node_modules/axios/lib/adapters/xhr.js +52 -3
  61. package/node_modules/axios/lib/core/Axios.js +43 -20
  62. package/node_modules/axios/lib/core/AxiosError.js +33 -2
  63. package/node_modules/axios/lib/core/AxiosHeaders.js +124 -1
  64. package/node_modules/axios/lib/core/InterceptorManager.js +107 -8
  65. package/node_modules/axios/lib/core/buildFullPath.js +41 -15
  66. package/node_modules/axios/lib/core/dispatchRequest.js +8 -2
  67. package/node_modules/axios/lib/core/mergeConfig.js +19 -4
  68. package/node_modules/axios/lib/core/methodList.js +17 -0
  69. package/node_modules/axios/lib/core/setFormDataHeaders.js +27 -0
  70. package/node_modules/axios/lib/defaults/index.js +2 -1
  71. package/node_modules/axios/lib/env/data.js +1 -1
  72. package/node_modules/axios/lib/helpers/Http2Sessions.js +2 -0
  73. package/node_modules/axios/lib/helpers/HttpStatusCode.js +12 -1
  74. package/node_modules/axios/lib/helpers/combineURLs.js +11 -3
  75. package/node_modules/axios/lib/helpers/composeSignals.js +12 -1
  76. package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
  77. package/node_modules/axios/lib/helpers/formDataToJSON.js +11 -5
  78. package/node_modules/axios/lib/helpers/fromDataURI.js +5 -4
  79. package/node_modules/axios/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
  80. package/node_modules/axios/lib/helpers/parseHeaders.js +5 -3
  81. package/node_modules/axios/lib/helpers/progressEventReducer.js +4 -4
  82. package/node_modules/axios/lib/helpers/resolveConfig.js +5 -17
  83. package/node_modules/axios/lib/helpers/shouldBypassProxy.js +300 -5
  84. package/node_modules/axios/lib/helpers/throttle.js +3 -2
  85. package/node_modules/axios/lib/helpers/toFormData.js +17 -23
  86. package/node_modules/axios/lib/platform/node/classes/Buffer.js +11 -0
  87. package/node_modules/axios/lib/utils.js +151 -18
  88. package/node_modules/axios/package.json +21 -19
  89. package/node_modules/brace-expansion/dist/commonjs/index.js +69 -25
  90. package/node_modules/brace-expansion/dist/esm/index.js +68 -24
  91. package/node_modules/brace-expansion/package.json +2 -1
  92. package/node_modules/fast-uri/index.js +10 -6
  93. package/node_modules/fast-uri/package.json +1 -1
  94. package/package.json +1 -1
@@ -17,6 +17,18 @@ import { toByteStringHeaderObject } from '../helpers/sanitizeHeaderValue.js';
17
17
 
18
18
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
19
19
 
20
+ const DEFAULT_REQUEST_OPTIONS = {
21
+ cache: 'default',
22
+ redirect: 'follow',
23
+ referrer: 'about:client',
24
+ referrerPolicy: '',
25
+ mode: 'cors',
26
+ integrity: '',
27
+ keepalive: false,
28
+ priority: 'auto',
29
+ window: null,
30
+ };
31
+
20
32
  const { isFunction } = utils;
21
33
 
22
34
  /**
@@ -67,9 +79,7 @@ const maybeWithAuthCredentials = (url) => {
67
79
 
68
80
  const factory = (env) => {
69
81
  const globalObject =
70
- utils.global !== undefined && utils.global !== null
71
- ? utils.global
72
- : globalThis;
82
+ utils.global !== undefined && utils.global !== null ? utils.global : globalThis;
73
83
  const { ReadableStream, TextEncoder } = globalObject;
74
84
 
75
85
  env = utils.merge.call(
@@ -208,6 +218,7 @@ const factory = (env) => {
208
218
  fetchOptions,
209
219
  maxContentLength,
210
220
  maxBodyLength,
221
+ maxRedirects,
211
222
  } = resolveConfig(config);
212
223
 
213
224
  const hasMaxContentLength = utils.isNumber(maxContentLength) && maxContentLength > -1;
@@ -258,7 +269,7 @@ const factory = (env) => {
258
269
  const password = utils.getSafeProp(configAuth, 'password') || '';
259
270
  auth = {
260
271
  username,
261
- password
272
+ password,
262
273
  };
263
274
  }
264
275
 
@@ -270,7 +281,7 @@ const factory = (env) => {
270
281
  const urlPassword = decodeURIComponentSafe(parsedURL.password);
271
282
  auth = {
272
283
  username: urlUsername,
273
- password: urlPassword
284
+ password: urlPassword,
274
285
  };
275
286
  }
276
287
 
@@ -344,7 +355,9 @@ const factory = (env) => {
344
355
  (onUploadProgress || mustEnforceStreamBody)
345
356
  ) {
346
357
  requestContentLength =
347
- requestContentLength == null ? await resolveBodyLength(headers, data) : requestContentLength;
358
+ requestContentLength == null
359
+ ? await resolveBodyLength(headers, data)
360
+ : requestContentLength;
348
361
 
349
362
  // A declared length of 0 is only trusted to skip the wrap when we are
350
363
  // not enforcing a stream limit (which must not rely on that header).
@@ -357,7 +370,10 @@ const factory = (env) => {
357
370
 
358
371
  let contentTypeHeader;
359
372
 
360
- if (utils.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
373
+ if (
374
+ utils.isFormData(data) &&
375
+ (contentTypeHeader = _request.headers.get('content-type'))
376
+ ) {
361
377
  headers.setContentType(contentTypeHeader);
362
378
  }
363
379
 
@@ -420,20 +436,57 @@ const factory = (env) => {
420
436
  // Set User-Agent header if not already set (fetch defaults to 'node' in Node.js)
421
437
  headers.set('User-Agent', 'axios/' + VERSION, false);
422
438
 
423
- const resolvedOptions = {
424
- ...fetchOptions,
439
+ const safeFetchOptions =
440
+ fetchOptions == null ? fetchOptions : Object.assign(Object.create(null), fetchOptions);
441
+
442
+ if (safeFetchOptions) {
443
+ // These options are owned by Axios and are already reflected in the
444
+ // resolved Request passed to fetch.
445
+ delete safeFetchOptions.body;
446
+ delete safeFetchOptions.headers;
447
+ delete safeFetchOptions.method;
448
+ delete safeFetchOptions.signal;
449
+ delete safeFetchOptions.duplex;
450
+ delete safeFetchOptions.credentials;
451
+ }
452
+
453
+ const resolvedOptions = Object.assign(Object.create(null), safeFetchOptions, {
425
454
  signal: composedSignal,
426
455
  method: method.toUpperCase(),
427
456
  headers: toByteStringHeaderObject(headers.normalize()),
428
457
  body: data,
429
458
  duplex: 'half',
430
459
  credentials: isCredentialsSupported ? withCredentials : undefined,
431
- };
460
+ });
461
+
462
+ if (isRequestSupported) {
463
+ utils.forEach(DEFAULT_REQUEST_OPTIONS, (value, key) => {
464
+ if (resolvedOptions[key] === undefined) {
465
+ resolvedOptions[key] = value;
466
+ }
467
+ });
468
+
469
+ if (resolvedOptions.signal === undefined) {
470
+ resolvedOptions.signal = null;
471
+ }
472
+
473
+ if (resolvedOptions.body === undefined) {
474
+ resolvedOptions.body = null;
475
+ }
476
+ }
477
+
478
+ if (maxRedirects === 0) {
479
+ resolvedOptions.redirect = 'manual';
480
+
481
+ if (safeFetchOptions) {
482
+ safeFetchOptions.redirect = 'manual';
483
+ }
484
+ }
432
485
 
433
486
  request = isRequestSupported && new Request(url, resolvedOptions);
434
487
 
435
488
  let response = await (isRequestSupported
436
- ? _fetch(request, fetchOptions)
489
+ ? _fetch(request, safeFetchOptions)
437
490
  : _fetch(url, resolvedOptions));
438
491
 
439
492
  const responseHeaders = AxiosHeaders.from(response.headers);
@@ -19,6 +19,7 @@ import platform from '../platform/index.js';
19
19
  import fromDataURI from '../helpers/fromDataURI.js';
20
20
  import stream from 'stream';
21
21
  import AxiosHeaders from '../core/AxiosHeaders.js';
22
+ import setFormDataHeaders from '../core/setFormDataHeaders.js';
22
23
  import AxiosTransformStream from '../helpers/AxiosTransformStream.js';
23
24
  import { EventEmitter } from 'events';
24
25
  import formDataToStream from '../helpers/formDataToStream.js';
@@ -33,7 +34,7 @@ import {
33
34
  progressEventDecorator,
34
35
  asyncDecorator,
35
36
  } from '../helpers/progressEventReducer.js';
36
- import estimateDataURLDecodedBytes from '../helpers/estimateDataURLDecodedBytes.js';
37
+ import { estimateDataURLBufferAllocation } from '../helpers/estimateDataURLDecodedBytes.js';
37
38
 
38
39
  const zlibOptions = {
39
40
  flush: zlib.constants.Z_SYNC_FLUSH,
@@ -54,30 +55,27 @@ const isBrotliSupported = utils.isFunction(zlib.createBrotliDecompress);
54
55
  const isZstdSupported = utils.isFunction(zlib.createZstdDecompress);
55
56
  const ACCEPT_ENCODING = 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : '');
56
57
  const ACCEPT_ENCODING_WITH_ZSTD = ACCEPT_ENCODING + (isZstdSupported ? ', zstd' : '');
58
+ const scheduleProgress =
59
+ typeof process !== 'undefined' && process.nextTick ? process.nextTick.bind(process) : utils.asap;
57
60
 
58
61
  const { http: httpFollow, https: httpsFollow } = followRedirects;
59
62
 
60
63
  const isHttps = /https:?/;
61
- const FORM_DATA_CONTENT_HEADERS = ['content-type', 'content-length'];
62
-
63
- function setFormDataHeaders(headers, formHeaders, policy) {
64
- if (policy !== 'content-only') {
65
- headers.set(formHeaders);
66
- return;
67
- }
68
-
69
- Object.entries(formHeaders).forEach(([key, val]) => {
70
- if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
71
- headers.set(key, val);
72
- }
73
- });
74
- }
75
64
 
76
65
  // Symbols used to bind a single 'error' listener to a pooled socket and track
77
66
  // the request currently owning that socket across keep-alive reuse (issue #10780).
78
67
  const kAxiosSocketListener = Symbol('axios.http.socketListener');
79
68
  const kAxiosCurrentReq = Symbol('axios.http.currentReq');
80
69
 
70
+ // A shared listener avoids retaining an adapter context for the lifetime of a
71
+ // pooled socket. EventEmitter invokes listeners with `this` set to the emitter.
72
+ function handleSocketError(err) {
73
+ const current = this[kAxiosCurrentReq];
74
+ if (current && !current.destroyed) {
75
+ current.destroy(err);
76
+ }
77
+ }
78
+
81
79
  // Tags HttpsProxyAgent instances installed by setProxy() so the redirect path
82
80
  // can strip them without clobbering a user-supplied agent that happens to be
83
81
  // an HttpsProxyAgent.
@@ -125,16 +123,14 @@ function isNodeEnvProxyEnabled(agent, nodeVersion = process.versions && process.
125
123
  const agentOptions = agent && agent.options;
126
124
 
127
125
  return Boolean(
128
- agentOptions &&
129
- utils.hasOwnProp(agentOptions, 'proxyEnv') &&
130
- agentOptions.proxyEnv != null
126
+ agentOptions && utils.hasOwnProp(agentOptions, 'proxyEnv') && agentOptions.proxyEnv != null
131
127
  );
132
128
  }
133
129
 
134
130
  function getProxyEnvAgent(options, configHttpAgent, configHttpsAgent) {
135
131
  return isHttps.test(options.protocol)
136
- ? (configHttpsAgent || https.globalAgent)
137
- : (configHttpAgent || http.globalAgent);
132
+ ? configHttpsAgent || https.globalAgent
133
+ : configHttpAgent || http.globalAgent;
138
134
  }
139
135
 
140
136
  function getTunnelingAgent(agentOptions, userHttpsAgent) {
@@ -147,17 +143,18 @@ function getTunnelingAgent(agentOptions, userHttpsAgent) {
147
143
  '#' +
148
144
  (agentOptions.auth || '');
149
145
  const cache = userHttpsAgent
150
- ? (tunnelingAgentCacheUser.get(userHttpsAgent) ||
151
- tunnelingAgentCacheUser.set(userHttpsAgent, new Map()).get(userHttpsAgent))
146
+ ? tunnelingAgentCacheUser.get(userHttpsAgent) ||
147
+ tunnelingAgentCacheUser.set(userHttpsAgent, new Map()).get(userHttpsAgent)
152
148
  : tunnelingAgentCache;
153
149
  let agent = cache.get(key);
154
150
  if (agent) return agent;
155
151
  // Forward the user's TLS options (custom CA, rejectUnauthorized, client cert,
156
152
  // etc.) into the tunneling agent so they apply to the origin TLS upgrade
157
153
  // performed after CONNECT. Our proxy fields take precedence on conflict.
158
- const merged = userHttpsAgent && userHttpsAgent.options
159
- ? { ...userHttpsAgent.options, ...agentOptions }
160
- : agentOptions;
154
+ const merged =
155
+ userHttpsAgent && userHttpsAgent.options
156
+ ? { ...userHttpsAgent.options, ...agentOptions }
157
+ : agentOptions;
161
158
  agent = new HttpsProxyAgent(merged);
162
159
  if (userHttpsAgent && userHttpsAgent.options) {
163
160
  const originTLSOptions = { ...userHttpsAgent.options };
@@ -254,13 +251,22 @@ function isSameOriginRedirect(redirectOptions, requestDetails) {
254
251
  * @param {http.ClientRequestArgs} options
255
252
  * @param {AxiosProxyConfig} configProxy configuration from Axios options object
256
253
  * @param {string} location
254
+ * @param {boolean} [allowEnvProxy=true] whether environment proxy configuration can be used
257
255
  *
258
- * @returns {http.ClientRequestArgs}
256
+ * @returns {boolean} whether a proxy applies to the selected transport
259
257
  */
260
- function setProxy(options, configProxy, location, isRedirect, configHttpsAgent, configHttpAgent) {
258
+ function setProxy(
259
+ options,
260
+ configProxy,
261
+ location,
262
+ isRedirect,
263
+ configHttpsAgent,
264
+ configHttpAgent,
265
+ allowEnvProxy = true
266
+ ) {
261
267
  let proxy = configProxy;
262
268
  const proxyEnvAgent = getProxyEnvAgent(options, configHttpAgent, configHttpsAgent);
263
- if (!proxy && proxy !== false && !isNodeEnvProxyEnabled(proxyEnvAgent)) {
269
+ if (!proxy && proxy !== false && allowEnvProxy && !isNodeEnvProxyEnabled(proxyEnvAgent)) {
264
270
  const proxyUrl = getProxyForUrl(location);
265
271
  if (proxyUrl) {
266
272
  if (!shouldBypassProxy(location)) {
@@ -417,9 +423,15 @@ function setProxy(options, configProxy, location, isRedirect, configHttpsAgent,
417
423
  redirectOptions.href,
418
424
  true,
419
425
  configHttpsAgent,
420
- configHttpAgent
426
+ configHttpAgent,
427
+ allowEnvProxy
421
428
  );
422
429
  };
430
+
431
+ return Boolean(
432
+ proxy ||
433
+ (configProxy !== false && allowEnvProxy && isNodeEnvProxyEnabled(proxyEnvAgent))
434
+ );
423
435
  }
424
436
 
425
437
  const isHttpAdapterSupported =
@@ -454,7 +466,7 @@ const wrapAsync = (asyncExecutor) => {
454
466
 
455
467
  const resolveFamily = ({ address, family }) => {
456
468
  if (!utils.isString(address)) {
457
- throw TypeError('address must be a string');
469
+ throw new AxiosError('address must be a string', AxiosError.ERR_BAD_OPTION_VALUE);
458
470
  }
459
471
  return {
460
472
  address,
@@ -465,6 +477,43 @@ const resolveFamily = ({ address, family }) => {
465
477
  const buildAddressEntry = (address, family) =>
466
478
  resolveFamily(utils.isObject(address) ? address : { address, family });
467
479
 
480
+ const normalizedLookupCache = new WeakMap();
481
+
482
+ const normalizeLookup = (lookup) => {
483
+ let normalized = normalizedLookupCache.get(lookup);
484
+
485
+ if (normalized) {
486
+ return normalized;
487
+ }
488
+
489
+ const callbackLookup = callbackify(lookup, (value) => (utils.isArray(value) ? value : [value]));
490
+
491
+ // Support opt.all, which is required by current Node.js releases.
492
+ normalized = (hostname, opt, cb) => {
493
+ callbackLookup(hostname, opt, (err, arg0, arg1) => {
494
+ if (err) {
495
+ return cb(err);
496
+ }
497
+
498
+ let addresses;
499
+
500
+ try {
501
+ addresses = utils.isArray(arg0)
502
+ ? arg0.map((addr) => buildAddressEntry(addr))
503
+ : [buildAddressEntry(arg0, arg1)];
504
+ } catch (error) {
505
+ return cb(error);
506
+ }
507
+
508
+ opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
509
+ });
510
+ };
511
+
512
+ normalizedLookupCache.set(lookup, normalized);
513
+
514
+ return normalized;
515
+ };
516
+
468
517
  const http2Transport = {
469
518
  request(options, cb) {
470
519
  const authority =
@@ -529,6 +578,7 @@ export default isHttpAdapterSupported &&
529
578
  let family = own('family');
530
579
  let httpVersion = own('httpVersion');
531
580
  if (httpVersion === undefined) httpVersion = 1;
581
+ const rawHttpVersion = httpVersion;
532
582
  let http2Options = own('http2Options');
533
583
  const httpAgent = own('httpAgent');
534
584
  const httpsAgent = own('httpsAgent');
@@ -546,34 +596,36 @@ export default isHttpAdapterSupported &&
546
596
  let req;
547
597
  let connectPhaseTimer;
548
598
 
549
- httpVersion = +httpVersion;
599
+ try {
600
+ httpVersion = +httpVersion;
601
+ } catch (err) {
602
+ throw new AxiosError(
603
+ 'Invalid protocol version: value is not a number',
604
+ AxiosError.ERR_BAD_OPTION_VALUE,
605
+ config
606
+ );
607
+ }
550
608
 
551
609
  if (Number.isNaN(httpVersion)) {
552
- throw TypeError(`Invalid protocol version: '${config.httpVersion}' is not a number`);
610
+ throw new AxiosError(
611
+ `Invalid protocol version: '${rawHttpVersion}' is not a number`,
612
+ AxiosError.ERR_BAD_OPTION_VALUE,
613
+ config
614
+ );
553
615
  }
554
616
 
555
617
  if (httpVersion !== 1 && httpVersion !== 2) {
556
- throw TypeError(`Unsupported protocol version '${httpVersion}'`);
618
+ throw new AxiosError(
619
+ `Unsupported protocol version '${httpVersion}'`,
620
+ AxiosError.ERR_BAD_OPTION_VALUE,
621
+ config
622
+ );
557
623
  }
558
624
 
559
625
  const isHttp2 = httpVersion === 2;
560
626
 
561
627
  if (lookup) {
562
- const _lookup = callbackify(lookup, (value) => (utils.isArray(value) ? value : [value]));
563
- // hotfix to support opt.all option which is required for node 20.x
564
- lookup = (hostname, opt, cb) => {
565
- _lookup(hostname, opt, (err, arg0, arg1) => {
566
- if (err) {
567
- return cb(err);
568
- }
569
-
570
- const addresses = utils.isArray(arg0)
571
- ? arg0.map((addr) => buildAddressEntry(addr))
572
- : [buildAddressEntry(arg0, arg1)];
573
-
574
- opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
575
- });
576
- };
628
+ lookup = normalizeLookup(lookup);
577
629
  }
578
630
 
579
631
  const abortEmitter = new EventEmitter();
@@ -666,7 +718,9 @@ export default isHttpAdapterSupported &&
666
718
  // prototype cannot influence URL base selection.
667
719
  const urlBase = socketPath
668
720
  ? 'http://localhost'
669
- : (platform.hasBrowserEnv ? platform.origin : undefined);
721
+ : platform.hasBrowserEnv
722
+ ? platform.origin
723
+ : undefined;
670
724
  const parsed = new URL(fullPath, urlBase);
671
725
  const protocol = parsed.protocol || supportedProtocols[0];
672
726
 
@@ -675,7 +729,7 @@ export default isHttpAdapterSupported &&
675
729
  if (maxContentLength > -1) {
676
730
  // Use the exact string passed to fromDataURI (the configured url); fall back to fullPath if needed.
677
731
  const dataUrl = String(own('url') || fullPath || '');
678
- const estimated = estimateDataURLDecodedBytes(dataUrl);
732
+ const estimated = estimateDataURLBufferAllocation(dataUrl);
679
733
 
680
734
  if (estimated > maxContentLength) {
681
735
  return reject(
@@ -842,7 +896,7 @@ export default isHttpAdapterSupported &&
842
896
  data,
843
897
  progressEventDecorator(
844
898
  contentLength,
845
- progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
899
+ progressEventReducer(asyncDecorator(onUploadProgress, scheduleProgress), false, 3)
846
900
  )
847
901
  )
848
902
  );
@@ -877,7 +931,7 @@ export default isHttpAdapterSupported &&
877
931
  return reject(
878
932
  AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config, null, null, {
879
933
  url: own('url'),
880
- exists: true
934
+ exists: true,
881
935
  })
882
936
  );
883
937
  }
@@ -885,10 +939,16 @@ export default isHttpAdapterSupported &&
885
939
  headers.set(
886
940
  'Accept-Encoding',
887
941
  utils.hasOwnProp(transitional, 'advertiseZstdAcceptEncoding') &&
888
- transitional.advertiseZstdAcceptEncoding === true ? ACCEPT_ENCODING_WITH_ZSTD : ACCEPT_ENCODING,
942
+ transitional.advertiseZstdAcceptEncoding === true
943
+ ? ACCEPT_ENCODING_WITH_ZSTD
944
+ : ACCEPT_ENCODING,
889
945
  false
890
946
  );
891
947
 
948
+ if (isHttp2 && lookup) {
949
+ http2Options = Object.assign(Object.create(null), http2Options, { lookup });
950
+ }
951
+
892
952
  // Null-prototype to block prototype pollution gadgets on properties read
893
953
  // directly by Node's http.request (e.g. insecureHTTPParser, lookup).
894
954
  const options = Object.assign(Object.create(null), {
@@ -902,11 +962,14 @@ export default isHttpAdapterSupported &&
902
962
  beforeRedirect: dispatchBeforeRedirect,
903
963
  beforeRedirects: Object.create(null),
904
964
  http2Options,
965
+ createConnection: undefined,
905
966
  });
906
967
 
907
968
  // cacheable-lookup integration hotfix
908
969
  !utils.isUndefined(lookup) && (options.lookup = lookup);
909
970
 
971
+ let proxyApplied = false;
972
+
910
973
  if (socketPath) {
911
974
  if (typeof socketPath !== 'string') {
912
975
  return reject(
@@ -942,13 +1005,17 @@ export default isHttpAdapterSupported &&
942
1005
  ? parsed.hostname.slice(1, -1)
943
1006
  : parsed.hostname;
944
1007
  options.port = parsed.port;
945
- setProxy(
1008
+ proxyApplied = setProxy(
946
1009
  options,
947
1010
  configProxy,
948
1011
  protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path,
949
1012
  false,
950
1013
  httpsAgent,
951
- httpAgent
1014
+ httpAgent,
1015
+ // The HTTP/2 transport connects independently of HTTP/1 agents, so it
1016
+ // cannot apply either axios-resolved or agent-local environment proxies.
1017
+ // Explicit proxy config is still processed and rejected below.
1018
+ !isHttp2
952
1019
  );
953
1020
  }
954
1021
  let transport;
@@ -966,6 +1033,16 @@ export default isHttpAdapterSupported &&
966
1033
  }
967
1034
 
968
1035
  if (isHttp2) {
1036
+ if (proxyApplied) {
1037
+ return reject(
1038
+ new AxiosError(
1039
+ 'HTTP/2 requests with a proxy are not supported',
1040
+ AxiosError.ERR_NOT_SUPPORT,
1041
+ config
1042
+ )
1043
+ );
1044
+ }
1045
+
969
1046
  transport = http2Transport;
970
1047
  } else {
971
1048
  const configTransport = own('transport');
@@ -1080,7 +1157,11 @@ export default isHttpAdapterSupported &&
1080
1157
  transformStream,
1081
1158
  progressEventDecorator(
1082
1159
  responseLength,
1083
- progressEventReducer(asyncDecorator(onDownloadProgress), true, 3)
1160
+ progressEventReducer(
1161
+ asyncDecorator(onDownloadProgress, scheduleProgress),
1162
+ true,
1163
+ 3
1164
+ )
1084
1165
  )
1085
1166
  )
1086
1167
  );
@@ -1278,18 +1359,10 @@ export default isHttpAdapterSupported &&
1278
1359
  socket.setKeepAlive(true, 1000 * 60);
1279
1360
  }
1280
1361
 
1281
- // Install a single 'error' listener per socket (not per request) to avoid
1282
- // accumulating listeners on pooled keep-alive sockets that get reassigned
1283
- // to new requests before the previous request's 'close' fires (issue #10780).
1284
- // The listener is bound to the socket's currently-active request via a
1285
- // symbol, which is swapped as the socket is reassigned.
1362
+ // Install one shared 'error' listener per socket. The symbol follows the
1363
+ // currently-active request as pooled sockets are reassigned (issue #10780).
1286
1364
  if (!socket[kAxiosSocketListener]) {
1287
- socket.on('error', function handleSocketError(err) {
1288
- const current = socket[kAxiosCurrentReq];
1289
- if (current && !current.destroyed) {
1290
- current.destroy(err);
1291
- }
1292
- });
1365
+ socket.on('error', handleSocketError);
1293
1366
  socket[kAxiosSocketListener] = true;
1294
1367
  }
1295
1368
 
@@ -3,6 +3,7 @@ import settle from '../core/settle.js';
3
3
  import transitionalDefaults from '../defaults/transitional.js';
4
4
  import AxiosError from '../core/AxiosError.js';
5
5
  import CanceledError from '../cancel/CanceledError.js';
6
+ import normalizeURLForProtocolCheck from '../helpers/normalizeURLForProtocolCheck.js';
6
7
  import parseProtocol from '../helpers/parseProtocol.js';
7
8
  import platform from '../platform/index.js';
8
9
  import AxiosHeaders from '../core/AxiosHeaders.js';
@@ -21,7 +22,7 @@ export default isXHRAdapterSupported &&
21
22
  let { responseType, onUploadProgress, onDownloadProgress } = _config;
22
23
  let onCanceled;
23
24
  let uploadThrottled, downloadThrottled;
24
- let flushUpload, flushDownload;
25
+ let flushUpload, flushDownload, flushDownloadWithEvent;
25
26
 
26
27
  function done() {
27
28
  flushUpload && flushUpload(); // flush events
@@ -39,10 +40,55 @@ export default isXHRAdapterSupported &&
39
40
  // Set the request timeout in MS
40
41
  request.timeout = _config.timeout;
41
42
 
42
- function onloadend() {
43
+ function onloadend(event) {
43
44
  if (!request) {
44
45
  return;
45
46
  }
47
+
48
+ // Status 0 means no response was received, which onerror and onabort normally
49
+ // reject before this runs. Firefox 152 fires only readystatechange and loadend for
50
+ // navigation-canceled requests (https://bugzilla.mozilla.org/show_bug.cgi?id=1505389),
51
+ // leaving settle() to resolve them as an empty success. ECONNABORTED is the error
52
+ // onabort raised on Firefox 151. Reads over file:, which some environments report as
53
+ // status 0 on success, are excluded by the request URL's scheme after browser-style
54
+ // preprocessing, by the page origin's scheme for relative URLs (which inherit it), or
55
+ // by responseURL where implemented.
56
+ if (
57
+ request.status === 0 &&
58
+ (parseProtocol(normalizeURLForProtocolCheck(_config.url)) ||
59
+ parseProtocol(platform.origin)) !== 'file' &&
60
+ !(request.responseURL && request.responseURL.startsWith('file:'))
61
+ ) {
62
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
63
+ done();
64
+
65
+ // Clean up request
66
+ request = null;
67
+ return;
68
+ }
69
+
70
+ // When loadend is still dispatching, flushing with it gives progress
71
+ // listeners a final delivery whose event has a live target. The legacy
72
+ // ready-state fallback has no event, so replay its pending progress.
73
+ // A throwing listener must not block settlement; rethrow asynchronously,
74
+ // matching how listener errors surface on the throttle timer path.
75
+ try {
76
+ if (event) {
77
+ flushDownloadWithEvent && flushDownloadWithEvent(event);
78
+ } else {
79
+ flushDownload && flushDownload();
80
+ }
81
+ } catch (err) {
82
+ setTimeout(() => {
83
+ throw err;
84
+ });
85
+ }
86
+
87
+ // A final progress callback can cancel the request synchronously.
88
+ if (!request) {
89
+ return;
90
+ }
91
+
46
92
  // Prepare the response
47
93
  const responseHeaders = AxiosHeaders.from(
48
94
  'getAllResponseHeaders' in request && request.getAllResponseHeaders()
@@ -174,7 +220,10 @@ export default isXHRAdapterSupported &&
174
220
 
175
221
  // Handle progress if needed
176
222
  if (onDownloadProgress) {
177
- [downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
223
+ [downloadThrottled, flushDownload, flushDownloadWithEvent] = progressEventReducer(
224
+ onDownloadProgress,
225
+ true
226
+ );
178
227
  request.addEventListener('progress', downloadThrottled);
179
228
  }
180
229