@ai-sdk/gateway 4.0.91 → 4.0.94
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/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/index.d.ts +132 -11
- package/dist/index.js +257 -209
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +153 -26
- package/package.json +3 -3
- package/src/gateway-image-model-settings.ts +1 -0
- package/src/gateway-language-model-settings.ts +3 -1
- package/src/gateway-provider-options.ts +8 -6
- package/src/gateway-speech-model-settings.ts +1 -1
- package/src/gateway-tools.ts +18 -0
- package/src/tool/browserbase-fetch.ts +157 -0
- package/src/tool/browserbase-search.ts +137 -0
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
|
|
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
|
-
|
|
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
|
-
)
|
|
28
|
+
) || void 0;
|
|
30
29
|
}
|
|
31
30
|
function getGatewayRealtimeTeamIdOrSlug(secWebSocketProtocol) {
|
|
32
|
-
|
|
33
|
-
const encoded = (_a12 = findProtocol(
|
|
31
|
+
const encoded = findProtocol(
|
|
34
32
|
secWebSocketProtocol,
|
|
35
33
|
GATEWAY_TEAM_SUBPROTOCOL_PREFIX
|
|
36
|
-
)
|
|
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
|
|
38
|
+
} catch {
|
|
41
39
|
return void 0;
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
function findProtocol(secWebSocketProtocol, prefix) {
|
|
45
|
-
return secWebSocketProtocol
|
|
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 =
|
|
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
|
|
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:
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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:
|
|
1339
|
-
pending:
|
|
1340
|
-
completed:
|
|
1341
|
-
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 =
|
|
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: [...
|
|
1455
|
+
warnings: [...responseBody.warnings ?? [], ...warnings]
|
|
1492
1456
|
};
|
|
1493
1457
|
} catch (error) {
|
|
1494
1458
|
throw await asGatewayError(
|
|
1495
1459
|
error,
|
|
1496
|
-
await parseAuthMethod(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
|
|
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
|
|
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:
|
|
1637
|
+
usage: responseBody.usage ?? void 0,
|
|
1681
1638
|
providerMetadata: responseBody.providerMetadata,
|
|
1682
1639
|
response: { headers: responseHeaders, body: rawValue },
|
|
1683
|
-
warnings:
|
|
1640
|
+
warnings: responseBody.warnings ?? []
|
|
1684
1641
|
};
|
|
1685
1642
|
} catch (error) {
|
|
1686
1643
|
throw await asGatewayError(
|
|
1687
1644
|
error,
|
|
1688
|
-
await parseAuthMethod(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
|
|
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:
|
|
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:
|
|
1831
|
-
outputTokens:
|
|
1832
|
-
totalTokens:
|
|
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
|
|
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
|
|
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:
|
|
2017
|
-
providerMetadata:
|
|
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
|
|
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
|
|
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:
|
|
2074
|
-
providerMetadata:
|
|
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
|
|
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
|
|
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:
|
|
2128
|
-
providerMetadata:
|
|
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:
|
|
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:
|
|
2085
|
+
providerMetadata: responseBody.providerMetadata ?? void 0,
|
|
2145
2086
|
response
|
|
2146
2087
|
};
|
|
2147
2088
|
}
|
|
2148
2089
|
return {
|
|
2149
2090
|
status: "pending",
|
|
2150
|
-
warnings:
|
|
2151
|
-
providerMetadata:
|
|
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
|
|
2098
|
+
await parseAuthMethod(resolvedHeaders ?? {})
|
|
2158
2099
|
);
|
|
2159
2100
|
}
|
|
2160
2101
|
}
|
|
@@ -2328,7 +2269,6 @@ var GatewayEvaluationModel = class {
|
|
|
2328
2269
|
abortSignal,
|
|
2329
2270
|
providerOptions
|
|
2330
2271
|
}) {
|
|
2331
|
-
var _a12;
|
|
2332
2272
|
const resolvedHeaders = this.config.headers ? await resolve9(this.config.headers) : void 0;
|
|
2333
2273
|
try {
|
|
2334
2274
|
const {
|
|
@@ -2339,7 +2279,7 @@ var GatewayEvaluationModel = class {
|
|
|
2339
2279
|
url: this.getUrl(),
|
|
2340
2280
|
headers: combineHeaders6(
|
|
2341
2281
|
resolvedHeaders,
|
|
2342
|
-
headers
|
|
2282
|
+
headers ?? {},
|
|
2343
2283
|
this.getModelConfigHeaders(),
|
|
2344
2284
|
await resolve9(this.config.o11yHeaders)
|
|
2345
2285
|
),
|
|
@@ -2353,10 +2293,7 @@ var GatewayEvaluationModel = class {
|
|
|
2353
2293
|
),
|
|
2354
2294
|
failedResponseHandler: createJsonErrorResponseHandler9({
|
|
2355
2295
|
errorSchema: z.any(),
|
|
2356
|
-
errorToMessage: (data) =>
|
|
2357
|
-
var _a13;
|
|
2358
|
-
return (_a13 = getErrorMessage9(data)) != null ? _a13 : "unknown error";
|
|
2359
|
-
}
|
|
2296
|
+
errorToMessage: (data) => getErrorMessage9(data) ?? "unknown error"
|
|
2360
2297
|
}),
|
|
2361
2298
|
...abortSignal && { abortSignal },
|
|
2362
2299
|
fetch: this.config.fetch
|
|
@@ -2365,7 +2302,7 @@ var GatewayEvaluationModel = class {
|
|
|
2365
2302
|
answers: responseBody.answers,
|
|
2366
2303
|
...responseBody.rounding ? { rounding: responseBody.rounding } : {},
|
|
2367
2304
|
...responseBody.usage ? { usage: responseBody.usage } : {},
|
|
2368
|
-
warnings:
|
|
2305
|
+
warnings: responseBody.warnings ?? [],
|
|
2369
2306
|
providerMetadata: responseBody.providerMetadata,
|
|
2370
2307
|
response: {
|
|
2371
2308
|
modelId: this.modelId,
|
|
@@ -2376,7 +2313,7 @@ var GatewayEvaluationModel = class {
|
|
|
2376
2313
|
} catch (error) {
|
|
2377
2314
|
throw await asGatewayError(
|
|
2378
2315
|
error,
|
|
2379
|
-
await parseAuthMethod(resolvedHeaders
|
|
2316
|
+
await parseAuthMethod(resolvedHeaders ?? {})
|
|
2380
2317
|
);
|
|
2381
2318
|
}
|
|
2382
2319
|
}
|
|
@@ -2473,7 +2410,6 @@ var GatewayRerankingModel = class {
|
|
|
2473
2410
|
abortSignal,
|
|
2474
2411
|
providerOptions
|
|
2475
2412
|
}) {
|
|
2476
|
-
var _a12;
|
|
2477
2413
|
const resolvedHeaders = this.config.headers ? await resolve10(this.config.headers) : void 0;
|
|
2478
2414
|
try {
|
|
2479
2415
|
const {
|
|
@@ -2484,7 +2420,7 @@ var GatewayRerankingModel = class {
|
|
|
2484
2420
|
url: this.getUrl(),
|
|
2485
2421
|
headers: combineHeaders7(
|
|
2486
2422
|
resolvedHeaders,
|
|
2487
|
-
headers
|
|
2423
|
+
headers ?? {},
|
|
2488
2424
|
this.getModelConfigHeaders(),
|
|
2489
2425
|
await resolve10(this.config.o11yHeaders)
|
|
2490
2426
|
),
|
|
@@ -2499,10 +2435,7 @@ var GatewayRerankingModel = class {
|
|
|
2499
2435
|
),
|
|
2500
2436
|
failedResponseHandler: createJsonErrorResponseHandler10({
|
|
2501
2437
|
errorSchema: z.any(),
|
|
2502
|
-
errorToMessage: (data) =>
|
|
2503
|
-
var _a13;
|
|
2504
|
-
return (_a13 = getErrorMessage10(data)) != null ? _a13 : "unknown error";
|
|
2505
|
-
}
|
|
2438
|
+
errorToMessage: (data) => getErrorMessage10(data) ?? "unknown error"
|
|
2506
2439
|
}),
|
|
2507
2440
|
...abortSignal && { abortSignal },
|
|
2508
2441
|
fetch: this.config.fetch
|
|
@@ -2511,12 +2444,12 @@ var GatewayRerankingModel = class {
|
|
|
2511
2444
|
ranking: responseBody.ranking,
|
|
2512
2445
|
providerMetadata: responseBody.providerMetadata,
|
|
2513
2446
|
response: { headers: responseHeaders, body: rawValue },
|
|
2514
|
-
warnings:
|
|
2447
|
+
warnings: responseBody.warnings ?? []
|
|
2515
2448
|
};
|
|
2516
2449
|
} catch (error) {
|
|
2517
2450
|
throw await asGatewayError(
|
|
2518
2451
|
error,
|
|
2519
|
-
await parseAuthMethod(resolvedHeaders
|
|
2452
|
+
await parseAuthMethod(resolvedHeaders ?? {})
|
|
2520
2453
|
);
|
|
2521
2454
|
}
|
|
2522
2455
|
}
|
|
@@ -2595,7 +2528,6 @@ var GatewaySpeechModel = class {
|
|
|
2595
2528
|
headers,
|
|
2596
2529
|
abortSignal
|
|
2597
2530
|
}) {
|
|
2598
|
-
var _a12;
|
|
2599
2531
|
const resolvedHeaders = this.config.headers ? await resolve11(this.config.headers) : void 0;
|
|
2600
2532
|
try {
|
|
2601
2533
|
const {
|
|
@@ -2606,7 +2538,7 @@ var GatewaySpeechModel = class {
|
|
|
2606
2538
|
url: this.getUrl(),
|
|
2607
2539
|
headers: combineHeaders8(
|
|
2608
2540
|
resolvedHeaders,
|
|
2609
|
-
headers
|
|
2541
|
+
headers ?? {},
|
|
2610
2542
|
this.getModelConfigHeaders(),
|
|
2611
2543
|
await resolve11(this.config.o11yHeaders)
|
|
2612
2544
|
),
|
|
@@ -2624,17 +2556,14 @@ var GatewaySpeechModel = class {
|
|
|
2624
2556
|
),
|
|
2625
2557
|
failedResponseHandler: createJsonErrorResponseHandler11({
|
|
2626
2558
|
errorSchema: z.any(),
|
|
2627
|
-
errorToMessage: (data) =>
|
|
2628
|
-
var _a13;
|
|
2629
|
-
return (_a13 = getErrorMessage11(data)) != null ? _a13 : "unknown error";
|
|
2630
|
-
}
|
|
2559
|
+
errorToMessage: (data) => getErrorMessage11(data) ?? "unknown error"
|
|
2631
2560
|
}),
|
|
2632
2561
|
...abortSignal && { abortSignal },
|
|
2633
2562
|
fetch: this.config.fetch
|
|
2634
2563
|
});
|
|
2635
2564
|
return {
|
|
2636
2565
|
audio: responseBody.audio,
|
|
2637
|
-
warnings:
|
|
2566
|
+
warnings: responseBody.warnings ?? [],
|
|
2638
2567
|
providerMetadata: responseBody.providerMetadata,
|
|
2639
2568
|
response: {
|
|
2640
2569
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -2646,7 +2575,7 @@ var GatewaySpeechModel = class {
|
|
|
2646
2575
|
} catch (error) {
|
|
2647
2576
|
throw await asGatewayError(
|
|
2648
2577
|
error,
|
|
2649
|
-
await parseAuthMethod(resolvedHeaders
|
|
2578
|
+
await parseAuthMethod(resolvedHeaders ?? {})
|
|
2650
2579
|
);
|
|
2651
2580
|
}
|
|
2652
2581
|
}
|
|
@@ -2723,7 +2652,6 @@ var GatewayTranscriptionModel = class {
|
|
|
2723
2652
|
headers,
|
|
2724
2653
|
abortSignal
|
|
2725
2654
|
}) {
|
|
2726
|
-
var _a12, _b12, _c, _d;
|
|
2727
2655
|
const resolvedHeaders = this.config.headers ? await resolve12(this.config.headers) : void 0;
|
|
2728
2656
|
try {
|
|
2729
2657
|
const {
|
|
@@ -2734,7 +2662,7 @@ var GatewayTranscriptionModel = class {
|
|
|
2734
2662
|
url: this.getUrl(),
|
|
2735
2663
|
headers: combineHeaders9(
|
|
2736
2664
|
resolvedHeaders,
|
|
2737
|
-
headers
|
|
2665
|
+
headers ?? {},
|
|
2738
2666
|
this.getModelConfigHeaders(),
|
|
2739
2667
|
await resolve12(this.config.o11yHeaders)
|
|
2740
2668
|
),
|
|
@@ -2748,20 +2676,17 @@ var GatewayTranscriptionModel = class {
|
|
|
2748
2676
|
),
|
|
2749
2677
|
failedResponseHandler: createJsonErrorResponseHandler12({
|
|
2750
2678
|
errorSchema: z.any(),
|
|
2751
|
-
errorToMessage: (data) =>
|
|
2752
|
-
var _a13;
|
|
2753
|
-
return (_a13 = getErrorMessage12(data)) != null ? _a13 : "unknown error";
|
|
2754
|
-
}
|
|
2679
|
+
errorToMessage: (data) => getErrorMessage12(data) ?? "unknown error"
|
|
2755
2680
|
}),
|
|
2756
2681
|
...abortSignal && { abortSignal },
|
|
2757
2682
|
fetch: this.config.fetch
|
|
2758
2683
|
});
|
|
2759
2684
|
return {
|
|
2760
2685
|
text: responseBody.text,
|
|
2761
|
-
segments:
|
|
2762
|
-
language:
|
|
2763
|
-
durationInSeconds:
|
|
2764
|
-
warnings:
|
|
2686
|
+
segments: responseBody.segments ?? [],
|
|
2687
|
+
language: responseBody.language ?? void 0,
|
|
2688
|
+
durationInSeconds: responseBody.durationInSeconds ?? void 0,
|
|
2689
|
+
warnings: responseBody.warnings ?? [],
|
|
2765
2690
|
providerMetadata: responseBody.providerMetadata,
|
|
2766
2691
|
response: {
|
|
2767
2692
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -2773,16 +2698,15 @@ var GatewayTranscriptionModel = class {
|
|
|
2773
2698
|
} catch (error) {
|
|
2774
2699
|
throw await asGatewayError(
|
|
2775
2700
|
error,
|
|
2776
|
-
await parseAuthMethod(resolvedHeaders
|
|
2701
|
+
await parseAuthMethod(resolvedHeaders ?? {})
|
|
2777
2702
|
);
|
|
2778
2703
|
}
|
|
2779
2704
|
}
|
|
2780
2705
|
async doStream(options) {
|
|
2781
|
-
|
|
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();
|
|
2706
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
2783
2707
|
const headers = combineHeaders9(
|
|
2784
|
-
await resolve12(
|
|
2785
|
-
|
|
2708
|
+
await resolve12(this.config.headers ?? {}),
|
|
2709
|
+
options.headers ?? {},
|
|
2786
2710
|
this.getModelConfigHeaders(),
|
|
2787
2711
|
await resolve12(this.config.o11yHeaders)
|
|
2788
2712
|
);
|
|
@@ -2830,7 +2754,7 @@ function toGatewayTranscriptionUrl(baseURL, modelId) {
|
|
|
2830
2754
|
function getProtocolsFromHeaders(headers) {
|
|
2831
2755
|
const normalizedHeaders = normalizeHeaders(headers);
|
|
2832
2756
|
const authorization = normalizedHeaders.authorization;
|
|
2833
|
-
const token =
|
|
2757
|
+
const token = authorization?.startsWith("Bearer ") ? authorization.slice("Bearer ".length) : void 0;
|
|
2834
2758
|
return token == null ? [GATEWAY_TRANSCRIPTION_SUBPROTOCOL] : getGatewayTranscriptionProtocols(token, {
|
|
2835
2759
|
teamIdOrSlug: normalizedHeaders[VERCEL_AI_GATEWAY_TEAM_HEADER]
|
|
2836
2760
|
});
|
|
@@ -2864,7 +2788,7 @@ function createGatewayTranscriptionStream({
|
|
|
2864
2788
|
void audio.cancel().catch(() => {
|
|
2865
2789
|
});
|
|
2866
2790
|
}
|
|
2867
|
-
connection
|
|
2791
|
+
connection?.close(closeCode);
|
|
2868
2792
|
};
|
|
2869
2793
|
const stopAudio = () => {
|
|
2870
2794
|
audioStopped = true;
|
|
@@ -3067,7 +2991,7 @@ var GatewayRealtimeModel = class {
|
|
|
3067
2991
|
async doCreateClientSecret(options) {
|
|
3068
2992
|
const secret = await this.config.createClientSecret({
|
|
3069
2993
|
modelId: this.modelId,
|
|
3070
|
-
...
|
|
2994
|
+
...options?.expiresAfterSeconds != null && {
|
|
3071
2995
|
expiresAfterSeconds: options.expiresAfterSeconds
|
|
3072
2996
|
}
|
|
3073
2997
|
});
|
|
@@ -3101,14 +3025,130 @@ function toGatewayRealtimeUrl(baseURL, modelId) {
|
|
|
3101
3025
|
return url.toString();
|
|
3102
3026
|
}
|
|
3103
3027
|
|
|
3104
|
-
// src/tool/
|
|
3028
|
+
// src/tool/browserbase-fetch.ts
|
|
3105
3029
|
import {
|
|
3106
3030
|
createProviderExecutedToolFactory,
|
|
3107
3031
|
lazySchema as lazySchema11,
|
|
3108
3032
|
zodSchema as zodSchema11
|
|
3109
3033
|
} from "@ai-sdk/provider-utils";
|
|
3110
|
-
var
|
|
3034
|
+
var jsonObjectSchema = z.record(z.string(), z.unknown());
|
|
3035
|
+
var browserbaseFetchInputSchema = lazySchema11(
|
|
3036
|
+
() => zodSchema11(
|
|
3037
|
+
z.object({
|
|
3038
|
+
url: z.string().url().describe("URL of the page to fetch."),
|
|
3039
|
+
allow_redirects: z.boolean().optional().describe("Whether to follow HTTP redirects (default: false)."),
|
|
3040
|
+
allow_insecure_ssl: z.boolean().optional().describe(
|
|
3041
|
+
"Whether to bypass TLS certificate verification (default: false). Only use for trusted hosts."
|
|
3042
|
+
),
|
|
3043
|
+
proxies: z.boolean().optional().describe(
|
|
3044
|
+
"Whether to route the request through Browserbase proxies (default: false)."
|
|
3045
|
+
),
|
|
3046
|
+
format: z.enum(["raw", "json", "markdown"]).optional().describe(
|
|
3047
|
+
"Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema."
|
|
3048
|
+
),
|
|
3049
|
+
schema: jsonObjectSchema.optional().describe(
|
|
3050
|
+
"JSON Schema for structured extraction. Only use with format set to json."
|
|
3051
|
+
)
|
|
3052
|
+
})
|
|
3053
|
+
)
|
|
3054
|
+
);
|
|
3055
|
+
var browserbaseFetchOutputSchema = lazySchema11(
|
|
3111
3056
|
() => zodSchema11(
|
|
3057
|
+
z.union([
|
|
3058
|
+
z.object({
|
|
3059
|
+
id: z.string(),
|
|
3060
|
+
content: z.union([z.string(), jsonObjectSchema]),
|
|
3061
|
+
contentType: z.string(),
|
|
3062
|
+
encoding: z.string(),
|
|
3063
|
+
headers: z.record(z.string(), z.string()),
|
|
3064
|
+
statusCode: z.number()
|
|
3065
|
+
}),
|
|
3066
|
+
z.object({
|
|
3067
|
+
error: z.enum([
|
|
3068
|
+
"api_error",
|
|
3069
|
+
"configuration_error",
|
|
3070
|
+
"execution_error",
|
|
3071
|
+
"invalid_input",
|
|
3072
|
+
"rate_limit",
|
|
3073
|
+
"timeout",
|
|
3074
|
+
"unknown"
|
|
3075
|
+
]),
|
|
3076
|
+
statusCode: z.number().optional(),
|
|
3077
|
+
message: z.string()
|
|
3078
|
+
})
|
|
3079
|
+
])
|
|
3080
|
+
)
|
|
3081
|
+
);
|
|
3082
|
+
var browserbaseFetchToolFactory = createProviderExecutedToolFactory({
|
|
3083
|
+
id: "gateway.browserbase_fetch",
|
|
3084
|
+
inputSchema: browserbaseFetchInputSchema,
|
|
3085
|
+
outputSchema: browserbaseFetchOutputSchema
|
|
3086
|
+
});
|
|
3087
|
+
var browserbaseFetch = (config = {}) => browserbaseFetchToolFactory(config);
|
|
3088
|
+
|
|
3089
|
+
// src/tool/browserbase-search.ts
|
|
3090
|
+
import {
|
|
3091
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
3092
|
+
lazySchema as lazySchema12,
|
|
3093
|
+
zodSchema as zodSchema12
|
|
3094
|
+
} from "@ai-sdk/provider-utils";
|
|
3095
|
+
var browserbaseSearchInputSchema = lazySchema12(
|
|
3096
|
+
() => zodSchema12(
|
|
3097
|
+
z.object({
|
|
3098
|
+
query: z.string().min(1).max(200).describe("Web search query. Must be between 1 and 200 characters."),
|
|
3099
|
+
num_results: z.number().int().min(1).max(25).optional().describe("Maximum number of results to return (1-25, default: 10).")
|
|
3100
|
+
})
|
|
3101
|
+
)
|
|
3102
|
+
);
|
|
3103
|
+
var browserbaseSearchOutputSchema = lazySchema12(
|
|
3104
|
+
() => zodSchema12(
|
|
3105
|
+
z.union([
|
|
3106
|
+
z.object({
|
|
3107
|
+
query: z.string(),
|
|
3108
|
+
requestId: z.string(),
|
|
3109
|
+
results: z.array(
|
|
3110
|
+
z.object({
|
|
3111
|
+
id: z.string(),
|
|
3112
|
+
title: z.string(),
|
|
3113
|
+
url: z.string(),
|
|
3114
|
+
author: z.string().optional(),
|
|
3115
|
+
favicon: z.string().optional(),
|
|
3116
|
+
image: z.string().optional(),
|
|
3117
|
+
publishedDate: z.string().optional()
|
|
3118
|
+
})
|
|
3119
|
+
)
|
|
3120
|
+
}),
|
|
3121
|
+
z.object({
|
|
3122
|
+
error: z.enum([
|
|
3123
|
+
"api_error",
|
|
3124
|
+
"configuration_error",
|
|
3125
|
+
"execution_error",
|
|
3126
|
+
"invalid_input",
|
|
3127
|
+
"rate_limit",
|
|
3128
|
+
"timeout",
|
|
3129
|
+
"unknown"
|
|
3130
|
+
]),
|
|
3131
|
+
statusCode: z.number().optional(),
|
|
3132
|
+
message: z.string()
|
|
3133
|
+
})
|
|
3134
|
+
])
|
|
3135
|
+
)
|
|
3136
|
+
);
|
|
3137
|
+
var browserbaseSearchToolFactory = createProviderExecutedToolFactory2({
|
|
3138
|
+
id: "gateway.browserbase_search",
|
|
3139
|
+
inputSchema: browserbaseSearchInputSchema,
|
|
3140
|
+
outputSchema: browserbaseSearchOutputSchema
|
|
3141
|
+
});
|
|
3142
|
+
var browserbaseSearch = (config = {}) => browserbaseSearchToolFactory(config);
|
|
3143
|
+
|
|
3144
|
+
// src/tool/exa-search.ts
|
|
3145
|
+
import {
|
|
3146
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
3147
|
+
lazySchema as lazySchema13,
|
|
3148
|
+
zodSchema as zodSchema13
|
|
3149
|
+
} from "@ai-sdk/provider-utils";
|
|
3150
|
+
var exaSearchInputSchema = lazySchema13(
|
|
3151
|
+
() => zodSchema13(
|
|
3112
3152
|
z.object({
|
|
3113
3153
|
query: z.string().describe("Natural-language web search query. This is required."),
|
|
3114
3154
|
type: z.enum(["auto", "fast", "instant"]).optional().describe(
|
|
@@ -3178,8 +3218,8 @@ var exaSearchInputSchema = lazySchema11(
|
|
|
3178
3218
|
})
|
|
3179
3219
|
)
|
|
3180
3220
|
);
|
|
3181
|
-
var exaSearchOutputSchema =
|
|
3182
|
-
() =>
|
|
3221
|
+
var exaSearchOutputSchema = lazySchema13(
|
|
3222
|
+
() => zodSchema13(
|
|
3183
3223
|
z.union([
|
|
3184
3224
|
z.object({
|
|
3185
3225
|
requestId: z.string(),
|
|
@@ -3226,7 +3266,7 @@ var exaSearchOutputSchema = lazySchema11(
|
|
|
3226
3266
|
])
|
|
3227
3267
|
)
|
|
3228
3268
|
);
|
|
3229
|
-
var exaSearchToolFactory =
|
|
3269
|
+
var exaSearchToolFactory = createProviderExecutedToolFactory3({
|
|
3230
3270
|
id: "gateway.exa_search",
|
|
3231
3271
|
inputSchema: exaSearchInputSchema,
|
|
3232
3272
|
outputSchema: exaSearchOutputSchema
|
|
@@ -3235,12 +3275,12 @@ var exaSearch = (config = {}) => exaSearchToolFactory(config);
|
|
|
3235
3275
|
|
|
3236
3276
|
// src/tool/parallel-search.ts
|
|
3237
3277
|
import {
|
|
3238
|
-
createProviderExecutedToolFactory as
|
|
3239
|
-
lazySchema as
|
|
3240
|
-
zodSchema as
|
|
3278
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
|
|
3279
|
+
lazySchema as lazySchema14,
|
|
3280
|
+
zodSchema as zodSchema14
|
|
3241
3281
|
} from "@ai-sdk/provider-utils";
|
|
3242
|
-
var parallelSearchInputSchema =
|
|
3243
|
-
() =>
|
|
3282
|
+
var parallelSearchInputSchema = lazySchema14(
|
|
3283
|
+
() => zodSchema14(
|
|
3244
3284
|
z.object({
|
|
3245
3285
|
objective: z.string().describe(
|
|
3246
3286
|
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
@@ -3279,8 +3319,8 @@ var parallelSearchInputSchema = lazySchema12(
|
|
|
3279
3319
|
})
|
|
3280
3320
|
)
|
|
3281
3321
|
);
|
|
3282
|
-
var parallelSearchOutputSchema =
|
|
3283
|
-
() =>
|
|
3322
|
+
var parallelSearchOutputSchema = lazySchema14(
|
|
3323
|
+
() => zodSchema14(
|
|
3284
3324
|
z.union([
|
|
3285
3325
|
// Success response
|
|
3286
3326
|
z.object({
|
|
@@ -3311,7 +3351,7 @@ var parallelSearchOutputSchema = lazySchema12(
|
|
|
3311
3351
|
])
|
|
3312
3352
|
)
|
|
3313
3353
|
);
|
|
3314
|
-
var parallelSearchToolFactory =
|
|
3354
|
+
var parallelSearchToolFactory = createProviderExecutedToolFactory4({
|
|
3315
3355
|
id: "gateway.parallel_search",
|
|
3316
3356
|
inputSchema: parallelSearchInputSchema,
|
|
3317
3357
|
outputSchema: parallelSearchOutputSchema
|
|
@@ -3320,12 +3360,12 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
|
3320
3360
|
|
|
3321
3361
|
// src/tool/perplexity-search.ts
|
|
3322
3362
|
import {
|
|
3323
|
-
createProviderExecutedToolFactory as
|
|
3324
|
-
lazySchema as
|
|
3325
|
-
zodSchema as
|
|
3363
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory5,
|
|
3364
|
+
lazySchema as lazySchema15,
|
|
3365
|
+
zodSchema as zodSchema15
|
|
3326
3366
|
} from "@ai-sdk/provider-utils";
|
|
3327
|
-
var perplexitySearchInputSchema =
|
|
3328
|
-
() =>
|
|
3367
|
+
var perplexitySearchInputSchema = lazySchema15(
|
|
3368
|
+
() => zodSchema15(
|
|
3329
3369
|
z.object({
|
|
3330
3370
|
query: z.union([z.string(), z.array(z.string())]).describe(
|
|
3331
3371
|
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
@@ -3366,8 +3406,8 @@ var perplexitySearchInputSchema = lazySchema13(
|
|
|
3366
3406
|
})
|
|
3367
3407
|
)
|
|
3368
3408
|
);
|
|
3369
|
-
var perplexitySearchOutputSchema =
|
|
3370
|
-
() =>
|
|
3409
|
+
var perplexitySearchOutputSchema = lazySchema15(
|
|
3410
|
+
() => zodSchema15(
|
|
3371
3411
|
z.union([
|
|
3372
3412
|
// Success response
|
|
3373
3413
|
z.object({
|
|
@@ -3397,7 +3437,7 @@ var perplexitySearchOutputSchema = lazySchema13(
|
|
|
3397
3437
|
])
|
|
3398
3438
|
)
|
|
3399
3439
|
);
|
|
3400
|
-
var perplexitySearchToolFactory =
|
|
3440
|
+
var perplexitySearchToolFactory = createProviderExecutedToolFactory5({
|
|
3401
3441
|
id: "gateway.perplexity_search",
|
|
3402
3442
|
inputSchema: perplexitySearchInputSchema,
|
|
3403
3443
|
outputSchema: perplexitySearchOutputSchema
|
|
@@ -3406,9 +3446,9 @@ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
|
|
|
3406
3446
|
|
|
3407
3447
|
// src/tool/tako-search.ts
|
|
3408
3448
|
import {
|
|
3409
|
-
createProviderExecutedToolFactory as
|
|
3410
|
-
lazySchema as
|
|
3411
|
-
zodSchema as
|
|
3449
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory6,
|
|
3450
|
+
lazySchema as lazySchema16,
|
|
3451
|
+
zodSchema as zodSchema16
|
|
3412
3452
|
} from "@ai-sdk/provider-utils";
|
|
3413
3453
|
var takoDataSourceInputSchema = z.object({
|
|
3414
3454
|
count: z.number().optional().describe(
|
|
@@ -3447,8 +3487,8 @@ var takoWebSourceInputSchema = z.object({
|
|
|
3447
3487
|
"Keep results published on or before this ISO date (YYYY-MM-DD)."
|
|
3448
3488
|
)
|
|
3449
3489
|
});
|
|
3450
|
-
var takoSearchInputSchema =
|
|
3451
|
-
() =>
|
|
3490
|
+
var takoSearchInputSchema = lazySchema16(
|
|
3491
|
+
() => zodSchema16(
|
|
3452
3492
|
z.object({
|
|
3453
3493
|
query: z.string().describe(
|
|
3454
3494
|
'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 +3618,8 @@ var takoWebResultSchema = z.object({
|
|
|
3578
3618
|
publish_date: z.string().nullish(),
|
|
3579
3619
|
content: takoResultContentSchema.nullish()
|
|
3580
3620
|
}).passthrough();
|
|
3581
|
-
var takoSearchOutputSchema =
|
|
3582
|
-
() =>
|
|
3621
|
+
var takoSearchOutputSchema = lazySchema16(
|
|
3622
|
+
() => zodSchema16(
|
|
3583
3623
|
z.union([
|
|
3584
3624
|
z.object({
|
|
3585
3625
|
request_id: z.string(),
|
|
@@ -3608,7 +3648,7 @@ var takoSearchOutputSchema = lazySchema14(
|
|
|
3608
3648
|
])
|
|
3609
3649
|
)
|
|
3610
3650
|
);
|
|
3611
|
-
var takoSearchToolFactory =
|
|
3651
|
+
var takoSearchToolFactory = createProviderExecutedToolFactory6({
|
|
3612
3652
|
id: "gateway.tako_search",
|
|
3613
3653
|
inputSchema: takoSearchInputSchema,
|
|
3614
3654
|
outputSchema: takoSearchOutputSchema
|
|
@@ -3617,6 +3657,20 @@ var takoSearch = (config = {}) => takoSearchToolFactory(config);
|
|
|
3617
3657
|
|
|
3618
3658
|
// src/gateway-tools.ts
|
|
3619
3659
|
var gatewayTools = {
|
|
3660
|
+
/**
|
|
3661
|
+
* Fetch page content using Browserbase's lightweight Fetch API.
|
|
3662
|
+
*
|
|
3663
|
+
* Supports raw, Markdown, and schema-driven JSON output as well as redirects,
|
|
3664
|
+
* proxy routing, and TLS controls.
|
|
3665
|
+
*/
|
|
3666
|
+
browserbaseFetch,
|
|
3667
|
+
/**
|
|
3668
|
+
* Search the web using Browserbase's Search API for fast, structured results.
|
|
3669
|
+
*
|
|
3670
|
+
* Returns titles, URLs, and available publication metadata without requiring
|
|
3671
|
+
* a browser session.
|
|
3672
|
+
*/
|
|
3673
|
+
browserbaseSearch,
|
|
3620
3674
|
/**
|
|
3621
3675
|
* Search the web using Exa for current information and token-efficient
|
|
3622
3676
|
* excerpts optimized for agent workflows.
|
|
@@ -3657,12 +3711,11 @@ var gatewayTools = {
|
|
|
3657
3711
|
import { getContext } from "@vercel/oidc";
|
|
3658
3712
|
import { getVercelOidcToken } from "@vercel/oidc";
|
|
3659
3713
|
async function getVercelRequestId() {
|
|
3660
|
-
|
|
3661
|
-
return (_a12 = getContext().headers) == null ? void 0 : _a12["x-vercel-id"];
|
|
3714
|
+
return getContext().headers?.["x-vercel-id"];
|
|
3662
3715
|
}
|
|
3663
3716
|
|
|
3664
3717
|
// src/version.ts
|
|
3665
|
-
var VERSION = true ? "4.0.
|
|
3718
|
+
var VERSION = true ? "4.0.94" : "0.0.0-test";
|
|
3666
3719
|
|
|
3667
3720
|
// src/gateway-provider.ts
|
|
3668
3721
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
@@ -3671,12 +3724,11 @@ var gatewayClientSecretResponseSchema = z.object({
|
|
|
3671
3724
|
expiresAt: z.number().nullish()
|
|
3672
3725
|
});
|
|
3673
3726
|
function createGateway(options = {}) {
|
|
3674
|
-
var _a12, _b12;
|
|
3675
3727
|
let pendingMetadata = null;
|
|
3676
3728
|
let metadataCache = null;
|
|
3677
|
-
const cacheRefreshMillis =
|
|
3729
|
+
const cacheRefreshMillis = options.metadataCacheRefreshMillis ?? 1e3 * 60 * 5;
|
|
3678
3730
|
let lastFetchTime = 0;
|
|
3679
|
-
const baseURL =
|
|
3731
|
+
const baseURL = withoutTrailingSlash(options.baseURL) ?? "https://ai-gateway.vercel.sh/v4/ai";
|
|
3680
3732
|
const createAuthHeaders = (auth) => withUserAgentSuffix(
|
|
3681
3733
|
{
|
|
3682
3734
|
Authorization: `Bearer ${auth.token}`,
|
|
@@ -3732,10 +3784,7 @@ function createGateway(options = {}) {
|
|
|
3732
3784
|
),
|
|
3733
3785
|
failedResponseHandler: createJsonErrorResponseHandler13({
|
|
3734
3786
|
errorSchema: z.any(),
|
|
3735
|
-
errorToMessage: (data) =>
|
|
3736
|
-
var _a13;
|
|
3737
|
-
return (_a13 = getErrorMessage13(data)) != null ? _a13 : "unknown error";
|
|
3738
|
-
}
|
|
3787
|
+
errorToMessage: (data) => getErrorMessage13(data) ?? "unknown error"
|
|
3739
3788
|
}),
|
|
3740
3789
|
fetch: options.fetch
|
|
3741
3790
|
});
|
|
@@ -3792,8 +3841,7 @@ function createGateway(options = {}) {
|
|
|
3792
3841
|
o11yHeaders: createO11yHeaders()
|
|
3793
3842
|
});
|
|
3794
3843
|
const getAvailableModels = async () => {
|
|
3795
|
-
|
|
3796
|
-
const now = (_c = (_b13 = (_a13 = options._internal) == null ? void 0 : _a13.currentDate) == null ? void 0 : _b13.call(_a13).getTime()) != null ? _c : Date.now();
|
|
3844
|
+
const now = options._internal?.currentDate?.().getTime() ?? Date.now();
|
|
3797
3845
|
if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
|
|
3798
3846
|
lastFetchTime = now;
|
|
3799
3847
|
pendingMetadata = new GatewayFetchMetadata({
|