main
md 51 lines 2.59 KB
Rendered Raw
1 # api_message.py DOX
2
3 ## Purpose
4
5 - Own the `api_message.py` API endpoint.
6 - This module accepts external API messages and dispatches them into Agent Zero chat processing.
7 - Keep this file-level DOX profile synchronized with `api_message.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `api_message.py` owns the runtime implementation.
12 - `api_message.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `ApiMessage` (`ApiHandler`)
15 - `requires_auth(cls) -> bool`
16 - `requires_csrf(cls) -> bool`
17 - `requires_api_key(cls) -> bool`
18 - `async process(self, input: dict, request: Request) -> dict | Response`
19
20 ## Runtime Contracts
21
22 - HTTP handlers must derive from `helpers.api.ApiHandler`; WebSocket handlers must derive from `helpers.ws.WsHandler`.
23 - Update this file whenever request payloads, authentication or CSRF requirements, response shapes, route side effects, or WebSocket event contracts change.
24 - `ApiMessage` is an `ApiHandler`.
25 - `ApiMessage` defines `process(...)`.
26 - `ApiMessage` defines `requires_auth(...)`.
27 - `ApiMessage` defines `requires_csrf(...)`.
28 - `ApiMessage` defines `requires_api_key(...)`.
29 - Observed side-effect areas: filesystem reads, filesystem writes, settings/state persistence, secret handling, scheduler state.
30 - Imported dependency areas include: `agent`, `base64`, `datetime`, `helpers`, `helpers.api`, `helpers.print_style`, `helpers.projects`, `helpers.security`, `initialize`, `os`, `uuid`.
31
32 ## Key Concepts
33
34 - Important called helpers/classes observed in the source: `context.set_data`, `datetime.now`, `Response`, `files.get_abs_path`, `os.makedirs`, `AgentContext.use`, `context.get_data`, `initialize_agent`, `AgentContext`, `context.log.log`, `context.communicate`, `ValueError`, `uuid.uuid4`, `UserMessage`, `task.result`, `PrintStyle.error`, `safe_filename`, `base64.b64decode`, `os.path.join`, `activate_project`.
35 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
36
37 ## Work Guidance
38
39 - Preserve authentication, CSRF, loopback, and API-key checks unless the endpoint contract explicitly changes.
40 - Update frontend callers, plugin callers, and tests together when payload shape changes.
41 - Use `helpers.api.Response` for non-JSON responses, files, redirects, or status-specific replies.
42
43 ## Verification
44
45 - Run endpoint-specific or API/WebSocket tests for changed behavior; smoke-test browser callers when no focused test exists.
46 - Related tests observed by source search:
47 - `tests/test_api_chat_lifetime.py`
48
49 ## Child DOX Index
50
51 No child DOX files.