@mastra/schema-compat
Version:
Tool schema compatibility layer for Mastra.ai
24 lines • 1.38 kB
TypeScript
import type { StandardSchemaWithJSON } from './standard-schema/standard-schema.types.js';
/**
* Recursively converts null values to undefined in an object based on which
* properties are optional in the JSON Schema. This is needed because OpenAI
* strict mode sends null for optional fields, but schemas like Zod's .optional()
* reject null.
*
* Only converts null→undefined for properties that are NOT in the schema's
* `required` array, preserving null for explicitly .nullable() fields.
*/
export declare function transformNullToUndefined(value: unknown, jsonSchema: Record<string, unknown>): unknown;
/**
* Wraps a StandardSchemaWithJSON to transform null values to undefined for
* optional fields before validation. This is a schema-agnostic solution for
* OpenAI strict mode, which sends null for optional fields.
*
* The wrapper:
* 1. Extracts the JSON Schema from the inner schema to determine optional fields
* 2. Before validation, transforms null→undefined for non-required properties
* 3. Delegates validation to the inner schema with the transformed value
* 4. Delegates JSON Schema conversion to the inner schema unchanged
*/
export declare function wrapSchemaWithNullTransform<Input = unknown, Output = Input>(schema: StandardSchemaWithJSON<Input, Output>): StandardSchemaWithJSON<Input, Output>;
//# sourceMappingURL=null-to-undefined.d.ts.map