main
md 67 lines 5.4 KB
Rendered Raw
1 # ui_server.py DOX
2
3 ## Purpose
4
5 - Own the `ui_server.py` helper module.
6 - This module configures and owns Flask/WebUI runtime route handlers.
7 - Keep this file-level DOX profile synchronized with `ui_server.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `ui_server.py` owns the runtime implementation.
12 - `ui_server.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `UiServerRuntime` (no explicit base class)
15 - `create(cls) -> 'UiServerRuntime'`
16 - `refresh_runtime_settings(self) -> None`
17 - `register_http_routes(self) -> None`
18 - `register_transport_handlers(self) -> None`
19 - `build_asgi_app(self, startup_monitor: StartupMonitor)`
20 - `access_log_enabled(self) -> bool`
21 - `UiRouteHandlers` (no explicit base class)
22 - `async login_handler(self)`
23 - `async logout_handler(self)`
24 - `async serve_splash(self)`
25 - `async serve_safe(self)`
26 - `async serve_index(self)`
27 - `async serve_ui_asset_bundle(self)`
28 - `async serve_builtin_plugin_asset(self, plugin_name, asset_path)`
29 - `async serve_plugin_asset(self, plugin_name, asset_path)`
30 - `async serve_extension_asset(self, asset_path)`
31 - `async serve_user_extension_asset(self, asset_path)`
32 - Top-level functions:
33 - `_positive_int_env(name: str, default: int) -> int`
34 - `configure_process_environment() -> None`
35 - Notable constants/configuration names: `UPLOAD_LIMIT_BYTES`, `SOCKETIO_PING_INTERVAL_SECONDS`, `SOCKETIO_PING_TIMEOUT_SECONDS`, `GZIP_MINIMUM_RESPONSE_BYTES`, `GZIP_COMPRESSION_LEVEL`, `UI_INDEX_ASSET_URL`, `A0_SOCKETIO_PING_INTERVAL_SECONDS`, `A0_SOCKETIO_PING_TIMEOUT_SECONDS`.
36
37 ## Runtime Contracts
38
39 - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
40 - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
41 - Socket.IO heartbeat defaults are intentionally longer than Engine.IO's short defaults so CLI sessions survive long prompt/context work; environment overrides must remain positive integers and fall back to source defaults when invalid.
42 - Observed side-effect areas: filesystem reads, network calls, subprocess/runtime control, WebSocket state, plugin state, settings/state persistence, secret handling.
43 - Imported dependency areas include: `asyncio`, `dataclasses`, `datetime`, `flask`, `helpers`, `helpers.api`, `helpers.extension`, `helpers.files`, `helpers.print_style`, `helpers.server_startup`, `helpers.ws`, `helpers.ws_manager`, `logging`, `os`, `secrets`, `socketio`, `starlette.middleware.gzip`.
44
45 ## Key Concepts
46
47 - Important called helpers/classes observed in the source: `logging.getLogger.setLevel`, `Localization.get.apply_process_timezone`, `_positive_int_env`, `field`, `Flask`, `threading.RLock`, `socketio.AsyncServer`, `WsManager`, `set_shared_ws_manager`, `cls`, `server_runtime.refresh_runtime_settings`, `settings_helper.get_settings`, `settings_helper.set_runtime_settings_snapshot`, `self.ws_manager.set_server_restart_broadcast`, `UiRouteHandlers`, `self.webapp.add_url_rule`, `register_api_route`, `register_ws_namespace`, `files.read_file`, `render_template_string`, `session.pop`.
48 - `serve_index()` bootstraps the normalized UI control visibility map, timezone and time-format preferences, and the complete enabled WebUI extension manifest so startup extension discovery requires no per-surface API requests.
49 - Authenticated extension asset routes serve root-contained files from both `extensions/webui/` and `usr/extensions/webui/`, matching the URLs emitted by the WebUI extension manifest.
50 - The authenticated `/` route uses `serve_splash()` to return the no-store, self-contained bootstrap document. The authenticated extensionless `/ui/index` route renders the existing index and runtime/user placeholders for the splash to install into the current document without navigation; `/index.html` remains a direct fallback for the same rendering path. The authenticated `/safe` route first returns a no-store, self-contained document that unregisters all origin service workers, then renders the existing index through `serve_index()` when its internal `__direct=1` marker is present; it never initializes the asset bundle or a worker. The authenticated `serve_ui_asset_bundle()` endpoint passes the application entry URL to the generic recursive bundler and supports gzip transfer and payload-specific ETag revalidation while component, extension, and Alpine lifecycles remain unchanged.
51 - The Starlette HTTP branch applies negotiated gzip to responses of at least 1 KiB at compression level 6 while preserving already encoded responses; Socket.IO remains outside that middleware branch.
52 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
53
54 ## Work Guidance
55
56 - Preserve public helper APIs used by core code and plugins unless every caller is updated.
57 - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
58 - Prefer adding cohesive helper functions here only when behavior is reused across modules.
59
60 ## Verification
61
62 - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
63 - No direct test reference was found by name search; choose the nearest behavioral test or perform a focused smoke check.
64
65 ## Child DOX Index
66
67 No child DOX files.