@ai-sdk/provider-utils 4.0.52 → 4.0.54

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,23 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 4.0.54
4
+
5
+ ### Patch Changes
6
+
7
+ - 069a945: Fix Google `embedMany` calls with more than 100 values by keeping per-value multimodal content aligned across automatic batches, including text-only entries. Validate content length before sending requests and validate each batch's provider options after middleware transforms them.
8
+ - d1a36d2: fix(ai): execute manually approved tool inputs produced by schema transforms
9
+
10
+ Preserve approved inputs during revalidation and reject histories whose reconstructed schema output differs, including signed approvals with missing original input. Validate transformed UI tool inputs against the reconstructed output before returning them as static tool parts.
11
+
12
+ - f7f36d2: chore: enable dead code lint rules
13
+
14
+ ## 4.0.53
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [da2e17b]
19
+ - @ai-sdk/provider@3.0.17
20
+
3
21
  ## 4.0.52
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
1
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, SharedV3ProviderOptions, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -172,6 +172,28 @@ declare class DownloadError extends AISDKError {
172
172
  static isInstance(error: unknown): error is DownloadError;
173
173
  }
174
174
 
175
+ /**
176
+ * Symbol for exposing the UTF-8 input byte budget of an embedding model.
177
+ *
178
+ * This capability is experimental and intentionally lives outside the versioned
179
+ * embedding model specification.
180
+ */
181
+ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
182
+ /**
183
+ * Symbol for transforming provider options for an automatically batched
184
+ * embedding model call.
185
+ *
186
+ * This capability is experimental and intentionally lives outside the versioned
187
+ * embedding model specification.
188
+ */
189
+ declare const EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER: unique symbol;
190
+ type EmbeddingModelProviderOptionsTransformer = (options: {
191
+ providerOptions: SharedV3ProviderOptions | undefined;
192
+ values: Array<string>;
193
+ startIndex: number;
194
+ endIndex: number;
195
+ }) => SharedV3ProviderOptions | undefined | PromiseLike<SharedV3ProviderOptions | undefined>;
196
+
175
197
  /**
176
198
  * Default maximum download size: 2 GiB.
177
199
  *
@@ -203,14 +225,6 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
203
225
  maxBytes?: number;
204
226
  }): Promise<Uint8Array>;
205
227
 
206
- /**
207
- * Symbol for exposing the UTF-8 input byte budget of an embedding model.
208
- *
209
- * This capability is experimental and intentionally lives outside the versioned
210
- * embedding model specification.
211
- */
212
- declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
213
-
214
228
  /**
215
229
  * Fetches a URL while enforcing the SSRF download guard on every hop.
216
230
  *
@@ -950,6 +964,13 @@ type ToolApprovalRequest = {
950
964
  * Present only when `experimental_toolApprovalSecret` is configured.
951
965
  */
952
966
  signature?: string;
967
+ /**
968
+ * Tool input before input schema validation and transformation.
969
+ *
970
+ * This is included when it differs from the validated tool input so that
971
+ * approved tool calls can be safely revalidated before execution.
972
+ */
973
+ inputSchemaInput?: unknown;
953
974
  };
954
975
 
955
976
  /**
@@ -1563,4 +1584,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1563
1584
  */
1564
1585
  type ToolCallOptions = ToolExecutionOptions;
1565
1586
 
1566
- 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 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 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, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1587
+ 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 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, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
1
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, SharedV3ProviderOptions, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -172,6 +172,28 @@ declare class DownloadError extends AISDKError {
172
172
  static isInstance(error: unknown): error is DownloadError;
173
173
  }
174
174
 
175
+ /**
176
+ * Symbol for exposing the UTF-8 input byte budget of an embedding model.
177
+ *
178
+ * This capability is experimental and intentionally lives outside the versioned
179
+ * embedding model specification.
180
+ */
181
+ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
182
+ /**
183
+ * Symbol for transforming provider options for an automatically batched
184
+ * embedding model call.
185
+ *
186
+ * This capability is experimental and intentionally lives outside the versioned
187
+ * embedding model specification.
188
+ */
189
+ declare const EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER: unique symbol;
190
+ type EmbeddingModelProviderOptionsTransformer = (options: {
191
+ providerOptions: SharedV3ProviderOptions | undefined;
192
+ values: Array<string>;
193
+ startIndex: number;
194
+ endIndex: number;
195
+ }) => SharedV3ProviderOptions | undefined | PromiseLike<SharedV3ProviderOptions | undefined>;
196
+
175
197
  /**
176
198
  * Default maximum download size: 2 GiB.
177
199
  *
@@ -203,14 +225,6 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
203
225
  maxBytes?: number;
204
226
  }): Promise<Uint8Array>;
205
227
 
206
- /**
207
- * Symbol for exposing the UTF-8 input byte budget of an embedding model.
208
- *
209
- * This capability is experimental and intentionally lives outside the versioned
210
- * embedding model specification.
211
- */
212
- declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
213
-
214
228
  /**
215
229
  * Fetches a URL while enforcing the SSRF download guard on every hop.
216
230
  *
@@ -950,6 +964,13 @@ type ToolApprovalRequest = {
950
964
  * Present only when `experimental_toolApprovalSecret` is configured.
951
965
  */
