tool_client.py 849 B

123456789101112131415161718192021222324
  1. import httpx
  2. from core_domain import ToolBindingDetailContract
  3. class ToolServiceClientError(Exception):
  4. pass
  5. class ToolServiceClient:
  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 get_tool_binding_detail(
  10. self,
  11. *,
  12. binding_id: str) -> ToolBindingDetailContract:
  13. try:
  14. with httpx.Client(timeout=self.timeout_seconds) as client:
  15. response = client.get(f"{self.base_url}/tools/bindings/{binding_id}")
  16. response.raise_for_status()
  17. return ToolBindingDetailContract.model_validate(response.json())
  18. except httpx.HTTPError as exc:
  19. raise ToolServiceClientError(f"tool-service request failed: {exc}") from exc