@songtonyli/dsh-cli 0.1.36 → 0.1.37

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 (63) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +1 -1
  4. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  5. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +2 -2
  6. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +1 -1
  7. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +1 -1
  8. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +85 -33
  9. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +22 -37
  10. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +26 -4
  11. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +49 -8
  12. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +12 -7
  13. package/node_modules/@smithy/core/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +22 -22
  14. package/node_modules/@smithy/core/dist-es/submodules/cbor/parseCborBody.js +0 -15
  15. package/node_modules/@smithy/core/dist-es/submodules/client/index.js +1 -1
  16. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/command.js +8 -1
  17. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/exceptions.js +18 -3
  18. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +49 -8
  19. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +12 -7
  20. package/node_modules/@smithy/core/package.json +2 -2
  21. package/node_modules/@smithy/types/package.json +1 -1
  22. package/node_modules/undici/docs/docs/api/Agent.md +8 -8
  23. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +9 -6
  24. package/node_modules/undici/docs/docs/api/Errors.md +25 -0
  25. package/node_modules/undici/docs/docs/api/Interceptors.md +4 -3
  26. package/node_modules/undici/docs/docs/api/Pool.md +5 -6
  27. package/node_modules/undici/lib/api/readable.js +1 -2
  28. package/node_modules/undici/lib/core/request.js +23 -2
  29. package/node_modules/undici/lib/core/util.js +0 -39
  30. package/node_modules/undici/lib/dispatcher/client-h1.js +11 -4
  31. package/node_modules/undici/lib/dispatcher/client-h2.js +52 -8
  32. package/node_modules/undici/lib/dispatcher/client.js +1 -1
  33. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +3 -2
  34. package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +21 -6
  35. package/node_modules/undici/lib/dispatcher/pool-base.js +63 -2
  36. package/node_modules/undici/lib/dispatcher/pool.js +90 -7
  37. package/node_modules/undici/lib/dispatcher/proxy-agent.js +16 -3
  38. package/node_modules/undici/lib/handler/deduplication-handler.js +24 -11
  39. package/node_modules/undici/lib/handler/redirect-handler.js +5 -0
  40. package/node_modules/undici/lib/handler/retry-handler.js +72 -13
  41. package/node_modules/undici/lib/interceptor/cache.js +4 -1
  42. package/node_modules/undici/lib/interceptor/decompress.js +236 -69
  43. package/node_modules/undici/lib/web/cache/cache.js +17 -8
  44. package/node_modules/undici/lib/web/cache/cachestorage.js +11 -5
  45. package/node_modules/undici/lib/web/cookies/index.js +19 -7
  46. package/node_modules/undici/lib/web/cookies/util.js +3 -1
  47. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -1
  48. package/node_modules/undici/lib/web/fetch/body.js +22 -15
  49. package/node_modules/undici/lib/web/fetch/data-url.js +6 -6
  50. package/node_modules/undici/lib/web/fetch/formdata.js +30 -36
  51. package/node_modules/undici/lib/web/fetch/headers.js +34 -31
  52. package/node_modules/undici/lib/web/fetch/index.js +38 -14
  53. package/node_modules/undici/lib/web/fetch/request.js +74 -79
  54. package/node_modules/undici/lib/web/fetch/response.js +43 -44
  55. package/node_modules/undici/lib/web/fetch/util.js +7 -7
  56. package/node_modules/undici/lib/web/infra/index.js +16 -1
  57. package/node_modules/undici/lib/web/webidl/index.js +2 -14
  58. package/node_modules/undici/lib/web/websocket/events.js +43 -26
  59. package/node_modules/undici/lib/web/websocket/receiver.js +5 -0
  60. package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +13 -10
  61. package/node_modules/undici/lib/web/websocket/websocket.js +44 -41
  62. package/node_modules/undici/package.json +1 -1
  63. package/package.json +4 -4
@@ -50,37 +50,37 @@ export class SmithyRpcV2CborProtocol extends RpcProtocol {
50
50
  return super.deserializeResponse(operationSchema, context, response);
51
51
  }
