fix: guard AI response parse against undefined textResponse

This commit is contained in:
2026-07-25 16:21:59 +07:00
parent 5628802e08
commit 7dd6300500
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -12248,10 +12248,12 @@ const App = () => {
model: 'gpt-4o',
systemInstruction: 'You are a MIDI composer. Output ONLY valid JSON array of notes. No markdown, no explanation. Use 4/4 time. pitch=C4=60, D4=62, E4=64, F4=65, G4=67, A4=69, B4=71, C5=72.'
});
if (!result) throw new Error('AI không phản hồi');
let notesData = null;
if (result.textResponse) {
const textResp = result.textResponse || result.text || '';
if (textResp && typeof textResp === 'string') {
try {
const cleaned = result.textResponse.replace(/```json?\s*/g, '').replace(/```/g, '').trim();
const cleaned = textResp.replace(/```json?\s*/g, '').replace(/```/g, '').trim();
notesData = JSON.parse(cleaned);
} catch (e1) {}
}
File diff suppressed because one or more lines are too long