UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

90 lines 2.82 kB
/** * TaskOutputFormatter * Implements structured output format controls with schema validation * Optimized for: * - Minimal memory overhead * - Efficient schema validation * - Reusable data transformations * - Zero runtime validation cost for known schemas */ import { z } from 'zod'; /** * TaskOutputSchema interface for custom schema definitions * Uses TypeScript's structural typing to avoid runtime overhead */ export interface TaskOutputSchema<T = any> { validate(data: unknown): T; parse(data: unknown): T; safeParse(data: unknown): { success: boolean; data?: T; error?: Error; }; } /** * ZodOutputSchema - Zod-based schema implementation * Provides efficient schema validation with minimal runtime overhead */ export declare class ZodOutputSchema<T> implements TaskOutputSchema<T> { private schema; constructor(schema: z.ZodType<T>); validate(data: unknown): T; parse(data: unknown): T; safeParse(data: unknown): { success: boolean; data?: T; error?: Error; }; } /** * InterfaceOutputSchema - Interface-based schema implementation * Uses TypeScript interfaces for zero runtime validation overhead * Only provides type checking at compile time */ export declare class InterfaceOutputSchema<T> implements TaskOutputSchema<T> { validate(data: unknown): T; parse(data: unknown): T; safeParse(data: unknown): { success: boolean; data?: T; error?: Error; }; } /** * TaskOutputFormatter - Main class to format task outputs * Provides methods to validate, transform, and format task outputs */ export declare class TaskOutputFormatter<T = any> { private schema; constructor(schema: TaskOutputSchema<T>); /** * Format raw output to structured data * Optimized for minimal object creation and memory usage */ format(rawOutput: string): T; /** * Safely format output with error handling * Returns either the formatted output or null with error information */ safeFormat(rawOutput: string): { success: boolean; data?: T; error?: Error; }; /** * Create a formatter with a Zod schema * Provides full validation but has runtime overhead */ static fromZodSchema<T>(schema: z.ZodType<T>): TaskOutputFormatter<T>; /** * Create a formatter with a TypeScript interface * Zero runtime validation overhead but no runtime type checking */ static fromInterface<T>(): TaskOutputFormatter<T>; } /** * Function to create a output formatter with a specific schema * Convenience function for common use cases */ export declare function createOutputFormatter<T>(schema: z.ZodType<T>): TaskOutputFormatter<T>; //# sourceMappingURL=TaskOutputFormatter.d.ts.map