52
52
  async handleError(operationSchema, context, response, dataObject, metadata) {
53
- const errorName = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
53
+ const errorIdentifier = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
54
+ const preferredNamespaces = ["*"];
55
+ const { defaultNamespace } = this.options;
56
+ preferredNamespaces.unshift(defaultNamespace);
57
+ const [namespace, errorShapeName] = (() => {
58
+ if (errorIdentifier.includes("#")) {
59
+ return errorIdentifier.split("#");
60
+ }
61
+ return [undefined, errorIdentifier];
62
+ })();
63
+ if (namespace) {
64
+ preferredNamespaces.unshift(namespace);
65
+ }
54
66
  const errorMetadata = {
55
67
  $metadata: metadata,
56
- $fault: response.statusCode <= 500 ? "client" : "server",
68
+ $fault: response.statusCode < 500 ? "client" : "server",
57
69
  };
58
- let namespace = this.options.defaultNamespace;
59
- if (errorName.includes("#")) {
60
- [namespace] = errorName.split("#");
70
+ const preferredRegistries = [this.compositeErrorRegistry];
71
+ if (namespace) {
72
+ preferredRegistries.push(TypeRegistry.for(namespace));
61
73
  }
62
- const registry = this.compositeErrorRegistry;
63
- const nsRegistry = TypeRegistry.for(namespace);
64
- registry.copyFrom(nsRegistry);
65
- let errorSchema;
66
- try {
67
- errorSchema = registry.getSchema(errorName);
68
- }
69
- catch (ignored) {
74
+ preferredRegistries.push(TypeRegistry.for(defaultNamespace));
75
+ const [errorSchema, ErrorCtor, errorMode] = this.resolveError(errorShapeName, preferredNamespaces, preferredRegistries);
76
+ if (errorMode === "native" || errorMode === "synthetic") {
70
77
  if (dataObject.Message) {
71
78
  dataObject.message = dataObject.Message;
72
79
  }
73
- const syntheticRegistry = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace);
74
- registry.copyFrom(syntheticRegistry);
75
- const baseExceptionSchema = registry.getBaseException();
76
- if (baseExceptionSchema) {
77
- const ErrorCtor = registry.getErrorCtor(baseExceptionSchema);
78
- throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
79
- }
80
- throw Object.assign(new Error(errorName), errorMetadata, dataObject);
80
+ const error = errorMode === "synthetic" ? new ErrorCtor({ name: errorShapeName }) : new Error(errorShapeName);
81
+ throw Object.assign(error, errorMetadata, dataObject);
81
82
  }
82
83
  const ns = NormalizedSchema.of(errorSchema);
83
- const ErrorCtor = registry.getErrorCtor(errorSchema);
84
84
  const message = dataObject.message ?? dataObject.Message ?? "Unknown";
85
85
  const exception = new ErrorCtor({});
86
86
  const output = {};
@@ -42,26 +42,11 @@ export const loadSmithyRpcV2CborErrorCode = (output, data) => {
42
42
  if (cleanValue.indexOf(":") >= 0) {
43
43
  cleanValue = cleanValue.split(":")[0];
44
44
  }
45
- if (cleanValue.indexOf("#") >= 0) {
46
- cleanValue = cleanValue.split("#")[1];
47
- }
48
45
  return cleanValue;
49
46
  };
50
47
  if (data["__type"] !== undefined) {
51
48
  return sanitizeErrorCode(data["__type"]);
52
49
  }
53
- let codeKey;
54
- for (const key in data) {
55
- if (!hasOwn(data, key))
56
- continue;
57
- if (key.toLowerCase() === "code") {
58
- codeKey = key;
59
- break;
60
- }
61
- }
62
- if (codeKey && data[codeKey] !== undefined) {
63
- return sanitizeErrorCode(data[codeKey]);
64
- }
65
50
  };
66
51
  export const checkCborResponse = (response) => {
67
52
  if (String(response.headers["smithy-protocol"]).toLowerCase() !== "rpc-v2-cbor") {
@@ -5,7 +5,7 @@ export { invalidFunction } from "./invalid-dependency/invalidFunction";
5
5
  export { invalidProvider } from "./invalid-dependency/invalidProvider";
6
6
  export { createWaiter } from "./util-waiter/createWaiter";
7
7
  export { waiterServiceDefaults, WaiterState, checkExceptions, } from "./util-waiter/waiter";
8
- export { Client } from "./smithy-client/client";
8
+ export { Client, } from "./smithy-client/client";
9
9
  export { Command } from "./smithy-client/command";
10
10
  export { SENSITIVE_STRING } from "./smithy-client/constants";
11
11
  export { createAggregatedClient } from "./smithy-client/create-aggregated-client";
@@ -13,20 +13,27 @@ export class Command {
13
13
  }
14
14
  const stack = clientStack.concat(this.middlewareStack);
15
15
  const { logger } = configuration;
16
+ const additionalSmithyContext = additionalContext[SMITHY_CONTEXT_KEY];
16
17
  const handlerExecutionContext = {
17
18
  logger,
18
19
  clientName,
19
20
  commandName,
20
21
  inputFilterSensitiveLog,
21
22
  outputFilterSensitiveLog,
23
+ ...additionalContext,
22
24
  [SMITHY_CONTEXT_KEY]: {
25
+ ...additionalSmithyContext,
23
26
  commandInstance: this,
24
27
  ...smithyContext,
28
+ ...(options?.metricsRecorder === undefined ? {} : { metricsRecorder: options.metricsRecorder }),
25
29
  },
26
- ...additionalContext,
27
30
  };
28
31
  const { requestHandler } = configuration;
29
32
  let requestOptions = options ?? {};
33
+ if (requestOptions.metricsRecorder) {
34
+ requestOptions = { ...requestOptions };
35
+ delete requestOptions.metricsRecorder;
36
+ }
30
37
  if (smithyContext.eventStream) {
31
38
  requestOptions = {
32
39
  isEventStream: true,
@@ -27,10 +27,25 @@ export class ServiceException extends Error {
27
27
  return ServiceException.isInstance(instance);
28
28
  }
29
29
  if (ServiceException.isInstance(instance)) {
30
- if (candidate.name && this.name) {
31
- return this.prototype.isPrototypeOf(instance) || candidate.name === this.name;
30
+ if (this.prototype.isPrototypeOf(instance)) {
31
+ return true;
32
32
  }
33
- return this.prototype.isPrototypeOf(instance);
33
+ const targetName = this.name;
34
+ if (!targetName || !candidate.name) {
35
+ return false;
36
+ }
37
+ if (candidate.name === targetName) {
38
+ return true;
39
+ }
40
+ let proto = Object.getPrototypeOf(candidate);
41
+ while (proto && proto !== Object.prototype) {
42
+ const ctorName = proto.constructor?.name;
43
+ if (ctorName && ctorName !== "Error" && ctorName === targetName) {
44
+ return true;
45
+ }
46
+ proto = Object.getPrototypeOf(proto);
47
+ }
48
+ return false;
34
49
  }
35
50
  return false;
36
51
  }
@@ -8,7 +8,7 @@ export class HttpProtocol extends SerdeContext {
8
8
  constructor(options) {
9
9
  super();
10
10
  this.options = options;
11
- this.compositeErrorRegistry = TypeRegistry.for(options.defaultNamespace);
11
+ this.compositeErrorRegistry = new TypeRegistry(options.defaultNamespace);
12
12
  for (const etr of options.errorTypeRegistries ?? []) {
13
13
  this.compositeErrorRegistry.copyFrom(etr);
14
14
  }
@@ -103,6 +103,47 @@ export class HttpProtocol extends SerdeContext {
103
103
  cfId: output.headers["x-amz-cf-id"],
104
104
  };
105
105
  }
106
+ resolveError(name, namespaces, registries) {
107
+ const defaultErrorSchema = [-3, "", "Error", 0, [], [], 0];
108
+ let schema;
109
+ for (const registry of registries) {
110
+ for (const ns of namespaces) {
111
+ try {
112
+ if (ns === "*") {
113
+ schema = registry.getSchema(name);
114
+ }
115
+ else {
116
+ schema = registry.getSchema(ns + "#" + name);
117
+ }
118
+ const errorCtor = registry.getErrorCtor(schema);
119
+ if (errorCtor) {
120
+ return [schema, errorCtor, "modeled"];
121
+ }
122
+ else {
123
+ const syntheticErrorSchema = registry.getBaseException();
124
+ if (syntheticErrorSchema) {
125
+ const syntheticErrorCtor = registry.getErrorCtor(syntheticErrorSchema);
126
+ if (syntheticErrorCtor) {
127
+ return [schema, syntheticErrorCtor, "synthetic"];
128
+ }
129
+ }
130
+ }
131
+ }
132
+ catch (ignored) {
133
+ }
134
+ }
135
+ }
136
+ for (const registry of registries) {
137
+ const syntheticErrorSchema = registry.getBaseException();
138
+ if (syntheticErrorSchema) {
139
+ const syntheticErrorCtor = registry.getErrorCtor(syntheticErrorSchema);
140
+ if (syntheticErrorCtor) {
141
+ return [syntheticErrorSchema, syntheticErrorCtor, "synthetic"];
142
+ }
143
+ }
144
+ }
145
+ return [defaultErrorSchema, Error, "native"];
146
+ }
106
147
  async serializeEventStream({ eventStream, requestSchema, initialRequest, }) {
107
148
  const eventStreamSerde = await this.loadEventStreamCapability();
108
149
  return eventStreamSerde.serializeEventStream({
@@ -131,13 +172,6 @@ export class HttpProtocol extends SerdeContext {
131
172
  compositeErrorRegistry: this.compositeErrorRegistry,
132
173
  });
133
174
  }
134
- resolveEventStreamMarshaller(importedProvider) {
135
- const context = this.serdeContext;
136
- if (context.eventStreamMarshaller) {
137
- return context.eventStreamMarshaller;
138
- }
139
- return importedProvider(this.serdeContext);
140
- }
141
175
  getDefaultContentType() {
142
176
  throw new Error(`@smithy/core/protocols - ${this.constructor.name} getDefaultContentType() implementation missing.`);
143
177
  }
@@ -156,4 +190,11 @@ export class HttpProtocol extends SerdeContext {
156
190
  }
157
191
  return context.eventStreamMarshaller;
158
192
  }
193
+ resolveEventStreamMarshaller(importedProvider) {
194
+ const context = this.serdeContext;
195
+ if (context.eventStreamMarshaller) {
196
+ return context.eventStreamMarshaller;
197
+ }
198
+ return importedProvider(this.serdeContext);
199
+ }
159
200
  }
@@ -7,12 +7,12 @@ export class TypeRegistry {
7
7
  this.namespace = namespace;
8
8
  this.schemas = schemas;
9
9
  this.exceptions = exceptions;
10
- }
11
- static for(namespace) {
12
10
  if (!TypeRegistry.registries.has(namespace)) {
13
- TypeRegistry.registries.set(namespace, new TypeRegistry(namespace));
11
+ TypeRegistry.registries.set(namespace, this);
14
12
  }
15
- return TypeRegistry.registries.get(namespace);
13
+ }
14
+ static for(namespace) {
15
+ return TypeRegistry.registries.get(namespace) ?? new TypeRegistry(namespace);
16
16
  }
17
17
  copyFrom(other) {
18
18
  const { schemas, exceptions } = this;
@@ -30,7 +30,9 @@ export class TypeRegistry {
30
30
  register(shapeId, schema) {
31
31
  const qualifiedName = this.normalizeShapeId(shapeId);
32
32
  for (const r of [this, TypeRegistry.for(qualifiedName.split("#")[0])]) {
33
- r.schemas.set(qualifiedName, schema);
33
+ if (!r.schemas.has(qualifiedName)) {
34
+ r.schemas.set(qualifiedName, schema);
35
+ }
34
36
  }
35
37
  }
36
38
  getSchema(shapeId) {
@@ -55,9 +57,12 @@ export class TypeRegistry {
55
57
  registerError(es, ctor) {
56
58
  const $error = es;
57
59
  const ns = $error[1];
60
+ const qualifiedName = ns + "#" + $error[2];
58
61
  for (const r of [this, TypeRegistry.for(ns)]) {
59
- r.schemas.set(ns + "#" + $error[2], $error);
60
- r.exceptions.set($error, ctor);
62
+ if (!r.schemas.has(qualifiedName) && !r.exceptions.has($error)) {
63
+ r.schemas.set(qualifiedName, $error);
64
+ r.exceptions.set($error, ctor);
65
+ }
61
66
  }
62
67
  }
63
68
  getErrorCtor(es) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.34.1",
3
+ "version": "3.35.0",
4
4
  "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/core",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -224,7 +224,7 @@
224
224
  }
225
225
  },
226
226
  "dependencies": {
227
- "@smithy/types": "^4.18.0",
227
+ "@smithy/types": "^4.19.0",
228
228
  "tslib": "^2.6.2"
229
229
  },
230
230
  "devDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/types",
3
- "version": "4.18.0",
3
+ "version": "4.19.0",
4
4
  "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/types",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -56,16 +56,16 @@ changes:
56
56
  `Infinity`, no limit is enforced. Must be a number greater than `0`.
57
57
  **Default:** `Infinity`.
58
58
 
59
- `Agent` inherits all {PoolOptions} (and therefore all {ClientOptions}). The
60
- per-origin {Pool} it creates uses the default unlimited `connections`, so
61
- concurrent requests to the same origin are spread across separate {Client}
62
- instances on separate sockets.
59
+ `Agent` inherits all {PoolOptions} (and therefore all {ClientOptions}). Each
60
+ origin gets a separate {Pool}, with `connections` acting as the maximum number
61
+ of clients that pool may create.
63
62
 
64
63
  > [!NOTE]
65
- > Because each concurrent request to an origin may use a different {Client},
66
- > HTTP/2 multiplexing on a shared session does not apply unless `connections` is
67
- > set to a small value (for example `connections: 1`). See {PoolOptions} and
68
- > {ClientOptions} for the full set of inherited options such as `allowH2`
64
+ > For an h2-capable HTTPS origin, the per-origin pool waits for the first TLS
65
+ > connection to finish ALPN negotiation. If the server selects h2, concurrent
66
+ > requests share that session up to `maxConcurrentStreams`. If it selects
67
+ > HTTP/1.1, normal connection fan-out resumes up to `connections`. See
68
+ > {PoolOptions} and {ClientOptions} for inherited options such as `allowH2`
69
69
  > (default `true`) and `maxConcurrentStreams` (default `100`).
70
70
 
71
71
  ### `agent.closed`
@@ -120,7 +120,8 @@ diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) =>
120
120
  added: v6.3.0
121
121
  -->
122
122
 
123
- Published after the response headers have been received.
123
+ Published after the response headers have been received. This includes a
124
+ successful CONNECT or protocol upgrade response.
124
125
 
125
126
  * `message` {Object}
126
127
  * `request` {Object} The same object published by
@@ -128,8 +129,9 @@ Published after the response headers have been received.
128
129
  * `response` {Object} The response being received.
129
130
  * `statusCode` {number} The HTTP status code.
130
131
  * `statusText` {string} The HTTP status message.
131
- * `headers` {Buffer[]} The raw response headers as an array of buffers,
132
- alternating between header name and value.
132
+ * `headers` {Buffer[]|Object} HTTP/1.1 response headers are an array of
133
+ buffers alternating between header name and value. HTTP/2 response
134
+ headers are an object.
133
135
 
134
136
  ```mjs
135
137
  import diagnosticsChannel from 'node:diagnostics_channel'
@@ -137,7 +139,7 @@ import diagnosticsChannel from 'node:diagnostics_channel'
137
139
  diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
138
140
  console.log('statusCode', response.statusCode)
139
141
  console.log(response.statusText)
140
- console.log(response.headers.map((x) => x.toString()))
142
+ console.log(response.headers)
141
143
  })
142
144
  ```
143
145
 
@@ -168,8 +170,9 @@ diagnosticsChannel.channel('undici:request:bodyChunkReceived').subscribe(({ requ
168
170
  added: v6.3.0
169
171
  -->
170
172
 
171
- Published after the response body and trailers have been received, that is, once
172
- the response has fully completed.
173
+ Published once the response has fully completed. After an upgraded socket has
174
+ been passed to the request handler, this event is published with an empty
175
+ `trailers` array.
173
176
 
174
177
  * `message` {Object}
175
178
  * `request` {Object} The same object published by
@@ -446,6 +446,31 @@ The response returned an error status code. This is raised, for example, when th
446
446
  * `headers` {Object|string[]|null} The response headers. (optional)
447
447
  * `body` {Object|string|null} The response body. (optional)
448
448
 
449
+ ## Class: `ProxyConnectionError`
450
+
451
+ <!-- YAML
452
+ added: v8.10.1
453
+ changes:
454
+ - version: v8.10.1
455
+ pr-url: https://github.com/nodejs/undici/pull/5707
456
+ description: Added to fail the request instead of retrying forever when the proxy connection is torn down.
457
+ -->
458
+
459
+ * Extends: {UndiciError}
460
+
461
+ A connection to the proxy failed in a way that cannot be recovered on the
462
+ same connection, so the request fails instead of being retried.
463
+
464
+ * `name` {string} Always `'ProxyConnectionError'`.
465
+ * `code` {string} Always `'UND_ERR_PRX_CONN'`.
466
+ * `cause` {Error} The underlying error that caused the proxy connection to fail.
467
+
468
+ ### `new ProxyConnectionError(cause[, message[, options]])`
469
+
470
+ * `cause` {Error} The underlying error. (optional)
471
+ * `message` {string} The error message. (optional)
472
+ * `options` {Object} Additional `Error` options merged with `cause`. (optional)
473
+
449
474
  ## Class: `SecureProxyConnectionError`
450
475
 
451
476
  <!-- YAML
@@ -210,9 +210,10 @@ Automatically decompresses response bodies encoded with `gzip`, `x-gzip`,
210
210
  skipped. **Default:** `[204, 304]`.
211
211
  * `skipErrorResponses` {boolean} When `true`, responses with a status code
212
212
  >= 400 are not decompressed. **Default:** `true`.
213
- * `maxSize` {number} Maximum decompressed response size in bytes. The request
214
- fails with a `ResponseExceededMaxSizeError` if the decoded body exceeds
215
- this limit. **Default:** `67108864` (64 MiB).
213
+ * `maxSize` {number} Maximum decompressed response size in bytes for each
214
+ decompression stage. The request fails with a
215
+ `ResponseExceededMaxSizeError` if a stage exceeds this limit. Set to `0` to
216
+ disable the limit. **Default:** `0`.
216
217
 
217
218
  **Returns:** {Dispatcher.DispatcherComposeInterceptor}
218
219
 
@@ -73,12 +73,11 @@ connector shared by every pooled client.
73
73
 
74
74
  > [!NOTE]
75
75
  > `Pool` inherits all {ClientOptions}, including `allowH2` and
76
- > `maxConcurrentStreams`. With the default unlimited `connections`, the pool
77
- > opens a new client - and therefore a new TCP/TLS socket - per concurrent
78
- > dispatch, which defeats HTTP/2 multiplexing over a shared session. To benefit
79
- > from h2 multiplexing on a single session, cap `connections` (for example
80
- > `connections: 1`) so that concurrent requests share a session up to
81
- > `maxConcurrentStreams`.
76
+ > `maxConcurrentStreams`. For an h2-capable HTTPS origin, the pool waits for
77
+ > the first TLS connection to finish ALPN negotiation before opening more
78
+ > clients. If the server selects h2, concurrent requests share that session up
79
+ > to `maxConcurrentStreams`. If it selects HTTP/1.1, the pool resumes normal
80
+ > connection fan-out up to `connections`.
82
81
 
83
82
  ```mjs
84
83
  import { Pool } from 'undici'
@@ -5,7 +5,6 @@ const { addAbortListener } = require('node:events')
5
5
  const { Readable } = require('node:stream')
6
6
  const { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require('../core/errors')
7
7
  const util = require('../core/util')
8
- const { ReadableStreamFrom } = require('../core/util')
9
8
 
10
9
  const kConsume = Symbol('kConsume')
11
10
  const kReading = Symbol('kReading')
@@ -246,7 +245,7 @@ class BodyReadable extends Readable {
246
245
  */
247
246
  get body () {
248
247
  if (!this[kBody]) {
249
- this[kBody] = ReadableStreamFrom(this)
248
+ this[kBody] = ReadableStream.from(this)
250
249
  if (this[kConsume]) {
251
250
  // TODO: Is this the best way to force a lock?
252
251
  this[kBody].getReader() // Ensure stream is locked.
@@ -368,10 +368,22 @@ class Request {
368
368
  }
369
369
  }
370
370
 
371
- onRequestUpgrade (statusCode, headers, socket) {
371
+ /**
372
+ * @param {number} statusCode
373
+ * @param {Buffer[]|string[]|import('../../types/header.d.ts').IncomingHttpHeaders} headers
374
+ * @param {import('node:stream').Duplex} socket
375
+ * @param {string} [statusText]
376
+ */
377
+ onRequestUpgrade (statusCode, headers, socket, statusText = '') {
378
+ this.onFinally()
379
+
372
380
  assert(!this.aborted)
373
381
  assert(!this.completed)
374
382
 
383
+ if (channels.headers.hasSubscribers) {
384
+ channels.headers.publish({ request: this, response: { statusCode, headers, statusText } })
385
+ }
386
+
375
387
  const controller = this[kController]
376
388
  if (controller) {
377
389
  controller.rawHeaders = headers
@@ -379,7 +391,16 @@ class Request {
379
391
 
380
392
  const parsedHeaders = Array.isArray(headers) ? parseHeaders(headers) : headers
381
393
 
382
- return this[kHandler].onRequestUpgrade?.(controller, statusCode, parsedHeaders, socket)
394
+ const result = this[kHandler].onRequestUpgrade?.(controller, statusCode, parsedHeaders, socket)
395
+
396
+ if (!this.aborted) {
397
+ this.completed = true
398
+ if (channels.trailers.hasSubscribers) {
399
+ channels.trailers.publish({ request: this, trailers: [] })
400
+ }
401
+ }
402
+
403
+ return result
383
404
  }
384
405
 
385
406
  onResponseEnd (trailers) {
@@ -644,44 +644,6 @@ function getSocketInfo (socket) {
644
644
  }
645
645
  }
646
646
 
647
- /**
648
- * @param {Iterable} iterable
649
- * @returns {ReadableStream}
650
- */
651
- function ReadableStreamFrom (iterable) {
652
- // We cannot use ReadableStream.from here because it does not return a byte stream.
653
-
654
- let iterator
655
- return new ReadableStream(
656
- {
657
- start () {
658
- iterator = iterable[Symbol.asyncIterator]()
659
- },
660
- pull (controller) {
661
- return iterator.next().then(({ done, value }) => {
662
- if (done) {
663
- return queueMicrotask(() => {
664
- controller.close()
665
- controller.byobRequest?.respond(0)
666
- })
667
- } else {
668
- const buf = Buffer.isBuffer(value) ? value : Buffer.from(value)
669
- if (buf.byteLength) {
670
- return controller.enqueue(new Uint8Array(buf))
671
- } else {
672
- return this.pull(controller)
673
- }
674
- }
675
- })
676
- },
677
- cancel () {
678
- return iterator.return()
679
- },
680
- type: 'bytes'
681
- }
682
- )
683
- }
684
-
685
647
  /**
686
648
  * The object should be a FormData instance and contains all the required
687
649
  * methods.
@@ -1026,7 +988,6 @@ module.exports = {
1026
988
  destroy,
1027
989
  bodyLength,
1028
990
  deepClone,
1029
- ReadableStreamFrom,
1030
991
  isBuffer,
1031
992
  assertRequestHandler,
1032
993
  getSocketInfo,
@@ -70,8 +70,14 @@ function lazyllhttp () {
70
70
 
71
71
  let mod
72
72
 
73
- // We disable wasm SIMD on ppc64 as it seems to be broken on Power 9 architectures.
74
- let useWasmSIMD = process.arch !== 'ppc64'
73
+ // We disable wasm SIMD on older versions of Node.js on ppc64 that are broken on Power >=9 architectures.
74
+ let useWasmSIMD = true
75
+ if (process.arch === 'ppc64') {
76
+ const [major, minor] = process.versions.node.split('.').map(n => parseInt(n, 10))
77
+ if (major < 24 || (major === 24 && minor < 12)) {
78
+ useWasmSIMD = false
79
+ }
80
+ }
75
81
  // The Env Variable UNDICI_NO_WASM_SIMD allows explicitly overriding the default behavior
76
82
  if (process.env.UNDICI_NO_WASM_SIMD === '1') {
77
83
  useWasmSIMD = false
@@ -561,7 +567,7 @@ class Parser {
561
567
  * @param {Buffer} head
562
568
  */
563
569
  onUpgrade (head) {
564
- const { upgrade, client, socket, headers, statusCode } = this
570
+ const { upgrade, client, socket, headers, statusCode, statusText } = this
565
571
 
566
572
  assert(upgrade)
567
573
  assert(client[kSocket] === socket)
@@ -596,8 +602,9 @@ class Parser {
596
602
  client.emit('disconnect', client[kUrl], [client], new InformationalError('upgrade'))
597
603
 
598
604
  try {
599
- request.onRequestUpgrade(statusCode, headers, socket)
605
+ request.onRequestUpgrade(statusCode, headers, socket, statusText)
600
606
  } catch (err) {
607
+ util.errorRequest(client, request, err)
601
608
  util.destroy(socket, err)
602
609
  }
603
610