responses.py
python
sha256:da49a05fd62cda46a7d73ec53a8d0adc5835d2070f6f0c51b12233a673c2e109
docs(mwp-1): mark Phase 5 complete, all acceptance criteria…
Sonnet 4.6
27 days ago
| 1 | """Protocol introspection response models and helpers.""" |
| 2 | |
| 3 | from pydantic import BaseModel |
| 4 | |
| 5 | from muse.core.types import content_hash |
| 6 | from musehub.types.json_types import JSONValue |
| 7 | from musehub.protocol.version import MUSE_VERSION |
| 8 | |
| 9 | class ProtocolInfoResponse(BaseModel): |
| 10 | """Response shape for ``GET /protocol``.""" |
| 11 | |
| 12 | version: str |
| 13 | protocol_hash: str |
| 14 | event_count: int |
| 15 | tool_count: int |
| 16 | |
| 17 | def compute_protocol_hash(data: JSONValue) -> str: |
| 18 | """Return a stable ``sha256:``-prefixed content ID for any JSON-serialisable object. |
| 19 | |
| 20 | Delegates to ``muse.core.types.content_hash`` for canonical compact JSON |
| 21 | serialisation (``sort_keys=True``, no whitespace, UTF-8) before hashing. |
| 22 | |
| 23 | >>> compute_protocol_hash({"b": 2, "a": 1}) == compute_protocol_hash({"a": 1, "b": 2}) |
| 24 | True |
| 25 | """ |
| 26 | return content_hash(data) |
| 27 | |
| 28 | def build_protocol_info(event_count: int, tool_count: int, schema: JSONValue) -> ProtocolInfoResponse: |
| 29 | """Construct a ``ProtocolInfoResponse`` from live event/tool counts and the full schema.""" |
| 30 | return ProtocolInfoResponse( |
| 31 | version=MUSE_VERSION, |
| 32 | protocol_hash=compute_protocol_hash(schema), |
| 33 | event_count=event_count, |
| 34 | tool_count=tool_count, |
| 35 | ) |
File History
1 commit
sha256:da49a05fd62cda46a7d73ec53a8d0adc5835d2070f6f0c51b12233a673c2e109
docs(mwp-1): mark Phase 5 complete, all acceptance criteria…
Sonnet 4.6
27 days ago