frontend changes
This commit is contained in:
parent
f87b6a864f
commit
c5c5cd743f
@ -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;
|
export const SOCKET_URL = BACKEND_URL;
|
||||||
|
|
||||||
|
|||||||
@ -16,13 +16,24 @@ export async function analyzeFeatureWithAI(
|
|||||||
): Promise<AIAnalysisResponse> {
|
): Promise<AIAnalysisResponse> {
|
||||||
try {
|
try {
|
||||||
// Prefer dedicated analysis endpoint if available in requirements service
|
// 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 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, {
|
let res = await fetch(primaryUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json', ...authHeaders },
|
headers,
|
||||||
body: JSON.stringify({ featureName, description, requirements, projectType, complexity: userSelectedComplexity }),
|
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
|
// 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`
|
const fallbackUrl = `${BACKEND_URL}/api/mockup/generate-wireframe`
|
||||||
res = await fetch(fallbackUrl, {
|
res = await fetch(fallbackUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json', ...authHeaders },
|
headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
prompt: `${featureName}: ${description}. Requirements: ${requirements.join('; ')}`,
|
prompt: `${featureName}: ${description}. Requirements: ${Array.isArray(requirements) ? requirements.join('; ') : 'No requirements provided'}`,
|
||||||
device: 'desktop',
|
device: 'desktop',
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
@ -47,6 +58,9 @@ export async function analyzeFeatureWithAI(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map various backend shapes to AIAnalysisResponse
|
// 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) {
|
if (json?.success && json?.data?.complexity && json?.data?.logicRules) {
|
||||||
return { complexity: json.data.complexity as Complexity, logicRules: json.data.logicRules as string[] }
|
return { complexity: json.data.complexity as Complexity, logicRules: json.data.logicRules as string[] }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user