@ai-sdk/provider-utils 3.0.19 → 3.0.21
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 +18 -0
- package/dist/index.d.mts +49 -2
- package/dist/index.d.ts +49 -2
- package/dist/index.js +188 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +137 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 20565b8: 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
|
+
## 3.0.20
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 526fe8d: fix: trigger new release for `@ai-v5` dist-tag
|
|
18
|
+
- Updated dependencies [526fe8d]
|
|
19
|
+
- @ai-sdk/provider@2.0.1
|
|
20
|
+
|
|
3
21
|
## 3.0.19
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
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
|
*/
|
|
@@ -957,4 +1004,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
957
1004
|
dynamic?: boolean;
|
|
958
1005
|
}
|
|
959
1006
|
|
|
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 };
|
|
1007
|
+
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, 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
|
*/
|
|
@@ -957,4 +1004,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
957
1004
|
dynamic?: boolean;
|
|
958
1005
|
}
|
|
959
1006
|
|
|
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 };
|
|
1007
|
+
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, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|