@ai-sdk/provider-utils 3.0.42 → 3.0.44
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 +14 -0
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +66 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.44
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0a069bd: fix(provider-utils): support cross-realm Uint8Array and ArrayBuffer in binary type guards and base64 conversion
|
|
8
|
+
- 0a069bd: fix(provider-utils): decode base64 into a preallocated Uint8Array to avoid ~25x transient memory and long event-loop blocking on large files
|
|
9
|
+
- 0a069bd: 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
|
+
|
|
11
|
+
## 3.0.43
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- a1a772f: use native Buffer base64 encoding when available. encoding a `Uint8Array` backed by a detached `ArrayBuffer` now throws a `TypeError` in runtimes with `Buffer` instead of returning an empty string
|
|
16
|
+
|
|
3
17
|
## 3.0.42
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1058,6 +1058,8 @@ declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = St
|
|
|
1058
1058
|
|
|
1059
1059
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
1060
1060
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
1061
|
+
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
1062
|
+
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
1061
1063
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
1062
1064
|
|
|
1063
1065
|
/**
|
|
@@ -1204,4 +1206,13 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1204
1206
|
dynamic?: boolean;
|
|
1205
1207
|
}
|
|
1206
1208
|
|
|
1207
|
-
|
|
1209
|
+
/**
|
|
1210
|
+
* Serializes a value as JSON, representing BigInt values as decimal strings and
|
|
1211
|
+
* ancestor cycles as "[Circular]". Reused objects, toJSON methods, and other JSON
|
|
1212
|
+
* serialization behavior are preserved. Getters and toJSON methods may throw.
|
|
1213
|
+
*/
|
|
1214
|
+
declare function stringifyWithBigIntAndCycles(value: unknown): string;
|
|
1215
|
+
|
|
1216
|
+
declare function secureJsonParse(text: string): any;
|
|
1217
|
+
|
|
1218
|
+
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, 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 StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, encodePathSegment, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isArrayBuffer, isBrowserRuntime, isParsableJson, isSameOrigin, isUint8Array, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, secureJsonParse, standardSchemaValidator, stringifyWithBigIntAndCycles, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1058,6 +1058,8 @@ declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = St
|
|
|
1058
1058
|
|
|
1059
1059
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
1060
1060
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
1061
|
+
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
1062
|
+
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
1061
1063
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
1062
1064
|
|
|
1063
1065
|
/**
|
|
@@ -1204,4 +1206,13 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1204
1206
|
dynamic?: boolean;
|
|
1205
1207
|
}
|
|
1206
1208
|
|
|
1207
|
-
|
|
1209
|
+
/**
|
|
1210
|
+
* Serializes a value as JSON, representing BigInt values as decimal strings and
|
|
1211
|
+
* ancestor cycles as "[Circular]". Reused objects, toJSON methods, and other JSON
|
|
1212
|
+
* serialization behavior are preserved. Getters and toJSON methods may throw.
|
|
1213
|
+
*/
|
|
1214
|
+
declare function stringifyWithBigIntAndCycles(value: unknown): string;
|
|
1215
|
+
|
|
1216
|
+
declare function secureJsonParse(text: string): any;
|
|
1217
|
+
|
|
1218
|
+
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, 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 StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, 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, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, encodePathSegment, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isArrayBuffer, isBrowserRuntime, isParsableJson, isSameOrigin, isUint8Array, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, secureJsonParse, standardSchemaValidator, stringifyWithBigIntAndCycles, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -68,9 +68,11 @@ __export(index_exports, {
|
|
|
68
68
|
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
|
69
69
|
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
|
70
70
|
isAbortError: () => isAbortError,
|
|
71
|
+
isArrayBuffer: () => isArrayBuffer,
|
|
71
72
|
isBrowserRuntime: () => isBrowserRuntime,
|
|
72
73
|
isParsableJson: () => isParsableJson,
|
|
73
74
|
isSameOrigin: () => isSameOrigin,
|
|
75
|
+
isUint8Array: () => isUint8Array,
|
|
74
76
|
isUrlSupported: () => isUrlSupported,
|
|
75
77
|
isValidator: () => isValidator,
|
|
76
78
|
jsonSchema: () => jsonSchema,
|
|
@@ -92,7 +94,9 @@ __export(index_exports, {
|
|
|
92
94
|
resolve: () => resolve,
|
|
93
95
|
safeParseJSON: () => safeParseJSON,
|
|
94
96
|
safeValidateTypes: () => safeValidateTypes,
|
|
97
|
+
secureJsonParse: () => secureJsonParse,
|
|
95
98
|
standardSchemaValidator: () => standardSchemaValidator,
|
|
99
|
+
stringifyWithBigIntAndCycles: () => stringifyWithBigIntAndCycles,
|
|
96
100
|
tool: () => tool,
|
|
97
101
|
validateDownloadUrl: () => validateDownloadUrl,
|
|
98
102
|
validateTypes: () => validateTypes,
|
|
@@ -845,7 +849,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
845
849
|
}
|
|
846
850
|
|
|
847
851
|
// src/version.ts
|
|
848
|
-
var VERSION = true ? "3.0.
|
|
852
|
+
var VERSION = true ? "3.0.44" : "0.0.0-test";
|
|
849
853
|
|
|
850
854
|
// src/get-from-api.ts
|
|
851
855
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -3384,9 +3388,21 @@ var { btoa, atob } = globalThis;
|
|
|
3384
3388
|
function convertBase64ToUint8Array(base64String) {
|
|
3385
3389
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
3386
3390
|
const latin1string = atob(base64Url);
|
|
3387
|
-
|
|
3391
|
+
const bytes = new Uint8Array(latin1string.length);
|
|
3392
|
+
for (let i = 0; i < latin1string.length; i++) {
|
|
3393
|
+
bytes[i] = latin1string.charCodeAt(i);
|
|
3394
|
+
}
|
|
3395
|
+
return bytes;
|
|
3388
3396
|
}
|
|
3389
3397
|
function convertUint8ArrayToBase64(array) {
|
|
3398
|
+
var _a2;
|
|
3399
|
+
if (typeof ((_a2 = globalThis.Buffer) == null ? void 0 : _a2.from) === "function") {
|
|
3400
|
+
return globalThis.Buffer.from(
|
|
3401
|
+
array.buffer,
|
|
3402
|
+
array.byteOffset,
|
|
3403
|
+
array.byteLength
|
|
3404
|
+
).toString("base64");
|
|
3405
|
+
}
|
|
3390
3406
|
const chunks = [];
|
|
3391
3407
|
const chunkSize = 4096;
|
|
3392
3408
|
for (let i = 0; i < array.length; i += chunkSize) {
|
|
@@ -3394,8 +3410,30 @@ function convertUint8ArrayToBase64(array) {
|
|
|
3394
3410
|
}
|
|
3395
3411
|
return btoa(chunks.join(""));
|
|
3396
3412
|
}
|
|
3413
|
+
var typedArrayTag = Object.getOwnPropertyDescriptor(
|
|
3414
|
+
Object.getPrototypeOf(Uint8Array.prototype),
|
|
3415
|
+
Symbol.toStringTag
|
|
3416
|
+
).get;
|
|
3417
|
+
var arrayBufferByteLength = Object.getOwnPropertyDescriptor(
|
|
3418
|
+
ArrayBuffer.prototype,
|
|
3419
|
+
"byteLength"
|
|
3420
|
+
).get;
|
|
3421
|
+
function isUint8Array(value) {
|
|
3422
|
+
return ArrayBuffer.isView(value) && typedArrayTag.call(value) === "Uint8Array";
|
|
3423
|
+
}
|
|
3424
|
+
function isArrayBuffer(value) {
|
|
3425
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) {
|
|
3426
|
+
return false;
|
|
3427
|
+
}
|
|
3428
|
+
try {
|
|
3429
|
+
arrayBufferByteLength.call(value);
|
|
3430
|
+
return true;
|
|
3431
|
+
} catch (e) {
|
|
3432
|
+
return false;
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3397
3435
|
function convertToBase64(value) {
|
|
3398
|
-
return value
|
|
3436
|
+
return isUint8Array(value) ? convertUint8ArrayToBase64(value) : value;
|
|
3399
3437
|
}
|
|
3400
3438
|
|
|
3401
3439
|
// src/without-trailing-slash.ts
|
|
@@ -3430,6 +3468,27 @@ async function* executeTool({
|
|
|
3430
3468
|
// src/index.ts
|
|
3431
3469
|
__reExport(index_exports, require("@standard-schema/spec"), module.exports);
|
|
3432
3470
|
var import_stream2 = require("eventsource-parser/stream");
|
|
3471
|
+
|
|
3472
|
+
// src/stringify-with-bigint-and-cycles.ts
|
|
3473
|
+
function stringifyWithBigIntAndCycles(value) {
|
|
3474
|
+
const ancestors = [];
|
|
3475
|
+
return JSON.stringify(value, function(_key, value2) {
|
|
3476
|
+
if (typeof value2 === "bigint") {
|
|
3477
|
+
return value2.toString();
|
|
3478
|
+
}
|
|
3479
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
3480
|
+
return value2;
|
|
3481
|
+
}
|
|
3482
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
3483
|
+
ancestors.pop();
|
|
3484
|
+
}
|
|
3485
|
+
if (ancestors.includes(value2)) {
|
|
3486
|
+
return "[Circular]";
|
|
3487
|
+
}
|
|
3488
|
+
ancestors.push(value2);
|
|
3489
|
+
return value2;
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3433
3492
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3434
3493
|
0 && (module.exports = {
|
|
3435
3494
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
@@ -3469,9 +3528,11 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
3469
3528
|
getRuntimeEnvironmentUserAgent,
|
|
3470
3529
|
injectJsonInstructionIntoMessages,
|
|
3471
3530
|
isAbortError,
|
|
3531
|
+
isArrayBuffer,
|
|
3472
3532
|
isBrowserRuntime,
|
|
3473
3533
|
isParsableJson,
|
|
3474
3534
|
isSameOrigin,
|
|
3535
|
+
isUint8Array,
|
|
3475
3536
|
isUrlSupported,
|
|
3476
3537
|
isValidator,
|
|
3477
3538
|
jsonSchema,
|
|
@@ -3493,7 +3554,9 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
3493
3554
|
resolve,
|
|
3494
3555
|
safeParseJSON,
|
|
3495
3556
|
safeValidateTypes,
|
|
3557
|
+
secureJsonParse,
|
|
3496
3558
|
standardSchemaValidator,
|
|
3559
|
+
stringifyWithBigIntAndCycles,
|
|
3497
3560
|
tool,
|
|
3498
3561
|
validateDownloadUrl,
|
|
3499
3562
|
validateTypes,
|