diff --git a/static/chat.html b/static/chat.html
index 9eaae98..087d450 100644
--- a/static/chat.html
+++ b/static/chat.html
@@ -160,7 +160,8 @@ function addMsg(type, text) {
btn.className = 'copy-btn';
btn.textContent = 'Копировать';
btn.onclick = () => {
- navigator.clipboard.writeText(div.textContent.replace('Копировать', '').trim());
+ const text = div.firstChild ? div.firstChild.textContent.trim() : div.textContent.replace('Копировать', '').trim();
+ navigator.clipboard.writeText(text);
btn.textContent = 'Скопировано';
btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'Копировать'; btn.classList.remove('copied'); }, 1500);
@@ -299,9 +300,12 @@ async function sendMessage() {
} else if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (eventType === 'text') {
- if (!aiDiv) aiDiv = addMsg('ai', '');
+ if (!aiDiv) {
+ aiDiv = addMsg('ai', '');
+ aiDiv._textNode = aiDiv.firstChild; // text node before copy button
+ }
aiText += data.text;
- aiDiv.textContent = aiText;
+ if (aiDiv._textNode) aiDiv._textNode.textContent = aiText;
msgs.scrollTop = msgs.scrollHeight;
} else if (eventType === 'tool') {
// Show minimal status, not raw code