From 706dcd44ff2f03c63044426563d3f0055ead2249 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 23 Feb 2026 17:22:07 +0100 Subject: [PATCH] WIP --- .../blueprint/settings/__init__.py | 18 +-- .../settings/templates/settings-llm.html | 120 ---------------- .../settings/templates/settings.html | 26 +--- changedetectionio/flask_app.py | 3 + changedetectionio/llm/plugin.py | 72 ++++++++-- changedetectionio/llm/queue_worker.py | 68 ++++++---- changedetectionio/llm/settings_form.py | 128 ++++++++++++++++++ .../llm/templates/settings-llm.html | 96 +++++++++++++ changedetectionio/static/js/llm.js | 26 +++- 9 files changed, 366 insertions(+), 191 deletions(-) delete mode 100644 changedetectionio/blueprint/settings/templates/settings-llm.html create mode 100644 changedetectionio/llm/settings_form.py create mode 100644 changedetectionio/llm/templates/settings-llm.html diff --git a/changedetectionio/blueprint/settings/__init__.py b/changedetectionio/blueprint/settings/__init__.py index 050d9691..36648388 100644 --- a/changedetectionio/blueprint/settings/__init__.py +++ b/changedetectionio/blueprint/settings/__init__.py @@ -45,6 +45,7 @@ def construct_blueprint(datastore: ChangeDetectionStore): extra_notification_tokens=datastore.get_unique_notification_tokens_available() ) + # Remove the last option 'System default' form.application.form.notification_format.choices.pop() @@ -76,15 +77,6 @@ def construct_blueprint(datastore: ChangeDetectionStore): datastore.data['settings']['application'].update(app_update) - # Persist LLM connections (JSON blob from the JS-managed hidden field) - import json as _json - llm_connections_raw = request.form.get('llm_connections', '') - if llm_connections_raw: - try: - datastore.data['settings']['application']['llm_connections'] = _json.loads(llm_connections_raw) - except (ValueError, TypeError): - flash(gettext("Invalid LLM connections data."), 'error') - # Handle dynamic worker count adjustment old_worker_count = datastore.data['settings']['requests'].get('workers', 1) new_worker_count = form.data['requests'].get('workers', 1) @@ -138,8 +130,12 @@ def construct_blueprint(datastore: ChangeDetectionStore): # Instantiate plugin form with POST data plugin_form = form_class(formdata=request.form) - # Save plugin settings (validation is optional for plugins) - if plugin_form.data: + # Save plugin settings — use plugin's own save_fn if provided + # (allows plugins to strip ephemeral staging fields etc.) + save_fn = tab.get('save_fn') + if save_fn: + save_fn(datastore, plugin_form) + elif plugin_form.data: save_plugin_settings(datastore.datastore_path, plugin_id, plugin_form.data) flash(gettext("Settings updated.")) diff --git a/changedetectionio/blueprint/settings/templates/settings-llm.html b/changedetectionio/blueprint/settings/templates/settings-llm.html deleted file mode 100644 index ee8d7033..00000000 --- a/changedetectionio/blueprint/settings/templates/settings-llm.html +++ /dev/null @@ -1,120 +0,0 @@ - - -{# ── Configured connections table ──────────────────── #} -
- {{ _('LLM Connections') }} - - - - - - - - - - - - - - -
{{ _('Default') }}{{ _('Name') }}{{ _('Model') }}{{ _('API Key') }}{{ _('TPM') }}
-
- -{# ── Add connection ─────────────────────────────────── #} -
- {{ _('Add a connection') }} - -
- - -
- -
-
-
- - -
-
-
-
- - -
-
-
-
- -
- - -
-
-
-
-
- - -
-
-
-
- - -
-
-
- -
- -
-
- -{# Hidden field carries the JSON to the backend #} - diff --git a/changedetectionio/blueprint/settings/templates/settings.html b/changedetectionio/blueprint/settings/templates/settings.html index 54b160fc..cc3e34db 100644 --- a/changedetectionio/blueprint/settings/templates/settings.html +++ b/changedetectionio/blueprint/settings/templates/settings.html @@ -15,7 +15,6 @@ -
-
- {% include 'settings-llm.html' %} -
+