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,397 @@
|
|
|
1
|
+
"""Sandbox 模型定义 / Sandbox Model Definitions
|
|
2
|
+
|
|
3
|
+
定义沙箱相关的数据模型和枚举。
|
|
4
|
+
Defines data models and enumerations related to sandboxes.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
|
9
|
+
import uuid
|
|
10
|
+
|
|
11
|
+
from pydantic import model_validator
|
|
12
|
+
|
|
13
|
+
from agentrun.utils.model import BaseModel
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from agentrun.sandbox.sandbox import Sandbox
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TemplateOSSPermission(str, Enum):
|
|
20
|
+
"""Agent Runtime 网络访问模式 / Agent Runtime Network Access Mode"""
|
|
21
|
+
|
|
22
|
+
READ_WRITE = "READ_WRITE"
|
|
23
|
+
"""读写模式 / Read-Write Mode"""
|
|
24
|
+
READ_ONLY = "READ_ONLY"
|
|
25
|
+
"""只读模式 / Read-Only Mode"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TemplateType(str, Enum):
|
|
29
|
+
"""沙箱模板类型 / Sandbox Template Type"""
|
|
30
|
+
|
|
31
|
+
CODE_INTERPRETER = "CodeInterpreter"
|
|
32
|
+
"""代码解释器 / Code Interpreter"""
|
|
33
|
+
BROWSER = "Browser"
|
|
34
|
+
"""浏览器 / Browser"""
|
|
35
|
+
AIO = "AllInOne"
|
|
36
|
+
"""All-in-One 沙箱 / All-in-One Sandbox"""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TemplateNetworkMode(str, Enum):
|
|
40
|
+
"""Agent Runtime 网络访问模式 / Agent Runtime Network Access Mode"""
|
|
41
|
+
|
|
42
|
+
PUBLIC = "PUBLIC"
|
|
43
|
+
"""公网模式 / Public Mode"""
|
|
44
|
+
PRIVATE = "PRIVATE"
|
|
45
|
+
"""私网模式 / Private Mode"""
|
|
46
|
+
PUBLIC_AND_PRIVATE = "PUBLIC_AND_PRIVATE"
|
|
47
|
+
"""公私网模式 / Public and Private Mode"""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class CodeLanguage(str, Enum):
|
|
51
|
+
"""Code Interpreter 代码语言 / Code Interpreter Programming Language"""
|
|
52
|
+
|
|
53
|
+
PYTHON = "python"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# ==================== NAS 配置相关 ====================
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class NASMountConfig(BaseModel):
|
|
60
|
+
"""NAS 挂载配置 / NAS Mount Configuration
|
|
61
|
+
|
|
62
|
+
定义 NAS 文件系统的挂载配置。
|
|
63
|
+
Defines the mount configuration for NAS file system.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
enable_tls: Optional[bool] = None
|
|
67
|
+
"""是否启用 TLS 加密 / Whether to enable TLS encryption"""
|
|
68
|
+
mount_dir: Optional[str] = None
|
|
69
|
+
"""挂载目录 / Mount Directory"""
|
|
70
|
+
server_addr: Optional[str] = None
|
|
71
|
+
"""NAS 服务器地址 / NAS Server Address"""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class NASConfig(BaseModel):
|
|
75
|
+
"""NAS 配置 / NAS Configuration
|
|
76
|
+
|
|
77
|
+
定义 NAS 文件系统的配置。
|
|
78
|
+
Defines the configuration for NAS file system.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
group_id: Optional[int] = None
|
|
82
|
+
"""组 ID / Group ID"""
|
|
83
|
+
mount_points: Optional[List[NASMountConfig]] = None
|
|
84
|
+
"""挂载点列表 / Mount Points List"""
|
|
85
|
+
user_id: Optional[int] = None
|
|
86
|
+
"""用户 ID / User ID"""
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# ==================== OSS 挂载配置相关 ====================
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class OSSMountPoint(BaseModel):
|
|
93
|
+
"""OSS 挂载点 / OSS Mount Point
|
|
94
|
+
|
|
95
|
+
定义 OSS 存储的挂载点配置。
|
|
96
|
+
Defines the mount point configuration for OSS storage.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
bucket_name: Optional[str] = None
|
|
100
|
+
"""OSS 存储桶名称 / OSS Bucket Name"""
|
|
101
|
+
bucket_path: Optional[str] = None
|
|
102
|
+
"""OSS 存储桶路径 / OSS Bucket Path"""
|
|
103
|
+
endpoint: Optional[str] = None
|
|
104
|
+
"""OSS 端点 / OSS Endpoint"""
|
|
105
|
+
mount_dir: Optional[str] = None
|
|
106
|
+
"""挂载目录 / Mount Directory"""
|
|
107
|
+
read_only: Optional[bool] = None
|
|
108
|
+
"""是否只读 / Read Only"""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class OSSMountConfig(BaseModel):
|
|
112
|
+
"""OSS 挂载配置 / OSS Mount Configuration
|
|
113
|
+
|
|
114
|
+
定义 OSS 存储的挂载配置。
|
|
115
|
+
Defines the mount configuration for OSS storage.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
mount_points: Optional[List[OSSMountPoint]] = None
|
|
119
|
+
"""挂载点列表 / Mount Points List"""
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# ==================== PolarFS 配置相关 ====================
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class PolarFsMountConfig(BaseModel):
|
|
126
|
+
"""PolarFS 挂载配置 / PolarFS Mount Configuration
|
|
127
|
+
|
|
128
|
+
定义 PolarFS 文件系统的挂载配置。
|
|
129
|
+
Defines the mount configuration for PolarFS file system.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
instance_id: Optional[str] = None
|
|
133
|
+
"""实例 ID / Instance ID"""
|
|
134
|
+
mount_dir: Optional[str] = None
|
|
135
|
+
"""挂载目录 / Mount Directory"""
|
|
136
|
+
remote_dir: Optional[str] = None
|
|
137
|
+
"""远程目录 / Remote Directory"""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class PolarFsConfig(BaseModel):
|
|
141
|
+
"""PolarFS 配置 / PolarFS Configuration
|
|
142
|
+
|
|
143
|
+
定义 PolarFS 文件系统的配置。
|
|
144
|
+
Defines the configuration for PolarFS file system.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
group_id: Optional[int] = None
|
|
148
|
+
"""组 ID / Group ID"""
|
|
149
|
+
mount_points: Optional[List[PolarFsMountConfig]] = None
|
|
150
|
+
"""挂载点列表 / Mount Points List"""
|
|
151
|
+
user_id: Optional[int] = None
|
|
152
|
+
"""用户 ID / User ID"""
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# ==================== 模板配置相关 ====================
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class TemplateNetworkConfiguration(BaseModel):
|
|
159
|
+
"""沙箱模板网络配置 / Sandbox Template Network Configuration"""
|
|
160
|
+
|
|
161
|
+
network_mode: TemplateNetworkMode = TemplateNetworkMode.PUBLIC
|
|
162
|
+
"""网络访问模式 / Network Access Mode"""
|
|
163
|
+
security_group_id: Optional[str] = None
|
|
164
|
+
"""安全组 ID / Security Group ID"""
|
|
165
|
+
vpc_id: Optional[str] = None
|
|
166
|
+
"""私有网络 ID / VPC ID"""
|
|
167
|
+
vswitch_ids: Optional[List[str]] = None
|
|
168
|
+
"""私有网络交换机 ID 列表 / VSwitch ID List"""
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class TemplateOssConfiguration(BaseModel):
|
|
172
|
+
"""沙箱模板 OSS 配置 / Sandbox Template OSS Configuration"""
|
|
173
|
+
|
|
174
|
+
bucket_name: str
|
|
175
|
+
"""OSS 存储桶名称 / OSS Bucket Name"""
|
|
176
|
+
mount_point: str
|
|
177
|
+
"""OSS 挂载点 / OSS Mount Point"""
|
|
178
|
+
permission: Optional[TemplateOSSPermission] = (
|
|
179
|
+
TemplateOSSPermission.READ_WRITE
|
|
180
|
+
)
|
|
181
|
+
"""OSS 权限 / OSS Permission"""
|
|
182
|
+
prefix: str
|
|
183
|
+
"""OSS 对象前缀/路径 / OSS Object Prefix/Path"""
|
|
184
|
+
region: str
|
|
185
|
+
"""OSS 区域"""
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class TemplateLogConfiguration(BaseModel):
|
|
189
|
+
"""沙箱模板日志配置 / Sandbox Template Log Configuration"""
|
|
190
|
+
|
|
191
|
+
project: Optional[str] = None
|
|
192
|
+
"""SLS 日志项目 / SLS Log Project"""
|
|
193
|
+
logstore: Optional[str] = None
|
|
194
|
+
"""SLS 日志库 / SLS Logstore"""
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class TemplateCredentialConfiguration(BaseModel):
|
|
198
|
+
"""沙箱模板凭证配置 / Sandbox Template Credential Configuration"""
|
|
199
|
+
|
|
200
|
+
credential_name: Optional[str] = None
|
|
201
|
+
"""凭证名称 / Credential Name"""
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class TemplateArmsConfiguration(BaseModel):
|
|
205
|
+
"""沙箱模板 ARMS 监控配置 / Sandbox Template ARMS Monitoring Configuration"""
|
|
206
|
+
|
|
207
|
+
arms_license_key: Optional[str] = None
|
|
208
|
+
"""ARMS 许可证密钥 / ARMS License Key"""
|
|
209
|
+
|
|
210
|
+
enable_arms: bool
|
|
211
|
+
"""是否启用 ARMS 监控 / Whether to enable ARMS monitoring"""
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class TemplateContainerConfiguration(BaseModel):
|
|
215
|
+
"""沙箱模板容器配置 / Sandbox Template Container Configuration"""
|
|
216
|
+
|
|
217
|
+
image: Optional[str] = None
|
|
218
|
+
"""容器镜像地址 / Container Image Address"""
|
|
219
|
+
command: Optional[List[str]] = None
|
|
220
|
+
"""容器启动命令 / Container Start Command"""
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class TemplateMcpOptions(BaseModel):
|
|
224
|
+
"""沙箱模板 MCP 选项配置 / Sandbox Template MCP Options Configuration"""
|
|
225
|
+
|
|
226
|
+
enabled_tools: Optional[List[str]] = None
|
|
227
|
+
|
|
228
|
+
"""启用的工具列表 / Enabled Tools List"""
|
|
229
|
+
transport: Optional[str] = None
|
|
230
|
+
"""传输协议 / Transport Protocol"""
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class TemplateMcpState(BaseModel):
|
|
234
|
+
"""沙箱模板 MCP 状态 / Sandbox Template MCP State"""
|
|
235
|
+
|
|
236
|
+
access_endpoint: Optional[str] = None
|
|
237
|
+
"""访问端点 / Access Endpoint"""
|
|
238
|
+
status: Optional[str] = None
|
|
239
|
+
"""状态 / Status"""
|
|
240
|
+
status_reason: Optional[str] = None
|
|
241
|
+
"""状态原因 / Status Reason"""
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class TemplateInput(BaseModel):
|
|
245
|
+
"""沙箱模板配置 / Sandbox Template Configuration"""
|
|
246
|
+
|
|
247
|
+
template_name: Optional[str] = f"sandbox_template_{uuid.uuid4()}"
|
|
248
|
+
"""模板名称 / Template Name"""
|
|
249
|
+
template_type: TemplateType
|
|
250
|
+
"""模板类型 / Template Type"""
|
|
251
|
+
cpu: Optional[float] = 2.0
|
|
252
|
+
"""CPU 核数 / CPU Cores"""
|
|
253
|
+
memory: Optional[int] = 4096
|
|
254
|
+
"""内存大小(MB) / Memory Size (MB)"""
|
|
255
|
+
execution_role_arn: Optional[str] = None
|
|
256
|
+
"""执行角色 ARN / Execution Role ARN"""
|
|
257
|
+
sandbox_idle_timeout_in_seconds: Optional[int] = 1800
|
|
258
|
+
"""沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)"""
|
|
259
|
+
sandbox_ttlin_seconds: Optional[int] = 21600
|
|
260
|
+
"""沙箱存活时间(秒) / Sandbox TTL (seconds)"""
|
|
261
|
+
share_concurrency_limit_per_sandbox: Optional[int] = 200
|
|
262
|
+
"""每个沙箱的最大并发会话数 / Max Concurrency Limit Per Sandbox"""
|
|
263
|
+
template_configuration: Optional[Dict] = None
|
|
264
|
+
"""模板配置 / Template Configuration"""
|
|
265
|
+
description: Optional[str] = None
|
|
266
|
+
"""描述 / Description"""
|
|
267
|
+
environment_variables: Optional[Dict] = None
|
|
268
|
+
"""环境变量 / Environment Variables"""
|
|
269
|
+
network_configuration: Optional[TemplateNetworkConfiguration] = (
|
|
270
|
+
TemplateNetworkConfiguration(network_mode=TemplateNetworkMode.PUBLIC)
|
|
271
|
+
)
|
|
272
|
+
"""网络配置 / Network Configuration"""
|
|
273
|
+
oss_configuration: Optional[List[TemplateOssConfiguration]] = None
|
|
274
|
+
"""OSS 配置列表 / OSS Configuration List"""
|
|
275
|
+
log_configuration: Optional[TemplateLogConfiguration] = None
|
|
276
|
+
"""日志配置 / Log Configuration"""
|
|
277
|
+
credential_configuration: Optional[TemplateCredentialConfiguration] = None
|
|
278
|
+
"""凭证配置 / Credential Configuration"""
|
|
279
|
+
arms_configuration: Optional[TemplateArmsConfiguration] = None
|
|
280
|
+
"""ARMS 监控配置 / ARMS Monitoring Configuration"""
|
|
281
|
+
container_configuration: Optional[TemplateContainerConfiguration] = None
|
|
282
|
+
"""容器配置 / Container Configuration"""
|
|
283
|
+
disk_size: Optional[int] = None
|
|
284
|
+
"""磁盘大小(GB) / Disk Size (GB)"""
|
|
285
|
+
allow_anonymous_manage: Optional[bool] = None
|
|
286
|
+
"""是否允许匿名管理 / Whether to allow anonymous management"""
|
|
287
|
+
|
|
288
|
+
@model_validator(mode="before")
|
|
289
|
+
@classmethod
|
|
290
|
+
def set_disk_size_default(cls, values):
|
|
291
|
+
"""根据 template_type 设置 disk_size 的默认值 / Set default disk_size based on template_type"""
|
|
292
|
+
# 如果 disk_size 已经被显式设置,则不修改
|
|
293
|
+
if (
|
|
294
|
+
values.get("disk_size") is not None
|
|
295
|
+
or values.get("diskSize") is not None
|
|
296
|
+
):
|
|
297
|
+
return values
|
|
298
|
+
|
|
299
|
+
# 获取 template_type(支持两种命名格式)
|
|
300
|
+
template_type = values.get("template_type") or values.get(
|
|
301
|
+
"templateType"
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
# 根据 template_type 设置默认值
|
|
305
|
+
if (
|
|
306
|
+
template_type == TemplateType.CODE_INTERPRETER
|
|
307
|
+
or template_type == "CodeInterpreter"
|
|
308
|
+
):
|
|
309
|
+
values["disk_size"] = 512
|
|
310
|
+
elif (
|
|
311
|
+
template_type == TemplateType.BROWSER
|
|
312
|
+
or template_type == "Browser"
|
|
313
|
+
or template_type == TemplateType.AIO
|
|
314
|
+
or template_type == "AllInOne"
|
|
315
|
+
):
|
|
316
|
+
values["disk_size"] = 10240
|
|
317
|
+
else:
|
|
318
|
+
# 如果 template_type 未设置或为其他值,使用 512 作为默认值
|
|
319
|
+
values["disk_size"] = 512
|
|
320
|
+
|
|
321
|
+
# 如果 template_type 为 AIO,则设置 cpu 和 memory 的默认值4C8G
|
|
322
|
+
if template_type == TemplateType.AIO or template_type == "AllInOne":
|
|
323
|
+
values["cpu"] = 4.0
|
|
324
|
+
values["memory"] = 8192
|
|
325
|
+
|
|
326
|
+
return values
|
|
327
|
+
|
|
328
|
+
@model_validator(mode="after")
|
|
329
|
+
def validate_template_constraints(self):
|
|
330
|
+
if (
|
|
331
|
+
self.template_type == TemplateType.BROWSER
|
|
332
|
+
or self.template_type == TemplateType.AIO
|
|
333
|
+
):
|
|
334
|
+
if self.disk_size != 10240:
|
|
335
|
+
raise ValueError(
|
|
336
|
+
"when template_type is BROWSER,disk_size should be 10240,"
|
|
337
|
+
f"the current disk size is {self.disk_size}"
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
if (
|
|
341
|
+
self.template_type == TemplateType.CODE_INTERPRETER
|
|
342
|
+
or self.template_type == TemplateType.AIO
|
|
343
|
+
):
|
|
344
|
+
if (
|
|
345
|
+
self.network_configuration
|
|
346
|
+
and self.network_configuration.network_mode
|
|
347
|
+
== TemplateNetworkMode.PRIVATE
|
|
348
|
+
):
|
|
349
|
+
raise ValueError(
|
|
350
|
+
"when template_type is CODE_INTERPRETER,"
|
|
351
|
+
"network_mode cannot be PRIVATE"
|
|
352
|
+
)
|
|
353
|
+
return self
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
class SandboxInput(BaseModel):
|
|
357
|
+
"""Sandbox 创建配置 / Sandbox Creation Configuration"""
|
|
358
|
+
|
|
359
|
+
template_name: str
|
|
360
|
+
"""模板名称 / Template Name"""
|
|
361
|
+
sandbox_idle_timeout_seconds: Optional[int] = 600
|
|
362
|
+
"""沙箱空闲超时时间(秒) / Sandbox Idle Timeout (seconds)"""
|
|
363
|
+
sandbox_id: Optional[str] = None
|
|
364
|
+
"""沙箱 ID(可选,用户可指定) / Sandbox ID (optional, user can specify)"""
|
|
365
|
+
nas_config: Optional[NASConfig] = None
|
|
366
|
+
"""NAS 配置 / NAS Configuration"""
|
|
367
|
+
oss_mount_config: Optional[OSSMountConfig] = None
|
|
368
|
+
"""OSS 挂载配置 / OSS Mount Configuration"""
|
|
369
|
+
polar_fs_config: Optional[PolarFsConfig] = None
|
|
370
|
+
"""PolarFS 配置 / PolarFS Configuration"""
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
class ListSandboxesInput(BaseModel):
|
|
374
|
+
"""Sandbox 列表查询配置 / Sandbox List Query Configuration"""
|
|
375
|
+
|
|
376
|
+
max_results: Optional[int] = 10
|
|
377
|
+
next_token: Optional[str] = None
|
|
378
|
+
status: Optional[str] = None
|
|
379
|
+
template_name: Optional[str] = None
|
|
380
|
+
template_type: Optional[TemplateType] = None
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
class ListSandboxesOutput(BaseModel):
|
|
384
|
+
"""Sandbox 列表查询结果 / Sandbox List Query Result"""
|
|
385
|
+
|
|
386
|
+
sandboxes: List["Sandbox"]
|
|
387
|
+
next_token: Optional[str] = None
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
class PageableInput(BaseModel):
|
|
391
|
+
"""分页查询参数 / Pagination Query Parameters"""
|
|
392
|
+
|
|
393
|
+
page_number: Optional[int] = 1
|
|
394
|
+
"""页码 / Page Number"""
|
|
395
|
+
page_size: Optional[int] = 10
|
|
396
|
+
"""每页大小 / Page Size"""
|
|
397
|
+
template_type: Optional[TemplateType] = None
|