@ai-sdk/provider-utils 4.0.0-beta.20 → 4.0.0-beta.22
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 +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +33 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -39
- 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
|
+
## 4.0.0-beta.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 58920e0: refactor: consolidate header normalization across packages, remove duplicates, preserve custom headers
|
|
8
|
+
|
|
9
|
+
## 4.0.0-beta.21
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 293a6b7: Added a title to the tools
|
|
14
|
+
|
|
3
15
|
## 4.0.0-beta.20
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
|
|
2
|
-
import * as z4 from 'zod/v4';
|
|
3
|
-
import { ZodType } from 'zod/v4';
|
|
4
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
3
|
export * from '@standard-schema/spec';
|
|
6
4
|
import * as z3 from 'zod/v3';
|
|
5
|
+
import * as z4 from 'zod/v4';
|
|
7
6
|
export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
|
|
8
7
|
|
|
9
8
|
declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
|
@@ -203,7 +202,6 @@ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage,
|
|
|
203
202
|
isRetryable?: (response: Response, error?: T) => boolean;
|
|
204
203
|
}) => ResponseHandler<APICallError>;
|
|
205
204
|
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
206
|
-
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
207
205
|
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
208
206
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
209
207
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
@@ -306,6 +304,15 @@ type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
|
306
304
|
*/
|
|
307
305
|
declare function mediaTypeToExtension(mediaType: string): string;
|
|
308
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
|
+
|
|
309
316
|
/**
|
|
310
317
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
311
318
|
*/
|
|
@@ -873,6 +880,10 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
873
880
|
*/
|
|
874
881
|
description?: string;
|
|
875
882
|
/**
|
|
883
|
+
* An optional title of the tool.
|
|
884
|
+
*/
|
|
885
|
+
title?: string;
|
|
886
|
+
/**
|
|
876
887
|
Additional provider-specific metadata. They are passed through
|
|
877
888
|
to the provider from the AI SDK and enable provider-specific
|
|
878
889
|
functionality that can be fully encapsulated in the provider.
|
|
@@ -963,6 +974,7 @@ declare function tool(tool: Tool<never, never>): Tool<never, never>;
|
|
|
963
974
|
*/
|
|
964
975
|
declare function dynamicTool(tool: {
|
|
965
976
|
description?: string;
|
|
977
|
+
title?: string;
|
|
966
978
|
providerOptions?: ProviderOptions;
|
|
967
979
|
inputSchema: FlexibleSchema<unknown>;
|
|
968
980
|
execute: ToolExecuteFunction<unknown, unknown>;
|
|
@@ -1143,4 +1155,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1143
1155
|
dynamic?: boolean;
|
|
1144
1156
|
}
|
|
1145
1157
|
|
|
1146
|
-
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,
|
|
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
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
|
|
2
|
-
import * as z4 from 'zod/v4';
|
|
3
|
-
import { ZodType } from 'zod/v4';
|
|
4
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
3
|
export * from '@standard-schema/spec';
|
|
6
4
|
import * as z3 from 'zod/v3';
|
|
5
|
+
import * as z4 from 'zod/v4';
|
|
7
6
|
export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
|
|
8
7
|
|
|
9
8
|
declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
|
@@ -203,7 +202,6 @@ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage,
|
|
|
203
202
|
isRetryable?: (response: Response, error?: T) => boolean;
|
|
204
203
|
}) => ResponseHandler<APICallError>;
|
|
205
204
|
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
206
|
-
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
207
205
|
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
208
206
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
209
207
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
@@ -306,6 +304,15 @@ type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
|
306
304
|
*/
|
|
307
305
|
declare function mediaTypeToExtension(mediaType: string): string;
|
|
308
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
|
+
|
|
309
316
|
/**
|
|
310
317
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
311
318
|
*/
|
|
@@ -873,6 +880,10 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
873
880
|
*/
|
|
874
881
|
description?: string;
|
|
875
882
|
/**
|
|
883
|
+
* An optional title of the tool.
|
|
884
|
+
*/
|
|
885
|
+
title?: string;
|
|
886
|
+
/**
|
|
876
887
|
Additional provider-specific metadata. They are passed through
|
|
877
888
|
to the provider from the AI SDK and enable provider-specific
|
|
878
889
|
functionality that can be fully encapsulated in the provider.
|
|
@@ -963,6 +974,7 @@ declare function tool(tool: Tool<never, never>): Tool<never, never>;
|
|
|
963
974
|
*/
|
|
964
975
|
declare function dynamicTool(tool: {
|
|
965
976
|
description?: string;
|
|
977
|
+
title?: string;
|
|
966
978
|
providerOptions?: ProviderOptions;
|
|
967
979
|
inputSchema: FlexibleSchema<unknown>;
|
|
968
980
|
execute: ToolExecuteFunction<unknown, unknown>;
|
|
@@ -1143,4 +1155,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1143
1155
|
dynamic?: boolean;
|
|
1144
1156
|
}
|
|
1145
1157
|
|
|
1146
|
-
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,
|
|
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
|
@@ -44,7 +44,6 @@ __export(src_exports, {
|
|
|
44
44
|
createIdGenerator: () => createIdGenerator,
|
|
45
45
|
createJsonErrorResponseHandler: () => createJsonErrorResponseHandler,
|
|
46
46
|
createJsonResponseHandler: () => createJsonResponseHandler,
|
|
47
|
-
createJsonStreamResponseHandler: () => createJsonStreamResponseHandler,
|
|
48
47
|
createProviderDefinedToolFactory: () => createProviderDefinedToolFactory,
|
|
49
48
|
createProviderDefinedToolFactoryWithOutputSchema: () => createProviderDefinedToolFactoryWithOutputSchema,
|
|
50
49
|
createStatusCodeErrorResponseHandler: () => createStatusCodeErrorResponseHandler,
|
|
@@ -67,6 +66,7 @@ __export(src_exports, {
|
|
|
67
66
|
loadOptionalSetting: () => loadOptionalSetting,
|
|
68
67
|
loadSetting: () => loadSetting,
|
|
69
68
|
mediaTypeToExtension: () => mediaTypeToExtension,
|
|
69
|
+
normalizeHeaders: () => normalizeHeaders,
|
|
70
70
|
parseJSON: () => parseJSON,
|
|
71
71
|
parseJsonEventStream: () => parseJsonEventStream,
|
|
72
72
|
parseProviderOptions: () => parseProviderOptions,
|
|
@@ -259,29 +259,42 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
|
259
259
|
return "runtime/unknown";
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
// src/
|
|
263
|
-
function
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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;
|
|
267
283
|
}
|
|
268
284
|
|
|
269
285
|
// src/with-user-agent-suffix.ts
|
|
270
286
|
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
271
|
-
const
|
|
272
|
-
headers != null ? headers : {}
|
|
273
|
-
);
|
|
274
|
-
const normalizedHeaders = new Headers(cleanedHeaders);
|
|
287
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
275
288
|
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
276
289
|
normalizedHeaders.set(
|
|
277
290
|
"user-agent",
|
|
278
291
|
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
279
292
|
);
|
|
280
|
-
return Object.fromEntries(normalizedHeaders);
|
|
293
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
281
294
|
}
|
|
282
295
|
|
|
283
296
|
// src/version.ts
|
|
284
|
-
var VERSION = true ? "4.0.0-beta.
|
|
297
|
+
var VERSION = true ? "4.0.0-beta.22" : "0.0.0-test";
|
|
285
298
|
|
|
286
299
|
// src/get-from-api.ts
|
|
287
300
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -2209,6 +2222,13 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
2209
2222
|
});
|
|
2210
2223
|
}
|
|
2211
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
|
+
|
|
2212
2232
|
// src/resolve.ts
|
|
2213
2233
|
async function resolve(value) {
|
|
2214
2234
|
if (typeof value === "function") {
|
|
@@ -2286,33 +2306,6 @@ var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) =>
|
|
|
2286
2306
|
})
|
|
2287
2307
|
};
|
|
2288
2308
|
};
|
|
2289
|
-
var createJsonStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
2290
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
2291
|
-
if (response.body == null) {
|
|
2292
|
-
throw new import_provider11.EmptyResponseBodyError({});
|
|
2293
|
-
}
|
|
2294
|
-
let buffer = "";
|
|
2295
|
-
return {
|
|
2296
|
-
responseHeaders,
|
|
2297
|
-
value: response.body.pipeThrough(new TextDecoderStream()).pipeThrough(
|
|
2298
|
-
new TransformStream({
|
|
2299
|
-
async transform(chunkText, controller) {
|
|
2300
|
-
if (chunkText.endsWith("\n")) {
|
|
2301
|
-
controller.enqueue(
|
|
2302
|
-
await safeParseJSON({
|
|
2303
|
-
text: buffer + chunkText,
|
|
2304
|
-
schema: chunkSchema
|
|
2305
|
-
})
|
|
2306
|
-
);
|
|
2307
|
-
buffer = "";
|
|
2308
|
-
} else {
|
|
2309
|
-
buffer += chunkText;
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
})
|
|
2313
|
-
)
|
|
2314
|
-
};
|
|
2315
|
-
};
|
|
2316
2309
|
var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
2317
2310
|
const responseBody = await response.text();
|
|
2318
2311
|
const parsedResult = await safeParseJSON({
|
|
@@ -2448,7 +2441,6 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2448
2441
|
createIdGenerator,
|
|
2449
2442
|
createJsonErrorResponseHandler,
|
|
2450
2443
|
createJsonResponseHandler,
|
|
2451
|
-
createJsonStreamResponseHandler,
|
|
2452
2444
|
createProviderDefinedToolFactory,
|
|
2453
2445
|
createProviderDefinedToolFactoryWithOutputSchema,
|
|
2454
2446
|
createStatusCodeErrorResponseHandler,
|
|
@@ -2471,6 +2463,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2471
2463
|
loadOptionalSetting,
|
|
2472
2464
|
loadSetting,
|
|
2473
2465
|
mediaTypeToExtension,
|
|
2466
|
+
normalizeHeaders,
|
|
2474
2467
|
parseJSON,
|
|
2475
2468
|
parseJsonEventStream,
|
|
2476
2469
|
parseProviderOptions,
|