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/dist/index.mjs CHANGED
@@ -1225,7 +1225,7 @@ import {
1225
1225
  } from "@ai-sdk/provider-utils";
1226
1226
 
1227
1227
  // src/version.ts
1228
- var VERSION = true ? "6.0.321" : "0.0.0-test";
1228
+ var VERSION = true ? "6.0.322" : "0.0.0-test";
1229
1229
 
1230
1230
  // src/util/download/download.ts
1231
1231
  var download = async ({
@@ -1317,6 +1317,8 @@ function mergeObjects(base, overrides) {
1317
1317
  // src/prompt/data-content.ts
1318
1318
  import { AISDKError as AISDKError24 } from "@ai-sdk/provider";
1319
1319
  import {
1320
+ isUint8Array,
1321
+ isArrayBuffer,
1320
1322
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
1321
1323
  convertUint8ArrayToBase64
1322
1324
  } from "@ai-sdk/provider-utils";
@@ -1341,8 +1343,8 @@ function splitDataUrl(dataUrl) {
1341
1343
  // src/prompt/data-content.ts
1342
1344
  var dataContentSchema = z.union([
1343
1345
  z.string(),
1344
- z.instanceof(Uint8Array),
1345
- z.instanceof(ArrayBuffer),
1346
+ z.custom(isUint8Array, { message: "Must be a Uint8Array" }),
1347
+ z.custom(isArrayBuffer, { message: "Must be an ArrayBuffer" }),
1346
1348
  z.custom(
1347
1349
  // Buffer might not be available in some environments such as CloudFlare:
1348
1350
  (value) => {
@@ -1354,10 +1356,13 @@ var dataContentSchema = z.union([
1354
1356
  ]);
1355
1357
  function convertToLanguageModelV3DataContent(content) {
1356
1358
  let originalUrl;
1357
- if (content instanceof Uint8Array) {
1358
- return { data: content, mediaType: void 0 };
1359
+ if (isUint8Array(content)) {
1360
+ return {
1361
+ data: convertDataContentToUint8Array(content),
1362
+ mediaType: void 0
1363
+ };
1359
1364
  }
1360
- if (content instanceof ArrayBuffer) {
1365
+ if (isArrayBuffer(content)) {
1361
1366
  return { data: new Uint8Array(content), mediaType: void 0 };
1362
1367
  }
1363
1368
  if (typeof content === "string") {
@@ -1390,14 +1395,15 @@ function convertDataContentToBase64String(content) {
1390
1395
  if (typeof content === "string") {
1391
1396
  return content;
1392
1397
  }
1393
- if (content instanceof ArrayBuffer) {
1394
- return convertUint8ArrayToBase64(new Uint8Array(content));
1395
- }
1396
- return convertUint8ArrayToBase64(content);
1398
+ return convertUint8ArrayToBase64(convertDataContentToUint8Array(content));
1397
1399
  }
1398
1400
  function convertDataContentToUint8Array(content) {
1399
- if (content instanceof Uint8Array) {
1400
- return content;
1401
+ if (isUint8Array(content)) {
1402
+ if (content instanceof Uint8Array) {
1403
+ return content;
1404
+ }
1405
+ const { buffer, byteOffset, byteLength } = content;
1406
+ return new Uint8Array(buffer, byteOffset, byteLength);
1401
1407
  }
1402
1408
  if (typeof content === "string") {
1403
1409
  try {
@@ -1410,7 +1416,7 @@ function convertDataContentToUint8Array(content) {
1410
1416
  });
1411
1417
  }
1412
1418
  }
1413
- if (content instanceof ArrayBuffer) {
1419
+ if (isArrayBuffer(content)) {
1414
1420
  return new Uint8Array(content);
1415
1421
  }
1416
1422
  throw new InvalidDataContentError({ content });
@@ -3109,9 +3115,8 @@ var DefaultGeneratedFile = class {
3109
3115
  data,
3110
3116
  mediaType
3111
3117
  }) {
3112
- const isUint8Array = data instanceof Uint8Array;
3113
- this.base64Data = isUint8Array ? void 0 : data;
3114
- this.uint8ArrayData = isUint8Array ? data : void 0;
3118
+ this.base64Data = typeof data === "string" ? data : void 0;
3119
+ this.uint8ArrayData = typeof data === "string" ? void 0 : convertDataContentToUint8Array(data);
3115
3120
  this.mediaType = mediaType;
3116
3121
  }
3117
3122
  // lazy conversion with caching to avoid unnecessary conversion overhead: