@ai-sdk/provider-utils 3.0.40 → 3.0.41

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,13 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.41
4
+
5
+ ### Patch Changes
6
+
7
+ - 2b1c2df: Keep default Node.js downloads protected by DNS validation and connection pinning when frameworks or instrumentation wrap global fetch before or after the SDK loads.
8
+ - 2b1c2df: fix(mcp): prevent SSRF in OAuth metadata discovery
9
+ - 2b1c2df: fix(provider-utils): make lazy Undici import visible to deployment tracers
10
+
3
11
  ## 3.0.40
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -80,6 +80,30 @@ declare class DownloadError extends AISDKError {
80
80
  */
81
81
  declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
82
82
 
83
+ /**
84
+ * Fetch function type (standardizes the version of fetch used).
85
+ */
86
+ type FetchFunction = typeof globalThis.fetch;
87
+
88
+ /**
89
+ * Fetches one validated URL without following redirects.
90
+ *
91
+ * On Node.js, the default fetch validates and pins DNS results at connect time.
92
+ * An injected fetch is responsible for equivalent connect-time validation.
93
+ * Redirects are rejected by default. Callers using `redirect: 'manual'` must
94
+ * validate the Location target before issuing another request.
95
+ */
96
+ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
97
+ url: string | URL;
98
+ init?: RequestInit;
99
+ fetch?: FetchFunction;
100
+ /**
101
+ * A developer-configured origin that may legitimately resolve to a private
102
+ * address. This must never be derived from untrusted response data.
103
+ */
104
+ trustedOrigin?: string;
105
+ redirect?: 'error' | 'manual';
106
+ }): Promise<Response>;
83
107
  /**
84
108
  * Fetches a URL while enforcing the SSRF download guard on every hop.
85
109
  *
@@ -97,6 +121,13 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
97
121
  * runtime we cannot validate the hop, so we fail closed rather than follow it
98
122
  * blindly and bypass the SSRF guard.
99
123
  *
124
+ * A hop that is same-origin with `trustedOrigin` (the developer-configured
125
+ * endpoint) skips target validation: that origin is exactly what an
126
+ * unvalidated, config-derived request would fetch anyway, and validating it
127
+ * would break legitimate self-hosted / localhost deployments whose response
128
+ * URLs point back at the configured host. Hops on any other origin are always
129
+ * validated.
130
+ *
100
131
  * The returned response is the final (non-redirect) response. The caller is
101
132
  * responsible for checking `response.ok` and reading the body.
102
133
  *
@@ -108,11 +139,17 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
108
139
  * @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
109
140
  * a redirect cannot be validated on a non-browser runtime.
110
141
  */
111
- declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
142
+ declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
112
143
  url: string;
113
144
  headers?: HeadersInit;
114
145
  abortSignal?: AbortSignal;
115
146
  maxRedirects?: number;
147
+ fetch?: FetchFunction;
148
+ /**
149
+ * A developer-configured origin whose hops skip target validation. Must
150
+ * never be derived from response data.
151
+ */
152
+ trustedOrigin?: string;
116
153
  }): Promise<Response>;
117
154
 
118
155
  /**
@@ -156,11 +193,6 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
156
193
  maxBytes?: number;
157
194
  }): Promise<Uint8Array>;
158
195
 
159
- /**
160
- * Fetch function type (standardizes the version of fetch used).
161
- */
162
- type FetchFunction = typeof globalThis.fetch;
163
-
164
196
  /**
165
197
  Creates an ID generator.
166
198
  The total length of the ID is the sum of the prefix, separator, and random part length.
@@ -1165,4 +1197,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1165
1197
  dynamic?: boolean;
1166
1198
  }
1167
1199
 
1168
- export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, 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 StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, 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 };
1200
+ export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, 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 StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, 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
@@ -80,6 +80,30 @@ declare class DownloadError extends AISDKError {
80
80
  */
81
81
  declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
82
82
 
