@ai-sdk/gateway 2.0.143 → 2.0.145

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.
package/dist/index.mjs CHANGED
@@ -19,12 +19,18 @@ var GatewayError = class _GatewayError extends (_b = Error, _a = symbol, _b) {
19
19
  constructor({
20
20
  message,
21
21
  statusCode = 500,
22
- cause
22
+ cause,
23
+ isRetryable = statusCode != null && (statusCode === 408 || // request timeout
24
+ statusCode === 409 || // conflict
25
+ statusCode === 429 || // too many requests
26
+ statusCode >= 500)
27
+ // server error
23
28
  }) {
24
29
  super(message);
25
30
  this[_a] = true;
26
31
  this.statusCode = statusCode;
27
32
  this.cause = cause;
33
+ this.isRetryable = isRetryable;
28
34
  }
29
35
  /**
30
36
  * Checks if the given error is a Gateway Error.
@@ -243,9 +249,10 @@ var GatewayResponseError = class extends (_b8 = GatewayError, _a8 = symbol8, _b8
243
249
  statusCode = 502,
244
250
  response,
245
251
  validationError,
246
- cause
252
+ cause,
253
+ isRetryable
247
254
  } = {}) {
248
- super({ message, statusCode, cause });
255
+ super({ message, statusCode, cause, isRetryable });
249
256
  this[_a8] = true;
250
257
  // used in isInstance
251
258
  this.name = name7;
@@ -269,7 +276,8 @@ async function createGatewayErrorFromResponse({
269
276
  statusCode,
270
277
  defaultMessage = "Gateway request failed",
271
278
  cause,
272
- authMethod
279
+ authMethod,
280
+ isRetryable
273
281
  }) {
274
282
  const parseResult = await safeValidateTypes({
275
283
  value: response,
@@ -281,7 +289,8 @@ async function createGatewayErrorFromResponse({
281
289
  statusCode,
282
290
  response,
283
291
  validationError: parseResult.error,
284
- cause
292
+ cause,
293
+ isRetryable
285
294
  });
286
295
  }
287
296
  const validatedResponse = parseResult.value;
@@ -435,7 +444,8 @@ async function asGatewayError(error, authMethod) {
435
444
  statusCode: (_a10 = error.statusCode) != null ? _a10 : 500,
436
445
  defaultMessage: "Gateway request failed",
437
446
  cause: error,
438
- authMethod
447
+ authMethod,
448
+ isRetryable: error.isRetryable && (error.statusCode == null || error.statusCode < 400) ? true : void 0
439
449
  });
440
450
  }
441
451
  return await createGatewayErrorFromResponse({
@@ -1366,7 +1376,7 @@ async function getVercelRequestId() {
1366
1376
  }
1367
1377
 
1368
1378
  // src/version.ts
1369
- var VERSION = true ? "2.0.143" : "0.0.0-test";
1379
+ var VERSION = true ? "2.0.145" : "0.0.0-test";
1370
1380
 
1371
1381
  // src/gateway-provider.ts
1372
1382
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";