ai 3.4.5 → 3.4.6
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 +14 -0
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +117 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/index.d.ts +24 -1
- package/rsc/dist/rsc-server.d.mts +24 -1
- package/rsc/dist/rsc-server.mjs +117 -81
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 3.4.6
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- d595d0d: feat (ai/core): file content parts
|
8
|
+
- Updated dependencies [d595d0d]
|
9
|
+
- @ai-sdk/provider@0.0.24
|
10
|
+
- @ai-sdk/provider-utils@1.0.20
|
11
|
+
- @ai-sdk/ui-utils@0.0.46
|
12
|
+
- @ai-sdk/react@0.0.62
|
13
|
+
- @ai-sdk/solid@0.0.49
|
14
|
+
- @ai-sdk/svelte@0.0.51
|
15
|
+
- @ai-sdk/vue@0.0.53
|
16
|
+
|
3
17
|
## 3.4.5
|
4
18
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -438,6 +438,29 @@ interface ImagePart {
|
|
438
438
|
experimental_providerMetadata?: ProviderMetadata;
|
439
439
|
}
|
440
440
|
/**
|
441
|
+
File content part of a prompt. It contains a file.
|
442
|
+
*/
|
443
|
+
interface FilePart {
|
444
|
+
type: 'file';
|
445
|
+
/**
|
446
|
+
File data. Can either be:
|
447
|
+
|
448
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
449
|
+
- URL: a URL that points to the image
|
450
|
+
*/
|
451
|
+
data: DataContent | URL;
|
452
|
+
/**
|
453
|
+
Mime type of the file.
|
454
|
+
*/
|
455
|
+
mimeType: string;
|
456
|
+
/**
|
457
|
+
Additional provider-specific metadata. They are passed through
|
458
|
+
to the provider from the AI SDK and enable provider-specific
|
459
|
+
functionality that can be fully encapsulated in the provider.
|
460
|
+
*/
|
461
|
+
experimental_providerMetadata?: ProviderMetadata;
|
462
|
+
}
|
463
|
+
/**
|
441
464
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
442
465
|
*/
|
443
466
|
interface ToolCallPart {
|
@@ -531,7 +554,7 @@ type ExperimentalUserMessage = CoreUserMessage;
|
|
531
554
|
/**
|
532
555
|
Content of a user message. It can be a string or an array of text and image parts.
|
533
556
|
*/
|
534
|
-
type UserContent = string | Array<TextPart$1 | ImagePart>;
|
557
|
+
type UserContent = string | Array<TextPart$1 | ImagePart | FilePart>;
|
535
558
|
/**
|
536
559
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
537
560
|
*/
|
package/dist/index.d.ts
CHANGED
@@ -438,6 +438,29 @@ interface ImagePart {
|
|
438
438
|
experimental_providerMetadata?: ProviderMetadata;
|
439
439
|
}
|
440
440
|
/**
|
441
|
+
File content part of a prompt. It contains a file.
|
442
|
+
*/
|
443
|
+
interface FilePart {
|
444
|
+
type: 'file';
|
445
|
+
/**
|
446
|
+
File data. Can either be:
|
447
|
+
|
448
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
449
|
+
- URL: a URL that points to the image
|
450
|
+
*/
|
451
|
+
data: DataContent | URL;
|
452
|
+
/**
|
453
|
+
Mime type of the file.
|
454
|
+
*/
|
455
|
+
mimeType: string;
|
456
|
+
/**
|
457
|
+
Additional provider-specific metadata. They are passed through
|
458
|
+
to the provider from the AI SDK and enable provider-specific
|
459
|
+
functionality that can be fully encapsulated in the provider.
|
460
|
+
*/
|
461
|
+
experimental_providerMetadata?: ProviderMetadata;
|
462
|
+
}
|
463
|
+
/**
|
441
464
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
442
465
|
*/
|
443
466
|
interface ToolCallPart {
|
@@ -531,7 +554,7 @@ type ExperimentalUserMessage = CoreUserMessage;
|
|
531
554
|
/**
|
532
555
|
Content of a user message. It can be a string or an array of text and image parts.
|
533
556
|
*/
|
534
|
-
type UserContent = string | Array<TextPart$1 | ImagePart>;
|
557
|
+
type UserContent = string | Array<TextPart$1 | ImagePart | FilePart>;
|
535
558
|
/**
|
536
559
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
537
560
|
*/
|
package/dist/index.js
CHANGED
@@ -825,6 +825,15 @@ var dataContentSchema = import_zod.z.union([
|
|
825
825
|
{ message: "Must be a Buffer" }
|
826
826
|
)
|
827
827
|
]);
|
828
|
+
function convertDataContentToBase64String(content) {
|
829
|
+
if (typeof content === "string") {
|
830
|
+
return content;
|
831
|
+
}
|
832
|
+
if (content instanceof ArrayBuffer) {
|
833
|
+
return (0, import_provider_utils2.convertUint8ArrayToBase64)(new Uint8Array(content));
|
834
|
+
}
|
835
|
+
return (0, import_provider_utils2.convertUint8ArrayToBase64)(content);
|
836
|
+
}
|
828
837
|
function convertDataContentToUint8Array(content) {
|
829
838
|
if (content instanceof Uint8Array) {
|
830
839
|
return content;
|
@@ -946,98 +955,119 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
946
955
|
}
|
947
956
|
return {
|
948
957
|
role: "user",
|
949
|
-
content: message.content.map(
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
case "image": {
|
960
|
-
if (part.image instanceof URL) {
|
961
|
-
if (downloadedImages == null) {
|
962
|
-
return {
|
963
|
-
type: "image",
|
964
|
-
image: part.image,
|
965
|
-
mimeType: part.mimeType,
|
966
|
-
providerMetadata: part.experimental_providerMetadata
|
967
|
-
};
|
968
|
-
} else {
|
969
|
-
const downloadedImage = downloadedImages[part.image.toString()];
|
970
|
-
return {
|
971
|
-
type: "image",
|
972
|
-
image: downloadedImage.data,
|
973
|
-
mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
|
974
|
-
providerMetadata: part.experimental_providerMetadata
|
975
|
-
};
|
976
|
-
}
|
958
|
+
content: message.content.map(
|
959
|
+
(part) => {
|
960
|
+
var _a11, _b, _c;
|
961
|
+
switch (part.type) {
|
962
|
+
case "text": {
|
963
|
+
return {
|
964
|
+
type: "text",
|
965
|
+
text: part.text,
|
966
|
+
providerMetadata: part.experimental_providerMetadata
|
967
|
+
};
|
977
968
|
}
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
969
|
+
case "image": {
|
970
|
+
if (part.image instanceof URL) {
|
971
|
+
if (downloadedImages == null) {
|
972
|
+
return {
|
973
|
+
type: "image",
|
974
|
+
image: part.image,
|
975
|
+
mimeType: part.mimeType,
|
976
|
+
providerMetadata: part.experimental_providerMetadata
|
977
|
+
};
|
978
|
+
} else {
|
979
|
+
const downloadedImage = downloadedImages[part.image.toString()];
|
980
|
+
return {
|
981
|
+
type: "image",
|
982
|
+
image: downloadedImage.data,
|
983
|
+
mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
|
984
|
+
providerMetadata: part.experimental_providerMetadata
|
985
|
+
};
|
986
|
+
}
|
987
|
+
}
|
988
|
+
if (typeof part.image === "string") {
|
989
|
+
try {
|
990
|
+
const url = new URL(part.image);
|
991
|
+
switch (url.protocol) {
|
992
|
+
case "http:":
|
993
|
+
case "https:": {
|
994
|
+
if (downloadedImages == null) {
|
995
|
+
return {
|
996
|
+
type: "image",
|
997
|
+
image: url,
|
998
|
+
mimeType: part.mimeType,
|
999
|
+
providerMetadata: part.experimental_providerMetadata
|
1000
|
+
};
|
1001
|
+
} else {
|
1002
|
+
const downloadedImage = downloadedImages[part.image];
|
1003
|
+
return {
|
1004
|
+
type: "image",
|
1005
|
+
image: downloadedImage.data,
|
1006
|
+
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
1007
|
+
providerMetadata: part.experimental_providerMetadata
|
1008
|
+
};
|
1009
|
+
}
|
999
1010
|
}
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1011
|
+
case "data:": {
|
1012
|
+
try {
|
1013
|
+
const [header, base64Content] = part.image.split(",");
|
1014
|
+
const mimeType = header.split(";")[0].split(":")[1];
|
1015
|
+
if (mimeType == null || base64Content == null) {
|
1016
|
+
throw new Error("Invalid data URL format");
|
1017
|
+
}
|
1018
|
+
return {
|
1019
|
+
type: "image",
|
1020
|
+
image: convertDataContentToUint8Array(base64Content),
|
1021
|
+
mimeType,
|
1022
|
+
providerMetadata: part.experimental_providerMetadata
|
1023
|
+
};
|
1024
|
+
} catch (error) {
|
1025
|
+
throw new Error(
|
1026
|
+
`Error processing data URL: ${(0, import_provider_utils3.getErrorMessage)(
|
1027
|
+
message
|
1028
|
+
)}`
|
1029
|
+
);
|
1007
1030
|
}
|
1008
|
-
|
1009
|
-
|
1010
|
-
image: convertDataContentToUint8Array(base64Content),
|
1011
|
-
mimeType,
|
1012
|
-
providerMetadata: part.experimental_providerMetadata
|
1013
|
-
};
|
1014
|
-
} catch (error) {
|
1031
|
+
}
|
1032
|
+
default: {
|
1015
1033
|
throw new Error(
|
1016
|
-
`
|
1017
|
-
message
|
1018
|
-
)}`
|
1034
|
+
`Unsupported URL protocol: ${url.protocol}`
|
1019
1035
|
);
|
1020
1036
|
}
|
1021
1037
|
}
|
1022
|
-
|
1023
|
-
throw new Error(
|
1024
|
-
`Unsupported URL protocol: ${url.protocol}`
|
1025
|
-
);
|
1026
|
-
}
|
1038
|
+
} catch (_ignored) {
|
1027
1039
|
}
|
1028
|
-
} catch (_ignored) {
|
1029
1040
|
}
|
1041
|
+
const imageUint8 = convertDataContentToUint8Array(part.image);
|
1042
|
+
return {
|
1043
|
+
type: "image",
|
1044
|
+
image: imageUint8,
|
1045
|
+
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
1046
|
+
providerMetadata: part.experimental_providerMetadata
|
1047
|
+
};
|
1048
|
+
}
|
1049
|
+
case "file": {
|
1050
|
+
if (part.data instanceof URL) {
|
1051
|
+
return {
|
1052
|
+
type: "file",
|
1053
|
+
data: part.data,
|
1054
|
+
mimeType: part.mimeType,
|
1055
|
+
providerMetadata: part.experimental_providerMetadata
|
1056
|
+
};
|
1057
|
+
}
|
1058
|
+
const imageBase64 = convertDataContentToBase64String(
|
1059
|
+
part.data
|
1060
|
+
);
|
1061
|
+
return {
|
1062
|
+
type: "file",
|
1063
|
+
data: imageBase64,
|
1064
|
+
mimeType: part.mimeType,
|
1065
|
+
providerMetadata: part.experimental_providerMetadata
|
1066
|
+
};
|
1030
1067
|
}
|
1031
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
1032
|
-
return {
|
1033
|
-
type: "image",
|
1034
|
-
image: imageUint8,
|
1035
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
1036
|
-
providerMetadata: part.experimental_providerMetadata
|
1037
|
-
};
|
1038
1068
|
}
|
1039
1069
|
}
|
1040
|
-
|
1070
|
+
).filter((part) => part.type !== "text" || part.text !== ""),
|
1041
1071
|
providerMetadata: message.experimental_providerMetadata
|
1042
1072
|
};
|
1043
1073
|
}
|
@@ -1298,6 +1328,12 @@ var imagePartSchema = import_zod4.z.object({
|
|
1298
1328
|
mimeType: import_zod4.z.string().optional(),
|
1299
1329
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1300
1330
|
});
|
1331
|
+
var filePartSchema = import_zod4.z.object({
|
1332
|
+
type: import_zod4.z.literal("file"),
|
1333
|
+
data: import_zod4.z.union([dataContentSchema, import_zod4.z.instanceof(URL)]),
|
1334
|
+
mimeType: import_zod4.z.string(),
|
1335
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1336
|
+
});
|
1301
1337
|
var toolCallPartSchema = import_zod4.z.object({
|
1302
1338
|
type: import_zod4.z.literal("tool-call"),
|
1303
1339
|
toolCallId: import_zod4.z.string(),
|
@@ -1323,7 +1359,7 @@ var coreUserMessageSchema = import_zod5.z.object({
|
|
1323
1359
|
role: import_zod5.z.literal("user"),
|
1324
1360
|
content: import_zod5.z.union([
|
1325
1361
|
import_zod5.z.string(),
|
1326
|
-
import_zod5.z.array(import_zod5.z.union([textPartSchema, imagePartSchema]))
|
1362
|
+
import_zod5.z.array(import_zod5.z.union([textPartSchema, imagePartSchema, filePartSchema]))
|
1327
1363
|
]),
|
1328
1364
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1329
1365
|
});
|