From c5c5cd743f2d49f2491112ec247bc00f7c43e833 Mon Sep 17 00:00:00 2001 From: Chandini Date: Mon, 22 Sep 2025 10:25:53 +0530 Subject: [PATCH] frontend changes --- src/config/backend.ts | 4 ++-- src/services/aiAnalysis.ts | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/config/backend.ts b/src/config/backend.ts index 41b2739..b4a07a2 100644 --- a/src/config/backend.ts +++ b/src/config/backend.ts @@ -1,8 +1,8 @@ // -export const BACKEND_URL = 'https://backend.codenuk.com'; +// export const BACKEND_URL = 'https://backend.codenuk.com'; -// export const BACKEND_URL = 'http://192.168.1.16:8000'; +export const BACKEND_URL = 'http://192.168.1.17:8000'; export const SOCKET_URL = BACKEND_URL; diff --git a/src/services/aiAnalysis.ts b/src/services/aiAnalysis.ts index c4965df..ecd5ec8 100644 --- a/src/services/aiAnalysis.ts +++ b/src/services/aiAnalysis.ts @@ -16,13 +16,24 @@ export async function analyzeFeatureWithAI( ): Promise { try { // Prefer dedicated analysis endpoint if available in requirements service - const primaryUrl = `${BACKEND_URL}/api/requirements/analyze-feature` + const primaryUrl = `${BACKEND_URL}/api/ai/analyze-feature` const accessToken = (typeof window !== 'undefined') ? localStorage.getItem('accessToken') : null - const authHeaders = accessToken ? { Authorization: `Bearer ${accessToken}` } : {} + const headers: Record = { 'Content-Type': 'application/json' } + if (accessToken) { + headers.Authorization = `Bearer ${accessToken}` + } let res = await fetch(primaryUrl, { method: 'POST', - headers: { 'Content-Type': 'application/json', ...authHeaders }, - body: JSON.stringify({ featureName, description, requirements, projectType, complexity: userSelectedComplexity }), + headers, + body: JSON.stringify({ + featureName, + feature_name: featureName, // Backend expects this field name + description, + requirements, + projectType, + project_type: projectType, // Backend expects this field name + complexity: userSelectedComplexity + }), }) // If primary endpoint not found, fall back to mockup service to at least return deterministic hints @@ -30,9 +41,9 @@ export async function analyzeFeatureWithAI( const fallbackUrl = `${BACKEND_URL}/api/mockup/generate-wireframe` res = await fetch(fallbackUrl, { method: 'POST', - headers: { 'Content-Type': 'application/json', ...authHeaders }, + headers, body: JSON.stringify({ - prompt: `${featureName}: ${description}. Requirements: ${requirements.join('; ')}`, + prompt: `${featureName}: ${description}. Requirements: ${Array.isArray(requirements) ? requirements.join('; ') : 'No requirements provided'}`, device: 'desktop', }), }) @@ -47,6 +58,9 @@ export async function analyzeFeatureWithAI( } // Map various backend shapes to AIAnalysisResponse + if (json?.success && json?.analysis?.complexity && json?.analysis?.logicRules) { + return { complexity: json.analysis.complexity as Complexity, logicRules: json.analysis.logicRules as string[] } + } if (json?.success && json?.data?.complexity && json?.data?.logicRules) { return { complexity: json.data.complexity as Complexity, logicRules: json.data.logicRules as string[] } }