@ai-sdk/provider-utils 3.0.43 → 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 CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 3.0.43
4
12
 
5
13
  ### 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
- 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, isBrowserRuntime, isParsableJson, isSameOrigin, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
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
- 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, isBrowserRuntime, isParsableJson, isSameOrigin, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
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.43" : "0.0.0-test";
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,7 +3388,11 @@ 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
- return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
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) {
3390
3398
  var _a2;
@@ -3402,8 +3410,30 @@ function convertUint8ArrayToBase64(array) {
3402
3410
  }
3403
3411
  return btoa(chunks.join(""));
3404
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
+ }
3405
3435
  function convertToBase64(value) {
3406
- return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
3436
+ return isUint8Array(value) ? convertUint8ArrayToBase64(value) : value;
3407
3437
  }
3408
3438
 
3409
3439
  // src/without-trailing-slash.ts
@@ -3438,6 +3468,27 @@ async function* executeTool({
3438
3468
  // src/index.ts
3439
3469
  __reExport(index_exports, require("@standard-schema/spec"), module.exports);
3440
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
+ }
3441
3492
  // Annotate the CommonJS export names for ESM import in node:
3442
3493
  0 && (module.exports = {
3443
3494
  DEFAULT_MAX_DOWNLOAD_SIZE,
@@ -3477,9 +3528,11 @@ var import_stream2 = require("eventsource-parser/stream");
3477
3528
  getRuntimeEnvironmentUserAgent,
3478
3529
  injectJsonInstructionIntoMessages,
3479
3530
  isAbortError,
3531
+ isArrayBuffer,
3480
3532
  isBrowserRuntime,
3481
3533
  isParsableJson,
3482
3534
  isSameOrigin,
3535
+ isUint8Array,
3483
3536
  isUrlSupported,
3484
3537
  isValidator,
3485
3538
  jsonSchema,
@@ -3501,7 +3554,9 @@ var import_stream2 = require("eventsource-parser/stream");
3501
3554
  resolve,
3502
3555
  safeParseJSON,
3503
3556
  safeValidateTypes,
3557
+ secureJsonParse,
3504
3558
  standardSchemaValidator,
3559
+ stringifyWithBigIntAndCycles,
3505
3560
  tool,
3506
3561
  validateDownloadUrl,
3507
3562
  validateTypes,