952
966
  signature?: string;
967
+ /**
968
+ * Tool input before input schema validation and transformation.
969
+ *
970
+ * This is included when it differs from the validated tool input so that
971
+ * approved tool calls can be safely revalidated before execution.
972
+ */
973
+ inputSchemaInput?: unknown;
953
974
  };
954
975
 
955
976
  /**
@@ -1563,4 +1584,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1563
1584
  */
1564
1585
  type ToolCallOptions = ToolExecutionOptions;
1565
1586
 
1566
- 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 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 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, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1587
+ 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 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, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  DelayedPromise: () => DelayedPromise,
35
35
  DownloadError: () => DownloadError,
36
36
  EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: () => EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
37
+ EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER: () => EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER,
37
38
  EventSourceParserStream: () => import_stream2.EventSourceParserStream,
38
39
  VERSION: () => VERSION,
39
40
  asSchema: () => asSchema,
@@ -106,7 +107,7 @@ function combineHeaders(...headers) {
106
107
  return headers.reduce(
107
108
  (combinedHeaders, currentHeaders) => ({
108
109
  ...combinedHeaders,
109
- ...currentHeaders != null ? currentHeaders : {}
110
+ ...currentHeaders
110
111
  }),
111
112
  {}
112
113
  );
@@ -184,7 +185,7 @@ function createToolNameMapping({
184
185
  // src/delay.ts
185
186
  async function delay(delayInMs, options) {
186
187
  if (delayInMs == null) {
187
- return Promise.resolve();
188
+ return;
188
189
  }
189
190
  const signal = options == null ? void 0 : options.abortSignal;
190
191
  return new Promise((resolve2, reject) => {
@@ -401,7 +402,6 @@ function validateDownloadUrl(url) {
401
402
  message: `URL with IP address ${hostname} is not allowed`
402
403
  });
403
404
  }
404
- return;
405
405
  }
406
406
  }
407
407
  function validateDownloadAddress({
@@ -739,6 +739,9 @@ async function downloadBlob(url, options) {
739
739
  var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL = /* @__PURE__ */ Symbol.for(
740
740
  "vercel.ai.embeddingModel.maxInputBytesPerCall"
741
741
  );
742
+ var EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER = /* @__PURE__ */ Symbol.for(
743
+ "vercel.ai.embeddingModel.providerOptionsTransformer"
744
+ );
742
745
 
743
746
  // src/generate-id.ts
744
747
  var import_provider2 = require("@ai-sdk/provider");
@@ -923,7 +926,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
923
926
  }
924
927
 
925
928
  // src/version.ts
926
- var VERSION = true ? "4.0.52" : "0.0.0-test";
929
+ var VERSION = true ? "4.0.54" : "0.0.0-test";
927
930
 
928
931
  // src/get-from-api.ts
929
932
  var getOriginalFetch = () => globalThis.fetch;
@@ -1496,7 +1499,7 @@ var zodPatterns = {
1496
1499
  /**
1497
1500
  * `a-z` was added to replicate /i flag
1498
1501
  */
1499
- email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
1502
+ email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}$/,
1500
1503
  /**
1501
1504
  * Constructed a valid Unicode RegExp
1502
1505
  *
@@ -2873,7 +2876,7 @@ async function resolve(value) {
2873
2876
  if (typeof value === "function") {
2874
2877
  value = value();
2875
2878
  }
2876
- return Promise.resolve(value);
2879
+ return value;
2877
2880
  }
2878
2881
 
2879
2882
  // src/retry-with-exponential-backoff.ts
@@ -3211,6 +3214,7 @@ var import_stream2 = require("eventsource-parser/stream");
3211
3214
  DelayedPromise,
3212
3215
  DownloadError,
3213
3216
  EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
3217
+ EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER,
3214
3218
  EventSourceParserStream,
3215
3219
  VERSION,
3216
3220
  asSchema,