@ai-sdk/provider-utils 3.0.20 → 3.0.22

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,11 +1,28 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.22
4
+
5
+ ### Patch Changes
6
+
7
+ - 6a2f01b: Add URL validation to `download` to prevent blind SSRF attacks. Private/internal IP addresses, localhost, and non-HTTP protocols are now rejected before fetching.
8
+ - 17d64e3: fix(provider-utils): prevent unicode escape bypass in secureJsonParse
9
+
10
+ ## 3.0.21
11
+
12
+ ### Patch Changes
13
+
14
+ - 20565b8: security: prevent unbounded memory growth in download functions
15
+
16
+ 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.
17
+
18
+ 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.
19
+
3
20
  ## 3.0.20
4
21
 
5
22
  ### Patch Changes
6
23
 
7
- - 4953414: fix: trigger new release for `@ai-v5` dist-tag
8
- - Updated dependencies [4953414]
24
+ - 526fe8d: fix: trigger new release for `@ai-v5` dist-tag
25
+ - Updated dependencies [526fe8d]
9
26
  - @ai-sdk/provider@2.0.1
10
27
 
11
28
  ## 3.0.19
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
1
+ import { AISDKError, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
2
2
  import * as z4 from 'zod/v4';
3
3
  import { ZodType } from 'zod/v4';
4
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -56,6 +56,53 @@ declare function extractResponseHeaders(response: Response): {
56
56
  [k: string]: string;
57
57
  };
58
58
 
59
+ declare const symbol: unique symbol;
60
+ declare class DownloadError extends AISDKError {
61
+ private readonly [symbol];
62
+ readonly url: string;
63
+ readonly statusCode?: number;
64
+ readonly statusText?: string;
65
+ constructor({ url, statusCode, statusText, cause, message, }: {
66
+ url: string;
67
+ statusCode?: number;
68
+ statusText?: string;
69
+ message?: string;
70
+ cause?: unknown;
71
+ });
72
+ static isInstance(error: unknown): error is DownloadError;
73
+ }
74
+
75
+ /**
76
+ * Default maximum download size: 2 GiB.
77
+ *
78
+ * `fetch().arrayBuffer()` has ~2x peak memory overhead (undici buffers the
79
+ * body internally, then creates the JS ArrayBuffer), so very large downloads
80
+ * risk exceeding the default V8 heap limit on 64-bit systems and terminating
81
+ * the process with an out-of-memory error.
82
+ *
83
+ * Setting this limit converts an unrecoverable OOM crash into a catchable
84
+ * `DownloadError`.
85
+ */
86
+ declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
87
+ /**
88
+ * Reads a fetch Response body with a size limit to prevent memory exhaustion.
89
+ *
90
+ * Checks the Content-Length header for early rejection, then reads the body
91
+ * incrementally via ReadableStream and aborts with a DownloadError when the
92
+ * limit is exceeded.
93
+ *
94
+ * @param response - The fetch Response to read.
95
+ * @param url - The URL being downloaded (used in error messages).
96
+ * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
97
+ * @returns A Uint8Array containing the response body.
98
+ * @throws DownloadError if the response exceeds maxBytes.
99
+ */
100
+ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
101
+ response: Response;
102
+ url: string;
103
+ maxBytes?: number;
104
+ }): Promise<Uint8Array>;
105
+
59
106
  /**
60
107
  * Fetch function type (standardizes the version of fetch used).
61
108
  */
@@ -825,6 +872,15 @@ declare function convertBase64ToUint8Array(base64String: string): Uint8Array<Arr
825
872
  declare function convertUint8ArrayToBase64(array: Uint8Array): string;
826
873
  declare function convertToBase64(value: string | Uint8Array): string;
827
874
 
875
+ /**
876
+ * Validates that a URL is safe to download from, blocking private/internal addresses
877
+ * to prevent SSRF attacks.
878
+ *
879
+ * @param url - The URL string to validate.
880
+ * @throws DownloadError if the URL is unsafe.
881
+ */
882
+ declare function validateDownloadUrl(url: string): void;
883
+
828
884
  /**
829
885
  * Validates the types of an unknown object using a schema and
830
886
  * return a strongly-typed object.
@@ -957,4 +1013,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
957
1013
  dynamic?: boolean;
958
1014
  }
959
1015
 
960
- export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1016
+ export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
1
+ import { AISDKError, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
2
2
  import * as z4 from 'zod/v4';
3
3
  import { ZodType } from 'zod/v4';
4
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -56,6 +56,53 @@ declare function extractResponseHeaders(response: Response): {
56
56
  [k: string]: string;
57
57
  };
58
58
 
59
+ declare const symbol: unique symbol;
60
+ declare class DownloadError extends AISDKError {
61
+ private readonly [symbol];
62
+ readonly url: string;
63
+ readonly statusCode?: number;
64
+ readonly statusText?: string;
65
+ constructor({ url, statusCode, statusText, cause, message, }: {
66
+ url: string;
67
+ statusCode?: number;
68
+ statusText?: string;
69
+ message?: string;
70
+ cause?: unknown;
71
+ });
72
+ static isInstance(error: unknown): error is DownloadError;
73
+ }
74
+
75
+ /**
76
+ * Default maximum download size: 2 GiB.
77
+ *
78
+ * `fetch().arrayBuffer()` has ~2x peak memory overhead (undici buffers the
79
+ * body internally, then creates the JS ArrayBuffer), so very large downloads
80
+ * risk exceeding the default V8 heap limit on 64-bit systems and terminating
81
+ * the process with an out-of-memory error.
82
+ *
83
+ * Setting this limit converts an unrecoverable OOM crash into a catchable
84
+ * `DownloadError`.
85
+ */
86
+ declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
87
+ /**
88
+ * Reads a fetch Response body with a size limit to prevent memory exhaustion.
89
+ *
90
+ * Checks the Content-Length header for early rejection, then reads the body
91
+ * incrementally via ReadableStream and aborts with a DownloadError when the
92
+ * limit is exceeded.
93
+ *
94
+ * @param response - The fetch Response to read.
95
+ * @param url - The URL being downloaded (used in error messages).
96
+ * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
97
+ * @returns A Uint8Array containing the response body.
98
+ * @throws DownloadError if the response exceeds maxBytes.
99
+ */
100
+ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
101
+ response: Response;
102
+ url: string;
103
+ maxBytes?: number;
104
+ }): Promise<Uint8Array>;
105
+
59
106
  /**
60
107
  * Fetch function type (standardizes the version of fetch used).
61
108
  */
@@ -825,6 +872,15 @@ declare function convertBase64ToUint8Array(base64String: string): Uint8Array<Arr
825
872
  declare function convertUint8ArrayToBase64(array: Uint8Array): string;
826
873
  declare function convertToBase64(value: string | Uint8Array): string;
827
874
 
875
+ /**
876
+ * Validates that a URL is safe to download from, blocking private/internal addresses
877
+ * to prevent SSRF attacks.
878
+ *
879
+ * @param url - The URL string to validate.
880
+ * @throws DownloadError if the URL is unsafe.
881
+ */
882
+ declare function validateDownloadUrl(url: string): void;
883
+
828
884
  /**
829
885
  * Validates the types of an unknown object using a schema and
830
886
  * return a strongly-typed object.
@@ -957,4 +1013,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
957
1013
  dynamic?: boolean;
958
1014
  }
959
1015
 
960
- export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1016
+ export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };