| 1 | # chat_media.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `chat_media.py` helper module. |
| 6 | - This module materializes, stores, and resolves chat-scoped image/media artifacts. |
| 7 | - Keep this file-level DOX profile synchronized with `chat_media.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `chat_media.py` owns the runtime implementation. |
| 12 | - `chat_media.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `ChatImage` (no explicit base class) |
| 15 | - Top-level functions: |
| 16 | - `screenshot_dir(context_id: str, source: str) -> Path` |
| 17 | - `artifact_dir(context_id: str, category: ImageCategory=..., source: str=...) -> Path` |
| 18 | - `save_image_bytes(context_id: str, payload: bytes, mime_type: str=..., category: ImageCategory=..., source: str=..., preferred_name: str=..., max_bytes: int | None=...) -> ChatImage` |
| 19 | - `save_image_base64(context_id: str, data: str, mime_type: str=..., category: ImageCategory=..., source: str=..., preferred_name: str=..., max_bytes: int | None=...) -> ChatImage` |
| 20 | - `save_image_file(context_id: str, path: str | Path, category: ImageCategory=..., source: str=..., preferred_name: str=..., max_bytes: int | None=...) -> ChatImage` |
| 21 | - `save_image_data_url(context_id: str, data_url: str, category: ImageCategory=..., source: str=..., preferred_name: str=..., max_bytes: int | None=...) -> ChatImage` |
| 22 | - `materialize_image_ref(context_id: str, url: str, source: str=..., preferred_name: str=..., max_bytes: int | None=...) -> str` |
| 23 | - `is_chat_scoped_path(context_id: str, path: str | Path) -> bool` |
| 24 | - `infer_source(value: str=..., preferred_name: str=...) -> str` |
| 25 | - `category_for_source(source: str) -> ImageCategory` |
| 26 | - `_guess_image_mime(path: Path) -> str` |
| 27 | - `_is_data_image_url(value: str) -> bool` |
| 28 | - `_split_image_data_url(data_url: str) -> tuple[str, str]` |
| 29 | - Notable constants/configuration names: `DEFAULT_MAX_IMAGE_BYTES`. |
| 30 | |
| 31 | ## Runtime Contracts |
| 32 | |
| 33 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 34 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 35 | - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion. |
| 36 | - Imported dependency areas include: `__future__`, `dataclasses`, `helpers`, `pathlib`, `time`, `typing`, `uuid`. |
| 37 | |
| 38 | ## Key Concepts |
| 39 | |
| 40 | - Important called helpers/classes observed in the source: `dataclass`, `artifact_dir`, `bytes`, `media_artifacts.normalize_mime`, `media_artifacts.guess_extension`, `media_artifacts.safe_filename`, `Path`, `time.strftime`, `path.parent.mkdir`, `path.write_bytes`, `ChatImage`, `media_artifacts.decode_base64_payload`, `save_image_bytes`, `image_path.read_bytes`, `_split_image_data_url`, `save_image_base64`, `str.strip`, `category_for_source`, `_is_data_image_url`, `images.resolve_ref`. |
| 41 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 42 | |
| 43 | ## Work Guidance |
| 44 | |
| 45 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 46 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 47 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 48 | |
| 49 | ## Verification |
| 50 | |
| 51 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 52 | - Related tests observed by source search: |
| 53 | - `tests/test_browser_agent_regressions.py` |
| 54 | - `tests/test_host_browser_connector.py` |
| 55 | - `tests/test_tool_action_contracts.py` |
| 56 | - `tests/test_vision_load_image_refs.py` |
| 57 | |
| 58 | ## Child DOX Index |
| 59 | |
| 60 | No child DOX files. |