ai 5.0.0-canary.2 → 5.0.0-canary.4
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 +30 -0
- package/dist/index.d.mts +154 -10
- package/dist/index.d.ts +154 -10
- package/dist/index.js +270 -147
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +226 -104
- package/dist/index.mjs.map +1 -1
- package/{rsc/dist/rsc-server.d.mts → dist/internal/index.d.mts} +212 -368
- package/dist/internal/index.d.ts +592 -0
- package/dist/internal/index.js +1429 -0
- package/dist/internal/index.js.map +1 -0
- package/{rsc/dist/rsc-server.mjs → dist/internal/index.mjs} +1034 -1777
- package/dist/internal/index.mjs.map +1 -0
- package/mcp-stdio/dist/index.js +1 -1
- package/mcp-stdio/dist/index.js.map +1 -1
- package/mcp-stdio/dist/index.mjs +1 -1
- package/mcp-stdio/dist/index.mjs.map +1 -1
- package/mcp-stdio/get-environment.test.ts +13 -0
- package/mcp-stdio/get-environment.ts +1 -1
- package/package.json +12 -27
- package/rsc/dist/index.d.ts +0 -813
- package/rsc/dist/index.mjs +0 -18
- package/rsc/dist/rsc-client.d.mts +0 -1
- package/rsc/dist/rsc-client.mjs +0 -18
- package/rsc/dist/rsc-client.mjs.map +0 -1
- package/rsc/dist/rsc-server.mjs.map +0 -1
- package/rsc/dist/rsc-shared.d.mts +0 -101
- package/rsc/dist/rsc-shared.mjs +0 -308
- package/rsc/dist/rsc-shared.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -830,12 +830,12 @@ import {
|
|
830
830
|
var DefaultGeneratedFile = class {
|
831
831
|
constructor({
|
832
832
|
data,
|
833
|
-
|
833
|
+
mediaType
|
834
834
|
}) {
|
835
835
|
const isUint8Array = data instanceof Uint8Array;
|
836
836
|
this.base64Data = isUint8Array ? void 0 : data;
|
837
837
|
this.uint8ArrayData = isUint8Array ? data : void 0;
|
838
|
-
this.
|
838
|
+
this.mediaType = mediaType;
|
839
839
|
}
|
840
840
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
841
841
|
get base64() {
|
@@ -859,45 +859,45 @@ var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
|
859
859
|
}
|
860
860
|
};
|
861
861
|
|
862
|
-
// core/util/detect-
|
863
|
-
var
|
862
|
+
// core/util/detect-media-type.ts
|
863
|
+
var imageMediaTypeSignatures = [
|
864
864
|
{
|
865
|
-
|
865
|
+
mediaType: "image/gif",
|
866
866
|
bytesPrefix: [71, 73, 70],
|
867
867
|
base64Prefix: "R0lG"
|
868
868
|
},
|
869
869
|
{
|
870
|
-
|
870
|
+
mediaType: "image/png",
|
871
871
|
bytesPrefix: [137, 80, 78, 71],
|
872
872
|
base64Prefix: "iVBORw"
|
873
873
|
},
|
874
874
|
{
|
875
|
-
|
875
|
+
mediaType: "image/jpeg",
|
876
876
|
bytesPrefix: [255, 216],
|
877
877
|
base64Prefix: "/9j/"
|
878
878
|
},
|
879
879
|
{
|
880
|
-
|
880
|
+
mediaType: "image/webp",
|
881
881
|
bytesPrefix: [82, 73, 70, 70],
|
882
882
|
base64Prefix: "UklGRg"
|
883
883
|
},
|
884
884
|
{
|
885
|
-
|
885
|
+
mediaType: "image/bmp",
|
886
886
|
bytesPrefix: [66, 77],
|
887
887
|
base64Prefix: "Qk"
|
888
888
|
},
|
889
889
|
{
|
890
|
-
|
890
|
+
mediaType: "image/tiff",
|
891
891
|
bytesPrefix: [73, 73, 42, 0],
|
892
892
|
base64Prefix: "SUkqAA"
|
893
893
|
},
|
894
894
|
{
|
895
|
-
|
895
|
+
mediaType: "image/tiff",
|
896
896
|
bytesPrefix: [77, 77, 0, 42],
|
897
897
|
base64Prefix: "TU0AKg"
|
898
898
|
},
|
899
899
|
{
|
900
|
-
|
900
|
+
mediaType: "image/avif",
|
901
901
|
bytesPrefix: [
|
902
902
|
0,
|
903
903
|
0,
|
@@ -915,7 +915,7 @@ var mimeTypeSignatures = [
|
|
915
915
|
base64Prefix: "AAAAIGZ0eXBhdmlm"
|
916
916
|
},
|
917
917
|
{
|
918
|
-
|
918
|
+
mediaType: "image/heic",
|
919
919
|
bytesPrefix: [
|
920
920
|
0,
|
921
921
|
0,
|
@@ -933,10 +933,45 @@ var mimeTypeSignatures = [
|
|
933
933
|
base64Prefix: "AAAAIGZ0eXBoZWlj"
|
934
934
|
}
|
935
935
|
];
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
936
|
+
var audioMediaTypeSignatures = [
|
937
|
+
{
|
938
|
+
mediaType: "audio/mpeg",
|
939
|
+
bytesPrefix: [255, 251],
|
940
|
+
base64Prefix: "//s="
|
941
|
+
},
|
942
|
+
{
|
943
|
+
mediaType: "audio/wav",
|
944
|
+
bytesPrefix: [82, 73, 70, 70],
|
945
|
+
base64Prefix: "UklGR"
|
946
|
+
},
|
947
|
+
{
|
948
|
+
mediaType: "audio/ogg",
|
949
|
+
bytesPrefix: [79, 103, 103, 83],
|
950
|
+
base64Prefix: "T2dnUw"
|
951
|
+
},
|
952
|
+
{
|
953
|
+
mediaType: "audio/flac",
|
954
|
+
bytesPrefix: [102, 76, 97, 67],
|
955
|
+
base64Prefix: "ZkxhQw"
|
956
|
+
},
|
957
|
+
{
|
958
|
+
mediaType: "audio/aac",
|
959
|
+
bytesPrefix: [64, 21, 0, 0],
|
960
|
+
base64Prefix: "QBUA"
|
961
|
+
},
|
962
|
+
{
|
963
|
+
mediaType: "audio/mp4",
|
964
|
+
bytesPrefix: [102, 116, 121, 112],
|
965
|
+
base64Prefix: "ZnR5cA"
|
966
|
+
}
|
967
|
+
];
|
968
|
+
function detectMediaType({
|
969
|
+
data,
|
970
|
+
signatures
|
971
|
+
}) {
|
972
|
+
for (const signature of signatures) {
|
973
|
+
if (typeof data === "string" ? data.startsWith(signature.base64Prefix) : data.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => data[index] === byte)) {
|
974
|
+
return signature.mediaType;
|
940
975
|
}
|
941
976
|
}
|
942
977
|
return void 0;
|
@@ -992,7 +1027,10 @@ async function generateImage({
|
|
992
1027
|
var _a18;
|
993
1028
|
return new DefaultGeneratedFile({
|
994
1029
|
data: image,
|
995
|
-
|
1030
|
+
mediaType: (_a18 = detectMediaType({
|
1031
|
+
data: image,
|
1032
|
+
signatures: imageMediaTypeSignatures
|
1033
|
+
})) != null ? _a18 : "image/png"
|
996
1034
|
});
|
997
1035
|
}
|
998
1036
|
)
|
@@ -1051,6 +1089,9 @@ var NoObjectGeneratedError = class extends AISDKError4 {
|
|
1051
1089
|
};
|
1052
1090
|
_a4 = symbol4;
|
1053
1091
|
|
1092
|
+
// core/prompt/convert-to-language-model-prompt.ts
|
1093
|
+
import { convertUint8ArrayToBase64 as convertUint8ArrayToBase643 } from "@ai-sdk/provider-utils";
|
1094
|
+
|
1054
1095
|
// util/download-error.ts
|
1055
1096
|
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
1056
1097
|
var name5 = "AI_DownloadError";
|
@@ -1092,7 +1133,7 @@ async function download({ url }) {
|
|
1092
1133
|
}
|
1093
1134
|
return {
|
1094
1135
|
data: new Uint8Array(await response.arrayBuffer()),
|
1095
|
-
|
1136
|
+
mediaType: (_a17 = response.headers.get("content-type")) != null ? _a17 : void 0
|
1096
1137
|
};
|
1097
1138
|
} catch (error) {
|
1098
1139
|
if (DownloadError.isInstance(error)) {
|
@@ -1208,12 +1249,12 @@ function splitDataUrl(dataUrl) {
|
|
1208
1249
|
try {
|
1209
1250
|
const [header, base64Content] = dataUrl.split(",");
|
1210
1251
|
return {
|
1211
|
-
|
1252
|
+
mediaType: header.split(";")[0].split(":")[1],
|
1212
1253
|
base64Content
|
1213
1254
|
};
|
1214
1255
|
} catch (error) {
|
1215
1256
|
return {
|
1216
|
-
|
1257
|
+
mediaType: void 0,
|
1217
1258
|
base64Content: void 0
|
1218
1259
|
};
|
1219
1260
|
}
|
@@ -1247,7 +1288,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1247
1288
|
return {
|
1248
1289
|
role: "system",
|
1249
1290
|
content: message.content,
|
1250
|
-
|
1291
|
+
providerOptions: (_a17 = message.providerOptions) != null ? _a17 : message.experimental_providerMetadata
|
1251
1292
|
};
|
1252
1293
|
}
|
1253
1294
|
case "user": {
|
@@ -1255,13 +1296,13 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1255
1296
|
return {
|
1256
1297
|
role: "user",
|
1257
1298
|
content: [{ type: "text", text: message.content }],
|
1258
|
-
|
1299
|
+
providerOptions: (_b = message.providerOptions) != null ? _b : message.experimental_providerMetadata
|
1259
1300
|
};
|
1260
1301
|
}
|
1261
1302
|
return {
|
1262
1303
|
role: "user",
|
1263
1304
|
content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
1264
|
-
|
1305
|
+
providerOptions: (_c = message.providerOptions) != null ? _c : message.experimental_providerMetadata
|
1265
1306
|
};
|
1266
1307
|
}
|
1267
1308
|
case "assistant": {
|
@@ -1269,7 +1310,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1269
1310
|
return {
|
1270
1311
|
role: "assistant",
|
1271
1312
|
content: [{ type: "text", text: message.content }],
|
1272
|
-
|
1313
|
+
providerOptions: (_d = message.providerOptions) != null ? _d : message.experimental_providerMetadata
|
1273
1314
|
};
|
1274
1315
|
}
|
1275
1316
|
return {
|
@@ -1278,7 +1319,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1278
1319
|
// remove empty text parts:
|
1279
1320
|
(part) => part.type !== "text" || part.text !== ""
|
1280
1321
|
).map((part) => {
|
1281
|
-
var _a18;
|
1322
|
+
var _a18, _b2;
|
1282
1323
|
const providerOptions = (_a18 = part.providerOptions) != null ? _a18 : part.experimental_providerMetadata;
|
1283
1324
|
switch (part.type) {
|
1284
1325
|
case "file": {
|
@@ -1286,8 +1327,8 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1286
1327
|
type: "file",
|
1287
1328
|
data: part.data instanceof URL ? part.data : convertDataContentToBase64String(part.data),
|
1288
1329
|
filename: part.filename,
|
1289
|
-
|
1290
|
-
|
1330
|
+
mediaType: (_b2 = part.mediaType) != null ? _b2 : part.mimeType,
|
1331
|
+
providerOptions
|
1291
1332
|
};
|
1292
1333
|
}
|
1293
1334
|
case "reasoning": {
|
@@ -1295,21 +1336,21 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1295
1336
|
type: "reasoning",
|
1296
1337
|
text: part.text,
|
1297
1338
|
signature: part.signature,
|
1298
|
-
|
1339
|
+
providerOptions
|
1299
1340
|
};
|
1300
1341
|
}
|
1301
1342
|
case "redacted-reasoning": {
|
1302
1343
|
return {
|
1303
1344
|
type: "redacted-reasoning",
|
1304
1345
|
data: part.data,
|
1305
|
-
|
1346
|
+
providerOptions
|
1306
1347
|
};
|
1307
1348
|
}
|
1308
1349
|
case "text": {
|
1309
1350
|
return {
|
1310
1351
|
type: "text",
|
1311
1352
|
text: part.text,
|
1312
|
-
|
1353
|
+
providerOptions
|
1313
1354
|
};
|
1314
1355
|
}
|
1315
1356
|
case "tool-call": {
|
@@ -1318,12 +1359,12 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1318
1359
|
toolCallId: part.toolCallId,
|
1319
1360
|
toolName: part.toolName,
|
1320
1361
|
args: part.args,
|
1321
|
-
|
1362
|
+
providerOptions
|
1322
1363
|
};
|
1323
1364
|
}
|
1324
1365
|
}
|
1325
1366
|
}),
|
1326
|
-
|
1367
|
+
providerOptions: (_e = message.providerOptions) != null ? _e : message.experimental_providerMetadata
|
1327
1368
|
};
|
1328
1369
|
}
|
1329
1370
|
case "tool": {
|
@@ -1338,10 +1379,10 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1338
1379
|
result: part.result,
|
1339
1380
|
content: part.experimental_content,
|
1340
1381
|
isError: part.isError,
|
1341
|
-
|
1382
|
+
providerOptions: (_a18 = part.providerOptions) != null ? _a18 : part.experimental_providerMetadata
|
1342
1383
|
};
|
1343
1384
|
}),
|
1344
|
-
|
1385
|
+
providerOptions: (_f = message.providerOptions) != null ? _f : message.experimental_providerMetadata
|
1345
1386
|
};
|
1346
1387
|
}
|
1347
1388
|
default: {
|
@@ -1374,15 +1415,15 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
|
|
1374
1415
|
);
|
1375
1416
|
}
|
1376
1417
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1377
|
-
var _a17, _b, _c, _d;
|
1418
|
+
var _a17, _b, _c, _d, _e;
|
1378
1419
|
if (part.type === "text") {
|
1379
1420
|
return {
|
1380
1421
|
type: "text",
|
1381
1422
|
text: part.text,
|
1382
|
-
|
1423
|
+
providerOptions: (_a17 = part.providerOptions) != null ? _a17 : part.experimental_providerMetadata
|
1383
1424
|
};
|
1384
1425
|
}
|
1385
|
-
let
|
1426
|
+
let mediaType = (_b = part.mediaType) != null ? _b : part.mimeType;
|
1386
1427
|
let data;
|
1387
1428
|
let content;
|
1388
1429
|
let normalizedData;
|
@@ -1404,19 +1445,19 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1404
1445
|
}
|
1405
1446
|
if (content instanceof URL) {
|
1406
1447
|
if (content.protocol === "data:") {
|
1407
|
-
const {
|
1448
|
+
const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
|
1408
1449
|
content.toString()
|
1409
1450
|
);
|
1410
|
-
if (
|
1451
|
+
if (dataUrlMediaType == null || base64Content == null) {
|
1411
1452
|
throw new Error(`Invalid data URL format in part ${type}`);
|
1412
1453
|
}
|
1413
|
-
|
1454
|
+
mediaType = dataUrlMediaType;
|
1414
1455
|
normalizedData = convertDataContentToUint8Array(base64Content);
|
1415
1456
|
} else {
|
1416
1457
|
const downloadedFile = downloadedAssets[content.toString()];
|
1417
1458
|
if (downloadedFile) {
|
1418
1459
|
normalizedData = downloadedFile.data;
|
1419
|
-
|
1460
|
+
mediaType != null ? mediaType : mediaType = downloadedFile.mediaType;
|
1420
1461
|
} else {
|
1421
1462
|
normalizedData = content;
|
1422
1463
|
}
|
@@ -1427,25 +1468,30 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1427
1468
|
switch (type) {
|
1428
1469
|
case "image": {
|
1429
1470
|
if (normalizedData instanceof Uint8Array) {
|
1430
|
-
|
1471
|
+
mediaType = (_c = detectMediaType({
|
1472
|
+
data: normalizedData,
|
1473
|
+
signatures: imageMediaTypeSignatures
|
1474
|
+
})) != null ? _c : mediaType;
|
1431
1475
|
}
|
1432
1476
|
return {
|
1433
|
-
type: "
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1477
|
+
type: "file",
|
1478
|
+
mediaType: mediaType != null ? mediaType : "image/*",
|
1479
|
+
// any image
|
1480
|
+
filename: void 0,
|
1481
|
+
data: normalizedData instanceof Uint8Array ? convertUint8ArrayToBase643(normalizedData) : normalizedData,
|
1482
|
+
providerOptions: (_d = part.providerOptions) != null ? _d : part.experimental_providerMetadata
|
1437
1483
|
};
|
1438
1484
|
}
|
1439
1485
|
case "file": {
|
1440
|
-
if (
|
1441
|
-
throw new Error(`
|
1486
|
+
if (mediaType == null) {
|
1487
|
+
throw new Error(`Media type is missing for file part`);
|
1442
1488
|
}
|
1443
1489
|
return {
|
1444
1490
|
type: "file",
|
1445
|
-
|
1491
|
+
mediaType,
|
1446
1492
|
filename: part.filename,
|
1447
|
-
|
1448
|
-
|
1493
|
+
data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
|
1494
|
+
providerOptions: (_e = part.providerOptions) != null ? _e : part.experimental_providerMetadata
|
1449
1495
|
};
|
1450
1496
|
}
|
1451
1497
|
}
|
@@ -1575,7 +1621,7 @@ function attachmentsToParts(attachments) {
|
|
1575
1621
|
parts.push({
|
1576
1622
|
type: "file",
|
1577
1623
|
data: url,
|
1578
|
-
|
1624
|
+
mediaType: attachment.contentType
|
1579
1625
|
});
|
1580
1626
|
}
|
1581
1627
|
break;
|
@@ -1583,14 +1629,14 @@ function attachmentsToParts(attachments) {
|
|
1583
1629
|
case "data:": {
|
1584
1630
|
let header;
|
1585
1631
|
let base64Content;
|
1586
|
-
let
|
1632
|
+
let mediaType;
|
1587
1633
|
try {
|
1588
1634
|
[header, base64Content] = attachment.url.split(",");
|
1589
|
-
|
1635
|
+
mediaType = header.split(";")[0].split(":")[1];
|
1590
1636
|
} catch (error) {
|
1591
1637
|
throw new Error(`Error processing data URL: ${attachment.url}`);
|
1592
1638
|
}
|
1593
|
-
if (
|
1639
|
+
if (mediaType == null || base64Content == null) {
|
1594
1640
|
throw new Error(`Invalid data URL format: ${attachment.url}`);
|
1595
1641
|
}
|
1596
1642
|
if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
|
@@ -1614,7 +1660,7 @@ function attachmentsToParts(attachments) {
|
|
1614
1660
|
parts.push({
|
1615
1661
|
type: "file",
|
1616
1662
|
data: base64Content,
|
1617
|
-
|
1663
|
+
mediaType: attachment.contentType
|
1618
1664
|
});
|
1619
1665
|
}
|
1620
1666
|
break;
|
@@ -1689,14 +1735,23 @@ function convertToCoreMessages(messages, options) {
|
|
1689
1735
|
case "assistant": {
|
1690
1736
|
if (message.parts != null) {
|
1691
1737
|
let processBlock2 = function() {
|
1738
|
+
var _a18;
|
1692
1739
|
const content2 = [];
|
1693
1740
|
for (const part of block) {
|
1694
1741
|
switch (part.type) {
|
1695
|
-
case "file":
|
1696
1742
|
case "text": {
|
1697
1743
|
content2.push(part);
|
1698
1744
|
break;
|
1699
1745
|
}
|
1746
|
+
case "file": {
|
1747
|
+
content2.push({
|
1748
|
+
type: "file",
|
1749
|
+
data: part.data,
|
1750
|
+
mediaType: (_a18 = part.mediaType) != null ? _a18 : part.mimeType
|
1751
|
+
// TODO migration, remove
|
1752
|
+
});
|
1753
|
+
break;
|
1754
|
+
}
|
1700
1755
|
case "reasoning": {
|
1701
1756
|
for (const detail of part.details) {
|
1702
1757
|
switch (detail.type) {
|
@@ -1953,7 +2008,7 @@ var toolResultContentSchema = z4.array(
|
|
1953
2008
|
z4.object({
|
1954
2009
|
type: z4.literal("image"),
|
1955
2010
|
data: z4.string(),
|
1956
|
-
|
2011
|
+
mediaType: z4.string().optional()
|
1957
2012
|
})
|
1958
2013
|
])
|
1959
2014
|
);
|
@@ -1968,6 +2023,7 @@ var textPartSchema = z5.object({
|
|
1968
2023
|
var imagePartSchema = z5.object({
|
1969
2024
|
type: z5.literal("image"),
|
1970
2025
|
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
2026
|
+
mediaType: z5.string().optional(),
|
1971
2027
|
mimeType: z5.string().optional(),
|
1972
2028
|
providerOptions: providerMetadataSchema.optional(),
|
1973
2029
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
@@ -1976,7 +2032,8 @@ var filePartSchema = z5.object({
|
|
1976
2032
|
type: z5.literal("file"),
|
1977
2033
|
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
1978
2034
|
filename: z5.string().optional(),
|
1979
|
-
|
2035
|
+
mediaType: z5.string(),
|
2036
|
+
mimeType: z5.string().optional(),
|
1980
2037
|
providerOptions: providerMetadataSchema.optional(),
|
1981
2038
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1982
2039
|
});
|
@@ -2689,8 +2746,8 @@ async function generateObject({
|
|
2689
2746
|
fn: async (span2) => {
|
2690
2747
|
var _a18, _b2, _c2, _d2, _e, _f;
|
2691
2748
|
const result2 = await model.doGenerate({
|
2692
|
-
|
2693
|
-
type: "
|
2749
|
+
responseFormat: {
|
2750
|
+
type: "json",
|
2694
2751
|
schema: outputStrategy.jsonSchema,
|
2695
2752
|
name: schemaName,
|
2696
2753
|
description: schemaDescription
|
@@ -2698,7 +2755,7 @@ async function generateObject({
|
|
2698
2755
|
...prepareCallSettings(settings),
|
2699
2756
|
inputFormat: standardizedPrompt.type,
|
2700
2757
|
prompt: promptMessages,
|
2701
|
-
|
2758
|
+
providerOptions,
|
2702
2759
|
abortSignal,
|
2703
2760
|
headers
|
2704
2761
|
});
|
@@ -2795,19 +2852,19 @@ async function generateObject({
|
|
2795
2852
|
fn: async (span2) => {
|
2796
2853
|
var _a18, _b2, _c2, _d2, _e, _f, _g, _h;
|
2797
2854
|
const result2 = await model.doGenerate({
|
2798
|
-
|
2799
|
-
|
2800
|
-
tool: {
|
2855
|
+
tools: [
|
2856
|
+
{
|
2801
2857
|
type: "function",
|
2802
2858
|
name: schemaName != null ? schemaName : "json",
|
2803
2859
|
description: schemaDescription != null ? schemaDescription : "Respond with a JSON object.",
|
2804
2860
|
parameters: outputStrategy.jsonSchema
|
2805
2861
|
}
|
2806
|
-
|
2862
|
+
],
|
2863
|
+
toolChoice: { type: "required" },
|
2807
2864
|
...prepareCallSettings(settings),
|
2808
2865
|
inputFormat,
|
2809
2866
|
prompt: promptMessages,
|
2810
|
-
|
2867
|
+
providerOptions,
|
2811
2868
|
abortSignal,
|
2812
2869
|
headers
|
2813
2870
|
});
|
@@ -3273,8 +3330,8 @@ var DefaultStreamObjectResult = class {
|
|
3273
3330
|
tools: void 0
|
3274
3331
|
});
|
3275
3332
|
callOptions = {
|
3276
|
-
|
3277
|
-
type: "
|
3333
|
+
responseFormat: {
|
3334
|
+
type: "json",
|
3278
3335
|
schema: outputStrategy.jsonSchema,
|
3279
3336
|
name: schemaName,
|
3280
3337
|
description: schemaDescription
|
@@ -3287,7 +3344,7 @@ var DefaultStreamObjectResult = class {
|
|
3287
3344
|
modelSupportsUrl: (_a17 = model.supportsUrl) == null ? void 0 : _a17.bind(model)
|
3288
3345
|
// support 'this' context
|
3289
3346
|
}),
|
3290
|
-
|
3347
|
+
providerOptions,
|
3291
3348
|
abortSignal,
|
3292
3349
|
headers
|
3293
3350
|
};
|
@@ -3313,15 +3370,15 @@ var DefaultStreamObjectResult = class {
|
|
3313
3370
|
tools: void 0
|
3314
3371
|
});
|
3315
3372
|
callOptions = {
|
3316
|
-
|
3317
|
-
|
3318
|
-
tool: {
|
3373
|
+
tools: [
|
3374
|
+
{
|
3319
3375
|
type: "function",
|
3320
3376
|
name: schemaName != null ? schemaName : "json",
|
3321
3377
|
description: schemaDescription != null ? schemaDescription : "Respond with a JSON object.",
|
3322
3378
|
parameters: outputStrategy.jsonSchema
|
3323
3379
|
}
|
3324
|
-
|
3380
|
+
],
|
3381
|
+
toolChoice: { type: "required" },
|
3325
3382
|
...prepareCallSettings(settings),
|
3326
3383
|
inputFormat: standardizedPrompt.type,
|
3327
3384
|
prompt: await convertToLanguageModelPrompt({
|
@@ -3330,7 +3387,7 @@ var DefaultStreamObjectResult = class {
|
|
3330
3387
|
modelSupportsUrl: (_b = model.supportsUrl) == null ? void 0 : _b.bind(model)
|
3331
3388
|
// support 'this' context,
|
3332
3389
|
}),
|
3333
|
-
|
3390
|
+
providerOptions,
|
3334
3391
|
abortSignal,
|
3335
3392
|
headers
|
3336
3393
|
};
|
@@ -3975,7 +4032,7 @@ function toResponseMessages({
|
|
3975
4032
|
...files.map((file) => ({
|
3976
4033
|
type: "file",
|
3977
4034
|
data: file.base64,
|
3978
|
-
|
4035
|
+
mediaType: file.mediaType
|
3979
4036
|
})),
|
3980
4037
|
{ type: "text", text: text2 },
|
3981
4038
|
...toolCalls
|
@@ -4087,8 +4144,7 @@ async function generateText({
|
|
4087
4144
|
tracer,
|
4088
4145
|
fn: async (span) => {
|
4089
4146
|
var _a18, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
4090
|
-
const
|
4091
|
-
type: "regular",
|
4147
|
+
const toolsAndToolChoice = {
|
4092
4148
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
4093
4149
|
};
|
4094
4150
|
const callSettings = prepareCallSettings(settings);
|
@@ -4142,11 +4198,11 @@ async function generateText({
|
|
4142
4198
|
// convert the language model level tools:
|
4143
4199
|
input: () => {
|
4144
4200
|
var _a19;
|
4145
|
-
return (_a19 =
|
4201
|
+
return (_a19 = toolsAndToolChoice.tools) == null ? void 0 : _a19.map((tool2) => JSON.stringify(tool2));
|
4146
4202
|
}
|
4147
4203
|
},
|
4148
4204
|
"ai.prompt.toolChoice": {
|
4149
|
-
input: () =>
|
4205
|
+
input: () => toolsAndToolChoice.toolChoice != null ? JSON.stringify(toolsAndToolChoice.toolChoice) : void 0
|
4150
4206
|
},
|
4151
4207
|
// standardized gen-ai llm span attributes:
|
4152
4208
|
"gen_ai.system": model.provider,
|
@@ -4164,12 +4220,12 @@ async function generateText({
|
|
4164
4220
|
fn: async (span2) => {
|
4165
4221
|
var _a19, _b2, _c2, _d2, _e2, _f2;
|
4166
4222
|
const result = await model.doGenerate({
|
4167
|
-
mode,
|
4168
4223
|
...callSettings,
|
4224
|
+
...toolsAndToolChoice,
|
4169
4225
|
inputFormat: promptFormat,
|
4170
4226
|
responseFormat: output == null ? void 0 : output.responseFormat({ model }),
|
4171
4227
|
prompt: promptMessages,
|
4172
|
-
|
4228
|
+
providerOptions,
|
4173
4229
|
abortSignal,
|
4174
4230
|
headers
|
4175
4231
|
});
|
@@ -4856,7 +4912,7 @@ function runToolsTransformation({
|
|
4856
4912
|
controller.enqueue(
|
4857
4913
|
new DefaultGeneratedFileWithType({
|
4858
4914
|
data: chunk.data,
|
4859
|
-
|
4915
|
+
mediaType: chunk.mediaType
|
4860
4916
|
})
|
4861
4917
|
);
|
4862
4918
|
break;
|
@@ -5474,8 +5530,7 @@ var DefaultStreamTextResult = class {
|
|
5474
5530
|
modelSupportsUrl: (_a18 = model.supportsUrl) == null ? void 0 : _a18.bind(model)
|
5475
5531
|
// support 'this' context
|
5476
5532
|
});
|
5477
|
-
const
|
5478
|
-
type: "regular",
|
5533
|
+
const toolsAndToolChoice = {
|
5479
5534
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
5480
5535
|
};
|
5481
5536
|
const {
|
@@ -5503,11 +5558,13 @@ var DefaultStreamTextResult = class {
|
|
5503
5558
|
// convert the language model level tools:
|
5504
5559
|
input: () => {
|
5505
5560
|
var _a19;
|
5506
|
-
return (_a19 =
|
5561
|
+
return (_a19 = toolsAndToolChoice.tools) == null ? void 0 : _a19.map(
|
5562
|
+
(tool2) => JSON.stringify(tool2)
|
5563
|
+
);
|
5507
5564
|
}
|
5508
5565
|
},
|
5509
5566
|
"ai.prompt.toolChoice": {
|
5510
|
-
input: () =>
|
5567
|
+
input: () => toolsAndToolChoice.toolChoice != null ? JSON.stringify(toolsAndToolChoice.toolChoice) : void 0
|
5511
5568
|
},
|
5512
5569
|
// standardized gen-ai llm span attributes:
|
5513
5570
|
"gen_ai.system": model.provider,
|
@@ -5528,12 +5585,12 @@ var DefaultStreamTextResult = class {
|
|
5528
5585
|
// get before the call
|
5529
5586
|
doStreamSpan: doStreamSpan2,
|
5530
5587
|
result: await model.doStream({
|
5531
|
-
mode,
|
5532
5588
|
...prepareCallSettings(settings),
|
5589
|
+
...toolsAndToolChoice,
|
5533
5590
|
inputFormat: promptFormat,
|
5534
5591
|
responseFormat: output == null ? void 0 : output.responseFormat({ model }),
|
5535
5592
|
prompt: promptMessages,
|
5536
|
-
|
5593
|
+
providerOptions,
|
5537
5594
|
abortSignal,
|
5538
5595
|
headers
|
5539
5596
|
})
|
@@ -6035,7 +6092,7 @@ var DefaultStreamTextResult = class {
|
|
6035
6092
|
case "file": {
|
6036
6093
|
controller.enqueue(
|
6037
6094
|
formatDataStreamPart2("file", {
|
6038
|
-
mimeType: chunk.
|
6095
|
+
mimeType: chunk.mediaType,
|
6039
6096
|
data: chunk.base64
|
6040
6097
|
})
|
6041
6098
|
);
|
@@ -6239,6 +6296,70 @@ var DefaultStreamTextResult = class {
|
|
6239
6296
|
}
|
6240
6297
|
};
|
6241
6298
|
|
6299
|
+
// errors/no-transcript-generated-error.ts
|
6300
|
+
import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
|
6301
|
+
var NoTranscriptGeneratedError = class extends AISDKError18 {
|
6302
|
+
constructor(options) {
|
6303
|
+
super({
|
6304
|
+
name: "AI_NoTranscriptGeneratedError",
|
6305
|
+
message: "No transcript generated."
|
6306
|
+
});
|
6307
|
+
this.responses = options.responses;
|
6308
|
+
}
|
6309
|
+
};
|
6310
|
+
|
6311
|
+
// core/transcribe/transcribe.ts
|
6312
|
+
async function transcribe({
|
6313
|
+
model,
|
6314
|
+
audio,
|
6315
|
+
providerOptions = {},
|
6316
|
+
maxRetries: maxRetriesArg,
|
6317
|
+
abortSignal,
|
6318
|
+
headers
|
6319
|
+
}) {
|
6320
|
+
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
6321
|
+
const audioData = audio instanceof URL ? (await download({ url: audio })).data : convertDataContentToUint8Array(audio);
|
6322
|
+
const result = await retry(
|
6323
|
+
() => {
|
6324
|
+
var _a17;
|
6325
|
+
return model.doGenerate({
|
6326
|
+
audio: audioData,
|
6327
|
+
abortSignal,
|
6328
|
+
headers,
|
6329
|
+
providerOptions,
|
6330
|
+
mediaType: (_a17 = detectMediaType({
|
6331
|
+
data: audioData,
|
6332
|
+
signatures: audioMediaTypeSignatures
|
6333
|
+
})) != null ? _a17 : "audio/wav"
|
6334
|
+
});
|
6335
|
+
}
|
6336
|
+
);
|
6337
|
+
if (!result.text) {
|
6338
|
+
throw new NoTranscriptGeneratedError({ responses: [result.response] });
|
6339
|
+
}
|
6340
|
+
return new DefaultTranscriptionResult({
|
6341
|
+
text: result.text,
|
6342
|
+
segments: result.segments,
|
6343
|
+
language: result.language,
|
6344
|
+
durationInSeconds: result.durationInSeconds,
|
6345
|
+
warnings: result.warnings,
|
6346
|
+
responses: [result.response],
|
6347
|
+
providerMetadata: result.providerMetadata
|
6348
|
+
});
|
6349
|
+
}
|
6350
|
+
var DefaultTranscriptionResult = class {
|
6351
|
+
constructor(options) {
|
6352
|
+
var _a17;
|
6353
|
+
this.text = options.text;
|
6354
|
+
this.segments = options.segments;
|
6355
|
+
this.language = options.language;
|
6356
|
+
this.durationInSeconds = options.durationInSeconds;
|
6357
|
+
this.warnings = options.warnings;
|
6358
|
+
this.responses = options.responses;
|
6359
|
+
this.providerMetadata = (_a17 = options.providerMetadata) != null ? _a17 : {};
|
6360
|
+
}
|
6361
|
+
};
|
6362
|
+
|
6242
6363
|
// core/util/merge-objects.ts
|
6243
6364
|
function mergeObjects(target, source) {
|
6244
6365
|
if (target === void 0 && source === void 0) {
|
@@ -6283,9 +6404,9 @@ function defaultSettingsMiddleware({
|
|
6283
6404
|
return {
|
6284
6405
|
...settings,
|
6285
6406
|
...params,
|
6286
|
-
|
6287
|
-
settings.
|
6288
|
-
params.
|
6407
|
+
providerOptions: mergeObjects(
|
6408
|
+
settings.providerOptions,
|
6409
|
+
params.providerOptions
|
6289
6410
|
),
|
6290
6411
|
// special case for temperature 0
|
6291
6412
|
// TODO remove when temperature defaults to undefined
|
@@ -6556,13 +6677,13 @@ function appendClientMessage({
|
|
6556
6677
|
import {
|
6557
6678
|
extractMaxToolInvocationStep
|
6558
6679
|
} from "@ai-sdk/ui-utils";
|
6559
|
-
import { AISDKError as
|
6680
|
+
import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
|
6560
6681
|
function appendResponseMessages({
|
6561
6682
|
messages,
|
6562
6683
|
responseMessages,
|
6563
6684
|
_internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
|
6564
6685
|
}) {
|
6565
|
-
var _a17, _b, _c, _d;
|
6686
|
+
var _a17, _b, _c, _d, _e;
|
6566
6687
|
const clonedMessages = structuredClone(messages);
|
6567
6688
|
for (const message of responseMessages) {
|
6568
6689
|
const role = message.role;
|
@@ -6639,14 +6760,14 @@ function appendResponseMessages({
|
|
6639
6760
|
break;
|
6640
6761
|
case "file":
|
6641
6762
|
if (part.data instanceof URL) {
|
6642
|
-
throw new
|
6763
|
+
throw new AISDKError19({
|
6643
6764
|
name: "InvalidAssistantFileData",
|
6644
6765
|
message: "File data cannot be a URL"
|
6645
6766
|
});
|
6646
6767
|
}
|
6647
6768
|
parts.push({
|
6648
6769
|
type: "file",
|
6649
|
-
|
6770
|
+
mediaType: (_a17 = part.mediaType) != null ? _a17 : part.mimeType,
|
6650
6771
|
data: convertDataContentToBase64String(part.data)
|
6651
6772
|
});
|
6652
6773
|
break;
|
@@ -6657,12 +6778,12 @@ function appendResponseMessages({
|
|
6657
6778
|
const maxStep = extractMaxToolInvocationStep(
|
6658
6779
|
lastMessage.toolInvocations
|
6659
6780
|
);
|
6660
|
-
(
|
6781
|
+
(_b = lastMessage.parts) != null ? _b : lastMessage.parts = [];
|
6661
6782
|
lastMessage.content = textContent;
|
6662
6783
|
lastMessage.reasoning = reasoningTextContent;
|
6663
6784
|
lastMessage.parts.push(...parts);
|
6664
6785
|
lastMessage.toolInvocations = [
|
6665
|
-
...(
|
6786
|
+
...(_c = lastMessage.toolInvocations) != null ? _c : [],
|
6666
6787
|
...getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1)
|
6667
6788
|
];
|
6668
6789
|
getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1).map((call) => ({
|
@@ -6692,13 +6813,13 @@ function appendResponseMessages({
|
|
6692
6813
|
break;
|
6693
6814
|
}
|
6694
6815
|
case "tool": {
|
6695
|
-
(
|
6816
|
+
(_d = lastMessage.toolInvocations) != null ? _d : lastMessage.toolInvocations = [];
|
6696
6817
|
if (lastMessage.role !== "assistant") {
|
6697
6818
|
throw new Error(
|
6698
6819
|
`Tool result must follow an assistant message: ${lastMessage.role}`
|
6699
6820
|
);
|
6700
6821
|
}
|
6701
|
-
(
|
6822
|
+
(_e = lastMessage.parts) != null ? _e : lastMessage.parts = [];
|
6702
6823
|
for (const contentPart of message.content) {
|
6703
6824
|
const toolCall = lastMessage.toolInvocations.find(
|
6704
6825
|
(call) => call.toolCallId === contentPart.toolCallId
|
@@ -6773,7 +6894,7 @@ function customProvider({
|
|
6773
6894
|
var experimental_customProvider = customProvider;
|
6774
6895
|
|
6775
6896
|
// core/registry/no-such-provider-error.ts
|
6776
|
-
import { AISDKError as
|
6897
|
+
import { AISDKError as AISDKError20, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
|
6777
6898
|
var name16 = "AI_NoSuchProviderError";
|
6778
6899
|
var marker16 = `vercel.ai.error.${name16}`;
|
6779
6900
|
var symbol16 = Symbol.for(marker16);
|
@@ -6792,7 +6913,7 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
6792
6913
|
this.availableProviders = availableProviders;
|
6793
6914
|
}
|
6794
6915
|
static isInstance(error) {
|
6795
|
-
return
|
6916
|
+
return AISDKError20.hasMarker(error, marker16);
|
6796
6917
|
}
|
6797
6918
|
};
|
6798
6919
|
_a16 = symbol16;
|
@@ -7777,6 +7898,7 @@ export {
|
|
7777
7898
|
experimental_createProviderRegistry,
|
7778
7899
|
experimental_customProvider,
|
7779
7900
|
generateImage as experimental_generateImage,
|
7901
|
+
transcribe as experimental_transcribe,
|
7780
7902
|
experimental_wrapLanguageModel,
|
7781
7903
|
extractReasoningMiddleware,
|
7782
7904
|
formatDataStreamPart3 as formatDataStreamPart,
|