ai 6.0.321 → 6.0.322

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,17 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.322
4
+
5
+ ### Patch Changes
6
+
7
+ - d900e58: fix(ai): support cross-realm Uint8Array and ArrayBuffer in DefaultGeneratedFile
8
+ - d900e58: fix(ai): handle cross-realm Uint8Array and ArrayBuffer in prompt data validation and conversion
9
+ - Updated dependencies [d900e58]
10
+ - Updated dependencies [d900e58]
11
+ - Updated dependencies [d900e58]
12
+ - @ai-sdk/provider-utils@4.0.64
13
+ - @ai-sdk/gateway@3.0.228
14
+
3
15
  ## 6.0.321
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -644,7 +644,7 @@ declare class DefaultGeneratedFile implements GeneratedFile {
644
644
  private uint8ArrayData;
645
645
  readonly mediaType: string;
646
646
  constructor({ data, mediaType, }: {
647
- data: string | Uint8Array;
647
+ data: string | Uint8Array | ArrayBuffer;
648
648
  mediaType: string;
649
649
  });
650
650
  get base64(): string;
package/dist/index.d.ts CHANGED
@@ -644,7 +644,7 @@ declare class DefaultGeneratedFile implements GeneratedFile {
644
644
  private uint8ArrayData;
645
645
  readonly mediaType: string;
646
646
  constructor({ data, mediaType, }: {
647
- data: string | Uint8Array;
647
+ data: string | Uint8Array | ArrayBuffer;
648
648
  mediaType: string;
649
649
  });
650
650
  get base64(): string;
package/dist/index.js CHANGED
@@ -1335,7 +1335,7 @@ function detectMediaType({
1335
1335
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1336
1336
 
1337
1337
  // src/version.ts
1338
- var VERSION = true ? "6.0.321" : "0.0.0-test";
1338
+ var VERSION = true ? "6.0.322" : "0.0.0-test";
1339
1339
 
1340
1340
  // src/util/download/download.ts
1341
1341
  var download = async ({
@@ -1448,8 +1448,8 @@ function splitDataUrl(dataUrl) {
1448
1448
  // src/prompt/data-content.ts
1449
1449
  var dataContentSchema = import_v4.z.union([
1450
1450
  import_v4.z.string(),
1451
- import_v4.z.instanceof(Uint8Array),
1452
- import_v4.z.instanceof(ArrayBuffer),
1451
+ import_v4.z.custom(import_provider_utils4.isUint8Array, { message: "Must be a Uint8Array" }),
1452
+ import_v4.z.custom(import_provider_utils4.isArrayBuffer, { message: "Must be an ArrayBuffer" }),
1453
1453
  import_v4.z.custom(
1454
1454
  // Buffer might not be available in some environments such as CloudFlare:
1455
1455
  (value) => {
@@ -1461,10 +1461,13 @@ var dataContentSchema = import_v4.z.union([
1461
1461
  ]);
1462
1462
  function convertToLanguageModelV3DataContent(content) {
1463
1463
  let originalUrl;
1464
- if (content instanceof Uint8Array) {
1465
- return { data: content, mediaType: void 0 };
1464
+ if ((0, import_provider_utils4.isUint8Array)(content)) {
1465
+ return {
1466
+ data: convertDataContentToUint8Array(content),
1467
+ mediaType: void 0
1468
+ };
1466
1469
  }
1467
- if (content instanceof ArrayBuffer) {
1470
+ if ((0, import_provider_utils4.isArrayBuffer)(content)) {
1468
1471
  return { data: new Uint8Array(content), mediaType: void 0 };
1469
1472
  }
1470
1473
  if (typeof content === "string") {
@@ -1497,14 +1500,15 @@ function convertDataContentToBase64String(content) {
1497
1500
  if (typeof content === "string") {
1498
1501
  return content;
1499
1502
  }
1500
- if (content instanceof ArrayBuffer) {
1501
- return (0, import_provider_utils4.convertUint8ArrayToBase64)(new Uint8Array(content));
1502
- }
1503
- return (0, import_provider_utils4.convertUint8ArrayToBase64)(content);
1503
+ return (0, import_provider_utils4.convertUint8ArrayToBase64)(convertDataContentToUint8Array(content));
1504
1504
  }
1505
1505
  function convertDataContentToUint8Array(content) {
1506
- if (content instanceof Uint8Array) {
1507
- return content;
1506
+ if ((0, import_provider_utils4.isUint8Array)(content)) {
1507
+ if (content instanceof Uint8Array) {
1508
+ return content;
1509
+ }
1510
+ const { buffer, byteOffset, byteLength } = content;
1511
+ return new Uint8Array(buffer, byteOffset, byteLength);
1508
1512
  }
1509
1513
  if (typeof content === "string") {
1510
1514
  try {
@@ -1517,7 +1521,7 @@ function convertDataContentToUint8Array(content) {
1517
1521
  });
1518
1522
  }
1519
1523
  }
1520
- if (content instanceof ArrayBuffer) {
1524
+ if ((0, import_provider_utils4.isArrayBuffer)(content)) {
1521
1525
  return new Uint8Array(content);
1522
1526
  }
1523
1527
  throw new InvalidDataContentError({ content });
@@ -3206,9 +3210,8 @@ var DefaultGeneratedFile = class {
3206
3210
  data,
3207
3211
  mediaType
3208
3212
  }) {
3209
- const isUint8Array = data instanceof Uint8Array;
3210
- this.base64Data = isUint8Array ? void 0 : data;
3211
- this.uint8ArrayData = isUint8Array ? data : void 0;
3213
+ this.base64Data = typeof data === "string" ? data : void 0;
3214
+ this.uint8ArrayData = typeof data === "string" ? void 0 : convertDataContentToUint8Array(data);
3212
3215
  this.mediaType = mediaType;
3213
3216
  }
3214
3217
  // lazy conversion with caching to avoid unnecessary conversion overhead: