diff --git a/web-ui/code.js b/web-ui/code.js index b307fa4..688f462 100644 --- a/web-ui/code.js +++ b/web-ui/code.js @@ -897,7 +897,7 @@ function openArduinoEmulator() { body: JSON.stringify({ code: file.content, board: 'uno' }), }).then(r => r.json()).then(data => { if (btn) { btn.textContent = '🔌 에뮬레이터'; btn.disabled = false; } - if (data.error) { codeAiAppend('system', '⚠️ 컴파일 오류:\n' + data.error); return; } + if (data.error) { sendCompileErrorToAI(data.error, file.name, file.content); return; } sessionStorage.setItem('arduino_sketch', file.content); sessionStorage.setItem('arduino_hex', data.hex); sessionStorage.setItem('arduino_filename', file.name); @@ -1323,7 +1323,7 @@ function codeRunWith(mode) { body: JSON.stringify({ code: file.content, board: 'esp32' }), }).then(r => r.json()).then(data => { if (data.error) { - codeAiAppend('system', '⚠️ 컴파일 오류:\n' + data.error); + sendCompileErrorToAI(data.error, file.name, file.content); return; } sessionStorage.setItem('arduino_merged', data.merged); @@ -1344,9 +1344,8 @@ function codeRunWith(mode) { body: JSON.stringify({ code: file.content, board }), }).then(r => r.json()).then(data => { if (data.error) { - let msg = '⚠️ 컴파일 오류:\n' + data.error; - if (data.install) msg += '\n\n설치 필요:\n' + data.install; - codeAiAppend('system', msg); + const extra = data.install ? `\n\n설치 필요: ${data.install}` : ''; + sendCompileErrorToAI(data.error + extra, file.name, file.content); return; } sessionStorage.setItem('arduino_hex', data.hex); @@ -1382,6 +1381,14 @@ function codeRunWith(mode) { }, codeTermOpen ? 0 : 500); } +function sendCompileErrorToAI(error, filename, code) { + const inp = document.getElementById('code-ai-input'); + if (!inp) return; + const codeBlock = code ? `\n\n코드:\n\`\`\`cpp\n${code}\n\`\`\`` : ''; + inp.value = `아두이노 컴파일 오류가 발생했습니다. 원인을 설명하고 수정해줘.\n\n파일: ${filename}\n오류:\n\`\`\`\n${error}\n\`\`\`${codeBlock}`; + codeAiSend(); +} + function codeSendSelectionToAI() { if (!monacoEditor) return; const sel = monacoEditor.getSelection();