@ai-sdk/gateway 4.0.75 → 4.0.76

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
@@ -1010,218 +1010,27 @@ var gatewayGenerationInfoResponseSchema = lazySchema7(
1010
1010
  )
1011
1011
  );
1012
1012
 
1013
- // src/gateway-language-model-batch.ts
1013
+ // src/gateway-batch.ts
1014
1014
  import {
1015
- combineHeaders as combineHeaders2,
1016
- convertAsyncIteratorToReadableStream,
1017
- createJsonErrorResponseHandler as createJsonErrorResponseHandler5,
1018
- createJsonLinesResponseHandler,
1019
- createJsonResponseHandler as createJsonResponseHandler5,
1020
- getErrorMessage as getErrorMessage5,
1021
- normalizeBatchRequestCounts,
1022
- postJsonToApi as postJsonToApi2,
1023
- resolve as resolve5,
1024
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
1025
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
1026
- } from "@ai-sdk/provider-utils";
1027
-
1028
- // src/gateway-language-model.ts
1015
+ InvalidArgumentError
1016
+ } from "@ai-sdk/provider";
1029
1017
  import {
1030
1018
  combineHeaders,
1031
- createEventSourceResponseHandler,
1019
+ convertAsyncIteratorToReadableStream,
1032
1020
  createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
1021
+ createJsonLinesResponseHandler,
1033
1022
  createJsonResponseHandler as createJsonResponseHandler4,
1034
1023
  getErrorMessage as getErrorMessage4,
1024
+ normalizeBatchRequestCounts,
1035
1025
  postJsonToApi,
1036
- resolve as resolve4,
1037
- serializeModelOptions,
1038
- WORKFLOW_SERIALIZE,
1039
- WORKFLOW_DESERIALIZE
1026
+ resolve as resolve4
1040
1027
  } from "@ai-sdk/provider-utils";
