@ai-sdk/provider-utils 3.0.8 → 3.0.9
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 +6 -0
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +57 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -8
- package/dist/index.mjs.map +1 -1
- package/dist/test/index.js +2 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +2 -0
- package/dist/test/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -43,6 +43,20 @@ declare function extractResponseHeaders(response: Response): {
|
|
43
43
|
*/
|
44
44
|
type FetchFunction = typeof globalThis.fetch;
|
45
45
|
|
46
|
+
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Appends suffix parts to the `user-agent` header.
|
50
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
51
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
52
|
+
* Automatically removes undefined entries from the headers.
|
53
|
+
*
|
54
|
+
* @param headers - The original headers.
|
55
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
56
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
57
|
+
*/
|
58
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
59
|
+
|
46
60
|
/**
|
47
61
|
Creates an ID generator.
|
48
62
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
@@ -892,4 +906,6 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
892
906
|
dynamic?: boolean;
|
893
907
|
}
|
894
908
|
|
895
|
-
|
909
|
+
declare const VERSION: string;
|
910
|
+
|
911
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, 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, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
@@ -43,6 +43,20 @@ declare function extractResponseHeaders(response: Response): {
|
|
43
43
|
*/
|
44
44
|
type FetchFunction = typeof globalThis.fetch;
|
45
45
|
|
46
|
+
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Appends suffix parts to the `user-agent` header.
|
50
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
51
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
52
|
+
* Automatically removes undefined entries from the headers.
|
53
|
+
*
|
54
|
+
* @param headers - The original headers.
|
55
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
56
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
57
|
+
*/
|
58
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
59
|
+
|
46
60
|
/**
|
47
61
|
Creates an ID generator.
|
48
62
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
@@ -892,4 +906,6 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
892
906
|
dynamic?: boolean;
|
893
907
|
}
|
894
908
|
|
895
|
-
|
909
|
+
declare const VERSION: string;
|
910
|
+
|
911
|
+
export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, 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, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, validatorSymbol, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
@@ -32,6 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
32
32
|
var src_exports = {};
|
33
33
|
__export(src_exports, {
|
34
34
|
EventSourceParserStream: () => import_stream2.EventSourceParserStream,
|
35
|
+
VERSION: () => VERSION,
|
35
36
|
asSchema: () => asSchema,
|
36
37
|
asValidator: () => asValidator,
|
37
38
|
combineHeaders: () => combineHeaders,
|
@@ -55,6 +56,7 @@ __export(src_exports, {
|
|
55
56
|
generateId: () => generateId,
|
56
57
|
getErrorMessage: () => getErrorMessage,
|
57
58
|
getFromApi: () => getFromApi,
|
59
|
+
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
58
60
|
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
59
61
|
isAbortError: () => isAbortError,
|
60
62
|
isParsableJson: () => isParsableJson,
|
@@ -80,6 +82,7 @@ __export(src_exports, {
|
|
80
82
|
validateTypes: () => validateTypes,
|
81
83
|
validator: () => validator,
|
82
84
|
validatorSymbol: () => validatorSymbol,
|
85
|
+
withUserAgentSuffix: () => withUserAgentSuffix,
|
83
86
|
withoutTrailingSlash: () => withoutTrailingSlash,
|
84
87
|
zodSchema: () => zodSchema
|
85
88
|
});
|
@@ -160,6 +163,45 @@ function extractResponseHeaders(response) {
|
|
160
163
|
return Object.fromEntries([...response.headers]);
|
161
164
|
}
|
162
165
|
|
166
|
+
// src/get-runtime-environment-user-agent.ts
|
167
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
168
|
+
var _a, _b, _c;
|
169
|
+
if (globalThisAny.window) {
|
170
|
+
return `runtime/browser`;
|
171
|
+
}
|
172
|
+
if ((_a = globalThisAny.navigator) == null ? void 0 : _a.userAgent) {
|
173
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
174
|
+
}
|
175
|
+
if ((_c = (_b = globalThisAny.process) == null ? void 0 : _b.versions) == null ? void 0 : _c.node) {
|
176
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
177
|
+
}
|
178
|
+
if (globalThisAny.EdgeRuntime) {
|
179
|
+
return `runtime/vercel-edge`;
|
180
|
+
}
|
181
|
+
return "runtime/unknown";
|
182
|
+
}
|
183
|
+
|
184
|
+
// src/remove-undefined-entries.ts
|
185
|
+
function removeUndefinedEntries(record) {
|
186
|
+
return Object.fromEntries(
|
187
|
+
Object.entries(record).filter(([_key, value]) => value != null)
|
188
|
+
);
|
189
|
+
}
|
190
|
+
|
191
|
+
// src/with-user-agent-suffix.ts
|
192
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
193
|
+
const cleanedHeaders = removeUndefinedEntries(
|
194
|
+
headers != null ? headers : {}
|
195
|
+
);
|
196
|
+
const normalizedHeaders = new Headers(cleanedHeaders);
|
197
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
198
|
+
normalizedHeaders.set(
|
199
|
+
"user-agent",
|
200
|
+
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
201
|
+
);
|
202
|
+
return Object.fromEntries(normalizedHeaders);
|
203
|
+
}
|
204
|
+
|
163
205
|
// src/generate-id.ts
|
164
206
|
var import_provider = require("@ai-sdk/provider");
|
165
207
|
var createIdGenerator = ({
|
@@ -241,12 +283,8 @@ function handleFetchError({
|
|
241
283
|
return error;
|
242
284
|
}
|
243
285
|
|
244
|
-
// src/
|
245
|
-
|
246
|
-
return Object.fromEntries(
|
247
|
-
Object.entries(record).filter(([_key, value]) => value != null)
|
248
|
-
);
|
249
|
-
}
|
286
|
+
// src/version.ts
|
287
|
+
var VERSION = true ? "3.0.9" : "0.0.0-test";
|
250
288
|
|
251
289
|
// src/get-from-api.ts
|
252
290
|
var getOriginalFetch = () => globalThis.fetch;
|
@@ -261,7 +299,11 @@ var getFromApi = async ({
|
|
261
299
|
try {
|
262
300
|
const response = await fetch(url, {
|
263
301
|
method: "GET",
|
264
|
-
headers:
|
302
|
+
headers: withUserAgentSuffix(
|
303
|
+
headers,
|
304
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
305
|
+
getRuntimeEnvironmentUserAgent()
|
306
|
+
),
|
265
307
|
signal: abortSignal
|
266
308
|
});
|
267
309
|
const responseHeaders = extractResponseHeaders(response);
|
@@ -727,7 +769,11 @@ var postToApi = async ({
|
|
727
769
|
try {
|
728
770
|
const response = await fetch(url, {
|
729
771
|
method: "POST",
|
730
|
-
headers:
|
772
|
+
headers: withUserAgentSuffix(
|
773
|
+
headers,
|
774
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
775
|
+
getRuntimeEnvironmentUserAgent()
|
776
|
+
),
|
731
777
|
body: body.content,
|
732
778
|
signal: abortSignal
|
733
779
|
});
|
@@ -2327,6 +2373,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
2327
2373
|
// Annotate the CommonJS export names for ESM import in node:
|
2328
2374
|
0 && (module.exports = {
|
2329
2375
|
EventSourceParserStream,
|
2376
|
+
VERSION,
|
2330
2377
|
asSchema,
|
2331
2378
|
asValidator,
|
2332
2379
|
combineHeaders,
|
@@ -2350,6 +2397,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
2350
2397
|
generateId,
|
2351
2398
|
getErrorMessage,
|
2352
2399
|
getFromApi,
|
2400
|
+
getRuntimeEnvironmentUserAgent,
|
2353
2401
|
injectJsonInstructionIntoMessages,
|
2354
2402
|
isAbortError,
|
2355
2403
|
isParsableJson,
|
@@ -2375,6 +2423,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
2375
2423
|
validateTypes,
|
2376
2424
|
validator,
|
2377
2425
|
validatorSymbol,
|
2426
|
+
withUserAgentSuffix,
|
2378
2427
|
withoutTrailingSlash,
|
2379
2428
|
zodSchema,
|
2380
2429
|
...require("@standard-schema/spec")
|