runtime_client.py 919 B

12345678910111213141516171819202122232425
  1. import httpx
  2. from core_domain import RunBootstrapContract, RunCreateContract
  3. class RuntimeServiceClientError(Exception):
  4. pass
  5. class RuntimeServiceClient:
  6. def __init__(self, base_url: str, timeout_seconds: float = 10.0) -> None:
  7. self.base_url = base_url.rstrip("/")
  8. self.timeout_seconds = timeout_seconds
  9. def create_run(self, payload: RunCreateContract) -> RunBootstrapContract:
  10. try:
  11. with httpx.Client(timeout=self.timeout_seconds) as client:
  12. response = client.post(
  13. f"{self.base_url}/runtime/runs",
  14. json=payload.model_dump(mode="json"),
  15. )
  16. response.raise_for_status()
  17. return RunBootstrapContract.model_validate(response.json())
  18. except httpx.HTTPError as exc:
  19. raise RuntimeServiceClientError(f"runtime-service request failed: {exc}") from exc