ai 6.0.83 → 6.0.84

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.84
4
+
5
+ ### Patch Changes
6
+
7
+ - 4024a3a: security: prevent unbounded memory growth in download functions
8
+
9
+ The `download()` and `downloadBlob()` functions now enforce a default 2 GiB size limit when downloading from user-provided URLs. Downloads that exceed this limit are aborted with a `DownloadError` instead of consuming unbounded memory and crashing the process. The `abortSignal` parameter is now passed through to `fetch()` in all download call sites.
10
+
11
+ Added `download` option to `transcribe()` and `experimental_generateVideo()` for providing a custom download function. Use the new `createDownload({ maxBytes })` factory to configure download size limits.
12
+
13
+ - Updated dependencies [4024a3a]
14
+ - @ai-sdk/provider-utils@4.0.15
15
+ - @ai-sdk/gateway@3.0.44
16
+
3
17
  ## 6.0.83
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -4874,6 +4874,23 @@ declare function consumeStream({ stream, onError, }: {
4874
4874
  */
4875
4875
  declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
4876
4876
 
4877
+ /**
4878
+ * Creates a download function with configurable options.
4879
+ *
4880
+ * @param options - Configuration options for the download function.
4881
+ * @param options.maxBytes - Maximum allowed download size in bytes. Default: 2 GiB.
4882
+ * @returns A download function that can be passed to `transcribe()` or `experimental_generateVideo()`.
4883
+ */
4884
+ declare function createDownload(options?: {
4885
+ maxBytes?: number;
4886
+ }): ({ url, abortSignal }: {
4887
+ url: URL;
4888
+ abortSignal?: AbortSignal;
4889
+ }) => Promise<{
4890
+ data: Uint8Array<ArrayBufferLike>;
4891
+ mediaType: string | undefined;
4892
+ }>;
4893
+
4877
4894
  /**
4878
4895
  * Converts a data URL of type text/* to a text string.
4879
4896
  */
@@ -5335,26 +5352,7 @@ type GenerateVideoPrompt = string | {
5335
5352
  image: DataContent;
5336
5353
  text?: string;
5337
5354
  };
5338
- /**
5339
- * Generates videos using a video model.
5340
- *
5341
- * @param model - The video model to use.
5342
- * @param prompt - The prompt that should be used to generate the video.
5343
- * @param n - Number of videos to generate. Default: 1.
5344
- * @param aspectRatio - Aspect ratio of the videos to generate. Must have the format `{width}:{height}`.
5345
- * @param resolution - Resolution of the videos to generate. Must have the format `{width}x{height}`.
5346
- * @param duration - Duration of the video in seconds.
5347
- * @param fps - Frames per second for the video.
5348
- * @param seed - Seed for the video generation.
5349
- * @param providerOptions - Additional provider-specific options that are passed through to the provider
5350
- * as body parameters.
5351
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
5352
- * @param abortSignal - An optional abort signal that can be used to cancel the call.
5353
- * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
5354
- *
5355
- * @returns A result object that contains the generated videos.
5356
- */
5357
- declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
5355
+ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, }: {
5358
5356
  /**
5359
5357
  * The video model to use.
5360
5358
  */
@@ -5411,6 +5409,19 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
5411
5409
  * Only applicable for HTTP-based providers.
5412
5410
  */
5413
5411
  headers?: Record<string, string>;
5412
+ /**
5413
+ * Custom download function for fetching videos from URLs.
5414
+ * Use `createDownload()` from `ai` to create a download function with custom size limits.
5415
+ *
5416
+ * @default createDownload() (2 GiB limit)
5417
+ */
5418
+ download?: (options: {
5419
+ url: URL;
5420
+ abortSignal?: AbortSignal;
5421
+ }) => Promise<{
5422
+ data: Uint8Array;
5423
+ mediaType: string | undefined;
5424
+ }>;
5414
5425
  }): Promise<GenerateVideoResult>;
5415
5426
 
