@ai-sdk/gateway 4.0.92 → 4.0.95

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.js CHANGED
@@ -15,7 +15,7 @@ function getGatewayTranscriptionProtocols(token, options) {
15
15
  }
16
16
  function buildGatewayProtocols(marker12, token, options) {
17
17
  const protocols = [marker12, `${GATEWAY_AUTH_SUBPROTOCOL_PREFIX}${token}`];
18
- if (options == null ? void 0 : options.teamIdOrSlug) {
18
+ if (options?.teamIdOrSlug) {
19
19
  protocols.push(
20
20
  `${GATEWAY_TEAM_SUBPROTOCOL_PREFIX}${encodeSubprotocolValue(options.teamIdOrSlug)}`
21
21
  );
@@ -23,26 +23,24 @@ function buildGatewayProtocols(marker12, token, options) {
23
23
  return protocols;
24
24
  }
25
25
  function getGatewayRealtimeAuthToken(secWebSocketProtocol) {
26
- var _a12;
27
- return ((_a12 = findProtocol(secWebSocketProtocol, GATEWAY_AUTH_SUBPROTOCOL_PREFIX)) == null ? void 0 : _a12.slice(
26
+ return findProtocol(secWebSocketProtocol, GATEWAY_AUTH_SUBPROTOCOL_PREFIX)?.slice(
28
27
  GATEWAY_AUTH_SUBPROTOCOL_PREFIX.length
29
- )) || void 0;
28
+ ) || void 0;
30
29
  }
31
30
  function getGatewayRealtimeTeamIdOrSlug(secWebSocketProtocol) {
32
- var _a12;
33
- const encoded = (_a12 = findProtocol(
31
+ const encoded = findProtocol(
34
32
  secWebSocketProtocol,
35
33
  GATEWAY_TEAM_SUBPROTOCOL_PREFIX
36
- )) == null ? void 0 : _a12.slice(GATEWAY_TEAM_SUBPROTOCOL_PREFIX.length);
34
+ )?.slice(GATEWAY_TEAM_SUBPROTOCOL_PREFIX.length);
37
35
  if (!encoded) return void 0;
38
36
  try {
39
37
  return decodeSubprotocolValue(encoded) || void 0;
40
- } catch (e) {
38
+ } catch {
41
39
  return void 0;
42
40
  }
43
41
  }
44
42
  function findProtocol(secWebSocketProtocol, prefix) {
45
- return secWebSocketProtocol == null ? void 0 : secWebSocketProtocol.split(",").map((protocol) => protocol.trim()).find((protocol) => protocol.startsWith(prefix));
43
+ return secWebSocketProtocol?.split(",").map((protocol) => protocol.trim()).find((protocol) => protocol.startsWith(prefix));
46
44
  }
47
45
  function encodeSubprotocolValue(value) {
48
46
  const bytes = new TextEncoder().encode(value);
@@ -430,7 +428,6 @@ async function createGatewayErrorFromResponse({
430
428
  authMethod,
431
429
  isRetryable
432
430
  }) {
433
- var _a12;
434
431
  const parseResult = await safeValidateTypes({
435
432
  value: response,
436
433
  schema: gatewayErrorResponseSchema
@@ -450,7 +447,7 @@ async function createGatewayErrorFromResponse({
450
447
  const validatedResponse = parseResult.value;
451
448
  const errorType = validatedResponse.error.type;
452
449
  const message = validatedResponse.error.message;
453
- const generationId = (_a12 = validatedResponse.generationId) != null ? _a12 : void 0;
450
+ const generationId = validatedResponse.generationId ?? void 0;
454
451
  switch (errorType) {
455
452
  case "authentication_error":
456
453
  return GatewayAuthenticationError.createContextualError({
@@ -553,7 +550,7 @@ function extractApiCallResponse(error) {
553
550
  if (error.responseBody != null) {
554
551
  try {
555
552
  return secureJsonParse(error.responseBody);
556
- } catch (e) {
553
+ } catch {
557
554
  return error.responseBody;
558
555
  }
559
556
  }
@@ -619,7 +616,6 @@ function isTimeoutError(error) {
619
616
  return false;
620
617
  }
621
618
  async function asGatewayError(error, authMethod) {
622
- var _a12;
623
619
  if (GatewayError.isInstance(error)) {
624
620
  return error;
625
621
  }
@@ -638,7 +634,7 @@ async function asGatewayError(error, authMethod) {
638
634
  }
639
635
  return await createGatewayErrorFromResponse({
640
636
  response: extractApiCallResponse(error),
641
- statusCode: (_a12 = error.statusCode) != null ? _a12 : 500,
637
+ statusCode: error.statusCode ?? 500,
642
638
  defaultMessage: "Gateway request failed",
643
639
  cause: error,
644
640
  authMethod,
@@ -715,10 +711,7 @@ var GatewayFetchMetadata = class {
715
711
  ),
716
712
  failedResponseHandler: createJsonErrorResponseHandler({
717
713
  errorSchema: z.any(),
718
- errorToMessage: (data) => {
719
- var _a12;
720
- return (_a12 = getErrorMessage(data)) != null ? _a12 : "unknown error";
721
- }
714
+ errorToMessage: (data) => getErrorMessage(data) ?? "unknown error"
722
715
  }),
723
716
  fetch: this.config.fetch
724
717
  });
@@ -739,10 +732,7 @@ var GatewayFetchMetadata = class {
739
732
  ),
740
733
  failedResponseHandler: createJsonErrorResponseHandler({
741
734
  errorSchema: z.any(),
742
- errorToMessage: (data) => {
743
- var _a12;
744
- return (_a12 = getErrorMessage(data)) != null ? _a12 : "unknown error";
745
- }
735
+ errorToMessage: (data) => getErrorMessage(data) ?? "unknown error"
746
736
  }),
747
737
  fetch: this.config.fetch
748
738
  });
@@ -850,10 +840,7 @@ var GatewaySpendReport = class {
850
840
  ),
851
841
  failedResponseHandler: createJsonErrorResponseHandler2({
852
842
  errorSchema: z.any(),
853
- errorToMessage: (data) => {
854
- var _a12;
855
- return (_a12 = getErrorMessage2(data)) != null ? _a12 : "unknown error";
856
- }
843
+ errorToMessage: (data) => getErrorMessage2(data) ?? "unknown error"
857
844
  }),
858
845
  fetch: this.config.fetch
859
846
  });
@@ -939,10 +926,7 @@ var GatewayGenerationInfoFetcher = class {
939
926
  ),
940
927
  failedResponseHandler: createJsonErrorResponseHandler3({
941
928
  errorSchema: z.any(),
942
- errorToMessage: (data) => {
943
- var _a12;
944
- return (_a12 = getErrorMessage3(data)) != null ? _a12 : "unknown error";
945
- }
929
+ errorToMessage: (data) => getErrorMessage3(data) ?? "unknown error"
946
930
  }),
947
931
  fetch: this.config.fetch
948
932
  });
@@ -1048,7 +1032,6 @@ var GatewayBatch = class {
1048
1032
  abortSignal,
1049
1033
  webhookUrl
1050
1034
  }) {
1051
- var _a12;
1052
1035
  assertTextBatchRequests(requests);
1053
1036
  const modelId = validateSingleModel(requests);
1054
1037
  const resolvedHeaders = this.config.headers ? await resolve4(this.config.headers) : void 0;
@@ -1081,10 +1064,7 @@ var GatewayBatch = class {
1081
1064
  ),
1082
1065
  failedResponseHandler: createJsonErrorResponseHandler4({
1083
1066
  errorSchema: z.any(),
1084
- errorToMessage: (data) => {
1085
- var _a13;
1086
- return (_a13 = getErrorMessage4(data)) != null ? _a13 : "unknown error";
1087
- }
1067
+ errorToMessage: (data) => getErrorMessage4(data) ?? "unknown error"
1088
1068
  }),
1089
1069
  ...abortSignal && { abortSignal },
1090
1070
  fetch: this.config.fetch
@@ -1092,7 +1072,7 @@ var GatewayBatch = class {
1092
1072
  return {
1093
1073
  batchId: responseBody.batchId,
1094
1074
  ...convertGatewayBatchStatus(responseBody),
1095
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : []
1075
+ warnings: responseBody.warnings ?? []
1096
1076
  };
1097
1077
  } catch (error) {
1098
1078
  if (isAbortOrTimeoutError(error)) {
@@ -1100,7 +1080,7 @@ var GatewayBatch = class {
1100
1080
  }
1101
1081
  throw await asGatewayError(
1102
1082
  error,
1103
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1083
+ await parseAuthMethod(resolvedHeaders ?? {})
1104
1084
  );
1105
1085
  }
1106
1086
  }
@@ -1128,10 +1108,7 @@ var GatewayBatch = class {
1128
1108
  ),
1129
1109
  failedResponseHandler: createJsonErrorResponseHandler4({
1130
1110
  errorSchema: z.any(),
1131
- errorToMessage: (data) => {
1132
- var _a12;
1133
- return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1134
- }
1111
+ errorToMessage: (data) => getErrorMessage4(data) ?? "unknown error"
1135
1112
  }),
1136
1113
  ...abortSignal && { abortSignal },
1137
1114
  fetch: this.config.fetch
@@ -1143,7 +1120,7 @@ var GatewayBatch = class {
1143
1120
  }
1144
1121
  throw await asGatewayError(
1145
1122
  error,
1146
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1123
+ await parseAuthMethod(resolvedHeaders ?? {})
1147
1124
  );
1148
1125
  }
1149
1126
  }
@@ -1174,10 +1151,7 @@ var GatewayBatch = class {
1174
1151
  ),
1175
1152
  failedResponseHandler: createJsonErrorResponseHandler4({
1176
1153
  errorSchema: z.any(),
1177
- errorToMessage: (data) => {
1178
- var _a12;
1179
- return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1180
- }
1154
+ errorToMessage: (data) => getErrorMessage4(data) ?? "unknown error"
1181
1155
  }),
1182
1156
  ...abortSignal && { abortSignal },
1183
1157
  fetch: this.config.fetch
@@ -1191,7 +1165,7 @@ var GatewayBatch = class {
1191
1165
  }
1192
1166
  throw await asGatewayError(
1193
1167
  error,
1194
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1168
+ await parseAuthMethod(resolvedHeaders ?? {})
1195
1169
  );
1196
1170
  }
1197
1171
  }
@@ -1216,10 +1190,7 @@ var GatewayBatch = class {
1216
1190
  ),
1217
1191
  failedResponseHandler: createJsonErrorResponseHandler4({
1218
1192
  errorSchema: z.any(),
1219
- errorToMessage: (data) => {
1220
- var _a12;
1221
- return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1222
- }
1193
+ errorToMessage: (data) => getErrorMessage4(data) ?? "unknown error"
1223
1194
  }),
1224
1195
  ...abortSignal && { abortSignal },
1225
1196
  fetch: this.config.fetch
@@ -1235,7 +1206,7 @@ var GatewayBatch = class {
1235
1206
  }
1236
1207
  throw await asGatewayError(
1237
1208
  error,
1238
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1209
+ await parseAuthMethod(resolvedHeaders ?? {})
1239
1210
  );
1240
1211
  }
1241
1212
  }
@@ -1272,8 +1243,7 @@ function maybeBase64EncodeFileData(data) {
1272
1243
  return data;
1273
1244
  }
1274
1245
  function validateSingleModel(requests) {
1275
- var _a12;
1276
- const modelId = (_a12 = requests[0]) == null ? void 0 : _a12.modelId;
1246
+ const modelId = requests[0]?.modelId;
1277
1247
  if (modelId == null) {
1278
1248
  throw new InvalidArgumentError({
1279
1249
  argument: "requests",
@@ -1302,7 +1272,7 @@ function assertTextBatchRequests(requests) {
1302
1272
  }
1303
1273
  }
1304
1274
  function getGatewayBatchIdempotencyKey(providerOptions) {
1305
- const gatewayOptions = providerOptions == null ? void 0 : providerOptions.gateway;
1275
+ const gatewayOptions = providerOptions?.gateway;
1306
1276
  if (gatewayOptions == null || typeof gatewayOptions !== "object" || Array.isArray(gatewayOptions)) {
1307
1277
  return void 0;
1308
1278
  }
@@ -1310,7 +1280,7 @@ function getGatewayBatchIdempotencyKey(providerOptions) {
1310
1280
  return typeof key === "string" && key.length > 0 ? key : void 0;
1311
1281
  }
1312
1282
  function omitGatewayIdempotencyKey(providerOptions) {
1313
- const gatewayOptions = providerOptions == null ? void 0 : providerOptions.gateway;
1283
+ const gatewayOptions = providerOptions?.gateway;
1314
1284
  if (gatewayOptions == null || typeof gatewayOptions !== "object" || Array.isArray(gatewayOptions) || !("idempotencyKey" in gatewayOptions)) {
1315
1285
  return providerOptions;
1316
1286
  }
@@ -1333,12 +1303,11 @@ function isAbortOrTimeoutError(error) {
1333
1303
  return error.name === "AbortError" || error.name === "TimeoutError";
1334
1304
  }
1335
1305
  function convertGatewayBatchStatus(body) {
1336
- var _a12, _b12, _c, _d;
1337
1306
  const requestCounts = normalizeBatchRequestCounts({
1338
- total: (_a12 = body.requestCounts) == null ? void 0 : _a12.total,
1339
- pending: (_b12 = body.requestCounts) == null ? void 0 : _b12.pending,
1340
- completed: (_c = body.requestCounts) == null ? void 0 : _c.completed,
1341
- failed: (_d = body.requestCounts) == null ? void 0 : _d.failed
1307
+ total: body.requestCounts?.total,
1308
+ pending: body.requestCounts?.pending,
1309
+ completed: body.requestCounts?.completed,
1310
+ failed: body.requestCounts?.failed
1342
1311
  });
1343
1312
  return {
1344
1313
  status: body.status,
@@ -1362,11 +1331,10 @@ function convertGatewayBatchStatus(body) {
1362
1331
  };
1363
1332
  }
1364
1333
  async function* convertGatewayBatchResultLines(lines) {
1365
- var _a12;
1366
1334
  for await (const line of lines) {
1367
1335
  const item = line;
1368
1336
  if (item.status === "succeeded") {
1369
- const response = (_a12 = item.result) == null ? void 0 : _a12.response;
1337
+ const response = item.result?.response;
1370
1338
  if (response !== void 0 && typeof response.timestamp === "string") {
1371
1339
  response.timestamp = new Date(response.timestamp);
1372
1340
  }
@@ -1455,7 +1423,6 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
1455
1423
  };
1456
1424
  }
1457
1425
  async doGenerate(options) {
1458
- var _a12;
1459
1426
  const { args, warnings } = await this.getArgs(options);
1460
1427
  const { abortSignal } = options;
1461
1428
  const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
@@ -1476,10 +1443,7 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
1476
1443
  successfulResponseHandler: createJsonResponseHandler5(z.any()),
1477
1444
  failedResponseHandler: createJsonErrorResponseHandler5({
1478
1445
  errorSchema: z.any(),
1479
- errorToMessage: (data) => {
1480
- var _a13;
1481
- return (_a13 = getErrorMessage5(data)) != null ? _a13 : "unknown error";
1482
- }
1446
+ errorToMessage: (data) => getErrorMessage5(data) ?? "unknown error"
1483
1447
  }),
1484
1448
  ...abortSignal && { abortSignal },
1485
1449
  fetch: this.config.fetch
@@ -1488,12 +1452,12 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
1488
1452
  ...responseBody,
1489
1453
  request: { body: args },
1490
1454
  response: { headers: responseHeaders, body: rawResponse },
1491
- warnings: [...(_a12 = responseBody.warnings) != null ? _a12 : [], ...warnings]
1455
+ warnings: [...responseBody.warnings ?? [], ...warnings]
1492
1456
  };
1493
1457
  } catch (error) {
1494
1458
  throw await asGatewayError(
1495
1459
  error,
1496
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1460
+ await parseAuthMethod(resolvedHeaders ?? {})
1497
1461
  );
1498
1462
  }
1499
1463
  }
@@ -1514,10 +1478,7 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
1514
1478
  successfulResponseHandler: createEventSourceResponseHandler(z.any()),
1515
1479
  failedResponseHandler: createJsonErrorResponseHandler5({
1516
1480
  errorSchema: z.any(),
1517
- errorToMessage: (data) => {
1518
- var _a12;
1519
- return (_a12 = getErrorMessage5(data)) != null ? _a12 : "unknown error";
1520
- }
1481
+ errorToMessage: (data) => getErrorMessage5(data) ?? "unknown error"
1521
1482
  }),
1522
1483
  ...abortSignal && { abortSignal },
1523
1484
  fetch: this.config.fetch
@@ -1554,7 +1515,7 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
1554
1515
  } catch (error) {
1555
1516
  throw await asGatewayError(
1556
1517
  error,
1557
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1518
+ await parseAuthMethod(resolvedHeaders ?? {})
1558
1519
  );
1559
1520
  }
1560
1521
  }
@@ -1643,7 +1604,6 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1643
1604
  abortSignal,
1644
1605
  providerOptions
1645
1606
  }) {
1646
- var _a12, _b12;
1647
1607
  const resolvedHeaders = this.config.headers ? await resolve6(this.config.headers) : void 0;
1648
1608
  try {
1649
1609
  const {
@@ -1654,7 +1614,7 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1654
1614
  url: this.getUrl(),
1655
1615
  headers: combineHeaders3(
1656
1616
  resolvedHeaders,
1657
- headers != null ? headers : {},
1617
+ headers ?? {},
1658
1618
  this.getModelConfigHeaders(),
1659
1619
  await resolve6(this.config.o11yHeaders)
1660
1620
  ),
@@ -1667,25 +1627,22 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1667
1627
  ),
1668
1628
  failedResponseHandler: createJsonErrorResponseHandler6({
1669
1629
  errorSchema: z.any(),
1670
- errorToMessage: (data) => {
1671
- var _a13;
1672
- return (_a13 = getErrorMessage6(data)) != null ? _a13 : "unknown error";
1673
- }
1630
+ errorToMessage: (data) => getErrorMessage6(data) ?? "unknown error"
1674
1631
  }),
1675
1632
  ...abortSignal && { abortSignal },
1676
1633
  fetch: this.config.fetch
1677
1634
  });
1678
1635
  return {
1679
1636
  embeddings: responseBody.embeddings,
1680
- usage: (_a12 = responseBody.usage) != null ? _a12 : void 0,
1637
+ usage: responseBody.usage ?? void 0,
1681
1638
  providerMetadata: responseBody.providerMetadata,
1682
1639
  response: { headers: responseHeaders, body: rawValue },
1683
- warnings: (_b12 = responseBody.warnings) != null ? _b12 : []
1640
+ warnings: responseBody.warnings ?? []
1684
1641
  };
1685
1642
  } catch (error) {
1686
1643
  throw await asGatewayError(
1687
1644
  error,
1688
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1645
+ await parseAuthMethod(resolvedHeaders ?? {})
1689
1646
  );
1690
1647
  }
1691
1648
  }
@@ -1776,14 +1733,13 @@ var GatewayImageModel = class _GatewayImageModel {
1776
1733
  headers,
1777
1734
  abortSignal
1778
1735
  }) {
1779
- var _a12, _b12, _c, _d;
1780
1736
  const resolvedHeaders = this.config.headers ? await resolve7(this.config.headers) : void 0;
1781
1737
  try {
1782
1738
  const { responseHeaders, value: responseBody } = await postJsonToApi4({
1783
1739
  url: this.getUrl(),
1784
1740
  headers: combineHeaders4(
1785
1741
  resolvedHeaders,
1786
- headers != null ? headers : {},
1742
+ headers ?? {},
1787
1743
  this.getModelConfigHeaders(),
1788
1744
  await resolve7(this.config.o11yHeaders)
1789
1745
  ),
@@ -1804,10 +1760,7 @@ var GatewayImageModel = class _GatewayImageModel {
1804
1760
  ),
1805
1761
  failedResponseHandler: createJsonErrorResponseHandler7({
1806
1762
  errorSchema: z.any(),
1807
- errorToMessage: (data) => {
1808
- var _a13;
1809
- return (_a13 = getErrorMessage7(data)) != null ? _a13 : "unknown error";
1810
- }
1763
+ errorToMessage: (data) => getErrorMessage7(data) ?? "unknown error"
1811
1764
  }),
1812
1765
  ...abortSignal && { abortSignal },
1813
1766
  fetch: this.config.fetch
@@ -1818,7 +1771,7 @@ var GatewayImageModel = class _GatewayImageModel {
1818
1771
  ...responseBody.isRetryable != null && {
1819
1772
  isRetryable: responseBody.isRetryable
1820
1773
  },
1821
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : [],
1774
+ warnings: responseBody.warnings ?? [],
1822
1775
  providerMetadata: responseBody.providerMetadata,
1823
1776
  response: {
1824
1777
  timestamp: /* @__PURE__ */ new Date(),
@@ -1827,16 +1780,16 @@ var GatewayImageModel = class _GatewayImageModel {
1827
1780
  },
1828
1781
  ...responseBody.usage != null && {
1829
1782
  usage: {
1830
- inputTokens: (_b12 = responseBody.usage.inputTokens) != null ? _b12 : void 0,
1831
- outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
1832
- totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
1783
+ inputTokens: responseBody.usage.inputTokens ?? void 0,
1784
+ outputTokens: responseBody.usage.outputTokens ?? void 0,
1785
+ totalTokens: responseBody.usage.totalTokens ?? void 0
1833
1786
  }
1834
1787
  }
1835
1788
  };
1836
1789
  } catch (error) {
1837
1790
  throw await asGatewayError(
1838
1791
  error,
1839
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1792
+ await parseAuthMethod(resolvedHeaders ?? {})
1840
1793
  );
1841
1794
  }
1842
1795
  }
@@ -1923,7 +1876,6 @@ var GatewayVideoModel = class {
1923
1876
  return this.config.provider;
1924
1877
  }
1925
1878
  async doGenerate(options) {
1926
- var _a12, _b12;
1927
1879
  const { headers, abortSignal } = options;
1928
1880
  const resolvedHeaders = this.config.headers ? await resolve8(this.config.headers) : void 0;
1929
1881
  try {
@@ -1931,7 +1883,7 @@ var GatewayVideoModel = class {
1931
1883
  url: this.getUrl(),
1932
1884
  headers: combineHeaders5(
1933
1885
  resolvedHeaders,
1934
- headers != null ? headers : {},
1886
+ headers ?? {},
1935
1887
  this.getModelConfigHeaders(),
1936
1888
  await resolve8(this.config.o11yHeaders),
1937
1889
  { accept: "text/event-stream" }
@@ -2003,18 +1955,15 @@ var GatewayVideoModel = class {
2003
1955
  },
2004
1956
  failedResponseHandler: createJsonErrorResponseHandler8({
2005
1957
  errorSchema: z.any(),
2006
- errorToMessage: (data) => {
2007
- var _a13;
2008
- return (_a13 = getErrorMessage8(data)) != null ? _a13 : "unknown error";
2009
- }
1958
+ errorToMessage: (data) => getErrorMessage8(data) ?? "unknown error"
2010
1959
  }),
2011
1960
  ...abortSignal && { abortSignal },
2012
1961
  fetch: this.config.fetch
2013
1962
  });
2014
1963
  return {
2015
1964
  videos: responseBody.videos,
2016
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : [],
2017
- providerMetadata: (_b12 = responseBody.providerMetadata) != null ? _b12 : void 0,
1965
+ warnings: responseBody.warnings ?? [],
1966
+ providerMetadata: responseBody.providerMetadata ?? void 0,
2018
1967
  response: {
2019
1968
  timestamp: /* @__PURE__ */ new Date(),
2020
1969
  modelId: this.modelId,
@@ -2024,7 +1973,7 @@ var GatewayVideoModel = class {
2024
1973
  } catch (error) {
2025
1974
  throw await asGatewayError(
2026
1975
  error,
2027
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1976
+ await parseAuthMethod(resolvedHeaders ?? {})
2028
1977
  );
2029
1978
  }
2030
1979
  }
@@ -2037,7 +1986,6 @@ var GatewayVideoModel = class {
2037
1986
  return { webhookUrl: url, received };
2038
1987
  }
2039
1988
  async doStart(options) {
2040
- var _a12, _b12;
2041
1989
  const { headers, abortSignal, webhookUrl } = options;
2042
1990
  const resolvedHeaders = this.config.headers ? await resolve8(this.config.headers) : void 0;
2043
1991
  try {
@@ -2045,7 +1993,7 @@ var GatewayVideoModel = class {
2045
1993
  url: this.getStartUrl(),
2046
1994
  headers: combineHeaders5(
2047
1995
  resolvedHeaders,
2048
- headers != null ? headers : {},
1996
+ headers ?? {},
2049
1997
  this.getModelConfigHeaders(),
2050
1998
  await resolve8(this.config.o11yHeaders)
2051
1999
  ),
@@ -2060,18 +2008,15 @@ var GatewayVideoModel = class {
2060
2008
  ),
2061
2009
  failedResponseHandler: createJsonErrorResponseHandler8({
2062
2010
  errorSchema: z.any(),
2063
- errorToMessage: (data) => {
2064
- var _a13;
2065
- return (_a13 = getErrorMessage8(data)) != null ? _a13 : "unknown error";
2066
- }
2011
+ errorToMessage: (data) => getErrorMessage8(data) ?? "unknown error"
2067
2012
  }),
2068
2013
  ...abortSignal && { abortSignal },
2069
2014
  fetch: this.config.fetch
2070
2015
  });
2071
2016
  return {
2072
2017
  operation: responseBody.operation,
2073
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : [],
2074
- providerMetadata: (_b12 = responseBody.providerMetadata) != null ? _b12 : void 0,
2018
+ warnings: responseBody.warnings ?? [],
2019
+ providerMetadata: responseBody.providerMetadata ?? void 0,
2075
2020
  response: {
2076
2021
  timestamp: /* @__PURE__ */ new Date(),
2077
2022
  modelId: this.modelId,
@@ -2081,7 +2026,7 @@ var GatewayVideoModel = class {
2081
2026
  } catch (error) {
2082
2027
  throw await asGatewayError(
2083
2028
  error,
2084
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
2029
+ await parseAuthMethod(resolvedHeaders ?? {})
2085
2030
  );
2086
2031
  }
2087
2032
  }
@@ -2090,14 +2035,13 @@ var GatewayVideoModel = class {
2090
2035
  abortSignal,
2091
2036
  headers
2092
2037
  }) {
2093
- var _a12, _b12, _c, _d, _e, _f;
2094
2038
  const resolvedHeaders = this.config.headers ? await resolve8(this.config.headers) : void 0;
2095
2039
  try {
2096
2040
  const { responseHeaders, value: responseBody } = await postJsonToApi5({
2097
2041
  url: this.getStatusUrl(),
2098
2042
  headers: combineHeaders5(
2099
2043
  resolvedHeaders,
2100
- headers != null ? headers : {},
2044
+ headers ?? {},
2101
2045
  this.getModelConfigHeaders(),
2102
2046
  await resolve8(this.config.o11yHeaders)
2103
2047
  ),
@@ -2107,10 +2051,7 @@ var GatewayVideoModel = class {
2107
2051
  ),
2108
2052
  failedResponseHandler: createJsonErrorResponseHandler8({
2109
2053
  errorSchema: z.any(),
2110
- errorToMessage: (data) => {
2111
- var _a13;
2112
- return (_a13 = getErrorMessage8(data)) != null ? _a13 : "unknown error";
2113
- }
2054
+ errorToMessage: (data) => getErrorMessage8(data) ?? "unknown error"
2114
2055
  }),
2115
2056
  ...abortSignal && { abortSignal },
2116
2057
  fetch: this.config.fetch
@@ -2124,8 +2065,8 @@ var GatewayVideoModel = class {
2124
2065
  return {
2125
2066
  status: "completed",
2126
2067
  videos: responseBody.videos,
2127
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : [],
2128
- providerMetadata: (_b12 = responseBody.providerMetadata) != null ? _b12 : void 0,
2068
+ warnings: responseBody.warnings ?? [],
2069
+ providerMetadata: responseBody.providerMetadata ?? void 0,
2129
2070
  response
2130
2071
  };
2131
2072
  }
@@ -2133,7 +2074,7 @@ var GatewayVideoModel = class {
2133
2074
  return {
2134
2075
  status: "error",
2135
2076
  error: responseBody.error,
2136
- providerMetadata: (_c = responseBody.providerMetadata) != null ? _c : void 0,
2077
+ providerMetadata: responseBody.providerMetadata ?? void 0,
2137
2078
  response
2138
2079
  };
2139
2080
  }
@@ -2141,20 +2082,20 @@ var GatewayVideoModel = class {
2141
2082
  return {
2142
2083
  status: "error",
2143
2084
  error: "Video generation was cancelled.",
2144
- providerMetadata: (_d = responseBody.providerMetadata) != null ? _d : void 0,
2085
+ providerMetadata: responseBody.providerMetadata ?? void 0,
2145
2086
  response
2146
2087
  };
2147
2088
  }
2148
2089
  return {
2149
2090
  status: "pending",
2150
- warnings: (_e = responseBody.warnings) != null ? _e : [],
2151
- providerMetadata: (_f = responseBody.providerMetadata) != null ? _f : void 0,
2091
+ warnings: responseBody.warnings ?? [],
2092
+ providerMetadata: responseBody.providerMetadata ?? void 0,
2152
2093
  response
2153
2094
  };
2154
2095
  } catch (error) {
2155
2096
  throw await asGatewayError(
2156
2097
  error,
2157
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
2098
+ await parseAuthMethod(resolvedHeaders ?? {})
2158
2099
  );
2159
2100
  }
2160
2101
  }
@@ -2306,11 +2247,98 @@ import {
2306
2247
  createJsonErrorResponseHandler as createJsonErrorResponseHandler9,
2307
2248
  createJsonResponseHandler as createJsonResponseHandler9,
2308
2249
  getErrorMessage as getErrorMessage9,
2309
- lazySchema as lazySchema9,
2250
+ lazySchema as lazySchema10,
2251
+ parseProviderOptions,
2310
2252
  postJsonToApi as postJsonToApi6,
2311
2253
  resolve as resolve9,
2312
- zodSchema as zodSchema9
2254
+ zodSchema as zodSchema10
2313
2255
  } from "@ai-sdk/provider-utils";
2256
+
2257
+ // src/gateway-provider-options.ts
2258
+ import { lazySchema as lazySchema9, zodSchema as zodSchema9 } from "@ai-sdk/provider-utils";
2259
+ var EVALUATION_FALLBACK_MAX_CONDITION_DEPTH = 5;
2260
+ var EVALUATION_FALLBACK_MAX_CONDITIONS_PER_LIST = 20;
2261
+ var EVALUATION_FALLBACK_MAX_QUESTION_LENGTH = 256;
2262
+ var EVALUATION_FALLBACK_MAX_MODEL_LENGTH = 256;
2263
+ var gatewayEvaluationProviderOptionsSchema = lazySchema9(
2264
+ () => zodSchema9(
2265
+ z.object({
2266
+ models: gatewayModelFallbacksSchema.optional()
2267
+ }).catchall(z.unknown())
2268
+ )
2269
+ );
2270
+ var probabilitySchema = z.number().finite().min(0).max(1);
2271
+ var questionSchema = z.string().min(1).max(EVALUATION_FALLBACK_MAX_QUESTION_LENGTH);
2272
+ var directConditionSchema = z.union([
2273
+ z.object({
2274
+ question: questionSchema,
2275
+ confidenceBelow: probabilitySchema
2276
+ }).strict(),
2277
+ z.object({
2278
+ question: questionSchema,
2279
+ probabilityBetween: z.array(probabilitySchema).length(2).refine(([minimum, maximum]) => minimum <= maximum, {
2280
+ message: "probabilityBetween minimum must be less than or equal to maximum"
2281
+ })
2282
+ }).strict()
2283
+ ]);
2284
+ var groupBeyondMaxDepthSchema = z.union([
2285
+ z.object({ any: z.unknown() }),
2286
+ z.object({ all: z.unknown() }),
2287
+ z.object({ atLeast: z.unknown() })
2288
+ ]).superRefine((_, context) => {
2289
+ context.addIssue({
2290
+ code: "custom",
2291
+ message: `conditions can be nested at most ${EVALUATION_FALLBACK_MAX_CONDITION_DEPTH} levels deep`
2292
+ });
2293
+ });
2294
+ var conditionalModelFallbackSchema = z.object({
2295
+ model: z.string().min(1).max(EVALUATION_FALLBACK_MAX_MODEL_LENGTH),
2296
+ when: conditionSchema(1)
2297
+ }).strict();
2298
+ var gatewayModelFallbacksSchema = z.array(z.union([z.string(), conditionalModelFallbackSchema])).superRefine((entries, context) => {
2299
+ const conditionalIndexes = entries.flatMap(
2300
+ (entry, index) => typeof entry === "string" ? [] : [index]
2301
+ );
2302
+ if (conditionalIndexes.length > 1) {
2303
+ context.addIssue({
2304
+ code: "custom",
2305
+ message: "models supports at most one conditional evaluation fallback"
2306
+ });
2307
+ }
2308
+ if (conditionalIndexes[0] !== void 0 && conditionalIndexes[0] !== 0) {
2309
+ context.addIssue({
2310
+ code: "custom",
2311
+ message: "a conditional evaluation fallback must be the first models entry",
2312
+ path: [conditionalIndexes[0]]
2313
+ });
2314
+ }
2315
+ });
2316
+ function conditionSchema(depth) {
2317
+ if (depth === EVALUATION_FALLBACK_MAX_CONDITION_DEPTH) {
2318
+ return z.union([
2319
+ directConditionSchema,
2320
+ groupBeyondMaxDepthSchema
2321
+ ]);
2322
+ }
2323
+ const childConditionSchema = conditionSchema(depth + 1);
2324
+ const conditionListSchema = z.array(childConditionSchema).min(1).max(EVALUATION_FALLBACK_MAX_CONDITIONS_PER_LIST);
2325
+ return z.union([
2326
+ directConditionSchema,
2327
+ z.object({ any: conditionListSchema }).strict(),
2328
+ z.object({ all: conditionListSchema }).strict(),
2329
+ z.object({
2330
+ atLeast: z.object({
2331
+ count: z.number().int().min(1),
2332
+ conditions: conditionListSchema
2333
+ }).strict().refine(({ count, conditions }) => count <= conditions.length, {
2334
+ message: "atLeast count cannot exceed the number of conditions",
2335
+ path: ["count"]
2336
+ })
2337
+ }).strict()
2338
+ ]);
2339
+ }
2340
+
2341
+ // src/gateway-evaluation-model.ts
2314
2342
  var GatewayEvaluationModel = class {
2315
2343
  constructor(modelId, config) {
2316
2344
  this.modelId = modelId;
@@ -2328,7 +2356,12 @@ var GatewayEvaluationModel = class {
2328
2356
  abortSignal,
2329
2357
  providerOptions
2330
2358
  }) {
2331
- var _a12;
2359
+ const gatewayOptions = await parseProviderOptions({
2360
+ provider: "gateway",
2361
+ providerOptions,
2362
+ schema: gatewayEvaluationProviderOptionsSchema
2363
+ });
2364
+ const validatedProviderOptions = gatewayOptions == null ? providerOptions : { ...providerOptions, gateway: gatewayOptions };
2332
2365
  const resolvedHeaders = this.config.headers ? await resolve9(this.config.headers) : void 0;
2333
2366
  try {
2334
2367
  const {
@@ -2339,24 +2372,21 @@ var GatewayEvaluationModel = class {
2339
2372
  url: this.getUrl(),
2340
2373
  headers: combineHeaders6(
2341
2374
  resolvedHeaders,
2342
- headers != null ? headers : {},
2375
+ headers ?? {},
2343
2376
  this.getModelConfigHeaders(),
2344
2377
  await resolve9(this.config.o11yHeaders)
2345
2378
  ),
2346
2379
  body: {
2347
2380
  state,
2348
2381
  questions,
2349
- ...providerOptions ? { providerOptions } : {}
2382
+ ...validatedProviderOptions ? { providerOptions: validatedProviderOptions } : {}
2350
2383
  },
2351
2384
  successfulResponseHandler: createJsonResponseHandler9(
2352
2385
  gatewayEvaluationResponseSchema
2353
2386
  ),
2354
2387
  failedResponseHandler: createJsonErrorResponseHandler9({
2355
2388
  errorSchema: z.any(),
2356
- errorToMessage: (data) => {
2357
- var _a13;
2358
- return (_a13 = getErrorMessage9(data)) != null ? _a13 : "unknown error";
2359
- }
2389
+ errorToMessage: (data) => getErrorMessage9(data) ?? "unknown error"
2360
2390
  }),
2361
2391
  ...abortSignal && { abortSignal },
2362
2392
  fetch: this.config.fetch
@@ -2365,10 +2395,10 @@ var GatewayEvaluationModel = class {
2365
2395
  answers: responseBody.answers,
2366
2396
  ...responseBody.rounding ? { rounding: responseBody.rounding } : {},
2367
2397
  ...responseBody.usage ? { usage: responseBody.usage } : {},
2368
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : [],
2398
+ warnings: responseBody.warnings ?? [],
2369
2399
  providerMetadata: responseBody.providerMetadata,
2370
2400
  response: {
2371
- modelId: this.modelId,
2401
+ modelId: responseBody.model ?? this.modelId,
2372
2402
  headers: responseHeaders,
2373
2403
  body: rawValue
2374
2404
  }
@@ -2376,7 +2406,7 @@ var GatewayEvaluationModel = class {
2376
2406
  } catch (error) {
2377
2407
  throw await asGatewayError(
2378
2408
  error,
2379
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
2409
+ await parseAuthMethod(resolvedHeaders ?? {})
2380
2410
  );
2381
2411
  }
2382
2412
  }
@@ -2427,10 +2457,11 @@ var gatewayEvaluationWarningSchema = z.discriminatedUnion("type", [
2427
2457
  message: z.string()
2428
2458
  })
2429
2459
  ]);
2430
- var gatewayEvaluationResponseSchema = lazySchema9(
2431
- () => zodSchema9(
2460
+ var gatewayEvaluationResponseSchema = lazySchema10(
2461
+ () => zodSchema10(
2432
2462
  z.object({
2433
2463
  answers: z.record(z.string(), gatewayEvaluationAnswerSchema),
2464
+ model: z.string().optional(),
2434
2465
  rounding: z.object({
2435
2466
  probabilityDecimals: z.number().optional(),
2436
2467
  scoreDecimals: z.number().optional()
@@ -2451,10 +2482,10 @@ import {
2451
2482
  createJsonErrorResponseHandler as createJsonErrorResponseHandler10,
2452
2483
  createJsonResponseHandler as createJsonResponseHandler10,
2453
2484
  getErrorMessage as getErrorMessage10,
2454
- lazySchema as lazySchema10,
2485
+ lazySchema as lazySchema11,
2455
2486
  postJsonToApi as postJsonToApi7,
2456
2487
  resolve as resolve10,
2457
- zodSchema as zodSchema10
2488
+ zodSchema as zodSchema11
2458
2489
  } from "@ai-sdk/provider-utils";
2459
2490
  var GatewayRerankingModel = class {
2460
2491
  constructor(modelId, config) {
@@ -2473,7 +2504,6 @@ var GatewayRerankingModel = class {
2473
2504
  abortSignal,
2474
2505
  providerOptions
2475
2506
  }) {
2476
- var _a12;
2477
2507
  const resolvedHeaders = this.config.headers ? await resolve10(this.config.headers) : void 0;
2478
2508
  try {
2479
2509
  const {
@@ -2484,7 +2514,7 @@ var GatewayRerankingModel = class {
2484
2514
  url: this.getUrl(),
2485
2515
  headers: combineHeaders7(
2486
2516
  resolvedHeaders,
2487
- headers != null ? headers : {},
2517
+ headers ?? {},
2488
2518
  this.getModelConfigHeaders(),
2489
2519
  await resolve10(this.config.o11yHeaders)
2490
2520
  ),
@@ -2499,10 +2529,7 @@ var GatewayRerankingModel = class {
2499
2529
  ),
2500
2530
  failedResponseHandler: createJsonErrorResponseHandler10({
2501
2531
  errorSchema: z.any(),
2502
- errorToMessage: (data) => {
2503
- var _a13;
2504
- return (_a13 = getErrorMessage10(data)) != null ? _a13 : "unknown error";
2505
- }
2532
+ errorToMessage: (data) => getErrorMessage10(data) ?? "unknown error"
2506
2533
  }),
2507
2534
  ...abortSignal && { abortSignal },
2508
2535
  fetch: this.config.fetch
@@ -2511,12 +2538,12 @@ var GatewayRerankingModel = class {
2511
2538
  ranking: responseBody.ranking,
2512
2539
  providerMetadata: responseBody.providerMetadata,
2513
2540
  response: { headers: responseHeaders, body: rawValue },
2514
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : []
2541
+ warnings: responseBody.warnings ?? []
2515
2542
  };
2516
2543
  } catch (error) {
2517
2544
  throw await asGatewayError(
2518
2545
  error,
2519
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
2546
+ await parseAuthMethod(resolvedHeaders ?? {})
2520
2547
  );
2521
2548
  }
2522
2549
  }
@@ -2551,8 +2578,8 @@ var gatewayRerankingWarningSchema = z.discriminatedUnion("type", [
2551
2578
  message: z.string()
2552
2579
  })
2553
2580
  ]);
2554
- var gatewayRerankingResponseSchema = lazySchema10(
2555
- () => zodSchema10(
2581
+ var gatewayRerankingResponseSchema = lazySchema11(
2582
+ () => zodSchema11(
2556
2583
  z.object({
2557
2584
  ranking: z.array(
2558
2585
  z.object({
@@ -2595,7 +2622,6 @@ var GatewaySpeechModel = class {
2595
2622
  headers,
2596
2623
  abortSignal
2597
2624
  }) {
2598
- var _a12;
2599
2625
  const resolvedHeaders = this.config.headers ? await resolve11(this.config.headers) : void 0;
2600
2626
  try {
2601
2627
  const {
@@ -2606,7 +2632,7 @@ var GatewaySpeechModel = class {
2606
2632
  url: this.getUrl(),
2607
2633
  headers: combineHeaders8(
2608
2634
  resolvedHeaders,
2609
- headers != null ? headers : {},
2635
+ headers ?? {},
2610
2636
  this.getModelConfigHeaders(),
2611
2637
  await resolve11(this.config.o11yHeaders)
2612
2638
  ),
@@ -2624,17 +2650,14 @@ var GatewaySpeechModel = class {
2624
2650
  ),
2625
2651
  failedResponseHandler: createJsonErrorResponseHandler11({
2626
2652
  errorSchema: z.any(),
2627
- errorToMessage: (data) => {
2628
- var _a13;
2629
- return (_a13 = getErrorMessage11(data)) != null ? _a13 : "unknown error";
2630
- }
2653
+ errorToMessage: (data) => getErrorMessage11(data) ?? "unknown error"
2631
2654
  }),
2632
2655
  ...abortSignal && { abortSignal },
2633
2656
  fetch: this.config.fetch
2634
2657
  });
2635
2658
  return {
2636
2659
  audio: responseBody.audio,
2637
- warnings: (_a12 = responseBody.warnings) != null ? _a12 : [],
2660
+ warnings: responseBody.warnings ?? [],
2638
2661
  providerMetadata: responseBody.providerMetadata,
2639
2662
  response: {
2640
2663
  timestamp: /* @__PURE__ */ new Date(),
@@ -2646,7 +2669,7 @@ var GatewaySpeechModel = class {
2646
2669
  } catch (error) {
2647
2670
  throw await asGatewayError(
2648
2671
  error,
2649
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
2672
+ await parseAuthMethod(resolvedHeaders ?? {})
2650
2673
  );
2651
2674
  }
2652
2675
  }
@@ -2723,7 +2746,6 @@ var GatewayTranscriptionModel = class {
2723
2746
  headers,
2724
2747
  abortSignal
2725
2748
  }) {
2726
- var _a12, _b12, _c, _d;
2727
2749
  const resolvedHeaders = this.config.headers ? await resolve12(this.config.headers) : void 0;
2728
2750
  try {
2729
2751
  const {
@@ -2734,7 +2756,7 @@ var GatewayTranscriptionModel = class {
2734
2756
  url: this.getUrl(),
2735
2757
  headers: combineHeaders9(
2736
2758
  resolvedHeaders,
2737
- headers != null ? headers : {},
2759
+ headers ?? {},
2738
2760
  this.getModelConfigHeaders(),
2739
2761
  await resolve12(this.config.o11yHeaders)
2740
2762
  ),
@@ -2748,20 +2770,17 @@ var GatewayTranscriptionModel = class {
2748
2770
  ),
2749
2771
  failedResponseHandler: createJsonErrorResponseHandler12({
2750
2772
  errorSchema: z.any(),
2751
- errorToMessage: (data) => {
2752
- var _a13;
2753
- return (_a13 = getErrorMessage12(data)) != null ? _a13 : "unknown error";
2754
- }
2773
+ errorToMessage: (data) => getErrorMessage12(data) ?? "unknown error"
2755
2774
  }),
2756
2775
  ...abortSignal && { abortSignal },
2757
2776
  fetch: this.config.fetch
2758
2777
  });
2759
2778
  return {
2760
2779
  text: responseBody.text,
2761
- segments: (_a12 = responseBody.segments) != null ? _a12 : [],
2762
- language: (_b12 = responseBody.language) != null ? _b12 : void 0,
2763
- durationInSeconds: (_c = responseBody.durationInSeconds) != null ? _c : void 0,
2764
- warnings: (_d = responseBody.warnings) != null ? _d : [],
2780
+ segments: responseBody.segments ?? [],
2781
+ language: responseBody.language ?? void 0,
2782
+ durationInSeconds: responseBody.durationInSeconds ?? void 0,
2783
+ warnings: responseBody.warnings ?? [],
2765
2784
  providerMetadata: responseBody.providerMetadata,
2766
2785
  response: {
2767
2786
  timestamp: /* @__PURE__ */ new Date(),
@@ -2773,16 +2792,15 @@ var GatewayTranscriptionModel = class {
2773
2792
  } catch (error) {
2774
2793
  throw await asGatewayError(
2775
2794
  error,
2776
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
2795
+ await parseAuthMethod(resolvedHeaders ?? {})
2777
2796
  );
2778
2797
  }
2779
2798
  }
2780
2799
  async doStream(options) {
2781
- var _a12, _b12, _c, _d, _e;
2782
- const currentDate = (_c = (_b12 = (_a12 = this.config._internal) == null ? void 0 : _a12.currentDate) == null ? void 0 : _b12.call(_a12)) != null ? _c : /* @__PURE__ */ new Date();
2800
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
2783
2801
  const headers = combineHeaders9(
2784
- await resolve12((_d = this.config.headers) != null ? _d : {}),
2785
- (_e = options.headers) != null ? _e : {},
2802
+ await resolve12(this.config.headers ?? {}),
2803
+ options.headers ?? {},
2786
2804
  this.getModelConfigHeaders(),
2787
2805
  await resolve12(this.config.o11yHeaders)
2788
2806
  );
@@ -2830,7 +2848,7 @@ function toGatewayTranscriptionUrl(baseURL, modelId) {
2830
2848
  function getProtocolsFromHeaders(headers) {
2831
2849
  const normalizedHeaders = normalizeHeaders(headers);
2832
2850
  const authorization = normalizedHeaders.authorization;
2833
- const token = (authorization == null ? void 0 : authorization.startsWith("Bearer ")) ? authorization.slice("Bearer ".length) : void 0;
2851
+ const token = authorization?.startsWith("Bearer ") ? authorization.slice("Bearer ".length) : void 0;
2834
2852
  return token == null ? [GATEWAY_TRANSCRIPTION_SUBPROTOCOL] : getGatewayTranscriptionProtocols(token, {
2835
2853
  teamIdOrSlug: normalizedHeaders[VERCEL_AI_GATEWAY_TEAM_HEADER]
2836
2854
  });
@@ -2864,7 +2882,7 @@ function createGatewayTranscriptionStream({
2864
2882
  void audio.cancel().catch(() => {
2865
2883
  });
2866
2884
  }
2867
- connection == null ? void 0 : connection.close(closeCode);
2885
+ connection?.close(closeCode);
2868
2886
  };
2869
2887
  const stopAudio = () => {
2870
2888
  audioStopped = true;
@@ -3067,7 +3085,7 @@ var GatewayRealtimeModel = class {
3067
3085
  async doCreateClientSecret(options) {
3068
3086
  const secret = await this.config.createClientSecret({
3069
3087
  modelId: this.modelId,
3070
- ...(options == null ? void 0 : options.expiresAfterSeconds) != null && {
3088
+ ...options?.expiresAfterSeconds != null && {
3071
3089
  expiresAfterSeconds: options.expiresAfterSeconds
3072
3090
  }
3073
3091
  });
@@ -3101,14 +3119,130 @@ function toGatewayRealtimeUrl(baseURL, modelId) {
3101
3119
  return url.toString();
3102
3120
  }
3103
3121
 
3104
- // src/tool/exa-search.ts
3122
+ // src/tool/browserbase-fetch.ts
3105
3123
  import {
3106
3124
  createProviderExecutedToolFactory,
3107
- lazySchema as lazySchema11,
3108
- zodSchema as zodSchema11
3125
+ lazySchema as lazySchema12,
3126
+ zodSchema as zodSchema12
3109
3127
  } from "@ai-sdk/provider-utils";
3110
- var exaSearchInputSchema = lazySchema11(
3111
- () => zodSchema11(
3128
+ var jsonObjectSchema = z.record(z.string(), z.unknown());
3129
+ var browserbaseFetchInputSchema = lazySchema12(
3130
+ () => zodSchema12(
3131
+ z.object({
3132
+ url: z.string().url().describe("URL of the page to fetch."),
3133
+ allow_redirects: z.boolean().optional().describe("Whether to follow HTTP redirects (default: false)."),
3134
+ allow_insecure_ssl: z.boolean().optional().describe(
3135
+ "Whether to bypass TLS certificate verification (default: false). Only use for trusted hosts."
3136
+ ),
3137
+ proxies: z.boolean().optional().describe(
3138
+ "Whether to route the request through Browserbase proxies (default: false)."
3139
+ ),
3140
+ format: z.enum(["raw", "json", "markdown"]).optional().describe(
3141
+ "Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema."
3142
+ ),
3143
+ schema: jsonObjectSchema.optional().describe(
3144
+ "JSON Schema for structured extraction. Only use with format set to json."
3145
+ )
3146
+ })
3147
+ )
3148
+ );
3149
+ var browserbaseFetchOutputSchema = lazySchema12(
3150
+ () => zodSchema12(
3151
+ z.union([
3152
+ z.object({
3153
+ id: z.string(),
3154
+ content: z.union([z.string(), jsonObjectSchema]),
3155
+ contentType: z.string(),
3156
+ encoding: z.string(),
3157
+ headers: z.record(z.string(), z.string()),
3158
+ statusCode: z.number()
3159
+ }),
3160
+ z.object({
3161
+ error: z.enum([
3162
+ "api_error",
3163
+ "configuration_error",
3164
+ "execution_error",
3165
+ "invalid_input",
3166
+ "rate_limit",
3167
+ "timeout",
3168
+ "unknown"
3169
+ ]),
3170
+ statusCode: z.number().optional(),
3171
+ message: z.string()
3172
+ })
3173
+ ])
3174
+ )
3175
+ );
3176
+ var browserbaseFetchToolFactory = createProviderExecutedToolFactory({
3177
+ id: "gateway.browserbase_fetch",
3178
+ inputSchema: browserbaseFetchInputSchema,
3179
+ outputSchema: browserbaseFetchOutputSchema
3180
+ });
3181
+ var browserbaseFetch = (config = {}) => browserbaseFetchToolFactory(config);
3182
+
3183
+ // src/tool/browserbase-search.ts
3184
+ import {
3185
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
3186
+ lazySchema as lazySchema13,
3187
+ zodSchema as zodSchema13
3188
+ } from "@ai-sdk/provider-utils";
3189
+ var browserbaseSearchInputSchema = lazySchema13(
3190
+ () => zodSchema13(
3191
+ z.object({
3192
+ query: z.string().min(1).max(200).describe("Web search query. Must be between 1 and 200 characters."),
3193
+ num_results: z.number().int().min(1).max(25).optional().describe("Maximum number of results to return (1-25, default: 10).")
3194
+ })
3195
+ )
3196
+ );
3197
+ var browserbaseSearchOutputSchema = lazySchema13(
3198
+ () => zodSchema13(
3199
+ z.union([
3200
+ z.object({
3201
+ query: z.string(),
3202
+ requestId: z.string(),
3203
+ results: z.array(
3204
+ z.object({
3205
+ id: z.string(),
3206
+ title: z.string(),
3207
+ url: z.string(),
3208
+ author: z.string().optional(),
3209
+ favicon: z.string().optional(),
3210
+ image: z.string().optional(),
3211
+ publishedDate: z.string().optional()
3212
+ })
3213
+ )
3214
+ }),
3215
+ z.object({
3216
+ error: z.enum([
3217
+ "api_error",
3218
+ "configuration_error",
3219
+ "execution_error",
3220
+ "invalid_input",
3221
+ "rate_limit",
3222
+ "timeout",
3223
+ "unknown"
3224
+ ]),
3225
+ statusCode: z.number().optional(),
3226
+ message: z.string()
3227
+ })
3228
+ ])
3229
+ )
3230
+ );
3231
+ var browserbaseSearchToolFactory = createProviderExecutedToolFactory2({
3232
+ id: "gateway.browserbase_search",
3233
+ inputSchema: browserbaseSearchInputSchema,
3234
+ outputSchema: browserbaseSearchOutputSchema
3235
+ });
3236
+ var browserbaseSearch = (config = {}) => browserbaseSearchToolFactory(config);
3237
+
3238
+ // src/tool/exa-search.ts
3239
+ import {
3240
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
3241
+ lazySchema as lazySchema14,
3242
+ zodSchema as zodSchema14
3243
+ } from "@ai-sdk/provider-utils";
3244
+ var exaSearchInputSchema = lazySchema14(
3245
+ () => zodSchema14(
3112
3246
  z.object({
3113
3247
  query: z.string().describe("Natural-language web search query. This is required."),
3114
3248
  type: z.enum(["auto", "fast", "instant"]).optional().describe(
@@ -3178,8 +3312,8 @@ var exaSearchInputSchema = lazySchema11(
3178
3312
  })
3179
3313
  )
3180
3314
  );
3181
- var exaSearchOutputSchema = lazySchema11(
3182
- () => zodSchema11(
3315
+ var exaSearchOutputSchema = lazySchema14(
3316
+ () => zodSchema14(
3183
3317
  z.union([
3184
3318
  z.object({
3185
3319
  requestId: z.string(),
@@ -3226,7 +3360,7 @@ var exaSearchOutputSchema = lazySchema11(
3226
3360
  ])
3227
3361
  )
3228
3362
  );
3229
- var exaSearchToolFactory = createProviderExecutedToolFactory({
3363
+ var exaSearchToolFactory = createProviderExecutedToolFactory3({
3230
3364
  id: "gateway.exa_search",
3231
3365
  inputSchema: exaSearchInputSchema,
3232
3366
  outputSchema: exaSearchOutputSchema
@@ -3235,12 +3369,12 @@ var exaSearch = (config = {}) => exaSearchToolFactory(config);
3235
3369
 
3236
3370
  // src/tool/parallel-search.ts
3237
3371
  import {
3238
- createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
3239
- lazySchema as lazySchema12,
3240
- zodSchema as zodSchema12
3372
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
3373
+ lazySchema as lazySchema15,
3374
+ zodSchema as zodSchema15
3241
3375
  } from "@ai-sdk/provider-utils";
3242
- var parallelSearchInputSchema = lazySchema12(
3243
- () => zodSchema12(
3376
+ var parallelSearchInputSchema = lazySchema15(
3377
+ () => zodSchema15(
3244
3378
  z.object({
3245
3379
  objective: z.string().describe(
3246
3380
  "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
@@ -3279,8 +3413,8 @@ var parallelSearchInputSchema = lazySchema12(
3279
3413
  })
3280
3414
  )
3281
3415
  );
3282
- var parallelSearchOutputSchema = lazySchema12(
3283
- () => zodSchema12(
3416
+ var parallelSearchOutputSchema = lazySchema15(
3417
+ () => zodSchema15(
3284
3418
  z.union([
3285
3419
  // Success response
3286
3420
  z.object({
@@ -3311,7 +3445,7 @@ var parallelSearchOutputSchema = lazySchema12(
3311
3445
  ])
3312
3446
  )
3313
3447
  );
3314
- var parallelSearchToolFactory = createProviderExecutedToolFactory2({
3448
+ var parallelSearchToolFactory = createProviderExecutedToolFactory4({
3315
3449
  id: "gateway.parallel_search",
3316
3450
  inputSchema: parallelSearchInputSchema,
3317
3451
  outputSchema: parallelSearchOutputSchema
@@ -3320,12 +3454,12 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
3320
3454
 
3321
3455
  // src/tool/perplexity-search.ts
3322
3456
  import {
3323
- createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
3324
- lazySchema as lazySchema13,
3325
- zodSchema as zodSchema13
3457
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory5,
3458
+ lazySchema as lazySchema16,
3459
+ zodSchema as zodSchema16
3326
3460
  } from "@ai-sdk/provider-utils";
3327
- var perplexitySearchInputSchema = lazySchema13(
3328
- () => zodSchema13(
3461
+ var perplexitySearchInputSchema = lazySchema16(
3462
+ () => zodSchema16(
3329
3463
  z.object({
3330
3464
  query: z.union([z.string(), z.array(z.string())]).describe(
3331
3465
  "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
@@ -3366,8 +3500,8 @@ var perplexitySearchInputSchema = lazySchema13(
3366
3500
  })
3367
3501
  )
3368
3502
  );
3369
- var perplexitySearchOutputSchema = lazySchema13(
3370
- () => zodSchema13(
3503
+ var perplexitySearchOutputSchema = lazySchema16(
3504
+ () => zodSchema16(
3371
3505
  z.union([
3372
3506
  // Success response
3373
3507
  z.object({
@@ -3397,7 +3531,7 @@ var perplexitySearchOutputSchema = lazySchema13(
3397
3531
  ])
3398
3532
  )
3399
3533
  );
3400
- var perplexitySearchToolFactory = createProviderExecutedToolFactory3({
3534
+ var perplexitySearchToolFactory = createProviderExecutedToolFactory5({
3401
3535
  id: "gateway.perplexity_search",
3402
3536
  inputSchema: perplexitySearchInputSchema,
3403
3537
  outputSchema: perplexitySearchOutputSchema
@@ -3406,9 +3540,9 @@ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
3406
3540
 
3407
3541
  // src/tool/tako-search.ts
3408
3542
  import {
3409
- createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
3410
- lazySchema as lazySchema14,
3411
- zodSchema as zodSchema14
3543
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory6,
3544
+ lazySchema as lazySchema17,
3545
+ zodSchema as zodSchema17
3412
3546
  } from "@ai-sdk/provider-utils";
3413
3547
  var takoDataSourceInputSchema = z.object({
3414
3548
  count: z.number().optional().describe(
@@ -3447,8 +3581,8 @@ var takoWebSourceInputSchema = z.object({
3447
3581
  "Keep results published on or before this ISO date (YYYY-MM-DD)."
3448
3582
  )
3449
3583
  });
3450
- var takoSearchInputSchema = lazySchema14(
3451
- () => zodSchema14(
3584
+ var takoSearchInputSchema = lazySchema17(
3585
+ () => zodSchema17(
3452
3586
  z.object({
3453
3587
  query: z.string().describe(
3454
3588
  'Natural-language search query. Include the entity, metric, and time period. Quote a phrase to force it to one entity, for example "Tesla":PRODUCT price.'
@@ -3578,8 +3712,8 @@ var takoWebResultSchema = z.object({
3578
3712
  publish_date: z.string().nullish(),
3579
3713
  content: takoResultContentSchema.nullish()
3580
3714
  }).passthrough();
3581
- var takoSearchOutputSchema = lazySchema14(
3582
- () => zodSchema14(
3715
+ var takoSearchOutputSchema = lazySchema17(
3716
+ () => zodSchema17(
3583
3717
  z.union([
3584
3718
  z.object({
3585
3719
  request_id: z.string(),
@@ -3608,7 +3742,7 @@ var takoSearchOutputSchema = lazySchema14(
3608
3742
  ])
3609
3743
  )
3610
3744
  );
3611
- var takoSearchToolFactory = createProviderExecutedToolFactory4({
3745
+ var takoSearchToolFactory = createProviderExecutedToolFactory6({
3612
3746
  id: "gateway.tako_search",
3613
3747
  inputSchema: takoSearchInputSchema,
3614
3748
  outputSchema: takoSearchOutputSchema
@@ -3617,6 +3751,20 @@ var takoSearch = (config = {}) => takoSearchToolFactory(config);
3617
3751
 
3618
3752
  // src/gateway-tools.ts
3619
3753
  var gatewayTools = {
3754
+ /**
3755
+ * Fetch page content using Browserbase's lightweight Fetch API.
3756
+ *
3757
+ * Supports raw, Markdown, and schema-driven JSON output as well as redirects,
3758
+ * proxy routing, and TLS controls.
3759
+ */
3760
+ browserbaseFetch,
3761
+ /**
3762
+ * Search the web using Browserbase's Search API for fast, structured results.
3763
+ *
3764
+ * Returns titles, URLs, and available publication metadata without requiring
3765
+ * a browser session.
3766
+ */
3767
+ browserbaseSearch,
3620
3768
  /**
3621
3769
  * Search the web using Exa for current information and token-efficient
3622
3770
  * excerpts optimized for agent workflows.
@@ -3657,12 +3805,11 @@ var gatewayTools = {
3657
3805
  import { getContext } from "@vercel/oidc";
3658
3806
  import { getVercelOidcToken } from "@vercel/oidc";
3659
3807
  async function getVercelRequestId() {
3660
- var _a12;
3661
- return (_a12 = getContext().headers) == null ? void 0 : _a12["x-vercel-id"];
3808
+ return getContext().headers?.["x-vercel-id"];
3662
3809
  }
3663
3810
 
3664
3811
  // src/version.ts
3665
- var VERSION = true ? "4.0.92" : "0.0.0-test";
3812
+ var VERSION = true ? "4.0.95" : "0.0.0-test";
3666
3813
 
3667
3814
  // src/gateway-provider.ts
3668
3815
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -3671,12 +3818,11 @@ var gatewayClientSecretResponseSchema = z.object({
3671
3818
  expiresAt: z.number().nullish()
3672
3819
  });
3673
3820
  function createGateway(options = {}) {
3674
- var _a12, _b12;
3675
3821
  let pendingMetadata = null;
3676
3822
  let metadataCache = null;
3677
- const cacheRefreshMillis = (_a12 = options.metadataCacheRefreshMillis) != null ? _a12 : 1e3 * 60 * 5;
3823
+ const cacheRefreshMillis = options.metadataCacheRefreshMillis ?? 1e3 * 60 * 5;
3678
3824
  let lastFetchTime = 0;
3679
- const baseURL = (_b12 = withoutTrailingSlash(options.baseURL)) != null ? _b12 : "https://ai-gateway.vercel.sh/v4/ai";
3825
+ const baseURL = withoutTrailingSlash(options.baseURL) ?? "https://ai-gateway.vercel.sh/v4/ai";
3680
3826
  const createAuthHeaders = (auth) => withUserAgentSuffix(
3681
3827
  {
3682
3828
  Authorization: `Bearer ${auth.token}`,
@@ -3732,10 +3878,7 @@ function createGateway(options = {}) {
3732
3878
  ),
3733
3879
  failedResponseHandler: createJsonErrorResponseHandler13({
3734
3880
  errorSchema: z.any(),
3735
- errorToMessage: (data) => {
3736
- var _a13;
3737
- return (_a13 = getErrorMessage13(data)) != null ? _a13 : "unknown error";
3738
- }
3881
+ errorToMessage: (data) => getErrorMessage13(data) ?? "unknown error"
3739
3882
  }),
3740
3883
  fetch: options.fetch
3741
3884
  });
@@ -3792,8 +3935,7 @@ function createGateway(options = {}) {
3792
3935
  o11yHeaders: createO11yHeaders()
3793
3936
  });
3794
3937
  const getAvailableModels = async () => {
3795
- var _a13, _b13, _c;
3796
- const now = (_c = (_b13 = (_a13 = options._internal) == null ? void 0 : _a13.currentDate) == null ? void 0 : _b13.call(_a13).getTime()) != null ? _c : Date.now();
3938
+ const now = options._internal?.currentDate?.().getTime() ?? Date.now();
3797
3939
  if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
3798
3940
  lastFetchTime = now;
3799
3941
  pendingMetadata = new GatewayFetchMetadata({