diff --git a/public/components/admin.html b/public/components/admin.html index 4a107f30..649dfef3 100644 --- a/public/components/admin.html +++ b/public/components/admin.html @@ -433,6 +433,7 @@ + diff --git a/public/js/admin/clinicalAssistant.js b/public/js/admin/clinicalAssistant.js index 28dc97fc..55916e88 100644 --- a/public/js/admin/clinicalAssistant.js +++ b/public/js/admin/clinicalAssistant.js @@ -406,9 +406,24 @@ export function initClinicalAssistantAdmin(adminEscapeHtml) { }).catch(function(err) { showToast(err.message, 'error'); if (box) box.textContent = err.message; }) .finally(function() { if (button) button.disabled = false; }); } + // The indexer's address and token have their own Save: the card's Save & Close + // writes exactly the five keys it shows, and a token is not a setting to + // rewrite on every visit. + function saveIndexerSettings() { + if (configState !== 'ready') return; + var writes = [putAssistantConfig('clinical_assistant.indexer_url', getValue('assistant-indexer-url') || '')]; + if (getValue('assistant-indexer-token')) writes.push(putAssistantConfig('clinical_assistant.indexer_token', getValue('assistant-indexer-token'))); + Promise.all(writes).then(function() { + setValue('assistant-indexer-token', ''); + showToast('Indexer settings saved', 'success'); + loadLibraryIndexStatus(); + }).catch(function(err) { showToast(err.message || 'Save failed', 'error'); }); + } document.addEventListener('click', function(e) { - if (e.target.closest && e.target.closest('#btn-assistant-index-now')) runLibraryIndexNow(); - else if (e.target.closest && e.target.closest('#btn-assistant-index-refresh')) loadLibraryIndexStatus(); + if (!e.target.closest) return; + if (e.target.closest('#btn-assistant-index-now')) runLibraryIndexNow(); + else if (e.target.closest('#btn-assistant-index-refresh')) loadLibraryIndexStatus(); + else if (e.target.closest('#btn-assistant-indexer-save')) saveIndexerSettings(); }); // Each card saves exactly what it shows, so no card needs a note explaining @@ -421,8 +436,6 @@ export function initClinicalAssistantAdmin(adminEscapeHtml) { Promise.all([ putAssistantConfig('clinical_assistant.conversation_chars', getValue('assistant-conversation-budget')), putAssistantConfig('clinical_assistant.search_limit', getValue('assistant-search-limit') || '8'), - putAssistantConfig('clinical_assistant.indexer_url', getValue('assistant-indexer-url') || ''), - getValue('assistant-indexer-token') ? putAssistantConfig('clinical_assistant.indexer_token', getValue('assistant-indexer-token')) : Promise.resolve(), putAssistantConfig('clinical_assistant.context_chars', getValue('assistant-context-chars') || '1400'), putAssistantConfig('clinical_assistant.translate_provider', getValue('assistant-translate-provider') || 'libretranslate'), putAssistantConfig('clinical_assistant.show_sources',