| 1 | # message.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `message.py` API endpoint. |
| 6 | - This module submits a user message and runs agent processing synchronously through the UI API. |
| 7 | - Keep this file-level DOX profile synchronized with `message.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `message.py` owns the runtime implementation. |
| 12 | - `message.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `Message` (`ApiHandler`) |
| 15 | - `async process(self, input: dict, request: Request) -> dict | Response` |
| 16 | - `async respond(self, task: DeferredTask, context: AgentContext)` |
| 17 | - `async communicate(self, input: dict, request: Request)` |
| 18 | |
| 19 | ## Runtime Contracts |
| 20 | |
| 21 | - HTTP handlers must derive from `helpers.api.ApiHandler`; WebSocket handlers must derive from `helpers.ws.WsHandler`. |
| 22 | - Update this file whenever request payloads, authentication or CSRF requirements, response shapes, route side effects, or WebSocket event contracts change. |
| 23 | - `Message` is an `ApiHandler`. |
| 24 | - `Message` defines `process(...)`. |
| 25 | - Observed side-effect areas: filesystem reads, filesystem writes, settings/state persistence, scheduler state. |
| 26 | - Imported dependency areas include: `agent`, `helpers`, `helpers.api`, `helpers.defer`, `helpers.security`, `os`. |
| 27 | |
| 28 | ## Key Concepts |
| 29 | |
| 30 | - Important called helpers/classes observed in the source: `request.content_type.startswith`, `self.use_context`, `mq.log_user_message`, `self.communicate`, `self.respond`, `task.result`, `request.files.getlist`, `files.get_abs_path`, `request.get_json`, `extension.call_extensions_async`, `context.communicate`, `os.makedirs`, `UserMessage`, `safe_filename`, `attachment.save`, `context.get_agent`, `os.path.join`. |
| 31 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 32 | |
| 33 | ## Work Guidance |
| 34 | |
| 35 | - Preserve authentication, CSRF, loopback, and API-key checks unless the endpoint contract explicitly changes. |
| 36 | - Update frontend callers, plugin callers, and tests together when payload shape changes. |
| 37 | - Use `helpers.api.Response` for non-JSON responses, files, redirects, or status-specific replies. |
| 38 | |
| 39 | ## Verification |
| 40 | |
| 41 | - Run endpoint-specific or API/WebSocket tests for changed behavior; smoke-test browser callers when no focused test exists. |
| 42 | - Related tests observed by source search: |
| 43 | - `tests/email_parser_test.py` |
| 44 | - `tests/rate_limiter_test.py` |
| 45 | - `tests/test_api_chat_lifetime.py` |
| 46 | - `tests/test_browser_agent_regressions.py` |
| 47 | - `tests/test_chat_compaction.py` |
| 48 | - `tests/test_docker_release_plan.py` |
| 49 | - `tests/test_document_query_fallback.py` |
| 50 | - `tests/test_download_toast_regressions.py` |
| 51 | |
| 52 | ## Child DOX Index |
| 53 | |
| 54 | No child DOX files. |