@ai-sdk/provider-utils 4.0.0-beta.21 → 4.0.0-beta.23
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 +13 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a755db5]
|
|
8
|
+
- @ai-sdk/provider@3.0.0-beta.9
|
|
9
|
+
|
|
10
|
+
## 4.0.0-beta.22
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 58920e0: refactor: consolidate header normalization across packages, remove duplicates, preserve custom headers
|
|
15
|
+
|
|
3
16
|
## 4.0.0-beta.21
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -304,6 +304,15 @@ type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
|
304
304
|
*/
|
|
305
305
|
declare function mediaTypeToExtension(mediaType: string): string;
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
309
|
+
* Entries with `undefined` or `null` values are removed.
|
|
310
|
+
*
|
|
311
|
+
* @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
|
|
312
|
+
* @returns A record containing the normalized header entries.
|
|
313
|
+
*/
|
|
314
|
+
declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
315
|
+
|
|
307
316
|
/**
|
|
308
317
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
309
318
|
*/
|
|
@@ -1146,4 +1155,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1146
1155
|
dynamic?: boolean;
|
|
1147
1156
|
}
|
|
1148
1157
|
|
|
1149
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1158
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -304,6 +304,15 @@ type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
|
304
304
|
*/
|
|
305
305
|
declare function mediaTypeToExtension(mediaType: string): string;
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
309
|
+
* Entries with `undefined` or `null` values are removed.
|
|
310
|
+
*
|
|
311
|
+
* @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
|
|
312
|
+
* @returns A record containing the normalized header entries.
|
|
313
|
+
*/
|
|
314
|
+
declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
315
|
+
|
|
307
316
|
/**
|
|
308
317
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
309
318
|
*/
|
|
@@ -1146,4 +1155,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1146
1155
|
dynamic?: boolean;
|
|
1147
1156
|
}
|
|
1148
1157
|
|
|
1149
|
-
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1158
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,7 @@ __export(src_exports, {
|
|
|
66
66
|
loadOptionalSetting: () => loadOptionalSetting,
|
|
67
67
|
loadSetting: () => loadSetting,
|
|
68
68
|
mediaTypeToExtension: () => mediaTypeToExtension,
|
|
69
|
+
normalizeHeaders: () => normalizeHeaders,
|
|
69
70
|
parseJSON: () => parseJSON,
|
|
70
71
|
parseJsonEventStream: () => parseJsonEventStream,
|
|
71
72
|
parseProviderOptions: () => parseProviderOptions,
|
|
@@ -258,29 +259,42 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
|
258
259
|
return "runtime/unknown";
|
|
259
260
|
}
|
|
260
261
|
|
|
261
|
-
// src/
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
// src/normalize-headers.ts
|
|
263
|
+
function normalizeHeaders(headers) {
|
|
264
|
+
if (headers == null) {
|
|
265
|
+
return {};
|
|
266
|
+
}
|
|
267
|
+
const normalized = {};
|
|
268
|
+
if (headers instanceof Headers) {
|
|
269
|
+
headers.forEach((value, key) => {
|
|
270
|
+
normalized[key.toLowerCase()] = value;
|
|
271
|
+
});
|
|
272
|
+
} else {
|
|
273
|
+
if (!Array.isArray(headers)) {
|
|
274
|
+
headers = Object.entries(headers);
|
|
275
|
+
}
|
|
276
|
+
for (const [key, value] of headers) {
|
|
277
|
+
if (value != null) {
|
|
278
|
+
normalized[key.toLowerCase()] = value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return normalized;
|
|
266
283
|
}
|
|
267
284
|
|
|
268
285
|
// src/with-user-agent-suffix.ts
|
|
269
286
|
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
270
|
-
const
|
|
271
|
-
headers != null ? headers : {}
|
|
272
|
-
);
|
|
273
|
-
const normalizedHeaders = new Headers(cleanedHeaders);
|
|
287
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
274
288
|
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
275
289
|
normalizedHeaders.set(
|
|
276
290
|
"user-agent",
|
|
277
291
|
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
278
292
|
);
|
|
279
|
-
return Object.fromEntries(normalizedHeaders);
|
|
293
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
280
294
|
}
|
|
281
295
|
|
|
282
296
|
// src/version.ts
|
|
283
|
-
var VERSION = true ? "4.0.0-beta.
|
|
297
|
+
var VERSION = true ? "4.0.0-beta.23" : "0.0.0-test";
|
|
284
298
|
|
|
285
299
|
// src/get-from-api.ts
|
|
286
300
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -2208,6 +2222,13 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
2208
2222
|
});
|
|
2209
2223
|
}
|
|
2210
2224
|
|
|
2225
|
+
// src/remove-undefined-entries.ts
|
|
2226
|
+
function removeUndefinedEntries(record) {
|
|
2227
|
+
return Object.fromEntries(
|
|
2228
|
+
Object.entries(record).filter(([_key, value]) => value != null)
|
|
2229
|
+
);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2211
2232
|
// src/resolve.ts
|
|
2212
2233
|
async function resolve(value) {
|
|
2213
2234
|
if (typeof value === "function") {
|
|
@@ -2442,6 +2463,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2442
2463
|
loadOptionalSetting,
|
|
2443
2464
|
loadSetting,
|
|
2444
2465
|
mediaTypeToExtension,
|
|
2466
|
+
normalizeHeaders,
|
|
2445
2467
|
parseJSON,
|
|
2446
2468
|
parseJsonEventStream,
|
|
2447
2469
|
parseProviderOptions,
|