83
+ /**
84
+ * Fetch function type (standardizes the version of fetch used).
85
+ */
86
+ type FetchFunction = typeof globalThis.fetch;
87
+
88
+ /**
89
+ * Fetches one validated URL without following redirects.
90
+ *
91
+ * On Node.js, the default fetch validates and pins DNS results at connect time.
92
+ * An injected fetch is responsible for equivalent connect-time validation.
93
+ * Redirects are rejected by default. Callers using `redirect: 'manual'` must
94
+ * validate the Location target before issuing another request.
95
+ */
96
+ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
97
+ url: string | URL;
98
+ init?: RequestInit;
99
+ fetch?: FetchFunction;
100
+ /**
101
+ * A developer-configured origin that may legitimately resolve to a private
102
+ * address. This must never be derived from untrusted response data.
103
+ */
104
+ trustedOrigin?: string;
105
+ redirect?: 'error' | 'manual';
106
+ }): Promise<Response>;
83
107
  /**
84
108
  * Fetches a URL while enforcing the SSRF download guard on every hop.
85
109
  *
@@ -97,6 +121,13 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
97
121
  * runtime we cannot validate the hop, so we fail closed rather than follow it
98
122
  * blindly and bypass the SSRF guard.
99
123
  *
124
+ * A hop that is same-origin with `trustedOrigin` (the developer-configured
125
+ * endpoint) skips target validation: that origin is exactly what an
126
+ * unvalidated, config-derived request would fetch anyway, and validating it
127
+ * would break legitimate self-hosted / localhost deployments whose response
128
+ * URLs point back at the configured host. Hops on any other origin are always
129
+ * validated.
130
+ *
100
131
  * The returned response is the final (non-redirect) response. The caller is
101
132
  * responsible for checking `response.ok` and reading the body.
102
133
  *
@@ -108,11 +139,17 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
108
139
  * @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
109
140
  * a redirect cannot be validated on a non-browser runtime.
110
141
  */
111
- declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
142
+ declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
112
143
  url: string;
113
144
  headers?: HeadersInit;
114
145
  abortSignal?: AbortSignal;
115
146
  maxRedirects?: number;
147
+ fetch?: FetchFunction;
148
+ /**
149
+ * A developer-configured origin whose hops skip target validation. Must
150
+ * never be derived from response data.
151
+ */
152
+ trustedOrigin?: string;
116
153
  }): Promise<Response>;
117
154
 
