frontend changes

This commit is contained in:
Chandini 2025-09-22 10:25:53 +05:30
parent f87b6a864f
commit c5c5cd743f
2 changed files with 22 additions and 8 deletions

View File

@ -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;

View File

@ -16,13 +16,24 @@ export async function analyzeFeatureWithAI(
): Promise<AIAnalysisResponse> {
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<string, string> = { '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[] }
}