5416
5427
  /**
@@ -5925,20 +5936,7 @@ interface TranscriptionResult {
5925
5936
  readonly providerMetadata: Record<string, JSONObject>;
5926
5937
  }
5927
5938
 
5928
- /**
5929
- * Generates transcripts using a transcription model.
5930
- *
5931
- * @param model - The transcription model to use.
5932
- * @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
5933
- * @param providerOptions - Additional provider-specific options that are passed through to the provider
5934
- * as body parameters.
5935
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
5936
- * @param abortSignal - An optional abort signal that can be used to cancel the call.
5937
- * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
5938
- *
5939
- * @returns A result object that contains the generated transcript.
5940
- */
5941
- declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
5939
+ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, }: {
5942
5940
  /**
5943
5941
  * The transcription model to use.
5944
5942
  */
@@ -5977,6 +5975,19 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
5977
5975
  * Only applicable for HTTP-based providers.
5978
5976
  */
5979
5977
  headers?: Record<string, string>;
5978
+ /**
5979
+ * Custom download function for fetching audio from URLs.
5980
+ * Use `createDownload()` from `ai` to create a download function with custom size limits.
5981
+ *
5982
+ * @default createDownload() (2 GiB limit)
5983
+ */
5984
+ download?: (options: {
5985
+ url: URL;
5986
+ abortSignal?: AbortSignal;
5987
+ }) => Promise<{
5988
+ data: Uint8Array;
5989
+ mediaType: string | undefined;
5990
+ }>;
5980
5991
  }): Promise<TranscriptionResult>;
5981
5992
 
5982
5993
  declare global {
@@ -5999,4 +6010,4 @@ declare global {
5999
6010
  var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
6000
6011
  }
6001
6012
 
6002
- export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
6013
+ export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
package/dist/index.d.ts CHANGED
@@ -4874,6 +4874,23 @@ declare function consumeStream({ stream, onError, }: {
4874
4874
  */
4875
4875
  declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
4876
4876
 
4877
+ /**
4878
+ * Creates a download function with configurable options.
4879
+ *
4880
+ * @param options - Configuration options for the download function.
4881
+ * @param options.maxBytes - Maximum allowed download size in bytes. Default: 2 GiB.
4882
+ * @returns A download function that can be passed to `transcribe()` or `experimental_generateVideo()`.
4883
+ */
4884
+ declare function createDownload(options?: {
4885
+ maxBytes?: number;
4886
+ }): ({ url, abortSignal }: {
4887
+ url: URL;
4888
+ abortSignal?: AbortSignal;
4889
+ }) => Promise<{
4890
+ data: Uint8Array<ArrayBufferLike>;
4891
+ mediaType: string | undefined;
4892
+ }>;
4893
+
4877
4894
  /**
4878
4895
  * Converts a data URL of type text/* to a text string.
4879
4896
  */
@@ -5335,26 +5352,7 @@ type GenerateVideoPrompt = string | {
5335
5352
  image: DataContent;
5336
5353
  text?: string;
5337
5354
  };
5338
- /**
5339
- * Generates videos using a video model.
5340
- *
5341
- * @param model - The video model to use.
5342
- * @param prompt - The prompt that should be used to generate the video.
5343
- * @param n - Number of videos to generate. Default: 1.
5344
- * @param aspectRatio - Aspect ratio of the videos to generate. Must have the format `{width}:{height}`.
5345
- * @param resolution - Resolution of the videos to generate. Must have the format `{width}x{height}`.
5346
- * @param duration - Duration of the video in seconds.
5347
- * @param fps - Frames per second for the video.
5348
- * @param seed - Seed for the video generation.
5349
- * @param providerOptions - Additional provider-specific options that are passed through to the provider
5350
- * as body parameters.
5351
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
5352
- * @param abortSignal - An optional abort signal that can be used to cancel the call.
5353
- * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
5354
- *
5355
- * @returns A result object that contains the generated videos.
5356
- */
5357
- declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
5355
+ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, }: {
5358
5356
  /**
5359
5357
  * The video model to use.
5360
5358
  */
@@ -5411,6 +5409,19 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
5411
5409
  * Only applicable for HTTP-based providers.
5412
5410
  */
5413
5411
  headers?: Record<string, string>;
5412
+ /**
5413
+ * Custom download function for fetching videos from URLs.
5414
+ * Use `createDownload()` from `ai` to create a download function with custom size limits.
5415
+ *
5416
+ * @default createDownload() (2 GiB limit)
5417
+ */
5418
+ download?: (options: {
5419
+ url: URL;
5420
+ abortSignal?: AbortSignal;
5421
+ }) => Promise<{
5422
+ data: Uint8Array;
5423
+ mediaType: string | undefined;
5424
+ }>;
5414
5425
  }): Promise<GenerateVideoResult>;
5415
5426
 
5416
5427
  /**
@@ -5925,20 +5936,7 @@ interface TranscriptionResult {
5925
5936
  readonly providerMetadata: Record<string, JSONObject>;
5926
5937
  }
5927
5938
 
5928
- /**
5929
- * Generates transcripts using a transcription model.
5930
- *
5931
- * @param model - The transcription model to use.
5932
- * @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
5933
- * @param providerOptions - Additional provider-specific options that are passed through to the provider
5934
- * as body parameters.
5935
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
5936
- * @param abortSignal - An optional abort signal that can be used to cancel the call.
5937
- * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
5938
- *
5939
- * @returns A result object that contains the generated transcript.
5940
- */
5941
- declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
5939
+ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, }: {
5942
5940
  /**
5943
5941
  * The transcription model to use.
5944
5942
  */
@@ -5977,6 +5975,19 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
5977
5975
  * Only applicable for HTTP-based providers.
5978
5976
  */
5979
5977
  headers?: Record<string, string>;
5978
+ /**
5979
+ * Custom download function for fetching audio from URLs.
5980
+ * Use `createDownload()` from `ai` to create a download function with custom size limits.
5981
+ *
5982
+ * @default createDownload() (2 GiB limit)
5983
+ */
5984
+ download?: (options: {
5985
+ url: URL;
5986
+ abortSignal?: AbortSignal;
5987
+ }) => Promise<{
5988
+ data: Uint8Array;
5989
+ mediaType: string | undefined;
5990
+ }>;
5980
5991
  }): Promise<TranscriptionResult>;
