- Notifications
You must be signed in to change notification settings - Fork148
Description
async function sendMessage() {
const text = inputEl.value.trim();
if (!text) return;
addMessage(text, 'user');
inputEl.value = '';
// thinkingMsg を手動で作る
const thinkingMsg = '……少しだけ考えるね。';
const thinkingEl = document.createElement('div');
thinkingEl.className = 'msg yura';
thinkingEl.textContent = thinkingMsg;
messagesEl.appendChild(thinkingEl);
messagesEl.scrollTop = messagesEl.scrollHeight;
// removeChild の安全版
const removeThinking = () => {
if (thinkingEl.parentNode) {
thinkingEl.parentNode.removeChild(thinkingEl);
}
};
try {
const res = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: text })
});
const data = await res.json();removeThinking();addMessage(data.reply || 'ごめんね、うまく返事ができなかったみたい。', 'yura');} catch (e) {
removeThinking();
addMessage('ごめんね、うまくつながらなかったみたい。またあとで話せたらうれしいな。', 'yura');
}
} yura-app/
server.js
package.json
public/
index.html