generalbots/botui/ui/suite/chat/chat-messages.js
Rodrigo Rodriguez (Pragmatismo) 2d715b2650
All checks were successful
Botlib CI / build (push) Successful in 12s
Bottest CI / build (push) Successful in 32s
BotUI CI / build (push) Successful in 44s
refactor: Split chat.html into modular JS files
- chat.html reduced from 1623 lines to 59 lines
- Created chat-switchers.js for switcher state management
- Created chat-messages.js for message rendering
- Created chat-main.js for initialization and coordination
- Added console logging to debug switcher toggle functionality
- Follows AGENTS.md 450-line limit rule
2026-04-24 16:22:08 +00:00

53 lines
1.4 KiB
JavaScript

// Chat Messages Module - Handles message rendering and display
function addMessage(role, content, messageId) {
var messages = document.getElementById("messages");
if (!messages) return;
var messageDiv = document.createElement("div");
messageDiv.className = "message message-" + role;
if (messageId) {
messageDiv.dataset.messageId = messageId;
}
if (role === "bot") {
messageDiv.innerHTML = marked.parse(content);
} else {
messageDiv.textContent = content;
}
messages.appendChild(messageDiv);
scrollToBottom(false);
}
function scrollToBottom(animate) {
var messages = document.getElementById("messages");
if (!messages) return;
if (animate) {
messages.scrollTo({
top: messages.scrollHeight,
behavior: "smooth"
});
} else {
messages.scrollTop = messages.scrollHeight;
}
}
function showThinking() {
var messages = document.getElementById("messages");
if (!messages) return;
var thinking = document.createElement("div");
thinking.className = "message message-bot thinking";
thinking.id = "thinking-indicator";
thinking.textContent = "Thinking...";
messages.appendChild(thinking);
scrollToBottom(false);
}
function hideThinking() {
var thinking = document.getElementById("thinking-indicator");
if (thinking) {
thinking.remove();
}
}