ai 4.3.7 → 4.3.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "4.3.7",
3
+ "version": "4.3.9",
4
4
  "description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -265,6 +265,7 @@ async function download({ url }) {
265
265
  }
266
266
 
267
267
  // core/util/detect-mimetype.ts
268
+ import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
268
269
  var imageMimeTypeSignatures = [
269
270
  {
270
271
  mimeType: "image/gif",
@@ -338,12 +339,26 @@ var imageMimeTypeSignatures = [
338
339
  base64Prefix: "AAAAIGZ0eXBoZWlj"
339
340
  }
340
341
  ];
342
+ var stripID3 = (data) => {
343
+ const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
344
+ const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
345
+ return bytes.slice(id3Size + 10);
346
+ };
347
+ function stripID3TagsIfPresent(data) {
348
+ const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
349
+ data[1] === 68 && // 'D'
350
+ data[2] === 51;
351
+ return hasId3 ? stripID3(data) : data;
352
+ }
341
353
  function detectMimeType({
342
354
  data,
343
355
  signatures
344
356
  }) {
357
+ const processedData = stripID3TagsIfPresent(data);
345
358
  for (const signature of signatures) {
346
- if (typeof data === "string" ? data.startsWith(signature.base64Prefix) : data.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => data[index] === byte)) {
359
+ if (typeof processedData === "string" ? processedData.startsWith(signature.base64Prefix) : processedData.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
360
+ (byte, index) => processedData[index] === byte
361
+ )) {
347
362
  return signature.mimeType;
348
363
  }
349
364
  }
@@ -352,7 +367,7 @@ function detectMimeType({
352
367
 
353
368
  // core/prompt/data-content.ts
354
369
  import {
355
- convertBase64ToUint8Array,
370
+ convertBase64ToUint8Array as convertBase64ToUint8Array2,
356
371
  convertUint8ArrayToBase64
357
372
  } from "@ai-sdk/provider-utils";
358
373
 
@@ -408,7 +423,7 @@ function convertDataContentToUint8Array(content) {
408
423
  }
409
424
  if (typeof content === "string") {
410
425
  try {
411
- return convertBase64ToUint8Array(content);
426
+ return convertBase64ToUint8Array2(content);
412
427
  } catch (error) {
413
428
  throw new InvalidDataContentError({
414
429
  message: "Invalid data content. Content string is not a base64-encoded media.",