1041
- var GatewayLanguageModel = class _GatewayLanguageModel {
1042
- constructor(modelId, config) {
1043
- this.modelId = modelId;
1028
+ var GatewayBatch = class {
1029
+ constructor(config) {
1044
1030
  this.config = config;
1045
1031
  this.specificationVersion = "v4";
1046
1032
  this.supportedUrls = { "*/*": [/.*/] };
1047
- }
1048
- static [WORKFLOW_SERIALIZE](model) {
1049
- return serializeModelOptions({
1050
- modelId: model.modelId,
1051
- config: model.config
1052
- });
1053
- }
1054
- static [WORKFLOW_DESERIALIZE](options) {
1055
- return new _GatewayLanguageModel(options.modelId, options.config);
1056
- }
1057
- get provider() {
1058
- return this.config.provider;
1059
- }
1060
- async getArgs(options) {
1061
- const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
1062
- return {
1063
- args: this.maybeEncodeFileParts(optionsWithoutSignal),
1064
- warnings: []
1065
- };
1066
- }
1067
- async doGenerate(options) {
1068
- const { args, warnings } = await this.getArgs(options);
1069
- const { abortSignal } = options;
1070
- const resolvedHeaders = this.config.headers ? await resolve4(this.config.headers) : void 0;
1071
- try {
1072
- const {
1073
- responseHeaders,
1074
- value: responseBody,
1075
- rawValue: rawResponse
1076
- } = await postJsonToApi({
1077
- url: this.getUrl(),
1078
- headers: combineHeaders(
1079
- resolvedHeaders,
1080
- options.headers,
1081
- this.getModelConfigHeaders(this.modelId, false),
1082
- await resolve4(this.config.o11yHeaders)
1083
- ),
1084
- body: args,
1085
- successfulResponseHandler: createJsonResponseHandler4(z.any()),
1086
- failedResponseHandler: createJsonErrorResponseHandler4({
1087
- errorSchema: z.any(),
1088
- errorToMessage: (data) => {
1089
- var _a12;
1090
- return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1091
- }
1092
- }),
1093
- ...abortSignal && { abortSignal },
1094
- fetch: this.config.fetch
1095
- });
1096
- return {
1097
- ...responseBody,
1098
- request: { body: args },
1099
- response: { headers: responseHeaders, body: rawResponse },
1100
- warnings
1101
- };
1102
- } catch (error) {
1103
- throw await asGatewayError(
1104
- error,
1105
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1106
- );
1107
- }
1108
- }
1109
- async doStream(options) {
1110
- const { args, warnings } = await this.getArgs(options);
1111
- const { abortSignal } = options;
1112
- const resolvedHeaders = this.config.headers ? await resolve4(this.config.headers) : void 0;
1113
- try {
1114
- const { value: response, responseHeaders } = await postJsonToApi({
1115
- url: this.getUrl(),
1116
- headers: combineHeaders(
1117
- resolvedHeaders,
1118
- options.headers,
1119
- this.getModelConfigHeaders(this.modelId, true),
1120
- await resolve4(this.config.o11yHeaders)
1121
- ),
1122
- body: args,
1123
- successfulResponseHandler: createEventSourceResponseHandler(z.any()),
1124
- failedResponseHandler: createJsonErrorResponseHandler4({
1125
- errorSchema: z.any(),
1126
- errorToMessage: (data) => {
1127
- var _a12;
1128
- return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1129
- }
1130
- }),
1131
- ...abortSignal && { abortSignal },
1132
- fetch: this.config.fetch
1133
- });
1134
- return {
1135
- stream: response.pipeThrough(
1136
- new TransformStream({
1137
- start(controller) {
1138
- if (warnings.length > 0) {
1139
- controller.enqueue({ type: "stream-start", warnings });
1140
- }
1141
- },
1142
- transform(chunk, controller) {
1143
- if (chunk.success) {
1144
- const streamPart = chunk.value;
1145
- if (streamPart.type === "raw" && !options.includeRawChunks) {
1146
- return;
1147
- }
1148
- if (streamPart.type === "response-metadata" && streamPart.timestamp && typeof streamPart.timestamp === "string") {
1149
- streamPart.timestamp = new Date(streamPart.timestamp);
1150
- }
1151
- controller.enqueue(streamPart);
1152
- } else {
1153
- controller.error(
1154
- chunk.error
1155
- );
1156
- }
1157
- }
1158
- })
1159
- ),
1160
- request: { body: args },
1161
- response: { headers: responseHeaders }
1162
- };
1163
- } catch (error) {
1164
- throw await asGatewayError(
1165
- error,
1166
- await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1167
- );
1168
- }
1169
- }
1170
- /**
1171
- * Encodes inline `Uint8Array` file data to a base64 string in place.
1172
- * @param options - The options to encode.
1173
- * @returns The options with the file data encoded.
1174
- */
1175
- maybeEncodeFileParts(options) {
1176
- for (const message of options.prompt) {
1177
- if (!Array.isArray(message.content)) {
1178
- continue;
1179
- }
1180
- for (const part of message.content) {
1181
- if (part.type === "file" || part.type === "reasoning-file") {
1182
- part.data = maybeBase64EncodeFileData(part.data);
1183
- } else if (part.type === "tool-result" && part.output.type === "content") {
1184
- for (const contentPart of part.output.value) {
1185
- if (contentPart.type === "file") {
1186
- contentPart.data = maybeBase64EncodeFileData(contentPart.data);
1187
- }
1188
- }
1189
- }
1190
- }
1191
- }
1192
- return options;
1193
- }
1194
- getUrl() {
1195
- return `${this.config.baseURL}/language-model`;
1196
- }
1197
- getModelConfigHeaders(modelId, streaming) {
1198
- return {
1199
- "ai-language-model-specification-version": "4",
1200
- "ai-language-model-id": modelId,
1201
- "ai-language-model-streaming": String(streaming)
1202
- };
1203
- }
1204
- };
1205
- function maybeBase64EncodeFileData(data) {
1206
- if (data.type === "data") {
1207
- const bytes = data.data;
1208
- if (bytes instanceof Uint8Array) {
1209
- return { ...data, data: Buffer.from(bytes).toString("base64") };
1210
- }
1211
- }
1212
- return data;
1213
- }
1214
-
1215
- // src/gateway-language-model-batch.ts
1216
- var GatewayBatchLanguageModel = class _GatewayBatchLanguageModel extends GatewayLanguageModel {
1217
- static [WORKFLOW_SERIALIZE2](model) {
1218
- return GatewayLanguageModel[WORKFLOW_SERIALIZE2](model);
1219
- }
1220
- static [WORKFLOW_DESERIALIZE2](options) {
1221
- return new _GatewayBatchLanguageModel(options.modelId, options.config);
1222
- }
1223
- constructor(modelId, config) {
1224
- super(modelId, config);
1033
+ this.provider = `${config.provider}.batch`;
1225
1034
  }
1226
1035
  /**
1227
1036
  * Starts a durable batch of text-generation requests through the Gateway's
@@ -1230,7 +1039,7 @@ var GatewayBatchLanguageModel = class _GatewayBatchLanguageModel extends Gateway
1230
1039
  * server-side, so status and results always route back through the
1231
1040
  * Gateway job.
1232
1041
  */
1233
- async experimental_doStartBatch({
1042
+ async doStartBatch({
1234
1043
  requests,
1235
1044
  providerOptions,
1236
1045
  headers,
@@ -1238,38 +1047,40 @@ var GatewayBatchLanguageModel = class _GatewayBatchLanguageModel extends Gateway
1238
1047
  webhookUrl
1239
1048
  }) {
1240
1049
  var _a12;
1241
- const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
1050
+ const modelId = validateSingleModel(requests);
1051
+ const resolvedHeaders = this.config.headers ? await resolve4(this.config.headers) : void 0;
1242
1052
  const idempotencyKey = getGatewayBatchIdempotencyKey(providerOptions);
1243
1053
  const forwardedProviderOptions = omitGatewayIdempotencyKey(providerOptions);
1244
1054
  try {
1245
- const { value: responseBody } = await postJsonToApi2({
1055
+ const { value: responseBody } = await postJsonToApi({
1246
1056
  url: this.getBatchUrl("start"),
1247
- headers: combineHeaders2(
1057
+ headers: combineHeaders(
1248
1058
  resolvedHeaders,
1249
1059
  headers,
1250
- this.getBatchConfigHeaders(),
1251
- await resolve5(this.config.o11yHeaders),
1060
+ { "ai-model-id": modelId },
1061
+ await resolve4(this.config.o11yHeaders),
1252
1062
  idempotencyKey != null ? { "idempotency-key": idempotencyKey } : void 0
1253
1063
  ),
1254
1064
  body: {
1255
1065
  ...webhookUrl != null && { callbackUrl: webhookUrl },
1256
- modelId: this.modelId,
1257
1066
  requests: requests.map((request) => ({
1258
1067
  id: request.id,
1259
- options: this.maybeEncodeFileParts(request.options)
1068
+ type: request.type,
1069
+ modelId: request.modelId,
1070
+ options: maybeEncodeBatchFileParts(request.options)
1260
1071
  })),
1261
1072
  ...forwardedProviderOptions != null && {
1262
1073
  providerOptions: forwardedProviderOptions
1263
1074
  }
1264
1075
  },
1265
- successfulResponseHandler: createJsonResponseHandler5(
1076
+ successfulResponseHandler: createJsonResponseHandler4(
1266
1077
  gatewayBatchStartResponseSchema
1267
1078
  ),
1268
- failedResponseHandler: createJsonErrorResponseHandler5({
1079
+ failedResponseHandler: createJsonErrorResponseHandler4({
1269
1080
  errorSchema: z.any(),
1270
1081
  errorToMessage: (data) => {
1271
1082
  var _a13;
1272
- return (_a13 = getErrorMessage5(data)) != null ? _a13 : "unknown error";
1083
+ return (_a13 = getErrorMessage4(data)) != null ? _a13 : "unknown error";
1273
1084
  }
1274
1085
  }),
1275
1086
  ...abortSignal && { abortSignal },
@@ -1294,30 +1105,29 @@ var GatewayBatchLanguageModel = class _GatewayBatchLanguageModel extends Gateway
1294
1105
  * Retrieves the lifecycle status of a Gateway batch job
1295
1106
  * (`POST {baseURL}/batch/status`).
1296
1107
  */
1297
- async experimental_doGetBatchStatus({
1108
+ async doGetBatchStatus({
1298
1109
  batchId,
1299
1110
  headers,
1300
1111
  abortSignal
1301
1112
  }) {
1302
- const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
1113
+ const resolvedHeaders = this.config.headers ? await resolve4(this.config.headers) : void 0;
1303
1114
  try {
1304
- const { value: responseBody } = await postJsonToApi2({
1115
+ const { value: responseBody } = await postJsonToApi({
1305
1116
  url: this.getBatchUrl("status"),
1306
- headers: combineHeaders2(
1117
+ headers: combineHeaders(
1307
1118
  resolvedHeaders,
1308
1119
  headers,
1309
- this.getBatchConfigHeaders(),
1310
- await resolve5(this.config.o11yHeaders)
1120
+ await resolve4(this.config.o11yHeaders)
1311
1121
  ),
1312
1122
  body: { batchId },
1313
- successfulResponseHandler: createJsonResponseHandler5(
1123
+ successfulResponseHandler: createJsonResponseHandler4(
1314
1124
  gatewayBatchStatusResponseSchema
1315
1125
  ),
1316
- failedResponseHandler: createJsonErrorResponseHandler5({
1126
+ failedResponseHandler: createJsonErrorResponseHandler4({
1317
1127
  errorSchema: z.any(),
1318
1128
  errorToMessage: (data) => {
1319
1129
  var _a12;
1320
- return (_a12 = getErrorMessage5(data)) != null ? _a12 : "unknown error";
1130
+ return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1321
1131
  }
1322
1132
  }),
1323
1133
  ...abortSignal && { abortSignal },
@@ -1341,30 +1151,29 @@ var GatewayBatchLanguageModel = class _GatewayBatchLanguageModel extends Gateway
1341
1151
  * (id + status) and passed through — the Gateway sanitizes them
1342
1152
  * server-side. The route responds 400 while the batch is non-terminal.
1343
1153
  */
1344
- async experimental_doGetBatchResults({
1154
+ async doGetBatchResults({
1345
1155
  batchId,
1346
1156
  headers,
1347
1157
  abortSignal
1348
1158
  }) {
1349
- const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
1159
+ const resolvedHeaders = this.config.headers ? await resolve4(this.config.headers) : void 0;
1350
1160
  try {
1351
- const { value: lines } = await postJsonToApi2({
1161
+ const { value: lines } = await postJsonToApi({
1352
1162
  url: this.getBatchUrl("results"),
1353
- headers: combineHeaders2(
1163
+ headers: combineHeaders(
1354
1164
  resolvedHeaders,
1355
1165
  headers,
1356
- this.getBatchConfigHeaders(),
1357
- await resolve5(this.config.o11yHeaders)
1166
+ await resolve4(this.config.o11yHeaders)
1358
1167
  ),
1359
1168
  body: { batchId },
1360
1169
  successfulResponseHandler: createJsonLinesResponseHandler(
1361
1170
  gatewayBatchItemResultLineSchema
1362
1171
  ),
1363
- failedResponseHandler: createJsonErrorResponseHandler5({
1172
+ failedResponseHandler: createJsonErrorResponseHandler4({
1364
1173
  errorSchema: z.any(),
1365
1174
  errorToMessage: (data) => {
1366
1175
  var _a12;
1367
- return (_a12 = getErrorMessage5(data)) != null ? _a12 : "unknown error";
1176
+ return (_a12 = getErrorMessage4(data)) != null ? _a12 : "unknown error";
1368
1177
  }
1369
1178
  }),
1370
1179
  ...abortSignal && { abortSignal },
@@ -1386,12 +1195,54 @@ var GatewayBatchLanguageModel = class _GatewayBatchLanguageModel extends Gateway
1386
1195
  getBatchUrl(path) {
1387
1196
  return `${this.config.baseURL}/batch/${path}`;
1388
1197
  }
1389
- getBatchConfigHeaders() {
1390
- return {
1391
- "ai-model-id": this.modelId
1392
- };
1393
- }
1394
1198
  };
1199
+ function maybeEncodeBatchFileParts(options) {
1200
+ for (const message of options.prompt) {
1201
+ if (!Array.isArray(message.content)) {
1202
+ continue;
1203
+ }
1204
+ for (const part of message.content) {
1205
+ if (part.type === "file" || part.type === "reasoning-file") {
1206
+ part.data = maybeBase64EncodeFileData(part.data);
1207
+ } else if (part.type === "tool-result" && part.output.type === "content") {
1208
+ for (const contentPart of part.output.value) {
1209
+ if (contentPart.type === "file") {
1210
+ contentPart.data = maybeBase64EncodeFileData(contentPart.data);
1211
+ }
1212
+ }
1213
+ }
1214
+ }
1215
+ }
1216
+ return options;
1217
+ }
1218
+ function maybeBase64EncodeFileData(data) {
1219
+ if (data.type === "data") {
1220
+ const bytes = data.data;
1221
+ if (bytes instanceof Uint8Array) {
1222
+ return { ...data, data: Buffer.from(bytes).toString("base64") };
1223
+ }
1224
+ }
1225
+ return data;
1226
+ }
1227
+ function validateSingleModel(requests) {
1228
+ var _a12;
1229
+ const modelId = (_a12 = requests[0]) == null ? void 0 : _a12.modelId;
1230
+ if (modelId == null) {
1231
+ throw new InvalidArgumentError({
1232
+ argument: "requests",
1233
+ message: "The AI Gateway Batch API requires at least one request."
1234
+ });
1235
+ }
1236
+ for (const request of requests) {
1237
+ if (request.modelId !== modelId) {
1238
+ throw new InvalidArgumentError({
1239
+ argument: "requests",
1240
+ message: `The AI Gateway Batch API requires all requests in a batch to use the same model. Found "${modelId}" and "${request.modelId}".`
1241
+ });
1242
+ }
1243
+ }
1244
+ return modelId;
1245
+ }
1395
1246
  function getGatewayBatchIdempotencyKey(providerOptions) {
1396
1247
  const gatewayOptions = providerOptions == null ? void 0 : providerOptions.gateway;
1397
1248
  if (gatewayOptions == null || typeof gatewayOptions !== "object" || Array.isArray(gatewayOptions)) {
@@ -1466,6 +1317,7 @@ async function* convertGatewayBatchResultLines(lines) {
1466
1317
  }
1467
1318
  }
1468
1319
  var gatewayBatchItemResultLineSchema = z.object({
1320
+ type: z.literal("text"),
1469
1321
  id: z.string(),
1470
1322
  status: z.enum(["cancelled", "expired", "failed", "succeeded"])
1471
1323
  }).catchall(z.unknown());
@@ -1505,6 +1357,193 @@ var gatewayBatchStartResponseSchema = gatewayBatchStatusFieldsSchema.extend({
1505
1357
  });
1506
1358
  var gatewayBatchStatusResponseSchema = gatewayBatchStatusFieldsSchema;
1507
1359
 
1360
+ // src/gateway-language-model.ts
1361
+ import {
1362
+ combineHeaders as combineHeaders2,
1363
+ createEventSourceResponseHandler,
1364
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler5,
1365
+ createJsonResponseHandler as createJsonResponseHandler5,
1366
+ getErrorMessage as getErrorMessage5,
1367
+ postJsonToApi as postJsonToApi2,
1368
+ resolve as resolve5,
1369
+ serializeModelOptions,
1370
+ WORKFLOW_SERIALIZE,
1371
+ WORKFLOW_DESERIALIZE
1372
+ } from "@ai-sdk/provider-utils";
1373
+ var GatewayLanguageModel = class _GatewayLanguageModel {
1374
+ constructor(modelId, config) {
1375
+ this.modelId = modelId;
1376
+ this.config = config;
1377
+ this.specificationVersion = "v4";
1378
+ this.supportedUrls = { "*/*": [/.*/] };
1379
+ }
1380
+ static [WORKFLOW_SERIALIZE](model) {
1381
+ return serializeModelOptions({
1382
+ modelId: model.modelId,
1383
+ config: model.config
1384
+ });
1385
+ }
1386
+ static [WORKFLOW_DESERIALIZE](options) {
1387
+ return new _GatewayLanguageModel(options.modelId, options.config);
1388
+ }
1389
+ get provider() {
1390
+ return this.config.provider;
1391
+ }
1392
+ async getArgs(options) {
1393
+ const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
1394
+ return {
1395
+ args: this.maybeEncodeFileParts(optionsWithoutSignal),
1396
+ warnings: []
1397
+ };
1398
+ }
1399
+ async doGenerate(options) {
1400
+ const { args, warnings } = await this.getArgs(options);
1401
+ const { abortSignal } = options;
1402
+ const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
1403
+ try {
1404
+ const {
1405
+ responseHeaders,
1406
+ value: responseBody,
1407
+ rawValue: rawResponse
1408
+ } = await postJsonToApi2({
1409
+ url: this.getUrl(),
1410
+ headers: combineHeaders2(
1411
+ resolvedHeaders,
1412
+ options.headers,
1413
+ this.getModelConfigHeaders(this.modelId, false),
1414
+ await resolve5(this.config.o11yHeaders)
1415
+ ),
1416
+ body: args,
1417
+ successfulResponseHandler: createJsonResponseHandler5(z.any()),
1418
+ failedResponseHandler: createJsonErrorResponseHandler5({
1419
+ errorSchema: z.any(),
1420
+ errorToMessage: (data) => {
1421
+ var _a12;
1422
+ return (_a12 = getErrorMessage5(data)) != null ? _a12 : "unknown error";
1423
+ }
1424
+ }),
1425
+ ...abortSignal && { abortSignal },
1426
+ fetch: this.config.fetch
1427
+ });
1428
+ return {
1429
+ ...responseBody,
1430
+ request: { body: args },
1431
+ response: { headers: responseHeaders, body: rawResponse },
1432
+ warnings
1433
+ };
1434
+ } catch (error) {
1435
+ throw await asGatewayError(
1436
+ error,
1437
+ await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1438
+ );
1439
+ }
1440
+ }
1441
+ async doStream(options) {
1442
+ const { args, warnings } = await this.getArgs(options);
1443
+ const { abortSignal } = options;
1444
+ const resolvedHeaders = this.config.headers ? await resolve5(this.config.headers) : void 0;
1445
+ try {
1446
+ const { value: response, responseHeaders } = await postJsonToApi2({
1447
+ url: this.getUrl(),
1448
+ headers: combineHeaders2(
1449
+ resolvedHeaders,
1450
+ options.headers,
1451
+ this.getModelConfigHeaders(this.modelId, true),
1452
+ await resolve5(this.config.o11yHeaders)
1453
+ ),
1454
+ body: args,
1455
+ successfulResponseHandler: createEventSourceResponseHandler(z.any()),
1456
+ failedResponseHandler: createJsonErrorResponseHandler5({
1457
+ errorSchema: z.any(),
1458
+ errorToMessage: (data) => {
1459
+ var _a12;
1460
+ return (_a12 = getErrorMessage5(data)) != null ? _a12 : "unknown error";
1461
+ }
1462
+ }),
1463
+ ...abortSignal && { abortSignal },
1464
+ fetch: this.config.fetch
1465
+ });
1466
+ return {
1467
+ stream: response.pipeThrough(
1468
+ new TransformStream({
1469
+ start(controller) {
1470
+ if (warnings.length > 0) {
1471
+ controller.enqueue({ type: "stream-start", warnings });
1472
+ }
1473
+ },
1474
+ transform(chunk, controller) {
1475
+ if (chunk.success) {
1476
+ const streamPart = chunk.value;
1477
+ if (streamPart.type === "raw" && !options.includeRawChunks) {
1478
+ return;
1479
+ }
1480
+ if (streamPart.type === "response-metadata" && streamPart.timestamp && typeof streamPart.timestamp === "string") {
1481
+ streamPart.timestamp = new Date(streamPart.timestamp);
1482
+ }
1483
+ controller.enqueue(streamPart);
1484
+ } else {
1485
+ controller.error(
1486
+ chunk.error
1487
+ );
1488
+ }
1489
+ }
1490
+ })
1491
+ ),
1492
+ request: { body: args },
1493
+ response: { headers: responseHeaders }
1494
+ };
1495
+ } catch (error) {
1496
+ throw await asGatewayError(
1497
+ error,
1498
+ await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1499
+ );
1500
+ }
1501
+ }
1502
+ /**
1503
+ * Encodes inline `Uint8Array` file data to a base64 string in place.
1504
+ * @param options - The options to encode.
1505
+ * @returns The options with the file data encoded.
1506
+ */
1507
+ maybeEncodeFileParts(options) {
1508
+ for (const message of options.prompt) {
1509
+ if (!Array.isArray(message.content)) {
1510
+ continue;
1511
+ }
1512
+ for (const part of message.content) {
1513
+ if (part.type === "file" || part.type === "reasoning-file") {
1514
+ part.data = maybeBase64EncodeFileData2(part.data);
1515
+ } else if (part.type === "tool-result" && part.output.type === "content") {
1516
+ for (const contentPart of part.output.value) {
1517
+ if (contentPart.type === "file") {
1518
+ contentPart.data = maybeBase64EncodeFileData2(contentPart.data);
1519
+ }
1520
+ }
1521
+ }
1522
+ }
1523
+ }
1524
+ return options;
1525
+ }
1526
+ getUrl() {
1527
+ return `${this.config.baseURL}/language-model`;
1528
+ }
1529
+ getModelConfigHeaders(modelId, streaming) {
1530
+ return {
1531
+ "ai-language-model-specification-version": "4",
1532
+ "ai-language-model-id": modelId,
1533
+ "ai-language-model-streaming": String(streaming)
1534
+ };
1535
+ }
1536
+ };
1537
+ function maybeBase64EncodeFileData2(data) {
1538
+ if (data.type === "data") {
1539
+ const bytes = data.data;
1540
+ if (bytes instanceof Uint8Array) {
1541
+ return { ...data, data: Buffer.from(bytes).toString("base64") };
1542
+ }
1543
+ }
1544
+ return data;
1545
+ }
1546
+
1508
1547
  // src/gateway-embedding-model.ts
1509
1548
  import {
1510
1549
  combineHeaders as combineHeaders3,
@@ -1515,8 +1554,8 @@ import {
1515
1554
  postJsonToApi as postJsonToApi3,
1516
1555
  resolve as resolve6,
1517
1556
  serializeModelOptions as serializeModelOptions2,
1518
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
1519
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
1557
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
1558
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2,
1520
1559
  zodSchema as zodSchema8
1521
1560
  } from "@ai-sdk/provider-utils";
1522
1561
  var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
@@ -1527,13 +1566,13 @@ var GatewayEmbeddingModel = class _GatewayEmbeddingModel {
1527
1566
  this.maxEmbeddingsPerCall = 2048;
1528
1567
  this.supportsParallelCalls = true;
1529
1568
  }
1530
- static [WORKFLOW_SERIALIZE3](model) {
1569
+ static [WORKFLOW_SERIALIZE2](model) {
1531
1570
  return serializeModelOptions2({
1532
1571
  modelId: model.modelId,
1533
1572
  config: model.config
1534
1573
  });
1535
1574
  }
1536
- static [WORKFLOW_DESERIALIZE3](options) {
1575
+ static [WORKFLOW_DESERIALIZE2](options) {
1537
1576
  return new _GatewayEmbeddingModel(options.modelId, options.config);
1538
1577
  }
1539
1578
  get provider() {
@@ -1643,8 +1682,8 @@ import {
1643
1682
  postJsonToApi as postJsonToApi4,
1644
1683
  resolve as resolve7,
1645
1684
  serializeModelOptions as serializeModelOptions3,
1646
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4,
1647
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4
1685
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
1686
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
1648
1687
  } from "@ai-sdk/provider-utils";
1649
1688
  var GatewayImageModel = class _GatewayImageModel {
1650
1689
  constructor(modelId, config) {
@@ -1654,13 +1693,13 @@ var GatewayImageModel = class _GatewayImageModel {
1654
1693
  // Set a very large number to prevent client-side splitting of requests
1655
1694
  this.maxImagesPerCall = Number.MAX_SAFE_INTEGER;
1656
1695
  }
1657
- static [WORKFLOW_SERIALIZE4](model) {
1696
+ static [WORKFLOW_SERIALIZE3](model) {
1658
1697
  return serializeModelOptions3({
1659
1698
  modelId: model.modelId,
1660
1699
  config: model.config
1661
1700
  });
1662
1701
  }
1663
- static [WORKFLOW_DESERIALIZE4](options) {
1702
+ static [WORKFLOW_DESERIALIZE3](options) {
1664
1703
  return new _GatewayImageModel(options.modelId, options.config);
1665
1704
  }
1666
1705
  get provider() {
@@ -3415,7 +3454,7 @@ async function getVercelRequestId() {
3415
3454
  }
3416
3455
 
3417
3456
  // src/version.ts
3418
- var VERSION = true ? "4.0.75" : "0.0.0-test";
3457
+ var VERSION = true ? "4.0.76" : "0.0.0-test";
3419
3458
 
3420
3459
  // src/gateway-provider.ts
3421
3460
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -3529,7 +3568,7 @@ function createGateway(options = {}) {
3529
3568
  };
3530
3569
  };
3531
3570
  const createLanguageModel = (modelId) => {
3532
- return new GatewayBatchLanguageModel(modelId, {
3571
+ return new GatewayLanguageModel(modelId, {
3533
3572
  provider: "gateway",
3534
3573
  baseURL,
3535
3574
  headers: getHeaders,
@@ -3537,6 +3576,13 @@ function createGateway(options = {}) {
3537
3576
  o11yHeaders: createO11yHeaders()
3538
3577
  });
3539
3578
  };
3579
+ const createBatch = () => new GatewayBatch({
3580
+ provider: "gateway",
3581
+ baseURL,
3582
+ headers: getHeaders,
3583
+ fetch: options.fetch,
3584
+ o11yHeaders: createO11yHeaders()
3585
+ });
3540
3586
  const getAvailableModels = async () => {
3541
3587
  var _a13, _b13, _c;
3542
3588
  const now = (_c = (_b13 = (_a13 = options._internal) == null ? void 0 : _a13.currentDate) == null ? void 0 : _b13.call(_a13).getTime()) != null ? _c : Date.now();
@@ -3617,6 +3663,7 @@ function createGateway(options = {}) {
3617
3663
  });
3618
3664
  };
3619
3665
  provider.languageModel = createLanguageModel;
3666
+ provider.experimental_batch = createBatch;
3620
3667
  const createEmbeddingModel = (modelId) => {
3621
3668
  return new GatewayEmbeddingModel(modelId, {
3622
3669
  provider: "gateway",