@ai-sdk/provider-utils 3.0.12 → 3.0.14
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 +12 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +43 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 949718b: fix(provider-utils): make ReadableStream.cancel() properly finalize async iterators
|
|
8
|
+
|
|
9
|
+
## 3.0.13
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1e05490: refactor: consolidate header normalization across packages, remove duplicates, preserve custom headers
|
|
14
|
+
|
|
3
15
|
## 3.0.12
|
|
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,
|
|
@@ -102,6 +103,7 @@ function combineHeaders(...headers) {
|
|
|
102
103
|
|
|
103
104
|
// src/convert-async-iterator-to-readable-stream.ts
|
|
104
105
|
function convertAsyncIteratorToReadableStream(iterator) {
|
|
106
|
+
let cancelled = false;
|
|
105
107
|
return new ReadableStream({
|
|
106
108
|
/**
|
|
107
109
|
* Called when the consumer wants to pull more data from the stream.
|
|
@@ -110,6 +112,7 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
110
112
|
* @returns {Promise<void>}
|
|
111
113
|
*/
|
|
112
114
|
async pull(controller) {
|
|
115
|
+
if (cancelled) return;
|
|
113
116
|
try {
|
|
114
117
|
const { value, done } = await iterator.next();
|
|
115
118
|
if (done) {
|
|
@@ -124,7 +127,14 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
124
127
|
/**
|
|
125
128
|
* Called when the consumer cancels the stream.
|
|
126
129
|
*/
|
|
127
|
-
cancel() {
|
|
130
|
+
async cancel(reason) {
|
|
131
|
+
cancelled = true;
|
|
132
|
+
if (iterator.return) {
|
|
133
|
+
try {
|
|
134
|
+
await iterator.return(reason);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
128
138
|
}
|
|
129
139
|
});
|
|
130
140
|
}
|
|
@@ -263,29 +273,42 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
|
263
273
|
return "runtime/unknown";
|
|
264
274
|
}
|
|
265
275
|
|
|
266
|
-
// src/
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
276
|
+
// src/normalize-headers.ts
|
|
277
|
+
function normalizeHeaders(headers) {
|
|
278
|
+
if (headers == null) {
|
|
279
|
+
return {};
|
|
280
|
+
}
|
|
281
|
+
const normalized = {};
|
|
282
|
+
if (headers instanceof Headers) {
|
|
283
|
+
headers.forEach((value, key) => {
|
|
284
|
+
normalized[key.toLowerCase()] = value;
|
|
285
|
+
});
|
|
286
|
+
} else {
|
|
287
|
+
if (!Array.isArray(headers)) {
|
|
288
|
+
headers = Object.entries(headers);
|
|
289
|
+
}
|
|
290
|
+
for (const [key, value] of headers) {
|
|
291
|
+
if (value != null) {
|
|
292
|
+
normalized[key.toLowerCase()] = value;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return normalized;
|
|
271
297
|
}
|
|
272
298
|
|
|
273
299
|
// src/with-user-agent-suffix.ts
|
|
274
300
|
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
275
|
-
const
|
|
276
|
-
headers != null ? headers : {}
|
|
277
|
-
);
|
|
278
|
-
const normalizedHeaders = new Headers(cleanedHeaders);
|
|
301
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
279
302
|
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
280
303
|
normalizedHeaders.set(
|
|
281
304
|
"user-agent",
|
|
282
305
|
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
283
306
|
);
|
|
284
|
-
return Object.fromEntries(normalizedHeaders);
|
|
307
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
285
308
|
}
|
|
286
309
|
|
|
287
310
|
// src/version.ts
|
|
288
|
-
var VERSION = true ? "3.0.
|
|
311
|
+
var VERSION = true ? "3.0.14" : "0.0.0-test";
|
|
289
312
|
|
|
290
313
|
// src/get-from-api.ts
|
|
291
314
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -901,6 +924,13 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
901
924
|
});
|
|
902
925
|
}
|
|
903
926
|
|
|
927
|
+
// src/remove-undefined-entries.ts
|
|
928
|
+
function removeUndefinedEntries(record) {
|
|
929
|
+
return Object.fromEntries(
|
|
930
|
+
Object.entries(record).filter(([_key, value]) => value != null)
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
|
|
904
934
|
// src/resolve.ts
|
|
905
935
|
async function resolve(value) {
|
|
906
936
|
if (typeof value === "function") {
|
|
@@ -2433,6 +2463,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2433
2463
|
loadOptionalSetting,
|
|
2434
2464
|
loadSetting,
|
|
2435
2465
|
mediaTypeToExtension,
|
|
2466
|
+
normalizeHeaders,
|
|
2436
2467
|
parseJSON,
|
|
2437
2468
|
parseJsonEventStream,
|
|
2438
2469
|
parseProviderOptions,
|