blaxel 0.1.9rc35__py3-none-any.whl → 0.1.9rc37__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.
- blaxel/agents/__init__.py +53 -16
- blaxel/authentication/__init__.py +3 -4
- blaxel/client/api/compute/__init__.py +0 -0
- blaxel/client/api/compute/create_sandbox.py +166 -0
- blaxel/client/api/compute/delete_sandbox.py +154 -0
- blaxel/client/api/compute/get_sandbox.py +154 -0
- blaxel/client/api/compute/list_sandboxes.py +135 -0
- blaxel/client/api/compute/start_sandbox.py +157 -0
- blaxel/client/api/compute/stop_sandbox.py +157 -0
- blaxel/client/api/compute/update_sandbox.py +179 -0
- blaxel/client/api/default/list_sandbox_hub_definitions.py +123 -0
- blaxel/client/api/functions/list_function_revisions.py +16 -11
- blaxel/client/api/knowledgebases/list_knowledgebase_revisions.py +16 -11
- blaxel/client/api/models/list_model_revisions.py +16 -11
- blaxel/client/api/templates/list_templates.py +16 -11
- blaxel/client/models/__init__.py +32 -2
- blaxel/client/models/agent_spec.py +25 -69
- blaxel/client/models/core_spec.py +1 -45
- blaxel/client/models/function_spec.py +1 -45
- blaxel/client/models/last_n_requests_metric.py +18 -0
- blaxel/client/models/metrics.py +20 -0
- blaxel/client/models/model_spec.py +1 -45
- blaxel/client/models/{agent_chain.py → port.py} +23 -32
- blaxel/client/models/request_total_metric.py +12 -1
- blaxel/client/models/request_total_response_data.py +97 -0
- blaxel/client/models/resource_log.py +9 -0
- blaxel/client/models/resource_metrics.py +144 -0
- blaxel/client/models/resource_metrics_request_total_per_code_previous.py +45 -0
- blaxel/client/models/resource_metrics_rps_per_code_previous.py +45 -0
- blaxel/client/models/runtime.py +83 -7
- blaxel/client/models/runtime_configuration.py +45 -0
- blaxel/client/models/sandbox.py +129 -0
- blaxel/client/models/sandbox_definition.py +181 -0
- blaxel/client/models/sandbox_spec.py +208 -0
- blaxel/client/models/sandboxes.py +129 -0
- blaxel/client/models/serverless_config.py +29 -1
- blaxel/client/models/serverless_config_configuration.py +45 -0
- blaxel/client/models/start_sandbox.py +94 -0
- blaxel/client/models/stop_sandbox.py +94 -0
- blaxel/client/models/trigger.py +98 -0
- blaxel/client/models/trigger_configuration.py +45 -0
- blaxel/client/models/workspace.py +20 -0
- blaxel/client/models/workspace_runtime.py +61 -0
- blaxel/common/autoload.py +0 -4
- blaxel/common/internal.py +75 -0
- blaxel/common/settings.py +6 -1
- blaxel/instrumentation/exporters.py +3 -6
- blaxel/instrumentation/manager.py +5 -3
- blaxel/mcp/client.py +1 -3
- blaxel/mcp/server.py +4 -4
- blaxel/models/__init__.py +2 -1
- blaxel/models/custom/langchain/gemini.py +41 -18
- blaxel/models/custom/llamaindex/cohere.py +25 -16
- blaxel/models/custom/pydantic/gemini.py +0 -1
- blaxel/models/livekit.py +1 -1
- blaxel/tools/__init__.py +63 -22
- blaxel/tools/langchain.py +1 -2
- {blaxel-0.1.9rc35.dist-info → blaxel-0.1.9rc37.dist-info}/METADATA +1 -4
- {blaxel-0.1.9rc35.dist-info → blaxel-0.1.9rc37.dist-info}/RECORD +61 -37
- {blaxel-0.1.9rc35.dist-info → blaxel-0.1.9rc37.dist-info}/WHEEL +0 -0
- {blaxel-0.1.9rc35.dist-info → blaxel-0.1.9rc37.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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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}"
|
@@ -98,5 +135,5 @@ async def get_agent_metadata(name):
|
|
98
135
|
return Agent.from_dict(cache_data)
|
99
136
|
try:
|
100
137
|
return await get_agent.asyncio(client=client, agent_name=name)
|
101
|
-
except Exception
|
138
|
+
except Exception:
|
102
139
|
return None
|
@@ -4,7 +4,6 @@ from pathlib import Path
|
|
4
4
|
from typing import Optional
|
5
5
|
|
6
6
|
import yaml
|
7
|
-
from httpx import Auth
|
8
7
|
|
9
8
|
from .apikey import ApiKey
|
10
9
|
from .clientcredentials import ClientCredentials
|
@@ -73,15 +72,15 @@ def auth(env: str, base_url: str) -> BlaxelAuth:
|
|
73
72
|
return None
|
74
73
|
|
75
74
|
if credentials.api_key:
|
76
|
-
logger.debug(
|
75
|
+
logger.debug("Using API key for authentication")
|
77
76
|
return ApiKey(credentials, credentials.workspace, base_url)
|
78
77
|
|
79
78
|
if credentials.client_credentials:
|
80
|
-
logger.debug(
|
79
|
+
logger.debug("Using client credentials for authentication")
|
81
80
|
return ClientCredentials(credentials, credentials.workspace, base_url)
|
82
81
|
|
83
82
|
if credentials.device_code:
|
84
|
-
logger.debug(
|
83
|
+
logger.debug("Using device code for authentication")
|
85
84
|
return DeviceMode(credentials, credentials.workspace, base_url)
|
86
85
|
|
87
86
|
return BlaxelAuth(credentials, credentials.workspace, base_url)
|
File without changes
|
@@ -0,0 +1,166 @@
|
|
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.sandbox import Sandbox
|
9
|
+
from ...types import Response
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
*,
|
14
|
+
body: Sandbox,
|
15
|
+
) -> dict[str, Any]:
|
16
|
+
headers: dict[str, Any] = {}
|
17
|
+
|
18
|
+
_kwargs: dict[str, Any] = {
|
19
|
+
"method": "post",
|
20
|
+
"url": "/sandboxes",
|
21
|
+
}
|
22
|
+
|
23
|
+
if type(body) == dict:
|
24
|
+
_body = body
|
25
|
+
else:
|
26
|
+
_body = body.to_dict()
|
27
|
+
|
28
|
+
_kwargs["json"] = _body
|
29
|
+
headers["Content-Type"] = "application/json"
|
30
|
+
|
31
|
+
_kwargs["headers"] = headers
|
32
|
+
return _kwargs
|
33
|
+
|
34
|
+
|
35
|
+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Sandbox]:
|
36
|
+
if response.status_code == 200:
|
37
|
+
response_200 = Sandbox.from_dict(response.json())
|
38
|
+
|
39
|
+
return response_200
|
40
|
+
if client.raise_on_unexpected_status:
|
41
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
42
|
+
else:
|
43
|
+
return None
|
44
|
+
|
45
|
+
|
46
|
+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Sandbox]:
|
47
|
+
return Response(
|
48
|
+
status_code=HTTPStatus(response.status_code),
|
49
|
+
content=response.content,
|
50
|
+
headers=response.headers,
|
51
|
+
parsed=_parse_response(client=client, response=response),
|
52
|
+
)
|
53
|
+
|
54
|
+
|
55
|
+
def sync_detailed(
|
56
|
+
*,
|
57
|
+
client: Union[Client],
|
58
|
+
body: Sandbox,
|
59
|
+
) -> Response[Sandbox]:
|
60
|
+
"""Create Sandbox
|
61
|
+
|
62
|
+
Creates a Sandbox.
|
63
|
+
|
64
|
+
Args:
|
65
|
+
body (Sandbox): Micro VM for running agentic tasks
|
66
|
+
|
67
|
+
Raises:
|
68
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
69
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
70
|
+
|
71
|
+
Returns:
|
72
|
+
Response[Sandbox]
|
73
|
+
"""
|
74
|
+
|
75
|
+
kwargs = _get_kwargs(
|
76
|
+
body=body,
|
77
|
+
)
|
78
|
+
|
79
|
+
response = client.get_httpx_client().request(
|
80
|
+
**kwargs,
|
81
|
+
)
|
82
|
+
|
83
|
+
return _build_response(client=client, response=response)
|
84
|
+
|
85
|
+
|
86
|
+
def sync(
|
87
|
+
*,
|
88
|
+
client: Union[Client],
|
89
|
+
body: Sandbox,
|
90
|
+
) -> Optional[Sandbox]:
|
91
|
+
"""Create Sandbox
|
92
|
+
|
93
|
+
Creates a Sandbox.
|
94
|
+
|
95
|
+
Args:
|
96
|
+
body (Sandbox): Micro VM for running agentic tasks
|
97
|
+
|
98
|
+
Raises:
|
99
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
100
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
101
|
+
|
102
|
+
Returns:
|
103
|
+
Sandbox
|
104
|
+
"""
|
105
|
+
|
106
|
+
return sync_detailed(
|
107
|
+
client=client,
|
108
|
+
body=body,
|
109
|
+
).parsed
|
110
|
+
|
111
|
+
|
112
|
+
async def asyncio_detailed(
|
113
|
+
*,
|
114
|
+
client: Union[Client],
|
115
|
+
body: Sandbox,
|
116
|
+
) -> Response[Sandbox]:
|
117
|
+
"""Create Sandbox
|
118
|
+
|
119
|
+
Creates a Sandbox.
|
120
|
+
|
121
|
+
Args:
|
122
|
+
body (Sandbox): Micro VM for running agentic tasks
|
123
|
+
|
124
|
+
Raises:
|
125
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
126
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
Response[Sandbox]
|
130
|
+
"""
|
131
|
+
|
132
|
+
kwargs = _get_kwargs(
|
133
|
+
body=body,
|
134
|
+
)
|
135
|
+
|
136
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
137
|
+
|
138
|
+
return _build_response(client=client, response=response)
|
139
|
+
|
140
|
+
|
141
|
+
async def asyncio(
|
142
|
+
*,
|
143
|
+
client: Union[Client],
|
144
|
+
body: Sandbox,
|
145
|
+
) -> Optional[Sandbox]:
|
146
|
+
"""Create Sandbox
|
147
|
+
|
148
|
+
Creates a Sandbox.
|
149
|
+
|
150
|
+
Args:
|
151
|
+
body (Sandbox): Micro VM for running agentic tasks
|
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
|
+
Sandbox
|
159
|
+
"""
|
160
|
+
|
161
|
+
return (
|
162
|
+
await asyncio_detailed(
|
163
|
+
client=client,
|
164
|
+
body=body,
|
165
|
+
)
|
166
|
+
).parsed
|
@@ -0,0 +1,154 @@
|
|
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.sandbox import Sandbox
|
9
|
+
from ...types import Response
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
sandbox_name: str,
|
14
|
+
) -> dict[str, Any]:
|
15
|
+
_kwargs: dict[str, Any] = {
|
16
|
+
"method": "delete",
|
17
|
+
"url": f"/sandboxes/{sandbox_name}",
|
18
|
+
}
|
19
|
+
|
20
|
+
return _kwargs
|
21
|
+
|
22
|
+
|
23
|
+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Sandbox]:
|
24
|
+
if response.status_code == 200:
|
25
|
+
response_200 = Sandbox.from_dict(response.json())
|
26
|
+
|
27
|
+
return response_200
|
28
|
+
if client.raise_on_unexpected_status:
|
29
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
30
|
+
else:
|
31
|
+
return None
|
32
|
+
|
33
|
+
|
34
|
+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Sandbox]:
|
35
|
+
return Response(
|
36
|
+
status_code=HTTPStatus(response.status_code),
|
37
|
+
content=response.content,
|
38
|
+
headers=response.headers,
|
39
|
+
parsed=_parse_response(client=client, response=response),
|
40
|
+
)
|
41
|
+
|
42
|
+
|
43
|
+
def sync_detailed(
|
44
|
+
sandbox_name: str,
|
45
|
+
*,
|
46
|
+
client: Union[Client],
|
47
|
+
) -> Response[Sandbox]:
|
48
|
+
"""Delete Sandbox
|
49
|
+
|
50
|
+
Deletes a Sandbox by name.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
sandbox_name (str):
|
54
|
+
|
55
|
+
Raises:
|
56
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
57
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
Response[Sandbox]
|
61
|
+
"""
|
62
|
+
|
63
|
+
kwargs = _get_kwargs(
|
64
|
+
sandbox_name=sandbox_name,
|
65
|
+
)
|
66
|
+
|
67
|
+
response = client.get_httpx_client().request(
|
68
|
+
**kwargs,
|
69
|
+
)
|
70
|
+
|
71
|
+
return _build_response(client=client, response=response)
|
72
|
+
|
73
|
+
|
74
|
+
def sync(
|
75
|
+
sandbox_name: str,
|
76
|
+
*,
|
77
|
+
client: Union[Client],
|
78
|
+
) -> Optional[Sandbox]:
|
79
|
+
"""Delete Sandbox
|
80
|
+
|
81
|
+
Deletes a Sandbox by name.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
sandbox_name (str):
|
85
|
+
|
86
|
+
Raises:
|
87
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
88
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
Sandbox
|
92
|
+
"""
|
93
|
+
|
94
|
+
return sync_detailed(
|
95
|
+
sandbox_name=sandbox_name,
|
96
|
+
client=client,
|
97
|
+
).parsed
|
98
|
+
|
99
|
+
|
100
|
+
async def asyncio_detailed(
|
101
|
+
sandbox_name: str,
|
102
|
+
*,
|
103
|
+
client: Union[Client],
|
104
|
+
) -> Response[Sandbox]:
|
105
|
+
"""Delete Sandbox
|
106
|
+
|
107
|
+
Deletes a Sandbox by name.
|
108
|
+
|
109
|
+
Args:
|
110
|
+
sandbox_name (str):
|
111
|
+
|
112
|
+
Raises:
|
113
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
114
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
Response[Sandbox]
|
118
|
+
"""
|
119
|
+
|
120
|
+
kwargs = _get_kwargs(
|
121
|
+
sandbox_name=sandbox_name,
|
122
|
+
)
|
123
|
+
|
124
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
125
|
+
|
126
|
+
return _build_response(client=client, response=response)
|
127
|
+
|
128
|
+
|
129
|
+
async def asyncio(
|
130
|
+
sandbox_name: str,
|
131
|
+
*,
|
132
|
+
client: Union[Client],
|
133
|
+
) -> Optional[Sandbox]:
|
134
|
+
"""Delete Sandbox
|
135
|
+
|
136
|
+
Deletes a Sandbox by name.
|
137
|
+
|
138
|
+
Args:
|
139
|
+
sandbox_name (str):
|
140
|
+
|
141
|
+
Raises:
|
142
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
143
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
Sandbox
|
147
|
+
"""
|
148
|
+
|
149
|
+
return (
|
150
|
+
await asyncio_detailed(
|
151
|
+
sandbox_name=sandbox_name,
|
152
|
+
client=client,
|
153
|
+
)
|
154
|
+
).parsed
|
@@ -0,0 +1,154 @@
|
|
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.sandbox import Sandbox
|
9
|
+
from ...types import Response
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
sandbox_name: str,
|
14
|
+
) -> dict[str, Any]:
|
15
|
+
_kwargs: dict[str, Any] = {
|
16
|
+
"method": "get",
|
17
|
+
"url": f"/sandboxes/{sandbox_name}",
|
18
|
+
}
|
19
|
+
|
20
|
+
return _kwargs
|
21
|
+
|
22
|
+
|
23
|
+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Sandbox]:
|
24
|
+
if response.status_code == 200:
|
25
|
+
response_200 = Sandbox.from_dict(response.json())
|
26
|
+
|
27
|
+
return response_200
|
28
|
+
if client.raise_on_unexpected_status:
|
29
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
30
|
+
else:
|
31
|
+
return None
|
32
|
+
|
33
|
+
|
34
|
+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Sandbox]:
|
35
|
+
return Response(
|
36
|
+
status_code=HTTPStatus(response.status_code),
|
37
|
+
content=response.content,
|
38
|
+
headers=response.headers,
|
39
|
+
parsed=_parse_response(client=client, response=response),
|
40
|
+
)
|
41
|
+
|
42
|
+
|
43
|
+
def sync_detailed(
|
44
|
+
sandbox_name: str,
|
45
|
+
*,
|
46
|
+
client: Union[Client],
|
47
|
+
) -> Response[Sandbox]:
|
48
|
+
"""Get Sandbox
|
49
|
+
|
50
|
+
Returns a Sandbox by name.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
sandbox_name (str):
|
54
|
+
|
55
|
+
Raises:
|
56
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
57
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
Response[Sandbox]
|
61
|
+
"""
|
62
|
+
|
63
|
+
kwargs = _get_kwargs(
|
64
|
+
sandbox_name=sandbox_name,
|
65
|
+
)
|
66
|
+
|
67
|
+
response = client.get_httpx_client().request(
|
68
|
+
**kwargs,
|
69
|
+
)
|
70
|
+
|
71
|
+
return _build_response(client=client, response=response)
|
72
|
+
|
73
|
+
|
74
|
+
def sync(
|
75
|
+
sandbox_name: str,
|
76
|
+
*,
|
77
|
+
client: Union[Client],
|
78
|
+
) -> Optional[Sandbox]:
|
79
|
+
"""Get Sandbox
|
80
|
+
|
81
|
+
Returns a Sandbox by name.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
sandbox_name (str):
|
85
|
+
|
86
|
+
Raises:
|
87
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
88
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
Sandbox
|
92
|
+
"""
|
93
|
+
|
94
|
+
return sync_detailed(
|
95
|
+
sandbox_name=sandbox_name,
|
96
|
+
client=client,
|
97
|
+
).parsed
|
98
|
+
|
99
|
+
|
100
|
+
async def asyncio_detailed(
|
101
|
+
sandbox_name: str,
|
102
|
+
*,
|
103
|
+
client: Union[Client],
|
104
|
+
) -> Response[Sandbox]:
|
105
|
+
"""Get Sandbox
|
106
|
+
|
107
|
+
Returns a Sandbox by name.
|
108
|
+
|
109
|
+
Args:
|
110
|
+
sandbox_name (str):
|
111
|
+
|
112
|
+
Raises:
|
113
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
114
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
Response[Sandbox]
|
118
|
+
"""
|
119
|
+
|
120
|
+
kwargs = _get_kwargs(
|
121
|
+
sandbox_name=sandbox_name,
|
122
|
+
)
|
123
|
+
|
124
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
125
|
+
|
126
|
+
return _build_response(client=client, response=response)
|
127
|
+
|
128
|
+
|
129
|
+
async def asyncio(
|
130
|
+
sandbox_name: str,
|
131
|
+
*,
|
132
|
+
client: Union[Client],
|
133
|
+
) -> Optional[Sandbox]:
|
134
|
+
"""Get Sandbox
|
135
|
+
|
136
|
+
Returns a Sandbox by name.
|
137
|
+
|
138
|
+
Args:
|
139
|
+
sandbox_name (str):
|
140
|
+
|
141
|
+
Raises:
|
142
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
143
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
Sandbox
|
147
|
+
"""
|
148
|
+
|
149
|
+
return (
|
150
|
+
await asyncio_detailed(
|
151
|
+
sandbox_name=sandbox_name,
|
152
|
+
client=client,
|
153
|
+
)
|
154
|
+
).parsed
|