@ai-sdk/provider-utils 3.0.10 → 3.0.12

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,18 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 17f9872: fix: revert zod import change
8
+
9
+ ## 3.0.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 6f0644c: chore: use import \* from zod/v4
14
+ - 6f0644c: chore: load zod schemas lazily
15
+
3
16
  ## 3.0.10
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { JSONValue, JSONParseError, TypeValidationError, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
1
+ import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
2
2
  import * as z4 from 'zod/v4';
3
- import { ZodType, z } from 'zod/v4';
4
- import * as z3 from 'zod/v3';
3
+ import { ZodType } from 'zod/v4';
5
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
5
  export * from '@standard-schema/spec';
6
+ import * as z3 from 'zod/v3';
7
7
  export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
8
8
 
9
9
  declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
@@ -43,20 +43,6 @@ 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
-
60
46
  /**
61
47
  Creates an ID generator.
62
48
  The total length of the ID is the sum of the prefix, separator, and random part length.
@@ -114,7 +100,19 @@ type Validator<OBJECT = unknown> = {
114
100
  */
115
101
  declare function validator<OBJECT>(validate?: undefined | ((value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>)): Validator<OBJECT>;
116
102
  declare function isValidator(value: unknown): value is Validator;
117
- declare function asValidator<OBJECT>(value: Validator<OBJECT> | StandardSchemaV1<unknown, OBJECT>): Validator<OBJECT>;
103
+ /**
104
+ * Creates a validator with deferred creation.
105
+ * This is important to reduce the startup time of the library
106
+ * and to avoid initializing unused validators.
107
+ *
108
+ * @param createValidator A function that creates a validator.
109
+ * @returns A function that returns a validator.
110
+ */
111
+ declare function lazyValidator<OBJECT>(createValidator: () => Validator<OBJECT>): LazyValidator<OBJECT>;
112
+ type LazyValidator<OBJECT> = () => Validator<OBJECT>;
113
+ type FlexibleValidator<OBJECT> = Validator<OBJECT> | LazyValidator<OBJECT> | StandardSchemaV1<unknown, OBJECT>;
114
+ type InferValidator<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazyValidator<infer T> ? T : SCHEMA extends Validator<infer T> ? T : never;
115
+ declare function asValidator<OBJECT>(value: FlexibleValidator<OBJECT>): Validator<OBJECT>;
118
116
  declare function standardSchemaValidator<OBJECT>(standardSchema: StandardSchemaV1<unknown, OBJECT>): Validator<OBJECT>;
119
117
 
120
118
  /**
@@ -137,7 +135,7 @@ declare function parseJSON(options: {
137
135
  */
138
136
  declare function parseJSON<T>(options: {
139
137
  text: string;
140
- schema: z4.core.$ZodType<T> | z3.Schema<T> | Validator<T>;
138
+ schema: FlexibleValidator<T>;
141
139
  }): Promise<T>;
142
140
  type ParseResult<T> = {
143
141
  success: true;
@@ -168,7 +166,7 @@ declare function safeParseJSON(options: {
168
166
  */
169
167
  declare function safeParseJSON<T>(options: {
170
168
  text: string;
171
- schema: z4.core.$ZodType<T> | z3.Schema<T> | Validator<T>;
169
+ schema: FlexibleValidator<T>;
172
170
  }): Promise<ParseResult<T>>;
173
171
  declare function isParsableJson(input: string): boolean;
174
172
 
@@ -182,13 +180,13 @@ type ResponseHandler<RETURN_TYPE> = (options: {
182
180
  responseHeaders?: Record<string, string>;
183
181
  }>;
184
182
  declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
185
- errorSchema: ZodType<T>;
183
+ errorSchema: FlexibleValidator<T>;
186
184
  errorToMessage: (error: T) => string;
187
185
  isRetryable?: (response: Response, error?: T) => boolean;
188
186
  }) => ResponseHandler<APICallError>;
189
- declare const createEventSourceResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
187
+ declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleValidator<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
190
188
  declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
191
- declare const createJsonResponseHandler: <T>(responseSchema: ZodType<T>) => ResponseHandler<T>;
189
+ declare const createJsonResponseHandler: <T>(responseSchema: FlexibleValidator<T>) => ResponseHandler<T>;
192
190
  declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
193
191
  declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
194
192
 
@@ -205,6 +203,8 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
205
203
  responseHeaders?: Record<string, string>;
206
204
  }>;
207
205
 
206
+ declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
207
+
208
208
  declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
209
209
  messages: LanguageModelV2Prompt;
210
210
  schema?: JSONSchema7;
@@ -282,14 +282,14 @@ declare function mediaTypeToExtension(mediaType: string): string;
282
282
  */
283
283
  declare function parseJsonEventStream<T>({ stream, schema, }: {
284
284
  stream: ReadableStream<Uint8Array>;
285
- schema: ZodType<T>;
285
+ schema: FlexibleValidator<T>;
286
286
  }): ReadableStream<ParseResult<T>>;
287
287
 
288
- declare function parseProviderOptions<T>({ provider, providerOptions, schema, }: {
288
+ declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
289
289
  provider: string;
290
290
  providerOptions: Record<string, unknown> | undefined;
291
- schema: z.core.$ZodType<T, any>;
292
- }): Promise<T | undefined>;
291
+ schema: FlexibleValidator<OPTIONS>;
292
+ }): Promise<OPTIONS | undefined>;
293
293
 
294
294
  declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
295
295
  url: string;
@@ -352,18 +352,28 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
352
352
  */
353
353
  readonly jsonSchema: JSONSchema7;
354
354
  };
