@ai-sdk/provider-utils 5.0.38 → 5.0.40

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,22 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 5.0.40
4
+
5
+ ### Patch Changes
6
+
7
+ - 813bb36: fix(provider-utils): avoid detecting plain text prefixes as BMP or GIF images
8
+ - c43e4b7: fix(mcp): prevent SSRF in OAuth metadata discovery
9
+ - Updated dependencies [5ec21a6]
10
+ - Updated dependencies [7469a3b]
11
+ - @ai-sdk/provider@4.0.14
12
+
13
+ ## 5.0.39
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [9942196]
18
+ - @ai-sdk/provider@4.0.13
19
+
3
20
  ## 5.0.38
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1039,6 +1039,25 @@ declare class DownloadError extends AISDKError {
1039
1039
  */
1040
1040
  declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
1041
1041
 
1042
+ /**
1043
+ * Fetches one validated URL without following redirects.
1044
+ *
1045
+ * On Node.js, the default fetch validates and pins DNS results at connect time.
1046
+ * An injected fetch is responsible for equivalent connect-time validation.
1047
+ * Redirects are rejected by default. Callers using `redirect: 'manual'` must
1048
+ * validate the Location target before issuing another request.
1049
+ */
1050
+ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
1051
+ url: string | URL;
1052
+ init?: RequestInit;
1053
+ fetch?: FetchFunction;
1054
+ /**
1055
+ * A developer-configured origin that may legitimately resolve to a private
1056
+ * address. This must never be derived from untrusted response data.
1057
+ */
1058
+ trustedOrigin?: string;
1059
+ redirect?: 'error' | 'manual';
1060
+ }): Promise<Response>;
1042
1061
  /**
1043
1062
  * Fetches a URL while enforcing the download guard on every hop.
1044
1063
  *
@@ -2788,4 +2807,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
2788
2807
  dynamic?: boolean;
2789
2808
  }
2790
2809
 
2791
- 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, 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 };
2810
+ 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 };
package/dist/index.js CHANGED
@@ -518,7 +518,7 @@ function handleFetchError({
518
518
  }
519
519
 
520
520
  // src/version.ts
521
- var VERSION = true ? "5.0.38" : "0.0.0-test";
521
+ var VERSION = true ? "5.0.40" : "0.0.0-test";
522
522
 
523
523
  // src/normalize-headers.ts
524
524
  function normalizeHeaders(headers) {
@@ -628,8 +628,13 @@ var deleteFromApi = async ({
628
628
  var imageMediaTypeSignatures = [
629
629
  {
630
630
  mediaType: "image/gif",
631
- bytesPrefix: [71, 73, 70]
632
- // GIF
631
+ bytesPrefix: [71, 73, 70, 56, 55, 97]
632
+ // GIF87a
633
+ },
634
+ {
635
+ mediaType: "image/gif",
636
+ bytesPrefix: [71, 73, 70, 56, 57, 97]
637
+ // GIF89a
633
638
  },
634
639
  {
635
640
  mediaType: "image/png",
@@ -663,7 +668,7 @@ var imageMediaTypeSignatures = [
663
668
  },
664
669
  {
665
670
  mediaType: "image/bmp",
666
- bytesPrefix: [66, 77]
671
+ bytesPrefix: [66, 77, null, null, null, null, 0, 0, 0, 0]
667
672
  },
668
673
  {
669
674
  mediaType: "image/tiff",
@@ -1266,6 +1271,27 @@ function sanitizeRequestHeaders(input) {
1266
1271
  // src/fetch-with-validated-redirects.ts
1267
1272
  var MAX_DOWNLOAD_REDIRECTS = 10;
1268
1273
  var REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
1274
+ async function getValidatedFetch(customFetch) {
1275
+ return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
1276
+ }
1277
+ async function fetchWithValidatedEndpoint({
1278
+ url,
1279
+ init,
1280
+ fetch: customFetch,
1281
+ trustedOrigin,
1282
+ redirect = "error"
1283
+ }) {
1284
+ const urlText = url.toString();
1285
+ const isTrusted = trustedOrigin !== void 0 && isSameOrigin(urlText, trustedOrigin);
1286
+ if (!isTrusted) {
1287
+ validateDownloadUrl(urlText);
1288
+ }
1289
+ const fetch = isTrusted && customFetch != null ? customFetch : isTrusted ? globalThis.fetch : await getValidatedFetch(customFetch);
1290
+ return await fetch(url, {
1291
+ ...init,
1292
+ redirect
1293
+ });
1294
+ }
1269
1295
  async function fetchWithValidatedRedirects({
1270
1296
  url,
1271
1297
  headers,
@@ -1274,6 +1300,7 @@ async function fetchWithValidatedRedirects({
1274
1300
  fetch: customFetch,
1275
1301
  trustedOrigin
1276
1302
  }) {
1303
+ var _a3;
1277
1304
  let currentHeaders = headers === void 0 ? void 0 : sanitizeRequestHeaders(headers);
1278
1305
  const perHopInit = (redirect) => {
1279
1306
  const init = { signal: abortSignal, redirect };
@@ -1288,7 +1315,7 @@ async function fetchWithValidatedRedirects({
1288
1315
  if (!isTrustedHop) {
1289
1316
  validateDownloadUrl(currentUrl);
1290
1317
  }
1291
- const fetch = customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getDefaultDownloadFetch();
1318
+ const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
1292
1319
  const response = await fetch(currentUrl, perHopInit("manual"));
1293
1320
  if (response.type === "opaqueredirect") {
1294
1321
  if (!isBrowserRuntime()) {
@@ -1299,7 +1326,7 @@ async function fetchWithValidatedRedirects({
1299
1326
  }
1300
1327
  return await fetch(currentUrl, perHopInit("follow"));
1301
1328
  }
1302
- const location = response.headers.get("location");
1329
+ const location = (_a3 = response.headers) == null ? void 0 : _a3.get("location");
1303
1330
  if (REDIRECT_STATUS_CODES.has(response.status) && location) {
1304
1331
  await cancelResponseBody(response);
1305
1332
  const nextUrl = new URL(location, currentUrl).toString();
@@ -4590,6 +4617,7 @@ export {
4590
4617
  toolCaller as experimental_toolCaller,
4591
4618
  extractLines,
4592
4619
  extractResponseHeaders,
4620
+ fetchWithValidatedEndpoint,
4593
4621
  fetchWithValidatedRedirects,
4594
4622
  filterNullable,
4595
4623
  generateId,