blaxel 0.1.9rc36__py3-none-any.whl → 0.1.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. blaxel/agents/__init__.py +52 -15
  2. blaxel/authentication/__init__.py +11 -2
  3. blaxel/client/api/compute/create_sandbox_preview.py +179 -0
  4. blaxel/client/api/compute/create_sandbox_preview_token.py +192 -0
  5. blaxel/client/api/compute/delete_sandbox_preview.py +167 -0
  6. blaxel/client/api/compute/delete_sandbox_preview_token.py +180 -0
  7. blaxel/client/api/compute/get_sandbox_preview.py +167 -0
  8. blaxel/client/api/compute/list_sandbox_preview_tokens.py +172 -0
  9. blaxel/client/api/compute/list_sandbox_previews.py +159 -0
  10. blaxel/client/api/compute/update_sandbox_preview.py +192 -0
  11. blaxel/client/api/integrations/get_integration.py +64 -7
  12. blaxel/client/api/workspaces/check_workspace_availability.py +165 -0
  13. blaxel/client/models/__init__.py +32 -2
  14. blaxel/client/models/check_workspace_availability_body.py +60 -0
  15. blaxel/client/models/delete_sandbox_preview_token_response_200.py +60 -0
  16. blaxel/client/models/integration.py +197 -0
  17. blaxel/client/models/integration_additional_infos.py +45 -0
  18. blaxel/client/models/integration_endpoint.py +143 -0
  19. blaxel/client/models/integration_endpoint_token.py +79 -0
  20. blaxel/client/models/integration_endpoints.py +61 -0
  21. blaxel/client/models/integration_headers.py +45 -0
  22. blaxel/client/models/integration_organization.py +88 -0
  23. blaxel/client/models/integration_query_params.py +45 -0
  24. blaxel/client/models/metrics.py +9 -0
  25. blaxel/client/models/preview.py +96 -0
  26. blaxel/client/models/preview_metadata.py +133 -0
  27. blaxel/client/models/preview_spec.py +79 -0
  28. blaxel/client/models/preview_token.py +96 -0
  29. blaxel/client/models/preview_token_metadata.py +97 -0
  30. blaxel/client/models/preview_token_spec.py +88 -0
  31. blaxel/common/autoload.py +0 -2
  32. blaxel/common/internal.py +75 -0
  33. blaxel/common/settings.py +6 -1
  34. blaxel/mcp/server.py +2 -1
  35. blaxel/sandbox/base.py +68 -0
  36. blaxel/sandbox/client/__init__.py +8 -0
  37. blaxel/sandbox/client/api/__init__.py +1 -0
  38. blaxel/sandbox/client/api/filesystem/__init__.py +0 -0
  39. blaxel/sandbox/client/api/filesystem/delete_filesystem_path.py +184 -0
  40. blaxel/sandbox/client/api/filesystem/get_filesystem_path.py +184 -0
  41. blaxel/sandbox/client/api/filesystem/put_filesystem_path.py +189 -0
  42. blaxel/sandbox/client/api/network/__init__.py +0 -0
  43. blaxel/sandbox/client/api/network/delete_network_process_pid_monitor.py +169 -0
  44. blaxel/sandbox/client/api/network/get_network_process_pid_ports.py +169 -0
  45. blaxel/sandbox/client/api/network/post_network_process_pid_monitor.py +195 -0
  46. blaxel/sandbox/client/api/process/__init__.py +0 -0
  47. blaxel/sandbox/client/api/process/delete_process_identifier.py +163 -0
  48. blaxel/sandbox/client/api/process/delete_process_identifier_kill.py +189 -0
  49. blaxel/sandbox/client/api/process/get_process.py +135 -0
  50. blaxel/sandbox/client/api/process/get_process_identifier.py +159 -0
  51. blaxel/sandbox/client/api/process/get_process_identifier_logs.py +188 -0
  52. blaxel/sandbox/client/api/process/get_process_identifier_logs_stream.py +190 -0
  53. blaxel/sandbox/client/api/process/post_process.py +176 -0
  54. blaxel/sandbox/client/client.py +162 -0
  55. blaxel/sandbox/client/errors.py +16 -0
  56. blaxel/sandbox/client/models/__init__.py +41 -0
  57. blaxel/sandbox/client/models/delete_network_process_pid_monitor_response_200.py +45 -0
  58. blaxel/sandbox/client/models/directory.py +112 -0
  59. blaxel/sandbox/client/models/error_response.py +60 -0
  60. blaxel/sandbox/client/models/file.py +105 -0
  61. blaxel/sandbox/client/models/file_request.py +78 -0
  62. blaxel/sandbox/client/models/file_with_content.py +114 -0
  63. blaxel/sandbox/client/models/get_network_process_pid_ports_response_200.py +45 -0
  64. blaxel/sandbox/client/models/get_process_identifier_logs_response_200.py +45 -0
  65. blaxel/sandbox/client/models/get_process_identifier_logs_stream_response_200.py +45 -0
  66. blaxel/sandbox/client/models/port_monitor_request.py +60 -0
  67. blaxel/sandbox/client/models/post_network_process_pid_monitor_response_200.py +45 -0
  68. blaxel/sandbox/client/models/process_kill_request.py +60 -0
  69. blaxel/sandbox/client/models/process_request.py +118 -0
  70. blaxel/sandbox/client/models/process_response.py +123 -0
  71. blaxel/sandbox/client/models/subdirectory.py +60 -0
  72. blaxel/sandbox/client/models/success_response.py +69 -0
  73. blaxel/sandbox/client/py.typed +1 -0
  74. blaxel/sandbox/client/types.py +46 -0
  75. blaxel/sandbox/filesystem.py +104 -0
  76. blaxel/sandbox/process.py +57 -0
  77. blaxel/sandbox/sandbox.py +92 -0
  78. blaxel/tools/__init__.py +62 -21
  79. {blaxel-0.1.9rc36.dist-info → blaxel-0.1.10.dist-info}/METADATA +1 -1
  80. {blaxel-0.1.9rc36.dist-info → blaxel-0.1.10.dist-info}/RECORD +82 -14
  81. blaxel/client/models/sandboxes.py +0 -129
  82. {blaxel-0.1.9rc36.dist-info → blaxel-0.1.10.dist-info}/WHEEL +0 -0
  83. {blaxel-0.1.9rc36.dist-info → blaxel-0.1.10.dist-info}/licenses/LICENSE +0 -0