355
- type FlexibleSchema<T> = z4.core.$ZodType<T, any> | z3.Schema<T, z3.ZodTypeDef, any> | Schema<T>;
356
- type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.core.$ZodType ? z4.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? T : never;
355
+ /**
356
+ * Creates a schema with deferred creation.
357
+ * This is important to reduce the startup time of the library
358
+ * and to avoid initializing unused validators.
359
+ *
360
+ * @param createValidator A function that creates a schema.
361
+ * @returns A function that returns a schema.
362
+ */
363
+ declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
364
+ type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
365
+ type FlexibleSchema<SCHEMA> = z4.core.$ZodType<SCHEMA, any> | z3.Schema<SCHEMA, z3.ZodTypeDef, any> | Schema<SCHEMA> | LazySchema<SCHEMA>;
366
+ type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.core.$ZodType ? z4.infer<SCHEMA> : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
357
367
  /**
358
368
  * Create a schema using a JSON Schema.
359
369
  *
360
370
  * @param jsonSchema The JSON Schema for the schema.
361
371
  * @param options.validate Optional. A validation function for the schema.
362
372
  */
363
- declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
373
+ declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | (() => JSONSchema7), { validate, }?: {
364
374
  validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
365
375
  }): Schema<OBJECT>;
366
- declare function asSchema<OBJECT>(schema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any> | Schema<OBJECT> | undefined): Schema<OBJECT>;
376
+ declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
367
377
 
368
378
  /**
369
379
  Additional provider-specific options.
@@ -799,7 +809,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
799
809
  */
800
810
  declare function validateTypes<OBJECT>({ value, schema, }: {
801
811
  value: unknown;
802
- schema: StandardSchemaV1<unknown, OBJECT> | Validator<OBJECT>;
812
+ schema: FlexibleValidator<OBJECT>;
803
813
  }): Promise<OBJECT>;
804
814
  /**
805
815
  * Safely validates the types of an unknown object using a schema and
@@ -812,7 +822,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
812
822
  */
