feat(webui): expand and organize settings with autosave (#5704)

* feat(webui): expand settings with autosave and live configuration

* feat(memory): add long-term memory and idle compaction switches

* refactor(webui): clarify settings hierarchy and align compact controls

* refactor(webui): keep only memory consolidation in memory settings

* refactor(webui): defer runtime changes until explicit restart

* refactor(webui): remove default workspace setting

* fix(webui): align model lists and remove preset counters

* fix(i18n): use natural Chinese labels for chat platforms

* fix(i18n): shorten chat settings navigation label

* fix(webui): match settings navigation icons to text size

* refactor(webui): remove redundant settings sidebar heading

* refactor(webui): use icon-only back navigation in settings

* fix(webui): remove back arrow hover hint

* refactor(webui): remove redundant overview details

* refactor(webui): hide secondary descriptions in settings rows

* style(webui): replace settings dividers with rounded highlights

* refactor(webui): remove redundant model list subtitles and badges

* fix(i18n): restore chat translation namespace boundaries

* fix(i18n): complete settings translations for all locales

* fix(webui): reveal settings only for enabled capabilities

* fix(webui): consolidate capabilities and isolate settings feedback

* fix(webui): clear restart notices when settings are reverted

* fix(webui): anchor restart controls in settings sidebar

* fix(webui): shorten sidebar restart label

* fix(webui): align settings spacing and control sizes

* refactor(webui): unify settings dialogs and interaction feedback

* fix(webui): keep settings option groups on one line without scrolling

* refactor(webui): align settings spacing and sidebar icon proportions

* style(webui): match main sidebar typography to settings

* style(webui): use monospace for sidebar session handles

* refactor(webui): remove heartbeat configuration from automations

* feat(webui): expose configuration actions beside capability toggles

* style(webui): remove ellipsis from configuration actions

* refactor(webui): remove redundant app configuration controls

* feat(webui): add compact sidebar navigation and shortcut hints

* fix(webui): synchronize npm dependency lockfile

* test(webui): align input radius expectation with pill styling

* feat(webui): show daily token usage and cache breakdown

* feat(webui): add model usage details and cache hit rates

* feat(webui): chart daily token usage by model

* refactor(webui): simplify usage details and model labels

* fix(webui): hide usage dialog date range

* refactor(webui): consolidate model usage into chart legends

* fix(webui): enforce restart choices and correct settings test route

* fix(webui): polish settings localization and controls

* fix(webui): avoid repeated usage legend labels

* fix(webui): skip empty usage columns in keyboard navigation

* test(webui): assert settings behavior positively

* feat(webui): refine sidebar navigation and add drag resizing

* style(webui): soften sidebar scroll edges

* style(webui): harmonize sidebar typography and text colors

* feat(webui): move channels to the main sidebar

* style(webui): remove dotted underlines from settings hints

* fix(webui): unify tooltip hover delay

* fix(webui): support Seatbelt sandbox settings

* fix(webui): remove unused appearance density preference

* fix(webui): align settings input values consistently

* style(webui): group compact settings controls before inputs

* feat(webui): edit multiline settings in compact dialogs

* feat(webui): add continuous settings scrolling with gentle snapping

* Revert "feat(webui): add continuous settings scrolling with gentle snapping"

This reverts commit f0978c261a53c844185eeab4d0c3190fbd196fe6.
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-10 11:10:51 +08:00
1 parent 20f115bf46
commit 8ea683679d
244 files changed
+6929 -3900

No files matched your search

+4
View File
@@ -123,6 +123,10 @@ def test_usage_payload_aggregates_cache_coverage_sources_and_failures(tmp_path:
assert payload["cache_read_tokens_30d"] == 40
assert payload["cache_read_observed_input_tokens_30d"] == 100
assert payload["cache_read_rate_30d"] == 0.4
assert payload["model_days_30d"] == [
{"date": "2026-06-03", "provider": "anthropic", "model": "claude-sonnet-4", "total_tokens": 40},
{"date": "2026-06-03", "provider": "openai", "model": "gpt-5", "total_tokens": 175},
]
day = payload["days"][0]
assert day["date"] == "2026-06-03"
+3 -1
View File
@@ -736,7 +736,7 @@ def test_model_configuration_advanced_options_round_trip(
assert row["reasoning_effort"] is None
def test_delete_model_configuration_requires_removing_it_from_call_order(
def test_delete_model_configuration_protects_primary_and_removes_fallback_references(
tmp_path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
@@ -747,6 +747,7 @@ def test_delete_model_configuration_requires_removing_it_from_call_order(
"spare": ModelPresetConfig(model="openai/gpt-4.1-mini"),
}
config.agents.defaults.model_preset = "primary"
config.agents.defaults.fallback_models = ["spare", "primary", "spare"]
save_config(config, config_path)
monkeypatch.setattr("nanobot.config.loader._current_config_path", config_path)
@@ -757,6 +758,7 @@ def test_delete_model_configuration_requires_removing_it_from_call_order(
payload = delete_model_configuration({"name": ["spare"]})
assert {row["name"] for row in payload["model_presets"]} == {"default", "primary"}
assert "spare" not in load_config(config_path).model_presets
assert load_config(config_path).agents.defaults.fallback_models == ["primary"]
def test_update_provider_settings_updates_dynamic_custom_provider(
+97
View File
@@ -526,3 +526,100 @@ async def test_version_check_route_enforces_auth_and_bounds_failures(
assert failed.status_code == 500
assert json.loads(failed.body) == {"error": "version check failed"}
assert "upstream secret body" not in failed.body.decode()
async def test_runtime_config_route_authentication_validation_and_restart(tmp_path):
from nanobot.config.loader import load_config
path = "/api/settings/runtime-config/update"
config_path = tmp_path / "config.json"
request = _mutation_request(path, {"values": {"tools.exec.timeout": 19}})
unauthorized = await _router(authorized=False, config_path=config_path).dispatch(None, request, path)
assert unauthorized.status_code == 401
assert not config_path.exists()
router = _router(config_path=config_path)
http_request = SimpleNamespace(path=path, headers=Headers())
assert (await router.dispatch(None, http_request, path)).status_code == 405
invalid = _mutation_request(path, {"values": {"channels.send_progress": False}})
assert (await router.dispatch(None, invalid, path)).status_code == 400
assert not config_path.exists()
result = await router.dispatch(None, request, path)
assert result.status_code == 200
assert load_config(config_path).tools.exec.timeout == 19
body = json.loads(result.body)
assert body["runtime_config"]["tools.exec.timeout"] == 19
assert body["restart_required_sections"] == ["runtime"]
refreshed = await router.dispatch(None, SimpleNamespace(path="/api/settings", headers=Headers()), "/api/settings")
assert json.loads(refreshed.body)["restart_required_sections"] == ["runtime"]
async def test_runtime_settings_only_save_without_refreshing_or_rebinding(tmp_path, monkeypatch):
refresh = MagicMock()
runtime = MagicMock()
monkeypatch.setattr(WebUISettingsRouter, "_api_runtime", lambda _self: runtime)
router = _router(config_path=tmp_path / "config.json", refresh_runtime_config=refresh)
path = "/api/settings/runtime-config/update"
response = await router.dispatch(None, _mutation_request(path, {
"values": {"agents.defaults.dream.enabled": False, "api.timeout": 45},
}), path)
assert response.status_code == 200
assert json.loads(response.body)["requires_restart"]
refresh.assert_not_called()
runtime.restart.assert_not_called()
async def test_reverting_runtime_switch_clears_restart_but_preserves_other_changes(tmp_path):
router = _router(config_path=tmp_path / "config.json")
config = router.settings.config.load()
original_memory = config.agents.defaults.dream.enabled
original_web = config.tools.web.enable
path = "/api/settings/runtime-config/update"
async def update(values):
response = await router.dispatch(None, _mutation_request(path, {"values": values}), path)
assert response.status_code == 200
return json.loads(response.body)
assert (await update({"agents.defaults.dream.enabled": not original_memory}))["requires_restart"]
await update({"tools.web.enable": not original_web})
assert (await update({"agents.defaults.dream.enabled": original_memory}))["requires_restart"]
reverted = await update({"tools.web.enable": original_web})
assert reverted["requires_restart"] is False
assert reverted["restart_required_sections"] == []
refreshed = await router.dispatch(None, SimpleNamespace(path="/api/settings", headers=Headers()), "/api/settings")
assert json.loads(refreshed.body)["requires_restart"] is False
async def test_reverting_web_reader_preserves_unrelated_restart_reason(tmp_path):
router = _router(config_path=tmp_path / "config.json")
original = router.settings.config.load().tools.web.fetch.use_jina_reader
path = "/api/settings/web-search/update"
first = await router.dispatch(None, _mutation_request(path, {"provider": "duckduckgo", "use_jina_reader": not original}), path)
assert json.loads(first.body)["restart_required_sections"] == ["browser"]
router._restart_sections.add("runtime")
restored = await router.dispatch(None, _mutation_request(path, {"provider": "duckduckgo", "use_jina_reader": original}), path)
assert json.loads(restored.body)["restart_required_sections"] == ["runtime"]
@pytest.mark.parametrize("enabled", [False, True])
async def test_image_switch_round_trip_clears_restart(tmp_path, monkeypatch, enabled):
from nanobot.config.loader import save_config
from nanobot.config.schema import Config
config = Config()
config.providers.openrouter.api_key = "sk-test"
config.tools.image_generation.enabled = enabled
config_path = tmp_path / "config.json"
save_config(config, config_path)
monkeypatch.setattr(
"nanobot.webui.settings_routes.request_image_generation_reload",
AsyncMock(return_value={"ok": False, "requires_restart": True}),
)
router = _router(config_path=config_path)
router.logger.warning = MagicMock()
path = "/api/settings/image-generation/update"
changed = await router.dispatch(None, _mutation_request(path, {"enabled": not enabled}), path)
assert json.loads(changed.body)["requires_restart"] is True
reverted = await router.dispatch(None, _mutation_request(path, {"enabled": enabled}), path)
assert json.loads(reverted.body)["requires_restart"] is False
assert json.loads(reverted.body)["restart_required_sections"] == []
+150
View File
@@ -0,0 +1,150 @@
from __future__ import annotations
import json
import re
from pathlib import Path
import pytest
from nanobot.config.loader import load_config, save_config
from nanobot.config.schema import Config
from nanobot.webui.settings_api import update_runtime_config_settings
from nanobot.webui.settings_contracts import WebUISettingsError
from nanobot.webui.settings_runtime import (
RUNTIME_CONFIG_PATHS,
runtime_config_payload,
update_runtime_config,
)
def test_runtime_patch_persists_and_preserves_other_domains(tmp_path):
path = tmp_path / "config.json"
config = Config.model_validate({
"providers": {"openai": {"apiKey": "${PRIVATE_API_KEY}"}},
"channels": {"telegram": {"token": "keep-me", "streaming": False}},
})
save_config(config, path)
payload = update_runtime_config_settings({
"agents.defaults.max_tool_iterations": 71,
"agents.defaults.timezone_mode": "manual",
"agents.defaults.timezone": "Asia/Shanghai",
"tools.exec.timeout": 0,
"tools.exec.allowed_env_keys": ["MY_TOKEN"],
"tools.image_generation.save_dir": "images",
}, local_browser=True, config_path=path)
saved = load_config(path)
assert saved.agents.defaults.max_tool_iterations == 71
assert saved.agents.defaults.timezone == "Asia/Shanghai"
assert saved.tools.exec.timeout == 0
assert saved.tools.exec.allowed_env_keys == ["MY_TOKEN"]
assert saved.providers.openai.api_key == "${PRIVATE_API_KEY}"
assert saved.channels.telegram == {"token": "keep-me", "streaming": False}
assert payload["requires_restart"]
assert payload["runtime_config"]["tools.image_generation.save_dir"] == "images"
assert "api.api_key" not in runtime_config_payload(saved)
assert "PRIVATE_API_KEY" not in json.dumps(runtime_config_payload(saved))
@pytest.mark.parametrize("values", [
{"channels.telegram.token": "bad"},
{"agents.defaults.workspace": "/not-editable-from-settings"},
{"providers.openai.api_key": "bad"},
{"tools.exec": {"enable": False}},
{"agents.defaults.max_concurrent_subagents": 0},
{"agents.defaults.max_tool_iterations": True},
{"tools.exec.timeout": -1},
{"tools.exec.timeout": "60"},
{"tools.exec.enable": "false"},
{"tools.exec.allowed_env_keys": "TOKEN"},
{"tools.exec.allowed_env_keys": [3]},
{"tools.exec.deny_patterns": ["["]},
{"tools.ssrf_whitelist": ["not-a-network"]},
{"tools.exec.sandbox": "unknown"},
{"agents.defaults.dream.cron": "not a cron"},
{"agents.defaults.dream.model_override": "missing"},
{"agents.defaults.timezone_mode": "manual", "agents.defaults.timezone": "Mars/Olympus"},
{"gateway.port": 65536},
{"gateway.heartbeat.interval_s": 0},
{"api.host": "192.168.1.2"},
{"api.timeout": float("nan")},
{"tools.image_generation.save_dir": ""},
{"tools.image_generation.save_dir": "../outside"},
{"tools.image_generation.save_dir": "C:/outside"},
{"tools.image_generation.save_dir": "/outside"},
])
def test_invalid_patch_is_atomic(tmp_path, values):
path = tmp_path / "config.json"
save_config(Config(), path)
before = path.read_bytes()
with pytest.raises(WebUISettingsError):
update_runtime_config_settings({
"agents.defaults.max_tool_iterations": 71, **values,
}, local_browser=True, config_path=path)
assert path.read_bytes() == before
def test_remote_client_cannot_change_install_policy():
config = Config()
with pytest.raises(WebUISettingsError) as error:
update_runtime_config(config, {
"tools.webui_allow_remote_package_install": True,
}, local_browser=False)
assert error.value.status == 403
assert not config.tools.webui_allow_remote_package_install
assert update_runtime_config(config, {
"tools.webui_allow_remote_package_install": True,
}, local_browser=True)
def test_timezone_auto_and_nullable_fields():
config = Config.model_validate({"agents": {"defaults": {
"timezoneMode": "manual", "timezone": "UTC", "dream": {"cron": "0 2 * * *"},
}}})
assert update_runtime_config(config, {
"agents.defaults.timezone_mode": "auto",
"tools.web.proxy": None,
}, local_browser=True)
assert config.agents.defaults.timezone_mode == "auto"
assert config.agents.defaults.dream.cron == "0 2 * * *"
assert not update_runtime_config(config, {}, local_browser=True)
def test_api_changes_require_explicit_restart(tmp_path):
path = tmp_path / "config.json"
payload = update_runtime_config_settings({"api.timeout": 222.5}, config_path=path)
assert payload["api"]["timeout"] == 222.5
assert payload["requires_restart"]
def test_every_exposed_runtime_setting_has_a_frontend_use():
fields = Path(__file__).parents[2] / "webui/src/components/settings/system/runtime-config-fields.ts"
paths = re.findall(r'group: "[^"]+", path: "([^"]+)"', fields.read_text(encoding="utf-8"))
assert len(paths) == len(set(paths))
# The CLI enable flag controls visibility of its advanced fields, without an editor.
visibility_only = {"tools.cli_apps.enable"}
assert set(paths) | visibility_only == set(RUNTIME_CONFIG_PATHS)
def test_disabling_memory_consolidation_preserves_other_memory_settings():
config = Config()
before = config.agents.defaults.model_dump()
assert update_runtime_config(config, {"agents.defaults.dream.enabled": False}, local_browser=True)
after = config.agents.defaults.model_dump()
before["dream"]["enabled"] = False
assert after == before
@pytest.mark.parametrize("backend", ["bwrap", "seatbelt"])
def test_sandbox_backend_persists_with_path_permissions(tmp_path, backend):
path = tmp_path / "config.json"
payload = update_runtime_config_settings({
"tools.exec.sandbox": backend,
"tools.exec.sandbox_ro_binds": ["shared/read"],
"tools.exec.sandbox_rw_binds": ["shared/write"],
}, local_browser=True, config_path=path)
saved = load_config(path).tools.exec
assert saved.sandbox == backend
assert saved.sandbox_ro_binds == ["shared/read"]
assert saved.sandbox_rw_binds == ["shared/write"]
assert payload["runtime_config"]["tools.exec.sandbox"] == backend
assert payload["requires_restart"]
+1 -1
View File
@@ -32,7 +32,7 @@ def test_system_domain_owns_runtime_dto_and_agent_updates(tmp_path) -> None:
assert payload["runtime"]["config_path"] == str(tmp_path / "config.json")
assert payload["version"] == {"current": "0.3.0"}
assert payload["docs"]["version"] == "0.3.0"
assert set(payload) == {"runtime", "usage", "advanced", "version", "docs"}
assert set(payload) == {"runtime", "runtime_config", "usage", "advanced", "version", "docs"}
def test_system_domain_validates_channel_field_values() -> None: