75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
/**
|
|
* AI Design Assistant routes
|
|
* - POST /api/ai/design-tips → contextual design advice
|
|
* - POST /api/ai/recommend-materials → material/color recommendations
|
|
* - POST /api/ai/render → DALL-E 3 photorealistic render
|
|
*/
|
|
import { getDesignTip, recommendMaterials, generateRender } from '../services/designAdvisor.js';
|
|
|
|
/**
|
|
* POST /api/ai/design-tips
|
|
* Body: { config: { width, height, depth, columns, materialName, ... } }
|
|
*/
|
|
export async function designTipsRoute(req, res) {
|
|
try {
|
|
const { config } = req.body;
|
|
if (!config) {
|
|
return res.status(400).json({ error: 'Missing config in body' });
|
|
}
|
|
const result = await getDesignTip(config);
|
|
res.json(result);
|
|
} catch (err) {
|
|
console.error('[AI design-tips]', err.message);
|
|
if (err.message.includes('OPENAI_API_KEY')) {
|
|
return res.status(503).json({ error: 'AI service not configured' });
|
|
}
|
|
res.status(500).json({ error: 'Failed to generate design tip' });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* POST /api/ai/recommend-materials
|
|
* Body: { config, finishes: [{ id, name, collection, price_chf? }], roomAnalysis?, priorities? }
|
|
* priorities: { price: 1-5, quality: 1-5, durability: 1-5, aesthetics: 1-5 }
|
|
*/
|
|
export async function recommendMaterialsRoute(req, res) {
|
|
try {
|
|
const { config, finishes, roomAnalysis, priorities } = req.body;
|
|
if (!config || !finishes) {
|
|
return res.status(400).json({ error: 'Missing config or finishes in body' });
|
|
}
|
|
const result = await recommendMaterials(config, finishes, roomAnalysis, priorities);
|
|
res.json(result);
|
|
} catch (err) {
|
|
console.error('[AI recommend-materials]', err.message);
|
|
if (err.message.includes('OPENAI_API_KEY')) {
|
|
return res.status(503).json({ error: 'AI service not configured' });
|
|
}
|
|
res.status(500).json({ error: 'Failed to generate recommendations' });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* POST /api/ai/render
|
|
* Body: { config, roomContext? }
|
|
*/
|
|
export async function renderRoute(req, res) {
|
|
try {
|
|
const { config, roomContext } = req.body;
|
|
if (!config) {
|
|
return res.status(400).json({ error: 'Missing config in body' });
|
|
}
|
|
const result = await generateRender(config, roomContext);
|
|
res.json(result);
|
|
} catch (err) {
|
|
console.error('[AI render]', err.message);
|
|
if (err.message.includes('OPENAI_API_KEY')) {
|
|
return res.status(503).json({ error: 'AI service not configured' });
|
|
}
|
|
if (err.message.includes('billing') || err.message.includes('quota')) {
|
|
return res.status(402).json({ error: 'AI quota exceeded' });
|
|
}
|
|
res.status(500).json({ error: 'Failed to generate render' });
|
|
}
|
|
}
|