813
823
  declare function safeValidateTypes<OBJECT>({ value, schema, }: {
814
824
  value: unknown;
815
- schema: StandardSchemaV1<unknown, OBJECT> | Validator<OBJECT>;
825
+ schema: FlexibleValidator<OBJECT>;
816
826
  }): Promise<{
817
827
  success: true;
818
828
  value: OBJECT;
@@ -823,6 +833,20 @@ declare function safeValidateTypes<OBJECT>({ value, schema, }: {
823
833
  rawValue: unknown;
824
834
  }>;
825
835
 
836
+ declare const VERSION: string;
837
+
838
+ /**
839
+ * Appends suffix parts to the `user-agent` header.
840
+ * If a `user-agent` header already exists, the suffix parts are appended to it.
841
+ * If no `user-agent` header exists, a new one is created with the suffix parts.
842
+ * Automatically removes undefined entries from the headers.
843
+ *
844
+ * @param headers - The original headers.
845
+ * @param userAgentSuffixParts - The parts to append to the `user-agent` header.
846
+ * @returns The new headers with the `user-agent` header set or updated.
847
+ */
848
+ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
849
+
826
850
  declare function withoutTrailingSlash(url: string | undefined): string | undefined;
827
851
 
828
852
  declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
@@ -906,6 +930,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
906
930
  dynamic?: boolean;
907
931
  }
908
932
 
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 };
933
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, 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 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, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { JSONValue, JSONParseError, TypeValidationError, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
1
+ import { JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
2
2
  import * as z4 from 'zod/v4';
3
- import { ZodType, z } from 'zod/v4';
4
- import * as z3 from 'zod/v3';
3
+ import { ZodType } from 'zod/v4';
5
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
5
  export * from '@standard-schema/spec';
6
+ import * as z3 from 'zod/v3';
7
7
  export { EventSourceMessage, EventSourceParserStream } from 'eventsource-parser/stream';
8
8
 
9
9
  declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
@@ -43,20 +43,6 @@ 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
-
60
46
  /**
61
47
  Creates an ID generator.
62
48
  The total length of the ID is the sum of the prefix, separator, and random part length.
@@ -114,7 +100,19 @@ type Validator<OBJECT = unknown> = {
114
100
  */
115
101
  declare function validator<OBJECT>(validate?: undefined | ((value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>)): Validator<OBJECT>;
116
102
  declare function isValidator(value: unknown): value is Validator;
117
- declare function asValidator<OBJECT>(value: Validator<OBJECT> | StandardSchemaV1<unknown, OBJECT>): Validator<OBJECT>;
103
+ /**
104
+ * Creates a validator with deferred creation.
105
+ * This is important to reduce the startup time of the library
106
+ * and to avoid initializing unused validators.
107
+ *
108
+ * @param createValidator A function that creates a validator.
109
+ * @returns A function that returns a validator.
110
+ */
111
+ declare function lazyValidator<OBJECT>(createValidator: () => Validator<OBJECT>): LazyValidator<OBJECT>;
112
+ type LazyValidator<OBJECT> = () => Validator<OBJECT>;
113
+ type FlexibleValidator<OBJECT> = Validator<OBJECT> | LazyValidator<OBJECT> | StandardSchemaV1<unknown, OBJECT>;
114
+ type InferValidator<SCHEMA> = SCHEMA extends StandardSchemaV1<unknown, infer T> ? T : SCHEMA extends LazyValidator<infer T> ? T : SCHEMA extends Validator<infer T> ? T : never;
115
+ declare function asValidator<OBJECT>(value: FlexibleValidator<OBJECT>): Validator<OBJECT>;
118
116
  declare function standardSchemaValidator<OBJECT>(standardSchema: StandardSchemaV1<unknown, OBJECT>): Validator<OBJECT>;
119
117
 
120
118
  /**
@@ -137,7 +135,7 @@ declare function parseJSON(options: {
137
135
  */
138
136
  declare function parseJSON<T>(options: {
139
137
  text: string;
140
- schema: z4.core.$ZodType<T> | z3.Schema<T> | Validator<T>;
138
+ schema: FlexibleValidator<T>;
141
139
  }): Promise<T>;
142
140
  type ParseResult<T> = {
143
141
  success: true;
@@ -168,7 +166,7 @@ declare function safeParseJSON(options: {
168
166
  */
169
167
  declare function safeParseJSON<T>(options: {
170
168
  text: string;
171
- schema: z4.core.$ZodType<T> | z3.Schema<T> | Validator<T>;
169
+ schema: FlexibleValidator<T>;
172
170
  }): Promise<ParseResult<T>>;
173
171
  declare function isParsableJson(input: string): boolean;
174
172
 
@@ -182,13 +180,13 @@ type ResponseHandler<RETURN_TYPE> = (options: {
182
180
  responseHeaders?: Record<string, string>;
183
181
  }>;
184
182
  declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
185
- errorSchema: ZodType<T>;
183
+ errorSchema: FlexibleValidator<T>;
186
184
  errorToMessage: (error: T) => string;
187
185
  isRetryable?: (response: Response, error?: T) => boolean;
188
186
  }) => ResponseHandler<APICallError>;
189
- declare const createEventSourceResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
187
+ declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleValidator<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
190
188
  declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodType<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
191
- declare const createJsonResponseHandler: <T>(responseSchema: ZodType<T>) => ResponseHandler<T>;
189
+ declare const createJsonResponseHandler: <T>(responseSchema: FlexibleValidator<T>) => ResponseHandler<T>;
192
190
  declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
193
191
  declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
194
192
 
@@ -205,6 +203,8 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
205
203
  responseHeaders?: Record<string, string>;
206
204
  }>;
207
205
 
206
+ declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
207
+
208
208
  declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
209
209
  messages: LanguageModelV2Prompt;
210
210
  schema?: JSONSchema7;
@@ -282,14 +282,14 @@ declare function mediaTypeToExtension(mediaType: string): string;
282
282
  */
283
283
  declare function parseJsonEventStream<T>({ stream, schema, }: {
284
284
  stream: ReadableStream<Uint8Array>;
285
- schema: ZodType<T>;
285
+ schema: FlexibleValidator<T>;
286
286
  }): ReadableStream<ParseResult<T>>;
287
287
 
288
- declare function parseProviderOptions<T>({ provider, providerOptions, schema, }: {
288
+ declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
289
289
  provider: string;
290
290
  providerOptions: Record<string, unknown> | undefined;
291
- schema: z.core.$ZodType<T, any>;
292
- }): Promise<T | undefined>;
291
+ schema: FlexibleValidator<OPTIONS>;
292
+ }): Promise<OPTIONS | undefined>;
293
293
 
294
294
  declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
295
295
  url: string;
@@ -352,18 +352,28 @@ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
352
352
  */
353
353
  readonly jsonSchema: JSONSchema7;
354
354
  };
355
- type FlexibleSchema<T> = z4.core.$ZodType<T, any> | z3.Schema<T, z3.ZodTypeDef, any> | Schema<T>;
356
- type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.core.$ZodType ? z4.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? T : never;
355
+ /**
356
+ * Creates a schema with deferred creation.
357
+ * This is important to reduce the startup time of the library
358
+ * and to avoid initializing unused validators.
359
+ *
360
+ * @param createValidator A function that creates a schema.
361
+ * @returns A function that returns a schema.
362
+ */
363
+ declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
364
+ type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
365
+ type FlexibleSchema<SCHEMA> = z4.core.$ZodType<SCHEMA, any> | z3.Schema<SCHEMA, z3.ZodTypeDef, any> | Schema<SCHEMA> | LazySchema<SCHEMA>;
366
+ type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.core.$ZodType ? z4.infer<SCHEMA> : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
357
367
  /**
358
368
  * Create a schema using a JSON Schema.
359
369
  *
360
370
  * @param jsonSchema The JSON Schema for the schema.
361
371
  * @param options.validate Optional. A validation function for the schema.
362
372
  */
363
- declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
373
+ declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | (() => JSONSchema7), { validate, }?: {
364
374
  validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
365
375
  }): Schema<OBJECT>;
