ai 3.4.18 → 3.4.21
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 +43 -0
- package/dist/index.d.mts +107 -76
- package/dist/index.d.ts +107 -76
- package/dist/index.js +380 -397
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +366 -386
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -12
- package/rsc/dist/index.d.ts +13 -0
- package/rsc/dist/rsc-server.d.mts +13 -0
- package/rsc/dist/rsc-server.mjs +178 -241
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +3 -1
- package/test/dist/index.d.ts +3 -1
- package/test/dist/index.js +2 -0
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +2 -0
- package/test/dist/index.mjs.map +1 -1
package/dist/index.js
CHANGED
@@ -96,7 +96,7 @@ __export(streams_exports, {
|
|
96
96
|
});
|
97
97
|
module.exports = __toCommonJS(streams_exports);
|
98
98
|
var import_ui_utils10 = require("@ai-sdk/ui-utils");
|
99
|
-
var
|
99
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
100
100
|
|
101
101
|
// core/index.ts
|
102
102
|
var import_ui_utils6 = require("@ai-sdk/ui-utils");
|
@@ -676,10 +676,7 @@ var DefaultEmbedManyResult = class {
|
|
676
676
|
};
|
677
677
|
|
678
678
|
// core/generate-object/generate-object.ts
|
679
|
-
var
|
680
|
-
|
681
|
-
// core/prompt/convert-to-language-model-prompt.ts
|
682
|
-
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
679
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
683
680
|
|
684
681
|
// util/download-error.ts
|
685
682
|
var import_provider3 = require("@ai-sdk/provider");
|
@@ -923,19 +920,21 @@ function splitDataUrl(dataUrl) {
|
|
923
920
|
async function convertToLanguageModelPrompt({
|
924
921
|
prompt,
|
925
922
|
modelSupportsImageUrls = true,
|
923
|
+
modelSupportsUrl = () => false,
|
926
924
|
downloadImplementation = download
|
927
925
|
}) {
|
928
|
-
const downloadedAssets =
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
926
|
+
const downloadedAssets = await downloadAssets(
|
927
|
+
prompt.messages,
|
928
|
+
downloadImplementation,
|
929
|
+
modelSupportsImageUrls,
|
930
|
+
modelSupportsUrl
|
931
|
+
);
|
932
|
+
return [
|
933
|
+
...prompt.system != null ? [{ role: "system", content: prompt.system }] : [],
|
934
934
|
...prompt.messages.map(
|
935
935
|
(message) => convertToLanguageModelMessage(message, downloadedAssets)
|
936
936
|
)
|
937
|
-
|
938
|
-
return languageModelMessages;
|
937
|
+
];
|
939
938
|
}
|
940
939
|
function convertToLanguageModelMessage(message, downloadedAssets) {
|
941
940
|
const role = message.role;
|
@@ -957,178 +956,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
957
956
|
}
|
958
957
|
return {
|
959
958
|
role: "user",
|
960
|
-
content: message.content.map(
|
961
|
-
(part) => {
|
962
|
-
var _a11, _b, _c, _d, _e;
|
963
|
-
switch (part.type) {
|
964
|
-
case "text": {
|
965
|
-
return {
|
966
|
-
type: "text",
|
967
|
-
text: part.text,
|
968
|
-
providerMetadata: part.experimental_providerMetadata
|
969
|
-
};
|
970
|
-
}
|
971
|
-
case "image": {
|
972
|
-
if (part.image instanceof URL) {
|
973
|
-
if (downloadedAssets == null) {
|
974
|
-
return {
|
975
|
-
type: "image",
|
976
|
-
image: part.image,
|
977
|
-
mimeType: part.mimeType,
|
978
|
-
providerMetadata: part.experimental_providerMetadata
|
979
|
-
};
|
980
|
-
} else {
|
981
|
-
const downloadedImage = downloadedAssets[part.image.toString()];
|
982
|
-
return {
|
983
|
-
type: "image",
|
984
|
-
image: downloadedImage.data,
|
985
|
-
mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
|
986
|
-
providerMetadata: part.experimental_providerMetadata
|
987
|
-
};
|
988
|
-
}
|
989
|
-
}
|
990
|
-
if (typeof part.image === "string") {
|
991
|
-
try {
|
992
|
-
const url = new URL(part.image);
|
993
|
-
switch (url.protocol) {
|
994
|
-
case "http:":
|
995
|
-
case "https:": {
|
996
|
-
if (downloadedAssets == null) {
|
997
|
-
return {
|
998
|
-
type: "image",
|
999
|
-
image: url,
|
1000
|
-
mimeType: part.mimeType,
|
1001
|
-
providerMetadata: part.experimental_providerMetadata
|
1002
|
-
};
|
1003
|
-
} else {
|
1004
|
-
const downloadedImage = downloadedAssets[url.toString()];
|
1005
|
-
return {
|
1006
|
-
type: "image",
|
1007
|
-
image: downloadedImage.data,
|
1008
|
-
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
1009
|
-
providerMetadata: part.experimental_providerMetadata
|
1010
|
-
};
|
1011
|
-
}
|
1012
|
-
}
|
1013
|
-
case "data:": {
|
1014
|
-
try {
|
1015
|
-
const { mimeType, base64Content } = splitDataUrl(
|
1016
|
-
part.image
|
1017
|
-
);
|
1018
|
-
if (mimeType == null || base64Content == null) {
|
1019
|
-
throw new Error("Invalid data URL format");
|
1020
|
-
}
|
1021
|
-
return {
|
1022
|
-
type: "image",
|
1023
|
-
image: convertDataContentToUint8Array(base64Content),
|
1024
|
-
mimeType,
|
1025
|
-
providerMetadata: part.experimental_providerMetadata
|
1026
|
-
};
|
1027
|
-
} catch (error) {
|
1028
|
-
throw new Error(
|
1029
|
-
`Error processing data URL: ${(0, import_provider_utils3.getErrorMessage)(
|
1030
|
-
message
|
1031
|
-
)}`
|
1032
|
-
);
|
1033
|
-
}
|
1034
|
-
}
|
1035
|
-
}
|
1036
|
-
} catch (_ignored) {
|
1037
|
-
}
|
1038
|
-
}
|
1039
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
1040
|
-
return {
|
1041
|
-
type: "image",
|
1042
|
-
image: imageUint8,
|
1043
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
1044
|
-
providerMetadata: part.experimental_providerMetadata
|
1045
|
-
};
|
1046
|
-
}
|
1047
|
-
case "file": {
|
1048
|
-
if (part.data instanceof URL) {
|
1049
|
-
if (downloadedAssets == null) {
|
1050
|
-
return {
|
1051
|
-
type: "file",
|
1052
|
-
data: part.data,
|
1053
|
-
mimeType: part.mimeType,
|
1054
|
-
providerMetadata: part.experimental_providerMetadata
|
1055
|
-
};
|
1056
|
-
} else {
|
1057
|
-
const downloadedImage = downloadedAssets[part.data.toString()];
|
1058
|
-
return {
|
1059
|
-
type: "file",
|
1060
|
-
data: (0, import_provider_utils3.convertUint8ArrayToBase64)(downloadedImage.data),
|
1061
|
-
mimeType: (_d = part.mimeType) != null ? _d : downloadedImage.mimeType,
|
1062
|
-
providerMetadata: part.experimental_providerMetadata
|
1063
|
-
};
|
1064
|
-
}
|
1065
|
-
}
|
1066
|
-
if (typeof part.data === "string") {
|
1067
|
-
try {
|
1068
|
-
const url = new URL(part.data);
|
1069
|
-
switch (url.protocol) {
|
1070
|
-
case "http:":
|
1071
|
-
case "https:": {
|
1072
|
-
if (downloadedAssets == null) {
|
1073
|
-
return {
|
1074
|
-
type: "file",
|
1075
|
-
data: url,
|
1076
|
-
mimeType: part.mimeType,
|
1077
|
-
providerMetadata: part.experimental_providerMetadata
|
1078
|
-
};
|
1079
|
-
} else {
|
1080
|
-
const downloadedImage = downloadedAssets[url.toString()];
|
1081
|
-
return {
|
1082
|
-
type: "file",
|
1083
|
-
data: (0, import_provider_utils3.convertUint8ArrayToBase64)(
|
1084
|
-
downloadedImage.data
|
1085
|
-
),
|
1086
|
-
mimeType: (_e = part.mimeType) != null ? _e : downloadedImage.mimeType,
|
1087
|
-
providerMetadata: part.experimental_providerMetadata
|
1088
|
-
};
|
1089
|
-
}
|
1090
|
-
}
|
1091
|
-
case "data:": {
|
1092
|
-
try {
|
1093
|
-
const { mimeType, base64Content } = splitDataUrl(
|
1094
|
-
part.data
|
1095
|
-
);
|
1096
|
-
if (mimeType == null || base64Content == null) {
|
1097
|
-
throw new Error("Invalid data URL format");
|
1098
|
-
}
|
1099
|
-
return {
|
1100
|
-
type: "file",
|
1101
|
-
data: convertDataContentToBase64String(
|
1102
|
-
base64Content
|
1103
|
-
),
|
1104
|
-
mimeType,
|
1105
|
-
providerMetadata: part.experimental_providerMetadata
|
1106
|
-
};
|
1107
|
-
} catch (error) {
|
1108
|
-
throw new Error(
|
1109
|
-
`Error processing data URL: ${(0, import_provider_utils3.getErrorMessage)(
|
1110
|
-
message
|
1111
|
-
)}`
|
1112
|
-
);
|
1113
|
-
}
|
1114
|
-
}
|
1115
|
-
}
|
1116
|
-
} catch (_ignored) {
|
1117
|
-
}
|
1118
|
-
}
|
1119
|
-
const imageBase64 = convertDataContentToBase64String(
|
1120
|
-
part.data
|
1121
|
-
);
|
1122
|
-
return {
|
1123
|
-
type: "file",
|
1124
|
-
data: imageBase64,
|
1125
|
-
mimeType: part.mimeType,
|
1126
|
-
providerMetadata: part.experimental_providerMetadata
|
1127
|
-
};
|
1128
|
-
}
|
1129
|
-
}
|
1130
|
-
}
|
1131
|
-
).filter((part) => part.type !== "text" || part.text !== ""),
|
959
|
+
content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
1132
960
|
providerMetadata: message.experimental_providerMetadata
|
1133
961
|
};
|
1134
962
|
}
|
@@ -1163,6 +991,8 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1163
991
|
toolCallId: part.toolCallId,
|
1164
992
|
toolName: part.toolName,
|
1165
993
|
result: part.result,
|
994
|
+
content: part.experimental_content,
|
995
|
+
isError: part.isError,
|
1166
996
|
providerMetadata: part.experimental_providerMetadata
|
1167
997
|
})),
|
1168
998
|
providerMetadata: message.experimental_providerMetadata
|
@@ -1174,17 +1004,19 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1174
1004
|
}
|
1175
1005
|
}
|
1176
1006
|
}
|
1177
|
-
async function downloadAssets(messages, downloadImplementation) {
|
1007
|
+
async function downloadAssets(messages, downloadImplementation, modelSupportsImageUrls, modelSupportsUrl) {
|
1178
1008
|
const urls = messages.filter((message) => message.role === "user").map((message) => message.content).filter(
|
1179
1009
|
(content) => Array.isArray(content)
|
1180
1010
|
).flat().filter(
|
1181
1011
|
(part) => part.type === "image" || part.type === "file"
|
1012
|
+
).filter(
|
1013
|
+
(part) => !(part.type === "image" && modelSupportsImageUrls === true)
|
1182
1014
|
).map((part) => part.type === "image" ? part.image : part.data).map(
|
1183
1015
|
(part) => (
|
1184
1016
|
// support string urls:
|
1185
1017
|
typeof part === "string" && (part.startsWith("http:") || part.startsWith("https:")) ? new URL(part) : part
|
1186
1018
|
)
|
1187
|
-
).filter((image) => image instanceof URL);
|
1019
|
+
).filter((image) => image instanceof URL).filter((url) => !modelSupportsUrl(url));
|
1188
1020
|
const downloadedImages = await Promise.all(
|
1189
1021
|
urls.map(async (url) => ({
|
1190
1022
|
url,
|
@@ -1195,6 +1027,79 @@ async function downloadAssets(messages, downloadImplementation) {
|
|
1195
1027
|
downloadedImages.map(({ url, data }) => [url.toString(), data])
|
1196
1028
|
);
|
1197
1029
|
}
|
1030
|
+
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1031
|
+
if (part.type === "text") {
|
1032
|
+
return {
|
1033
|
+
type: "text",
|
1034
|
+
text: part.text,
|
1035
|
+
providerMetadata: part.experimental_providerMetadata
|
1036
|
+
};
|
1037
|
+
}
|
1038
|
+
let mimeType = part.mimeType;
|
1039
|
+
let data;
|
1040
|
+
let content;
|
1041
|
+
let normalizedData;
|
1042
|
+
const type = part.type;
|
1043
|
+
switch (type) {
|
1044
|
+
case "image":
|
1045
|
+
data = part.image;
|
1046
|
+
break;
|
1047
|
+
case "file":
|
1048
|
+
data = part.data;
|
1049
|
+
break;
|
1050
|
+
default:
|
1051
|
+
throw new Error(`Unsupported part type: ${type}`);
|
1052
|
+
}
|
1053
|
+
try {
|
1054
|
+
content = typeof data === "string" ? new URL(data) : data;
|
1055
|
+
} catch (error) {
|
1056
|
+
content = data;
|
1057
|
+
}
|
1058
|
+
if (content instanceof URL) {
|
1059
|
+
if (content.protocol === "data:") {
|
1060
|
+
const { mimeType: dataUrlMimeType, base64Content } = splitDataUrl(
|
1061
|
+
content.toString()
|
1062
|
+
);
|
1063
|
+
if (dataUrlMimeType == null || base64Content == null) {
|
1064
|
+
throw new Error(`Invalid data URL format in part ${type}`);
|
1065
|
+
}
|
1066
|
+
mimeType = dataUrlMimeType;
|
1067
|
+
normalizedData = convertDataContentToUint8Array(base64Content);
|
1068
|
+
} else {
|
1069
|
+
const downloadedFile = downloadedAssets[content.toString()];
|
1070
|
+
if (downloadedFile) {
|
1071
|
+
normalizedData = downloadedFile.data;
|
1072
|
+
mimeType != null ? mimeType : mimeType = downloadedFile.mimeType;
|
1073
|
+
} else {
|
1074
|
+
normalizedData = content;
|
1075
|
+
}
|
1076
|
+
}
|
1077
|
+
} else {
|
1078
|
+
normalizedData = convertDataContentToUint8Array(content);
|
1079
|
+
}
|
1080
|
+
switch (type) {
|
1081
|
+
case "image":
|
1082
|
+
if (mimeType == null && normalizedData instanceof Uint8Array) {
|
1083
|
+
mimeType = detectImageMimeType(normalizedData);
|
1084
|
+
}
|
1085
|
+
return {
|
1086
|
+
type: "image",
|
1087
|
+
image: normalizedData,
|
1088
|
+
mimeType,
|
1089
|
+
providerMetadata: part.experimental_providerMetadata
|
1090
|
+
};
|
1091
|
+
case "file":
|
1092
|
+
if (mimeType == null) {
|
1093
|
+
throw new Error(`Mime type is missing for file part`);
|
1094
|
+
}
|
1095
|
+
return {
|
1096
|
+
type: "file",
|
1097
|
+
data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
|
1098
|
+
mimeType,
|
1099
|
+
providerMetadata: part.experimental_providerMetadata
|
1100
|
+
};
|
1101
|
+
}
|
1102
|
+
}
|
1198
1103
|
|
1199
1104
|
// errors/invalid-argument-error.ts
|
1200
1105
|
var import_provider6 = require("@ai-sdk/provider");
|
@@ -1350,11 +1255,11 @@ function prepareCallSettings({
|
|
1350
1255
|
|
1351
1256
|
// core/prompt/standardize-prompt.ts
|
1352
1257
|
var import_provider7 = require("@ai-sdk/provider");
|
1353
|
-
var
|
1354
|
-
var
|
1258
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
1259
|
+
var import_zod7 = require("zod");
|
1355
1260
|
|
1356
1261
|
// core/prompt/message.ts
|
1357
|
-
var
|
1262
|
+
var import_zod6 = require("zod");
|
1358
1263
|
|
1359
1264
|
// core/types/provider-metadata.ts
|
1360
1265
|
var import_zod3 = require("zod");
|
@@ -1379,67 +1284,83 @@ var providerMetadataSchema = import_zod3.z.record(
|
|
1379
1284
|
);
|
1380
1285
|
|
1381
1286
|
// core/prompt/content-part.ts
|
1287
|
+
var import_zod5 = require("zod");
|
1288
|
+
|
1289
|
+
// core/prompt/tool-result-content.ts
|
1382
1290
|
var import_zod4 = require("zod");
|
1383
|
-
var
|
1384
|
-
|
1385
|
-
|
1291
|
+
var toolResultContentSchema = import_zod4.z.array(
|
1292
|
+
import_zod4.z.union([
|
1293
|
+
import_zod4.z.object({ type: import_zod4.z.literal("text"), text: import_zod4.z.string() }),
|
1294
|
+
import_zod4.z.object({
|
1295
|
+
type: import_zod4.z.literal("image"),
|
1296
|
+
data: import_zod4.z.string(),
|
1297
|
+
mimeType: import_zod4.z.string().optional()
|
1298
|
+
})
|
1299
|
+
])
|
1300
|
+
);
|
1301
|
+
|
1302
|
+
// core/prompt/content-part.ts
|
1303
|
+
var textPartSchema = import_zod5.z.object({
|
1304
|
+
type: import_zod5.z.literal("text"),
|
1305
|
+
text: import_zod5.z.string(),
|
1386
1306
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1387
1307
|
});
|
1388
|
-
var imagePartSchema =
|
1389
|
-
type:
|
1390
|
-
image:
|
1391
|
-
mimeType:
|
1308
|
+
var imagePartSchema = import_zod5.z.object({
|
1309
|
+
type: import_zod5.z.literal("image"),
|
1310
|
+
image: import_zod5.z.union([dataContentSchema, import_zod5.z.instanceof(URL)]),
|
1311
|
+
mimeType: import_zod5.z.string().optional(),
|
1392
1312
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1393
1313
|
});
|
1394
|
-
var filePartSchema =
|
1395
|
-
type:
|
1396
|
-
data:
|
1397
|
-
mimeType:
|
1314
|
+
var filePartSchema = import_zod5.z.object({
|
1315
|
+
type: import_zod5.z.literal("file"),
|
1316
|
+
data: import_zod5.z.union([dataContentSchema, import_zod5.z.instanceof(URL)]),
|
1317
|
+
mimeType: import_zod5.z.string(),
|
1398
1318
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1399
1319
|
});
|
1400
|
-
var toolCallPartSchema =
|
1401
|
-
type:
|
1402
|
-
toolCallId:
|
1403
|
-
toolName:
|
1404
|
-
args:
|
1320
|
+
var toolCallPartSchema = import_zod5.z.object({
|
1321
|
+
type: import_zod5.z.literal("tool-call"),
|
1322
|
+
toolCallId: import_zod5.z.string(),
|
1323
|
+
toolName: import_zod5.z.string(),
|
1324
|
+
args: import_zod5.z.unknown()
|
1405
1325
|
});
|
1406
|
-
var toolResultPartSchema =
|
1407
|
-
type:
|
1408
|
-
toolCallId:
|
1409
|
-
toolName:
|
1410
|
-
result:
|
1411
|
-
|
1326
|
+
var toolResultPartSchema = import_zod5.z.object({
|
1327
|
+
type: import_zod5.z.literal("tool-result"),
|
1328
|
+
toolCallId: import_zod5.z.string(),
|
1329
|
+
toolName: import_zod5.z.string(),
|
1330
|
+
result: import_zod5.z.unknown(),
|
1331
|
+
content: toolResultContentSchema.optional(),
|
1332
|
+
isError: import_zod5.z.boolean().optional(),
|
1412
1333
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1413
1334
|
});
|
1414
1335
|
|
1415
1336
|
// core/prompt/message.ts
|
1416
|
-
var coreSystemMessageSchema =
|
1417
|
-
role:
|
1418
|
-
content:
|
1337
|
+
var coreSystemMessageSchema = import_zod6.z.object({
|
1338
|
+
role: import_zod6.z.literal("system"),
|
1339
|
+
content: import_zod6.z.string(),
|
1419
1340
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1420
1341
|
});
|
1421
|
-
var coreUserMessageSchema =
|
1422
|
-
role:
|
1423
|
-
content:
|
1424
|
-
|
1425
|
-
|
1342
|
+
var coreUserMessageSchema = import_zod6.z.object({
|
1343
|
+
role: import_zod6.z.literal("user"),
|
1344
|
+
content: import_zod6.z.union([
|
1345
|
+
import_zod6.z.string(),
|
1346
|
+
import_zod6.z.array(import_zod6.z.union([textPartSchema, imagePartSchema, filePartSchema]))
|
1426
1347
|
]),
|
1427
1348
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1428
1349
|
});
|
1429
|
-
var coreAssistantMessageSchema =
|
1430
|
-
role:
|
1431
|
-
content:
|
1432
|
-
|
1433
|
-
|
1350
|
+
var coreAssistantMessageSchema = import_zod6.z.object({
|
1351
|
+
role: import_zod6.z.literal("assistant"),
|
1352
|
+
content: import_zod6.z.union([
|
1353
|
+
import_zod6.z.string(),
|
1354
|
+
import_zod6.z.array(import_zod6.z.union([textPartSchema, toolCallPartSchema]))
|
1434
1355
|
]),
|
1435
1356
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1436
1357
|
});
|
1437
|
-
var coreToolMessageSchema =
|
1438
|
-
role:
|
1439
|
-
content:
|
1358
|
+
var coreToolMessageSchema = import_zod6.z.object({
|
1359
|
+
role: import_zod6.z.literal("tool"),
|
1360
|
+
content: import_zod6.z.array(toolResultPartSchema),
|
1440
1361
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1441
1362
|
});
|
1442
|
-
var coreMessageSchema =
|
1363
|
+
var coreMessageSchema = import_zod6.z.union([
|
1443
1364
|
coreSystemMessageSchema,
|
1444
1365
|
coreUserMessageSchema,
|
1445
1366
|
coreAssistantMessageSchema,
|
@@ -1485,9 +1406,9 @@ function standardizePrompt(prompt) {
|
|
1485
1406
|
};
|
1486
1407
|
}
|
1487
1408
|
if (prompt.messages != null) {
|
1488
|
-
const validationResult = (0,
|
1409
|
+
const validationResult = (0, import_provider_utils3.safeValidateTypes)({
|
1489
1410
|
value: prompt.messages,
|
1490
|
-
schema:
|
1411
|
+
schema: import_zod7.z.array(coreMessageSchema)
|
1491
1412
|
});
|
1492
1413
|
if (!validationResult.success) {
|
1493
1414
|
throw new import_provider7.InvalidPromptError({
|
@@ -1588,7 +1509,7 @@ _a6 = symbol6;
|
|
1588
1509
|
|
1589
1510
|
// core/generate-object/output-strategy.ts
|
1590
1511
|
var import_provider9 = require("@ai-sdk/provider");
|
1591
|
-
var
|
1512
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1592
1513
|
var import_ui_utils = require("@ai-sdk/ui-utils");
|
1593
1514
|
|
1594
1515
|
// core/util/async-iterable-stream.ts
|
@@ -1638,7 +1559,7 @@ var objectOutputStrategy = (schema) => ({
|
|
1638
1559
|
};
|
1639
1560
|
},
|
1640
1561
|
validateFinalResult(value) {
|
1641
|
-
return (0,
|
1562
|
+
return (0, import_provider_utils4.safeValidateTypes)({ value, schema });
|
1642
1563
|
},
|
1643
1564
|
createElementStream() {
|
1644
1565
|
throw new import_provider9.UnsupportedFunctionalityError({
|
@@ -1677,7 +1598,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1677
1598
|
const resultArray = [];
|
1678
1599
|
for (let i = 0; i < inputArray.length; i++) {
|
1679
1600
|
const element = inputArray[i];
|
1680
|
-
const result = (0,
|
1601
|
+
const result = (0, import_provider_utils4.safeValidateTypes)({ value: element, schema });
|
1681
1602
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
1682
1603
|
continue;
|
1683
1604
|
}
|
@@ -1718,7 +1639,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1718
1639
|
}
|
1719
1640
|
const inputArray = value.elements;
|
1720
1641
|
for (const element of inputArray) {
|
1721
|
-
const result = (0,
|
1642
|
+
const result = (0, import_provider_utils4.safeValidateTypes)({ value: element, schema });
|
1722
1643
|
if (!result.success) {
|
1723
1644
|
return result;
|
1724
1645
|
}
|
@@ -1947,7 +1868,7 @@ function validateObjectGenerationInput({
|
|
1947
1868
|
}
|
1948
1869
|
|
1949
1870
|
// core/generate-object/generate-object.ts
|
1950
|
-
var originalGenerateId = (0,
|
1871
|
+
var originalGenerateId = (0, import_provider_utils5.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
1951
1872
|
async function generateObject({
|
1952
1873
|
model,
|
1953
1874
|
enum: enumValues,
|
@@ -2017,6 +1938,7 @@ async function generateObject({
|
|
2017
1938
|
}),
|
2018
1939
|
tracer,
|
2019
1940
|
fn: async (span) => {
|
1941
|
+
var _a11, _b;
|
2020
1942
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2021
1943
|
if (mode === "auto" || mode == null) {
|
2022
1944
|
mode = model.defaultObjectGenerationMode;
|
@@ -2027,6 +1949,7 @@ async function generateObject({
|
|
2027
1949
|
let warnings;
|
2028
1950
|
let rawResponse;
|
2029
1951
|
let response;
|
1952
|
+
let request;
|
2030
1953
|
let logprobs;
|
2031
1954
|
let resultProviderMetadata;
|
2032
1955
|
switch (mode) {
|
@@ -2041,7 +1964,8 @@ async function generateObject({
|
|
2041
1964
|
});
|
2042
1965
|
const promptMessages = await convertToLanguageModelPrompt({
|
2043
1966
|
prompt: standardPrompt,
|
2044
|
-
modelSupportsImageUrls: model.supportsImageUrls
|
1967
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
1968
|
+
modelSupportsUrl: model.supportsUrl
|
2045
1969
|
});
|
2046
1970
|
const generateResult = await retry(
|
2047
1971
|
() => recordSpan({
|
@@ -2074,7 +1998,7 @@ async function generateObject({
|
|
2074
1998
|
}),
|
2075
1999
|
tracer,
|
2076
2000
|
fn: async (span2) => {
|
2077
|
-
var
|
2001
|
+
var _a12, _b2, _c, _d, _e, _f;
|
2078
2002
|
const result2 = await model.doGenerate({
|
2079
2003
|
mode: {
|
2080
2004
|
type: "object-json",
|
@@ -2093,7 +2017,7 @@ async function generateObject({
|
|
2093
2017
|
throw new NoObjectGeneratedError();
|
2094
2018
|
}
|
2095
2019
|
const responseData = {
|
2096
|
-
id: (
|
2020
|
+
id: (_b2 = (_a12 = result2.response) == null ? void 0 : _a12.id) != null ? _b2 : generateId3(),
|
2097
2021
|
timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
|
2098
2022
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
2099
2023
|
};
|
@@ -2131,6 +2055,7 @@ async function generateObject({
|
|
2131
2055
|
rawResponse = generateResult.rawResponse;
|
2132
2056
|
logprobs = generateResult.logprobs;
|
2133
2057
|
resultProviderMetadata = generateResult.providerMetadata;
|
2058
|
+
request = (_a11 = generateResult.request) != null ? _a11 : {};
|
2134
2059
|
response = generateResult.responseData;
|
2135
2060
|
break;
|
2136
2061
|
}
|
@@ -2142,7 +2067,8 @@ async function generateObject({
|
|
2142
2067
|
});
|
2143
2068
|
const promptMessages = await convertToLanguageModelPrompt({
|
2144
2069
|
prompt: validatedPrompt,
|
2145
|
-
modelSupportsImageUrls: model.supportsImageUrls
|
2070
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
2071
|
+
modelSupportsUrl: model.supportsUrl
|
2146
2072
|
});
|
2147
2073
|
const inputFormat = validatedPrompt.type;
|
2148
2074
|
const generateResult = await retry(
|
@@ -2176,7 +2102,7 @@ async function generateObject({
|
|
2176
2102
|
}),
|
2177
2103
|
tracer,
|
2178
2104
|
fn: async (span2) => {
|
2179
|
-
var
|
2105
|
+
var _a12, _b2, _c, _d, _e, _f, _g, _h;
|
2180
2106
|
const result2 = await model.doGenerate({
|
2181
2107
|
mode: {
|
2182
2108
|
type: "object-tool",
|
@@ -2194,7 +2120,7 @@ async function generateObject({
|
|
2194
2120
|
abortSignal,
|
2195
2121
|
headers
|
2196
2122
|
});
|
2197
|
-
const objectText = (
|
2123
|
+
const objectText = (_b2 = (_a12 = result2.toolCalls) == null ? void 0 : _a12[0]) == null ? void 0 : _b2.args;
|
2198
2124
|
if (objectText === void 0) {
|
2199
2125
|
throw new NoObjectGeneratedError();
|
2200
2126
|
}
|
@@ -2237,6 +2163,7 @@ async function generateObject({
|
|
2237
2163
|
rawResponse = generateResult.rawResponse;
|
2238
2164
|
logprobs = generateResult.logprobs;
|
2239
2165
|
resultProviderMetadata = generateResult.providerMetadata;
|
2166
|
+
request = (_b = generateResult.request) != null ? _b : {};
|
2240
2167
|
response = generateResult.responseData;
|
2241
2168
|
break;
|
2242
2169
|
}
|
@@ -2250,7 +2177,7 @@ async function generateObject({
|
|
2250
2177
|
throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
|
2251
2178
|
}
|
2252
2179
|
}
|
2253
|
-
const parseResult = (0,
|
2180
|
+
const parseResult = (0, import_provider_utils5.safeParseJSON)({ text: result });
|
2254
2181
|
if (!parseResult.success) {
|
2255
2182
|
throw parseResult.error;
|
2256
2183
|
}
|
@@ -2283,6 +2210,7 @@ async function generateObject({
|
|
2283
2210
|
finishReason,
|
2284
2211
|
usage: calculateLanguageModelUsage(usage),
|
2285
2212
|
warnings,
|
2213
|
+
request,
|
2286
2214
|
response: {
|
2287
2215
|
...response,
|
2288
2216
|
headers: rawResponse == null ? void 0 : rawResponse.headers
|
@@ -2301,6 +2229,7 @@ var DefaultGenerateObjectResult = class {
|
|
2301
2229
|
this.warnings = options.warnings;
|
2302
2230
|
this.experimental_providerMetadata = options.providerMetadata;
|
2303
2231
|
this.response = options.response;
|
2232
|
+
this.request = options.request;
|
2304
2233
|
this.rawResponse = {
|
2305
2234
|
headers: options.response.headers
|
2306
2235
|
};
|
@@ -2319,7 +2248,7 @@ var DefaultGenerateObjectResult = class {
|
|
2319
2248
|
var experimental_generateObject = generateObject;
|
2320
2249
|
|
2321
2250
|
// core/generate-object/stream-object.ts
|
2322
|
-
var
|
2251
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
2323
2252
|
var import_ui_utils2 = require("@ai-sdk/ui-utils");
|
2324
2253
|
|
2325
2254
|
// util/create-resolvable-promise.ts
|
@@ -2429,7 +2358,7 @@ function writeToServerResponse({
|
|
2429
2358
|
}
|
2430
2359
|
|
2431
2360
|
// core/generate-object/stream-object.ts
|
2432
|
-
var originalGenerateId2 = (0,
|
2361
|
+
var originalGenerateId2 = (0, import_provider_utils6.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
2433
2362
|
async function streamObject({
|
2434
2363
|
model,
|
2435
2364
|
schema: inputSchema,
|
@@ -2522,7 +2451,8 @@ async function streamObject({
|
|
2522
2451
|
inputFormat: standardPrompt.type,
|
2523
2452
|
prompt: await convertToLanguageModelPrompt({
|
2524
2453
|
prompt: standardPrompt,
|
2525
|
-
modelSupportsImageUrls: model.supportsImageUrls
|
2454
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
2455
|
+
modelSupportsUrl: model.supportsUrl
|
2526
2456
|
}),
|
2527
2457
|
providerMetadata,
|
2528
2458
|
abortSignal,
|
@@ -2564,7 +2494,8 @@ async function streamObject({
|
|
2564
2494
|
inputFormat: validatedPrompt.type,
|
2565
2495
|
prompt: await convertToLanguageModelPrompt({
|
2566
2496
|
prompt: validatedPrompt,
|
2567
|
-
modelSupportsImageUrls: model.supportsImageUrls
|
2497
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
2498
|
+
modelSupportsUrl: model.supportsUrl
|
2568
2499
|
}),
|
2569
2500
|
providerMetadata,
|
2570
2501
|
abortSignal,
|
@@ -2597,7 +2528,7 @@ async function streamObject({
|
|
2597
2528
|
}
|
2598
2529
|
}
|
2599
2530
|
const {
|
2600
|
-
result: { stream, warnings, rawResponse },
|
2531
|
+
result: { stream, warnings, rawResponse, request },
|
2601
2532
|
doStreamSpan,
|
2602
2533
|
startTimestampMs
|
2603
2534
|
} = await retry(
|
@@ -2643,6 +2574,7 @@ async function streamObject({
|
|
2643
2574
|
stream: stream.pipeThrough(new TransformStream(transformer)),
|
2644
2575
|
warnings,
|
2645
2576
|
rawResponse,
|
2577
|
+
request: request != null ? request : {},
|
2646
2578
|
onFinish,
|
2647
2579
|
rootSpan,
|
2648
2580
|
doStreamSpan,
|
@@ -2661,6 +2593,7 @@ var DefaultStreamObjectResult = class {
|
|
2661
2593
|
stream,
|
2662
2594
|
warnings,
|
2663
2595
|
rawResponse,
|
2596
|
+
request,
|
2664
2597
|
outputStrategy,
|
2665
2598
|
onFinish,
|
2666
2599
|
rootSpan,
|
@@ -2675,6 +2608,7 @@ var DefaultStreamObjectResult = class {
|
|
2675
2608
|
this.warnings = warnings;
|
2676
2609
|
this.rawResponse = rawResponse;
|
2677
2610
|
this.outputStrategy = outputStrategy;
|
2611
|
+
this.request = Promise.resolve(request);
|
2678
2612
|
this.objectPromise = new DelayedPromise();
|
2679
2613
|
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
2680
2614
|
this.usage = usagePromise;
|
@@ -2932,7 +2866,7 @@ var DefaultStreamObjectResult = class {
|
|
2932
2866
|
var experimental_streamObject = streamObject;
|
2933
2867
|
|
2934
2868
|
// core/generate-text/generate-text.ts
|
2935
|
-
var
|
2869
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
2936
2870
|
|
2937
2871
|
// errors/index.ts
|
2938
2872
|
var import_provider13 = require("@ai-sdk/provider");
|
@@ -3068,12 +3002,30 @@ function prepareToolsAndToolChoice({
|
|
3068
3002
|
([name11]) => activeTools.includes(name11)
|
3069
3003
|
) : Object.entries(tools);
|
3070
3004
|
return {
|
3071
|
-
tools: filteredTools.map(([name11, tool2]) =>
|
3072
|
-
type
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
|
3005
|
+
tools: filteredTools.map(([name11, tool2]) => {
|
3006
|
+
const toolType = tool2.type;
|
3007
|
+
switch (toolType) {
|
3008
|
+
case void 0:
|
3009
|
+
case "function":
|
3010
|
+
return {
|
3011
|
+
type: "function",
|
3012
|
+
name: name11,
|
3013
|
+
description: tool2.description,
|
3014
|
+
parameters: (0, import_ui_utils3.asSchema)(tool2.parameters).jsonSchema
|
3015
|
+
};
|
3016
|
+
case "provider-defined":
|
3017
|
+
return {
|
3018
|
+
type: "provider-defined",
|
3019
|
+
name: name11,
|
3020
|
+
id: tool2.id,
|
3021
|
+
args: tool2.args
|
3022
|
+
};
|
3023
|
+
default: {
|
3024
|
+
const exhaustiveCheck = toolType;
|
3025
|
+
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
3026
|
+
}
|
3027
|
+
}
|
3028
|
+
}),
|
3077
3029
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
3078
3030
|
};
|
3079
3031
|
}
|
@@ -3092,7 +3044,7 @@ function removeTextAfterLastWhitespace(text) {
|
|
3092
3044
|
}
|
3093
3045
|
|
3094
3046
|
// core/generate-text/parse-tool-call.ts
|
3095
|
-
var
|
3047
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
3096
3048
|
var import_ui_utils4 = require("@ai-sdk/ui-utils");
|
3097
3049
|
function parseToolCall({
|
3098
3050
|
toolCall,
|
@@ -3110,7 +3062,7 @@ function parseToolCall({
|
|
3110
3062
|
});
|
3111
3063
|
}
|
3112
3064
|
const schema = (0, import_ui_utils4.asSchema)(tool2.parameters);
|
3113
|
-
const parseResult = toolCall.args.trim() === "" ? (0,
|
3065
|
+
const parseResult = toolCall.args.trim() === "" ? (0, import_provider_utils7.safeValidateTypes)({ value: {}, schema }) : (0, import_provider_utils7.safeParseJSON)({ text: toolCall.args, schema });
|
3114
3066
|
if (parseResult.success === false) {
|
3115
3067
|
throw new InvalidToolArgumentsError({
|
3116
3068
|
toolName,
|
@@ -3129,6 +3081,7 @@ function parseToolCall({
|
|
3129
3081
|
// core/generate-text/to-response-messages.ts
|
3130
3082
|
function toResponseMessages({
|
3131
3083
|
text = "",
|
3084
|
+
tools,
|
3132
3085
|
toolCalls,
|
3133
3086
|
toolResults
|
3134
3087
|
}) {
|
@@ -3140,19 +3093,30 @@ function toResponseMessages({
|
|
3140
3093
|
if (toolResults.length > 0) {
|
3141
3094
|
responseMessages.push({
|
3142
3095
|
role: "tool",
|
3143
|
-
content: toolResults.map((
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
|
3148
|
-
|
3096
|
+
content: toolResults.map((toolResult) => {
|
3097
|
+
const tool2 = tools[toolResult.toolName];
|
3098
|
+
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
3099
|
+
type: "tool-result",
|
3100
|
+
toolCallId: toolResult.toolCallId,
|
3101
|
+
toolName: toolResult.toolName,
|
3102
|
+
result: tool2.experimental_toToolResultContent(toolResult.result),
|
3103
|
+
experimental_content: tool2.experimental_toToolResultContent(
|
3104
|
+
toolResult.result
|
3105
|
+
)
|
3106
|
+
} : {
|
3107
|
+
type: "tool-result",
|
3108
|
+
toolCallId: toolResult.toolCallId,
|
3109
|
+
toolName: toolResult.toolName,
|
3110
|
+
result: toolResult.result
|
3111
|
+
};
|
3112
|
+
})
|
3149
3113
|
});
|
3150
3114
|
}
|
3151
3115
|
return responseMessages;
|
3152
3116
|
}
|
3153
3117
|
|
3154
3118
|
// core/generate-text/generate-text.ts
|
3155
|
-
var originalGenerateId3 = (0,
|
3119
|
+
var originalGenerateId3 = (0, import_provider_utils8.createIdGenerator)({ prefix: "aitxt", size: 24 });
|
3156
3120
|
async function generateText({
|
3157
3121
|
model,
|
3158
3122
|
tools,
|
@@ -3191,6 +3155,7 @@ async function generateText({
|
|
3191
3155
|
headers,
|
3192
3156
|
settings: { ...settings, maxRetries }
|
3193
3157
|
});
|
3158
|
+
const initialPrompt = standardizePrompt({ system, prompt, messages });
|
3194
3159
|
const tracer = getTracer(telemetry);
|
3195
3160
|
return recordSpan({
|
3196
3161
|
name: "ai.generateText",
|
@@ -3211,9 +3176,8 @@ async function generateText({
|
|
3211
3176
|
}),
|
3212
3177
|
tracer,
|
3213
3178
|
fn: async (span) => {
|
3214
|
-
var _a11, _b, _c, _d, _e;
|
3179
|
+
var _a11, _b, _c, _d, _e, _f, _g;
|
3215
3180
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
3216
|
-
const currentPrompt = standardizePrompt({ system, prompt, messages });
|
3217
3181
|
const mode = {
|
3218
3182
|
type: "regular",
|
3219
3183
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
@@ -3234,11 +3198,17 @@ async function generateText({
|
|
3234
3198
|
let stepType = "initial";
|
3235
3199
|
do {
|
3236
3200
|
if (stepCount === 1) {
|
3237
|
-
|
3201
|
+
initialPrompt.type = "messages";
|
3238
3202
|
}
|
3203
|
+
const promptFormat = stepCount === 0 ? initialPrompt.type : "messages";
|
3239
3204
|
const promptMessages = await convertToLanguageModelPrompt({
|
3240
|
-
prompt:
|
3241
|
-
|
3205
|
+
prompt: {
|
3206
|
+
type: promptFormat,
|
3207
|
+
system: initialPrompt.system,
|
3208
|
+
messages: [...initialPrompt.messages, ...responseMessages]
|
3209
|
+
},
|
3210
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
3211
|
+
modelSupportsUrl: model.supportsUrl
|
3242
3212
|
});
|
3243
3213
|
currentModelResponse = await retry(
|
3244
3214
|
() => recordSpan({
|
@@ -3251,7 +3221,7 @@ async function generateText({
|
|
3251
3221
|
telemetry
|
3252
3222
|
}),
|
3253
3223
|
...baseTelemetryAttributes,
|
3254
|
-
"ai.prompt.format": { input: () =>
|
3224
|
+
"ai.prompt.format": { input: () => promptFormat },
|
3255
3225
|
"ai.prompt.messages": {
|
3256
3226
|
input: () => JSON.stringify(promptMessages)
|
3257
3227
|
},
|
@@ -3269,11 +3239,11 @@ async function generateText({
|
|
3269
3239
|
}),
|
3270
3240
|
tracer,
|
3271
3241
|
fn: async (span2) => {
|
3272
|
-
var _a12, _b2, _c2, _d2, _e2,
|
3242
|
+
var _a12, _b2, _c2, _d2, _e2, _f2;
|
3273
3243
|
const result = await model.doGenerate({
|
3274
3244
|
mode,
|
3275
3245
|
...callSettings,
|
3276
|
-
inputFormat:
|
3246
|
+
inputFormat: promptFormat,
|
3277
3247
|
prompt: promptMessages,
|
3278
3248
|
providerMetadata,
|
3279
3249
|
abortSignal,
|
@@ -3282,7 +3252,7 @@ async function generateText({
|
|
3282
3252
|
const responseData = {
|
3283
3253
|
id: (_b2 = (_a12 = result.response) == null ? void 0 : _a12.id) != null ? _b2 : generateId3(),
|
3284
3254
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3285
|
-
modelId: (
|
3255
|
+
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : model.modelId
|
3286
3256
|
};
|
3287
3257
|
span2.setAttributes(
|
3288
3258
|
selectTelemetryAttributes({
|
@@ -3352,7 +3322,27 @@ async function generateText({
|
|
3352
3322
|
}
|
3353
3323
|
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace((_b = currentModelResponse.text) != null ? _b : "") : (_c = currentModelResponse.text) != null ? _c : "";
|
3354
3324
|
text = nextStepType === "continue" || stepType === "continue" ? text + stepText : stepText;
|
3355
|
-
|
3325
|
+
if (stepType === "continue") {
|
3326
|
+
const lastMessage = responseMessages[responseMessages.length - 1];
|
3327
|
+
if (typeof lastMessage.content === "string") {
|
3328
|
+
lastMessage.content = text;
|
3329
|
+
} else {
|
3330
|
+
lastMessage.content.push({
|
3331
|
+
text: stepText,
|
3332
|
+
type: "text"
|
3333
|
+
});
|
3334
|
+
}
|
3335
|
+
} else {
|
3336
|
+
responseMessages.push(
|
3337
|
+
...toResponseMessages({
|
3338
|
+
text,
|
3339
|
+
tools: tools != null ? tools : {},
|
3340
|
+
toolCalls: currentToolCalls,
|
3341
|
+
toolResults: currentToolResults
|
3342
|
+
})
|
3343
|
+
);
|
3344
|
+
}
|
3345
|
+
const currentStepResult = {
|
3356
3346
|
stepType,
|
3357
3347
|
text: stepText,
|
3358
3348
|
toolCalls: currentToolCalls,
|
@@ -3361,36 +3351,18 @@ async function generateText({
|
|
3361
3351
|
usage: currentUsage,
|
3362
3352
|
warnings: currentModelResponse.warnings,
|
3363
3353
|
logprobs: currentModelResponse.logprobs,
|
3354
|
+
request: (_d = currentModelResponse.request) != null ? _d : {},
|
3364
3355
|
response: {
|
3365
3356
|
...currentModelResponse.response,
|
3366
|
-
headers: (
|
3357
|
+
headers: (_e = currentModelResponse.rawResponse) == null ? void 0 : _e.headers,
|
3358
|
+
// deep clone msgs to avoid mutating past messages in multi-step:
|
3359
|
+
messages: JSON.parse(JSON.stringify(responseMessages))
|
3367
3360
|
},
|
3368
3361
|
experimental_providerMetadata: currentModelResponse.providerMetadata,
|
3369
3362
|
isContinued: nextStepType === "continue"
|
3370
3363
|
};
|
3371
|
-
steps.push(
|
3372
|
-
await (onStepFinish == null ? void 0 : onStepFinish(
|
3373
|
-
if (stepType === "continue") {
|
3374
|
-
const lastMessage = currentPrompt.messages[currentPrompt.messages.length - 1];
|
3375
|
-
if (typeof lastMessage.content === "string") {
|
3376
|
-
lastMessage.content = text;
|
3377
|
-
} else {
|
3378
|
-
lastMessage.content.push({
|
3379
|
-
text: stepText,
|
3380
|
-
type: "text"
|
3381
|
-
});
|
3382
|
-
}
|
3383
|
-
responseMessages[responseMessages.length - 1] = lastMessage;
|
3384
|
-
currentPrompt.messages[currentPrompt.messages.length - 1] = lastMessage;
|
3385
|
-
} else {
|
3386
|
-
const newResponseMessages = toResponseMessages({
|
3387
|
-
text,
|
3388
|
-
toolCalls: currentToolCalls,
|
3389
|
-
toolResults: currentToolResults
|
3390
|
-
});
|
3391
|
-
responseMessages.push(...newResponseMessages);
|
3392
|
-
currentPrompt.messages.push(...newResponseMessages);
|
3393
|
-
}
|
3364
|
+
steps.push(currentStepResult);
|
3365
|
+
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
3394
3366
|
stepType = nextStepType;
|
3395
3367
|
} while (stepType !== "done");
|
3396
3368
|
span.setAttributes(
|
@@ -3424,9 +3396,11 @@ async function generateText({
|
|
3424
3396
|
finishReason: currentModelResponse.finishReason,
|
3425
3397
|
usage,
|
3426
3398
|
warnings: currentModelResponse.warnings,
|
3399
|
+
request: (_f = currentModelResponse.request) != null ? _f : {},
|
3427
3400
|
response: {
|
3428
3401
|
...currentModelResponse.response,
|
3429
|
-
headers: (
|
3402
|
+
headers: (_g = currentModelResponse.rawResponse) == null ? void 0 : _g.headers,
|
3403
|
+
messages: responseMessages
|
3430
3404
|
},
|
3431
3405
|
logprobs: currentModelResponse.logprobs,
|
3432
3406
|
responseMessages,
|
@@ -3504,6 +3478,7 @@ var DefaultGenerateTextResult = class {
|
|
3504
3478
|
this.finishReason = options.finishReason;
|
3505
3479
|
this.usage = options.usage;
|
3506
3480
|
this.warnings = options.warnings;
|
3481
|
+
this.request = options.request;
|
3507
3482
|
this.response = options.response;
|
3508
3483
|
this.responseMessages = options.responseMessages;
|
3509
3484
|
this.roundtrips = options.steps;
|
@@ -3518,7 +3493,7 @@ var DefaultGenerateTextResult = class {
|
|
3518
3493
|
var experimental_generateText = generateText;
|
3519
3494
|
|
3520
3495
|
// core/generate-text/stream-text.ts
|
3521
|
-
var
|
3496
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
3522
3497
|
|
3523
3498
|
// core/util/create-stitchable-stream.ts
|
3524
3499
|
function createStitchableStream() {
|
@@ -3861,7 +3836,7 @@ function runToolsTransformation({
|
|
3861
3836
|
}
|
3862
3837
|
|
3863
3838
|
// core/generate-text/stream-text.ts
|
3864
|
-
var originalGenerateId4 = (0,
|
3839
|
+
var originalGenerateId4 = (0, import_provider_utils9.createIdGenerator)({ prefix: "aitxt", size: 24 });
|
3865
3840
|
async function streamText({
|
3866
3841
|
model,
|
3867
3842
|
tools,
|
@@ -3903,6 +3878,7 @@ async function streamText({
|
|
3903
3878
|
settings: { ...settings, maxRetries }
|
3904
3879
|
});
|
3905
3880
|
const tracer = getTracer(telemetry);
|
3881
|
+
const initialPrompt = standardizePrompt({ system, prompt, messages });
|
3906
3882
|
return recordSpan({
|
3907
3883
|
name: "ai.streamText",
|
3908
3884
|
attributes: selectTelemetryAttributes({
|
@@ -3922,14 +3898,20 @@ async function streamText({
|
|
3922
3898
|
fn: async (rootSpan) => {
|
3923
3899
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
3924
3900
|
const startStep = async ({
|
3925
|
-
|
3901
|
+
responseMessages
|
3926
3902
|
}) => {
|
3903
|
+
const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
|
3927
3904
|
const promptMessages = await convertToLanguageModelPrompt({
|
3928
|
-
prompt:
|
3929
|
-
|
3905
|
+
prompt: {
|
3906
|
+
type: promptFormat,
|
3907
|
+
system: initialPrompt.system,
|
3908
|
+
messages: [...initialPrompt.messages, ...responseMessages]
|
3909
|
+
},
|
3910
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
3911
|
+
modelSupportsUrl: model.supportsUrl
|
3930
3912
|
});
|
3931
3913
|
const {
|
3932
|
-
result: { stream: stream2, warnings: warnings2, rawResponse: rawResponse2 },
|
3914
|
+
result: { stream: stream2, warnings: warnings2, rawResponse: rawResponse2, request: request2 },
|
3933
3915
|
doStreamSpan: doStreamSpan2,
|
3934
3916
|
startTimestampMs: startTimestampMs2
|
3935
3917
|
} = await retry(
|
@@ -3944,7 +3926,7 @@ async function streamText({
|
|
3944
3926
|
}),
|
3945
3927
|
...baseTelemetryAttributes,
|
3946
3928
|
"ai.prompt.format": {
|
3947
|
-
input: () =>
|
3929
|
+
input: () => promptFormat
|
3948
3930
|
},
|
3949
3931
|
"ai.prompt.messages": {
|
3950
3932
|
input: () => JSON.stringify(promptMessages)
|
@@ -3977,7 +3959,7 @@ async function streamText({
|
|
3977
3959
|
})
|
3978
3960
|
},
|
3979
3961
|
...prepareCallSettings(settings),
|
3980
|
-
inputFormat:
|
3962
|
+
inputFormat: promptFormat,
|
3981
3963
|
prompt: promptMessages,
|
3982
3964
|
providerMetadata,
|
3983
3965
|
abortSignal,
|
@@ -3997,22 +3979,23 @@ async function streamText({
|
|
3997
3979
|
abortSignal
|
3998
3980
|
}),
|
3999
3981
|
warnings: warnings2,
|
3982
|
+
request: request2 != null ? request2 : {},
|
4000
3983
|
rawResponse: rawResponse2
|
4001
3984
|
},
|
4002
3985
|
doStreamSpan: doStreamSpan2,
|
4003
3986
|
startTimestampMs: startTimestampMs2
|
4004
3987
|
};
|
4005
3988
|
};
|
4006
|
-
const currentPrompt = standardizePrompt({ system, prompt, messages });
|
4007
3989
|
const {
|
4008
|
-
result: { stream, warnings, rawResponse },
|
3990
|
+
result: { stream, warnings, rawResponse, request },
|
4009
3991
|
doStreamSpan,
|
4010
3992
|
startTimestampMs
|
4011
|
-
} = await startStep({
|
3993
|
+
} = await startStep({ responseMessages: [] });
|
4012
3994
|
return new DefaultStreamTextResult({
|
4013
3995
|
stream,
|
4014
3996
|
warnings,
|
4015
3997
|
rawResponse,
|
3998
|
+
request,
|
4016
3999
|
onChunk,
|
4017
4000
|
onFinish,
|
4018
4001
|
onStepFinish,
|
@@ -4023,11 +4006,11 @@ async function streamText({
|
|
4023
4006
|
maxSteps,
|
4024
4007
|
continueSteps,
|
4025
4008
|
startStep,
|
4026
|
-
currentPrompt,
|
4027
4009
|
modelId: model.modelId,
|
4028
4010
|
now: now2,
|
4029
4011
|
currentDate,
|
4030
|
-
generateId: generateId3
|
4012
|
+
generateId: generateId3,
|
4013
|
+
tools
|
4031
4014
|
});
|
4032
4015
|
}
|
4033
4016
|
});
|
@@ -4037,6 +4020,7 @@ var DefaultStreamTextResult = class {
|
|
4037
4020
|
stream,
|
4038
4021
|
warnings,
|
4039
4022
|
rawResponse,
|
4023
|
+
request,
|
4040
4024
|
onChunk,
|
4041
4025
|
onFinish,
|
4042
4026
|
onStepFinish,
|
@@ -4047,11 +4031,11 @@ var DefaultStreamTextResult = class {
|
|
4047
4031
|
maxSteps,
|
4048
4032
|
continueSteps,
|
4049
4033
|
startStep,
|
4050
|
-
currentPrompt,
|
4051
4034
|
modelId,
|
4052
4035
|
now: now2,
|
4053
4036
|
currentDate,
|
4054
|
-
generateId: generateId3
|
4037
|
+
generateId: generateId3,
|
4038
|
+
tools
|
4055
4039
|
}) {
|
4056
4040
|
this.warnings = warnings;
|
4057
4041
|
this.rawResponse = rawResponse;
|
@@ -4072,6 +4056,8 @@ var DefaultStreamTextResult = class {
|
|
4072
4056
|
promise: providerMetadataPromise
|
4073
4057
|
} = createResolvablePromise();
|
4074
4058
|
this.experimental_providerMetadata = providerMetadataPromise;
|
4059
|
+
const { resolve: resolveRequest, promise: requestPromise } = createResolvablePromise();
|
4060
|
+
this.request = requestPromise;
|
4075
4061
|
const { resolve: resolveResponse, promise: responsePromise } = createResolvablePromise();
|
4076
4062
|
this.response = responsePromise;
|
4077
4063
|
const {
|
@@ -4092,14 +4078,15 @@ var DefaultStreamTextResult = class {
|
|
4092
4078
|
startTimestamp,
|
4093
4079
|
doStreamSpan: doStreamSpan2,
|
4094
4080
|
currentStep,
|
4095
|
-
|
4081
|
+
responseMessages,
|
4096
4082
|
usage = {
|
4097
4083
|
promptTokens: 0,
|
4098
4084
|
completionTokens: 0,
|
4099
4085
|
totalTokens: 0
|
4100
4086
|
},
|
4101
4087
|
stepType,
|
4102
|
-
previousStepText = ""
|
4088
|
+
previousStepText = "",
|
4089
|
+
stepRequest
|
4103
4090
|
}) {
|
4104
4091
|
const stepToolCalls = [];
|
4105
4092
|
const stepToolResults = [];
|
@@ -4226,6 +4213,7 @@ var DefaultStreamTextResult = class {
|
|
4226
4213
|
},
|
4227
4214
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
4228
4215
|
async flush(controller) {
|
4216
|
+
var _a11;
|
4229
4217
|
const stepToolCallsJson = stepToolCalls.length > 0 ? JSON.stringify(stepToolCalls) : void 0;
|
4230
4218
|
let nextStepType = "done";
|
4231
4219
|
if (currentStep + 1 < maxSteps) {
|
@@ -4291,10 +4279,32 @@ var DefaultStreamTextResult = class {
|
|
4291
4279
|
usage: stepUsage,
|
4292
4280
|
experimental_providerMetadata: stepProviderMetadata,
|
4293
4281
|
logprobs: stepLogProbs,
|
4294
|
-
response:
|
4282
|
+
response: {
|
4283
|
+
...stepResponse
|
4284
|
+
},
|
4295
4285
|
isContinued: nextStepType === "continue"
|
4296
4286
|
});
|
4297
|
-
|
4287
|
+
if (stepType === "continue") {
|
4288
|
+
const lastMessage = responseMessages[responseMessages.length - 1];
|
4289
|
+
if (typeof lastMessage.content === "string") {
|
4290
|
+
lastMessage.content = stepText;
|
4291
|
+
} else {
|
4292
|
+
lastMessage.content.push({
|
4293
|
+
text: stepText,
|
4294
|
+
type: "text"
|
4295
|
+
});
|
4296
|
+
}
|
4297
|
+
} else {
|
4298
|
+
responseMessages.push(
|
4299
|
+
...toResponseMessages({
|
4300
|
+
text: stepText,
|
4301
|
+
tools: tools != null ? tools : {},
|
4302
|
+
toolCalls: stepToolCalls,
|
4303
|
+
toolResults: stepToolResults
|
4304
|
+
})
|
4305
|
+
);
|
4306
|
+
}
|
4307
|
+
const currentStepResult = {
|
4298
4308
|
stepType,
|
4299
4309
|
text: stepText,
|
4300
4310
|
toolCalls: stepToolCalls,
|
@@ -4303,49 +4313,30 @@ var DefaultStreamTextResult = class {
|
|
4303
4313
|
usage: stepUsage,
|
4304
4314
|
warnings: self.warnings,
|
4305
4315
|
logprobs: stepLogProbs,
|
4306
|
-
|
4316
|
+
request: stepRequest,
|
4307
4317
|
rawResponse: self.rawResponse,
|
4318
|
+
response: {
|
4319
|
+
...stepResponse,
|
4320
|
+
headers: (_a11 = self.rawResponse) == null ? void 0 : _a11.headers,
|
4321
|
+
// deep clone msgs to avoid mutating past messages in multi-step:
|
4322
|
+
messages: JSON.parse(JSON.stringify(responseMessages))
|
4323
|
+
},
|
4308
4324
|
experimental_providerMetadata: stepProviderMetadata,
|
4309
4325
|
isContinued: nextStepType === "continue"
|
4310
4326
|
};
|
4311
|
-
stepResults.push(
|
4312
|
-
await (onStepFinish == null ? void 0 : onStepFinish(
|
4327
|
+
stepResults.push(currentStepResult);
|
4328
|
+
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
4313
4329
|
const combinedUsage = {
|
4314
4330
|
promptTokens: usage.promptTokens + stepUsage.promptTokens,
|
4315
4331
|
completionTokens: usage.completionTokens + stepUsage.completionTokens,
|
4316
4332
|
totalTokens: usage.totalTokens + stepUsage.totalTokens
|
4317
4333
|
};
|
4318
4334
|
if (nextStepType !== "done") {
|
4319
|
-
if (stepType === "continue") {
|
4320
|
-
const lastMessage = currentPrompt2.messages[currentPrompt2.messages.length - 1];
|
4321
|
-
if (typeof lastMessage.content === "string") {
|
4322
|
-
lastMessage.content = stepText;
|
4323
|
-
} else {
|
4324
|
-
lastMessage.content.push({
|
4325
|
-
text: stepText,
|
4326
|
-
type: "text"
|
4327
|
-
});
|
4328
|
-
}
|
4329
|
-
currentPrompt2.messages[currentPrompt2.messages.length - 1] = lastMessage;
|
4330
|
-
} else {
|
4331
|
-
const newResponseMessages = toResponseMessages({
|
4332
|
-
text: stepText,
|
4333
|
-
toolCalls: stepToolCalls,
|
4334
|
-
toolResults: stepToolResults
|
4335
|
-
});
|
4336
|
-
currentPrompt2.messages.push(...newResponseMessages);
|
4337
|
-
}
|
4338
4335
|
const {
|
4339
4336
|
result,
|
4340
4337
|
doStreamSpan: doStreamSpan3,
|
4341
4338
|
startTimestampMs: startTimestamp2
|
4342
|
-
} = await startStep({
|
4343
|
-
currentPrompt: {
|
4344
|
-
type: "messages",
|
4345
|
-
system: currentPrompt2.system,
|
4346
|
-
messages: currentPrompt2.messages
|
4347
|
-
}
|
4348
|
-
});
|
4339
|
+
} = await startStep({ responseMessages });
|
4349
4340
|
self.warnings = result.warnings;
|
4350
4341
|
self.rawResponse = result.rawResponse;
|
4351
4342
|
addStepStream({
|
@@ -4353,10 +4344,11 @@ var DefaultStreamTextResult = class {
|
|
4353
4344
|
startTimestamp: startTimestamp2,
|
4354
4345
|
doStreamSpan: doStreamSpan3,
|
4355
4346
|
currentStep: currentStep + 1,
|
4356
|
-
|
4347
|
+
responseMessages,
|
4357
4348
|
usage: combinedUsage,
|
4358
4349
|
stepType: nextStepType,
|
4359
|
-
previousStepText: fullStepText
|
4350
|
+
previousStepText: fullStepText,
|
4351
|
+
stepRequest: result.request
|
4360
4352
|
});
|
4361
4353
|
return;
|
4362
4354
|
}
|
@@ -4367,7 +4359,9 @@ var DefaultStreamTextResult = class {
|
|
4367
4359
|
usage: combinedUsage,
|
4368
4360
|
experimental_providerMetadata: stepProviderMetadata,
|
4369
4361
|
logprobs: stepLogProbs,
|
4370
|
-
response:
|
4362
|
+
response: {
|
4363
|
+
...stepResponse
|
4364
|
+
}
|
4371
4365
|
});
|
4372
4366
|
closeStitchableStream();
|
4373
4367
|
rootSpan.setAttributes(
|
@@ -4390,34 +4384,13 @@ var DefaultStreamTextResult = class {
|
|
4390
4384
|
}
|
4391
4385
|
})
|
4392
4386
|
);
|
4393
|
-
const responseMessages = stepResults.reduce((responseMessages2, step) => {
|
4394
|
-
if (step.stepType === "continue") {
|
4395
|
-
const lastResponseMessage = responseMessages2.pop();
|
4396
|
-
if (typeof lastResponseMessage.content === "string") {
|
4397
|
-
lastResponseMessage.content += step.text;
|
4398
|
-
} else {
|
4399
|
-
lastResponseMessage.content.push({
|
4400
|
-
text: step.text,
|
4401
|
-
type: "text"
|
4402
|
-
});
|
4403
|
-
}
|
4404
|
-
return [...responseMessages2, lastResponseMessage];
|
4405
|
-
}
|
4406
|
-
return [
|
4407
|
-
...responseMessages2,
|
4408
|
-
...toResponseMessages({
|
4409
|
-
text: step.text,
|
4410
|
-
toolCalls: step.toolCalls,
|
4411
|
-
toolResults: step.toolResults
|
4412
|
-
})
|
4413
|
-
];
|
4414
|
-
}, []);
|
4415
4387
|
resolveUsage(combinedUsage);
|
4416
4388
|
resolveFinishReason(stepFinishReason);
|
4417
4389
|
resolveText(fullStepText);
|
4418
4390
|
resolveToolCalls(stepToolCalls);
|
4419
4391
|
resolveProviderMetadata(stepProviderMetadata);
|
4420
4392
|
resolveToolResults(stepToolResults);
|
4393
|
+
resolveRequest(stepRequest);
|
4421
4394
|
resolveResponse({
|
4422
4395
|
...stepResponse,
|
4423
4396
|
headers: rawResponse == null ? void 0 : rawResponse.headers
|
@@ -4435,10 +4408,12 @@ var DefaultStreamTextResult = class {
|
|
4435
4408
|
// optional as well. Therefore we need to cast the toolResults to any.
|
4436
4409
|
// The type exposed to the users will be correctly inferred.
|
4437
4410
|
toolResults: stepToolResults,
|
4411
|
+
request: stepRequest,
|
4438
4412
|
rawResponse,
|
4439
4413
|
response: {
|
4440
4414
|
...stepResponse,
|
4441
|
-
headers: rawResponse == null ? void 0 : rawResponse.headers
|
4415
|
+
headers: rawResponse == null ? void 0 : rawResponse.headers,
|
4416
|
+
messages: responseMessages
|
4442
4417
|
},
|
4443
4418
|
warnings,
|
4444
4419
|
experimental_providerMetadata: stepProviderMetadata,
|
@@ -4460,9 +4435,10 @@ var DefaultStreamTextResult = class {
|
|
4460
4435
|
startTimestamp: startTimestampMs,
|
4461
4436
|
doStreamSpan,
|
4462
4437
|
currentStep: 0,
|
4463
|
-
|
4438
|
+
responseMessages: [],
|
4464
4439
|
usage: void 0,
|
4465
|
-
stepType: "initial"
|
4440
|
+
stepType: "initial",
|
4441
|
+
stepRequest: request
|
4466
4442
|
});
|
4467
4443
|
}
|
4468
4444
|
/**
|
@@ -4501,7 +4477,7 @@ var DefaultStreamTextResult = class {
|
|
4501
4477
|
}
|
4502
4478
|
toDataStreamInternal({
|
4503
4479
|
callbacks = {},
|
4504
|
-
getErrorMessage:
|
4480
|
+
getErrorMessage: getErrorMessage3 = () => "",
|
4505
4481
|
// mask error messages for safety by default
|
4506
4482
|
sendUsage = true
|
4507
4483
|
} = {}) {
|
@@ -4576,7 +4552,7 @@ var DefaultStreamTextResult = class {
|
|
4576
4552
|
}
|
4577
4553
|
case "error": {
|
4578
4554
|
controller.enqueue(
|
4579
|
-
(0, import_ui_utils10.formatStreamPart)("error",
|
4555
|
+
(0, import_ui_utils10.formatStreamPart)("error", getErrorMessage3(chunk.error))
|
4580
4556
|
);
|
4581
4557
|
break;
|
4582
4558
|
}
|
@@ -4624,7 +4600,7 @@ var DefaultStreamTextResult = class {
|
|
4624
4600
|
statusText: "statusText" in options ? options.statusText : void 0
|
4625
4601
|
};
|
4626
4602
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
4627
|
-
const
|
4603
|
+
const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
|
4628
4604
|
const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
|
4629
4605
|
writeToServerResponse({
|
4630
4606
|
response,
|
@@ -4634,7 +4610,7 @@ var DefaultStreamTextResult = class {
|
|
4634
4610
|
contentType: "text/plain; charset=utf-8",
|
4635
4611
|
dataStreamVersion: "v1"
|
4636
4612
|
}),
|
4637
|
-
stream: this.toDataStream({ data, getErrorMessage:
|
4613
|
+
stream: this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage })
|
4638
4614
|
});
|
4639
4615
|
}
|
4640
4616
|
pipeTextStreamToResponse(response, init) {
|
@@ -4666,10 +4642,10 @@ var DefaultStreamTextResult = class {
|
|
4666
4642
|
statusText: "statusText" in options ? options.statusText : void 0
|
4667
4643
|
};
|
4668
4644
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
4669
|
-
const
|
4645
|
+
const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
|
4670
4646
|
const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
|
4671
4647
|
return new Response(
|
4672
|
-
this.toDataStream({ data, getErrorMessage:
|
4648
|
+
this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage }),
|
4673
4649
|
{
|
4674
4650
|
status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
|
4675
4651
|
statusText: init == null ? void 0 : init.statusText,
|
@@ -4711,6 +4687,7 @@ var experimental_wrapLanguageModel = ({
|
|
4711
4687
|
modelId: modelId != null ? modelId : model.modelId,
|
4712
4688
|
defaultObjectGenerationMode: model.defaultObjectGenerationMode,
|
4713
4689
|
supportsImageUrls: model.supportsImageUrls,
|
4690
|
+
supportsUrl: model.supportsUrl,
|
4714
4691
|
supportsStructuredOutputs: model.supportsStructuredOutputs,
|
4715
4692
|
async doGenerate(params) {
|
4716
4693
|
const transformedParams = await doTransform({ params, type: "generate" });
|
@@ -4834,7 +4811,7 @@ function convertToCoreMessages(messages) {
|
|
4834
4811
|
role: "assistant",
|
4835
4812
|
content: [
|
4836
4813
|
{ type: "text", text: content },
|
4837
|
-
...toolInvocations.
|
4814
|
+
...toolInvocations.map(({ toolCallId, toolName, args }) => ({
|
4838
4815
|
type: "tool-call",
|
4839
4816
|
toolCallId,
|
4840
4817
|
toolName,
|
@@ -4842,19 +4819,25 @@ function convertToCoreMessages(messages) {
|
|
4842
4819
|
}))
|
4843
4820
|
]
|
4844
4821
|
});
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4822
|
+
coreMessages.push({
|
4823
|
+
role: "tool",
|
4824
|
+
content: toolInvocations.map((ToolInvocation) => {
|
4825
|
+
if (!("result" in ToolInvocation)) {
|
4826
|
+
throw new MessageConversionError({
|
4827
|
+
originalMessage: message,
|
4828
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(ToolInvocation)
|
4829
|
+
});
|
4830
|
+
}
|
4831
|
+
const { toolCallId, toolName, args, result } = ToolInvocation;
|
4832
|
+
return {
|
4833
|
+
type: "tool-result",
|
4834
|
+
toolCallId,
|
4835
|
+
toolName,
|
4836
|
+
args,
|
4837
|
+
result
|
4838
|
+
};
|
4839
|
+
})
|
4840
|
+
});
|
4858
4841
|
break;
|
4859
4842
|
}
|
4860
4843
|
case "function":
|
@@ -6130,8 +6113,8 @@ var StreamingTextResponse = class extends Response {
|
|
6130
6113
|
};
|
6131
6114
|
|
6132
6115
|
// streams/index.ts
|
6133
|
-
var generateId2 =
|
6134
|
-
var nanoid =
|
6116
|
+
var generateId2 = import_provider_utils10.generateId;
|
6117
|
+
var nanoid = import_provider_utils10.generateId;
|
6135
6118
|
// Annotate the CommonJS export names for ESM import in node:
|
6136
6119
|
0 && (module.exports = {
|
6137
6120
|
AISDKError,
|