blaxel/agents/__init__.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  import json
3
2
  from logging import getLogger
4
3
  from typing import Any, Awaitable
@@ -8,6 +7,7 @@ from ..client import client
8
7
  from ..client.api.agents import get_agent
9
8
  from ..client.models import Agent
10
9
  from ..common.env import env
10
+ from ..common.internal import get_global_unique_hash
11
11
  from ..common.settings import settings
12
12
  from ..instrumentation.span import SpanManager
13
13
 
@@ -17,6 +17,19 @@ class BlAgent:
17
17
  def __init__(self, name: str):
18
18
  self.name = name
19
19
 
20
+ @property
21
+ def internal_url(self):
22
+ """Get the internal URL for the agent using a hash of workspace and agent name."""
23
+ hash = get_global_unique_hash(settings.workspace, "agent", self.name)
24
+ return f"{settings.run_internal_protocol}://bl-{settings.env}-{hash}.{settings.run_internal_hostname}"
25
+
26
+ @property
27
+ def forced_url(self):
28
+ """Get the forced URL from environment variables if set."""
29
+ env_var = self.name.replace("-", "_").upper()
30
+ if env[f"BL_AGENT_{env_var}_URL"]:
31
+ return env[f"BL_AGENT_{env_var}_URL"]
32
+ return None
20
33
 
