UNPKG

cyber-mysql-openai

Version:

Intelligent natural language to SQL translator with self-correction capabilities using OpenAI and MySQL

110 lines (109 loc) 2.69 kB
export interface TableContext { description?: string; columns?: Record<string, string>; } export interface QueryExample { question: string; sql: string; } export interface SchemaContext { businessDescription?: string; tables?: Record<string, TableContext>; examples?: QueryExample[]; customInstructions?: string[]; responseStyle?: "concise" | "detailed" | "technical"; } export interface DBConfig { host: string; port: number; user: string; password: string; database: string; ssl?: boolean; socketPath?: string; } export interface OpenAIConfig { apiKey: string; model: string; lightModel?: string; } export interface CacheConfig { enabled?: boolean; maxSize?: number; cleanupIntervalMs?: number; } export interface CyberMySQLOpenAIConfig { database: DBConfig; openai: OpenAIConfig; context?: SchemaContext; maxReflections?: number; logLevel?: "error" | "warn" | "info" | "debug" | "none"; logDirectory?: string; logEnabled?: boolean; language?: "es" | "en"; cache?: CacheConfig; schemaTTL?: number; mode?: "direct" | "agentic"; } export interface TokenUsage { promptTokens: number; completionTokens: number; totalTokens: number; estimatedCost?: number; } export interface TranslationResult { sql: string; results: any[]; reflections: Reflection[]; attempts: number; success: boolean; confidence?: number; naturalResponse?: string; detailedResponse?: string; executionTime?: number; fromCache?: boolean; tokenUsage?: TokenUsage; } export interface ValidationResult { valid: boolean; warnings: string[]; errors: string[]; suggestions: string[]; } export interface SQLResult { sql: string; results: any[]; success: boolean; naturalResponse?: string; detailedResponse?: string; executionTime?: number; fromCache?: boolean; } export interface Reflection { error: string; reasoning: string; fixAttempt: string; } export type LogLevel = "error" | "warn" | "info" | "debug" | "none"; export interface NaturalResponseOptions { detailed?: boolean; bypassCache?: boolean; onChunk?: (chunk: string) => void; } export interface QueryStreamChunk { type: "sql" | "results" | "chunk" | "reflection" | "done"; content?: string; sql?: string; results?: any[]; reflections?: Reflection[]; metadata?: Partial<TranslationResult>; } export interface CacheStats { totalEntries: number; hits: number; misses: number; hitRate: number; memoryUsage: number; oldestEntry: number; newestEntry: number; }