118
155
  /**
@@ -156,11 +193,6 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
156
193
  maxBytes?: number;
157
194
  }): Promise<Uint8Array>;
158
195
 
159
- /**
160
- * Fetch function type (standardizes the version of fetch used).
161
- */
162
- type FetchFunction = typeof globalThis.fetch;
163
-
164
196
  /**
165
197
  Creates an ID generator.
166
198
  The total length of the ID is the sum of the prefix, separator, and random part length.
@@ -1165,4 +1197,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1165
1197
  dynamic?: boolean;
1166
1198
  }
1167
1199
 
1168
- export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, 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 StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, 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 };
1200
+ export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, 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 StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, 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.js CHANGED
@@ -59,6 +59,7 @@ __export(index_exports, {
59
59
  dynamicTool: () => dynamicTool,
60
60
  executeTool: () => executeTool,
61
61
  extractResponseHeaders: () => extractResponseHeaders,
62
+ fetchWithValidatedEndpoint: () => fetchWithValidatedEndpoint,
62
63
  fetchWithValidatedRedirects: () => fetchWithValidatedRedirects,
63
64
  generateId: () => generateId,
64
65
  getErrorMessage: () => getErrorMessage,
@@ -276,6 +277,15 @@ function isBrowserRuntime(globalThisAny = globalThis) {
276
277
  return globalThisAny.window != null;
277
278
  }
278
279
 
280
+ // src/is-same-origin.ts
281
+ function isSameOrigin(url, baseUrl) {
282
+ try {
283
+ return new URL(url).origin === new URL(baseUrl).origin;
284
+ } catch (e) {
285
+ return false;
286
+ }
287
+ }
288
+
279
289
  // src/validate-download-url.ts
280
290
  function validateDownloadUrl(url) {
281
291
  let parsed;
@@ -461,34 +471,24 @@ function createSafeLookup(lookup) {
461
471
  });
462
472
  }
463
473
  var safeNodeFetchPromise;
464
- var initialGlobalFetch = globalThis.fetch;
465
- var initialGlobalFetchIsNodeDefault = isNodeDefaultFetch(initialGlobalFetch);
466
474
  function isNodeRuntime() {
467
- var _a2, _b2;
475
+ var _a2, _b2, _c;
468
476
  const runtimeProcess = globalThis.process;
469
- return ((_a2 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a2.name) === "node" && ((_b2 = runtimeProcess.versions) == null ? void 0 : _b2.bun) == null;
477
+ return ((_a2 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a2.name) === "node" && ((_b2 = runtimeProcess.versions) == null ? void 0 : _b2.bun) == null && ((_c = runtimeProcess.versions) == null ? void 0 : _c.deno) == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
470
478
  }
471
479
  async function getDefaultDownloadFetch() {
472
- if (!isNodeRuntime() || !initialGlobalFetchIsNodeDefault || globalThis.fetch !== initialGlobalFetch) {
480
+ if (!isNodeRuntime()) {
473
481
  return globalThis.fetch;
474
482
  }
475
483
  return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
476
484
  }
477
- function isNodeDefaultFetch(fetch) {
478
- if (typeof fetch !== "function") {
479
- return false;
480
- }
481
- const source = Function.prototype.toString.call(fetch);
482
- return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
483
- }
484
485
  async function createSafeNodeFetch() {
485
- const [{ createRequire }, { lookup }] = await Promise.all([
486
+ const [module2, { lookup }] = await Promise.all([
486
487
  loadNodeModule("node:module"),
487
488
  loadNodeModule("node:dns")
488
489
  ]);
489
- const { Agent, fetch } = createRequire(getCurrentModulePath())(
490
- "undici"
491
- );
490
+ const nodeRequire = module2.createRequire(getCurrentModulePath());
491
+ const { Agent, fetch } = nodeRequire("undici");
492
492
  const dispatcher = new Agent({
493
493
  connect: {
494
494
  lookup: createSafeLookup(lookup)
@@ -530,20 +530,47 @@ function getCurrentModulePath() {
530
530
 
531
531
  // src/fetch-with-validated-redirects.ts
532
532
  var MAX_DOWNLOAD_REDIRECTS = 10;
533
+ async function getValidatedFetch(customFetch) {
534
+ return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
535
+ }
536
+ async function fetchWithValidatedEndpoint({
537
+ url,
538
+ init,
539
+ fetch: customFetch,
540
+ trustedOrigin,
541
+ redirect = "error"
542
+ }) {
543
+ const urlText = url.toString();
544
+ const isTrusted = trustedOrigin !== void 0 && isSameOrigin(urlText, trustedOrigin);
545
+ if (!isTrusted) {
546
+ validateDownloadUrl(urlText);
547
+ }
548
+ const fetch = isTrusted && customFetch != null ? customFetch : isTrusted ? globalThis.fetch : await getValidatedFetch(customFetch);
549
+ return await fetch(url, {
550
+ ...init,
551
+ redirect
552
+ });
553
+ }
533
554
  async function fetchWithValidatedRedirects({
534
555
  url,
535
556
  headers,
536
557
  abortSignal,
537
- maxRedirects = MAX_DOWNLOAD_REDIRECTS
558
+ maxRedirects = MAX_DOWNLOAD_REDIRECTS,
559
+ fetch: customFetch,
560
+ trustedOrigin
538
561
  }) {
562
+ var _a2;
539
563
  const baseInit = { signal: abortSignal };
540
564
  if (headers !== void 0) {
541
565
  baseInit.headers = headers;
542
566
  }
543
567
  let currentUrl = url;
544
568
  for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
545
- validateDownloadUrl(currentUrl);
546
- const fetch = await getDefaultDownloadFetch();
569
+ const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin);
570
+ if (!isTrustedHop) {
571
+ validateDownloadUrl(currentUrl);
572
+ }
573
+ const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
547
574
  const response = await fetch(currentUrl, {
548
575
  ...baseInit,
549
576
  redirect: "manual"
@@ -557,7 +584,7 @@ async function fetchWithValidatedRedirects({
557
584
  }
558
585
  return await fetch(currentUrl, { ...baseInit, redirect: "follow" });
559
586
  }
560
- const location = response.headers.get("location");
587
+ const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
561
588
  if (response.status >= 300 && response.status < 400 && location) {
562
589
  await cancelResponseBody(response);
563
590
  currentUrl = new URL(location, currentUrl).toString();
@@ -811,7 +838,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
811
838
  }
812
839
 
813
840
  // src/version.ts
814
- var VERSION = true ? "3.0.40" : "0.0.0-test";
841
+ var VERSION = true ? "3.0.41" : "0.0.0-test";
815
842
 
816
843
  // src/get-from-api.ts
817
844
  var getOriginalFetch = () => globalThis.fetch;
@@ -922,15 +949,6 @@ function injectJsonInstructionIntoMessages({
922
949
  ];
923
950
  }
924
951
 
925
- // src/is-same-origin.ts
926
- function isSameOrigin(url, baseUrl) {
927
- try {
928
- return new URL(url).origin === new URL(baseUrl).origin;
929
- } catch (e) {
930
- return false;
931
- }
932
- }
933
-
934
952
  // src/is-url-supported.ts
935
953
  function isUrlSupported({
936
954
  mediaType,
@@ -3435,6 +3453,7 @@ var import_stream2 = require("eventsource-parser/stream");
3435
3453
  dynamicTool,
3436
3454
  executeTool,
3437
3455
  extractResponseHeaders,
3456
+ fetchWithValidatedEndpoint,
3438
3457
  fetchWithValidatedRedirects,
3439
3458
  generateId,
3440
3459
  getErrorMessage,