@ai-sdk/provider-utils 5.0.46 → 5.0.49

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.d.ts CHANGED
@@ -1038,6 +1038,20 @@ declare class DownloadError extends AISDKError {
1038
1038
  * embedding model specification.
1039
1039
  */
1040
1040
  declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
1041
+ /**
1042
+ * Symbol for transforming provider options for an automatically batched
1043
+ * embedding model call.
1044
+ *
1045
+ * This capability is experimental and intentionally lives outside the versioned
1046
+ * embedding model specification.
1047
+ */
1048
+ declare const EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER: unique symbol;
1049
+ type EmbeddingModelProviderOptionsTransformer = (options: {
1050
+ providerOptions: SharedV4ProviderOptions | undefined;
1051
+ values: Array<string>;
1052
+ startIndex: number;
1053
+ endIndex: number;
1054
+ }) => SharedV4ProviderOptions | undefined | PromiseLike<SharedV4ProviderOptions | undefined>;
1041
1055
 
1042
1056
  /**
1043
1057
  * Fetches one validated URL without following redirects.
@@ -1070,6 +1084,9 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
1070
1084
  * Request headers are also protected: {@link sanitizeRequestHeaders} strips
1071
1085
  * proxy/metadata/cookie/hop-by-hop headers before the first request, and all
1072
1086
  * caller headers except `User-Agent` are dropped on a cross-origin redirect.
1087
+ * Credentials and custom headers are preserved on the first hop for backwards
1088
+ * compatibility. The caller must ensure that the initial URL may receive them.
1089
+ * Use `fetchUntrustedUrl` for URLs that require first-hop credential isolation.
1073
1090
  * The fetch spec only strips `Authorization` on cross-origin redirects because
1074
1091
  * in a browser, CORS preflighting protects custom headers; there is no CORS on
1075
1092
  * the server, so provider API keys carried in custom headers (e.g. `x-key`)
@@ -1140,6 +1157,41 @@ declare function extractResponseHeaders(response: Response): {
1140
1157
  [k: string]: string;
1141
1158
  };
1142
1159
 
1160
+ /**
1161
+ * Fetches an untrusted URL with first-hop credential isolation and validated
1162
+ * redirects. Uses the URL validation, DNS-pinned Node.js transport, redirect
1163
+ * limits, and cross-origin header stripping of {@link fetchWithValidatedRedirects}.
1164
+ * An injected fetch must provide equivalent connect-time DNS validation.
1165
+ *
1166
+ * Without a matching `credentialedOrigin` (or `trustedOrigin` when it is
1167
+ * omitted), only allowlisted request metadata is sent on the first hop.
1168
+ * Arbitrary caller headers require an explicit matching origin because vendor
1169
+ * credential names cannot be inferred safely. Proxy, metadata, cookie, and
1170
+ * hop-by-hop headers are sanitized even for a matching origin.
1171
+ *
1172
+ * `trustedOrigin` also exempts same-origin hops from URL validation, allowing
1173
+ * developer-configured private endpoints. Both origin options must come from
1174
+ * developer configuration, never from untrusted response data.
1175
+ *
1176
+ * This is an opt-in alternative to `fetchWithValidatedRedirects`, whose
1177
+ * existing first-hop header behavior is preserved for compatibility.
1178
+ */
1179
+ declare function fetchUntrustedUrl({ headers, credentialedOrigin, untrustedFirstHopHeaders, ...options }: Parameters<typeof fetchWithValidatedRedirects>[0] & {
1180
+ /**
1181
+ * The developer-configured origin allowed to receive arbitrary caller
1182
+ * headers on the first hop. Defaults to `trustedOrigin` when omitted.
1183
+ * An explicit value takes precedence over `trustedOrigin` and does not
1184
+ * exempt the URL from validation.
1185
+ */
1186
+ credentialedOrigin?: string;
1187
+ /**
1188
+ * Additional sanitized header names safe to disclose to an untrusted first
1189
+ * hop. Use only for non-credential protocol metadata. Credentials require
1190
+ * a matching `credentialedOrigin` instead. Names are case-insensitive.
1191
+ */
1192
+ untrustedFirstHopHeaders?: readonly string[];
1193
+ }): Promise<Response>;
1194
+
1143
1195
  /**
1144
1196
  * Filters `null` and `undefined` values out of a list of values.
1145
1197
  *
@@ -1294,11 +1346,11 @@ declare function isRecord(value: unknown): value is Record<string, unknown>;
1294
1346
  /**
1295
1347
  * Checks if the given URL is supported natively by the model.
1296
1348
  *
1297
- * @param mediaType - The media type of the URL. Case-sensitive. May be a full
1349
+ * @param mediaType - The media type of the URL. Case-insensitive. May be a full
1298
1350
  * `type/subtype`, a wildcard `type/*`, or just the
1299
1351
  * top-level segment (e.g. `image`).
1300
1352
  * @param url - The URL to check.
1301
- * @param supportedUrls - A record where keys are case-sensitive media types (or '*')
1353
+ * @param supportedUrls - A record where keys are case-insensitive media types (or '*')
1302
1354
  * and values are arrays of RegExp patterns for URLs.
1303
1355
  *
1304
1356
  * @returns `true` if the URL matches a pattern under the specific media type
@@ -1560,6 +1612,13 @@ type ToolApprovalRequest = {
1560
1612
  * Present only when `experimental_toolApprovalSecret` is configured.
1561
1613
  */
1562
1614
  signature?: string;
1615
+ /**
1616
+ * Tool input before input schema validation and transformation.
1617
+ *
1618
+ * This is included when it differs from the validated tool input so that
1619
+ * approved tool calls can be safely revalidated before execution.
1620
+ */
1621
+ inputSchemaInput?: unknown;
1563
1622
  };
1564
1623
 
1565
1624
  /**
@@ -2822,4 +2881,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
2822
2881
  dynamic?: boolean;
2823
2882
  }
2824
2883
 
2825
- export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, 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 ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, 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 MultipartStreamPart, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ProviderStreamError, 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, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, deleteFromApi, detectMediaType, downloadBlob, dynamicTool, executeTool, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isProviderStreamError, isRecord, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
2884
+ export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, 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 EmbeddingModelProviderOptionsTransformer, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, 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 MultipartStreamPart, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ProviderStreamError, 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, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, deleteFromApi, detectMediaType, downloadBlob, dynamicTool, executeTool, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchUntrustedUrl, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isProviderStreamError, isRecord, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };