mas-modes-v0.1-spec/ (contract, message + gateway-event schemas, transition table, message fixtures, statute) vendored into mas_modes. EmailMode implements the master role over the reference ticket service (MasterStore): handoff, negotiation by email, statuses in the thread, timeouts, resume by email, principle 10 shared via mas_modes.mailer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assistant: claude-code Assistant-Model: opus Assistant-Process: 5787@bnt-lap001 Assistant-Session: 5db26b82-138b-40cc-9856-4d5eb0f752fd
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""MAS mode contract v0.1: email hands a case to another mode, or works
|
|
inside a control flow it does not own (`mas-modes-v0.1-spec/CONTRACT.md`).
|
|
|
|
`schema/` and `conformance/` are vendored unchanged from the bundle.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from functools import lru_cache
|
|
from importlib import resources
|
|
|
|
CONTRACT_VERSION = "0.1"
|
|
|
|
|
|
def _load(name: str):
|
|
return json.loads(resources.files(__name__).joinpath(name).read_text(encoding="utf-8"))
|
|
|
|
|
|
@lru_cache(maxsize=None)
|
|
def _validator(schema_file: str):
|
|
from jsonschema import Draft202012Validator
|
|
return Draft202012Validator(_load(f"schema/{schema_file}"))
|
|
|
|
|
|
def message_errors(msg: dict) -> list[str]:
|
|
"""Schema errors for a contract message; empty if valid."""
|
|
return [e.message for e in _validator("mas-modes-v0.1.schema.json").iter_errors(msg)]
|
|
|
|
|
|
def event_errors(event: dict) -> list[str]:
|
|
"""Schema errors for a normalized gateway event; empty if valid."""
|
|
return [e.message for e in _validator("mas-event-v0.1.schema.json").iter_errors(event)]
|
|
|
|
|
|
def transitions() -> dict:
|
|
return _load("conformance/transitions.json")
|
|
|
|
|
|
def message_fixtures() -> dict:
|
|
return _load("conformance/messages.json")
|
|
|
|
|
|
def flow_fixtures() -> list[dict]:
|
|
return _load("conformance/flows.json")["flows"]
|