ai 3.4.18 → 3.4.20
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 +37 -0
- package/dist/index.d.mts +107 -76
- package/dist/index.d.ts +107 -76
- package/dist/index.js +378 -397
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +364 -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,28 @@ 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
|
+
content: tool2.experimental_toToolResultContent(toolResult.result)
|
3104
|
+
} : {
|
3105
|
+
type: "tool-result",
|
3106
|
+
toolCallId: toolResult.toolCallId,
|
3107
|
+
toolName: toolResult.toolName,
|
3108
|
+
result: toolResult.result
|
3109
|
+
};
|
3110
|
+
})
|
3149
3111
|
});
|
3150
3112
|
}
|
3151
3113
|
return responseMessages;
|
3152
3114
|
}
|
3153
3115
|
|
3154
3116
|
// core/generate-text/generate-text.ts
|
3155
|
-
var originalGenerateId3 = (0,
|
3117
|
+
var originalGenerateId3 = (0, import_provider_utils8.createIdGenerator)({ prefix: "aitxt", size: 24 });
|
3156
3118
|
async function generateText({
|
3157
3119
|
model,
|
3158
3120
|
tools,
|
@@ -3191,6 +3153,7 @@ async function generateText({
|
|
3191
3153
|
headers,
|
3192
3154
|
settings: { ...settings, maxRetries }
|
3193
3155
|
});
|
3156
|
+
const initialPrompt = standardizePrompt({ system, prompt, messages });
|
3194
3157
|
const tracer = getTracer(telemetry);
|
3195
3158
|
return recordSpan({
|
3196
3159
|
name: "ai.generateText",
|
@@ -3211,9 +3174,8 @@ async function generateText({
|
|
3211
3174
|
}),
|
3212
3175
|
tracer,
|
3213
3176
|
fn: async (span) => {
|
3214
|
-
var _a11, _b, _c, _d, _e;
|
3177
|
+
var _a11, _b, _c, _d, _e, _f, _g;
|
3215
3178
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
3216
|
-
const currentPrompt = standardizePrompt({ system, prompt, messages });
|
3217
3179
|
const mode = {
|
3218
3180
|
type: "regular",
|
3219
3181
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
@@ -3234,11 +3196,17 @@ async function generateText({
|
|
3234
3196
|
let stepType = "initial";
|
3235
3197
|
do {
|
3236
3198
|
if (stepCount === 1) {
|
3237
|
-
|
3199
|
+
initialPrompt.type = "messages";
|
3238
3200
|
}
|
3201
|
+
const promptFormat = stepCount === 0 ? initialPrompt.type : "messages";
|
3239
3202
|
const promptMessages = await convertToLanguageModelPrompt({
|
3240
|
-
prompt:
|
3241
|
-
|
3203
|
+
prompt: {
|
3204
|
+
type: promptFormat,
|
3205
|
+
system: initialPrompt.system,
|
3206
|
+
messages: [...initialPrompt.messages, ...responseMessages]
|
3207
|
+
},
|
3208
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
3209
|
+
modelSupportsUrl: model.supportsUrl
|
3242
3210
|
});
|
3243
3211
|
currentModelResponse = await retry(
|
3244
3212
|
() => recordSpan({
|
@@ -3251,7 +3219,7 @@ async function generateText({
|
|
3251
3219
|
telemetry
|
3252
3220
|
}),
|
3253
3221
|
...baseTelemetryAttributes,
|
3254
|
-
"ai.prompt.format": { input: () =>
|
3222
|
+
"ai.prompt.format": { input: () => promptFormat },
|
3255
3223
|
"ai.prompt.messages": {
|
3256
3224
|
input: () => JSON.stringify(promptMessages)
|
3257
3225
|
},
|
@@ -3269,11 +3237,11 @@ async function generateText({
|
|
3269
3237
|
}),
|
3270
3238
|
tracer,
|
3271
3239
|
fn: async (span2) => {
|
3272
|
-
var _a12, _b2, _c2, _d2, _e2,
|
3240
|
+
var _a12, _b2, _c2, _d2, _e2, _f2;
|
3273
3241
|
const result = await model.doGenerate({
|
3274
3242
|
mode,
|
3275
3243
|
...callSettings,
|
3276
|
-
inputFormat:
|
3244
|
+
inputFormat: promptFormat,
|
3277
3245
|
prompt: promptMessages,
|
3278
3246
|
providerMetadata,
|
3279
3247
|
abortSignal,
|
@@ -3282,7 +3250,7 @@ async function generateText({
|
|
3282
3250
|
const responseData = {
|
3283
3251
|
id: (_b2 = (_a12 = result.response) == null ? void 0 : _a12.id) != null ? _b2 : generateId3(),
|
3284
3252
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3285
|
-
modelId: (
|
3253
|
+
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : model.modelId
|
3286
3254
|
};
|
3287
3255
|
span2.setAttributes(
|
3288
3256
|
selectTelemetryAttributes({
|
@@ -3352,7 +3320,27 @@ async function generateText({
|
|
3352
3320
|
}
|
3353
3321
|
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace((_b = currentModelResponse.text) != null ? _b : "") : (_c = currentModelResponse.text) != null ? _c : "";
|
3354
3322
|
text = nextStepType === "continue" || stepType === "continue" ? text + stepText : stepText;
|
3355
|
-
|
3323
|
+
if (stepType === "continue") {
|
3324
|
+
const lastMessage = responseMessages[responseMessages.length - 1];
|
3325
|
+
if (typeof lastMessage.content === "string") {
|
3326
|
+
lastMessage.content = text;
|
3327
|
+
} else {
|
3328
|
+
lastMessage.content.push({
|
3329
|
+
text: stepText,
|
3330
|
+
type: "text"
|
3331
|
+
});
|
3332
|
+
}
|
3333
|
+
} else {
|
3334
|
+
responseMessages.push(
|
3335
|
+
...toResponseMessages({
|
3336
|
+
text,
|
3337
|
+
tools: tools != null ? tools : {},
|
3338
|
+
toolCalls: currentToolCalls,
|
3339
|
+
toolResults: currentToolResults
|
3340
|
+
})
|
3341
|
+
);
|
3342
|
+
}
|
3343
|
+
const currentStepResult = {
|
3356
3344
|
stepType,
|
3357
3345
|
text: stepText,
|
3358
3346
|
toolCalls: currentToolCalls,
|
@@ -3361,36 +3349,18 @@ async function generateText({
|
|
3361
3349
|
usage: currentUsage,
|
3362
3350
|
warnings: currentModelResponse.warnings,
|
3363
3351
|
logprobs: currentModelResponse.logprobs,
|
3352
|
+
request: (_d = currentModelResponse.request) != null ? _d : {},
|
3364
3353
|
response: {
|
3365
3354
|
...currentModelResponse.response,
|
3366
|
-
headers: (
|
3355
|
+
headers: (_e = currentModelResponse.rawResponse) == null ? void 0 : _e.headers,
|
3356
|
+
// deep clone msgs to avoid mutating past messages in multi-step:
|
3357
|
+
messages: JSON.parse(JSON.stringify(responseMessages))
|
3367
3358
|
},
|
3368
3359
|
experimental_providerMetadata: currentModelResponse.providerMetadata,
|
3369
3360
|
isContinued: nextStepType === "continue"
|
3370
3361
|
};
|
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
|
-
}
|
3362
|
+
steps.push(currentStepResult);
|
3363
|
+
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
3394
3364
|
stepType = nextStepType;
|
3395
3365
|
} while (stepType !== "done");
|
3396
3366
|
span.setAttributes(
|
@@ -3424,9 +3394,11 @@ async function generateText({
|
|
3424
3394
|
finishReason: currentModelResponse.finishReason,
|
3425
3395
|
usage,
|
3426
3396
|
warnings: currentModelResponse.warnings,
|
3397
|
+
request: (_f = currentModelResponse.request) != null ? _f : {},
|
3427
3398
|
response: {
|
3428
3399
|
...currentModelResponse.response,
|
3429
|
-
headers: (
|
3400
|
+
headers: (_g = currentModelResponse.rawResponse) == null ? void 0 : _g.headers,
|
3401
|
+
messages: responseMessages
|
3430
3402
|
},
|
3431
3403
|
logprobs: currentModelResponse.logprobs,
|
3432
3404
|
responseMessages,
|
@@ -3504,6 +3476,7 @@ var DefaultGenerateTextResult = class {
|
|
3504
3476
|
this.finishReason = options.finishReason;
|
3505
3477
|
this.usage = options.usage;
|
3506
3478
|
this.warnings = options.warnings;
|
3479
|
+
this.request = options.request;
|
3507
3480
|
this.response = options.response;
|
3508
3481
|
this.responseMessages = options.responseMessages;
|
3509
3482
|
this.roundtrips = options.steps;
|
@@ -3518,7 +3491,7 @@ var DefaultGenerateTextResult = class {
|
|
3518
3491
|
var experimental_generateText = generateText;
|
3519
3492
|
|
3520
3493
|
// core/generate-text/stream-text.ts
|
3521
|
-
var
|
3494
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
3522
3495
|
|
3523
3496
|
// core/util/create-stitchable-stream.ts
|
3524
3497
|
function createStitchableStream() {
|
@@ -3861,7 +3834,7 @@ function runToolsTransformation({
|
|
3861
3834
|
}
|
3862
3835
|
|
3863
3836
|
// core/generate-text/stream-text.ts
|
3864
|
-
var originalGenerateId4 = (0,
|
3837
|
+
var originalGenerateId4 = (0, import_provider_utils9.createIdGenerator)({ prefix: "aitxt", size: 24 });
|
3865
3838
|
async function streamText({
|
3866
3839
|
model,
|
3867
3840
|
tools,
|
@@ -3903,6 +3876,7 @@ async function streamText({
|
|
3903
3876
|
settings: { ...settings, maxRetries }
|
3904
3877
|
});
|
3905
3878
|
const tracer = getTracer(telemetry);
|
3879
|
+
const initialPrompt = standardizePrompt({ system, prompt, messages });
|
3906
3880
|
return recordSpan({
|
3907
3881
|
name: "ai.streamText",
|
3908
3882
|
attributes: selectTelemetryAttributes({
|
@@ -3922,14 +3896,20 @@ async function streamText({
|
|
3922
3896
|
fn: async (rootSpan) => {
|
3923
3897
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
3924
3898
|
const startStep = async ({
|
3925
|
-
|
3899
|
+
responseMessages
|
3926
3900
|
}) => {
|
3901
|
+
const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
|
3927
3902
|
const promptMessages = await convertToLanguageModelPrompt({
|
3928
|
-
prompt:
|
3929
|
-
|
3903
|
+
prompt: {
|
3904
|
+
type: promptFormat,
|
3905
|
+
system: initialPrompt.system,
|
3906
|
+
messages: [...initialPrompt.messages, ...responseMessages]
|
3907
|
+
},
|
3908
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
3909
|
+
modelSupportsUrl: model.supportsUrl
|
3930
3910
|
});
|
3931
3911
|
const {
|
3932
|
-
result: { stream: stream2, warnings: warnings2, rawResponse: rawResponse2 },
|
3912
|
+
result: { stream: stream2, warnings: warnings2, rawResponse: rawResponse2, request: request2 },
|
3933
3913
|
doStreamSpan: doStreamSpan2,
|
3934
3914
|
startTimestampMs: startTimestampMs2
|
3935
3915
|
} = await retry(
|
@@ -3944,7 +3924,7 @@ async function streamText({
|
|
3944
3924
|
}),
|
3945
3925
|
...baseTelemetryAttributes,
|
3946
3926
|
"ai.prompt.format": {
|
3947
|
-
input: () =>
|
3927
|
+
input: () => promptFormat
|
3948
3928
|
},
|
3949
3929
|
"ai.prompt.messages": {
|
3950
3930
|
input: () => JSON.stringify(promptMessages)
|
@@ -3977,7 +3957,7 @@ async function streamText({
|
|
3977
3957
|
})
|
3978
3958
|
},
|
3979
3959
|
...prepareCallSettings(settings),
|
3980
|
-
inputFormat:
|
3960
|
+
inputFormat: promptFormat,
|
3981
3961
|
prompt: promptMessages,
|
3982
3962
|
providerMetadata,
|
3983
3963
|
abortSignal,
|
@@ -3997,22 +3977,23 @@ async function streamText({
|
|
3997
3977
|
abortSignal
|
3998
3978
|
}),
|
3999
3979
|
warnings: warnings2,
|
3980
|
+
request: request2 != null ? request2 : {},
|
4000
3981
|
rawResponse: rawResponse2
|
4001
3982
|
},
|
4002
3983
|
doStreamSpan: doStreamSpan2,
|
4003
3984
|
startTimestampMs: startTimestampMs2
|
4004
3985
|
};
|
4005
3986
|
};
|
4006
|
-
const currentPrompt = standardizePrompt({ system, prompt, messages });
|
4007
3987
|
const {
|
4008
|
-
result: { stream, warnings, rawResponse },
|
3988
|
+
result: { stream, warnings, rawResponse, request },
|
4009
3989
|
doStreamSpan,
|
4010
3990
|
startTimestampMs
|
4011
|
-
} = await startStep({
|
3991
|
+
} = await startStep({ responseMessages: [] });
|
4012
3992
|
return new DefaultStreamTextResult({
|
4013
3993
|
stream,
|
4014
3994
|
warnings,
|
4015
3995
|
rawResponse,
|
3996
|
+
request,
|
4016
3997
|
onChunk,
|
4017
3998
|
onFinish,
|
4018
3999
|
onStepFinish,
|
@@ -4023,11 +4004,11 @@ async function streamText({
|
|
4023
4004
|
maxSteps,
|
4024
4005
|
continueSteps,
|
4025
4006
|
startStep,
|
4026
|
-
currentPrompt,
|
4027
4007
|
modelId: model.modelId,
|
4028
4008
|
now: now2,
|
4029
4009
|
currentDate,
|
4030
|
-
generateId: generateId3
|
4010
|
+
generateId: generateId3,
|
4011
|
+
tools
|
4031
4012
|
});
|
4032
4013
|
}
|
4033
4014
|
});
|
@@ -4037,6 +4018,7 @@ var DefaultStreamTextResult = class {
|
|
4037
4018
|
stream,
|
4038
4019
|
warnings,
|
4039
4020
|
rawResponse,
|
4021
|
+
request,
|
4040
4022
|
onChunk,
|
4041
4023
|
onFinish,
|
4042
4024
|
onStepFinish,
|
@@ -4047,11 +4029,11 @@ var DefaultStreamTextResult = class {
|
|
4047
4029
|
maxSteps,
|
4048
4030
|
continueSteps,
|
4049
4031
|
startStep,
|
4050
|
-
currentPrompt,
|
4051
4032
|
modelId,
|
4052
4033
|
now: now2,
|
4053
4034
|
currentDate,
|
4054
|
-
generateId: generateId3
|
4035
|
+
generateId: generateId3,
|
4036
|
+
tools
|
4055
4037
|
}) {
|
4056
4038
|
this.warnings = warnings;
|
4057
4039
|
this.rawResponse = rawResponse;
|
@@ -4072,6 +4054,8 @@ var DefaultStreamTextResult = class {
|
|
4072
4054
|
promise: providerMetadataPromise
|
4073
4055
|
} = createResolvablePromise();
|
4074
4056
|
this.experimental_providerMetadata = providerMetadataPromise;
|
4057
|
+
const { resolve: resolveRequest, promise: requestPromise } = createResolvablePromise();
|
4058
|
+
this.request = requestPromise;
|
4075
4059
|
const { resolve: resolveResponse, promise: responsePromise } = createResolvablePromise();
|
4076
4060
|
this.response = responsePromise;
|
4077
4061
|
const {
|
@@ -4092,14 +4076,15 @@ var DefaultStreamTextResult = class {
|
|
4092
4076
|
startTimestamp,
|
4093
4077
|
doStreamSpan: doStreamSpan2,
|
4094
4078
|
currentStep,
|
4095
|
-
|
4079
|
+
responseMessages,
|
4096
4080
|
usage = {
|
4097
4081
|
promptTokens: 0,
|
4098
4082
|
completionTokens: 0,
|
4099
4083
|
totalTokens: 0
|
4100
4084
|
},
|
4101
4085
|
stepType,
|
4102
|
-
previousStepText = ""
|
4086
|
+
previousStepText = "",
|
4087
|
+
stepRequest
|
4103
4088
|
}) {
|
4104
4089
|
const stepToolCalls = [];
|
4105
4090
|
const stepToolResults = [];
|
@@ -4226,6 +4211,7 @@ var DefaultStreamTextResult = class {
|
|
4226
4211
|
},
|
4227
4212
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
4228
4213
|
async flush(controller) {
|
4214
|
+
var _a11;
|
4229
4215
|
const stepToolCallsJson = stepToolCalls.length > 0 ? JSON.stringify(stepToolCalls) : void 0;
|
4230
4216
|
let nextStepType = "done";
|
4231
4217
|
if (currentStep + 1 < maxSteps) {
|
@@ -4291,10 +4277,32 @@ var DefaultStreamTextResult = class {
|
|
4291
4277
|
usage: stepUsage,
|
4292
4278
|
experimental_providerMetadata: stepProviderMetadata,
|
4293
4279
|
logprobs: stepLogProbs,
|
4294
|
-
response:
|
4280
|
+
response: {
|
4281
|
+
...stepResponse
|
4282
|
+
},
|
4295
4283
|
isContinued: nextStepType === "continue"
|
4296
4284
|
});
|
4297
|
-
|
4285
|
+
if (stepType === "continue") {
|
4286
|
+
const lastMessage = responseMessages[responseMessages.length - 1];
|
4287
|
+
if (typeof lastMessage.content === "string") {
|
4288
|
+
lastMessage.content = stepText;
|
4289
|
+
} else {
|
4290
|
+
lastMessage.content.push({
|
4291
|
+
text: stepText,
|
4292
|
+
type: "text"
|
4293
|
+
});
|
4294
|
+
}
|
4295
|
+
} else {
|
4296
|
+
responseMessages.push(
|
4297
|
+
...toResponseMessages({
|
4298
|
+
text: stepText,
|
4299
|
+
tools: tools != null ? tools : {},
|
4300
|
+
toolCalls: stepToolCalls,
|
4301
|
+
toolResults: stepToolResults
|
4302
|
+
})
|
4303
|
+
);
|
4304
|
+
}
|
4305
|
+
const currentStepResult = {
|
4298
4306
|
stepType,
|
4299
4307
|
text: stepText,
|
4300
4308
|
toolCalls: stepToolCalls,
|
@@ -4303,49 +4311,30 @@ var DefaultStreamTextResult = class {
|
|
4303
4311
|
usage: stepUsage,
|
4304
4312
|
warnings: self.warnings,
|
4305
4313
|
logprobs: stepLogProbs,
|
4306
|
-
|
4314
|
+
request: stepRequest,
|
4307
4315
|
rawResponse: self.rawResponse,
|
4316
|
+
response: {
|
4317
|
+
...stepResponse,
|
4318
|
+
headers: (_a11 = self.rawResponse) == null ? void 0 : _a11.headers,
|
4319
|
+
// deep clone msgs to avoid mutating past messages in multi-step:
|
4320
|
+
messages: JSON.parse(JSON.stringify(responseMessages))
|
4321
|
+
},
|
4308
4322
|
experimental_providerMetadata: stepProviderMetadata,
|
4309
4323
|
isContinued: nextStepType === "continue"
|
4310
4324
|
};
|
4311
|
-
stepResults.push(
|
4312
|
-
await (onStepFinish == null ? void 0 : onStepFinish(
|
4325
|
+
stepResults.push(currentStepResult);
|
4326
|
+
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
4313
4327
|
const combinedUsage = {
|
4314
4328
|
promptTokens: usage.promptTokens + stepUsage.promptTokens,
|
4315
4329
|
completionTokens: usage.completionTokens + stepUsage.completionTokens,
|
4316
4330
|
totalTokens: usage.totalTokens + stepUsage.totalTokens
|
4317
4331
|
};
|
4318
4332
|
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
4333
|
const {
|
4339
4334
|
result,
|
4340
4335
|
doStreamSpan: doStreamSpan3,
|
4341
4336
|
startTimestampMs: startTimestamp2
|
4342
|
-
} = await startStep({
|
4343
|
-
currentPrompt: {
|
4344
|
-
type: "messages",
|
4345
|
-
system: currentPrompt2.system,
|
4346
|
-
messages: currentPrompt2.messages
|
4347
|
-
}
|
4348
|
-
});
|
4337
|
+
} = await startStep({ responseMessages });
|
4349
4338
|
self.warnings = result.warnings;
|
4350
4339
|
self.rawResponse = result.rawResponse;
|
4351
4340
|
addStepStream({
|
@@ -4353,10 +4342,11 @@ var DefaultStreamTextResult = class {
|
|
4353
4342
|
startTimestamp: startTimestamp2,
|
4354
4343
|
doStreamSpan: doStreamSpan3,
|
4355
4344
|
currentStep: currentStep + 1,
|
4356
|
-
|
4345
|
+
responseMessages,
|
4357
4346
|
usage: combinedUsage,
|
4358
4347
|
stepType: nextStepType,
|
4359
|
-
previousStepText: fullStepText
|
4348
|
+
previousStepText: fullStepText,
|
4349
|
+
stepRequest: result.request
|
4360
4350
|
});
|
4361
4351
|
return;
|
4362
4352
|
}
|
@@ -4367,7 +4357,9 @@ var DefaultStreamTextResult = class {
|
|
4367
4357
|
usage: combinedUsage,
|
4368
4358
|
experimental_providerMetadata: stepProviderMetadata,
|
4369
4359
|
logprobs: stepLogProbs,
|
4370
|
-
response:
|
4360
|
+
response: {
|
4361
|
+
...stepResponse
|
4362
|
+
}
|
4371
4363
|
});
|
4372
4364
|
closeStitchableStream();
|
4373
4365
|
rootSpan.setAttributes(
|
@@ -4390,34 +4382,13 @@ var DefaultStreamTextResult = class {
|
|
4390
4382
|
}
|
4391
4383
|
})
|
4392
4384
|
);
|
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
4385
|
resolveUsage(combinedUsage);
|
4416
4386
|
resolveFinishReason(stepFinishReason);
|
4417
4387
|
resolveText(fullStepText);
|
4418
4388
|
resolveToolCalls(stepToolCalls);
|
4419
4389
|
resolveProviderMetadata(stepProviderMetadata);
|
4420
4390
|
resolveToolResults(stepToolResults);
|
4391
|
+
resolveRequest(stepRequest);
|
4421
4392
|
resolveResponse({
|
4422
4393
|
...stepResponse,
|
4423
4394
|
headers: rawResponse == null ? void 0 : rawResponse.headers
|
@@ -4435,10 +4406,12 @@ var DefaultStreamTextResult = class {
|
|
4435
4406
|
// optional as well. Therefore we need to cast the toolResults to any.
|
4436
4407
|
// The type exposed to the users will be correctly inferred.
|
4437
4408
|
toolResults: stepToolResults,
|
4409
|
+
request: stepRequest,
|
4438
4410
|
rawResponse,
|
4439
4411
|
response: {
|
4440
4412
|
...stepResponse,
|
4441
|
-
headers: rawResponse == null ? void 0 : rawResponse.headers
|
4413
|
+
headers: rawResponse == null ? void 0 : rawResponse.headers,
|
4414
|
+
messages: responseMessages
|
4442
4415
|
},
|
4443
4416
|
warnings,
|
4444
4417
|
experimental_providerMetadata: stepProviderMetadata,
|
@@ -4460,9 +4433,10 @@ var DefaultStreamTextResult = class {
|
|
4460
4433
|
startTimestamp: startTimestampMs,
|
4461
4434
|
doStreamSpan,
|
4462
4435
|
currentStep: 0,
|
4463
|
-
|
4436
|
+
responseMessages: [],
|
4464
4437
|
usage: void 0,
|
4465
|
-
stepType: "initial"
|
4438
|
+
stepType: "initial",
|
4439
|
+
stepRequest: request
|
4466
4440
|
});
|
4467
4441
|
}
|
4468
4442
|
/**
|
@@ -4501,7 +4475,7 @@ var DefaultStreamTextResult = class {
|
|
4501
4475
|
}
|
4502
4476
|
toDataStreamInternal({
|
4503
4477
|
callbacks = {},
|
4504
|
-
getErrorMessage:
|
4478
|
+
getErrorMessage: getErrorMessage3 = () => "",
|
4505
4479
|
// mask error messages for safety by default
|
4506
4480
|
sendUsage = true
|
4507
4481
|
} = {}) {
|
@@ -4576,7 +4550,7 @@ var DefaultStreamTextResult = class {
|
|
4576
4550
|
}
|
4577
4551
|
case "error": {
|
4578
4552
|
controller.enqueue(
|
4579
|
-
(0, import_ui_utils10.formatStreamPart)("error",
|
4553
|
+
(0, import_ui_utils10.formatStreamPart)("error", getErrorMessage3(chunk.error))
|
4580
4554
|
);
|
4581
4555
|
break;
|
4582
4556
|
}
|
@@ -4624,7 +4598,7 @@ var DefaultStreamTextResult = class {
|
|
4624
4598
|
statusText: "statusText" in options ? options.statusText : void 0
|
4625
4599
|
};
|
4626
4600
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
4627
|
-
const
|
4601
|
+
const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
|
4628
4602
|
const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
|
4629
4603
|
writeToServerResponse({
|
4630
4604
|
response,
|
@@ -4634,7 +4608,7 @@ var DefaultStreamTextResult = class {
|
|
4634
4608
|
contentType: "text/plain; charset=utf-8",
|
4635
4609
|
dataStreamVersion: "v1"
|
4636
4610
|
}),
|
4637
|
-
stream: this.toDataStream({ data, getErrorMessage:
|
4611
|
+
stream: this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage })
|
4638
4612
|
});
|
4639
4613
|
}
|
4640
4614
|
pipeTextStreamToResponse(response, init) {
|
@@ -4666,10 +4640,10 @@ var DefaultStreamTextResult = class {
|
|
4666
4640
|
statusText: "statusText" in options ? options.statusText : void 0
|
4667
4641
|
};
|
4668
4642
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
4669
|
-
const
|
4643
|
+
const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
|
4670
4644
|
const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
|
4671
4645
|
return new Response(
|
4672
|
-
this.toDataStream({ data, getErrorMessage:
|
4646
|
+
this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage }),
|
4673
4647
|
{
|
4674
4648
|
status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
|
4675
4649
|
statusText: init == null ? void 0 : init.statusText,
|
@@ -4711,6 +4685,7 @@ var experimental_wrapLanguageModel = ({
|
|
4711
4685
|
modelId: modelId != null ? modelId : model.modelId,
|
4712
4686
|
defaultObjectGenerationMode: model.defaultObjectGenerationMode,
|
4713
4687
|
supportsImageUrls: model.supportsImageUrls,
|
4688
|
+
supportsUrl: model.supportsUrl,
|
4714
4689
|
supportsStructuredOutputs: model.supportsStructuredOutputs,
|
4715
4690
|
async doGenerate(params) {
|
4716
4691
|
const transformedParams = await doTransform({ params, type: "generate" });
|
@@ -4834,7 +4809,7 @@ function convertToCoreMessages(messages) {
|
|
4834
4809
|
role: "assistant",
|
4835
4810
|
content: [
|
4836
4811
|
{ type: "text", text: content },
|
4837
|
-
...toolInvocations.
|
4812
|
+
...toolInvocations.map(({ toolCallId, toolName, args }) => ({
|
4838
4813
|
type: "tool-call",
|
4839
4814
|
toolCallId,
|
4840
4815
|
toolName,
|
@@ -4842,19 +4817,25 @@ function convertToCoreMessages(messages) {
|
|
4842
4817
|
}))
|
4843
4818
|
]
|
4844
4819
|
});
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4820
|
+
coreMessages.push({
|
4821
|
+
role: "tool",
|
4822
|
+
content: toolInvocations.map((ToolInvocation) => {
|
4823
|
+
if (!("result" in ToolInvocation)) {
|
4824
|
+
throw new MessageConversionError({
|
4825
|
+
originalMessage: message,
|
4826
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(ToolInvocation)
|
4827
|
+
});
|
4828
|
+
}
|
4829
|
+
const { toolCallId, toolName, args, result } = ToolInvocation;
|
4830
|
+
return {
|
4831
|
+
type: "tool-result",
|
4832
|
+
toolCallId,
|
4833
|
+
toolName,
|
4834
|
+
args,
|
4835
|
+
result
|
4836
|
+
};
|
4837
|
+
})
|
4838
|
+
});
|
4858
4839
|
break;
|
4859
4840
|
}
|
4860
4841
|
case "function":
|
@@ -6130,8 +6111,8 @@ var StreamingTextResponse = class extends Response {
|
|
6130
6111
|
};
|
6131
6112
|
|
6132
6113
|
// streams/index.ts
|
6133
|
-
var generateId2 =
|
6134
|
-
var nanoid =
|
6114
|
+
var generateId2 = import_provider_utils10.generateId;
|
6115
|
+
var nanoid = import_provider_utils10.generateId;
|
6135
6116
|
// Annotate the CommonJS export names for ESM import in node:
|
6136
6117
|
0 && (module.exports = {
|
6137
6118
|
AISDKError,
|