@ai-sdk/gateway 4.0.0-canary.98 → 4.0.0

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
@@ -1,9 +1,67 @@
1
+ // src/gateway-realtime-auth.ts
2
+ var GATEWAY_REALTIME_SUBPROTOCOL = "ai-gateway-realtime.v1";
3
+ var GATEWAY_AUTH_SUBPROTOCOL_PREFIX = "ai-gateway-auth.";
4
+ var GATEWAY_TEAM_SUBPROTOCOL_PREFIX = "ai-gateway-team.";
5
+ function getGatewayRealtimeProtocols(token, options) {
6
+ const protocols = [
7
+ GATEWAY_REALTIME_SUBPROTOCOL,
8
+ `${GATEWAY_AUTH_SUBPROTOCOL_PREFIX}${token}`
9
+ ];
10
+ if (options == null ? void 0 : options.teamIdOrSlug) {
11
+ protocols.push(
12
+ `${GATEWAY_TEAM_SUBPROTOCOL_PREFIX}${encodeSubprotocolValue(options.teamIdOrSlug)}`
13
+ );
14
+ }
15
+ return protocols;
16
+ }
17
+ function getGatewayRealtimeAuthToken(secWebSocketProtocol) {
18
+ var _a11;
19
+ return ((_a11 = findProtocol(secWebSocketProtocol, GATEWAY_AUTH_SUBPROTOCOL_PREFIX)) == null ? void 0 : _a11.slice(
20
+ GATEWAY_AUTH_SUBPROTOCOL_PREFIX.length
21
+ )) || void 0;
22
+ }
23
+ function getGatewayRealtimeTeamIdOrSlug(secWebSocketProtocol) {
24
+ var _a11;
25
+ const encoded = (_a11 = findProtocol(
26
+ secWebSocketProtocol,
27
+ GATEWAY_TEAM_SUBPROTOCOL_PREFIX
28
+ )) == null ? void 0 : _a11.slice(GATEWAY_TEAM_SUBPROTOCOL_PREFIX.length);
29
+ if (!encoded) return void 0;
30
+ try {
31
+ return decodeSubprotocolValue(encoded) || void 0;
32
+ } catch (e) {
33
+ return void 0;
34
+ }
35
+ }
36
+ function findProtocol(secWebSocketProtocol, prefix) {
37
+ return secWebSocketProtocol == null ? void 0 : secWebSocketProtocol.split(",").map((protocol) => protocol.trim()).find((protocol) => protocol.startsWith(prefix));
38
+ }
39
+ function encodeSubprotocolValue(value) {
40
+ const bytes = new TextEncoder().encode(value);
41
+ let binary = "";
42
+ for (const byte of bytes) {
43
+ binary += String.fromCharCode(byte);
44
+ }
45
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/u, "");
46
+ }
47
+ function decodeSubprotocolValue(value) {
48
+ const base64 = value.replace(/-/g, "+").replace(/_/g, "/");
49
+ const padding = "=".repeat((4 - base64.length % 4) % 4);
50
+ const binary = atob(`${base64}${padding}`);
51
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
52
+ return new TextDecoder().decode(bytes);
53
+ }
54
+
1
55
  // src/gateway-provider.ts
2
56
  import {
57
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler11,
58
+ createJsonResponseHandler as createJsonResponseHandler10,
3
59
  loadOptionalSetting,
60
+ postJsonToApi as postJsonToApi8,
4
61
  withoutTrailingSlash,
5
62
  withUserAgentSuffix
6
63
  } from "@ai-sdk/provider-utils";
64
+ import { z as z17 } from "zod/v4";
7
65
 
8
66
  // src/errors/as-gateway-error.ts
9
67
  import { APICallError } from "@ai-sdk/provider";
@@ -217,12 +275,58 @@ var GatewayInternalServerError = class extends (_b6 = GatewayError, _a6 = symbol
217
275
  }
218
276
  };
219
277
 
220
- // src/errors/gateway-response-error.ts
221
- var name6 = "GatewayResponseError";
278
+ // src/errors/gateway-failed-dependency-error.ts
279
+ var name6 = "GatewayFailedDependencyError";
222
280
  var marker7 = `vercel.ai.gateway.error.${name6}`;
223
281
  var symbol7 = Symbol.for(marker7);
224
282
  var _a7, _b7;
225
- var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7) {
283
+ var GatewayFailedDependencyError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7) {
284
+ constructor({
285
+ message = "Failed dependency",
286
+ statusCode = 424,
287
+ cause,
288
+ generationId
289
+ } = {}) {
290
+ super({ message, statusCode, cause, generationId });
291
+ this[_a7] = true;
292
+ // used in isInstance
293
+ this.name = name6;
294
+ this.type = "failed_dependency";
295
+ }
296
+ static isInstance(error) {
297
+ return GatewayError.hasMarker(error) && symbol7 in error;
298
+ }
299
+ };
300
+
301
+ // src/errors/gateway-forbidden-error.ts
302
+ var name7 = "GatewayForbiddenError";
303
+ var marker8 = `vercel.ai.gateway.error.${name7}`;
304
+ var symbol8 = Symbol.for(marker8);
305
+ var _a8, _b8;
306
+ var GatewayForbiddenError = class extends (_b8 = GatewayError, _a8 = symbol8, _b8) {
307
+ constructor({
308
+ message = "Forbidden",
309
+ statusCode = 403,
310
+ cause,
311
+ generationId
312
+ } = {}) {
313
+ super({ message, statusCode, cause, generationId });
314
+ this[_a8] = true;
315
+ // used in isInstance
316
+ this.name = name7;
317
+ this.type = "forbidden";
318
+ }
319
+ static isInstance(error) {
320
+ return GatewayError.hasMarker(error) && symbol8 in error;
321
+ }
322
+ };
323
+
324
+ // src/errors/gateway-response-error.ts
325
+ var name8 = "GatewayResponseError";
326
+ var marker9 = `vercel.ai.gateway.error.${name8}`;
327
+ var symbol9 = Symbol.for(marker9);
328
+ var _a9, _b9;
329
+ var GatewayResponseError = class extends (_b9 = GatewayError, _a9 = symbol9, _b9) {
226
330
  constructor({
227
331
  message = "Invalid response from Gateway",
228
332
  statusCode = 502,
@@ -232,15 +336,15 @@ var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7
232
336
  generationId
233
337
  } = {}) {
234
338
  super({ message, statusCode, cause, generationId });
235
- this[_a7] = true;
339
+ this[_a9] = true;
236
340
  // used in isInstance
237
- this.name = name6;
341
+ this.name = name8;
238
342
  this.type = "response_error";
239
343
  this.response = response;
240
344
  this.validationError = validationError;
241
345
  }
242
346
  static isInstance(error) {
243
- return GatewayError.hasMarker(error) && symbol7 in error;
347
+ return GatewayError.hasMarker(error) && symbol9 in error;
244
348
  }
245
349
  };
