@ai-sdk/provider-utils 5.0.13 → 5.0.15

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-sdk/provider-utils
2
2
 
3
+ ## 5.0.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 1659cd5: Prevent validated downloads on Node.js from reaching private or internal services through DNS aliases or DNS rebinding by validating and pinning every resolved address at connection time.
8
+ - 6a5bdff: Fix validated Node.js downloads when the HTTP connector requests a single DNS address.
9
+
10
+ ## 5.0.14
11
+
12
+ ### Patch Changes
13
+
14
+ - 0c464d9: feat(provider-utils): add a typed serialization error
15
+ - c49380c: feat: add experimental streaming speech translation models (`openai.translation('gpt-realtime-translate')` over the OpenAI Realtime translations WebSocket and `google.translation('gemini-3.5-live-translate-preview')` over the Gemini Live API). `connectToWebSocket` in `@ai-sdk/provider-utils` now passes close code and reason to `onClose` (additive, optional parameter).
16
+
3
17
  ## 5.0.13
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -85,7 +85,14 @@ declare function connectToWebSocket({ url, protocols, headers, webSocket, abortS
85
85
  /** Constructor throws and message decoding/processing failures. */
86
86
  onProcessingError: (error: unknown) => void;
87
87
  onSocketError?: () => void;
88
- onClose?: () => void;
88
+ /**
89
+ * Receives the close code and reason when the transport provides them
90
+ * (native `CloseEvent` / `ws` close event).
91
+ */
92
+ onClose?: (info: {
93
+ code?: number;
94
+ reason?: string;
95
+ }) => void;
89
96
  /** Also called (without opening a socket) when the signal is already aborted. */
90
97
  onAbort?: (reason: unknown) => void;
91
98
  }): WebSocketConnection;
@@ -793,9 +800,9 @@ declare function downloadBlob(url: string, options?: {
793
800
  abortSignal?: AbortSignal;
794
801
  }): Promise<Blob>;
795
802
 
796
- declare const symbol: unique symbol;
803
+ declare const symbol$1: unique symbol;
797
804
  declare class DownloadError extends AISDKError {
798
- private readonly [symbol];
805
+ private readonly [symbol$1];
799
806
  readonly url: string;
800
807
  readonly statusCode?: number;
801
808
  readonly statusText?: string;
@@ -849,18 +856,16 @@ type FetchFunction = typeof globalThis.fetch;
849
856
  * The returned response is the final (non-redirect) response. The caller is
850
857
  * responsible for checking `response.ok` and reading the body.
851
858
  *
852
- * Not solved here: this does string/literal checks only and does not resolve
853
- * DNS, so a hostname that *resolves* to a private address, and DNS rebinding
854
- * (the resolved IP flipping between validation and connect), are not blocked.
855
- * Server deployments fetching untrusted URLs should constrain egress at the
856
- * network layer or inject a Node `fetch` that pins the resolved IP at connect
857
- * time — those need DNS/socket APIs not available on all target runtimes
858
- * (edge, browser, Bun), so they are intentionally not built in.
859
+ * On Node.js, the default fetch resolves every hostname through a validating
860
+ * lookup hook and passes those exact addresses to the connector, preventing
861
+ * hostname-to-private-IP and DNS-rebinding bypasses. An injected fetch is
862
+ * responsible for equivalent connect-time validation. Other runtimes should
863
+ * constrain egress at the network layer when handling untrusted URLs.
859
864
  *
860
865
  * @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
861
866
  * a redirect cannot be validated on a non-browser runtime.
862
867
  */
863
- declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch, trustedOrigin, }: {
868
+ declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
864
869
  url: string;
865
870
  headers?: HeadersInit;
866
871
  abortSignal?: AbortSignal;
@@ -2216,6 +2221,16 @@ declare function serializeModelOptions<CONFIG extends {
2216
2221
  config: JSONObject;
2217
2222
  };
2218
2223
 
2224
+ declare const symbol: unique symbol;
2225
+ declare class SerializationError extends AISDKError {
2226
+ private readonly [symbol];
2227
+ constructor({ message, cause, }?: {
2228
+ message?: string;
2229
+ cause?: unknown;
2230
+ });
2231
+ static isInstance(error: unknown): error is SerializationError;
2232
+ }
2233
+
2219
2234
  declare function secureJsonParse(text: string): any;
2220
2235
 
2221
2236
  /**
@@ -2406,9 +2421,8 @@ declare function validateBaseURL(baseURL: string | undefined): string | undefine
2406
2421
  * Validates that a URL is safe to download from, blocking private/internal addresses
2407
2422
  * to prevent SSRF attacks.
2408
2423
  *
2409
- * Note: this performs string/literal-IP checks only. It does not resolve DNS, so a
2410
- * hostname that resolves to a private address is not blocked here (see callers, which
2411
- * should additionally constrain egress at the network layer when handling untrusted URLs).
2424
+ * Note: this function performs string/literal-IP checks only. The Node.js
2425
+ * download fetch additionally validates and pins DNS results at connect time.
2412
2426
  *
2413
2427
  * @param url - The URL string to validate.
2414
2428
  * @throws DownloadError if the URL is unsafe.
@@ -2621,4 +2635,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
2621
2635
  dynamic?: boolean;
2622
2636
  }
2623
2637
 
2624
- export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
2638
+ export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, SerializationError, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };