ai 5.0.218 → 5.0.219

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
@@ -658,25 +658,37 @@ var audioMediaTypeSignatures = [
658
658
  bytesPrefix: [26, 69, 223, 163]
659
659
  }
660
660
  ];
661
- var stripID3 = (data) => {
662
- const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
661
+ var DEFAULT_SNIFF_BYTES = 18;
662
+ var MAX_SIGNATURE_BYTES = 12;
663
+ var MAX_ID3_TAG_BYTES = 128 * 1024;
664
+ var ID3_SCAN_BYTES = MAX_ID3_TAG_BYTES + MAX_SIGNATURE_BYTES;
665
+ function decodePrefix(data, maxBytes) {
666
+ if (typeof data !== "string") {
667
+ return data.length > maxBytes ? data.subarray(0, maxBytes) : data;
668
+ }
669
+ const maxChars = Math.ceil(maxBytes / 3) * 4;
670
+ const bytes = convertBase64ToUint8Array(
671
+ data.substring(0, Math.min(data.length, maxChars))
672
+ );
673
+ return bytes.length > maxBytes ? bytes.subarray(0, maxBytes) : bytes;
674
+ }
675
+ function hasID3(bytes) {
676
+ return bytes.length > 10 && bytes[0] === 73 && // 'I'
677
+ bytes[1] === 68 && // 'D'
678
+ bytes[2] === 51;
679
+ }
680
+ var stripID3 = (bytes) => {
663
681
  const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
664
- return bytes.slice(id3Size + 10);
682
+ return bytes.subarray(id3Size + 10);
665
683
  };
666
- function stripID3TagsIfPresent(data) {
667
- const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
668
- data[1] === 68 && // 'D'
669
- data[2] === 51;
670
- return hasId3 ? stripID3(data) : data;
671
- }
672
684
  function detectMediaType({
673
685
  data,
674
686
  signatures
675
687
  }) {
676
- const processedData = stripID3TagsIfPresent(data);
677
- const bytes = typeof processedData === "string" ? convertBase64ToUint8Array(
678
- processedData.substring(0, Math.min(processedData.length, 24))
679
- ) : processedData;
688
+ let bytes = decodePrefix(data, DEFAULT_SNIFF_BYTES);
689
+ if (hasID3(bytes)) {
690
+ bytes = stripID3(decodePrefix(data, ID3_SCAN_BYTES));
691
+ }
680
692
  for (const signature of signatures) {
681
693
  if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
682
694
  (byte, index) => byte === null || bytes[index] === byte
@@ -699,7 +711,7 @@ import {
699
711
  } from "@ai-sdk/provider-utils";
700
712
 
701
713
  // src/version.ts
702
- var VERSION = true ? "5.0.218" : "0.0.0-test";
714
+ var VERSION = true ? "5.0.219" : "0.0.0-test";
703
715
 
704
716
  // src/util/download/download.ts
705
717
  var download = async ({
@@ -2871,7 +2883,7 @@ function writeToServerResponse({
2871
2883
  response.end();
2872
2884
  }
2873
2885
  };
2874
- read();
2886
+ return read();
2875
2887
  }
2876
2888
 
2877
2889
  // src/text-stream/pipe-text-stream-to-response.ts
@@ -2882,7 +2894,7 @@ function pipeTextStreamToResponse({
2882
2894
  headers,
2883
2895
  textStream
2884
2896
  }) {
2885
- writeToServerResponse({
2897
+ return writeToServerResponse({
2886
2898
  response,
2887
2899
  status,
2888
2900
  statusText,
@@ -4119,7 +4131,7 @@ function pipeUIMessageStreamToResponse({
4119
4131
  sseStream = stream1;
4120
4132
  consumeSseStream({ stream: stream2 });
4121
4133
  }
4122
- writeToServerResponse({
4134
+ return writeToServerResponse({
4123
4135
  response,
4124
4136
  status,
4125
4137
  statusText,
@@ -5870,7 +5882,7 @@ var DefaultStreamTextResult = class {
5870
5882
  onError,
5871
5883
  ...init
5872
5884
  } = {}) {
5873
- pipeUIMessageStreamToResponse({
5885
+ return pipeUIMessageStreamToResponse({
5874
5886
  response,
5875
5887
  stream: this.toUIMessageStream({
5876
5888
  originalMessages,
@@ -5887,7 +5899,7 @@ var DefaultStreamTextResult = class {
5887
5899
  });
5888
5900
  }
5889
5901
  pipeTextStreamToResponse(response, init) {
5890
- pipeTextStreamToResponse({
5902
+ return pipeTextStreamToResponse({
5891
5903
  response,
5892
5904
  textStream: this.textStream,
5893
5905
  ...init
@@ -8033,7 +8045,7 @@ var DefaultStreamObjectResult = class {
8033
8045
  return createAsyncIterableStream(this.baseStream);
8034
8046
  }
8035
8047
  pipeTextStreamToResponse(response, init) {
8036
- pipeTextStreamToResponse({
8048
+ return pipeTextStreamToResponse({
8037
8049
  response,
8038
8050
  textStream: this.textStream,
8039
8051
  ...init