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:
1 parent
20f115bf46
commit
8ea683679d
244 files changed
+6929
-3900
No files matched your search
@@ -19,6 +19,7 @@ from nanobot.config.schema import Config
|
||||
from nanobot.webui import settings_capabilities as capabilities
|
||||
from nanobot.webui import settings_contracts as contracts
|
||||
from nanobot.webui import settings_models as models
|
||||
from nanobot.webui import settings_runtime as runtime
|
||||
from nanobot.webui import settings_system as system
|
||||
from nanobot.webui.settings_contracts import QueryParams, WebUISettingsError
|
||||
from nanobot.webui.workspaces import write_webui_default_access_mode
|
||||
@@ -459,3 +460,16 @@ def update_transcription_settings(
|
||||
if capabilities.update_transcription_settings(config, query):
|
||||
_save_settings_config(config, config_path)
|
||||
return settings_payload(config_path=config_path)
|
||||
|
||||
|
||||
def update_runtime_config_settings(
|
||||
values: dict[str, Any], *, local_browser: bool = False, config_path: Path | None = None,
|
||||
) -> dict[str, Any]:
|
||||
config = _load_settings_config(config_path)
|
||||
changed = runtime.update_runtime_config(config, values, local_browser=local_browser)
|
||||
if changed:
|
||||
_save_settings_config(config, config_path)
|
||||
return settings_payload(
|
||||
requires_restart=changed,
|
||||
config_path=config_path,
|
||||
)
|
||||
@@ -1429,14 +1429,12 @@ def delete_model_configuration(config: Config, query: QueryParams) -> None:
|
||||
if name not in config.model_presets:
|
||||
raise WebUISettingsError("unknown model configuration")
|
||||
defaults = config.agents.defaults
|
||||
referenced = defaults.model_preset == name or any(
|
||||
fallback == name for fallback in defaults.fallback_models
|
||||
)
|
||||
if referenced:
|
||||
if defaults.model_preset == name:
|
||||
raise WebUISettingsError(
|
||||
"remove the model preset from the call order first",
|
||||
"the primary model preset cannot be deleted",
|
||||
status=409,
|
||||
)
|
||||
defaults.fallback_models = [fallback for fallback in defaults.fallback_models if fallback != name]
|
||||
del config.model_presets[name]
|
||||
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ from nanobot.webui.settings_api import (
|
||||
update_model_configuration,
|
||||
update_network_safety_settings,
|
||||
update_provider_settings,
|
||||
update_runtime_config_settings,
|
||||
update_transcription_settings,
|
||||
update_web_search_settings,
|
||||
)
|
||||
@@ -62,6 +63,7 @@ from nanobot.webui.settings_contracts import (
|
||||
SettingsRequest,
|
||||
SettingsRouteResult,
|
||||
)
|
||||
from nanobot.webui.settings_runtime import runtime_config_payload
|
||||
from nanobot.webui.settings_services import WebUISettingsServices
|
||||
from nanobot.webui.version_check import check_for_update
|
||||
|
||||
@@ -126,6 +128,7 @@ _CAPABILITY_ROUTES = {
|
||||
}
|
||||
|
||||
_SYSTEM_ROUTES = {
|
||||
"/api/settings/runtime-config/update": "runtime-config-update",
|
||||
"/api/settings/cli-apps": "cli-list",
|
||||
"/api/settings/cli-apps/install": "cli-install",
|
||||
"/api/settings/cli-apps/update": "cli-update",
|
||||
@@ -148,6 +151,7 @@ _SYSTEM_ROUTES = {
|
||||
}
|
||||
|
||||
_SETTINGS_MUTATION_PATHS = frozenset({
|
||||
"/api/settings/runtime-config/update",
|
||||
"/api/settings/update",
|
||||
"/api/settings/model-configurations/create",
|
||||
"/api/settings/model-configurations/update",
|
||||
@@ -245,6 +249,8 @@ class WebUISettingsRouter:
|
||||
self._mcp_oauth_redirect_uri = mcp_oauth_redirect_uri
|
||||
self._mcp_oauth = McpOAuthManager()
|
||||
self._restart_sections: set[str] = set()
|
||||
self._restart_baselines: dict[str, dict[str, Any]] = {}
|
||||
self._restart_changes: dict[str, str] = {}
|
||||
self._models = model_domain.ModelSettingsHandler(settings, logger)
|
||||
self._capabilities = capability_domain.CapabilitySettingsHandler(
|
||||
settings,
|
||||
@@ -289,12 +295,18 @@ class WebUISettingsRouter:
|
||||
return await asyncio.to_thread(self._handle_settings_usage)
|
||||
|
||||
domain, action = route
|
||||
restart_before = (
|
||||
await asyncio.to_thread(self._restart_values, action)
|
||||
if action in {"runtime-config-update", "image-update", "web-search-update"}
|
||||
else None
|
||||
)
|
||||
domain_request = self._domain_request(
|
||||
connection,
|
||||
request,
|
||||
needs_local_browser=(
|
||||
action in {
|
||||
"api-start",
|
||||
"runtime-config-update",
|
||||
"features-enable",
|
||||
"channel-configure",
|
||||
"channel-connect",
|
||||
@@ -322,8 +334,36 @@ class WebUISettingsRouter:
|
||||
channel_name=(channel_connect[0] if channel_connect else None),
|
||||
connect_action=(channel_connect[1] if channel_connect else None),
|
||||
)
|
||||
if restart_before is not None and result.error is None and result.payload is not None:
|
||||
restart_after = await asyncio.to_thread(self._restart_values, action)
|
||||
if result.clear_restart_section:
|
||||
self._restart_baselines.pop(action, None)
|
||||
self._restart_changes.pop(action, None)
|
||||
elif result.payload.get("requires_restart") or action in self._restart_changes:
|
||||
baseline = self._restart_baselines.setdefault(action, {})
|
||||
for key, value in restart_before.items():
|
||||
if restart_after.get(key) != value:
|
||||
baseline.setdefault(key, value)
|
||||
for key in list(baseline):
|
||||
if restart_after.get(key) == baseline[key]:
|
||||
del baseline[key]
|
||||
if not baseline:
|
||||
self._restart_baselines.pop(action, None)
|
||||
self._restart_changes.pop(action, None)
|
||||
elif result.restart_section:
|
||||
self._restart_changes[action] = result.restart_section
|
||||
# Reversible changes are tracked separately from installation and reload failures.
|
||||
result.payload["requires_restart"] = False
|
||||
return self._render_result(result)
|
||||
|
||||
def _restart_values(self, action: str) -> dict[str, Any]:
|
||||
config = self.settings.config.load()
|
||||
if action == "runtime-config-update":
|
||||
return runtime_config_payload(config)
|
||||
if action == "image-update":
|
||||
return config.tools.image_generation.model_dump(mode="json")
|
||||
return {"use_jina_reader": config.tools.web.fetch.use_jina_reader}
|
||||
|
||||
@staticmethod
|
||||
def is_mutation_path(path: str) -> bool:
|
||||
return path in _SETTINGS_MUTATION_PATHS or _channel_connect_route(path) is not None
|
||||
@@ -381,7 +421,7 @@ class WebUISettingsRouter:
|
||||
) -> dict[str, Any]:
|
||||
if section and payload.get("requires_restart"):
|
||||
self._restart_sections.add(section)
|
||||
sections = sorted(self._restart_sections)
|
||||
sections = sorted(self._restart_sections | set(self._restart_changes.values()))
|
||||
updated = dict(payload)
|
||||
if sections:
|
||||
updated["requires_restart"] = True
|
||||
@@ -462,6 +502,7 @@ class WebUISettingsRouter:
|
||||
|
||||
def _system_operations(self) -> system_domain.SystemSettingsOperations:
|
||||
return system_domain.SystemSettingsOperations(
|
||||
update_runtime_config=update_runtime_config_settings,
|
||||
cli_apps_payload=cli_apps_payload,
|
||||
cli_apps_action=cli_apps_action,
|
||||
nanobot_features_payload=nanobot_features_payload,
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
"""Explicit non-channel runtime configuration exposed by the settings UI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ipaddress
|
||||
import math
|
||||
import re
|
||||
from pathlib import PurePosixPath, PureWindowsPath
|
||||
from typing import Any, cast
|
||||
|
||||
from pydantic import BaseModel, TypeAdapter, ValidationError
|
||||
|
||||
from nanobot.config.schema import Config
|
||||
from nanobot.security.network import is_loopback_host
|
||||
from nanobot.webui.settings_contracts import WebUISettingsError
|
||||
|
||||
# Only these leaves may be read or patched through this surface. Model/provider,
|
||||
# channel, and secret configuration keep their dedicated mutation contracts.
|
||||
RUNTIME_CONFIG_PATHS = (
|
||||
"agents.defaults.timezone",
|
||||
"agents.defaults.timezone_mode",
|
||||
"agents.defaults.unified_session",
|
||||
"agents.defaults.max_tool_iterations",
|
||||
"agents.defaults.max_concurrent_subagents",
|
||||
"agents.defaults.max_tool_result_chars",
|
||||
"agents.defaults.provider_retry_mode",
|
||||
"agents.defaults.tool_hint_max_length",
|
||||
"agents.defaults.dream.enabled",
|
||||
"gateway.host",
|
||||
"gateway.port",
|
||||
"gateway.restart_mode",
|
||||
"tools.exec.enable",
|
||||
"tools.exec.timeout",
|
||||
"tools.exec.path_prepend",
|
||||
"tools.exec.path_append",
|
||||
"tools.exec.sandbox",
|
||||
"tools.exec.sandbox_ro_binds",
|
||||
"tools.exec.sandbox_rw_binds",
|
||||
"tools.exec.allowed_env_keys",
|
||||
"tools.exec.allow_patterns",
|
||||
"tools.exec.deny_patterns",
|
||||
"tools.file.enable",
|
||||
"tools.my.enable",
|
||||
"tools.my.allow_set",
|
||||
"tools.cli_apps.enable",
|
||||
"tools.cli_apps.install_timeout",
|
||||
"tools.cli_apps.run_timeout",
|
||||
"tools.cli_apps.catalog_ttl_seconds",
|
||||
"tools.restrict_to_workspace",
|
||||
"tools.ssrf_whitelist",
|
||||
"tools.max_session_messages_per_minute",
|
||||
"tools.webui_allow_remote_package_install",
|
||||
"tools.web.enable",
|
||||
"tools.web.proxy",
|
||||
"tools.web.user_agent",
|
||||
"tools.image_generation.save_dir",
|
||||
"api.host",
|
||||
"api.timeout",
|
||||
)
|
||||
|
||||
|
||||
def _parent(config: Config, path: str) -> tuple[BaseModel, str]:
|
||||
parent: BaseModel = config
|
||||
*parts, leaf = path.split(".")
|
||||
for part in parts:
|
||||
value: object = getattr(parent, part)
|
||||
assert isinstance(value, BaseModel)
|
||||
parent = value
|
||||
return parent, leaf
|
||||
|
||||
|
||||
def runtime_config_payload(config: Config) -> dict[str, Any]:
|
||||
return {
|
||||
path: getattr(parent, leaf)
|
||||
for path in RUNTIME_CONFIG_PATHS
|
||||
for parent, leaf in [_parent(config, path)]
|
||||
}
|
||||
|
||||
|
||||
def update_runtime_config(
|
||||
config: Config, values: dict[str, Any], *, local_browser: bool,
|
||||
) -> bool:
|
||||
"""Validate the complete patch before changing any persisted configuration."""
|
||||
unknown = values.keys() - set(RUNTIME_CONFIG_PATHS)
|
||||
if unknown:
|
||||
raise WebUISettingsError("Unknown runtime setting: " + sorted(unknown)[0])
|
||||
remote_install = "tools.webui_allow_remote_package_install"
|
||||
if remote_install in values and not local_browser:
|
||||
if values[remote_install] != config.tools.webui_allow_remote_package_install:
|
||||
raise WebUISettingsError(
|
||||
"Change remote installation access from a browser on the gateway host.",
|
||||
status=403,
|
||||
)
|
||||
candidate = config.model_copy(deep=True)
|
||||
for path, value in values.items():
|
||||
parent, leaf = _parent(candidate, path)
|
||||
if isinstance(value, float) and not math.isfinite(value):
|
||||
raise WebUISettingsError(f"{path}: enter a finite number")
|
||||
try:
|
||||
field = type(parent).model_fields[leaf]
|
||||
parsed = TypeAdapter(field.rebuild_annotation()).validate_python(value, strict=True)
|
||||
except ValidationError as exc:
|
||||
message = exc.errors(include_input=False, include_url=False)[0]["msg"]
|
||||
raise WebUISettingsError(f"{path}: {message}") from None
|
||||
setattr(parent, leaf, parsed)
|
||||
try:
|
||||
# Dump aliases so legacy field names and timezone/model validators are
|
||||
# handled by the same schema as a normal configuration-file load.
|
||||
validated = Config.model_validate(candidate.model_dump(by_alias=True), strict=True)
|
||||
except ValidationError as exc:
|
||||
errors = exc.errors(include_input=False, include_url=False)
|
||||
error = errors[0]
|
||||
location = ".".join(str(part) for part in error["loc"])
|
||||
raise WebUISettingsError(f"{location}: {error['msg']}") from None
|
||||
|
||||
numeric_minima = {
|
||||
"agents.defaults.max_tool_iterations": 1,
|
||||
"agents.defaults.max_tool_result_chars": 1,
|
||||
"gateway.port": 1,
|
||||
"api.timeout": 1,
|
||||
}
|
||||
for path, minimum in numeric_minima.items():
|
||||
if path in values:
|
||||
parent, leaf = _parent(validated, path)
|
||||
if getattr(parent, leaf) < minimum:
|
||||
raise WebUISettingsError(f"{path}: must be at least {minimum}")
|
||||
if "gateway.port" in values and validated.gateway.port > 65535:
|
||||
raise WebUISettingsError("gateway.port: must be at most 65535")
|
||||
if "api.timeout" in values and validated.api.timeout > 3600:
|
||||
raise WebUISettingsError("api.timeout: must be at most 3600 seconds")
|
||||
for path in ("gateway.host", "api.host", "tools.image_generation.save_dir"):
|
||||
if path in values:
|
||||
parent, leaf = _parent(validated, path)
|
||||
if not str(getattr(parent, leaf)).strip():
|
||||
raise WebUISettingsError(f"{path}: must not be empty")
|
||||
if "tools.image_generation.save_dir" in values:
|
||||
directory = validated.tools.image_generation.save_dir
|
||||
if (PureWindowsPath(directory).drive or directory.startswith(("/", "\\"))
|
||||
or ".." in PurePosixPath(directory.replace("\\", "/")).parts):
|
||||
raise WebUISettingsError("tools.image_generation.save_dir: use a relative path inside the media directory")
|
||||
if "api.host" in values and not is_loopback_host(validated.api.host):
|
||||
if not validated.api.api_key.strip():
|
||||
raise WebUISettingsError("Set an API key in System before using a network bind address.")
|
||||
if "tools.exec.sandbox" in values and validated.tools.exec.sandbox not in {"", "bwrap", "seatbelt"}:
|
||||
raise WebUISettingsError("tools.exec.sandbox: choose no sandbox, bwrap, or seatbelt")
|
||||
if "tools.ssrf_whitelist" in values:
|
||||
for cidr in validated.tools.ssrf_whitelist:
|
||||
try:
|
||||
ipaddress.ip_network(cidr, strict=False)
|
||||
except ValueError:
|
||||
raise WebUISettingsError("tools.ssrf_whitelist: enter valid IP addresses or CIDR ranges") from None
|
||||
for path in ("tools.exec.allow_patterns", "tools.exec.deny_patterns"):
|
||||
if path in values:
|
||||
patterns = cast(list[str], values[path]) # Schema validation above guarantees list[str].
|
||||
for pattern in patterns:
|
||||
try:
|
||||
re.compile(pattern)
|
||||
except re.error:
|
||||
raise WebUISettingsError(f"{path}: invalid regular expression") from None
|
||||
before = runtime_config_payload(config)
|
||||
after = runtime_config_payload(validated)
|
||||
if before == after:
|
||||
return False
|
||||
config.agents = validated.agents
|
||||
config.tools = validated.tools
|
||||
config.gateway = validated.gateway
|
||||
config.api = validated.api
|
||||
return True
|
||||
@@ -32,6 +32,7 @@ from nanobot.webui.settings_contracts import (
|
||||
query_first,
|
||||
query_first_alias,
|
||||
)
|
||||
from nanobot.webui.settings_runtime import runtime_config_payload
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nanobot.webui.settings_services import WebUISettingsServices
|
||||
@@ -43,6 +44,7 @@ SettingsOperation = Callable[..., Any]
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SystemSettingsOperations:
|
||||
update_runtime_config: SettingsOperation
|
||||
cli_apps_payload: SettingsOperation
|
||||
cli_apps_action: SettingsOperation
|
||||
nanobot_features_payload: SettingsOperation
|
||||
@@ -62,6 +64,7 @@ class SystemSettingsOperations:
|
||||
|
||||
|
||||
class SystemSettingsPayload(TypedDict):
|
||||
runtime_config: dict[str, Any]
|
||||
runtime: dict[str, Any]
|
||||
usage: dict[str, Any]
|
||||
advanced: dict[str, Any]
|
||||
@@ -106,6 +109,7 @@ def system_settings_payload(
|
||||
workspace=config.workspace_path,
|
||||
)
|
||||
return {
|
||||
"runtime_config": runtime_config_payload(config),
|
||||
"runtime": {
|
||||
"config_path": str(config_path.expanduser()),
|
||||
"workspace_path": str(config.workspace_path),
|
||||
@@ -371,6 +375,22 @@ class SystemSettingsHandler:
|
||||
channel_name: str | None = None,
|
||||
connect_action: str | None = None,
|
||||
) -> SettingsRouteResult:
|
||||
if action == "runtime-config-update":
|
||||
values = (request.payload or {}).get("values")
|
||||
if not isinstance(values, dict):
|
||||
return SettingsRouteResult.failure(400, "Runtime settings must be an object")
|
||||
try:
|
||||
payload = await asyncio.to_thread(
|
||||
self.settings.mutate,
|
||||
operations.update_runtime_config,
|
||||
values,
|
||||
local_browser=request.local_browser,
|
||||
)
|
||||
except WebUISettingsError as exc:
|
||||
return SettingsRouteResult.failure(exc.status, exc.message)
|
||||
return SettingsRouteResult.success(
|
||||
payload, decorate_restart=True, restart_section="runtime",
|
||||
)
|
||||
if action == "cli-list":
|
||||
return await self._cli_apps(request, operations)
|
||||
if action.startswith("cli-"):
|
||||
|
||||
@@ -165,6 +165,7 @@ _WEBUI_MUTATION_PATHS = {
|
||||
"settings.api_service.stop": "/api/settings/api-service/stop",
|
||||
"settings.image_generation.update": "/api/settings/image-generation/update",
|
||||
"settings.transcription.update": "/api/settings/transcription/update",
|
||||
"settings.runtime_config.update": "/api/settings/runtime-config/update",
|
||||
"settings.network_safety.update": "/api/settings/network-safety/update",
|
||||
"settings.cli_app.install": "/api/settings/cli-apps/install",
|
||||
"settings.cli_app.update": "/api/settings/cli-apps/update",
|
||||
|
||||
Reference in new issue
Block a user