feat: initialize project with docker-compose infrastructure and server application logic
This commit is contained in:
@@ -137,15 +137,16 @@ const normalizeHealthAnalysis = (raw, language) => {
|
||||
const actionsNowRaw = getStringArray(raw.actionsNow).slice(0, 8);
|
||||
const plan7DaysRaw = getStringArray(raw.plan7Days).slice(0, 10);
|
||||
|
||||
if (scoreRaw == null || !statusRaw || !Array.isArray(issuesRaw)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const status = statusRaw === 'healthy' || statusRaw === 'watch' || statusRaw === 'critical'
|
||||
// Use safe defaults instead of returning null — bad/partial JSON falls through
|
||||
// to the graceful "Uncertain analysis" fallback at line 164 rather than
|
||||
// propagating null → PROVIDER_ERROR to the caller.
|
||||
const score = scoreRaw ?? 50;
|
||||
const status = (statusRaw === 'healthy' || statusRaw === 'watch' || statusRaw === 'critical')
|
||||
? statusRaw
|
||||
: 'watch';
|
||||
const issuesInput = Array.isArray(issuesRaw) ? issuesRaw : [];
|
||||
|
||||
const likelyIssues = issuesRaw
|
||||
const likelyIssues = issuesInput
|
||||
.map((entry) => {
|
||||
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return null;
|
||||
const title = getString(entry.title);
|
||||
@@ -168,7 +169,7 @@ const normalizeHealthAnalysis = (raw, language) => {
|
||||
? 'La IA no pudo extraer senales de salud estables.'
|
||||
: 'AI could not extract stable health signals.';
|
||||
return {
|
||||
overallHealthScore: Math.round(clamp(scoreRaw, 0, 100)),
|
||||
overallHealthScore: Math.round(clamp(score, 0, 100)),
|
||||
status,
|
||||
likelyIssues: [
|
||||
{
|
||||
@@ -191,7 +192,7 @@ const normalizeHealthAnalysis = (raw, language) => {
|
||||
}
|
||||
|
||||
return {
|
||||
overallHealthScore: Math.round(clamp(scoreRaw, 0, 100)),
|
||||
overallHealthScore: Math.round(clamp(score, 0, 100)),
|
||||
status,
|
||||
likelyIssues,
|
||||
actionsNow: actionsNowRaw,
|
||||
@@ -305,10 +306,14 @@ const postChatCompletion = async ({ modelChain, messages, imageUri, temperature
|
||||
|
||||
if (!response.ok) {
|
||||
const body = await response.text();
|
||||
let parsedError = {};
|
||||
try { parsedError = JSON.parse(body); } catch {}
|
||||
console.warn('OpenAI request HTTP error.', {
|
||||
status: response.status,
|
||||
model,
|
||||
endpoint: OPENAI_CHAT_COMPLETIONS_URL,
|
||||
openAiCode: parsedError?.error?.code,
|
||||
openAiMessage: parsedError?.error?.message,
|
||||
image: summarizeImageUri(imageUri),
|
||||
bodyPreview: body.slice(0, 300),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user