| 1 | # image_get.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `image_get.py` API endpoint. |
| 6 | - This module serves allowed image references and fallback file-type icons. |
| 7 | - Keep this file-level DOX profile synchronized with `image_get.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `image_get.py` owns the runtime implementation. |
| 12 | - `image_get.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `ImageGet` (`ApiHandler`) |
| 15 | - `get_methods(cls) -> list[str]` |
| 16 | - `async process(self, input: dict, request: Request) -> dict | Response` |
| 17 | - Top-level functions: |
| 18 | - `_resolve_allowed_image_path(path: str) -> str`: Resolve a requested image path and keep it inside Agent Zero's base dir. |
| 19 | - `_set_image_headers(response: Response, filename: str, file_ext: str) -> None` |
| 20 | - `_send_file_type_icon(file_ext, filename=...)`: Return appropriate icon for file type |
| 21 | - `_send_fallback_icon(icon_name)`: Return fallback icon from public directory |
| 22 | - Notable constants/configuration names: `IMAGE_EXTENSIONS`, `SVG_EXTENSIONS`, `SVG_CONTENT_SECURITY_POLICY`. |
| 23 | |
| 24 | ## Runtime Contracts |
| 25 | |
| 26 | - HTTP handlers must derive from `helpers.api.ApiHandler`; WebSocket handlers must derive from `helpers.ws.WsHandler`. |
| 27 | - Update this file whenever request payloads, authentication or CSRF requirements, response shapes, route side effects, or WebSocket event contracts change. |
| 28 | - `ImageGet` is an `ApiHandler`. |
| 29 | - `ImageGet` defines `process(...)`. |
| 30 | - `ImageGet` defines `get_methods(...)`. |
| 31 | - Observed side-effect areas: filesystem reads, network calls, subprocess/runtime control, settings/state persistence. |
| 32 | - Imported dependency areas include: `base64`, `helpers`, `helpers.api`, `io`, `mimetypes`, `os`, `pathlib`, `urllib.parse`. |
| 33 | |
| 34 | ## Key Concepts |
| 35 | |
| 36 | - Important called helpers/classes observed in the source: `runtime.is_development`, `Path.resolve`, `candidate.resolve`, `quote`, `_send_fallback_icon`, `files.get_abs_path`, `send_file`, `os.path.splitext.lower`, `os.path.basename`, `Path`, `candidate.is_absolute`, `resolved.relative_to`, `os.path.exists`, `ValueError`, `_set_image_headers`, `_send_file_type_icon`, `files.fix_dev_path`, `_resolve_allowed_image_path`, `files.exists`, `files.get_base_dir`. |
| 37 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 38 | |
| 39 | ## Work Guidance |
| 40 | |
| 41 | - Preserve authentication, CSRF, loopback, and API-key checks unless the endpoint contract explicitly changes. |
| 42 | - Update frontend callers, plugin callers, and tests together when payload shape changes. |
| 43 | - Use `helpers.api.Response` for non-JSON responses, files, redirects, or status-specific replies. |
| 44 | |
| 45 | ## Verification |
| 46 | |
| 47 | - Run endpoint-specific or API/WebSocket tests for changed behavior; smoke-test browser callers when no focused test exists. |
| 48 | - Related tests observed by source search: |
| 49 | - `tests/test_image_get_security.py` |
| 50 | |
| 51 | ## Child DOX Index |
| 52 | |
| 53 | No child DOX files. |