@mastra/schema-compat
Version:
Tool schema compatibility layer for Mastra.ai
147 lines • 8.65 kB
TypeScript
import type { z as zV3 } from 'zod/v3';
import type { z as zV4 } from 'zod/v4';
import type { Targets } from 'zod-to-json-schema';
import type { JSONSchema7, Schema } from './json-schema/index.js';
import type { PublicSchema, StandardSchemaWithJSON } from './schema.js';
import * as v3 from './schema-compatibility-v3.js';
import * as v4 from './schema-compatibility-v4.js';
import type { ZodType, ZodUnion } from './schema.types.js';
import type { ModelInformation } from './types.js';
export { ALL_STRING_CHECKS, ALL_NUMBER_CHECKS, ALL_ARRAY_CHECKS, UNSUPPORTED_ZOD_TYPES as UNSUPPORTED_ZOD_TYPES_V3, SUPPORTED_ZOD_TYPES as SUPPORTED_ZOD_TYPES_V3, } from './schema-compatibility-v3.js';
export type { UnsupportedZodType as UnsupportedZodTypeV3, ShapeValue as ShapeValueV3, StringCheckType, NumberCheckType, ArrayCheckType, AllZodType as AllZodTypeV3, } from './schema-compatibility-v3.js';
export { UNSUPPORTED_ZOD_TYPES as UNSUPPORTED_ZOD_TYPES_V4, SUPPORTED_ZOD_TYPES as SUPPORTED_ZOD_TYPES_V4, } from './schema-compatibility-v4.js';
export type { UnsupportedZodType as UnsupportedZodTypeV4, ShapeValue as ShapeValueV4, AllZodType as AllZodTypeV4, } from './schema-compatibility-v4.js';
type ConstraintHelperText = string[];
export declare abstract class SchemaCompatLayer {
private model;
private v3Layer;
private v4Layer;
/**
* Creates a new schema compatibility instance.
*
* @param model - The language model this compatibility layer applies to
*/
constructor(model: ModelInformation);
preProcessJSONNode(_schema: JSONSchema7, _parentSchema?: JSONSchema7): void;
postProcessJSONNode(_schema: JSONSchema7, _parentSchema?: JSONSchema7): void;
/**
* Gets the language model associated with this compatibility layer.
*
* @returns The language model instance
*/
getModel(): ModelInformation;
getUnsupportedZodTypes(value: ZodType): readonly string[];
isOptional(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodOptional<any> | zV4.ZodOptional<any>;
isObj(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodObject<any, any, any, any, any> | zV4.ZodObject<any, any>;
isNull(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodNull | zV4.ZodNull;
isNullable(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodNullable<any> | zV4.ZodNullable<any>;
isArr(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodArray<any, any> | zV4.ZodArray<any>;
isUnion(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]> | zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>;
isString(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodString | zV4.ZodString;
isNumber(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodNumber | zV4.ZodNumber;
isDate(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodDate | zV4.ZodDate;
isDefault(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodDefault<any> | zV4.ZodDefault<any>;
isIntersection(v: zV3.ZodType | zV4.ZodType): v is zV3.ZodIntersection<any, any> | zV4.ZodIntersection<any, any>;
abstract shouldApply(): boolean;
abstract getSchemaTarget(): Targets | undefined;
abstract processZodType(value: ZodType): ZodType;
defaultZodObjectHandler(value: zV3.ZodObject<any, any, any, any, any> | zV4.ZodObject<any, any>, options?: {
passthrough?: boolean;
}): zV3.ZodObject<any, any, any, any, any> | zV4.ZodObject<any, any>;
mergeParameterDescription(description: string | undefined, constraints: ConstraintHelperText): string | undefined;
defaultUnsupportedZodTypeHandler(value: zV3.ZodType | zV4.ZodType, throwOnTypes?: readonly (v3.UnsupportedZodType | v4.UnsupportedZodType)[]): zV3.ZodType | zV4.ZodType;
defaultZodArrayHandler(value: zV3.ZodArray<any, any> | zV4.ZodArray<any>, handleChecks?: readonly v3.ArrayCheckType[]): zV3.ZodArray<any, any> | zV4.ZodArray<any>;
defaultZodUnionHandler(value: ZodUnion): zV3.ZodType | zV4.ZodType;
defaultZodStringHandler(value: zV3.ZodString | zV4.ZodString, handleChecks?: readonly v3.StringCheckType[]): zV3.ZodString | zV4.ZodString;
defaultZodNumberHandler(value: zV3.ZodNumber | zV4.ZodNumber, handleChecks?: readonly v3.NumberCheckType[]): zV3.ZodNumber | zV4.ZodNumber;
defaultZodDateHandler(value: zV3.ZodDate | zV4.ZodDate): zV3.ZodString | zV4.ZodString;
defaultZodOptionalHandler(value: zV3.ZodOptional<any> | zV4.ZodOptional<any>, handleTypes?: readonly string[]): zV3.ZodType | zV4.ZodType;
defaultZodNullableHandler(value: zV3.ZodNullable<any> | zV4.ZodNullable<any>, handleTypes?: readonly string[]): zV3.ZodType | zV4.ZodType;
defaultZodIntersectionHandler(value: zV3.ZodIntersection<any, any> | zV4.ZodIntersection<any, any>): zV3.ZodType | zV4.ZodType;
/**
* @deprecated please use processToCompatSchema to usse StandardSchemaWithJSON
* @param zodSchema
* @returns
*/
processToAISDKSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): Schema;
/**
* @param schema
* @returns
*/
processToJSONSchema(schema: PublicSchema<any>, io?: 'input' | 'output'): JSONSchema7;
processToCompatSchema<T>(schema: PublicSchema<T>): StandardSchemaWithJSON<T>;
/**
* Default handler for JSON Schema objects.
* Processes object schemas with properties and required fields.
*/
protected defaultObjectHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema arrays.
* Converts array constraints (minItems, maxItems) to description text.
*/
protected defaultArrayHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema strings.
* Converts string constraints (minLength, maxLength, pattern, format) to description text.
*/
protected defaultStringHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema numbers/integers.
* Converts number constraints (minimum, maximum, multipleOf, exclusiveMinimum, exclusiveMaximum) to description text.
*/
protected defaultNumberHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema unions (anyOf/oneOf).
* Processes union schemas and can convert anyOf patterns to type arrays for simple primitives.
*/
protected defaultUnionHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema allOf (intersection) types.
* Flattens allOf sub-schemas by merging properties and required arrays into a single object schema.
*/
protected defaultAllOfHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema nullable types.
* Ensures nullable types are represented correctly.
*/
protected defaultNullableHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for JSON Schema dates (string with date/date-time format).
* Converts date formats to string type with format constraint in description.
*/
protected defaultDateHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for empty JSON schemas.
* Converts empty {} schemas to a union of primitive types.
*/
protected defaultEmptySchemaHandler(schema: JSONSchema7): JSONSchema7;
/**
* Default handler for unsupported JSON Schema features.
* Can be used to strip or convert unsupported keywords.
*/
protected defaultUnsupportedHandler(schema: JSONSchema7, unsupportedKeywords?: string[]): JSONSchema7;
protected isObjectSchema(schema: JSONSchema7): boolean;
protected isArraySchema(schema: JSONSchema7): boolean;
protected isStringSchema(schema: JSONSchema7): boolean;
protected isNumberSchema(schema: JSONSchema7): boolean;
protected isUnionSchema(schema: JSONSchema7): boolean;
protected isAllOfSchema(schema: JSONSchema7): schema is JSONSchema7 & {
allOf: JSONSchema7[];
};
/**
* Checks if a property is optional within a parent object schema.
* A property is optional if it's not in the parent's `required` array.
* @param propertyName - The name of the property to check
* @param parentSchema - The parent object schema containing the property
*/
protected isOptionalProperty(propertyName: string, parentSchema: JSONSchema7): boolean;
/**
* Converts a Zod schema to JSON Schema using the standard-schema interface
* and applies pre/post processing via traverse.
*
* Uses 'input' io mode so that fields with defaults are optional (appropriate for tool parameters).
* @deprecated please use processToCompatSchema
*/
toJSONSchema(zodSchema: ZodType): JSONSchema7;
}
//# sourceMappingURL=schema-compatibility.d.ts.map