@openclaw/anthropic-vertex-provider 2026.8.2 → 2026.8.34

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 (50) hide show
  1. package/node_modules/undici/docs/docs/api/Client.md +4 -0
  2. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +3 -2
  3. package/node_modules/undici/docs/docs/api/EventSource.md +4 -0
  4. package/node_modules/undici/docs/docs/api/Interceptors.md +7 -3
  5. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +7 -1
  6. package/node_modules/undici/lib/cache/memory-cache-store.js +2 -2
  7. package/node_modules/undici/lib/core/symbols.js +2 -0
  8. package/node_modules/undici/lib/dispatcher/agent.js +7 -2
  9. package/node_modules/undici/lib/dispatcher/balanced-pool.js +7 -4
  10. package/node_modules/undici/lib/dispatcher/client-h1.js +12 -4
  11. package/node_modules/undici/lib/dispatcher/client-h2.js +43 -3
  12. package/node_modules/undici/lib/dispatcher/client.js +3 -2
  13. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +13 -1
  14. package/node_modules/undici/lib/dispatcher/dispatcher.js +15 -1
  15. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +3 -0
  16. package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +10 -3
  17. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -1
  18. package/node_modules/undici/lib/dispatcher/retry-agent.js +3 -0
  19. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +1 -1
  20. package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +91 -21
  21. package/node_modules/undici/lib/handler/cache-handler.js +29 -5
  22. package/node_modules/undici/lib/handler/decorator-handler.js +7 -1
  23. package/node_modules/undici/lib/handler/deduplication-handler.js +12 -6
  24. package/node_modules/undici/lib/handler/redirect-handler.js +21 -4
  25. package/node_modules/undici/lib/handler/retry-handler.js +148 -30
  26. package/node_modules/undici/lib/interceptor/cache.js +65 -12
  27. package/node_modules/undici/lib/interceptor/decompress.js +115 -13
  28. package/node_modules/undici/lib/interceptor/deduplicate.js +5 -4
  29. package/node_modules/undici/lib/interceptor/dns.js +7 -0
  30. package/node_modules/undici/lib/interceptor/dump.js +10 -23
  31. package/node_modules/undici/lib/mock/mock-agent.js +13 -1
  32. package/node_modules/undici/lib/mock/mock-utils.js +11 -10
  33. package/node_modules/undici/lib/util/cache.js +45 -3
  34. package/node_modules/undici/lib/web/cookies/parse.js +150 -147
  35. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +28 -1
  36. package/node_modules/undici/lib/web/eventsource/eventsource.js +13 -3
  37. package/node_modules/undici/lib/web/fetch/index.js +6 -0
  38. package/node_modules/undici/lib/web/fetch/request.js +2 -3
  39. package/node_modules/undici/lib/web/fetch/util.js +6 -1
  40. package/node_modules/undici/lib/web/webidl/index.js +3 -3
  41. package/node_modules/undici/lib/web/websocket/connection.js +1 -1
  42. package/node_modules/undici/lib/web/websocket/permessage-deflate.js +5 -0
  43. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -10
  44. package/node_modules/undici/package.json +3 -3
  45. package/node_modules/undici/types/client.d.ts +10 -0
  46. package/node_modules/undici/types/interceptors.d.ts +2 -0
  47. package/node_modules/undici/types/mock-agent.d.ts +11 -10
  48. package/node_modules/undici/types/socks5-proxy-agent.d.ts +2 -0
  49. package/openclaw.plugin.json +10 -4
  50. package/package.json +5 -5
@@ -4,22 +4,33 @@ const { URL } = require('node:url')
4
4
 
5
5
  let tls // include tls conditionally since it is not always available
6
6
  const DispatcherBase = require('./dispatcher-base')
7
- const { InvalidArgumentError } = require('../core/errors')
7
+ const { ConnectTimeoutError, InvalidArgumentError } = require('../core/errors')
8
8
  const { Socks5Client, STATES } = require('../core/socks5-client')
9
9
  const { kBusy, kConnected, kDispatch, kClose, kDestroy } = require('../core/symbols')
10
10
  const Pool = require('./pool')
11
11
  const buildConnector = require('../core/connect')
12
+ const { setupConnectTimeout } = require('../core/util')
12
13
  const { debuglog } = require('node:util')
13
14
 
14
15
  const debug = debuglog('undici:socks5-proxy')
