/** * TypeScript Code Evaluator for PraisonAI Bench * * Evaluates TypeScript code through multiple stages: * 1. Syntax validation (30 points) * 2. Code execution (40 points) * 3. Output comparison with expected results (30 points if provided) * * Uses secure subprocess execution with timeout and resource limits. */ import { BaseEvaluator, FeedbackItem, EvaluationResult as BaseEvaluationResult } from './base-evaluator'; /** * Score breakdown structure */ export interface ScoreBreakdown { syntax: number; execution: number; output_match: number; } /** * Evaluation details structure */ export interface EvaluationDetails { extracted_code: string; executed?: boolean; output?: string; error?: string | null; syntax_error?: string; similarity?: number; expected?: string; score_breakdown?: ScoreBreakdown; [key: string]: unknown; } /** * Evaluation result structure */ export interface EvaluationResult extends BaseEvaluationResult { details: EvaluationDetails; } export { FeedbackItem }; /** * Syntax validation result */ interface SyntaxValidationResult { isValid: boolean; error: string | null; details: { imports: string[]; }; } /** * Execution result */ interface ExecutionResult { success: boolean; output: string | null; error: string | null; } /** * Comprehensive TypeScript code evaluator. * * Features: * - Syntax validation using TypeScript compiler API * - Secure code execution in subprocess via ts-node * - Output comparison with fuzzy matching * - Import detection * - Timeout protection (5 seconds default) * * @example * ```typescript * const evaluator = new TypeScriptEvaluator(); * const result = evaluator.evaluate( * 'console.log("Hello World")', * "hello_world", * "Write TypeScript code that prints Hello World", * "Hello World" * ); * ``` */ export declare class TypeScriptEvaluator extends BaseEvaluator { private timeout; private tsNodePath; /** * Initialise the TypeScript evaluator. * * @param timeout - Maximum execution time in seconds (default: 5) * @param tsNodePath - Path to ts-node executable (default: uses npx) */ constructor(timeout?: number, tsNodePath?: string | null); /** * Return language identifier */ getLanguage(): string; /** * Return file extension for TypeScript files */ getFileExtension(): string; /** * Evaluate TypeScript code comprehensively. * * Scoring: * - Syntax validation: 30 points * - Successful execution: 40 points * - Output matches expected: 30 points (if expected provided) * * @param code - TypeScript code to evaluate * @param testName - Name of the test * @param prompt - Original prompt/requirement * @param expected - Expected output (optional) * @returns Evaluation result with score, passed status, feedback, and details */ evaluate(code: string, _testName: string, _prompt: string, expected?: string): Promise; /** * Extract TypeScript code from markdown code blocks. * * Supports: * - ```typescript ... ``` * - ```ts ... ``` * - ``` ... ``` * - Raw TypeScript code */ extractCode(response: string): string; /** * Validate TypeScript syntax using the TypeScript compiler API. * * @returns Validation result with isValid, error message, and details */ validateSyntax(code: string): SyntaxValidationResult; /** * Execute TypeScript code safely in a subprocess using ts-node. * * Security measures: * - Runs in separate process * - Timeout protection * - No direct system access from main process * * @returns Execution result with success, stdout, and stderr */ executeCode(code: string): Promise; /** * Compare actual output with expected output. * * Scoring (out of 30 points): * - Exact match: 30 points * - High similarity (>80%): 25-29 points * - Medium similarity (50-80%): 15-24 points * - Low similarity (<50%): 0-14 points * * @returns Tuple of [score, similarity_ratio] */ compareOutput(actual: string, expected: string): [number, number]; /** * Calculate similarity ratio between two strings using sequence matching. */ private calculateSimilarity; /** * Calculate longest common subsequence length. */ private longestCommonSubsequence; } //# sourceMappingURL=evaluator.d.ts.map