ai 5.0.283 → 5.0.285

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.285
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a069bd: fix(ai): support cross-realm Uint8Array and ArrayBuffer in DefaultGeneratedFile
8
+ - 0a069bd: fix(ai): handle cross-realm Uint8Array and ArrayBuffer in prompt data validation and conversion
9
+ - Updated dependencies [0a069bd]
10
+ - Updated dependencies [0a069bd]
11
+ - Updated dependencies [0a069bd]
12
+ - @ai-sdk/provider-utils@3.0.44
13
+ - @ai-sdk/gateway@2.0.176
14
+
15
+ ## 5.0.284
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [80dca68]
20
+ - Updated dependencies [74e240d]
21
+ - Updated dependencies [a16b8df]
22
+ - @ai-sdk/gateway@2.0.175
23
+
3
24
  ## 5.0.283
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -847,7 +847,7 @@ function detectMediaType({
847
847
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
848
848
 
849
849
  // src/version.ts
850
- var VERSION = true ? "5.0.283" : "0.0.0-test";
850
+ var VERSION = true ? "5.0.285" : "0.0.0-test";
851
851
 
852
852
  // src/util/download/download.ts
853
853
  var download = async ({
@@ -924,8 +924,8 @@ function splitDataUrl(dataUrl) {
924
924
  // src/prompt/data-content.ts
925
925
  var dataContentSchema = import_v4.z.union([
926
926
  import_v4.z.string(),
927
- import_v4.z.instanceof(Uint8Array),
928
- import_v4.z.instanceof(ArrayBuffer),
927
+ import_v4.z.custom(import_provider_utils3.isUint8Array, { message: "Must be a Uint8Array" }),
928
+ import_v4.z.custom(import_provider_utils3.isArrayBuffer, { message: "Must be an ArrayBuffer" }),
929
929
  import_v4.z.custom(
930
930
  // Buffer might not be available in some environments such as CloudFlare:
931
931
  (value) => {
@@ -936,10 +936,13 @@ var dataContentSchema = import_v4.z.union([
936
936
  )
937
937
  ]);
938
938
  function convertToLanguageModelV2DataContent(content) {
939
- if (content instanceof Uint8Array) {
940
- return { data: content, mediaType: void 0 };
939
+ if ((0, import_provider_utils3.isUint8Array)(content)) {
940
+ return {
941
+ data: convertDataContentToUint8Array(content),
942
+ mediaType: void 0
943
+ };
941
944
  }
942
- if (content instanceof ArrayBuffer) {
945
+ if ((0, import_provider_utils3.isArrayBuffer)(content)) {
943
946
  return { data: new Uint8Array(content), mediaType: void 0 };
944
947
  }
945
948
  if (typeof content === "string") {
@@ -966,14 +969,15 @@ function convertDataContentToBase64String(content) {
966
969
  if (typeof content === "string") {
967
970
  return content;
968
971
  }
969
- if (content instanceof ArrayBuffer) {
970
- return (0, import_provider_utils3.convertUint8ArrayToBase64)(new Uint8Array(content));
971
- }
972
- return (0, import_provider_utils3.convertUint8ArrayToBase64)(content);
972
+ return (0, import_provider_utils3.convertUint8ArrayToBase64)(convertDataContentToUint8Array(content));
973
973
  }
974
974
  function convertDataContentToUint8Array(content) {
975
- if (content instanceof Uint8Array) {
976
- return content;
975
+ if ((0, import_provider_utils3.isUint8Array)(content)) {
976
+ if (content instanceof Uint8Array) {
977
+ return content;
978
+ }
979
+ const { buffer, byteOffset, byteLength } = content;
980
+ return new Uint8Array(buffer, byteOffset, byteLength);
977
981
  }
978
982
  if (typeof content === "string") {
979
983
  try {
@@ -986,7 +990,7 @@ function convertDataContentToUint8Array(content) {
986
990
  });
987
991
  }
988
992
  }
989
- if (content instanceof ArrayBuffer) {
993
+ if ((0, import_provider_utils3.isArrayBuffer)(content)) {
990
994
  return new Uint8Array(content);
991
995
  }
992
996
  throw new InvalidDataContentError({ content });
@@ -2035,9 +2039,8 @@ var DefaultGeneratedFile = class {
2035
2039
  data,
2036
2040
  mediaType
2037
2041
  }) {
2038
- const isUint8Array = data instanceof Uint8Array;
2039
- this.base64Data = isUint8Array ? void 0 : data;
2040
- this.uint8ArrayData = isUint8Array ? data : void 0;
2042
+ this.base64Data = typeof data === "string" ? data : void 0;
2043
+ this.uint8ArrayData = typeof data === "string" ? void 0 : convertDataContentToUint8Array(data);
2041
2044
  this.mediaType = mediaType;
2042
2045
  }
2043
2046
  // lazy conversion with caching to avoid unnecessary conversion overhead: