ai 6.0.233 → 6.0.235

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
@@ -1140,25 +1140,37 @@ var videoMediaTypeSignatures = [
1140
1140
  // RIFF (AVI)
1141
1141
  }
1142
1142
  ];
1143
- var stripID3 = (data) => {
1144
- const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
1143
+ var DEFAULT_SNIFF_BYTES = 18;
1144
+ var MAX_SIGNATURE_BYTES = 12;
1145
+ var MAX_ID3_TAG_BYTES = 128 * 1024;
1146
+ var ID3_SCAN_BYTES = MAX_ID3_TAG_BYTES + MAX_SIGNATURE_BYTES;
1147
+ function decodePrefix(data, maxBytes) {
1148
+ if (typeof data !== "string") {
1149
+ return data.length > maxBytes ? data.subarray(0, maxBytes) : data;
1150
+ }
1151
+ const maxChars = Math.ceil(maxBytes / 3) * 4;
1152
+ const bytes = convertBase64ToUint8Array(
1153
+ data.substring(0, Math.min(data.length, maxChars))
1154
+ );
1155
+ return bytes.length > maxBytes ? bytes.subarray(0, maxBytes) : bytes;
1156
+ }
1157
+ function hasID3(bytes) {
1158
+ return bytes.length > 10 && bytes[0] === 73 && // 'I'
1159
+ bytes[1] === 68 && // 'D'
1160
+ bytes[2] === 51;
1161
+ }
1162
+ var stripID3 = (bytes) => {
1145
1163
  const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
1146
- return bytes.slice(id3Size + 10);
1164
+ return bytes.subarray(id3Size + 10);
1147
1165
  };
1148
- function stripID3TagsIfPresent(data) {
1149
- const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
1150
- data[1] === 68 && // 'D'
1151
- data[2] === 51;
1152
- return hasId3 ? stripID3(data) : data;
1153
- }
1154
1166
  function detectMediaType({
1155
1167
  data,
1156
1168
  signatures
1157
1169
  }) {
1158
- const processedData = stripID3TagsIfPresent(data);
1159
- const bytes = typeof processedData === "string" ? convertBase64ToUint8Array(
1160
- processedData.substring(0, Math.min(processedData.length, 24))
1161
- ) : processedData;
1170
+ let bytes = decodePrefix(data, DEFAULT_SNIFF_BYTES);
1171
+ if (hasID3(bytes)) {
1172
+ bytes = stripID3(decodePrefix(data, ID3_SCAN_BYTES));
1173
+ }
1162
1174
  for (const signature of signatures) {
1163
1175
  if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
1164
1176
  (byte, index) => byte === null || bytes[index] === byte
@@ -1181,7 +1193,7 @@ import {
1181
1193
  } from "@ai-sdk/provider-utils";
1182
1194
 
1183
1195
  // src/version.ts
1184
- var VERSION = true ? "6.0.233" : "0.0.0-test";
1196
+ var VERSION = true ? "6.0.235" : "0.0.0-test";
1185
1197
 
1186
1198
  // src/util/download/download.ts
1187
1199
  var download = async ({
@@ -5388,7 +5400,7 @@ function writeToServerResponse({
5388
5400
  response.end();
5389
5401
  }
5390
5402
  };
5391
- read();
5403
+ return read();
5392
5404
  }
5393
5405
 
5394
5406
  // src/text-stream/pipe-text-stream-to-response.ts
@@ -5399,7 +5411,7 @@ function pipeTextStreamToResponse({
5399
5411
  headers,
5400
5412
  textStream
5401
5413
  }) {
5402
- writeToServerResponse({
5414
+ return writeToServerResponse({
5403
5415
  response,
5404
5416
  status,
5405
5417
  statusText,
@@ -6410,7 +6422,7 @@ function pipeUIMessageStreamToResponse({
6410
6422
  sseStream = stream1;
6411
6423
  consumeSseStream({ stream: stream2 });
6412
6424
  }
6413
- writeToServerResponse({
6425
+ return writeToServerResponse({
6414
6426
  response,
6415
6427
  status,
6416
6428
  statusText,
@@ -8649,7 +8661,7 @@ var DefaultStreamTextResult = class {
8649
8661
  onError,
8650
8662
  ...init
8651
8663
  } = {}) {
8652
- pipeUIMessageStreamToResponse({
8664
+ return pipeUIMessageStreamToResponse({
8653
8665
  response,
8654
8666
  stream: this.toUIMessageStream({
8655
8667
  originalMessages,
@@ -8666,7 +8678,7 @@ var DefaultStreamTextResult = class {
8666
8678
  });
8667
8679
  }
8668
8680
  pipeTextStreamToResponse(response, init) {
8669
- pipeTextStreamToResponse({
8681
+ return pipeTextStreamToResponse({
8670
8682
  response,
8671
8683
  textStream: this.textStream,
8672
8684
  ...init
@@ -9703,7 +9715,7 @@ async function pipeAgentUIStreamToResponse({
9703
9715
  consumeSseStream,
9704
9716
  ...options
9705
9717
  }) {
9706
- pipeUIMessageStreamToResponse({
9718
+ return pipeUIMessageStreamToResponse({
9707
9719
  response,
9708
9720
  headers,
9709
9721
  status,
@@ -11671,7 +11683,7 @@ var DefaultStreamObjectResult = class {
11671
11683
  return createAsyncIterableStream(this.baseStream);
11672
11684
  }
11673
11685
  pipeTextStreamToResponse(response, init) {
11674
- pipeTextStreamToResponse({
11686
+ return pipeTextStreamToResponse({
11675
11687
  response,
11676
11688
  textStream: this.textStream,
11677
11689
  ...init