@ai-sdk/provider-utils 3.0.11 → 3.0.13

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,17 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 1e05490: refactor: consolidate header normalization across packages, remove duplicates, preserve custom headers
8
+
9
+ ## 3.0.12
10
+
11
+ ### Patch Changes
12
+
13
+ - 17f9872: fix: revert zod import change
14
+
3
15
  ## 3.0.11
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -277,6 +277,15 @@ declare function loadSetting({ settingValue, environmentVariableName, settingNam
277
277
  */
278
278
  declare function mediaTypeToExtension(mediaType: string): string;
279
279
 
280
+ /**
281
+ * Normalizes different header inputs into a plain record with lower-case keys.
282
+ * Entries with `undefined` or `null` values are removed.
283
+ *
284
+ * @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
285
+ * @returns A record containing the normalized header entries.
286
+ */
287
+ declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
288
+
280
289
  /**
281
290
  * Parses a JSON event stream into a stream of parsed JSON objects.
282
291
  */
@@ -930,4 +939,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
930
939
  dynamic?: boolean;
931
940
  }
932
941
 
933
- export { type AssistantContent, type AssistantModelMessage, type DataContent, 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, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
942
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, 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 };
package/dist/index.d.ts CHANGED
@@ -277,6 +277,15 @@ declare function loadSetting({ settingValue, environmentVariableName, settingNam
277
277
  */
278
278
  declare function mediaTypeToExtension(mediaType: string): string;
279
279
 
280
+ /**
281
+ * Normalizes different header inputs into a plain record with lower-case keys.
282
+ * Entries with `undefined` or `null` values are removed.
283
+ *
284
+ * @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
285
+ * @returns A record containing the normalized header entries.
286
+ */
287
+ declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
288
+
280
289
  /**
281
290
  * Parses a JSON event stream into a stream of parsed JSON objects.
282
291
  */
@@ -930,4 +939,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
930
939
  dynamic?: boolean;
931
940
  }
932
941
 
933
- export { type AssistantContent, type AssistantModelMessage, type DataContent, 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, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
942
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, 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 };
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ __export(src_exports, {
69
69
  loadOptionalSetting: () => loadOptionalSetting,
70
70
  loadSetting: () => loadSetting,
71
71
  mediaTypeToExtension: () => mediaTypeToExtension,
72
+ normalizeHeaders: () => normalizeHeaders,
72
73
  parseJSON: () => parseJSON,
73
74
  parseJsonEventStream: () => parseJsonEventStream,
74
75
  parseProviderOptions: () => parseProviderOptions,
@@ -263,29 +264,42 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
263
264
  return "runtime/unknown";
264
265
  }
265
266
 
266
- // src/remove-undefined-entries.ts
267
- function removeUndefinedEntries(record) {
268
- return Object.fromEntries(
269
- Object.entries(record).filter(([_key, value]) => value != null)
270
- );
267
+ // src/normalize-headers.ts
268
+ function normalizeHeaders(headers) {
269
+ if (headers == null) {
270
+ return {};
271
+ }
272
+ const normalized = {};
273
+ if (headers instanceof Headers) {
274
+ headers.forEach((value, key) => {
275
+ normalized[key.toLowerCase()] = value;
276
+ });
277
+ } else {
278
+ if (!Array.isArray(headers)) {
279
+ headers = Object.entries(headers);
280
+ }
281
+ for (const [key, value] of headers) {
282
+ if (value != null) {
283
+ normalized[key.toLowerCase()] = value;
284
+ }
285
+ }
286
+ }
287
+ return normalized;
271
288
  }
272
289
 
273
290
  // src/with-user-agent-suffix.ts
274
291
  function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
275
- const cleanedHeaders = removeUndefinedEntries(
276
- headers != null ? headers : {}
277
- );
278
- const normalizedHeaders = new Headers(cleanedHeaders);
292
+ const normalizedHeaders = new Headers(normalizeHeaders(headers));
279
293
  const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
280
294
  normalizedHeaders.set(
281
295
  "user-agent",
282
296
  [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
283
297
  );
284
- return Object.fromEntries(normalizedHeaders);
298
+ return Object.fromEntries(normalizedHeaders.entries());
285
299
  }
286
300
 
287
301
  // src/version.ts
288
- var VERSION = true ? "3.0.11" : "0.0.0-test";
302
+ var VERSION = true ? "3.0.13" : "0.0.0-test";
289
303
 
290
304
  // src/get-from-api.ts
291
305
  var getOriginalFetch = () => globalThis.fetch;
@@ -901,6 +915,13 @@ function createProviderDefinedToolFactoryWithOutputSchema({
901
915
  });
902
916
  }
903
917
 
918
+ // src/remove-undefined-entries.ts
919
+ function removeUndefinedEntries(record) {
920
+ return Object.fromEntries(
921
+ Object.entries(record).filter(([_key, value]) => value != null)
922
+ );
923
+ }
924
+
904
925
  // src/resolve.ts
905
926
  async function resolve(value) {
906
927
  if (typeof value === "function") {
@@ -2433,6 +2454,7 @@ var import_stream2 = require("eventsource-parser/stream");
2433
2454
  loadOptionalSetting,
2434
2455
  loadSetting,
2435
2456
  mediaTypeToExtension,
2457
+ normalizeHeaders,
2436
2458
  parseJSON,
2437
2459
  parseJsonEventStream,
2438
2460
  parseProviderOptions,