~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
Fix some issues with handling JSON settings.
Daniel Pettid73ac9373a16
diff --git a/src/local_deep_research/web/services/settings_manager.py b/src/local_deep_research/web/services/settings_manager.pyindex 59fabdeec2..c2f0c5c8d0 100644--- a/src/local_deep_research/web/services/settings_manager.py+++ b/src/local_deep_research/web/services/settings_manager.py@@ -47,6 +47,8 @@ class SettingsManager:_UI_ELEMENT_TO_SETTING_TYPE = {"text": str,+ # SQLAlchemy should already handle JSON parsing.+ "json": lambda x: x,"password": str,"select": str,"number": float,@@ -70,7 +72,7 @@ class SettingsManager:def __get_typed_setting_value(self, setting: Type[Setting], default: Any = None, check_env: bool = True- ) -> str | float | bool | None:+ ) -> Any:"""Extracts the value for a particular setting, ensuring that it has thecorrect type.diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.jsindex 2156ccdb75..45a58fda7f 100644--- a/src/local_deep_research/web/static/js/components/settings.js+++ b/src/local_deep_research/web/static/js/components/settings.js@@ -395,16 +395,28 @@shouldSaveImmediately = true;}}- // Handle range/slider (save on change/input or blur)- else if (input.type === 'range') {+ // Handle range/slider (save on change/input or blur)+ else if (input.type === 'range') {value = input.value;if (eventType === 'change' || eventType === 'input' || eventType === 'blur') {shouldSaveImmediately = true;}- }+ }// Handle other inputs (text, number, textarea) - Save on Enter or Blurelse {value = input.value;++ // Handle JSON.+ if (input.classList.contains('json-content')) {+ try {+ // Validate+ value = JSON.parse(input.value);+ } catch (e) {+ markInvalidInput(input, 'Invalid JSON');+ return;+ }+ }+// Basic validation for numberif (input.type === 'number') {try {@@ -1429,31 +1441,32 @@// Generate the appropriate input element based on UI element typeswitch(setting.ui_element) {case 'textarea':- // Check if it's JSON- let isJson = false;- let jsonClass = '';+ inputElement = `+ <textarea id="${settingId}" name="${setting.key}"+ class="settings-textarea"+ ${!setting.editable ? 'disabled' : ''}+ >${setting.value !== null ? setting.value : ''}</textarea>+ `;+ break;++ case 'json':+ let jsonClass = ' json-content';- if (typeof setting.value === 'string' &&- (setting.value.startsWith('{') || setting.value.startsWith('['))) {- isJson = true;- jsonClass = ' json-content';+ // Try to format the JSON for better display+ try {+ setting.value = JSON.stringify(JSON.parse(setting.value), null, 2);+ } catch (e) {+ // If parsing fails, keep the original value+ console.log('Error formatting JSON:', e);+ }- // Try to format the JSON for better display+ // If it's an object (not an array), render individual controls+ if (setting.value.startsWith('{')) {try {- setting.value = JSON.stringify(JSON.parse(setting.value), null, 2);+ const jsonObj = JSON.parse(setting.value);+ return renderExpandedJsonControls(setting, settingId, jsonObj);} catch (e) {- // If parsing fails, keep the original value- console.log('Error formatting JSON:', e);- }-- // If it's an object (not an array), render individual controls- if (setting.value.startsWith('{')) {- try {- const jsonObj = JSON.parse(setting.value);- return renderExpandedJsonControls(setting, settingId, jsonObj);- } catch (e) {- console.log('Error parsing JSON for controls:', e);- }+ console.log('Error parsing JSON for controls:', e);}}@@ -1581,26 +1594,15 @@default:// Handle llm.model here explicitly if not handled by ui_element- if (typeof setting.value === 'string' &&- (setting.value.startsWith('{') || setting.value.startsWith('['))) {- // Handle JSON objects/arrays rendered as textareas if not expanded- inputElement = `- <textarea id="${settingId}" name="${setting.key}"- class="settings-textarea json-content"- ${!setting.editable ? 'disabled' : ''}- >${setting.value}</textarea>- `;- } else {- // Default to text input- inputElement = `- <input type="${setting.ui_element === 'password' ? 'password' : 'text'}"- id="${settingId}" name="${setting.key}"- class="settings-input form-control"- value="${setting.value !== null ? setting.value : ''}"- ${!setting.editable ? 'disabled' : ''}- >- `;- }+ // Default to text input+ inputElement = `+ <input type="${setting.ui_element === 'password' ? 'password' : 'text'}"+ id="${settingId}" name="${setting.key}"+ class="settings-input form-control"+ value="${setting.value !== null ? setting.value : ''}"+ ${!setting.editable ? 'disabled' : ''}+ >+ `;break;}@@ -1945,6 +1947,22 @@}, 1500);}+ /**+ * Validates user-specified JSON data and shows and error if it is not+ * valid JSON.+ * @param content The content to validate.+ * @return True if the content is valid.+ */+ function validateJsonContent(content) {+ try {+ JSON.parse(content);+ return true;+ } catch (e) {+ showMessage('Setting value must be valid JSON.', 'error', 5000);+ return false;+ }+ }+/*** Submit settings data to the API* @param {Object} formData - The settings to save@@ -1962,6 +1980,11 @@} else if (sourceElement.classList.contains('json-property-control')) {// For JSON property controls, use the property itemloadingContainer = sourceElement.closest('.json-property-item') || sourceElement;+ } else if (sourceElement.classList.contains('json-content')) {+ // For JSON content, validate it before saving.+ if (!validateJsonContent(sourceElement.value)) {+ return;+ }} else {// For other inputs, use the form-group or settings-itemloadingContainer = sourceElement.closest('.form-group') ||@@ -3688,16 +3711,16 @@return false;}-+if (providerUpper === 'OPENAI_ENDPOINT') {if (model.provider && model.provider.toUpperCase() === 'OPENAI_ENDPOINT') {return true;}-+if (model.label && model.label.toLowerCase().includes('custom')) {return true;}-+return false;}