app_agents.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. from http import HTTPStatus
  2. from typing import Any, Optional, Union
  3. import httpx
  4. from ... import errors
  5. from ...client import AuthenticatedClient, Client
  6. from ...models.agent import Agent
  7. from ...types import UNSET, Response, Unset
  8. def _get_kwargs(
  9. *,
  10. directory: Union[Unset, str] = UNSET,
  11. ) -> dict[str, Any]:
  12. params: dict[str, Any] = {}
  13. params["directory"] = directory
  14. params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
  15. _kwargs: dict[str, Any] = {
  16. "method": "get",
  17. "url": "/agent",
  18. "params": params,
  19. }
  20. return _kwargs
  21. def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[list["Agent"]]:
  22. if response.status_code == 200:
  23. response_200 = []
  24. _response_200 = response.json()
  25. for response_200_item_data in _response_200:
  26. response_200_item = Agent.from_dict(response_200_item_data)
  27. response_200.append(response_200_item)
  28. return response_200
  29. if client.raise_on_unexpected_status:
  30. raise errors.UnexpectedStatus(response.status_code, response.content)
  31. else:
  32. return None
  33. def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[list["Agent"]]:
  34. return Response(
  35. status_code=HTTPStatus(response.status_code),
  36. content=response.content,
  37. headers=response.headers,
  38. parsed=_parse_response(client=client, response=response),
  39. )
  40. def sync_detailed(
  41. *,
  42. client: Union[AuthenticatedClient, Client],
  43. directory: Union[Unset, str] = UNSET,
  44. ) -> Response[list["Agent"]]:
  45. """List all agents
  46. Args:
  47. directory (Union[Unset, str]):
  48. Raises:
  49. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  50. httpx.TimeoutException: If the request takes longer than Client.timeout.
  51. Returns:
  52. Response[list['Agent']]
  53. """
  54. kwargs = _get_kwargs(
  55. directory=directory,
  56. )
  57. response = client.get_httpx_client().request(
  58. **kwargs,
  59. )
  60. return _build_response(client=client, response=response)
  61. def sync(
  62. *,
  63. client: Union[AuthenticatedClient, Client],
  64. directory: Union[Unset, str] = UNSET,
  65. ) -> Optional[list["Agent"]]:
  66. """List all agents
  67. Args:
  68. directory (Union[Unset, str]):
  69. Raises:
  70. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  71. httpx.TimeoutException: If the request takes longer than Client.timeout.
  72. Returns:
  73. list['Agent']
  74. """
  75. return sync_detailed(
  76. client=client,
  77. directory=directory,
  78. ).parsed
  79. async def asyncio_detailed(
  80. *,
  81. client: Union[AuthenticatedClient, Client],
  82. directory: Union[Unset, str] = UNSET,
  83. ) -> Response[list["Agent"]]:
  84. """List all agents
  85. Args:
  86. directory (Union[Unset, str]):
  87. Raises:
  88. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  89. httpx.TimeoutException: If the request takes longer than Client.timeout.
  90. Returns:
  91. Response[list['Agent']]
  92. """
  93. kwargs = _get_kwargs(
  94. directory=directory,
  95. )
  96. response = await client.get_async_httpx_client().request(**kwargs)
  97. return _build_response(client=client, response=response)
  98. async def asyncio(
  99. *,
  100. client: Union[AuthenticatedClient, Client],
  101. directory: Union[Unset, str] = UNSET,
  102. ) -> Optional[list["Agent"]]:
  103. """List all agents
  104. Args:
  105. directory (Union[Unset, str]):
  106. Raises:
  107. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  108. httpx.TimeoutException: If the request takes longer than Client.timeout.
  109. Returns:
  110. list['Agent']
  111. """
  112. return (
  113. await asyncio_detailed(
  114. client=client,
  115. directory=directory,
  116. )
  117. ).parsed