/**
 * SQL Generation Capability
 *
 * Enables agents to dynamically generate SQL queries based on analysis objectives.
 * This gives agents true autonomy to explore data beyond predefined Skills.
 *
 * Key features:
 * 1. Schema context injection - LLM knows available tables/columns
 * 2. Safety constraints - read-only, table whitelist, max rows
 * 3. Explanation generation - each query comes with reasoning
 * 4. Risk assessment - flags potentially expensive queries
 *
 * Design principles:
 * - Agent proposes, validator validates, executor runs
 * - LLM generates SQL, not arbitrary code
 * - All queries are SELECT-only (enforced by validator)
 * - Schema context prevents hallucinated table names
 */
import { ModelRouter } from '../core/modelRouter';
/**
 * Schema information for a Perfetto table
 */
export interface TableSchema {
    name: string;
    columns: ColumnInfo[];
    description?: string;
    /** Approximate row count (for query optimization hints) */
    estimatedRows?: number;
}
/**
 * Column information
 */
export interface ColumnInfo {
    name: string;
    type: 'INTEGER' | 'TEXT' | 'REAL' | 'BLOB' | 'ANY';
    nullable?: boolean;
    description?: string;
}
/**
 * Schema context provided to the LLM
 */
export interface SchemaContext {
    tables: TableSchema[];
    /** Common Perfetto idioms and patterns */
    hints?: string[];
}
/**
 * Safety constraints for SQL generation
 */
export interface SQLConstraints {
    /** Maximum rows to return (default: 1000) */
    maxRows: number;
    /** Allowed tables (whitelist) */
    allowedTables: string[];
    /** Forbidden SQL patterns (regex) */
    forbiddenPatterns: RegExp[];
    /** Query timeout in milliseconds */
    timeout: number;
    /** Maximum query complexity (joins, subqueries) */
    maxComplexity?: number;
}
/**
 * Generated SQL result
 */
export interface GeneratedSQL {
    /** The SQL query string */
    sql: string;
    /** Explanation of what this query does */
    explanation: string;
    /** Expected column names in result */
    expectedColumns: string[];
    /** Risk assessment */
    riskLevel: 'safe' | 'moderate' | 'high';
    /** Risk factors if any */
    riskFactors?: string[];
    /** Suggested LIMIT clause if not present */
    suggestedLimit?: number;
}
/**
 * SQL generation result (may include validation errors)
 */
export interface SQLGenerationResult {
    success: boolean;
    sql?: GeneratedSQL;
    error?: string;
    /** Validation errors if any */
    validationErrors?: string[];
}
/**
 * SQL generation capability for agents.
 * Uses LLM to generate Perfetto SQL queries based on analysis objectives.
 */
export declare class SQLGenerator {
    private modelRouter;
    private defaultConstraints;
    constructor(modelRouter: ModelRouter, constraints?: Partial<SQLConstraints>);
    /**
     * Generate SQL query for an analysis objective.
     *
     * @param objective - What the agent wants to analyze
     * @param schemaContext - Available tables and columns
     * @param constraints - Safety constraints (optional, uses defaults)
     * @returns Generated SQL with metadata
     */
    generateSQL(objective: string, schemaContext: SchemaContext, constraints?: Partial<SQLConstraints>): Promise<SQLGenerationResult>;
    /**
     * Repair an SQL query based on an execution/validation error.
     *
     * The LLM receives:
     * - objective
     * - schema
     * - constraints
     * - previous SQL
     * - concrete error message
     */
    repairSQL(params: {
        objective: string;
        schemaContext: SchemaContext;
        previousSQL: string;
        error: string;
        constraints?: Partial<SQLConstraints>;
    }): Promise<SQLGenerationResult>;
    /**
     * Build the LLM prompt for SQL generation.
     */
    private buildGenerationPrompt;
    /**
     * Build the LLM prompt for SQL repair.
     */
    private buildRepairPrompt;
    /**
     * Process LLM response and validate the generated SQL.
     */
    private processLLMResponse;
    /**
     * Quick validation of generated SQL (basic checks before full validation).
     */
    private quickValidate;
    /**
     * Update default constraints.
     */
    setDefaultConstraints(constraints: Partial<SQLConstraints>): void;
}
/**
 * Detect schema from a Perfetto trace.
 * Returns commonly used tables relevant for performance analysis.
 */
export declare function detectSchema(traceProcessorService: any, traceId: string): Promise<SchemaContext>;
/**
 * Create an SQL generator instance.
 */
export declare function createSQLGenerator(modelRouter: ModelRouter, constraints?: Partial<SQLConstraints>): SQLGenerator;
export default SQLGenerator;
//# sourceMappingURL=sqlGenerator.d.ts.map