ai 4.3.2 → 4.3.3

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
@@ -861,8 +861,8 @@ var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
861
861
  }
862
862
  };
863
863
 
864
- // core/util/detect-image-mimetype.ts
865
- var mimeTypeSignatures = [
864
+ // core/util/detect-mimetype.ts
865
+ var imageMimeTypeSignatures = [
866
866
  {
867
867
  mimeType: "image/gif",
868
868
  bytesPrefix: [71, 73, 70],
@@ -935,9 +935,44 @@ var mimeTypeSignatures = [
935
935
  base64Prefix: "AAAAIGZ0eXBoZWlj"
936
936
  }
937
937
  ];
938
- function detectImageMimeType(image) {
939
- for (const signature of mimeTypeSignatures) {
940
- if (typeof image === "string" ? image.startsWith(signature.base64Prefix) : image.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => image[index] === byte)) {
938
+ var audioMimeTypeSignatures = [
939
+ {
940
+ mimeType: "audio/mpeg",
941
+ bytesPrefix: [255, 251],
942
+ base64Prefix: "//s="
943
+ },
944
+ {
945
+ mimeType: "audio/wav",
946
+ bytesPrefix: [82, 73, 70, 70],
947
+ base64Prefix: "UklGR"
948
+ },
949
+ {
950
+ mimeType: "audio/ogg",
951
+ bytesPrefix: [79, 103, 103, 83],
952
+ base64Prefix: "T2dnUw"
953
+ },
954
+ {
955
+ mimeType: "audio/flac",
956
+ bytesPrefix: [102, 76, 97, 67],
957
+ base64Prefix: "ZkxhQw"
958
+ },
959
+ {
960
+ mimeType: "audio/aac",
961
+ bytesPrefix: [64, 21, 0, 0],
962
+ base64Prefix: "QBUA"
963
+ },
964
+ {
965
+ mimeType: "audio/mp4",
966
+ bytesPrefix: [102, 116, 121, 112],
967
+ base64Prefix: "ZnR5cA"
968
+ }
969
+ ];
970
+ function detectMimeType({
971
+ data,
972
+ signatures
973
+ }) {
974
+ for (const signature of signatures) {
975
+ if (typeof data === "string" ? data.startsWith(signature.base64Prefix) : data.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => data[index] === byte)) {
941
976
  return signature.mimeType;
942
977
  }
943
978
  }
@@ -994,7 +1029,10 @@ async function generateImage({
994
1029
  var _a18;
995
1030
  return new DefaultGeneratedFile({
996
1031
  data: image,
997
- mimeType: (_a18 = detectImageMimeType(image)) != null ? _a18 : "image/png"
1032
+ mimeType: (_a18 = detectMimeType({
1033
+ data: image,
1034
+ signatures: imageMimeTypeSignatures
1035
+ })) != null ? _a18 : "image/png"
998
1036
  });
999
1037
  }
1000
1038
  )
@@ -1429,7 +1467,10 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1429
1467
  switch (type) {
1430
1468
  case "image": {
1431
1469
  if (normalizedData instanceof Uint8Array) {
1432
- mimeType = (_b = detectImageMimeType(normalizedData)) != null ? _b : mimeType;
1470
+ mimeType = (_b = detectMimeType({
1471
+ data: normalizedData,
1472
+ signatures: imageMimeTypeSignatures
1473
+ })) != null ? _b : mimeType;
1433
1474
  }
1434
1475
  return {
1435
1476
  type: "image",
@@ -6241,6 +6282,70 @@ var DefaultStreamTextResult = class {
6241
6282
  }
6242
6283
  };
6243
6284
 
6285
+ // errors/no-transcript-generated-error.ts
6286
+ import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
6287
+ var NoTranscriptGeneratedError = class extends AISDKError18 {
6288
+ constructor(options) {
6289
+ super({
6290
+ name: "AI_NoTranscriptGeneratedError",
6291
+ message: "No transcript generated."
6292
+ });
6293
+ this.responses = options.responses;
6294
+ }
6295
+ };
6296
+
6297
+ // core/transcribe/transcribe.ts
6298
+ async function transcribe({
6299
+ model,
6300
+ audio,
6301
+ providerOptions = {},
6302
+ maxRetries: maxRetriesArg,
6303
+ abortSignal,
6304
+ headers
6305
+ }) {
6306
+ const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
6307
+ const audioData = audio instanceof URL ? new Uint8Array((await download({ url: audio })).data) : convertDataContentToUint8Array(audio);
6308
+ const result = await retry(
6309
+ () => {
6310
+ var _a17;
6311
+ return model.doGenerate({
6312
+ audio: audioData,
6313
+ abortSignal,
6314
+ headers,
6315
+ providerOptions,
6316
+ mimeType: (_a17 = detectMimeType({
6317
+ data: audioData,
6318
+ signatures: audioMimeTypeSignatures
6319
+ })) != null ? _a17 : "audio/wav"
6320
+ });
6321
+ }
6322
+ );
6323
+ if (!result.text) {
6324
+ throw new NoTranscriptGeneratedError({ responses: [result.response] });
6325
+ }
6326
+ return new DefaultTranscriptionResult({
6327
+ text: result.text,
6328
+ segments: result.segments,
6329
+ language: result.language,
6330
+ durationInSeconds: result.durationInSeconds,
6331
+ warnings: result.warnings,
6332
+ responses: [result.response],
6333
+ providerMetadata: result.providerMetadata
6334
+ });
6335
+ }
6336
+ var DefaultTranscriptionResult = class {
6337
+ constructor(options) {
6338
+ var _a17;
6339
+ this.text = options.text;
6340
+ this.segments = options.segments;
6341
+ this.language = options.language;
6342
+ this.durationInSeconds = options.durationInSeconds;
6343
+ this.warnings = options.warnings;
6344
+ this.responses = options.responses;
6345
+ this.providerMetadata = (_a17 = options.providerMetadata) != null ? _a17 : {};
6346
+ }
6347
+ };
6348
+
6244
6349
  // core/util/merge-objects.ts
6245
6350
  function mergeObjects(target, source) {
6246
6351
  if (target === void 0 && source === void 0) {
@@ -6558,7 +6663,7 @@ function appendClientMessage({
6558
6663
  import {
6559
6664
  extractMaxToolInvocationStep
6560
6665
  } from "@ai-sdk/ui-utils";
6561
- import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
6666
+ import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
6562
6667
  function appendResponseMessages({
6563
6668
  messages,
6564
6669
  responseMessages,
@@ -6641,7 +6746,7 @@ function appendResponseMessages({
6641
6746
  break;
6642
6747
  case "file":
6643
6748
  if (part.data instanceof URL) {
6644
- throw new AISDKError18({
6749
+ throw new AISDKError19({
6645
6750
  name: "InvalidAssistantFileData",
6646
6751
  message: "File data cannot be a URL"
6647
6752
  });
@@ -6775,7 +6880,7 @@ function customProvider({
6775
6880
  var experimental_customProvider = customProvider;
6776
6881
 
6777
6882
  // core/registry/no-such-provider-error.ts
6778
- import { AISDKError as AISDKError19, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
6883
+ import { AISDKError as AISDKError20, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
6779
6884
  var name16 = "AI_NoSuchProviderError";
6780
6885
  var marker16 = `vercel.ai.error.${name16}`;
6781
6886
  var symbol16 = Symbol.for(marker16);
@@ -6794,7 +6899,7 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
6794
6899
  this.availableProviders = availableProviders;
6795
6900
  }
6796
6901
  static isInstance(error) {
6797
- return AISDKError19.hasMarker(error, marker16);
6902
+ return AISDKError20.hasMarker(error, marker16);
6798
6903
  }
6799
6904
  };
6800
6905
  _a16 = symbol16;
@@ -7878,6 +7983,7 @@ export {
7878
7983
  experimental_createProviderRegistry,
7879
7984
  experimental_customProvider,
7880
7985
  generateImage as experimental_generateImage,
7986
+ transcribe as experimental_transcribe,
7881
7987
  experimental_wrapLanguageModel,
7882
7988
  extractReasoningMiddleware,
7883
7989
  formatAssistantStreamPart,