From d9648a70dbadad47d227f3c4385cf9e42de6cb49 Mon Sep 17 00:00:00 2001 From: NeonKirill Date: Sat, 21 Dec 2024 09:48:43 +0100 Subject: [PATCH 01/17] bots table template --- chat_client/static/js/sio.js | 5 +++ chat_client/static/js/submind_utils.js | 41 +++++++++++++++++++ chat_client/templates/base.html | 1 + .../components/conversation_skins/base.html | 13 ++++-- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 chat_client/static/js/submind_utils.js diff --git a/chat_client/static/js/sio.js b/chat_client/static/js/sio.js index 8d2059a0..ea412306 100644 --- a/chat_client/static/js/sio.js +++ b/chat_client/static/js/sio.js @@ -93,6 +93,11 @@ function initSIO(){ await applyTranslations(data); }); + socket.on('subminds_state', async (data) => { + //console.log('subminds_state: ', data) + await parseSubmindsState(data); + }); + socket.on('incoming_tts', (data)=> { console.log('received incoming stt audio'); playTTS(data['cid'], data['lang'], data['audio_data']); diff --git a/chat_client/static/js/submind_utils.js b/chat_client/static/js/submind_utils.js new file mode 100644 index 00000000..2de64d9f --- /dev/null +++ b/chat_client/static/js/submind_utils.js @@ -0,0 +1,41 @@ + +let submindsPerCid; + + + + +function renderActiveSubminds(cid) { + const table = document.getElementById(`${cid}-subminds-state-table`); + table.innerHTML = ''; + + (submindsPerCid?.[cid] || []).forEach(submind => { + const row = document.createElement('tr'); + + const checkboxCell = document.createElement('td'); + const checkbox = document.createElement('input'); + checkbox.type = 'checkbox'; + checkbox.className = 'form-check-input bot-checkbox'; + checkbox.value = submind.name; + checkbox.checked = submind.status === 'active'; + checkbox.id = `bot-${submind.submind_id}-${cid}`; + checkboxCell.appendChild(checkbox); + + + const nameCell = document.createElement('td'); + const label = document.createElement('label'); + label.className = 'form-check-label'; + label.htmlFor = `bot-${submind.submind_id}-${cid}`; + label.textContent = submind.submind_id.slice(0, submind.submind_id.lastIndexOf('-')); + nameCell.appendChild(label); + + row.appendChild(checkboxCell); + row.appendChild(nameCell); + + table.appendChild(row); + }); +} + + +async function parseSubmindsState(data){ + submindsPerCid = data['subminds_per_cid']; +} \ No newline at end of file diff --git a/chat_client/templates/base.html b/chat_client/templates/base.html index 20ab4752..090ea69c 100644 --- a/chat_client/templates/base.html +++ b/chat_client/templates/base.html @@ -53,6 +53,7 @@ 'date_utils.js', 'file_utils.js', 'language_utils.js', + 'submind_utils.js', 'user_settings.js' ] %} diff --git a/chat_client/templates/components/conversation_skins/base.html b/chat_client/templates/components/conversation_skins/base.html index cc32d0f8..1d97e287 100644 --- a/chat_client/templates/components/conversation_skins/base.html +++ b/chat_client/templates/components/conversation_skins/base.html @@ -3,9 +3,16 @@ {% block skin_body %}
{conversation_name_shrunk} - - 0 - + `; + + const checkbox = row.querySelector(`#toggle-${cid}-${submind.submind_id}`); + checkbox.addEventListener('change', () => { + currentState[index].active = checkbox.checked; + updateButtonVisibility(); + }); entriesContainer.appendChild(row); }); + + resetButton.onclick = () => { + currentState = structuredClone(initialState); + currentState.forEach((submind, index) => { + const checkbox = document.getElementById(`toggle-${cid}-${submind.id}`); + if (checkbox) checkbox.checked = submind.active; + }); + updateButtonVisibility(); + }; + + submitButton.onclick = () => { + + // function to apply changes for chat + + socket.emit('update_subminds', {cid: currentState}); + + const dropdownToggle = document.getElementById(`dropdownToggle-${cid}`); + if (dropdownToggle) dropdownToggle.click(); + + buttonsContainer.style.display = 'none'; + }; } async function parseSubmindsState(data){ submindsPerCid = data['subminds_per_cid']; + + for (const cid of Object.keys(submindsPerCid)){ + refreshSubmindsCount(cid); + } } + diff --git a/chat_client/templates/components/conversation_skins/prompts.html b/chat_client/templates/components/conversation_skins/prompts.html index a75e07d6..427fd00e 100644 --- a/chat_client/templates/components/conversation_skins/prompts.html +++ b/chat_client/templates/components/conversation_skins/prompts.html @@ -3,8 +3,8 @@ {% block skin_body %}
{conversation_name_shrunk} -