15
16
 
17
+ const DEFAULT_SOCKS5_CONNECT_TIMEOUT = 5000
18
+
16
19
  const kProxyUrl = Symbol('proxy url')
17
20
  const kProxyHeaders = Symbol('proxy headers')
18
21
  const kProxyAuth = Symbol('proxy auth')
19
22
  const kProxyProtocol = Symbol('proxy protocol')
20
23
  const kPools = Symbol('pools')
21
24
  const kConnector = Symbol('connector')
25
+ const kConnectTimeout = Symbol('connect timeout')
22
26
  const kRequestTls = Symbol('request tls settings')
27
+ const kRequestTlsTimeout = Symbol('request tls timeout')
28
+
29
+ function createConnectTimeoutError (hostname, port, timeout) {
30
+ return new ConnectTimeoutError(
31
+ `Connect Timeout Error (attempted address: ${hostname}:${port}, timeout: ${timeout}ms)`
32
+ )
33
+ }
23
34
 
24
35
  // Static flag to ensure warning is only emitted once per process
25
36
  let experimentalWarningEmitted = false
@@ -29,7 +40,7 @@ let experimentalWarningEmitted = false
29
40
  */
30
41
  class Socks5ProxyAgent extends DispatcherBase {
31
42
  constructor (proxyUrl, options = {}) {
32
- super()
43
+ super(options)
33
44
 
34
45
  // Emit experimental warning only once
35
46
  if (!experimentalWarningEmitted) {
@@ -54,7 +65,20 @@ class Socks5ProxyAgent extends DispatcherBase {
54
65
  this[kProxyUrl] = url
55
66
  this[kProxyHeaders] = options.headers || {}
56
67
  this[kProxyProtocol] = options.proxyTls ? 'https:' : 'http:'
57
- this[kRequestTls] = options.requestTls
68
+
69
+ const connectTimeout = options.connectTimeout ?? DEFAULT_SOCKS5_CONNECT_TIMEOUT
70
+ if (!Number.isFinite(connectTimeout) || connectTimeout < 0) {
71
+ throw new InvalidArgumentError('invalid connectTimeout')
72
+ }
73
+ this[kConnectTimeout] = connectTimeout
74
+
75
+ const { timeout, ...requestTls } = options.requestTls || {}
76
+ const requestTlsTimeout = timeout ?? connectTimeout
77
+ if (!Number.isFinite(requestTlsTimeout) || requestTlsTimeout < 0) {
78
+ throw new InvalidArgumentError('invalid requestTls.timeout')
79
+ }
80
+ this[kRequestTls] = requestTls
81
+ this[kRequestTlsTimeout] = requestTlsTimeout
58
82
 
59
83
  // Extract auth from URL or options
60
84
  this[kProxyAuth] = {
@@ -63,8 +87,13 @@ class Socks5ProxyAgent extends DispatcherBase {
63
87
  }
64
88
 
65
89
  // Create connector for proxy connection
90
+ const proxyTlsTimeout = options.proxyTls?.timeout ?? connectTimeout
91
+ if (!Number.isFinite(proxyTlsTimeout) || proxyTlsTimeout < 0) {
92
+ throw new InvalidArgumentError('invalid proxyTls.timeout')
93
+ }
66
94
  this[kConnector] = options.connect || buildConnector({
67
95
  ...options.proxyTls,
96
+ timeout: proxyTlsTimeout,
68
97
  servername: options.proxyTls?.servername || url.hostname
69
98
  })
70
99
 
@@ -113,20 +142,29 @@ class Socks5ProxyAgent extends DispatcherBase {
113
142
 
114
143
  // Wait for authentication (if required)
115
144
  const authenticationReady = Promise.withResolvers()
116
-
117
- const authenticationTimeout = setTimeout(() => {
118
- authenticationReady.reject(new Error('SOCKS5 authentication timeout'))
119
- }, 5000)
120
-
121
- const onAuthenticated = () => {
145
+ const authenticationTimeout = this[kConnectTimeout] === 0
146
+ ? null
147
+ : setTimeout(() => {
148
+ cleanupAuthenticationListeners()
149
+ socks5Client.destroy()
150
+ authenticationReady.reject(
151
+ createConnectTimeoutError(proxyHost, proxyPort, this[kConnectTimeout])
152
+ )
153
+ }, this[kConnectTimeout])
154
+
155
+ const cleanupAuthenticationListeners = () => {
122
156
  clearTimeout(authenticationTimeout)
157
+ socks5Client.removeListener('authenticated', onAuthenticated)
123
158
  socks5Client.removeListener('error', onAuthenticationError)
159
+ }
160
+
161
+ const onAuthenticated = () => {
162
+ cleanupAuthenticationListeners()
124
163
  authenticationReady.resolve()
125
164
  }
126
165
 
127
166
  const onAuthenticationError = (err) => {
128
- clearTimeout(authenticationTimeout)
129
- socks5Client.removeListener('authenticated', onAuthenticated)
167
+ cleanupAuthenticationListeners()
130
168
  authenticationReady.reject(err)
131
169
  }
132
170
 
@@ -146,21 +184,30 @@ class Socks5ProxyAgent extends DispatcherBase {
146
184
 
147
185
  // Wait for connection
148
186
  const connectionReady = Promise.withResolvers()
149
-
150
- const connectionTimeout = setTimeout(() => {
151
- connectionReady.reject(new Error('SOCKS5 connection timeout'))
152
- }, 5000)
187
+ const connectionTimeout = this[kConnectTimeout] === 0
188
+ ? null
189
+ : setTimeout(() => {
190
+ cleanupConnectionListeners()
191
+ socks5Client.destroy()
192
+ connectionReady.reject(
193
+ createConnectTimeoutError(targetHost, targetPort, this[kConnectTimeout])
194
+ )
195
+ }, this[kConnectTimeout])
196
+
197
+ const cleanupConnectionListeners = () => {
198
+ clearTimeout(connectionTimeout)
199
+ socks5Client.removeListener('connected', onConnected)
200
+ socks5Client.removeListener('error', onConnectionError)
201
+ }
153
202
 
154
203
  const onConnected = (info) => {
155
204
  debug('SOCKS5 tunnel established to', targetHost, targetPort, 'via', info)
156
- clearTimeout(connectionTimeout)
157
- socks5Client.removeListener('error', onConnectionError)
205
+ cleanupConnectionListeners()
158
206
  connectionReady.resolve()
159
207
  }
160
208
 
161
209
  const onConnectionError = (err) => {
162
- clearTimeout(connectionTimeout)
163
- socks5Client.removeListener('connected', onConnected)
210
+ cleanupConnectionListeners()
164
211
  connectionReady.reject(err)
165
212
  }
166
213
 
@@ -213,8 +260,31 @@ class Socks5ProxyAgent extends DispatcherBase {
213
260
  })
214
261
 
215
262
  const tlsReady = Promise.withResolvers()
216
- finalSocket.once('secureConnect', tlsReady.resolve)
217
- finalSocket.once('error', tlsReady.reject)
263
+
264
+ const cleanupTlsListeners = () => {
265
+ queueMicrotask(clearTlsTimeout)
266
+ finalSocket.removeListener('secureConnect', onSecureConnect)
267
+ finalSocket.removeListener('error', onTlsError)
268
+ }
269
+
270
+ const onSecureConnect = () => {
271
+ cleanupTlsListeners()
272
+ tlsReady.resolve()
273
+ }
274
+
275
+ const onTlsError = (err) => {
276
+ cleanupTlsListeners()
277
+ tlsReady.reject(err)
278
+ }
279
+
280
+ const clearTlsTimeout = setupConnectTimeout(new WeakRef(finalSocket), {
281
+ timeout: this[kRequestTlsTimeout],
282
+ hostname: targetHost,
283
+ port: targetPort
284
+ })
285
+
286
+ finalSocket.once('secureConnect', onSecureConnect)
287
+ finalSocket.once('error', onTlsError)
218
288
  await tlsReady.promise
219
289
  }
220
290
 
@@ -173,6 +173,14 @@ class CacheHandler {
173
173
  this.#handler.onRequestStart?.(controller, context)
174
174
  }
175
175
 
176
+ onBodySent (chunk) {
177
+ this.#handler.onBodySent?.(chunk)
178
+ }
179
+
180
+ onRequestSent () {
181
+ this.#handler.onRequestSent?.()
182
+ }
183
+
176
184
  onRequestUpgrade (controller, statusCode, headers, socket) {
177
185
  this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
178
186
  }
@@ -210,6 +218,13 @@ class CacheHandler {
210
218
  }
211
219
 
212
220
  const cacheControlHeader = resHeaders['cache-control']
221
+ const cacheControlDirectives = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {}
222
+
223
+ if (revalidationResponseDisallowsCachedReuse(this.#cacheType, resHeaders, cacheControlDirectives)) {
224
+ deleteCachedValue(this.#store, this.#cacheKey)
225
+ return downstreamOnHeaders()
226
+ }
227
+
213
228
  const heuristicallyCacheable = resHeaders['last-modified'] && arrayIncludes(HEURISTICALLY_CACHEABLE_STATUS_CODES, statusCode)
214
229
  if (
215
230
  !cacheControlHeader &&
@@ -226,8 +241,7 @@ class CacheHandler {
226
241
  return downstreamOnHeaders()
227
242
  }
228
243
 
229
- const cacheControlDirectives = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {}
230
- if (!canCacheResponse(this.#cacheType, statusCode, resHeaders, cacheControlDirectives, this.#cacheKey.headers)) {
244
+ if (!canCacheResponse(this.#cacheType, this.#cacheKey.method, statusCode, resHeaders, cacheControlDirectives, this.#cacheKey.headers)) {
231
245
  if (statusCode === 304 && (cacheControlHeader || revalidationResponseDisallowsCachedReuse(this.#cacheType, resHeaders, cacheControlDirectives))) {
232
246
  deleteCachedValue(this.#store, this.#cacheKey)
233
247
  }
@@ -476,7 +490,10 @@ function deleteCachedValueIfNotModified (statusCode, store, cacheKey) {
476
490
  */
477
491
  function revalidationResponseDisallowsCachedReuse (cacheType, resHeaders, cacheControlDirectives) {
478
492
  return cacheControlDirectives['no-store'] === true ||
479
- (cacheType === 'shared' && cacheControlDirectives.private === true) ||
493
+ (cacheType === 'shared' && (
494
+ cacheControlDirectives.private === true ||
495
+ Object.hasOwn(resHeaders, 'set-cookie')
496
+ )) ||
480
497
  (resHeaders.vary ? isInvalidOrWildcardVaryHeader(resHeaders.vary) : false)
481
498
  }
482
499
 
@@ -484,12 +501,16 @@ function revalidationResponseDisallowsCachedReuse (cacheType, resHeaders, cacheC
484
501
  * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-storing-responses-to-authen
485
502
  *
486
503
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
504
+ * @param {string} method
487
505
  * @param {number} statusCode
488
506
  * @param {import('../../types/header.d.ts').IncomingHttpHeaders} resHeaders
489
507
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives} cacheControlDirectives
490
508
  * @param {import('../../types/header.d.ts').IncomingHttpHeaders} [reqHeaders]
491
509
  */
492
- function canCacheResponse (cacheType, statusCode, resHeaders, cacheControlDirectives, reqHeaders) {
510
+ function canCacheResponse (cacheType, method, statusCode, resHeaders, cacheControlDirectives, reqHeaders) {
511
+ if (!arrayIncludes(util.safeHTTPMethods, method)) {
512
+ return false
513
+ }
493
514
  // Status code must be final and understood.
494
515
  if (statusCode < 200 || arrayIncludes(NOT_UNDERSTOOD_STATUS_CODES, statusCode)) {
495
516
  return false
@@ -510,7 +531,10 @@ function canCacheResponse (cacheType, statusCode, resHeaders, cacheControlDirect
510
531
  return false
511
532
  }
512
533
 
513
- if (cacheType === 'shared' && cacheControlDirectives.private === true) {
534
+ if (cacheType === 'shared' && (
535
+ cacheControlDirectives.private === true ||
536
+ Object.hasOwn(resHeaders, 'set-cookie')
537
+ )) {
514
538
  return false
515
539
  }
516
540
 
@@ -62,5 +62,11 @@ module.exports = class DecoratorHandler {
62
62
  /**
63
63
  * @deprecated
64
64
  */
65
- onBodySent () {}
65
+ onBodySent (...args) {
66
+ return this.#handler.onBodySent?.(...args)
67
+ }
68
+
69
+ onRequestSent (...args) {
70
+ return this.#handler.onRequestSent?.(...args)
71
+ }
66
72
  }
@@ -365,12 +365,22 @@ class DeduplicationHandler {
365
365
  get aborted () { return state.aborted },
366
366
  get reason () { return state.reason },
367
367
  abort: (reason) => {
368
+ if (state.aborted) {
369
+ return
370
+ }
371
+
368
372
  state.aborted = true
369
373
  state.reason = reason ?? null
370
374
  waitingHandler.done = true
371
375
  waitingHandler.pendingTrailers = null
372
376
  waitingHandler.bufferedChunks = []
373
377
  waitingHandler.bufferedBytes = 0
378
+
379
+ try {
380
+ handler.onResponseError?.(waitingHandler.controller, state.reason ?? new RequestAbortedError())
381
+ } catch {
382
+ // Ignore errors from waiting handlers
383
+ }
374
384
  }
375
385
  }
376
386
 
@@ -444,12 +454,8 @@ class DeduplicationHandler {
444
454
  waitingHandler.bufferedChunks = []
445
455
  waitingHandler.bufferedBytes = 0
446
456
 
447
- try {
448
- waitingHandler.controller.abort(err)
449
- waitingHandler.handler.onResponseError?.(waitingHandler.controller, err)
450
- } catch {
451
- // Ignore errors from waiting handlers
452
- }
457
+ // controller.abort(err) notifies the handler via onResponseError
458
+ waitingHandler.controller.abort(err)
453
459
  }
454
460
 
455
461
  #pruneDoneWaitingHandlers () {
@@ -3,6 +3,7 @@
3
3
  const util = require('../core/util')
4
4
  const assert = require('node:assert')
5
5
  const { InvalidArgumentError } = require('../core/errors')
6
+ const { kRequestOrigin } = require('../core/symbols')
6
7
 
7
8
  const redirectableStatusCodes = [300, 301, 302, 303, 307, 308]
8
9
 
@@ -43,6 +44,14 @@ class RedirectHandler {
43
44
  this.handler.onRequestStart?.(controller, { ...context, history: this.history })
44
45
  }
45
46
 
47
+ onBodySent (chunk) {
48
+ this.handler.onBodySent?.(chunk)
49
+ }
50
+
51
+ onRequestSent () {
52
+ this.handler.onRequestSent?.()
53
+ }
54
+
46
55
  onRequestUpgrade (controller, statusCode, headers, socket) {
47
56
  this.handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
48
57
  }
@@ -81,8 +90,12 @@ class RedirectHandler {
81
90
  ? null
82
91
  : headers.location
83
92
 
84
- if (this.opts.origin) {
85
- this.history.push(new URL(this.opts.path, this.opts.origin))
93
+ const requestOrigin = this.opts[kRequestOrigin] === undefined
94
+ ? this.opts.origin
95
+ : this.opts[kRequestOrigin]
96
+
97
+ if (requestOrigin) {
98
+ this.history.push(new URL(this.opts.path, requestOrigin))
86
99
  }
87
100
 
88
101
  if (!this.location) {
@@ -90,7 +103,10 @@ class RedirectHandler {
90
103
  return
91
104
  }
92
105
 
93
- const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)))
106
+ const baseUrl = requestOrigin
107
+ ? new URL(this.opts.path, requestOrigin)
108
+ : undefined
109
+ const { origin, pathname, search } = util.parseURL(new URL(this.location, baseUrl))
94
110
  const path = search ? `${pathname}${search}` : pathname
95
111
 
96
112
  // Check for redirect loops by seeing if we've already visited this URL in our history
@@ -106,9 +122,10 @@ class RedirectHandler {
106
122
  // Remove headers referring to the original URL.
107
123
  // By default it is Host only. A 303 or a 301/302 POST-to-GET redirect also removes all Content-* headers.
108
124
  // https://tools.ietf.org/html/rfc7231#section-6.4
109
- this.opts.headers = cleanRequestHeaders(this.opts.headers, removeContentHeaders, this.opts.origin !== origin, this.stripHeadersOnRedirect, this.stripHeadersOnCrossOriginRedirect)
125
+ this.opts.headers = cleanRequestHeaders(this.opts.headers, removeContentHeaders, requestOrigin !== origin, this.stripHeadersOnRedirect, this.stripHeadersOnCrossOriginRedirect)
110
126
  this.opts.path = path
111
127
  this.opts.origin = origin
128
+ this.opts[kRequestOrigin] = origin
112
129
  this.opts.query = null
113
130
  }
114
131