/** * MxChat Test Panel JavaScript * Handles the testing interface for admins - always active when panel is open */ class MxChatTestPanel { constructor() { this.panel = null; this.tab = null; this.isOpen = false; this.lastQueryData = null; this.init(); } init() { // Wait for DOM to be ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => this.setup()); } else { this.setup(); } } setup() { this.createElements(); this.bindEvents(); this.setupChatInterception(); } createElements() { // Create the test tab this.tab = document.createElement('div'); this.tab.className = 'mxchat-test-tab'; this.tab.innerHTML = 'MXCHAT DEBUGGING'; this.tab.title = 'Open MxChat Debug Panel'; document.body.appendChild(this.tab); // Create the test panel this.panel = document.createElement('div'); this.panel.className = 'mxchat-test-panel'; this.panel.innerHTML = this.getPanelHTML(); document.body.appendChild(this.panel); } getPanelHTML() { return `
Always-on debugging for administrators
${data.data.threshold_percentage}`;
} else {
thresholdEl.innerHTML = 'Error loading threshold';
}
})
.catch(error => {
console.error('Error fetching similarity threshold:', error);
const thresholdEl = this.panel.querySelector('#similarity-threshold');
thresholdEl.innerHTML = 'Connection error';
});
}
updateSystemPrompt() {
const promptEl = this.panel.querySelector('#system-prompt');
promptEl.textContent = 'Loading system prompt...';
fetch(mxchatTestData.ajaxUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'mxchat_get_system_info',
nonce: mxchatTestData.nonce
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
promptEl.textContent = data.data.system_prompt || 'No system prompt configured';
this.log(`๐ค Model: ${data.data.selected_model}`);
this.log(`๐ API Status: ${JSON.stringify(data.data.api_status)}`);
} else {
promptEl.textContent = 'Error loading system prompt';
}
})
.catch(error => {
console.error('Error fetching system info:', error);
promptEl.textContent = 'Connection error';
});
}
updateKnowledgeBaseStatus() {
const statusEl = this.panel.querySelector('#kb-status');
statusEl.innerHTML = 'Checking...';
fetch(mxchatTestData.ajaxUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'mxchat_get_kb_status',
nonce: mxchatTestData.nonce
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
const kbData = data.data;
statusEl.innerHTML = `โ ${kbData.status} (${kbData.type} - ${kbData.documents})`;
} else {
statusEl.innerHTML = 'Error loading KB status';
}
})
.catch(error => {
console.error('Error fetching KB status:', error);
statusEl.innerHTML = 'Connection error';
});
}
clearDebugConsole() {
const console = this.panel.querySelector('#debug-console');
console.innerHTML = '