366
- declare function asSchema<OBJECT>(schema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any> | Schema<OBJECT> | undefined): Schema<OBJECT>;
376
+ declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
367
377
 
368
378
  /**
369
379
  Additional provider-specific options.
@@ -799,7 +809,7 @@ declare function convertToBase64(value: string | Uint8Array): string;
799
809
  */
800
810
  declare function validateTypes<OBJECT>({ value, schema, }: {
801
811
  value: unknown;
802
- schema: StandardSchemaV1<unknown, OBJECT> | Validator<OBJECT>;
812
+ schema: FlexibleValidator<OBJECT>;
803
813
  }): Promise<OBJECT>;
804
814
  /**
805
815
  * Safely validates the types of an unknown object using a schema and
@@ -812,7 +822,7 @@ declare function validateTypes<OBJECT>({ value, schema, }: {
812
822
  */
813
823
  declare function safeValidateTypes<OBJECT>({ value, schema, }: {
814
824
  value: unknown;
815
- schema: StandardSchemaV1<unknown, OBJECT> | Validator<OBJECT>;
825
+ schema: FlexibleValidator<OBJECT>;
816
826
  }): Promise<{
817
827
  success: true;
818
828
  value: OBJECT;
@@ -823,6 +833,20 @@ declare function safeValidateTypes<OBJECT>({ value, schema, }: {
823
833
  rawValue: unknown;
824
834
  }>;
825
835
 
836
+ declare const VERSION: string;
837
+
838
+ /**
839
+ * Appends suffix parts to the `user-agent` header.
840
+ * If a `user-agent` header already exists, the suffix parts are appended to it.
841
+ * If no `user-agent` header exists, a new one is created with the suffix parts.
842
+ * Automatically removes undefined entries from the headers.
843
+ *
844
+ * @param headers - The original headers.
845
+ * @param userAgentSuffixParts - The parts to append to the `user-agent` header.
846
+ * @returns The new headers with the `user-agent` header set or updated.
847
+ */
848
+ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
849
+
826
850
  declare function withoutTrailingSlash(url: string | undefined): string | undefined;
827
851
 
828
852
  declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
@@ -906,6 +930,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
906
930
  dynamic?: boolean;
907
931
  }
908
932
 
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 };
933
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, 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 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, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };