pi-dent-agent 0.2.9 → 0.2.10

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 (39) hide show
  1. package/lib/plugin-state.ts +484 -0
  2. package/lib/plugin-ui.ts +2 -0
  3. package/lib/script-runner.ts +8 -0
  4. package/lib/script-tool.ts +3 -0
  5. package/lib/script-worker.ts +78 -7
  6. package/node_modules/pi-web-access/node_modules/undici/docs/docs/api/CacheStore.md +11 -0
  7. package/node_modules/pi-web-access/node_modules/undici/docs/docs/api/Client.md +1 -1
  8. package/node_modules/pi-web-access/node_modules/undici/docs/docs/api/Connector.md +9 -2
  9. package/node_modules/pi-web-access/node_modules/undici/docs/docs/api/Dispatcher.md +20 -0
  10. package/node_modules/pi-web-access/node_modules/undici/docs/docs/api/Interceptors.md +13 -3
  11. package/node_modules/pi-web-access/node_modules/undici/docs/docs/best-practices/mocking-request.md +1 -1
  12. package/node_modules/pi-web-access/node_modules/undici/lib/api/abort-signal.js +55 -5
  13. package/node_modules/pi-web-access/node_modules/undici/lib/api/api-connect.js +6 -2
  14. package/node_modules/pi-web-access/node_modules/undici/lib/api/api-pipeline.js +7 -2
  15. package/node_modules/pi-web-access/node_modules/undici/lib/api/api-request.js +12 -4
  16. package/node_modules/pi-web-access/node_modules/undici/lib/api/api-stream.js +6 -2
  17. package/node_modules/pi-web-access/node_modules/undici/lib/api/api-upgrade.js +6 -2
  18. package/node_modules/pi-web-access/node_modules/undici/lib/core/request.js +17 -0
  19. package/node_modules/pi-web-access/node_modules/undici/lib/core/symbols.js +3 -1
  20. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/client-h1.js +24 -0
  21. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/client-h2.js +11 -5
  22. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/client.js +109 -2
  23. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/dispatcher-base.js +6 -1
  24. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/dispatcher.js +22 -1
  25. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/pool-base.js +72 -16
  26. package/node_modules/pi-web-access/node_modules/undici/lib/dispatcher/pool.js +22 -9
  27. package/node_modules/pi-web-access/node_modules/undici/lib/handler/cache-handler.js +1 -1
  28. package/node_modules/pi-web-access/node_modules/undici/lib/handler/retry-handler.js +27 -1
  29. package/node_modules/pi-web-access/node_modules/undici/lib/interceptor/cache.js +9 -2
  30. package/node_modules/pi-web-access/node_modules/undici/lib/interceptor/decompress.js +0 -11
  31. package/node_modules/pi-web-access/node_modules/undici/lib/interceptor/deduplicate.js +4 -1
  32. package/node_modules/pi-web-access/node_modules/undici/lib/interceptor/redirect.js +4 -1
  33. package/node_modules/pi-web-access/node_modules/undici/lib/util/cache.js +1 -1
  34. package/node_modules/pi-web-access/node_modules/undici/lib/util/timers.js +1 -1
  35. package/node_modules/pi-web-access/node_modules/undici/lib/web/fetch/index.js +20 -1
  36. package/node_modules/pi-web-access/node_modules/undici/lib/web/fetch/util.js +2 -2
  37. package/node_modules/pi-web-access/node_modules/undici/package.json +3 -3
  38. package/node_modules/pi-web-access/node_modules/undici/types/retry-handler.d.ts +1 -1
  39. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
  const EventEmitter = require('node:events')
3
- const { kOriginless, kUrl } = require('../core/symbols')
3
+ const { InvalidArgumentError } = require('../core/errors')
4
+ const { kOriginless, kUrl, kInterceptorKind } = require('../core/symbols')
4
5
 
