fix: prevent cleanAndParseJson from converting single standard object into an array

This commit is contained in:
2026-06-23 19:26:10 +00:00
parent f1fc44c58b
commit a94744f60c
+12 -1
View File
@@ -675,7 +675,18 @@ Regras Cruciais:
resultJson = data.choices[0].message.content;
}
const parsed = cleanAndParseJson(resultJson);
let cleanedString = resultJson.trim();
const jsonMatch = cleanedString.match(/```(?:json)?\s*([\s\S]*?)\s*```/i);
if (jsonMatch) cleanedString = jsonMatch[1].trim();
else {
const startIndex = cleanedString.indexOf('{');
const endIndex = cleanedString.lastIndexOf('}');
if (startIndex !== -1 && endIndex !== -1) {
cleanedString = cleanedString.substring(startIndex, endIndex + 1);
}
}
const parsed = JSON.parse(cleanedString);
return parsed;
} catch (error) {
console.error("Erro no buildStandardWithAI:", error);