21
34
  @property
22
35
  def external_url(self):
@@ -30,11 +43,10 @@ class BlAgent:
30
43
 
31
44
  @property
32
45
  def url(self):
33
- env_var = self.name.replace("-", "_").upper()
34
- if env[f"BL_AGENT_{env_var}_URL"]:
35
- return env[f"BL_AGENT_{env_var}_URL"]
36
- if f"BL_AGENT_{env_var}_SERVICE_NAME" in settings.env:
37
- return f"https://{settings.env[f'BL_AGENT_{env_var}_SERVICE_NAME']}.{settings.run_internal_hostname}"
46
+ if self.forced_url:
47
+ return self.forced_url
48
+ if settings.run_internal_hostname:
49
+ return self.internal_url
38
50
  return self.external_url
39
51
 
40
52
  def call(self, url, input_data, headers: dict = {}, params: dict = {}):
@@ -52,14 +64,14 @@ class BlAgent:
52
64
  params=params
53
65
  )
54
66
 
55
- async def acall(self, input_data, headers: dict = {}, params: dict = {}):
67
+ async def acall(self, url, input_data, headers: dict = {}, params: dict = {}):
56
68
  logger.debug(f"Agent Calling: {self.name}")
57
69
  body = input_data
58
70
  if not isinstance(body, str):
59
71
  body = json.dumps(body)
60
72
 
