Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: improve checkbox handler and boolean parsing

tombiied7198f3442e
diff --git a/src/local_deep_research/settings/manager.py b/src/local_deep_research/settings/manager.py
index 6d238b9cf2..967dfe6d6a 100644
--- a/src/local_deep_research/settings/manager.py
+++ b/src/local_deep_research/settings/manager.py
@@ -40,6 +40,9 @@ def parse_boolean(value: Any) -> bool:
bool: True for truthy values (any non-empty string except explicit false);
False for falsy values ('off', 'false', '0', '', 'no', False, None)
"""
+ # Constants for boolean value parsing
+ FALSY_VALUES = ("off", "false", "0", "", "no")
+
# Handle already-boolean values
if isinstance(value, bool):
return value
@@ -52,7 +55,7 @@ def parse_boolean(value: Any) -> bool:
if isinstance(value, str):
value_lower = value.lower().strip()
# Explicitly falsy values (empty string, false-like values)
- if value_lower in ("off", "false", "0", "", "no"):
+ if value_lower in FALSY_VALUES:
return False
# Any other non-empty string = True (HTML checkbox semantics)
return True
diff --git a/src/local_deep_research/web/static/js/components/checkbox_handler.js b/src/local_deep_research/web/static/js/components/checkbox_handler.js
index 4a250b283d..34b4faad81 100644
--- a/src/local_deep_research/web/static/js/components/checkbox_handler.js
+++ b/src/local_deep_research/web/static/js/components/checkbox_handler.js
@@ -34,6 +34,7 @@
* - Auto-initialization on DOM ready
* - Form submission integration (for traditional POST)
* - Cleanup method for dynamically created/removed checkboxes
+ * - Mutation observer for dynamically added checkboxes
* - Works in both AJAX and traditional POST modes
*/
(function() {
@@ -41,9 +42,11 @@
const CheckboxHandler = {
_initialized: false,
+ _observer: null,
/**
* Initialize all checkbox-hidden fallback pairs
+ * @returns {void}
*/
init: function() {
if (this._initialized) {
@@ -53,12 +56,14 @@
this.initializeCheckboxes();
this.setupFormSubmissionHandler();
+ this.setupMutationObserver();
this._initialized = true;
console.log('Checkbox handler initialized');
},
/**
* Initialize all checkbox-hidden input pairs
+ * @returns {void}
* @private
*/
initializeCheckboxes: function() {
@@ -71,6 +76,7 @@
/**
* Setup individual checkbox with hidden input
* @param {HTMLInputElement} checkbox - The checkbox element
+ * @returns {void}
* @private
*/
setupCheckbox: function(checkbox) {
@@ -115,6 +121,7 @@
/**
* Cleanup event listeners for a specific checkbox
* @param {HTMLInputElement} checkbox - The checkbox element to cleanup
+ * @returns {void}
* @public
*/
cleanup: function(checkbox) {
@@ -127,6 +134,7 @@
/**
* Set up document-level form submission handler
* Ensures all checkbox-hidden pairs are synced before any form submits
+ * @returns {void}
* @private
*/
setupFormSubmissionHandler: function() {
@@ -138,6 +146,7 @@
/**
* Prepare a specific form for submission by syncing all checkbox-hidden pairs
* @param {HTMLFormElement} form - The form element to prepare
+ * @returns {void}
* @public
*/
prepareFormSubmission: function(form) {
@@ -160,6 +169,45 @@
console.warn(`Hidden input not found during form submission: ${hiddenId}`);
}
});
+ },
+
+ /**
+ * Set up mutation observer to handle dynamically added checkboxes
+ * @returns {void}
+ * @private
+ */
+ setupMutationObserver: function() {
+ this._observer = new MutationObserver((mutations) => {
+ mutations.forEach((mutation) => {
+ mutation.addedNodes.forEach((node) => {
+ if (node.nodeType === 1) { // Element node
+ // Check if the node itself is a checkbox
+ if (node.matches && node.matches('input[type="checkbox"][data-hidden-fallback]')) {
+ this.setupCheckbox(node);
+ }
+ // Check for checkboxes within the added node
+ if (node.querySelectorAll) {
+ const checkboxes = node.querySelectorAll('input[type="checkbox"][data-hidden-fallback]');
+ checkboxes.forEach(checkbox => this.setupCheckbox(checkbox));
+ }
+ }
+ });
+ });
+ });
+
+ this._observer.observe(document.body, { childList: true, subtree: true });
+ },
+
+ /**
+ * Disconnect the mutation observer
+ * @returns {void}
+ * @public
+ */
+ disconnect: function() {
+ if (this._observer) {
+ this._observer.disconnect();
+ this._observer = null;
+ }
}
};