@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
77 lines • 2.98 kB
TypeScript
import type { RequestContext } from '../request-context/index.js';
import type { PublicSchema, StandardSchemaWithJSON } from '../schema/index.js';
/**
* Formatted validation errors structure.
* Contains `errors` array for messages at this level, and `fields` for nested field errors.
*/
export type FormattedValidationErrors<T = unknown> = {
errors: string[];
fields: T extends object ? {
[K in keyof T]?: FormattedValidationErrors<T[K]>;
} : unknown;
};
export interface ValidationError<T = unknown> {
error: true;
message: string;
validationErrors: FormattedValidationErrors<T>;
}
export declare function isValidationError(value: unknown): value is ValidationError;
/**
* Validates raw suspend data against a schema.
*
* @param schema The schema to validate against
* @param suspendData The raw suspend data to validate
* @param toolId Optional tool ID for better error messages
* @returns The validated data or a validation error
*/
export declare function validateToolSuspendData<T = unknown>(schema: StandardSchemaWithJSON<T> | undefined, suspendData: unknown, toolId?: string): {
data: T;
error?: undefined;
} | {
data?: undefined;
error: ValidationError<T>;
};
/**
* Validates raw input data against a schema.
*
* @param schema The schema to validate against (or undefined to skip validation)
* @param input The raw input data to validate
* @param toolId Optional tool ID for better error messages
* @returns The validated data or a validation error
*/
export declare function validateToolInput<T = unknown>(schema: StandardSchemaWithJSON<T> | undefined, input: unknown, toolId?: string): {
data: T;
error?: undefined;
} | {
data?: undefined;
error: ValidationError<T>;
};
/**
* Validates tool output data against a schema.
*
* @param schema The schema to validate against
* @param output The output data to validate
* @param toolId Optional tool ID for better error messages
* @returns The validated data or a validation error
*/
export declare function validateToolOutput<T = unknown>(schema: StandardSchemaWithJSON<T> | undefined, output: unknown, toolId?: string, suspendCalled?: boolean): {
data: T;
error?: undefined;
} | {
data?: undefined;
error: ValidationError<T>;
};
/**
* Validates request context data against a schema.
* This is used to validate the request context before tool execution.
*
* @param schema The schema to validate against (PublicSchema which accepts Zod, JSONSchema, etc.)
* @param requestContext The request context to validate
* @param identifier Optional identifier (tool/step ID) for better error messages
* @returns The validated data or a validation error
*/
export declare function validateRequestContext<T = any>(schema: PublicSchema<T> | undefined, requestContext: RequestContext | undefined, identifier?: string): {
data: T | Record<string, any>;
error?: ValidationError<T>;
};
//# sourceMappingURL=validation.d.ts.map