5
6
  class Dispatcher extends EventEmitter {
6
7
  dispatch () {
@@ -24,6 +25,8 @@ class Dispatcher extends EventEmitter {
24
25
  : this[kUrl]?.origin
25
26
  let dispatch = this.dispatch.bind(this)
26
27
 
28
+ const orderSensitiveKinds = []
29
+
27
30
  for (const interceptor of interceptors) {
28
31
  if (interceptor == null) {
29
32
  continue
@@ -33,6 +36,10 @@ class Dispatcher extends EventEmitter {
33
36
  throw new TypeError(`invalid interceptor, expected function received ${typeof interceptor}`)
34
37
  }
35
38
 
39
+ if (interceptor[kInterceptorKind] != null) {
40
+ orderSensitiveKinds.push(interceptor[kInterceptorKind])
41
+ }
42
+
36
43
  dispatch = interceptor(dispatch, interceptorOrigin)
37
44
 
38
45
  if (dispatch == null || typeof dispatch !== 'function' || dispatch.length !== 2) {
@@ -40,6 +47,20 @@ class Dispatcher extends EventEmitter {
40
47
  }
41
48
  }
42
49
 
50
+ // Several shipped interceptors are order-sensitive: they cooperate through
51
+ // the redirect history threaded on the request context, and the cache
52
+ // handler only receives it when the redirect interceptor is composed before
53
+ // the cache interceptor. Composing `cache` before `redirect` silently
54
+ // disables the cache's redirect-origin guards (cross-origin cache
55
+ // poisoning, credential-bearing redirect replay), so fail fast instead of
56
+ // storing an attacker-controlled or cross-principal response under a key
57
+ // the application trusts.
58
+ const cacheIndex = orderSensitiveKinds.indexOf('cache')
59
+ const redirectIndex = orderSensitiveKinds.indexOf('redirect')
60
+ if (cacheIndex !== -1 && redirectIndex !== -1 && cacheIndex < redirectIndex) {
61
+ throw new InvalidArgumentError('the cache interceptor must be composed after the redirect interceptor; composing the cache before the redirect disables the cache\'s cross-origin and credential redirect guards (GHSA-75VM-9G8F-99J4, GHSA-MQG3-3V4R-CM32, GHSA-4W7W-5XRC-9H26, GHSA-7XG3-FPHP-28HG)')
62
+ }
63
+
43
64
  const originalDispatch = dispatch
44
65
  const self = this
45
66
  dispatch = function (opts, handler) {
@@ -4,7 +4,8 @@ const { AsyncResource } = require('node:async_hooks')
4
4
  const { PoolStats } = require('../util/stats.js')
5
5
  const DispatcherBase = require('./dispatcher-base')
6
6
  const FixedQueue = require('./fixed-queue')
7
- const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
7
+ const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch, kQueuedAbort } = require('../core/symbols')
8
+ const { createAbortedController } = require('../core/request')
8
9
 
9
10
  const kClients = Symbol('clients')
10
11
  const kNeedDrain = Symbol('needDrain')
@@ -23,6 +24,8 @@ const kAddClient = Symbol('add client')
23
24
  const kRemoveClient = Symbol('remove client')
24
25
  const kRetireClient = Symbol('retire client')
25
26
  const kRetiring = Symbol('retiring clients')
27
+ const kShiftQueue = Symbol('shift queue')
28
+ const kAbortQueued = Symbol('abort queued')
26
29
 
27
30
  // Closes every live client, including clients that have been
28
31
  // taken out of rotation but are still finishing their own
@@ -36,6 +39,8 @@ class QueuedRequest extends AsyncResource {
36
39
  super('UNDICI_POOL_QUEUED_REQUEST')
37
40
  this.opts = opts
38
41
  this.handler = handler
42
+ // Cleared once the request leaves the queue, so a late abort is ignored.
43
+ this.queued = true
39
44
  }
40
45
 
41
46
  dispatch (dispatcher) {
@@ -75,17 +80,15 @@ class PoolBase extends DispatcherBase {
75
80
  return
76
81
  }
77
82
 
78
- const queue = this[kQueue]
79
83
  let needDrain = false
80
84
 
81
85
  this[kOnClientDrain](client)
82
86
 
83
87
  while (!needDrain) {
84
- const item = queue.shift()
88
+ const item = this[kShiftQueue]()
85
89
  if (!item) {
86
90
  break
87
91
  }
88
- this[kQueued]--
89
92
  needDrain = !item.dispatch(client)
90
93
  }
91
94
 
@@ -98,7 +101,7 @@ class PoolBase extends DispatcherBase {
98
101
  // negotiated and hit maxConcurrentStreams. Hand the rest to other
99
102
  // clients, creating new ones up to the connection limit, instead of
100
103
  // leaving them for this client to drain one batch at a time.
101
- if (!queue.isEmpty()) {
104
+ if (this[kQueued] > 0) {
102
105
  return this[kDrainQueue](origin, targets)
103
106
  }
104
107
  }
@@ -108,7 +111,7 @@ class PoolBase extends DispatcherBase {
108
111
  this.emit('drain', origin, [this, ...targets])
109
112
  }
110
113
 
111
- if (this[kClosedResolve] && queue.isEmpty()) {
114
+ if (this[kClosedResolve] && this[kQueued] === 0) {
112
115
  return closeClients(this).then(this[kClosedResolve])
113
116
  }
114
117
  }
@@ -118,23 +121,31 @@ class PoolBase extends DispatcherBase {
118
121
  [kOnClientDrain] () {}
119
122
 
120
123
  [kDrainQueue] (origin, targets) {
121
- const queue = this[kQueue]
122
124
  let hasDispatcher = true
123
125
 
124
- while (!queue.isEmpty()) {
125
- const dispatcher = this[kGetDispatcher]()
126
+ while (this[kQueued] > 0) {
127
+ let dispatcher
128
+ try {
129
+ dispatcher = this[kGetDispatcher]()
130
+ } catch (err) {
131
+ // Selection failed before a dispatcher took ownership of this item.
132
+ const item = this[kShiftQueue]()
133
+ item.runInAsyncScope(item.handler.onResponseError, item.handler, null, err)
134
+ // The error handler may synchronously dispatch and consume capacity.
135
+ hasDispatcher = !this.destroyed && this[kHasDispatcher](false)
136
+ continue
137
+ }
126
138
  if (!dispatcher) {
127
139
  hasDispatcher = false
128
140
  break
129
141
  }
130
142
 
131
- const item = queue.shift()
132
- this[kQueued]--
143
+ const item = this[kShiftQueue]()
133
144
 
134
145
  if (!item.dispatch(dispatcher)) {
135
146
  dispatcher[kNeedDrain] = true
136
147
  this[kOnClientBusy](dispatcher)
137
- hasDispatcher = this[kHasDispatcher]()
148
+ hasDispatcher = this[kHasDispatcher](false)
138
149
  if (!hasDispatcher) {
139
150
  break
140
151
  }
@@ -146,11 +157,48 @@ class PoolBase extends DispatcherBase {
146
157
  this.emit('drain', origin, [this, ...targets])
147
158
  }
148
159
 
149
- if (this[kClosedResolve] && queue.isEmpty()) {
160
+ if (this[kClosedResolve] && this[kQueued] === 0) {
150
161
  return closeClients(this).then(this[kClosedResolve])
151
162
  }
152
163
  }
153
164
 
165
+ // Aborted requests stay in the queue as tombstones (queued === false) and
166
+ // are skipped here; kQueued only counts the live ones.
167
+ [kShiftQueue] () {
168
+ const queue = this[kQueue]
169
+ let item = queue.shift()
170
+ while (item !== null && item.queued === false) {
171
+ item = queue.shift()
172
+ }
173
+
174
+ if (item !== null) {
175
+ this[kQueued]--
176
+ item.queued = false
177
+ }
178
+
179
+ return item
180
+ }
181
+
182
+ // Called through the handler's kQueuedAbort hook when a queued request is
183
+ // aborted.
184
+ [kAbortQueued] (item, reason) {
185
+ if (!item.queued) {
186
+ return
187
+ }
188
+
189
+ const { handler } = item
190
+ item.queued = false
191
+ item.opts = null
192
+ item.handler = null
193
+ this[kQueued]--
194
+
195
+ item.runInAsyncScope(handler.onResponseError, handler, createAbortedController(reason), reason)
196
+
197
+ if (this[kClosedResolve] && this[kQueued] === 0) {
198
+ closeClients(this).then(this[kClosedResolve])
199
+ }
200
+ }
201
+
154
202
  [kOnConnect] = (origin, targets) => {
155
203
  this.emit('connect', origin, [this, ...targets])
156
204
  };
@@ -212,7 +260,7 @@ class PoolBase extends DispatcherBase {
212
260
  }
213
261
 
214
262
  [kClose] () {
215
- if (this[kQueue].isEmpty()) {
263
+ if (this[kQueued] === 0) {
216
264
  return closeClients(this)
217
265
  } else {
218
266
  return new Promise((resolve) => {
@@ -223,7 +271,7 @@ class PoolBase extends DispatcherBase {
223
271
 
224
272
  [kDestroy] (err) {
225
273
  while (true) {
226
- const item = this[kQueue].shift()
274
+ const item = this[kShiftQueue]()
227
275
  if (!item) {
228
276
  break
229
277
  }
@@ -244,9 +292,17 @@ class PoolBase extends DispatcherBase {
244
292
  const dispatcher = this[kGetDispatcher]()
245
293
 
246
294
  if (!dispatcher) {
295
+ const item = new QueuedRequest(opts, handler)
247
296
  this[kNeedDrain] = true
248
- this[kQueue].push(new QueuedRequest(opts, handler))
297
+ this[kQueue].push(item)
249
298
  this[kQueued]++
299
+
300
+ const onQueued = opts[kQueuedAbort]
301
+ if (onQueued !== undefined) {
302
+ // Give the handler a way to remove the request from the queue as soon
303
+ // as it is aborted.
304
+ onQueued((reason) => this[kAbortQueued](item, reason))
305
+ }
250
306
  } else if (!dispatcher.dispatch(opts, handler)) {
251
307
  dispatcher[kNeedDrain] = true
252
308
  this[kOnClientBusy](dispatcher)
@@ -18,7 +18,7 @@ const {
18
18
  InvalidArgumentError
19
19
  } = require('../core/errors')
20
20
  const util = require('../core/util')
21
- const { kConnecting, kHTTPContext, kUrl, kQueued } = require('../core/symbols')
21
+ const { kConnecting, kHTTPContext, kHTTP2Session, kRemoteSettings, kUrl, kQueued } = require('../core/symbols')
22
22
  const buildConnector = require('../core/connect')
23
23
 
24
24
  const kOptions = Symbol('options')
@@ -116,12 +116,25 @@ class Pool extends PoolBase {
116
116
  }
117
117
 
118
118
  if (client === this[kProtocolProbe]) {
119
- // An h2 Client's drain event releases the requests accumulated during
120
- // negotiation onto that Client. If ALPN selected h1, release the probe
121
- // immediately and restore normal Pool fan-out instead.
122
- if (this[kProtocol] !== 'h2') {
123
- this[kProtocolProbe] = null
124
- this[kDrainQueue](origin, targets.slice(1))
119
+ const releaseProbe = () => {
120
+ if (client === this[kProtocolProbe]) {
121
+ this[kProtocolProbe] = null
122
+ // An empty queue must not release backpressure when this client
123
+ // is still saturated and the connection limit prevents fan-out.
124
+ // Check capacity without invoking a factory for unused capacity.
125
+ if (!this.destroyed && (this[kQueued] > 0 || (!this.closed && this[kHasDispatcher](false)))) {
126
+ this[kDrainQueue](origin, targets.slice(1))
127
+ }
128
+ }
129
+ }
130
+ const session = client[kHTTP2Session]
131
+ // A peer's stream limit can keep the probe busy indefinitely. Once
132
+ // SETTINGS arrive, queued work may need another connection without
133
+ // waiting for this client's drain event.
134
+ if (this[kProtocol] !== 'h2' || session[kRemoteSettings]) {
135
+ releaseProbe()
136
+ } else {
137
+ session.once('remoteSettings', releaseProbe)
125
138
  }
126
139
  }
127
140
  })
@@ -200,7 +213,7 @@ class Pool extends PoolBase {
200
213
  }
201
214
  }
202
215
 
203
- [kHasDispatcher] () {
216
+ [kHasDispatcher] (create = true) {
204
217
  const clientTtlOption = this[kOptions].clientTtl
205
218
  for (let i = 0; i < this[kClients].length; i++) {
206
219
  const client = this[kClients][i]
@@ -218,7 +231,7 @@ class Pool extends PoolBase {
218
231
  }
219
232
 
220
233
  if (!this[kConnections] || this[kClients].length < this[kConnections]) {
221
- createClient(this)
234
+ if (create) createClient(this)
222
235
  return true
223
236
  }
224
237
 
@@ -412,7 +412,7 @@ class CacheHandler {
412
412
  deleteCachedValue(this.#store, this.#cacheKey)
413
413
  }
414
414
 
415
- // Don't have anything to tell us this response is cachable and we're not
415
+ // Don't have anything to tell us this response is cacheable and we're not
416
416
  // caching by default
417
417
  return downstreamOnHeaders()
418
418
  }
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
  const assert = require('node:assert')
3
3
 
4
- const { kRetryHandlerDefaultRetry } = require('../core/symbols')
4
+ const { kRetryHandlerDefaultRetry, kQueuedAbort } = require('../core/symbols')
5
5
  const { RequestRetryError, RequestAbortedError } = require('../core/errors')
6
6
  const {
7
7
  hasSafeIterator,
@@ -98,6 +98,11 @@ class RetryController {
98
98
  }
99
99
 
100
100
  class RetryHandler {
101
+ // Takes the retry that waits for a connection out of its queue.
102
+ #queuedCancel = null
103
+ // Whether retries are dispatched with a hook that sets #queuedCancel.
104
+ #tracksQueuedRetry = false
105
+
101
106
  constructor (opts, { dispatch, handler }) {
102
107
  const { retryOptions, ...dispatchOpts } = opts
103
108
  const {
@@ -561,6 +566,18 @@ class RetryHandler {
561
566
  }
562
567
  }
563
568
 
569
+ if (!this.#tracksQueuedRetry) {
570
+ // The consumer's controller still targets the earlier attempt, so an
571
+ // abort would not reach a retry that waits for a connection. Keep the
572
+ // function that takes it out of its queue; the caller's hook still runs.
573
+ this.#tracksQueuedRetry = true
574
+ const onQueued = this.opts[kQueuedAbort]
575
+ this.opts[kQueuedAbort] = (cancel) => {
576
+ this.#queuedCancel = cancel
577
+ onQueued?.(cancel)
578
+ }
579
+ }
580
+
564
581
  try {
565
582
  this.retryCountCheckpoint = this.retryCount
566
583
  this.dispatch(this.opts, this)
@@ -622,6 +639,15 @@ class RetryHandler {
622
639
  }
623
640
 
624
641
  #onAbort (reason) {
642
+ // A retry that waits for a connection is taken out of its queue: its
643
+ // dispatcher fails it with an aborted controller, so onResponseError passes
644
+ // the abort on instead of retrying. Once the retry started, this does nothing.
645
+ const cancel = this.#queuedCancel
646
+ if (cancel !== null) {
647
+ this.#queuedCancel = null
648
+ cancel(reason ?? new RequestAbortedError())
649
+ }
650
+
625
651
  // A consumer abort lands on the controller proxy. If the retry policy is
626
652
  // still deciding (typically holding a backoff timer), cancel the wait and
627
653
  // surface the abort immediately instead of letting the request hang until
@@ -18,7 +18,9 @@ const {
18
18
  isEtagUsable
19
19
  } = require('../util/cache.js')
20
20
  const { AbortError } = require('../core/errors.js')
21
+ const { kQueuedAbort } = require('../core/symbols.js')
21
22
  const { parseHttpDate } = require('../util/date.js')
23
+ const { kInterceptorKind } = require('../core/symbols.js')
22
24
 
23
25
  /**
24
26
  * @param {(string | RegExp)[] | undefined} origins
@@ -541,7 +543,10 @@ function handleResult (
541
543
  dispatch(
542
544
  {
543
545
  ...opts,
544
- headers
546
+ headers,
547
+ // The revalidation is not the caller's request: aborting the
548
+ // caller must not cancel it while it waits for a connection.
549
+ [kQueuedAbort]: undefined
545
550
  },
546
551
  new CacheHandler(globalOpts, cacheKey, {
547
552
  // Silent handler that just updates the cache
@@ -665,7 +670,7 @@ module.exports = (opts = {}) => {
665
670
  }
666
671
  }
667
672
 
668
- return (dispatch, interceptorOrigin) => {
673
+ const interceptor = (dispatch, interceptorOrigin) => {
669
674
  return (opts, handler) => {
670
675
  const requestOrigin = getInterceptorOrigin(opts, interceptorOrigin)
671
676
  if (!requestOrigin || arrayIncludes(safeMethodsToNotCache, opts.method)) {
@@ -768,4 +773,6 @@ module.exports = (opts = {}) => {
768
773
  }
769
774
  }
770
775
  }
776
+ interceptor[kInterceptorKind] = 'cache'
777
+ return interceptor
771
778
  }
@@ -105,8 +105,6 @@ function createMaxSizeLimiter (maxSize) {
105
105
  })
106
106
  }
107
107
 
108
- let warningEmitted = /** @type {boolean} */ (false)
109
-
110
108
  /**
111
109
  * @typedef {Object} DecompressHandlerOptions
112
110
  * @property {number[]|Readonly<number[]>} [skipStatusCodes=[204, 304]] - List of status codes to skip decompression for
@@ -550,15 +548,6 @@ class DecompressHandler extends DecoratorHandler {
550
548
  * @returns {Function} - Interceptor function
551
549
  */
552
550
  function createDecompressInterceptor (options = {}) {
553
- // Emit experimental warning only once
554
- if (!warningEmitted) {
555
- process.emitWarning(
556
- 'DecompressInterceptor is experimental and subject to change',
557
- 'ExperimentalWarning'
558
- )
559
- warningEmitted = true
560
- }
561
-
562
551
  return (dispatch) => {
563
552
  return (opts, handler) => {
564
553
  if (opts.method === 'HEAD') {
@@ -4,6 +4,7 @@ const diagnosticsChannel = require('node:diagnostics_channel')
4
4
  const util = require('../core/util')
5
5
  const DeduplicationHandler = require('../handler/deduplication-handler')
6
6
  const { getInterceptorOrigin, normalizeHeaders, makeCacheKey, makeDeduplicationKey } = require('../util/cache.js')
7
+ const { kInterceptorKind } = require('../core/symbols.js')
7
8
 
8
9
  const pendingRequestsChannel = diagnosticsChannel.channel('undici:request:pending-requests')
9
10
 
@@ -57,7 +58,7 @@ module.exports = (opts = {}) => {
57
58
  */
58
59
  const pendingRequests = new Map()
59
60
 
60
- return (dispatch, interceptorOrigin) => {
61
+ const interceptor = (dispatch, interceptorOrigin) => {
61
62
  return (opts, handler) => {
62
63
  const requestOrigin = getInterceptorOrigin(opts, interceptorOrigin)
63
64
  if (!requestOrigin || opts.upgrade || methods.includes(opts.method) === false) {
@@ -115,4 +116,6 @@ module.exports = (opts = {}) => {
115
116
  return dispatch(opts, deduplicationHandler)
116
117
  }
117
118
  }
119
+ interceptor[kInterceptorKind] = 'deduplicate'
120
+ return interceptor
118
121
  }
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const RedirectHandler = require('../handler/redirect-handler')
4
+ const { kInterceptorKind } = require('../core/symbols.js')
4
5
 
5
6
  function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections, throwOnMaxRedirect: defaultThrowOnMaxRedirect, stripHeadersOnRedirect: defaultStripHeadersOnRedirect, stripHeadersOnCrossOriginRedirect: defaultStripHeadersOnCrossOriginRedirect } = {}) {
6
- return (dispatch) => {
7
+ const interceptor = (dispatch) => {
7
8
  return function Intercept (opts, handler) {
8
9
  const { maxRedirections = defaultMaxRedirections, throwOnMaxRedirect = defaultThrowOnMaxRedirect, stripHeadersOnRedirect = defaultStripHeadersOnRedirect, stripHeadersOnCrossOriginRedirect = defaultStripHeadersOnCrossOriginRedirect, ...rest } = opts
9
10
 
@@ -16,6 +17,8 @@ function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections, t
16
17
  return dispatch(dispatchOpts, redirectHandler)
17
18
  }
18
19
  }
20
+ interceptor[kInterceptorKind] = 'redirect'
21
+ return interceptor
19
22
  }
20
23
 
21
24
  module.exports = createRedirectInterceptor
@@ -650,7 +650,7 @@ function isInvalidOrWildcardVaryHeader (varyHeader) {
650
650
 
651
651
  /**
652
652
  * Note: this deviates from the spec a little. Empty etags ("", W/"") are valid,
653
- * however, including them in cached resposnes serves little to no purpose.
653
+ * however, including them in cached responses serves little to no purpose.
654
654
  *
655
655
  * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-etag
656
656
  *
@@ -194,7 +194,7 @@ function refreshTimeout () {
194
194
  // method (e.g. mocked timers in tests).
195
195
  if (fastNowTimeout?.refresh) {
196
196
  fastNowTimeout.refresh()
197
- // fastNowTimeout is not instantiated yet or refresh is not availabe,
197
+ // fastNowTimeout is not instantiated yet or refresh is not available,
198
198
  // create a new Timer.
199
199
  } else {
200
200
  clearTimeout(fastNowTimeout)
@@ -59,7 +59,7 @@ const {
59
59
  const EE = require('node:events')
60
60
  const { Readable, pipeline, finished, isErrored, isReadable } = require('node:stream')
61
61
  const { addAbortListener, bufferToLowerCasedHeaderName } = require('../../core/util')
62
- const { SocketError } = require('../../core/errors')
62
+ const { SocketError, InformationalError } = require('../../core/errors')
63
63
  const { dataURLProcessor, serializeAMimeType, minimizeSupportedMimeType } = require('./data-url')
64
64
  const { getGlobalDispatcher } = require('../../global')
65
65
  const { webidl } = require('../webidl')
@@ -2333,6 +2333,10 @@ async function httpNetworkFetch (
2333
2333
  }
2334
2334
  }
2335
2335
 
2336
+ // The response will be exposed without a body, so any content the
2337
+ // server sends is disregarded (see main fetch step 19).
2338
+ this.nullBodyStatus = nullBodyStatus.includes(status)
2339
+
2336
2340
  this.body = new Readable({ read: () => controller.resume() })
2337
2341
 
2338
2342
  const onError = (err) => this.onResponseError(controller, err)
@@ -2352,6 +2356,14 @@ async function httpNetworkFetch (
2352
2356
  },
2353
2357
 
2354
2358
  onResponseData (controller, chunk) {
2359
+ if (this.nullBodyStatus) {
2360
+ // The server sent content in a response that must not have any.
2361
+ // Nobody can read it, so close the connection instead of waiting
2362
+ // for the server to finish sending it.
2363
+ controller.abort(new InformationalError('response with null body status has content'))
2364
+ return
2365
+ }
2366
+
2355
2367
  if (fetchParams.controller.dump) {
2356
2368
  return
2357
2369
  }
@@ -2391,6 +2403,13 @@ async function httpNetworkFetch (
2391
2403
  fetchParams.controller.off('terminated', this.abort)
2392
2404
  }
2393
2405
 
2406
+ if (this.nullBodyStatus) {
2407
+ // The response has no body, so a failure while receiving the
2408
+ // disregarded content must not turn it into a network error.
2409
+ this.body?.destroy()
2410
+ return
2411
+ }
2412
+
2394
2413
  if (
2395
2414
  request.mode === 'websocket' &&
2396
2415
  allowH2 !== false &&
@@ -560,7 +560,7 @@ function stripURLForReferrer (url, originOnly = false) {
560
560
  return url
561
561
  }
562
562
 
563
- const isPotentialleTrustworthyIPv4 = RegExp.prototype.test
563
+ const isPotentiallyTrustworthyIPv4 = RegExp.prototype.test
564
564
  .bind(/^127\.(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){2}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)$/)
565
565
 
566
566
  const isPotentiallyTrustworthyIPv6 = RegExp.prototype.test
@@ -583,7 +583,7 @@ function isOriginIPPotentiallyTrustworthy (origin) {
583
583
  }
584
584
 
585
585
  // IPv4
586
- return isPotentialleTrustworthyIPv4(origin)
586
+ return isPotentiallyTrustworthyIPv4(origin)
587
587
  }
588
588
 
589
589
  /**
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "8.12.4",
3
+ "version": "8.13.0",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {
@@ -93,7 +93,7 @@
93
93
  "test:node-test": "borp --timeout 180000 -p \"test/node-test/**/*.js\"",
94
94
  "test:tdd": "borp --timeout 180000 --expose-gc -p \"test/*.js\"",
95
95
  "test:tdd:node-test": "borp --timeout 180000 -p \"test/node-test/**/*.js\" -w",
96
- "test:typescript": "tsd && tsc test/imports/undici-import.ts --typeRoots ./types --noEmit && tsc ./types/*.d.ts --noEmit --typeRoots ./types",
96
+ "test:typescript": "tsd && tsc test/imports/undici-import.ts --typeRoots ./types --noEmit && tsc -p tsconfig.types.json",
97
97
  "test:webidl": "borp --timeout 180000 -p \"test/webidl/*.js\"",
98
98
  "test:websocket": "borp --timeout 180000 -p \"test/websocket/**/*.js\"",
99
99
  "test:websocket:autobahn": "node test/autobahn/client.js",
@@ -111,7 +111,7 @@
111
111
  "prepare": "husky && node ./scripts/platform-shell.js"
112
112
  },
113
113
  "devDependencies": {
114
- "@fastify/busboy": "3.2.4",
114
+ "@fastify/busboy": "3.2.5",
115
115
  "@matteo.collina/tspl": "^0.2.0",
116
116
  "@metcoder95/https-pem": "^1.0.0",
117
117
  "@sinonjs/fake-timers": "^12.0.0",
@@ -78,7 +78,7 @@ declare namespace RetryHandler {
78
78
  */
79
79
  minTimeout?: number;
80
80
  /**
81
- * Factior to multiply the timeout factor between retries.
81
+ * Factor to multiply the timeout factor between retries.
82
82
  *
83
83
  * @type {number}
84
84
  * @memberof RetryOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dent-agent",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "A generic coding agent as a pi extension: Bash, Task, Agent, Fleet, Script, Search, Markdown and more tools, with billing and terms extensions bundled",
5
5
  "keywords": [
6
6
  "coding-agent",