5981
5992
 
5982
5993
  declare global {
@@ -5999,4 +6010,4 @@ declare global {
5999
6010
  var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
6000
6011
  }
6001
6012
 
6002
- export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
6013
+ export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
package/dist/index.js CHANGED
@@ -77,6 +77,7 @@ __export(src_exports, {
77
77
  cosineSimilarity: () => cosineSimilarity,
78
78
  createAgentUIStream: () => createAgentUIStream,
79
79
  createAgentUIStreamResponse: () => createAgentUIStreamResponse,
80
+ createDownload: () => createDownload,
80
81
  createGateway: () => import_gateway3.createGateway,
81
82
  createIdGenerator: () => import_provider_utils39.createIdGenerator,
82
83
  createProviderRegistry: () => createProviderRegistry,
@@ -1210,10 +1211,14 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1210
1211
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1211
1212
 
1212
1213
  // src/version.ts
1213
- var VERSION = true ? "6.0.83" : "0.0.0-test";
1214
+ var VERSION = true ? "6.0.84" : "0.0.0-test";
1214
1215
 
1215
1216
  // src/util/download/download.ts
1216
- var download = async ({ url }) => {
1217
+ var download = async ({
1218
+ url,
1219
+ maxBytes,
1220
+ abortSignal
1221
+ }) => {
1217
1222
  var _a21;
1218
1223
  const urlText = url.toString();
1219
1224
  try {
@@ -1222,7 +1227,8 @@ var download = async ({ url }) => {
1222
1227
  {},
1223
1228
  `ai-sdk/${VERSION}`,
1224
1229
  (0, import_provider_utils4.getRuntimeEnvironmentUserAgent)()
1225
- )
1230
+ ),
1231
+ signal: abortSignal
1226
1232
  });
1227
1233
  if (!response.ok) {
1228
1234
  throw new import_provider_utils3.DownloadError({
@@ -1231,8 +1237,13 @@ var download = async ({ url }) => {
1231
1237
  statusText: response.statusText
1232
1238
  });
1233
1239
  }
1240
+ const data = await (0, import_provider_utils3.readResponseWithSizeLimit)({
1241
+ response,
1242
+ url: urlText,
1243
+ maxBytes: maxBytes != null ? maxBytes : import_provider_utils3.DEFAULT_MAX_DOWNLOAD_SIZE
1244
+ });
1234
1245
  return {
1235
- data: new Uint8Array(await response.arrayBuffer()),
1246
+ data,
1236
1247
  mediaType: (_a21 = response.headers.get("content-type")) != null ? _a21 : void 0
1237
1248
  };
1238
1249
  } catch (error) {
@@ -9939,6 +9950,11 @@ function cosineSimilarity(vector1, vector2) {
9939
9950
  return magnitudeSquared1 === 0 || magnitudeSquared2 === 0 ? 0 : dotProduct / (Math.sqrt(magnitudeSquared1) * Math.sqrt(magnitudeSquared2));
9940
9951
  }
9941
9952
 
9953
+ // src/util/download/create-download.ts
9954
+ function createDownload(options) {
9955
+ return ({ url, abortSignal }) => download({ url, maxBytes: options == null ? void 0 : options.maxBytes, abortSignal });
9956
+ }
9957
+
9942
9958
  // src/util/data-url.ts
9943
9959
  function getTextFromDataUrl(dataUrl) {
9944
9960
  const [header, base64Content] = dataUrl.split(",");
@@ -10845,6 +10861,7 @@ function smoothStream({
10845
10861
 
10846
10862
  // src/generate-video/generate-video.ts
10847
10863
  var import_provider_utils33 = require("@ai-sdk/provider-utils");
10864
+ var defaultDownload = createDownload();
10848
10865
  async function experimental_generateVideo({
10849
10866
  model: modelArg,
10850
10867
  prompt: promptArg,
@@ -10858,7 +10875,8 @@ async function experimental_generateVideo({
10858
10875
  providerOptions,
10859
10876
  maxRetries: maxRetriesArg,
10860
10877
  abortSignal,
10861
- headers
10878
+ headers,
10879
+ download: downloadFn = defaultDownload
10862
10880
  }) {
10863
10881
  var _a21;
10864
10882
  const model = resolveVideoModel(modelArg);
@@ -10904,8 +10922,9 @@ async function experimental_generateVideo({
10904
10922
  for (const videoData of result.videos) {
10905
10923
  switch (videoData.type) {
10906
10924
  case "url": {
10907
- const { data, mediaType: downloadedMediaType } = await download({
10908
- url: new URL(videoData.url)
10925
+ const { data, mediaType: downloadedMediaType } = await downloadFn({
10926
+ url: new URL(videoData.url),
10927
+ abortSignal
10909
10928
  });
10910
10929
  const isUsableMediaType = (type) => !!type && type !== "application/octet-stream";
10911
10930
  const mediaType = isUsableMediaType(videoData.mediaType) && videoData.mediaType || isUsableMediaType(downloadedMediaType) && downloadedMediaType || detectMediaType({
@@ -12063,13 +12082,15 @@ var DefaultRerankResult = class {
12063
12082
 
12064
12083
  // src/transcribe/transcribe.ts
12065
12084
  var import_provider_utils34 = require("@ai-sdk/provider-utils");
12085
+ var defaultDownload2 = createDownload();
12066
12086
  async function transcribe({
12067
12087
  model,
12068
12088
  audio,
12069
12089
  providerOptions = {},
12070
12090
  maxRetries: maxRetriesArg,
12071
12091
  abortSignal,
12072
- headers
12092
+ headers,
12093
+ download: downloadFn = defaultDownload2
12073
12094
  }) {
12074
12095
  const resolvedModel = resolveTranscriptionModel(model);
12075
12096
  if (!resolvedModel) {
@@ -12083,7 +12104,7 @@ async function transcribe({
12083
12104
  headers != null ? headers : {},
12084
12105
  `ai/${VERSION}`
12085
12106
  );
12086
- const audioData = audio instanceof URL ? (await download({ url: audio })).data : convertDataContentToUint8Array(audio);
12107
+ const audioData = audio instanceof URL ? (await downloadFn({ url: audio, abortSignal })).data : convertDataContentToUint8Array(audio);
12087
12108
  const result = await retry(
12088
12109
  () => {
12089
12110
  var _a21;
@@ -12996,6 +13017,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
12996
13017
  cosineSimilarity,
12997
13018
  createAgentUIStream,
12998
13019
  createAgentUIStreamResponse,
13020
+ createDownload,
12999
13021
  createGateway,
13000
13022
  createIdGenerator,
13001
13023
  createProviderRegistry,