agentrun-inner-test 0.0.46__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.
- agentrun/__init__.py +325 -0
- agentrun/agent_runtime/__client_async_template.py +466 -0
- agentrun/agent_runtime/__endpoint_async_template.py +345 -0
- agentrun/agent_runtime/__init__.py +53 -0
- agentrun/agent_runtime/__runtime_async_template.py +477 -0
- agentrun/agent_runtime/api/__data_async_template.py +58 -0
- agentrun/agent_runtime/api/__init__.py +6 -0
- agentrun/agent_runtime/api/control.py +1362 -0
- agentrun/agent_runtime/api/data.py +98 -0
- agentrun/agent_runtime/client.py +868 -0
- agentrun/agent_runtime/endpoint.py +649 -0
- agentrun/agent_runtime/model.py +362 -0
- agentrun/agent_runtime/runtime.py +904 -0
- agentrun/credential/__client_async_template.py +177 -0
- agentrun/credential/__credential_async_template.py +216 -0
- agentrun/credential/__init__.py +28 -0
- agentrun/credential/api/__init__.py +5 -0
- agentrun/credential/api/control.py +606 -0
- agentrun/credential/client.py +319 -0
- agentrun/credential/credential.py +381 -0
- agentrun/credential/model.py +248 -0
- agentrun/integration/__init__.py +21 -0
- agentrun/integration/agentscope/__init__.py +12 -0
- agentrun/integration/agentscope/adapter.py +17 -0
- agentrun/integration/agentscope/builtin.py +65 -0
- agentrun/integration/agentscope/message_adapter.py +185 -0
- agentrun/integration/agentscope/model_adapter.py +60 -0
- agentrun/integration/agentscope/tool_adapter.py +59 -0
- agentrun/integration/builtin/__init__.py +16 -0
- agentrun/integration/builtin/model.py +93 -0
- agentrun/integration/builtin/sandbox.py +1234 -0
- agentrun/integration/builtin/toolset.py +47 -0
- agentrun/integration/crewai/__init__.py +12 -0
- agentrun/integration/crewai/adapter.py +9 -0
- agentrun/integration/crewai/builtin.py +65 -0
- agentrun/integration/crewai/model_adapter.py +31 -0
- agentrun/integration/crewai/tool_adapter.py +26 -0
- agentrun/integration/google_adk/__init__.py +12 -0
- agentrun/integration/google_adk/adapter.py +15 -0
- agentrun/integration/google_adk/builtin.py +65 -0
- agentrun/integration/google_adk/message_adapter.py +144 -0
- agentrun/integration/google_adk/model_adapter.py +46 -0
- agentrun/integration/google_adk/tool_adapter.py +235 -0
- agentrun/integration/langchain/__init__.py +30 -0
- agentrun/integration/langchain/adapter.py +15 -0
- agentrun/integration/langchain/builtin.py +71 -0
- agentrun/integration/langchain/message_adapter.py +141 -0
- agentrun/integration/langchain/model_adapter.py +37 -0
- agentrun/integration/langchain/tool_adapter.py +50 -0
- agentrun/integration/langgraph/__init__.py +35 -0
- agentrun/integration/langgraph/adapter.py +20 -0
- agentrun/integration/langgraph/agent_converter.py +1073 -0
- agentrun/integration/langgraph/builtin.py +65 -0
- agentrun/integration/pydantic_ai/__init__.py +12 -0
- agentrun/integration/pydantic_ai/adapter.py +13 -0
- agentrun/integration/pydantic_ai/builtin.py +65 -0
- agentrun/integration/pydantic_ai/model_adapter.py +44 -0
- agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
- agentrun/integration/utils/__init__.py +112 -0
- agentrun/integration/utils/adapter.py +560 -0
- agentrun/integration/utils/canonical.py +164 -0
- agentrun/integration/utils/converter.py +134 -0
- agentrun/integration/utils/model.py +110 -0
- agentrun/integration/utils/tool.py +1759 -0
- agentrun/model/__client_async_template.py +357 -0
- agentrun/model/__init__.py +57 -0
- agentrun/model/__model_proxy_async_template.py +270 -0
- agentrun/model/__model_service_async_template.py +267 -0
- agentrun/model/api/__init__.py +6 -0
- agentrun/model/api/control.py +1173 -0
- agentrun/model/api/data.py +196 -0
- agentrun/model/client.py +674 -0
- agentrun/model/model.py +235 -0
- agentrun/model/model_proxy.py +439 -0
- agentrun/model/model_service.py +438 -0
- agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
- agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
- agentrun/sandbox/__client_async_template.py +491 -0
- agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
- agentrun/sandbox/__init__.py +69 -0
- agentrun/sandbox/__sandbox_async_template.py +463 -0
- agentrun/sandbox/__template_async_template.py +152 -0
- agentrun/sandbox/aio_sandbox.py +905 -0
- agentrun/sandbox/api/__aio_data_async_template.py +335 -0
- agentrun/sandbox/api/__browser_data_async_template.py +140 -0
- agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
- agentrun/sandbox/api/__init__.py +19 -0
- agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
- agentrun/sandbox/api/aio_data.py +551 -0
- agentrun/sandbox/api/browser_data.py +172 -0
- agentrun/sandbox/api/code_interpreter_data.py +396 -0
- agentrun/sandbox/api/control.py +1051 -0
- agentrun/sandbox/api/playwright_async.py +492 -0
- agentrun/sandbox/api/playwright_sync.py +492 -0
- agentrun/sandbox/api/sandbox_data.py +154 -0
- agentrun/sandbox/browser_sandbox.py +185 -0
- agentrun/sandbox/client.py +925 -0
- agentrun/sandbox/code_interpreter_sandbox.py +823 -0
- agentrun/sandbox/model.py +397 -0
- agentrun/sandbox/sandbox.py +848 -0
- agentrun/sandbox/template.py +217 -0
- agentrun/server/__init__.py +191 -0
- agentrun/server/agui_normalizer.py +180 -0
- agentrun/server/agui_protocol.py +797 -0
- agentrun/server/invoker.py +309 -0
- agentrun/server/model.py +427 -0
- agentrun/server/openai_protocol.py +535 -0
- agentrun/server/protocol.py +140 -0
- agentrun/server/server.py +208 -0
- agentrun/toolset/__client_async_template.py +62 -0
- agentrun/toolset/__init__.py +51 -0
- agentrun/toolset/__toolset_async_template.py +204 -0
- agentrun/toolset/api/__init__.py +17 -0
- agentrun/toolset/api/control.py +262 -0
- agentrun/toolset/api/mcp.py +100 -0
- agentrun/toolset/api/openapi.py +1251 -0
- agentrun/toolset/client.py +102 -0
- agentrun/toolset/model.py +321 -0
- agentrun/toolset/toolset.py +270 -0
- agentrun/utils/__data_api_async_template.py +720 -0
- agentrun/utils/__init__.py +5 -0
- agentrun/utils/__resource_async_template.py +158 -0
- agentrun/utils/config.py +258 -0
- agentrun/utils/control_api.py +78 -0
- agentrun/utils/data_api.py +1120 -0
- agentrun/utils/exception.py +151 -0
- agentrun/utils/helper.py +108 -0
- agentrun/utils/log.py +77 -0
- agentrun/utils/model.py +168 -0
- agentrun/utils/resource.py +291 -0
- agentrun_inner_test-0.0.46.dist-info/METADATA +263 -0
- agentrun_inner_test-0.0.46.dist-info/RECORD +135 -0
- agentrun_inner_test-0.0.46.dist-info/WHEEL +5 -0
- agentrun_inner_test-0.0.46.dist-info/licenses/LICENSE +201 -0
- agentrun_inner_test-0.0.46.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
"""Sandbox客户端模板 / Sandbox Client Template
|
|
2
|
+
|
|
3
|
+
此模板用于生成沙箱客户端代码。
|
|
4
|
+
This template is used to generate sandbox client code.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import time
|
|
8
|
+
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from alibabacloud_agentrun20250910.models import (
|
|
11
|
+
CreateTemplateInput,
|
|
12
|
+
ListSandboxesRequest,
|
|
13
|
+
ListTemplatesRequest,
|
|
14
|
+
UpdateTemplateInput,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from agentrun.sandbox.api import SandboxControlAPI, SandboxDataAPI
|
|
18
|
+
from agentrun.sandbox.model import (
|
|
19
|
+
ListSandboxesInput,
|
|
20
|
+
ListSandboxesOutput,
|
|
21
|
+
NASConfig,
|
|
22
|
+
OSSMountConfig,
|
|
23
|
+
PageableInput,
|
|
24
|
+
PolarFsConfig,
|
|
25
|
+
TemplateInput,
|
|
26
|
+
)
|
|
27
|
+
from agentrun.utils.config import Config
|
|
28
|
+
from agentrun.utils.exception import (
|
|
29
|
+
AgentRunError,
|
|
30
|
+
ClientError,
|
|
31
|
+
ResourceNotExistError,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from .sandbox import Sandbox
|
|
35
|
+
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
from agentrun.sandbox.template import Template
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class SandboxClient:
|
|
41
|
+
"""Sandbox 客户端 / Sandbox Client
|
|
42
|
+
|
|
43
|
+
用于管理 Sandbox 和 Template。
|
|
44
|
+
Used for managing Sandboxes and Templates.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, config: Optional[Config] = None):
|
|
48
|
+
"""初始化 Sandbox 客户端 / Initialize Sandbox client
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
52
|
+
"""
|
|
53
|
+
self.__control_api = SandboxControlAPI(config=config)
|
|
54
|
+
self.__sandbox_data_api = SandboxDataAPI(config=config)
|
|
55
|
+
|
|
56
|
+
async def _wait_template_ready_async(
|
|
57
|
+
self,
|
|
58
|
+
template_name: str,
|
|
59
|
+
config: Optional[Config] = None,
|
|
60
|
+
interval_seconds: int = 5,
|
|
61
|
+
timeout_seconds: int = 300,
|
|
62
|
+
) -> "Template":
|
|
63
|
+
"""Wait for Template to be ready (async)
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
template_name: Template name
|
|
67
|
+
config: Config object
|
|
68
|
+
interval_seconds: Polling interval in seconds
|
|
69
|
+
timeout_seconds: Timeout in seconds
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Template: Ready Template object
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
TimeoutError: Timeout error
|
|
76
|
+
ClientError: Client error
|
|
77
|
+
"""
|
|
78
|
+
import asyncio
|
|
79
|
+
|
|
80
|
+
start_time = time.time()
|
|
81
|
+
while True:
|
|
82
|
+
template = await self.get_template_async(
|
|
83
|
+
template_name, config=config
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Check if ready
|
|
87
|
+
if template.status == "READY":
|
|
88
|
+
return template
|
|
89
|
+
|
|
90
|
+
# Check if failed
|
|
91
|
+
if (
|
|
92
|
+
template.status == "CREATE_FAILED"
|
|
93
|
+
or template.status == "UPDATE_FAILED"
|
|
94
|
+
):
|
|
95
|
+
raise AgentRunError(
|
|
96
|
+
f"Template {template_name} creation failed, status:"
|
|
97
|
+
f" {template.status}"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# Check timeout
|
|
101
|
+
if time.time() - start_time > timeout_seconds:
|
|
102
|
+
raise TimeoutError(
|
|
103
|
+
f"Timeout waiting for Template {template_name} to be ready,"
|
|
104
|
+
f" current status: {template.status}"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
await asyncio.sleep(interval_seconds)
|
|
108
|
+
|
|
109
|
+
async def create_template_async(
|
|
110
|
+
self, input: TemplateInput, config: Optional[Config] = None
|
|
111
|
+
) -> "Template":
|
|
112
|
+
"""创建 Template(异步)
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
input: Template 配置
|
|
116
|
+
config: 配置对象
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
Template: 创建的 Template 对象
|
|
120
|
+
|
|
121
|
+
Raises:
|
|
122
|
+
ClientError: 客户端错误
|
|
123
|
+
ServerError: 服务器错误
|
|
124
|
+
"""
|
|
125
|
+
from agentrun.sandbox.template import Template
|
|
126
|
+
|
|
127
|
+
# 转换为 SDK 需要的格式
|
|
128
|
+
sdk_input = CreateTemplateInput().from_map(
|
|
129
|
+
input.model_dump(by_alias=True)
|
|
130
|
+
)
|
|
131
|
+
result = await self.__control_api.create_template_async(
|
|
132
|
+
sdk_input, config=config
|
|
133
|
+
)
|
|
134
|
+
template = Template.from_inner_object(result)
|
|
135
|
+
|
|
136
|
+
# Poll and wait for Template to be ready
|
|
137
|
+
template = await self._wait_template_ready_async(
|
|
138
|
+
template.template_name or "", config=config
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
return template
|
|
142
|
+
|
|
143
|
+
async def delete_template_async(
|
|
144
|
+
self, template_name: str, config: Optional[Config] = None
|
|
145
|
+
) -> "Template":
|
|
146
|
+
"""删除 Template(异步)
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
template_name: Template 名称
|
|
150
|
+
config: 配置对象
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Template: 删除的 Template 对象
|
|
154
|
+
|
|
155
|
+
Raises:
|
|
156
|
+
ResourceNotExistError: Template 不存在
|
|
157
|
+
ClientError: 客户端错误
|
|
158
|
+
ServerError: 服务器错误
|
|
159
|
+
"""
|
|
160
|
+
from agentrun.sandbox.template import Template
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
result = await self.__control_api.delete_template_async(
|
|
164
|
+
template_name, config=config
|
|
165
|
+
)
|
|
166
|
+
return Template.from_inner_object(result)
|
|
167
|
+
except ClientError as e:
|
|
168
|
+
if e.status_code == 404:
|
|
169
|
+
raise ResourceNotExistError("Template", template_name) from e
|
|
170
|
+
raise e
|
|
171
|
+
|
|
172
|
+
async def update_template_async(
|
|
173
|
+
self,
|
|
174
|
+
template_name: str,
|
|
175
|
+
input: TemplateInput,
|
|
176
|
+
config: Optional[Config] = None,
|
|
177
|
+
) -> "Template":
|
|
178
|
+
"""更新 Template(异步)
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
template_name: Template 名称
|
|
182
|
+
input: Template 更新配置
|
|
183
|
+
config: 配置对象
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
Template: 更新后的 Template 对象
|
|
187
|
+
|
|
188
|
+
Raises:
|
|
189
|
+
ResourceNotExistError: Template 不存在
|
|
190
|
+
ClientError: 客户端错误
|
|
191
|
+
ServerError: 服务器错误
|
|
192
|
+
"""
|
|
193
|
+
from agentrun.sandbox.template import Template
|
|
194
|
+
|
|
195
|
+
try:
|
|
196
|
+
# 转换为 SDK 需要的格式
|
|
197
|
+
sdk_input = UpdateTemplateInput().from_map(
|
|
198
|
+
input.model_dump(by_alias=True, exclude_none=True)
|
|
199
|
+
)
|
|
200
|
+
result = await self.__control_api.update_template_async(
|
|
201
|
+
template_name, sdk_input, config=config
|
|
202
|
+
)
|
|
203
|
+
return Template.from_inner_object(result)
|
|
204
|
+
except ClientError as e:
|
|
205
|
+
if e.status_code == 404:
|
|
206
|
+
raise ResourceNotExistError("Template", template_name) from e
|
|
207
|
+
raise e
|
|
208
|
+
|
|
209
|
+
async def get_template_async(
|
|
210
|
+
self, template_name: str, config: Optional[Config] = None
|
|
211
|
+
) -> "Template":
|
|
212
|
+
"""获取 Template(异步)
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
template_name: Template 名称
|
|
216
|
+
config: 配置对象
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
Template: Template 对象
|
|
220
|
+
|
|
221
|
+
Raises:
|
|
222
|
+
ResourceNotExistError: Template 不存在
|
|
223
|
+
ClientError: 客户端错误
|
|
224
|
+
ServerError: 服务器错误
|
|
225
|
+
"""
|
|
226
|
+
from agentrun.sandbox.template import Template
|
|
227
|
+
|
|
228
|
+
try:
|
|
229
|
+
result = await self.__control_api.get_template_async(
|
|
230
|
+
template_name, config=config
|
|
231
|
+
)
|
|
232
|
+
return Template.from_inner_object(result)
|
|
233
|
+
except ClientError as e:
|
|
234
|
+
if e.status_code == 404:
|
|
235
|
+
raise ResourceNotExistError("Template", template_name) from e
|
|
236
|
+
raise e
|
|
237
|
+
|
|
238
|
+
async def list_templates_async(
|
|
239
|
+
self,
|
|
240
|
+
input: Optional[PageableInput] = None,
|
|
241
|
+
config: Optional[Config] = None,
|
|
242
|
+
) -> List["Template"]:
|
|
243
|
+
"""枚举 Templates(异步)
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
input: 分页配置
|
|
247
|
+
config: 配置对象
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
List[Template]: Template 列表
|
|
251
|
+
|
|
252
|
+
Raises:
|
|
253
|
+
ClientError: 客户端错误
|
|
254
|
+
ServerError: 服务器错误
|
|
255
|
+
TimeoutError: Timeout waiting for Template to be ready
|
|
256
|
+
"""
|
|
257
|
+
from agentrun.sandbox.template import Template
|
|
258
|
+
|
|
259
|
+
if input is None:
|
|
260
|
+
input = PageableInput()
|
|
261
|
+
|
|
262
|
+
# 转换为 SDK 需要的格式
|
|
263
|
+
sdk_input = ListTemplatesRequest().from_map(
|
|
264
|
+
input.model_dump(by_alias=True)
|
|
265
|
+
)
|
|
266
|
+
results = await self.__control_api.list_templates_async(
|
|
267
|
+
sdk_input, config=config
|
|
268
|
+
)
|
|
269
|
+
return (
|
|
270
|
+
[Template.from_inner_object(item) for item in results.items]
|
|
271
|
+
if results.items
|
|
272
|
+
else []
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
async def create_sandbox_async(
|
|
276
|
+
self,
|
|
277
|
+
template_name: str,
|
|
278
|
+
sandbox_idle_timeout_seconds: Optional[int] = 600,
|
|
279
|
+
nas_config: Optional[NASConfig] = None,
|
|
280
|
+
oss_mount_config: Optional[OSSMountConfig] = None,
|
|
281
|
+
polar_fs_config: Optional[PolarFsConfig] = None,
|
|
282
|
+
config: Optional[Config] = None,
|
|
283
|
+
) -> Sandbox:
|
|
284
|
+
"""创建 Sandbox(异步) / Create Sandbox (async)
|
|
285
|
+
|
|
286
|
+
Args:
|
|
287
|
+
template_name: 模板名称 / Template name
|
|
288
|
+
sandbox_idle_timeout_seconds: 沙箱空闲超时时间(秒) / Sandbox idle timeout (seconds)
|
|
289
|
+
nas_config: NAS 配置 / NAS configuration
|
|
290
|
+
oss_mount_config: OSS 挂载配置 / OSS mount configuration
|
|
291
|
+
polar_fs_config: PolarFS 配置 / PolarFS configuration
|
|
292
|
+
config: 配置对象 / Config object
|
|
293
|
+
|
|
294
|
+
Returns:
|
|
295
|
+
Sandbox: 创建的 Sandbox 对象 / Created Sandbox object
|
|
296
|
+
|
|
297
|
+
Raises:
|
|
298
|
+
ClientError: 客户端错误 / Client error
|
|
299
|
+
ServerError: 服务器错误 / Server error
|
|
300
|
+
"""
|
|
301
|
+
# 将配置对象转换为字典格式
|
|
302
|
+
nas_config_dict: Optional[Dict[str, Any]] = None
|
|
303
|
+
if nas_config is not None:
|
|
304
|
+
nas_config_dict = nas_config.model_dump(by_alias=True)
|
|
305
|
+
|
|
306
|
+
oss_mount_config_dict: Optional[Dict[str, Any]] = None
|
|
307
|
+
if oss_mount_config is not None:
|
|
308
|
+
oss_mount_config_dict = oss_mount_config.model_dump(by_alias=True)
|
|
309
|
+
|
|
310
|
+
polar_fs_config_dict: Optional[Dict[str, Any]] = None
|
|
311
|
+
if polar_fs_config is not None:
|
|
312
|
+
polar_fs_config_dict = polar_fs_config.model_dump(by_alias=True)
|
|
313
|
+
|
|
314
|
+
result = await self.__sandbox_data_api.create_sandbox_async(
|
|
315
|
+
template_name=template_name,
|
|
316
|
+
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
|
|
317
|
+
nas_config=nas_config_dict,
|
|
318
|
+
oss_mount_config=oss_mount_config_dict,
|
|
319
|
+
polar_fs_config=polar_fs_config_dict,
|
|
320
|
+
config=config,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
# 判断返回结果是否成功
|
|
324
|
+
if result.get("code") != "SUCCESS":
|
|
325
|
+
raise ClientError(
|
|
326
|
+
status_code=0,
|
|
327
|
+
message=(
|
|
328
|
+
"Failed to create sandbox:"
|
|
329
|
+
f" {result.get('message', 'Unknown error')}"
|
|
330
|
+
),
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
# 从 data 字段中提取数据并实例化(使用 model_validate 从字典创建)
|
|
334
|
+
data = result.get("data", {})
|
|
335
|
+
return Sandbox.model_validate(data, by_alias=True)
|
|
336
|
+
|
|
337
|
+
async def stop_sandbox_async(
|
|
338
|
+
self, sandbox_id: str, config: Optional[Config] = None
|
|
339
|
+
) -> Sandbox:
|
|
340
|
+
"""停止 Sandbox(异步)
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
sandbox_id: Sandbox ID
|
|
344
|
+
config: 配置对象
|
|
345
|
+
|
|
346
|
+
Returns:
|
|
347
|
+
Sandbox: 停止后的 Sandbox 对象
|
|
348
|
+
|
|
349
|
+
Raises:
|
|
350
|
+
ResourceNotExistError: Sandbox 不存在
|
|
351
|
+
ClientError: 客户端错误
|
|
352
|
+
ServerError: 服务器错误
|
|
353
|
+
"""
|
|
354
|
+
try:
|
|
355
|
+
result = await self.__sandbox_data_api.stop_sandbox_async(
|
|
356
|
+
sandbox_id
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
# 判断返回结果是否成功
|
|
360
|
+
if result.get("code") != "SUCCESS":
|
|
361
|
+
raise ClientError(
|
|
362
|
+
status_code=0,
|
|
363
|
+
message=(
|
|
364
|
+
"Failed to stop sandbox:"
|
|
365
|
+
f" {result.get('message', 'Unknown error')}"
|
|
366
|
+
),
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
# 从 data 字段中提取数据并实例化(使用 model_validate 从字典创建)
|
|
370
|
+
data = result.get("data", {})
|
|
371
|
+
return Sandbox.model_validate(data, by_alias=True)
|
|
372
|
+
except ClientError as e:
|
|
373
|
+
if e.status_code == 404:
|
|
374
|
+
raise ResourceNotExistError("Sandbox", sandbox_id) from e
|
|
375
|
+
raise e
|
|
376
|
+
|
|
377
|
+
async def delete_sandbox_async(
|
|
378
|
+
self, sandbox_id: str, config: Optional[Config] = None
|
|
379
|
+
) -> Sandbox:
|
|
380
|
+
"""删除 Sandbox(异步)
|
|
381
|
+
|
|
382
|
+
Args:
|
|
383
|
+
sandbox_id: Sandbox ID
|
|
384
|
+
config: 配置对象
|
|
385
|
+
|
|
386
|
+
Returns:
|
|
387
|
+
Sandbox: 停止后的 Sandbox 对象
|
|
388
|
+
|
|
389
|
+
Raises:
|
|
390
|
+
ResourceNotExistError: Sandbox 不存在
|
|
391
|
+
ClientError: 客户端错误
|
|
392
|
+
ServerError: 服务器错误
|
|
393
|
+
"""
|
|
394
|
+
try:
|
|
395
|
+
result = await self.__sandbox_data_api.delete_sandbox_async(
|
|
396
|
+
sandbox_id
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
# 判断返回结果是否成功
|
|
400
|
+
if result.get("code") != "SUCCESS":
|
|
401
|
+
raise ClientError(
|
|
402
|
+
status_code=0,
|
|
403
|
+
message=(
|
|
404
|
+
"Failed to stop sandbox:"
|
|
405
|
+
f" {result.get('message', 'Unknown error')}"
|
|
406
|
+
),
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
# 从 data 字段中提取数据并实例化(使用 model_validate 从字典创建)
|
|
410
|
+
data = result.get("data", {})
|
|
411
|
+
return Sandbox.model_validate(data, by_alias=True)
|
|
412
|
+
except ClientError as e:
|
|
413
|
+
if e.status_code == 404:
|
|
414
|
+
raise ResourceNotExistError("Sandbox", sandbox_id) from e
|
|
415
|
+
raise e
|
|
416
|
+
|
|
417
|
+
async def get_sandbox_async(
|
|
418
|
+
self,
|
|
419
|
+
sandbox_id: str,
|
|
420
|
+
config: Optional[Config] = None,
|
|
421
|
+
) -> Sandbox:
|
|
422
|
+
"""获取 Sandbox(异步)
|
|
423
|
+
|
|
424
|
+
Args:
|
|
425
|
+
sandbox_id: Sandbox ID
|
|
426
|
+
config: 配置对象
|
|
427
|
+
|
|
428
|
+
Returns:
|
|
429
|
+
Sandbox: Sandbox 对象
|
|
430
|
+
|
|
431
|
+
Raises:
|
|
432
|
+
ResourceNotExistError: Sandbox 不存在
|
|
433
|
+
ClientError: 客户端错误
|
|
434
|
+
ServerError: 服务器错误
|
|
435
|
+
"""
|
|
436
|
+
try:
|
|
437
|
+
result = await self.__sandbox_data_api.get_sandbox_async(sandbox_id)
|
|
438
|
+
|
|
439
|
+
# 判断返回结果是否成功
|
|
440
|
+
if result.get("code") != "SUCCESS":
|
|
441
|
+
raise ClientError(
|
|
442
|
+
status_code=0,
|
|
443
|
+
message=(
|
|
444
|
+
"Failed to get sandbox:"
|
|
445
|
+
f" {result.get('message', 'Unknown error')}"
|
|
446
|
+
),
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
# 从 data 字段中提取数据并实例化(使用 model_validate 从字典创建)
|
|
450
|
+
data = result.get("data", {})
|
|
451
|
+
return Sandbox.model_validate(data, by_alias=True)
|
|
452
|
+
except ClientError as e:
|
|
453
|
+
if e.status_code == 404:
|
|
454
|
+
raise ResourceNotExistError("Sandbox", sandbox_id) from e
|
|
455
|
+
raise e
|
|
456
|
+
|
|
457
|
+
async def list_sandboxes_async(
|
|
458
|
+
self,
|
|
459
|
+
input: Optional[ListSandboxesInput] = None,
|
|
460
|
+
config: Optional[Config] = None,
|
|
461
|
+
) -> ListSandboxesOutput:
|
|
462
|
+
"""枚举 Sandboxes(异步)
|
|
463
|
+
|
|
464
|
+
Args:
|
|
465
|
+
input: 分页配置
|
|
466
|
+
config: 配置对象
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
List[Sandbox]: Sandbox 列表
|
|
470
|
+
|
|
471
|
+
Raises:
|
|
472
|
+
ClientError: 客户端错误
|
|
473
|
+
ServerError: 服务器错误
|
|
474
|
+
"""
|
|
475
|
+
if input is None:
|
|
476
|
+
input = ListSandboxesInput()
|
|
477
|
+
|
|
478
|
+
# 转换为 SDK 需要的格式
|
|
479
|
+
sdk_input = ListSandboxesRequest().from_map(
|
|
480
|
+
input.model_dump(by_alias=True)
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
results = await self.__control_api.list_sandboxes_async(
|
|
484
|
+
sdk_input, config=config
|
|
485
|
+
)
|
|
486
|
+
return ListSandboxesOutput(
|
|
487
|
+
sandboxes=[
|
|
488
|
+
Sandbox.from_inner_object(item) for item in results.items
|
|
489
|
+
],
|
|
490
|
+
next_token=results.next_token,
|
|
491
|
+
)
|