246
350
 
@@ -257,7 +361,7 @@ async function createGatewayErrorFromResponse({
257
361
  cause,
258
362
  authMethod
259
363
  }) {
260
- var _a9;
364
+ var _a11;
261
365
  const parseResult = await safeValidateTypes({
262
366
  value: response,
263
367
  schema: gatewayErrorResponseSchema
@@ -276,7 +380,7 @@ async function createGatewayErrorFromResponse({
276
380
  const validatedResponse = parseResult.value;
277
381
  const errorType = validatedResponse.error.type;
278
382
  const message = validatedResponse.error.message;
279
- const generationId = (_a9 = validatedResponse.generationId) != null ? _a9 : void 0;
383
+ const generationId = (_a11 = validatedResponse.generationId) != null ? _a11 : void 0;
280
384
  switch (errorType) {
281
385
  case "authentication_error":
282
386
  return GatewayAuthenticationError.createContextualError({
@@ -320,6 +424,20 @@ async function createGatewayErrorFromResponse({
320
424
  cause,
321
425
  generationId
322
426
  });
427
+ case "failed_dependency":
428
+ return new GatewayFailedDependencyError({
429
+ message,
430
+ statusCode,
431
+ cause,
432
+ generationId
433
+ });
434
+ case "forbidden":
435
+ return new GatewayForbiddenError({
436
+ message,
437
+ statusCode,
438
+ cause,
439
+ generationId
440
+ });
323
441
  default:
324
442
  return new GatewayInternalServerError({
325
443
  message,
@@ -359,11 +477,11 @@ function extractApiCallResponse(error) {
359
477
  }
360
478
 
361
479
  // src/errors/gateway-timeout-error.ts
362
- var name7 = "GatewayTimeoutError";
363
- var marker8 = `vercel.ai.gateway.error.${name7}`;
364
- var symbol8 = Symbol.for(marker8);
365
- var _a8, _b8;
366
- var GatewayTimeoutError = class _GatewayTimeoutError extends (_b8 = GatewayError, _a8 = symbol8, _b8) {
480
+ var name9 = "GatewayTimeoutError";
481
+ var marker10 = `vercel.ai.gateway.error.${name9}`;
482
+ var symbol10 = Symbol.for(marker10);
483
+ var _a10, _b10;
484
+ var GatewayTimeoutError = class _GatewayTimeoutError extends (_b10 = GatewayError, _a10 = symbol10, _b10) {
367
485
  constructor({
368
486
  message = "Request timed out",
369
487
  statusCode = 408,
@@ -371,13 +489,13 @@ var GatewayTimeoutError = class _GatewayTimeoutError extends (_b8 = GatewayError
371
489
  generationId
372
490
  } = {}) {
373
491
  super({ message, statusCode, cause, generationId });
374
- this[_a8] = true;
492
+ this[_a10] = true;
375
493
  // used in isInstance
376
- this.name = name7;
494
+ this.name = name9;
377
495
  this.type = "timeout_error";
378
496
  }
379
497
  static isInstance(error) {
380
- return GatewayError.hasMarker(error) && symbol8 in error;
498
+ return GatewayError.hasMarker(error) && symbol10 in error;
381
499
  }
382
500
  /**
383
501
  * Creates a helpful timeout error message with troubleshooting guidance
@@ -417,7 +535,7 @@ function isTimeoutError(error) {
417
535
  return false;
418
536
  }
419
537
  async function asGatewayError(error, authMethod) {
420
- var _a9;
538
+ var _a11;
421
539
  if (GatewayError.isInstance(error)) {
422
540
  return error;
423
541
  }
@@ -436,7 +554,7 @@ async function asGatewayError(error, authMethod) {
436
554
  }
437
555
  return await createGatewayErrorFromResponse({
438
556
  response: extractApiCallResponse(error),
439
- statusCode: (_a9 = error.statusCode) != null ? _a9 : 500,
557
+ statusCode: (_a11 = error.statusCode) != null ? _a11 : 500,
440
558
  defaultMessage: "Gateway request failed",
441
559
  cause: error,
442
560
  authMethod
@@ -927,24 +1045,24 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
927
1045
  );
928
1046
  }
929
1047
  }
930
- isFilePart(part) {
931
- return part && typeof part === "object" && "type" in part && part.type === "file";
932
- }
933
1048
  /**
934
- * Encodes inline `Uint8Array` file part data to a base64 string in place.
1049
+ * Encodes inline `Uint8Array` file data to a base64 string in place.
935
1050
  * @param options - The options to encode.
936
- * @returns The options with the file parts encoded.
1051
+ * @returns The options with the file data encoded.
937
1052
  */
938
1053
  maybeEncodeFileParts(options) {
939
1054
  for (const message of options.prompt) {
1055
+ if (!Array.isArray(message.content)) {
1056
+ continue;
1057
+ }
940
1058
  for (const part of message.content) {
941
- if (this.isFilePart(part)) {
942
- const filePart = part;
943
- if (filePart.data.type === "data" && filePart.data.data instanceof Uint8Array) {
944
- filePart.data = {
945
- type: "data",
946
- data: Buffer.from(filePart.data.data).toString("base64")
947
- };
1059
+ if (part.type === "file" || part.type === "reasoning-file") {
1060
+ part.data = maybeBase64EncodeFileData(part.data);
1061
+ } else if (part.type === "tool-result" && part.output.type === "content") {
1062
+ for (const contentPart of part.output.value) {
1063
+ if (contentPart.type === "file") {
1064
+ contentPart.data = maybeBase64EncodeFileData(contentPart.data);
1065
+ }
948
1066
  }
949
1067
  }
950
1068
  }
@@ -962,6 +1080,15 @@ var GatewayLanguageModel = class _GatewayLanguageModel {
962
1080
  };
963
1081
  }
964
1082
  };
1083
+ function maybeBase64EncodeFileData(data) {
1084
+ if (data.type === "data") {
1085
+ const bytes = data.data;
1086
+ if (bytes instanceof Uint8Array) {
1087
+ return { ...data, data: Buffer.from(bytes).toString("base64") };
1088
+ }
1089
+ }
1090
+ return data;
1091
+ }
965
1092
 
966
1093
  // src/gateway-embedding-model.ts
967
1094
  import {
@@ -1003,7 +1130,7 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1003
1130
  abortSignal,
1004
1131
  providerOptions
1005
1132
  }) {
1006
- var _a9;
1133
+ var _a11, _b11;
1007
1134
  const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
1008
1135
  try {
1009
1136
  const {
@@ -1034,10 +1161,10 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1034
1161
  });
1035
1162
  return {
1036
1163
  embeddings: responseBody.embeddings,
1037
- usage: (_a9 = responseBody.usage) != null ? _a9 : void 0,
1164
+ usage: (_a11 = responseBody.usage) != null ? _a11 : void 0,
1038
1165
  providerMetadata: responseBody.providerMetadata,
1039
1166
  response: { headers: responseHeaders, body: rawValue },
1040
- warnings: []
1167
+ warnings: (_b11 = responseBody.warnings) != null ? _b11 : []
1041
1168
  };
1042
1169
  } catch (error) {
1043
1170
  throw await asGatewayError(
@@ -1056,11 +1183,33 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1056
1183
  };
1057
1184
  }
1058
1185
  };
1186
+ var gatewayEmbeddingWarningSchema = z8.discriminatedUnion("type", [
1187
+ z8.object({
1188
+ type: z8.literal("unsupported"),
1189
+ feature: z8.string(),
1190
+ details: z8.string().optional()
1191
+ }),
1192
+ z8.object({
1193
+ type: z8.literal("compatibility"),
1194
+ feature: z8.string(),
1195
+ details: z8.string().optional()
1196
+ }),
1197
+ z8.object({
1198
+ type: z8.literal("deprecated"),
1199
+ setting: z8.string(),
1200
+ message: z8.string()
1201
+ }),
1202
+ z8.object({
1203
+ type: z8.literal("other"),
1204
+ message: z8.string()
1205
+ })
1206
+ ]);
1059
1207
  var gatewayEmbeddingResponseSchema = lazySchema7(
1060
1208
  () => zodSchema7(
1061
1209
  z8.object({
1062
1210
  embeddings: z8.array(z8.array(z8.number())),
1063
1211
  usage: z8.object({ tokens: z8.number() }).nullish(),
1212
+ warnings: z8.array(gatewayEmbeddingWarningSchema).optional(),
1064
1213
  providerMetadata: z8.record(z8.string(), z8.record(z8.string(), z8.unknown())).optional()
1065
1214
  })
1066
1215
  )
@@ -1111,7 +1260,7 @@ var GatewayImageModel = class _GatewayImageModel {
1111
1260
  headers,
1112
1261
  abortSignal
1113
1262
  }) {
1114
- var _a9, _b9, _c, _d;
1263
+ var _a11, _b11, _c, _d;
1115
1264
  const resolvedHeaders = this.config.headers ? await resolve6(this.config.headers) : void 0;
1116
1265
  try {
1117
1266
  const { responseHeaders, value: responseBody } = await postJsonToApi3({
@@ -1147,7 +1296,7 @@ var GatewayImageModel = class _GatewayImageModel {
1147
1296
  return {
1148
1297
  images: responseBody.images,
1149
1298
  // Always base64 strings from server
1150
- warnings: (_a9 = responseBody.warnings) != null ? _a9 : [],
1299
+ warnings: (_a11 = responseBody.warnings) != null ? _a11 : [],
1151
1300
  providerMetadata: responseBody.providerMetadata,
1152
1301
  response: {
1153
1302
  timestamp: /* @__PURE__ */ new Date(),
@@ -1156,7 +1305,7 @@ var GatewayImageModel = class _GatewayImageModel {
1156
1305
  },
1157
1306
  ...responseBody.usage != null && {
1158
1307
  usage: {
1159
- inputTokens: (_b9 = responseBody.usage.inputTokens) != null ? _b9 : void 0,
1308
+ inputTokens: (_b11 = responseBody.usage.inputTokens) != null ? _b11 : void 0,
1160
1309
  outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
1161
1310
  totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
1162
1311
  }
@@ -1202,6 +1351,11 @@ var gatewayImageWarningSchema = z9.discriminatedUnion("type", [
1202
1351
  feature: z9.string(),
1203
1352
  details: z9.string().optional()
1204
1353
  }),
1354
+ z9.object({
1355
+ type: z9.literal("deprecated"),
1356
+ setting: z9.string(),
1357
+ message: z9.string()
1358
+ }),
1205
1359
  z9.object({
1206
1360
  type: z9.literal("other"),
1207
1361
  message: z9.string()
@@ -1252,12 +1406,13 @@ var GatewayVideoModel = class {
1252
1406
  duration,
1253
1407
  fps,
1254
1408
  seed,
1409
+ generateAudio,
1255
1410
  image,
1256
1411
  providerOptions,
1257
1412
  headers,
1258
1413
  abortSignal
1259
1414
  }) {
1260
- var _a9;
1415
+ var _a11;
1261
1416
  const resolvedHeaders = this.config.headers ? await resolve7(this.config.headers) : void 0;
1262
1417
  try {
1263
1418
  const { responseHeaders, value: responseBody } = await postJsonToApi4({
@@ -1277,6 +1432,7 @@ var GatewayVideoModel = class {
1277
1432
  ...duration && { duration },
1278
1433
  ...fps && { fps },
1279
1434
  ...seed && { seed },
1435
+ ...generateAudio !== void 0 && { generateAudio },
1280
1436
  ...providerOptions && { providerOptions },
1281
1437
  ...image && { image: maybeEncodeVideoFile(image) }
1282
1438
  },
@@ -1353,7 +1509,7 @@ var GatewayVideoModel = class {
1353
1509
  });
1354
1510
  return {
1355
1511
  videos: responseBody.videos,
1356
- warnings: (_a9 = responseBody.warnings) != null ? _a9 : [],
1512
+ warnings: (_a11 = responseBody.warnings) != null ? _a11 : [],
1357
1513
  providerMetadata: responseBody.providerMetadata,
1358
1514
  response: {
1359
1515
  timestamp: /* @__PURE__ */ new Date(),
@@ -1413,6 +1569,11 @@ var gatewayVideoWarningSchema = z10.discriminatedUnion("type", [
1413
1569
  feature: z10.string(),
1414
1570
  details: z10.string().optional()
1415
1571
  }),
1572
+ z10.object({
1573
+ type: z10.literal("deprecated"),
1574
+ setting: z10.string(),
1575
+ message: z10.string()
1576
+ }),
1416
1577
  z10.object({
1417
1578
  type: z10.literal("other"),
1418
1579
  message: z10.string()
@@ -1462,6 +1623,7 @@ var GatewayRerankingModel = class {
1462
1623
  abortSignal,
1463
1624
  providerOptions
1464
1625
  }) {
1626
+ var _a11;
1465
1627
  const resolvedHeaders = this.config.headers ? await resolve8(this.config.headers) : void 0;
1466
1628
  try {
1467
1629
  const {
@@ -1496,7 +1658,7 @@ var GatewayRerankingModel = class {
1496
1658
  ranking: responseBody.ranking,
1497
1659
  providerMetadata: responseBody.providerMetadata,
1498
1660
  response: { headers: responseHeaders, body: rawValue },
1499
- warnings: []
1661
+ warnings: (_a11 = responseBody.warnings) != null ? _a11 : []
1500
1662
  };
1501
1663
  } catch (error) {
1502
1664
  throw await asGatewayError(
@@ -1515,6 +1677,27 @@ var GatewayRerankingModel = class {
1515
1677
  };
1516
1678
  }
1517
1679
  };
1680
+ var gatewayRerankingWarningSchema = z11.discriminatedUnion("type", [
1681
+ z11.object({
1682
+ type: z11.literal("unsupported"),
1683
+ feature: z11.string(),
1684
+ details: z11.string().optional()
1685
+ }),
1686
+ z11.object({
1687
+ type: z11.literal("compatibility"),
1688
+ feature: z11.string(),
1689
+ details: z11.string().optional()
1690
+ }),
1691
+ z11.object({
1692
+ type: z11.literal("deprecated"),
1693
+ setting: z11.string(),
1694
+ message: z11.string()
1695
+ }),
1696
+ z11.object({
1697
+ type: z11.literal("other"),
1698
+ message: z11.string()
1699
+ })
1700
+ ]);
1518
1701
  var gatewayRerankingResponseSchema = lazySchema8(
1519
1702
  () => zodSchema8(
1520
1703
  z11.object({
@@ -1524,6 +1707,7 @@ var gatewayRerankingResponseSchema = lazySchema8(
1524
1707
  relevanceScore: z11.number()
1525
1708
  })
1526
1709
  ),
1710
+ warnings: z11.array(gatewayRerankingWarningSchema).optional(),
1527
1711
  providerMetadata: z11.record(z11.string(), z11.record(z11.string(), z11.unknown())).optional()
1528
1712
  })
1529
1713
  )
@@ -1558,7 +1742,7 @@ var GatewaySpeechModel = class {
1558
1742
  headers,
1559
1743
  abortSignal
1560
1744
  }) {
1561
- var _a9;
1745
+ var _a11;
1562
1746
  const resolvedHeaders = this.config.headers ? await resolve9(this.config.headers) : void 0;
1563
1747
  try {
1564
1748
  const {
@@ -1594,7 +1778,7 @@ var GatewaySpeechModel = class {
1594
1778
  });
1595
1779
  return {
1596
1780
  audio: responseBody.audio,
1597
- warnings: (_a9 = responseBody.warnings) != null ? _a9 : [],
1781
+ warnings: (_a11 = responseBody.warnings) != null ? _a11 : [],
1598
1782
  providerMetadata: responseBody.providerMetadata,
1599
1783
  response: {
1600
1784
  timestamp: /* @__PURE__ */ new Date(),
@@ -1632,6 +1816,11 @@ var gatewaySpeechWarningSchema = z12.discriminatedUnion("type", [
1632
1816
  feature: z12.string(),
1633
1817
  details: z12.string().optional()
1634
1818
  }),
1819
+ z12.object({
1820
+ type: z12.literal("deprecated"),
1821
+ setting: z12.string(),
1822
+ message: z12.string()
1823
+ }),
1635
1824
  z12.object({
1636
1825
  type: z12.literal("other"),
1637
1826
  message: z12.string()
@@ -1669,7 +1858,7 @@ var GatewayTranscriptionModel = class {
1669
1858
  headers,
1670
1859
  abortSignal
1671
1860
  }) {
1672
- var _a9, _b9, _c, _d;
1861
+ var _a11, _b11, _c, _d;
1673
1862
  const resolvedHeaders = this.config.headers ? await resolve10(this.config.headers) : void 0;
1674
1863
  try {
1675
1864
  const {
@@ -1701,8 +1890,8 @@ var GatewayTranscriptionModel = class {
1701
1890
  });
1702
1891
  return {
1703
1892
  text: responseBody.text,
1704
- segments: (_a9 = responseBody.segments) != null ? _a9 : [],
1705
- language: (_b9 = responseBody.language) != null ? _b9 : void 0,
1893
+ segments: (_a11 = responseBody.segments) != null ? _a11 : [],
1894
+ language: (_b11 = responseBody.language) != null ? _b11 : void 0,
1706
1895
  durationInSeconds: (_c = responseBody.durationInSeconds) != null ? _c : void 0,
1707
1896
  warnings: (_d = responseBody.warnings) != null ? _d : [],
1708
1897
  providerMetadata: responseBody.providerMetadata,
@@ -1742,6 +1931,11 @@ var gatewayTranscriptionWarningSchema = z13.discriminatedUnion("type", [
1742
1931
  feature: z13.string(),
1743
1932
  details: z13.string().optional()
1744
1933
  }),
1934
+ z13.object({
1935
+ type: z13.literal("deprecated"),
1936
+ setting: z13.string(),
1937
+ message: z13.string()
1938
+ }),
1745
1939
  z13.object({
1746
1940
  type: z13.literal("other"),
1747
1941
  message: z13.string()
@@ -1762,68 +1956,256 @@ var gatewayTranscriptionResponseSchema = z13.object({
1762
1956
  providerMetadata: z13.record(z13.string(), providerMetadataEntrySchema4).optional()
1763
1957
  });
1764
1958
 
1765
- // src/tool/parallel-search.ts
1959
+ // src/gateway-realtime-model.ts
1960
+ var GatewayRealtimeModel = class {
1961
+ constructor(modelId, config) {
1962
+ this.specificationVersion = "v4";
1963
+ this.modelId = modelId;
1964
+ this.provider = config.provider;
1965
+ this.config = config;
1966
+ }
1967
+ /**
1968
+ * Mints a single-use, short-lived client secret (`vcst_`) the browser uses to
1969
+ * open the realtime WebSocket without ever holding the long-lived Gateway
1970
+ * credential. The customer's server calls this (via
1971
+ * `gateway.experimental_realtime.getToken`) and hands the returned token to
1972
+ * the browser, which connects with it through the `ai-gateway-auth.<token>`
1973
+ * subprotocol. `expiresAfterSeconds` is forwarded to the mint endpoint;
1974
+ * `sessionConfig` is intentionally unused here — it is applied later via the
1975
+ * normalized `session-update` event.
1976
+ */
1977
+ async doCreateClientSecret(options) {
1978
+ const secret = await this.config.createClientSecret({
1979
+ modelId: this.modelId,
1980
+ ...(options == null ? void 0 : options.expiresAfterSeconds) != null && {
1981
+ expiresAfterSeconds: options.expiresAfterSeconds
1982
+ }
1983
+ });
1984
+ return {
1985
+ token: secret.token,
1986
+ url: toGatewayRealtimeUrl(this.config.baseURL, this.modelId),
1987
+ ...secret.expiresAt != null && { expiresAt: secret.expiresAt }
1988
+ };
1989
+ }
1990
+ getWebSocketConfig(options) {
1991
+ return {
1992
+ url: options.url,
1993
+ protocols: getGatewayRealtimeProtocols(options.token, {
1994
+ teamIdOrSlug: this.config.teamIdOrSlug
1995
+ })
1996
+ };
1997
+ }
1998
+ parseServerEvent(raw) {
1999
+ return raw;
2000
+ }
2001
+ serializeClientEvent(event) {
2002
+ return event;
2003
+ }
2004
+ buildSessionConfig(config) {
2005
+ return config;
2006
+ }
2007
+ };
2008
+ function toGatewayRealtimeUrl(baseURL, modelId) {
2009
+ const url = new URL(`${baseURL.replace(/^http/, "ws")}/realtime-model`);
2010
+ url.searchParams.set("ai-model-id", modelId);
2011
+ return url.toString();
2012
+ }
2013
+
2014
+ // src/tool/exa-search.ts
1766
2015
  import {
1767
2016
  createProviderExecutedToolFactory,
1768
2017
  lazySchema as lazySchema9,
1769
2018
  zodSchema as zodSchema9
1770
2019
  } from "@ai-sdk/provider-utils";
1771
2020
  import { z as z14 } from "zod";
1772
- var parallelSearchInputSchema = lazySchema9(
2021
+ var exaSearchInputSchema = lazySchema9(
1773
2022
  () => zodSchema9(
1774
2023
  z14.object({
1775
- objective: z14.string().describe(
2024
+ query: z14.string().describe("Natural-language web search query. This is required."),
2025
+ type: z14.enum(["auto", "fast", "instant"]).optional().describe(
2026
+ "Search method. Use auto for the default balance of speed and quality."
2027
+ ),
2028
+ num_results: z14.number().optional().describe("Maximum number of results to return (1-100, default: 10)."),
2029
+ category: z14.enum([
2030
+ "company",
2031
+ "people",
2032
+ "research paper",
2033
+ "news",
2034
+ "personal site",
2035
+ "financial report"
2036
+ ]).optional().describe("Optional content category to focus results."),
2037
+ user_location: z14.string().optional().describe("Two-letter ISO country code such as 'US'."),
2038
+ include_domains: z14.array(z14.string()).optional().describe("Only return results from these domains."),
2039
+ exclude_domains: z14.array(z14.string()).optional().describe("Exclude results from these domains."),
2040
+ start_published_date: z14.string().optional().describe("Only return links published after this ISO 8601 date."),
2041
+ end_published_date: z14.string().optional().describe("Only return links published before this ISO 8601 date."),
2042
+ contents: z14.object({
2043
+ text: z14.union([
2044
+ z14.boolean(),
2045
+ z14.object({
2046
+ max_characters: z14.number().optional(),
2047
+ include_html_tags: z14.boolean().optional(),
2048
+ verbosity: z14.enum(["compact", "standard", "full"]).optional(),
2049
+ include_sections: z14.array(
2050
+ z14.enum([
2051
+ "header",
2052
+ "navigation",
2053
+ "banner",
2054
+ "body",
2055
+ "sidebar",
2056
+ "footer",
2057
+ "metadata"
2058
+ ])
2059
+ ).optional(),
2060
+ exclude_sections: z14.array(
2061
+ z14.enum([
2062
+ "header",
2063
+ "navigation",
2064
+ "banner",
2065
+ "body",
2066
+ "sidebar",
2067
+ "footer",
2068
+ "metadata"
2069
+ ])
2070
+ ).optional()
2071
+ })
2072
+ ]).optional(),
2073
+ highlights: z14.union([
2074
+ z14.boolean(),
2075
+ z14.object({
2076
+ query: z14.string().optional(),
2077
+ max_characters: z14.number().optional()
2078
+ })
2079
+ ]).optional(),
2080
+ max_age_hours: z14.number().optional(),
2081
+ livecrawl_timeout: z14.number().optional(),
2082
+ subpages: z14.number().optional(),
2083
+ subpage_target: z14.union([z14.string(), z14.array(z14.string())]).optional(),
2084
+ extras: z14.object({
2085
+ links: z14.number().optional(),
2086
+ image_links: z14.number().optional()
2087
+ }).optional()
2088
+ }).optional().describe("Controls extracted page content and freshness.")
2089
+ })
2090
+ )
2091
+ );
2092
+ var exaSearchOutputSchema = lazySchema9(
2093
+ () => zodSchema9(
2094
+ z14.union([
2095
+ z14.object({
2096
+ requestId: z14.string(),
2097
+ searchType: z14.string().optional(),
2098
+ resolvedSearchType: z14.string().optional(),
2099
+ results: z14.array(
2100
+ z14.object({
2101
+ title: z14.string(),
2102
+ url: z14.string(),
2103
+ id: z14.string(),
2104
+ publishedDate: z14.string().nullable().optional(),
2105
+ author: z14.string().nullable().optional(),
2106
+ image: z14.string().nullable().optional(),
2107
+ favicon: z14.string().nullable().optional(),
2108
+ text: z14.string().optional(),
2109
+ highlights: z14.array(z14.string()).optional(),
2110
+ highlightScores: z14.array(z14.number()).optional(),
2111
+ summary: z14.string().optional(),
2112
+ subpages: z14.array(z14.any()).optional(),
2113
+ extras: z14.object({
2114
+ links: z14.array(z14.string()).optional(),
2115
+ imageLinks: z14.array(z14.string()).optional()
2116
+ }).optional()
2117
+ })
2118
+ ),
2119
+ costDollars: z14.object({
2120
+ total: z14.number().optional(),
2121
+ search: z14.record(z14.number()).optional()
2122
+ }).optional()
2123
+ }),
2124
+ z14.object({
2125
+ error: z14.enum([
2126
+ "api_error",
2127
+ "rate_limit",
2128
+ "timeout",
2129
+ "invalid_input",
2130
+ "configuration_error",
2131
+ "execution_error",
2132
+ "unknown"
2133
+ ]),
2134
+ statusCode: z14.number().optional(),
2135
+ message: z14.string()
2136
+ })
2137
+ ])
2138
+ )
2139
+ );
2140
+ var exaSearchToolFactory = createProviderExecutedToolFactory({
2141
+ id: "gateway.exa_search",
2142
+ inputSchema: exaSearchInputSchema,
2143
+ outputSchema: exaSearchOutputSchema
2144
+ });
2145
+ var exaSearch = (config = {}) => exaSearchToolFactory(config);
2146
+
2147
+ // src/tool/parallel-search.ts
2148
+ import {
2149
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
2150
+ lazySchema as lazySchema10,
2151
+ zodSchema as zodSchema10
2152
+ } from "@ai-sdk/provider-utils";
2153
+ import { z as z15 } from "zod";
2154
+ var parallelSearchInputSchema = lazySchema10(
2155
+ () => zodSchema10(
2156
+ z15.object({
2157
+ objective: z15.string().describe(
1776
2158
  "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
1777
2159
  ),
1778
- search_queries: z14.array(z14.string()).optional().describe(
2160
+ search_queries: z15.array(z15.string()).optional().describe(
1779
2161
  "Optional search queries to supplement the objective. Maximum 200 characters per query."
1780
2162
  ),
1781
- mode: z14.enum(["one-shot", "agentic"]).optional().describe(
2163
+ mode: z15.enum(["one-shot", "agentic"]).optional().describe(
1782
2164
  'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
1783
2165
  ),
1784
- max_results: z14.number().optional().describe(
2166
+ max_results: z15.number().optional().describe(
1785
2167
  "Maximum number of results to return (1-20). Defaults to 10 if not specified."
1786
2168
  ),
1787
- source_policy: z14.object({
1788
- include_domains: z14.array(z14.string()).optional().describe("List of domains to include in search results."),
1789
- exclude_domains: z14.array(z14.string()).optional().describe("List of domains to exclude from search results."),
1790
- after_date: z14.string().optional().describe(
2169
+ source_policy: z15.object({
2170
+ include_domains: z15.array(z15.string()).optional().describe("List of domains to include in search results."),
2171
+ exclude_domains: z15.array(z15.string()).optional().describe("List of domains to exclude from search results."),
2172
+ after_date: z15.string().optional().describe(
1791
2173
  "Only include results published after this date (ISO 8601 format)."
1792
2174
  )
1793
2175
  }).optional().describe(
1794
2176
  "Source policy for controlling which domains to include/exclude and freshness."
1795
2177
  ),
1796
- excerpts: z14.object({
1797
- max_chars_per_result: z14.number().optional().describe("Maximum characters per result."),
1798
- max_chars_total: z14.number().optional().describe("Maximum total characters across all results.")
2178
+ excerpts: z15.object({
2179
+ max_chars_per_result: z15.number().optional().describe("Maximum characters per result."),
2180
+ max_chars_total: z15.number().optional().describe("Maximum total characters across all results.")
1799
2181
  }).optional().describe("Excerpt configuration for controlling result length."),
1800
- fetch_policy: z14.object({
1801
- max_age_seconds: z14.number().optional().describe(
2182
+ fetch_policy: z15.object({
2183
+ max_age_seconds: z15.number().optional().describe(
1802
2184
  "Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
1803
2185
  )
1804
2186
  }).optional().describe("Fetch policy for controlling content freshness.")
1805
2187
  })
1806
2188
  )
1807
2189
  );
1808
- var parallelSearchOutputSchema = lazySchema9(
1809
- () => zodSchema9(
1810
- z14.union([
2190
+ var parallelSearchOutputSchema = lazySchema10(
2191
+ () => zodSchema10(
2192
+ z15.union([
1811
2193
  // Success response
1812
- z14.object({
1813
- searchId: z14.string(),
1814
- results: z14.array(
1815
- z14.object({
1816
- url: z14.string(),
1817
- title: z14.string(),
1818
- excerpt: z14.string(),
1819
- publishDate: z14.string().nullable().optional(),
1820
- relevanceScore: z14.number().optional()
2194
+ z15.object({
2195
+ searchId: z15.string(),
2196
+ results: z15.array(
2197
+ z15.object({
2198
+ url: z15.string(),
2199
+ title: z15.string(),
2200
+ excerpt: z15.string(),
2201
+ publishDate: z15.string().nullable().optional(),
2202
+ relevanceScore: z15.number().optional()
1821
2203
  })
1822
2204
  )
1823
2205
  }),
1824
2206
  // Error response
1825
- z14.object({
1826
- error: z14.enum([
2207
+ z15.object({
2208
+ error: z15.enum([
1827
2209
  "api_error",
1828
2210
  "rate_limit",
1829
2211
  "timeout",
@@ -1831,13 +2213,13 @@ var parallelSearchOutputSchema = lazySchema9(
1831
2213
  "configuration_error",
1832
2214
  "unknown"
1833
2215
  ]),
1834
- statusCode: z14.number().optional(),
1835
- message: z14.string()
2216
+ statusCode: z15.number().optional(),
2217
+ message: z15.string()
1836
2218
  })
1837
2219
  ])
1838
2220
  )
1839
2221
  );
1840
- var parallelSearchToolFactory = createProviderExecutedToolFactory({
2222
+ var parallelSearchToolFactory = createProviderExecutedToolFactory2({
1841
2223
  id: "gateway.parallel_search",
1842
2224
  inputSchema: parallelSearchInputSchema,
1843
2225
  outputSchema: parallelSearchOutputSchema
@@ -1846,85 +2228,85 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
1846
2228
 
1847
2229
  // src/tool/perplexity-search.ts
1848
2230
  import {
1849
- createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
1850
- lazySchema as lazySchema10,
1851
- zodSchema as zodSchema10
2231
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
2232
+ lazySchema as lazySchema11,
2233
+ zodSchema as zodSchema11
1852
2234
  } from "@ai-sdk/provider-utils";
1853
- import { z as z15 } from "zod";
1854
- var perplexitySearchInputSchema = lazySchema10(
1855
- () => zodSchema10(
1856
- z15.object({
1857
- query: z15.union([z15.string(), z15.array(z15.string())]).describe(
2235
+ import { z as z16 } from "zod";
2236
+ var perplexitySearchInputSchema = lazySchema11(
2237
+ () => zodSchema11(
2238
+ z16.object({
2239
+ query: z16.union([z16.string(), z16.array(z16.string())]).describe(
1858
2240
  "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
1859
2241
  ),
1860
- max_results: z15.number().optional().describe(
2242
+ max_results: z16.number().optional().describe(
1861
2243
  "Maximum number of search results to return (1-20, default: 10)"
1862
2244
  ),
1863
- max_tokens_per_page: z15.number().optional().describe(
2245
+ max_tokens_per_page: z16.number().optional().describe(
1864
2246
  "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
1865
2247
  ),
1866
- max_tokens: z15.number().optional().describe(
2248
+ max_tokens: z16.number().optional().describe(
1867
2249
  "Maximum total tokens across all search results (default: 25000, max: 1000000)"
1868
2250
  ),
1869
- country: z15.string().optional().describe(
2251
+ country: z16.string().optional().describe(
1870
2252
  "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
1871
2253
  ),
1872
- search_domain_filter: z15.array(z15.string()).optional().describe(
2254
+ search_domain_filter: z16.array(z16.string()).optional().describe(
1873
2255
  "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
1874
2256
  ),
1875
- search_language_filter: z15.array(z15.string()).optional().describe(
2257
+ search_language_filter: z16.array(z16.string()).optional().describe(
1876
2258
  "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
1877
2259
  ),
1878
- search_after_date: z15.string().optional().describe(
2260
+ search_after_date: z16.string().optional().describe(
1879
2261
  "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1880
2262
  ),
1881
- search_before_date: z15.string().optional().describe(
2263
+ search_before_date: z16.string().optional().describe(
1882
2264
  "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1883
2265
  ),
1884
- last_updated_after_filter: z15.string().optional().describe(
2266
+ last_updated_after_filter: z16.string().optional().describe(
1885
2267
  "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1886
2268
  ),
1887
- last_updated_before_filter: z15.string().optional().describe(
2269
+ last_updated_before_filter: z16.string().optional().describe(
1888
2270
  "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1889
2271
  ),
1890
- search_recency_filter: z15.enum(["day", "week", "month", "year"]).optional().describe(
2272
+ search_recency_filter: z16.enum(["day", "week", "month", "year"]).optional().describe(
1891
2273
  "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
1892
2274
  )
1893
2275
  })
1894
2276
  )
1895
2277
  );
1896
- var perplexitySearchOutputSchema = lazySchema10(
1897
- () => zodSchema10(
1898
- z15.union([
2278
+ var perplexitySearchOutputSchema = lazySchema11(
2279
+ () => zodSchema11(
2280
+ z16.union([
1899
2281
  // Success response
1900
- z15.object({
1901
- results: z15.array(
1902
- z15.object({
1903
- title: z15.string(),
1904
- url: z15.string(),
1905
- snippet: z15.string(),
1906
- date: z15.string().optional(),
1907
- lastUpdated: z15.string().optional()
2282
+ z16.object({
2283
+ results: z16.array(
2284
+ z16.object({
2285
+ title: z16.string(),
2286
+ url: z16.string(),
2287
+ snippet: z16.string(),
2288
+ date: z16.string().optional(),
2289
+ lastUpdated: z16.string().optional()
1908
2290
  })
1909
2291
  ),
1910
- id: z15.string()
2292
+ id: z16.string()
1911
2293
  }),
1912
2294
  // Error response
1913
- z15.object({
1914
- error: z15.enum([
2295
+ z16.object({
2296
+ error: z16.enum([
1915
2297
  "api_error",
1916
2298
  "rate_limit",
1917
2299
  "timeout",
1918
2300
  "invalid_input",
1919
2301
  "unknown"
1920
2302
  ]),
1921
- statusCode: z15.number().optional(),
1922
- message: z15.string()
2303
+ statusCode: z16.number().optional(),
2304
+ message: z16.string()
1923
2305
  })
1924
2306
  ])
1925
2307
  )
1926
2308
  );
1927
- var perplexitySearchToolFactory = createProviderExecutedToolFactory2({
2309
+ var perplexitySearchToolFactory = createProviderExecutedToolFactory3({
1928
2310
  id: "gateway.perplexity_search",
1929
2311
  inputSchema: perplexitySearchInputSchema,
1930
2312
  outputSchema: perplexitySearchOutputSchema
@@ -1933,6 +2315,14 @@ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
1933
2315
 
1934
2316
  // src/gateway-tools.ts
1935
2317
  var gatewayTools = {
2318
+ /**
2319
+ * Search the web using Exa for current information and token-efficient
2320
+ * excerpts optimized for agent workflows.
2321
+ *
2322
+ * Supports search type, category, domain, date, location, and content
2323
+ * extraction controls.
2324
+ */
2325
+ exaSearch,
1936
2326
  /**
1937
2327
  * Search the web using Parallel AI's Search API for LLM-optimized excerpts.
1938
2328
  *
@@ -1956,22 +2346,26 @@ var gatewayTools = {
1956
2346
  import { getContext } from "@vercel/oidc";
1957
2347
  import { getVercelOidcToken } from "@vercel/oidc";
1958
2348
  async function getVercelRequestId() {
1959
- var _a9;
1960
- return (_a9 = getContext().headers) == null ? void 0 : _a9["x-vercel-id"];
2349
+ var _a11;
2350
+ return (_a11 = getContext().headers) == null ? void 0 : _a11["x-vercel-id"];
1961
2351
  }
1962
2352
 
1963
2353
  // src/version.ts
1964
- var VERSION = true ? "4.0.0-canary.98" : "0.0.0-test";
2354
+ var VERSION = true ? "4.0.0" : "0.0.0-test";
1965
2355
 
1966
2356
  // src/gateway-provider.ts
1967
2357
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
2358
+ var gatewayClientSecretResponseSchema = z17.object({
2359
+ token: z17.string(),
2360
+ expiresAt: z17.number().nullish()
2361
+ });
1968
2362
  function createGateway(options = {}) {
1969
- var _a9, _b9;
2363
+ var _a11, _b11;
1970
2364
  let pendingMetadata = null;
1971
2365
  let metadataCache = null;
1972
- const cacheRefreshMillis = (_a9 = options.metadataCacheRefreshMillis) != null ? _a9 : 1e3 * 60 * 5;
2366
+ const cacheRefreshMillis = (_a11 = options.metadataCacheRefreshMillis) != null ? _a11 : 1e3 * 60 * 5;
1973
2367
  let lastFetchTime = 0;
1974
- const baseURL = (_b9 = withoutTrailingSlash(options.baseURL)) != null ? _b9 : "https://ai-gateway.vercel.sh/v4/ai";
2368
+ const baseURL = (_b11 = withoutTrailingSlash(options.baseURL)) != null ? _b11 : "https://ai-gateway.vercel.sh/v4/ai";
1975
2369
  const createAuthHeaders = (auth) => withUserAgentSuffix(
1976
2370
  {
1977
2371
  Authorization: `Bearer ${auth.token}`,
@@ -1994,6 +2388,50 @@ function createGateway(options = {}) {
1994
2388
  });
1995
2389
  }
1996
2390
  };
2391
+ const getRealtimeAuthToken = async () => {
2392
+ try {
2393
+ return await getGatewayAuthToken(options);
2394
+ } catch (error) {
2395
+ throw GatewayAuthenticationError.createContextualError({
2396
+ apiKeyProvided: false,
2397
+ oidcTokenProvided: false,
2398
+ statusCode: 401,
2399
+ cause: error
2400
+ });
2401
+ }
2402
+ };
2403
+ const mintRealtimeClientSecret = async (params) => {
2404
+ assertGatewayRealtimeServerEnvironment();
2405
+ const auth = await getRealtimeAuthToken();
2406
+ const headers = createAuthHeaders(auth);
2407
+ const url = new URL("/v1/realtime/client-secrets", baseURL).toString();
2408
+ try {
2409
+ const { value } = await postJsonToApi8({
2410
+ url,
2411
+ headers,
2412
+ body: {
2413
+ model: params.modelId,
2414
+ ...params.expiresAfterSeconds != null && {
2415
+ expiresIn: params.expiresAfterSeconds
2416
+ }
2417
+ },
2418
+ successfulResponseHandler: createJsonResponseHandler10(
2419
+ gatewayClientSecretResponseSchema
2420
+ ),
2421
+ failedResponseHandler: createJsonErrorResponseHandler11({
2422
+ errorSchema: z17.any(),
2423
+ errorToMessage: (data) => data
2424
+ }),
2425
+ fetch: options.fetch
2426
+ });
2427
+ return {
2428
+ token: value.token,
2429
+ ...value.expiresAt != null && { expiresAt: value.expiresAt }
2430
+ };
2431
+ } catch (error) {
2432
+ throw await asGatewayError(error, await parseAuthMethod(headers));
2433
+ }
2434
+ };
1997
2435
  const createO11yHeaders = () => {
1998
2436
  const deploymentId = loadOptionalSetting({
1999
2437
  settingValue: void 0,
@@ -2032,8 +2470,8 @@ function createGateway(options = {}) {
2032
2470
  });
2033
2471
  };
2034
2472
  const getAvailableModels = async () => {
2035
- var _a10, _b10, _c;
2036
- const now = (_c = (_b10 = (_a10 = options._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b10.call(_a10).getTime()) != null ? _c : Date.now();
2473
+ var _a12, _b12, _c;
2474
+ const now = (_c = (_b12 = (_a12 = options._internal) == null ? void 0 : _a12.currentDate) == null ? void 0 : _b12.call(_a12).getTime()) != null ? _c : Date.now();
2037
2475
  if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
2038
2476
  lastFetchTime = now;
2039
2477
  pendingMetadata = new GatewayFetchMetadata({
@@ -2164,6 +2602,27 @@ function createGateway(options = {}) {
2164
2602
  };
2165
2603
  provider.transcriptionModel = createTranscriptionModel;
2166
2604
  provider.transcription = createTranscriptionModel;
2605
+ const createRealtimeModel = (modelId) => new GatewayRealtimeModel(modelId, {
2606
+ provider: "gateway.realtime",
2607
+ baseURL,
2608
+ teamIdOrSlug: options.teamIdOrSlug,
2609
+ createClientSecret: mintRealtimeClientSecret
2610
+ });
2611
+ provider.experimental_realtime = Object.assign(
2612
+ (modelId) => createRealtimeModel(modelId),
2613
+ {
2614
+ getToken: async (tokenOptions) => {
2615
+ const { model: modelId, ...secretOptions } = tokenOptions;
2616
+ const model = createRealtimeModel(modelId);
2617
+ const secret = await model.doCreateClientSecret(secretOptions);
2618
+ return {
2619
+ token: secret.token,
2620
+ url: secret.url,
2621
+ ...secret.expiresAt != null && { expiresAt: secret.expiresAt }
2622
+ };
2623
+ }
2624
+ }
2625
+ );
2167
2626
  provider.chat = provider.languageModel;
2168
2627
  provider.embedding = provider.embeddingModel;
2169
2628
  provider.image = provider.imageModel;
@@ -2189,9 +2648,21 @@ async function getGatewayAuthToken(options) {
2189
2648
  authMethod: "oidc"
2190
2649
  };
2191
2650
  }
2651
+ function assertGatewayRealtimeServerEnvironment() {
2652
+ if (typeof globalThis.window !== "undefined") {
2653
+ throw new Error(
2654
+ "AI Gateway realtime client secrets must be minted server-side: minting needs your Gateway credential, which must never reach the browser. Call gateway.experimental_realtime.getToken() from your server and pass the returned token to the client."
2655
+ );
2656
+ }
2657
+ }
2192
2658
  export {
2659
+ GATEWAY_AUTH_SUBPROTOCOL_PREFIX,
2660
+ GATEWAY_REALTIME_SUBPROTOCOL,
2661
+ GATEWAY_TEAM_SUBPROTOCOL_PREFIX,
2193
2662
  GatewayAuthenticationError,
2194
2663
  GatewayError,
2664
+ GatewayFailedDependencyError,
2665
+ GatewayForbiddenError,
2195
2666
  GatewayInternalServerError,
2196
2667
  GatewayInvalidRequestError,
2197
2668
  GatewayModelNotFoundError,
@@ -2200,6 +2671,9 @@ export {
2200
2671
  VERSION,
2201
2672
  createGateway,
2202
2673
  createGateway as createGatewayProvider,
2203
- gateway
2674
+ gateway,
2675
+ getGatewayRealtimeAuthToken,
2676
+ getGatewayRealtimeProtocols,
2677
+ getGatewayRealtimeTeamIdOrSlug
2204
2678
  };
2205
2679
  //# sourceMappingURL=index.js.map