tool_client.py 972 B

123456789101112131415161718192021222324252627282930
  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. tenant_id: str,
  13. binding_id: str,
  14. ) -> ToolBindingDetailContract:
  15. try:
  16. with httpx.Client(timeout=self.timeout_seconds) as client:
  17. response = client.get(
  18. f"{self.base_url}/tools/bindings/{binding_id}",
  19. params={"tenant_id": tenant_id},
  20. )
  21. response.raise_for_status()
  22. return ToolBindingDetailContract.model_validate(response.json())
  23. except httpx.HTTPError as exc:
  24. raise ToolServiceClientError(f"tool-service request failed: {exc}") from exc