generalbots/botui/ui/suite/chat/chat-state.js
Rodrigo Rodriguez (Pragmatismo) 28c48eeabf feat: Split chat.html into modular JS modules for #495 switcher support
- Split partials/chat.html (1513→70 lines) into 8 JS modules:
  chat-state.js, chat-switchers.js, chat-mentions.js,
  chat-messages.js, chat-suggestions.js, chat-theme.js,
  chat-websocket.js, chat-init.js
- Centralized state in ChatState global object
- Switcher chips auto-activate on switch_context suggestion action
- active_switchers sent in every WS message payload
- Removed old chat-main.js (merged into modules)
- Split vibe.html into vibe/ module directory with CSS extraction
- Updated standalone chat/chat.html to use same modules
2026-04-25 07:03:26 -03:00

108 lines
2.1 KiB
JavaScript

var ChatState = {
ws: null,
currentSessionId: null,
currentUserId: null,
currentBotId: "default",
currentBotName: "default",
isStreaming: false,
streamingMessageId: null,
currentStreamingContent: "",
streamingBuffer: "",
lastRenderTime: 0,
renderInterval: 200,
reconnectAttempts: 0,
maxReconnectAttempts: 5,
disconnectNotified: false,
isUserScrolling: false,
activeSwitchers: new Set(),
switcherDefinitions: [],
mentionState: {
active: false,
query: "",
startPos: -1,
selectedIndex: 0,
results: [],
},
};
var WS_BASE_URL =
window.location.protocol === "https:" ? "wss://" : "ws://";
var WS_URL = WS_BASE_URL + window.location.host + "/ws";
var MessageType = {
EXTERNAL: 0,
USER: 1,
BOT_RESPONSE: 2,
CONTINUE: 3,
SUGGESTION: 4,
CONTEXT_CHANGE: 5,
};
var EntityTypes = {
lead: { icon: "\u{1F464}", color: "#4CAF50", label: "Lead", route: "crm" },
opportunity: {
icon: "\u{1F4B0}",
color: "#FF9800",
label: "Opportunity",
route: "crm",
},
account: {
icon: "\u{1F3E2}",
color: "#2196F3",
label: "Account",
route: "crm",
},
contact: {
icon: "\u{1F4C7}",
color: "#9C27B0",
label: "Contact",
route: "crm",
},
invoice: {
icon: "\u{1F4C4}",
color: "#F44336",
label: "Invoice",
route: "billing",
},
quote: {
icon: "\u{1F4CB}",
color: "#607D8B",
label: "Quote",
route: "billing",
},
case: {
icon: "\u{1F3AB}",
color: "#E91E63",
label: "Case",
route: "tickets",
},
product: {
icon: "\u{1F4E6}",
color: "#795548",
label: "Product",
route: "products",
},
service: {
icon: "\u2699\uFE0F",
color: "#00BCD4",
label: "Service",
route: "products",
},
};
var SWITCHER_ICONS = {
tables: "\u{1F4CA}",
infographic: "\u{1F4CD}",
cards: "\u{1F0CF}",
list: "\u{1F4CB}",
comparison: "\u2696",
timeline: "\u23F0",
markdown: "\u{1F4DD}",
chart: "\u{1F4C8}",
};
function escapeHtml(text) {
var div = document.createElement("div");
div.textContent = text;
return div.innerHTML;
}