export type Complexity = 'low' | 'medium' | 'high' export interface AIAnalysisResponse { complexity: Complexity logicRules: string[] } export async function analyzeFeatureWithAI( featureName: string, description: string, requirements: string[], projectType?: string, userSelectedComplexity?: Complexity ): Promise { try { const res = await fetch('/api/ai/analyze', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ featureName, description, requirements, projectType, complexity: userSelectedComplexity }), }) const json = await res.json() if (!res.ok || !json.success) { throw new Error(json.message || `AI request failed (${res.status})`) } const data = json.data as AIAnalysisResponse return { complexity: data.complexity, logicRules: data.logicRules } } catch (error) { // Fallback if the server route fails return { complexity: 'medium', logicRules: [ 'Unable to determine specific business rules due to insufficient requirements information', 'Generic logic implementation may be required', 'Basic validation rules should be considered', ], } } }