@ai-sdk/provider-utils 4.0.63 → 4.0.64
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 +8 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +56 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/stringify-with-bigint-and-cycles.ts +26 -0
- package/src/uint8-utils.ts +39 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.64
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d900e58: fix(provider-utils): support cross-realm Uint8Array and ArrayBuffer in binary type guards and base64 conversion
|
|
8
|
+
- d900e58: fix(provider-utils): decode base64 into a preallocated Uint8Array to avoid ~25x transient memory and long event-loop blocking on large files
|
|
9
|
+
- d900e58: Add `stringifyWithBigIntAndCycles` for provider tool serialization that converts BigInt values to decimal strings and replaces ancestor cycles while preserving shared references and `toJSON` behavior.
|
|
10
|
+
|
|
3
11
|
## 4.0.63
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1599,6 +1599,8 @@ declare function stripFileExtension(filename: string): string;
|
|
|
1599
1599
|
|
|
1600
1600
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
1601
1601
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
1602
|
+
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
1603
|
+
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
1602
1604
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
1603
1605
|
|
|
1604
1606
|
/**
|
|
@@ -1744,4 +1746,11 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1744
1746
|
*/
|
|
1745
1747
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1746
1748
|
|
|
1747
|
-
|
|
1749
|
+
/**
|
|
1750
|
+
* Serializes a value as JSON, representing BigInt values as decimal strings and
|
|
1751
|
+
* ancestor cycles as "[Circular]". Reused objects, toJSON methods, and other JSON
|
|
1752
|
+
* serialization behavior are preserved. Getters and toJSON methods may throw.
|
|
1753
|
+
*/
|
|
1754
|
+
declare function stringifyWithBigIntAndCycles(value: unknown): string;
|
|
1755
|
+
|
|
1756
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, type EmbeddingModelProviderOptionsTransformer, 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 ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, encodePathSegment, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isArrayBuffer, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUint8Array, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stringifyWithBigIntAndCycles, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1599,6 +1599,8 @@ declare function stripFileExtension(filename: string): string;
|
|
|
1599
1599
|
|
|
1600
1600
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
1601
1601
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
1602
|
+
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
1603
|
+
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
1602
1604
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
1603
1605
|
|
|
1604
1606
|
/**
|
|
@@ -1744,4 +1746,11 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1744
1746
|
*/
|
|
1745
1747
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1746
1748
|
|
|
1747
|
-
|
|
1749
|
+
/**
|
|
1750
|
+
* Serializes a value as JSON, representing BigInt values as decimal strings and
|
|
1751
|
+
* ancestor cycles as "[Circular]". Reused objects, toJSON methods, and other JSON
|
|
1752
|
+
* serialization behavior are preserved. Getters and toJSON methods may throw.
|
|
1753
|
+
*/
|
|
1754
|
+
declare function stringifyWithBigIntAndCycles(value: unknown): string;
|
|
1755
|
+
|
|
1756
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, type EmbeddingModelProviderOptionsTransformer, 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 ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, encodePathSegment, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isArrayBuffer, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUint8Array, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stringifyWithBigIntAndCycles, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -70,10 +70,12 @@ __export(index_exports, {
|
|
|
70
70
|
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
|
71
71
|
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
|
72
72
|
isAbortError: () => isAbortError,
|
|
73
|
+
isArrayBuffer: () => isArrayBuffer,
|
|
73
74
|
isBrowserRuntime: () => isBrowserRuntime,
|
|
74
75
|
isNonNullable: () => isNonNullable,
|
|
75
76
|
isParsableJson: () => isParsableJson,
|
|
76
77
|
isSameOrigin: () => isSameOrigin,
|
|
78
|
+
isUint8Array: () => isUint8Array,
|
|
77
79
|
isUrlSupported: () => isUrlSupported,
|
|
78
80
|
jsonSchema: () => jsonSchema,
|
|
79
81
|
lazySchema: () => lazySchema,
|
|
@@ -95,6 +97,7 @@ __export(index_exports, {
|
|
|
95
97
|
safeParseJSON: () => safeParseJSON,
|
|
96
98
|
safeValidateTypes: () => safeValidateTypes,
|
|
97
99
|
secureJsonParse: () => secureJsonParse,
|
|
100
|
+
stringifyWithBigIntAndCycles: () => stringifyWithBigIntAndCycles,
|
|
98
101
|
stripFileExtension: () => stripFileExtension,
|
|
99
102
|
tool: () => tool,
|
|
100
103
|
validateDownloadUrl: () => validateDownloadUrl,
|
|
@@ -272,7 +275,11 @@ var { btoa, atob } = globalThis;
|
|
|
272
275
|
function convertBase64ToUint8Array(base64String) {
|
|
273
276
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
274
277
|
const latin1string = atob(base64Url);
|
|
275
|
-
|
|
278
|
+
const bytes = new Uint8Array(latin1string.length);
|
|
279
|
+
for (let i = 0; i < latin1string.length; i++) {
|
|
280
|
+
bytes[i] = latin1string.charCodeAt(i);
|
|
281
|
+
}
|
|
282
|
+
return bytes;
|
|
276
283
|
}
|
|
277
284
|
function convertUint8ArrayToBase64(array) {
|
|
278
285
|
var _a2;
|
|
@@ -290,8 +297,30 @@ function convertUint8ArrayToBase64(array) {
|
|
|
290
297
|
}
|
|
291
298
|
return btoa(chunks.join(""));
|
|
292
299
|
}
|
|
300
|
+
var typedArrayTag = Object.getOwnPropertyDescriptor(
|
|
301
|
+
Object.getPrototypeOf(Uint8Array.prototype),
|
|
302
|
+
Symbol.toStringTag
|
|
303
|
+
).get;
|
|
304
|
+
var arrayBufferByteLength = Object.getOwnPropertyDescriptor(
|
|
305
|
+
ArrayBuffer.prototype,
|
|
306
|
+
"byteLength"
|
|
307
|
+
).get;
|
|
308
|
+
function isUint8Array(value) {
|
|
309
|
+
return ArrayBuffer.isView(value) && typedArrayTag.call(value) === "Uint8Array";
|
|
310
|
+
}
|
|
311
|
+
function isArrayBuffer(value) {
|
|
312
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
try {
|
|
316
|
+
arrayBufferByteLength.call(value);
|
|
317
|
+
return true;
|
|
318
|
+
} catch (e) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
293
322
|
function convertToBase64(value) {
|
|
294
|
-
return value
|
|
323
|
+
return isUint8Array(value) ? convertUint8ArrayToBase64(value) : value;
|
|
295
324
|
}
|
|
296
325
|
|
|
297
326
|
// src/convert-image-model-file-to-data-uri.ts
|
|
@@ -1014,7 +1043,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1014
1043
|
}
|
|
1015
1044
|
|
|
1016
1045
|
// src/version.ts
|
|
1017
|
-
var VERSION = true ? "4.0.
|
|
1046
|
+
var VERSION = true ? "4.0.64" : "0.0.0-test";
|
|
1018
1047
|
|
|
1019
1048
|
// src/get-from-api.ts
|
|
1020
1049
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -3659,6 +3688,27 @@ async function* executeTool({
|
|
|
3659
3688
|
|
|
3660
3689
|
// src/index.ts
|
|
3661
3690
|
var import_stream2 = require("eventsource-parser/stream");
|
|
3691
|
+
|
|
3692
|
+
// src/stringify-with-bigint-and-cycles.ts
|
|
3693
|
+
function stringifyWithBigIntAndCycles(value) {
|
|
3694
|
+
const ancestors = [];
|
|
3695
|
+
return JSON.stringify(value, function(_key, value2) {
|
|
3696
|
+
if (typeof value2 === "bigint") {
|
|
3697
|
+
return value2.toString();
|
|
3698
|
+
}
|
|
3699
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
3700
|
+
return value2;
|
|
3701
|
+
}
|
|
3702
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
3703
|
+
ancestors.pop();
|
|
3704
|
+
}
|
|
3705
|
+
if (ancestors.includes(value2)) {
|
|
3706
|
+
return "[Circular]";
|
|
3707
|
+
}
|
|
3708
|
+
ancestors.push(value2);
|
|
3709
|
+
return value2;
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3662
3712
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3663
3713
|
0 && (module.exports = {
|
|
3664
3714
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
@@ -3701,10 +3751,12 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
3701
3751
|
getRuntimeEnvironmentUserAgent,
|
|
3702
3752
|
injectJsonInstructionIntoMessages,
|
|
3703
3753
|
isAbortError,
|
|
3754
|
+
isArrayBuffer,
|
|
3704
3755
|
isBrowserRuntime,
|
|
3705
3756
|
isNonNullable,
|
|
3706
3757
|
isParsableJson,
|
|
3707
3758
|
isSameOrigin,
|
|
3759
|
+
isUint8Array,
|
|
3708
3760
|
isUrlSupported,
|
|
3709
3761
|
jsonSchema,
|
|
3710
3762
|
lazySchema,
|
|
@@ -3726,6 +3778,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
3726
3778
|
safeParseJSON,
|
|
3727
3779
|
safeValidateTypes,
|
|
3728
3780
|
secureJsonParse,
|
|
3781
|
+
stringifyWithBigIntAndCycles,
|
|
3729
3782
|
stripFileExtension,
|
|
3730
3783
|
tool,
|
|
3731
3784
|
validateDownloadUrl,
|