| 1 | # media_artifacts.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `media_artifacts.py` helper module. |
| 6 | - This module validates, decodes, names, and normalizes media artifact payloads. |
| 7 | - Keep this file-level DOX profile synchronized with `media_artifacts.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `media_artifacts.py` owns the runtime implementation. |
| 12 | - `media_artifacts.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `MediaArtifactError` (`ValueError`) |
| 15 | - `EmptyBase64Data` (`MediaArtifactError`) |
| 16 | - `InvalidBase64Data` (`MediaArtifactError`) |
| 17 | - `ArtifactTooLarge` (`MediaArtifactError`) |
| 18 | - `Base64Payload` (no explicit base class) |
| 19 | - `ImageDataUrl` (no explicit base class) |
| 20 | - `SavedArtifact` (no explicit base class) |
| 21 | - Top-level functions: |
| 22 | - `compact_base64(data: str) -> str` |
| 23 | - `estimated_base64_decoded_size(data: str) -> int` |
| 24 | - `decode_base64_payload(data: str, max_bytes: int | None=...) -> Base64Payload` |
| 25 | - `normalize_mime(mime_type: str, default: str=..., required_prefix: str=...) -> str` |
| 26 | - `guess_extension(mime_type: str, fallback: str=...) -> str` |
| 27 | - `filename_from_uri(uri: str) -> str` |
| 28 | - `safe_filename(value: str, default: str=..., default_extension: str=...) -> str` |
| 29 | - `image_data_url_from_base64(data: str, mime_type: str=..., max_bytes: int | None=...) -> ImageDataUrl` |
| 30 | - `save_base64_artifact(data: str, mime_type: str=..., directory_parts: tuple[str, ...], preferred_name: str=..., default_filename: str=..., max_bytes: int | None=...) -> SavedArtifact` |
| 31 | - Notable constants/configuration names: `DEFAULT_MAX_ARTIFACT_SIZE_BYTES`. |
| 32 | |
| 33 | ## Runtime Contracts |
| 34 | |
| 35 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 36 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 37 | - Observed side-effect areas: filesystem reads, filesystem writes, network calls. |
| 38 | - Imported dependency areas include: `__future__`, `base64`, `binascii`, `dataclasses`, `helpers`, `mimetypes`, `pathlib`, `urllib.parse`, `uuid`. |
| 39 | |
| 40 | ## Key Concepts |
| 41 | |
| 42 | - Important called helpers/classes observed in the source: `dataclass`, `join`, `compact_base64`, `Base64Payload`, `str.strip.lower`, `str.strip`, `urlparse`, `decode_base64_payload`, `normalize_mime`, `ImageDataUrl`, `guess_extension`, `safe_filename`, `Path`, `artifact_dir.mkdir`, `path.write_bytes`, `SavedArtifact`, `super.__init__`, `EmptyBase64Data`, `estimated_base64_decoded_size`, `base64.b64decode`. |
| 43 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 44 | |
| 45 | ## Work Guidance |
| 46 | |
| 47 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 48 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 49 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 50 | |
| 51 | ## Verification |
| 52 | |
| 53 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 54 | - Related tests observed by source search: |
| 55 | - `tests/test_mcp_handler_multimodal.py` |
| 56 | - `tests/test_media_artifacts.py` |
| 57 | |
| 58 | ## Child DOX Index |
| 59 | |
| 60 | No child DOX files. |