61
73
  return await client.get_async_httpx_client().post(
62
- self.url,
74
+ url,
63
75
  headers={
64
76
  'Content-Type': 'application/json',
65
77
  **headers
@@ -69,19 +81,44 @@ class BlAgent:
69
81
  )
70
82
 
71
83
  def run(self, input: Any, headers: dict = {}, params: dict = {}) -> str:
72
- with SpanManager("blaxel-tracer").create_active_span(self.name, {"agent.name": self.name, "agent.args": json.dumps(input)}):
84
+ attributes = {
85
+ "agent.name": self.name,
86
+ "agent.args": json.dumps(input),
87
+ "span.type": "agent.run",
88
+ }
89
+ with SpanManager("blaxel-tracer").create_active_span(self.name, attributes) as span:
73
90
  logger.debug(f"Agent Calling: {self.name}")
74
91
  response = self.call(self.url, input, headers, params)
75
92
  if response.status_code >= 400:
76
- raise Exception(f"Agent {self.name} returned status code {response.status_code} with body {response.text}")
93
+ if not self.fallback_url:
94
+ span.set_attribute("agent.run.error", response.text)
95
+ raise Exception(f"Agent {self.name} returned status code {response.status_code} with body {response.text}")
96
+ response = self.call(self.fallback_url, input, headers, params)
97
+ if response.status_code >= 400:
98
+ span.set_attribute("agent.run.error", response.text)
99
+ raise Exception(f"Agent {self.name} returned status code {response.status_code} with body {response.text}")
100
+ span.set_attribute("agent.run.result", response.text)
77
101
  return response.text
78
102
 
79
103
  async def arun(self, input: Any, headers: dict = {}, params: dict = {}) -> Awaitable[str]:
80
- logger.debug(f"Agent Calling: {self.name}")
81
- response = await self.acall(input, headers, params)
82
- if response.status_code >= 400:
83
- raise Exception(f"Agent {self.name} returned status code {response.status_code} with body {response.text}")
84
- return response.text
104
+ attributes = {
105
+ "agent.name": self.name,
106
+ "agent.args": json.dumps(input),
107
+ "span.type": "agent.run",
108
+ }
109
+ with SpanManager("blaxel-tracer").create_active_span(self.name, attributes) as span:
110
+ logger.debug(f"Agent Calling: {self.name}")
111
+ response = await self.acall(self.url, input, headers, params)
112
+ if response.status_code >= 400:
113
+ if not self.fallback_url:
114
+ span.set_attribute("agent.run.error", response.text)
115
+ raise Exception(f"Agent {self.name} returned status code {response.status_code} with body {response.text}")
116
+ response = await self.acall(self.fallback_url, input, headers, params)
117
+ if response.status_code >= 400:
118
+ span.set_attribute("agent.run.error", response.text)
119
+ raise Exception(f"Agent {self.name} returned status code {response.status_code} with body {response.text}")
120
+ span.set_attribute("agent.run.result", response.text)
121
+ return response.text
85
122
 
86
123
  def __str__(self):
87
124
  return f"Agent {self.name}"
@@ -19,16 +19,25 @@ def get_credentials() -> Optional[CredentialsType]:
19
19
  Returns:
20
20
  Optional[CredentialsType]: The credentials or None if not found
21
21
  """
22
+ def get_workspace():
23
+ if os.environ.get("BL_WORKSPACE"):
24
+ return os.environ.get("BL_WORKSPACE")
25
+ home_dir = Path.home()
26
+ config_path = home_dir / '.blaxel' / 'config.yaml'
27
+ with open(config_path, encoding='utf-8') as f:
28
+ config_json = yaml.safe_load(f)
29
+ return config_json.get("context", {}).get("workspace")
30
+
22
31
  if os.environ.get("BL_API_KEY"):
23
32
  return CredentialsType(
24
33
  api_key=os.environ.get("BL_API_KEY"),
25
- workspace=os.environ.get("BL_WORKSPACE")
34
+ workspace=get_workspace()
26
35
  )
27
36
 
28
37
  if os.environ.get("BL_CLIENT_CREDENTIALS"):
29
38
  return CredentialsType(
30
39
  client_credentials=os.environ.get("BL_CLIENT_CREDENTIALS"),
31
- workspace=os.environ.get("BL_WORKSPACE")
40
+ workspace=get_workspace()
32
41
  )
33
42
 
34
43
  try:
@@ -0,0 +1,179 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import Client
8
+ from ...models.preview import Preview
9
+ from ...types import Response
10
+
11
+
12
+ def _get_kwargs(
13
+ sandbox_name: str,
14
+ *,
15
+ body: Preview,
16
+ ) -> dict[str, Any]:
17
+ headers: dict[str, Any] = {}
18
+
19
+ _kwargs: dict[str, Any] = {
20
+ "method": "post",
21
+ "url": f"/sandboxes/{sandbox_name}/previews",
22
+ }
23
+
24
+ if type(body) == dict:
25
+ _body = body
26
+ else:
27
+ _body = body.to_dict()
28
+
29
+ _kwargs["json"] = _body
30
+ headers["Content-Type"] = "application/json"
31
+
32
+ _kwargs["headers"] = headers
33
+ return _kwargs
34
+
35
+
36
+ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Preview]:
37
+ if response.status_code == 200:
38
+ response_200 = Preview.from_dict(response.json())
39
+
40
+ return response_200
41
+ if client.raise_on_unexpected_status:
42
+ raise errors.UnexpectedStatus(response.status_code, response.content)
43
+ else:
44
+ return None
45
+
46
+
47
+ def _build_response(*, client: Client, response: httpx.Response) -> Response[Preview]:
48
+ return Response(
49
+ status_code=HTTPStatus(response.status_code),
50
+ content=response.content,
51
+ headers=response.headers,
52
+ parsed=_parse_response(client=client, response=response),
53
+ )
54
+
55
+
56
+ def sync_detailed(
57
+ sandbox_name: str,
58
+ *,
59
+ client: Union[Client],
60
+ body: Preview,
61
+ ) -> Response[Preview]:
62
+ """Create Sandbox Preview
63
+
64
+ Create a preview
65
+
66
+ Args:
67
+ sandbox_name (str):
68
+ body (Preview): Preview of a Resource
69
+
70
+ Raises:
71
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
72
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
73
+
74
+ Returns:
75
+ Response[Preview]
76
+ """
77
+
78
+ kwargs = _get_kwargs(
79
+ sandbox_name=sandbox_name,
80
+ body=body,
81
+ )
82
+
83
+ response = client.get_httpx_client().request(
84
+ **kwargs,
85
+ )
86
+
87
+ return _build_response(client=client, response=response)
88
+
89
+
90
+ def sync(
91
+ sandbox_name: str,
92
+ *,
93
+ client: Union[Client],
94
+ body: Preview,
95
+ ) -> Optional[Preview]:
96
+ """Create Sandbox Preview
97
+
98
+ Create a preview
99
+
100
+ Args:
101
+ sandbox_name (str):
102
+ body (Preview): Preview of a Resource
103
+
104
+ Raises:
105
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
106
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
107
+
108
+ Returns:
109
+ Preview
110
+ """
111
+
112
+ return sync_detailed(
113
+ sandbox_name=sandbox_name,
114
+ client=client,
115
+ body=body,
116
+ ).parsed
117
+
118
+
119
+ async def asyncio_detailed(
120
+ sandbox_name: str,
121
+ *,
122
+ client: Union[Client],
123
+ body: Preview,
124
+ ) -> Response[Preview]:
125
+ """Create Sandbox Preview
126
+
127
+ Create a preview
128
+
129
+ Args:
130
+ sandbox_name (str):
131
+ body (Preview): Preview of a Resource
132
+
133
+ Raises:
134
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
135
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
136
+
137
+ Returns:
138
+ Response[Preview]
139
+ """
140
+
141
+ kwargs = _get_kwargs(
142
+ sandbox_name=sandbox_name,
143
+ body=body,
144
+ )
145
+
146
+ response = await client.get_async_httpx_client().request(**kwargs)
147
+
148
+ return _build_response(client=client, response=response)
149
+
150
+
151
+ async def asyncio(
152
+ sandbox_name: str,
153
+ *,
154
+ client: Union[Client],
155
+ body: Preview,
156
+ ) -> Optional[Preview]:
157
+ """Create Sandbox Preview
158
+
159
+ Create a preview
160
+
161
+ Args:
162
+ sandbox_name (str):
163
+ body (Preview): Preview of a Resource
164
+
165
+ Raises:
166
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
167
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
168
+
169
+ Returns:
170
+ Preview
171
+ """
172
+
173
+ return (
174
+ await asyncio_detailed(
175
+ sandbox_name=sandbox_name,
176
+ client=client,
177
+ body=body,
178
+ )
179
+ ).parsed
@@ -0,0 +1,192 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import Client
8
+ from ...models.preview_token import PreviewToken
9
+ from ...types import Response
10
+
11
+
12
+ def _get_kwargs(
13
+ sandbox_name: str,
14
+ preview_name: str,
15
+ *,
16
+ body: PreviewToken,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": f"/sandboxes/{sandbox_name}/previews/{preview_name}/tokens",
23
+ }
24
+
25
+ if type(body) == dict:
26
+ _body = body
27
+ else:
28
+ _body = body.to_dict()
29
+
30
+ _kwargs["json"] = _body
31
+ headers["Content-Type"] = "application/json"
32
+
33
+ _kwargs["headers"] = headers
34
+ return _kwargs
35
+
36
+
37
+ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[PreviewToken]:
38
+ if response.status_code == 200:
39
+ response_200 = PreviewToken.from_dict(response.json())
40
+
41
+ return response_200
42
+ if client.raise_on_unexpected_status:
43
+ raise errors.UnexpectedStatus(response.status_code, response.content)
44
+ else:
45
+ return None
46
+
47
+
48
+ def _build_response(*, client: Client, response: httpx.Response) -> Response[PreviewToken]:
49
+ return Response(
50
+ status_code=HTTPStatus(response.status_code),
51
+ content=response.content,
52
+ headers=response.headers,
53
+ parsed=_parse_response(client=client, response=response),
54
+ )
55
+
56
+
57
+ def sync_detailed(
58
+ sandbox_name: str,
59
+ preview_name: str,
60
+ *,
61
+ client: Union[Client],
62
+ body: PreviewToken,
63
+ ) -> Response[PreviewToken]:
64
+ """Create token for Sandbox Preview
65
+
66
+ Creates a token for a Sandbox Preview.
67
+
68
+ Args:
69
+ sandbox_name (str):
70
+ preview_name (str):
71
+ body (PreviewToken): Token for a Preview
72
+
73
+ Raises:
74
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
75
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
76
+
77
+ Returns:
78
+ Response[PreviewToken]
79
+ """
80
+
81
+ kwargs = _get_kwargs(
82
+ sandbox_name=sandbox_name,
83
+ preview_name=preview_name,
84
+ body=body,
85
+ )
86
+
87
+ response = client.get_httpx_client().request(
88
+ **kwargs,
89
+ )
90
+
91
+ return _build_response(client=client, response=response)
92
+
93
+
94
+ def sync(
95
+ sandbox_name: str,
96
+ preview_name: str,
97
+ *,
98
+ client: Union[Client],
99
+ body: PreviewToken,
100
+ ) -> Optional[PreviewToken]:
101
+ """Create token for Sandbox Preview
102
+
103
+ Creates a token for a Sandbox Preview.
104
+
105
+ Args:
106
+ sandbox_name (str):
107
+ preview_name (str):
108
+ body (PreviewToken): Token for a Preview
109
+
110
+ Raises:
111
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
112
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
113
+
114
+ Returns:
115
+ PreviewToken
116
+ """
117
+
118
+ return sync_detailed(
119
+ sandbox_name=sandbox_name,
120
+ preview_name=preview_name,
121
+ client=client,
122
+ body=body,
123
+ ).parsed
124
+
125
+
126
+ async def asyncio_detailed(
127
+ sandbox_name: str,
128
+ preview_name: str,
129
+ *,
130
+ client: Union[Client],
131
+ body: PreviewToken,
132
+ ) -> Response[PreviewToken]:
133
+ """Create token for Sandbox Preview
134
+
135
+ Creates a token for a Sandbox Preview.
136
+
137
+ Args:
138
+ sandbox_name (str):
139
+ preview_name (str):
140
+ body (PreviewToken): Token for a Preview
141
+
142
+ Raises:
143
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
144
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
145
+
146
+ Returns:
147
+ Response[PreviewToken]
148
+ """
149
+
150
+ kwargs = _get_kwargs(
151
+ sandbox_name=sandbox_name,
152
+ preview_name=preview_name,
153
+ body=body,
154
+ )
155
+
156
+ response = await client.get_async_httpx_client().request(**kwargs)
157
+
158
+ return _build_response(client=client, response=response)
159
+
160
+
161
+ async def asyncio(
162
+ sandbox_name: str,
163
+ preview_name: str,
164
+ *,
165
+ client: Union[Client],
166
+ body: PreviewToken,
167
+ ) -> Optional[PreviewToken]:
168
+ """Create token for Sandbox Preview
169
+
170
+ Creates a token for a Sandbox Preview.
171
+
172
+ Args:
173
+ sandbox_name (str):
174
+ preview_name (str):
175
+ body (PreviewToken): Token for a Preview
176
+
177
+ Raises:
178
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
179
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
180
+
181
+ Returns:
182
+ PreviewToken
183
+ """
184
+
185
+ return (
186
+ await asyncio_detailed(
187
+ sandbox_name=sandbox_name,
188
+ preview_name=preview_name,
189
+ client=client,
190
+ body=body,
191
+ )
192
+ ).parsed
@@ -0,0 +1,167 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import Client
8
+ from ...models.preview import Preview
9
+ from ...types import Response
10
+
11
+
12
+ def _get_kwargs(
13
+ sandbox_name: str,
14
+ preview_name: str,
15
+ ) -> dict[str, Any]:
16
+ _kwargs: dict[str, Any] = {
17
+ "method": "delete",
18
+ "url": f"/sandboxes/{sandbox_name}/previews/{preview_name}",
19
+ }
20
+
21
+ return _kwargs
22
+
23
+
24
+ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Preview]:
25
+ if response.status_code == 200:
26
+ response_200 = Preview.from_dict(response.json())
27
+
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
+
34
+
35
+ def _build_response(*, client: Client, response: httpx.Response) -> Response[Preview]:
36
+ return Response(
37
+ status_code=HTTPStatus(response.status_code),
38
+ content=response.content,
39
+ headers=response.headers,
40
+ parsed=_parse_response(client=client, response=response),
41
+ )
42
+
43
+
44
+ def sync_detailed(
45
+ sandbox_name: str,
46
+ preview_name: str,
47
+ *,
48
+ client: Union[Client],
49
+ ) -> Response[Preview]:
50
+ """Delete Sandbox Preview
51
+
52
+ Deletes a Sandbox Preview by name.
53
+
54
+ Args:
55
+ sandbox_name (str):
56
+ preview_name (str):
57
+
58
+ Raises:
59
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
60
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
61
+
62
+ Returns:
63
+ Response[Preview]
64
+ """
65
+
66
+ kwargs = _get_kwargs(
67
+ sandbox_name=sandbox_name,
68
+ preview_name=preview_name,
69
+ )
70
+
71
+ response = client.get_httpx_client().request(
72
+ **kwargs,
73
+ )
74
+
75
+ return _build_response(client=client, response=response)
76
+
77
+
78
+ def sync(
79
+ sandbox_name: str,
80
+ preview_name: str,
81
+ *,
82
+ client: Union[Client],
83
+ ) -> Optional[Preview]:
84
+ """Delete Sandbox Preview
85
+
86
+ Deletes a Sandbox Preview by name.
87
+
88
+ Args:
89
+ sandbox_name (str):
90
+ preview_name (str):
91
+
92
+ Raises:
93
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
94
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
95
+
96
+ Returns:
97
+ Preview
98
+ """
99
+
100
+ return sync_detailed(
101
+ sandbox_name=sandbox_name,
102
+ preview_name=preview_name,
103
+ client=client,
104
+ ).parsed
105
+
106
+
107
+ async def asyncio_detailed(
108
+ sandbox_name: str,
109
+ preview_name: str,
110
+ *,
111
+ client: Union[Client],
112
+ ) -> Response[Preview]:
113
+ """Delete Sandbox Preview
114
+
115
+ Deletes a Sandbox Preview by name.
116
+
117
+ Args:
118
+ sandbox_name (str):
119
+ preview_name (str):
120
+
121
+ Raises:
122
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
124
+
125
+ Returns:
126
+ Response[Preview]
127
+ """
128
+
129
+ kwargs = _get_kwargs(
130
+ sandbox_name=sandbox_name,
131
+ preview_name=preview_name,
132
+ )
133
+
134
+ response = await client.get_async_httpx_client().request(**kwargs)
135
+
136
+ return _build_response(client=client, response=response)
137
+
138
+
139
+ async def asyncio(
140
+ sandbox_name: str,
141
+ preview_name: str,
142
+ *,
143
+ client: Union[Client],
144
+ ) -> Optional[Preview]:
145
+ """Delete Sandbox Preview
146
+
147
+ Deletes a Sandbox Preview by name.
148
+
149
+ Args:
150
+ sandbox_name (str):
151
+ preview_name (str):
152
+
153
+ Raises:
154
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
155
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
156
+
157
+ Returns:
158
+ Preview
159
+ """
160
+
161
+ return (
162
+ await asyncio_detailed(
163
+ sandbox_name=sandbox_name,
164
+ preview_name=preview_name,
165
+ client=client,
166
+ )
167
+ ).parsed