agentrun-inner-test 0.0.62__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.

Potentially problematic release.


This version of agentrun-inner-test might be problematic. Click here for more details.

Files changed (154) hide show
  1. agentrun/__init__.py +358 -0
  2. agentrun/agent_runtime/__client_async_template.py +466 -0
  3. agentrun/agent_runtime/__endpoint_async_template.py +345 -0
  4. agentrun/agent_runtime/__init__.py +53 -0
  5. agentrun/agent_runtime/__runtime_async_template.py +477 -0
  6. agentrun/agent_runtime/api/__data_async_template.py +58 -0
  7. agentrun/agent_runtime/api/__init__.py +6 -0
  8. agentrun/agent_runtime/api/control.py +1362 -0
  9. agentrun/agent_runtime/api/data.py +98 -0
  10. agentrun/agent_runtime/client.py +868 -0
  11. agentrun/agent_runtime/endpoint.py +649 -0
  12. agentrun/agent_runtime/model.py +362 -0
  13. agentrun/agent_runtime/runtime.py +904 -0
  14. agentrun/credential/__client_async_template.py +177 -0
  15. agentrun/credential/__credential_async_template.py +216 -0
  16. agentrun/credential/__init__.py +28 -0
  17. agentrun/credential/api/__init__.py +5 -0
  18. agentrun/credential/api/control.py +606 -0
  19. agentrun/credential/client.py +319 -0
  20. agentrun/credential/credential.py +381 -0
  21. agentrun/credential/model.py +248 -0
  22. agentrun/integration/__init__.py +21 -0
  23. agentrun/integration/agentscope/__init__.py +13 -0
  24. agentrun/integration/agentscope/adapter.py +17 -0
  25. agentrun/integration/agentscope/builtin.py +88 -0
  26. agentrun/integration/agentscope/message_adapter.py +185 -0
  27. agentrun/integration/agentscope/model_adapter.py +60 -0
  28. agentrun/integration/agentscope/tool_adapter.py +59 -0
  29. agentrun/integration/builtin/__init__.py +18 -0
  30. agentrun/integration/builtin/knowledgebase.py +137 -0
  31. agentrun/integration/builtin/model.py +93 -0
  32. agentrun/integration/builtin/sandbox.py +1234 -0
  33. agentrun/integration/builtin/toolset.py +47 -0
  34. agentrun/integration/crewai/__init__.py +13 -0
  35. agentrun/integration/crewai/adapter.py +9 -0
  36. agentrun/integration/crewai/builtin.py +88 -0
  37. agentrun/integration/crewai/model_adapter.py +31 -0
  38. agentrun/integration/crewai/tool_adapter.py +26 -0
  39. agentrun/integration/google_adk/__init__.py +13 -0
  40. agentrun/integration/google_adk/adapter.py +15 -0
  41. agentrun/integration/google_adk/builtin.py +88 -0
  42. agentrun/integration/google_adk/message_adapter.py +144 -0
  43. agentrun/integration/google_adk/model_adapter.py +46 -0
  44. agentrun/integration/google_adk/tool_adapter.py +235 -0
  45. agentrun/integration/langchain/__init__.py +31 -0
  46. agentrun/integration/langchain/adapter.py +15 -0
  47. agentrun/integration/langchain/builtin.py +94 -0
  48. agentrun/integration/langchain/message_adapter.py +141 -0
  49. agentrun/integration/langchain/model_adapter.py +37 -0
  50. agentrun/integration/langchain/tool_adapter.py +50 -0
  51. agentrun/integration/langgraph/__init__.py +36 -0
  52. agentrun/integration/langgraph/adapter.py +20 -0
  53. agentrun/integration/langgraph/agent_converter.py +1073 -0
  54. agentrun/integration/langgraph/builtin.py +88 -0
  55. agentrun/integration/pydantic_ai/__init__.py +13 -0
  56. agentrun/integration/pydantic_ai/adapter.py +13 -0
  57. agentrun/integration/pydantic_ai/builtin.py +88 -0
  58. agentrun/integration/pydantic_ai/model_adapter.py +44 -0
  59. agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
  60. agentrun/integration/utils/__init__.py +112 -0
  61. agentrun/integration/utils/adapter.py +560 -0
  62. agentrun/integration/utils/canonical.py +164 -0
  63. agentrun/integration/utils/converter.py +134 -0
  64. agentrun/integration/utils/model.py +110 -0
  65. agentrun/integration/utils/tool.py +1759 -0
  66. agentrun/knowledgebase/__client_async_template.py +173 -0
  67. agentrun/knowledgebase/__init__.py +53 -0
  68. agentrun/knowledgebase/__knowledgebase_async_template.py +438 -0
  69. agentrun/knowledgebase/api/__data_async_template.py +414 -0
  70. agentrun/knowledgebase/api/__init__.py +19 -0
  71. agentrun/knowledgebase/api/control.py +606 -0
  72. agentrun/knowledgebase/api/data.py +624 -0
  73. agentrun/knowledgebase/client.py +311 -0
  74. agentrun/knowledgebase/knowledgebase.py +748 -0
  75. agentrun/knowledgebase/model.py +270 -0
  76. agentrun/memory_collection/__client_async_template.py +178 -0
  77. agentrun/memory_collection/__init__.py +37 -0
  78. agentrun/memory_collection/__memory_collection_async_template.py +457 -0
  79. agentrun/memory_collection/api/__init__.py +5 -0
  80. agentrun/memory_collection/api/control.py +610 -0
  81. agentrun/memory_collection/client.py +323 -0
  82. agentrun/memory_collection/memory_collection.py +844 -0
  83. agentrun/memory_collection/model.py +162 -0
  84. agentrun/model/__client_async_template.py +357 -0
  85. agentrun/model/__init__.py +57 -0
  86. agentrun/model/__model_proxy_async_template.py +270 -0
  87. agentrun/model/__model_service_async_template.py +267 -0
  88. agentrun/model/api/__init__.py +6 -0
  89. agentrun/model/api/control.py +1173 -0
  90. agentrun/model/api/data.py +196 -0
  91. agentrun/model/client.py +674 -0
  92. agentrun/model/model.py +235 -0
  93. agentrun/model/model_proxy.py +439 -0
  94. agentrun/model/model_service.py +438 -0
  95. agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
  96. agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
  97. agentrun/sandbox/__client_async_template.py +491 -0
  98. agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
  99. agentrun/sandbox/__init__.py +69 -0
  100. agentrun/sandbox/__sandbox_async_template.py +463 -0
  101. agentrun/sandbox/__template_async_template.py +152 -0
  102. agentrun/sandbox/aio_sandbox.py +912 -0
  103. agentrun/sandbox/api/__aio_data_async_template.py +335 -0
  104. agentrun/sandbox/api/__browser_data_async_template.py +140 -0
  105. agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
  106. agentrun/sandbox/api/__init__.py +19 -0
  107. agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
  108. agentrun/sandbox/api/aio_data.py +551 -0
  109. agentrun/sandbox/api/browser_data.py +172 -0
  110. agentrun/sandbox/api/code_interpreter_data.py +396 -0
  111. agentrun/sandbox/api/control.py +1051 -0
  112. agentrun/sandbox/api/playwright_async.py +492 -0
  113. agentrun/sandbox/api/playwright_sync.py +492 -0
  114. agentrun/sandbox/api/sandbox_data.py +154 -0
  115. agentrun/sandbox/browser_sandbox.py +185 -0
  116. agentrun/sandbox/client.py +925 -0
  117. agentrun/sandbox/code_interpreter_sandbox.py +823 -0
  118. agentrun/sandbox/model.py +384 -0
  119. agentrun/sandbox/sandbox.py +848 -0
  120. agentrun/sandbox/template.py +217 -0
  121. agentrun/server/__init__.py +191 -0
  122. agentrun/server/agui_normalizer.py +180 -0
  123. agentrun/server/agui_protocol.py +797 -0
  124. agentrun/server/invoker.py +309 -0
  125. agentrun/server/model.py +427 -0
  126. agentrun/server/openai_protocol.py +535 -0
  127. agentrun/server/protocol.py +140 -0
  128. agentrun/server/server.py +208 -0
  129. agentrun/toolset/__client_async_template.py +62 -0
  130. agentrun/toolset/__init__.py +51 -0
  131. agentrun/toolset/__toolset_async_template.py +204 -0
  132. agentrun/toolset/api/__init__.py +17 -0
  133. agentrun/toolset/api/control.py +262 -0
  134. agentrun/toolset/api/mcp.py +100 -0
  135. agentrun/toolset/api/openapi.py +1251 -0
  136. agentrun/toolset/client.py +102 -0
  137. agentrun/toolset/model.py +321 -0
  138. agentrun/toolset/toolset.py +271 -0
  139. agentrun/utils/__data_api_async_template.py +721 -0
  140. agentrun/utils/__init__.py +5 -0
  141. agentrun/utils/__resource_async_template.py +158 -0
  142. agentrun/utils/config.py +270 -0
  143. agentrun/utils/control_api.py +105 -0
  144. agentrun/utils/data_api.py +1121 -0
  145. agentrun/utils/exception.py +151 -0
  146. agentrun/utils/helper.py +108 -0
  147. agentrun/utils/log.py +77 -0
  148. agentrun/utils/model.py +168 -0
  149. agentrun/utils/resource.py +291 -0
  150. agentrun_inner_test-0.0.62.dist-info/METADATA +265 -0
  151. agentrun_inner_test-0.0.62.dist-info/RECORD +154 -0
  152. agentrun_inner_test-0.0.62.dist-info/WHEEL +5 -0
  153. agentrun_inner_test-0.0.62.dist-info/licenses/LICENSE +201 -0
  154. agentrun_inner_test-0.0.62.dist-info/top_level.txt +1 -0
@@ -0,0 +1,335 @@
1
+ """All-in-One 沙箱数据API模板 / All-in-One Sandbox Data API Template
2
+
3
+ 此模板用于生成 All-in-One 沙箱数据API代码,结合了浏览器和代码解释器的功能。
4
+ This template is used to generate All-in-One sandbox data API code,
5
+ combining browser and code interpreter capabilities.
6
+ """
7
+
8
+ from typing import Any, Dict, Optional
9
+ from urllib.parse import parse_qs, urlencode, urlparse
10
+
11
+ from agentrun.sandbox.model import CodeLanguage
12
+ from agentrun.utils.config import Config
13
+
14
+ from .sandbox_data import SandboxDataAPI
15
+
16
+
17
+ class AioDataAPI(SandboxDataAPI):
18
+ """All-in-One Sandbox Data API
19
+
20
+ This class combines the functionality of BrowserDataAPI and CodeInterpreterDataAPI,
21
+ providing a unified interface for all-in-one sandbox operations.
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ sandbox_id: str,
27
+ config: Optional[Config] = None,
28
+ ):
29
+ self.sandbox_id = sandbox_id
30
+ super().__init__(
31
+ sandbox_id=sandbox_id,
32
+ config=config,
33
+ )
34
+
35
+ # ========================================
36
+ # Browser API Methods
37
+ # ========================================
38
+
39
+ def get_cdp_url(self, record: Optional[bool] = False):
40
+ """
41
+ Generate the WebSocket URL for Chrome DevTools Protocol (CDP) connection.
42
+
43
+ This method constructs a WebSocket URL by:
44
+ 1. Converting the HTTP endpoint to WebSocket protocol (ws://)
45
+ 2. Parsing the existing URL and query parameters
46
+ 3. Adding the session ID to the query parameters
47
+ 4. Reconstructing the complete WebSocket URL
48
+
49
+ Returns:
50
+ str: The complete WebSocket URL for CDP automation connection,
51
+ including the session ID in the query parameters.
52
+
53
+ Example:
54
+ >>> api = AioDataAPI("sandbox123")
55
+ >>> api.get_cdp_url()
56
+ 'ws://example.com/ws/automation?sessionId=session456'
57
+ """
58
+ cdp_url = self.with_path("/ws/automation").replace("http", "ws")
59
+ u = urlparse(cdp_url)
60
+ query_dict = parse_qs(u.query)
61
+ query_dict["tenantId"] = [self.config.get_account_id()]
62
+ if record:
63
+ query_dict["recording"] = ["true"]
64
+ new_query = urlencode(query_dict, doseq=True)
65
+ new_u = u._replace(query=new_query)
66
+ return new_u.geturl()
67
+
68
+ def get_vnc_url(self, record: Optional[bool] = False):
69
+ """
70
+ Generate the WebSocket URL for VNC (Virtual Network Computing) live view connection.
71
+
72
+ This method constructs a WebSocket URL for real-time browser viewing by:
73
+ 1. Converting the HTTP endpoint to WebSocket protocol (ws://)
74
+ 2. Parsing the existing URL and query parameters
75
+ 3. Adding the session ID to the query parameters
76
+ 4. Reconstructing the complete WebSocket URL
77
+
78
+ Returns:
79
+ str: The complete WebSocket URL for VNC live view connection,
80
+ including the session ID in the query parameters.
81
+
82
+ Example:
83
+ >>> api = AioDataAPI("sandbox123")
84
+ >>> api.get_vnc_url()
85
+ 'ws://example.com/ws/liveview?sessionId=session456'
86
+ """
87
+ vnc_url = self.with_path("/ws/liveview").replace("http", "ws")
88
+ u = urlparse(vnc_url)
89
+ query_dict = parse_qs(u.query)
90
+ query_dict["tenantId"] = [self.config.get_account_id()]
91
+ if record:
92
+ query_dict["recording"] = ["true"]
93
+ new_query = urlencode(query_dict, doseq=True)
94
+ new_u = u._replace(query=new_query)
95
+ return new_u.geturl()
96
+
97
+ def sync_playwright(
98
+ self,
99
+ browser_type: str = "chrome",
100
+ record: Optional[bool] = False,
101
+ config: Optional[Config] = None,
102
+ ):
103
+ from .playwright_sync import BrowserPlaywrightSync
104
+
105
+ cfg = Config.with_configs(self.config, config)
106
+ _, headers, _ = self.auth(headers=cfg.get_headers(), config=cfg)
107
+ return BrowserPlaywrightSync(
108
+ self.get_cdp_url(record=record),
109
+ browser_type=browser_type,
110
+ headers=headers,
111
+ )
112
+
113
+ def async_playwright(
114
+ self,
115
+ browser_type: str = "chrome",
116
+ record: Optional[bool] = False,
117
+ config: Optional[Config] = None,
118
+ ):
119
+ from .playwright_async import BrowserPlaywrightAsync
120
+
121
+ cfg = Config.with_configs(self.config, config)
122
+ _, headers, _ = self.auth(headers=cfg.get_headers(), config=cfg)
123
+ return BrowserPlaywrightAsync(
124
+ self.get_cdp_url(record=record),
125
+ browser_type=browser_type,
126
+ headers=headers,
127
+ )
128
+
129
+ async def list_recordings_async(self):
130
+ return await self.get_async("/recordings")
131
+
132
+ async def delete_recording_async(self, filename: str):
133
+ return await self.delete_async(f"/recordings/{filename}")
134
+
135
+ async def download_recording_async(self, filename: str, save_path: str):
136
+ """
137
+ Asynchronously download a recording video file and save it to local path.
138
+
139
+ Args:
140
+ filename: The name of the recording file to download
141
+ save_path: Local file path to save the downloaded video file (.mkv)
142
+
143
+ Returns:
144
+ Dictionary with 'saved_path' and 'size' keys
145
+
146
+ Examples:
147
+ >>> await api.download_recording_async("recording.mp4", "/local/video.mkv")
148
+ """
149
+ return await self.get_video_async(
150
+ f"/recordings/{filename}", save_path=save_path
151
+ )
152
+
153
+ # ========================================
154
+ # Code Interpreter API Methods
155
+ # ========================================
156
+
157
+ async def list_directory_async(
158
+ self,
159
+ path: Optional[str] = None,
160
+ depth: Optional[int] = None,
161
+ ):
162
+ query = {}
163
+ if path is not None:
164
+ query["path"] = path
165
+ if depth is not None:
166
+ query["depth"] = depth
167
+
168
+ return await self.get_async("/filesystem", query=query)
169
+
170
+ async def stat_async(
171
+ self,
172
+ path: str,
173
+ ):
174
+ query = {
175
+ "path": path,
176
+ }
177
+ return await self.get_async("/filesystem/stat", query=query)
178
+
179
+ async def mkdir_async(
180
+ self,
181
+ path: str,
182
+ parents: Optional[bool] = True,
183
+ mode: Optional[str] = "0755",
184
+ ):
185
+ data = {
186
+ "path": path,
187
+ "parents": parents,
188
+ "mode": mode,
189
+ }
190
+ return await self.post_async("/filesystem/mkdir", data=data)
191
+
192
+ async def move_file_async(
193
+ self,
194
+ source: str,
195
+ destination: str,
196
+ ):
197
+ data = {
198
+ "source": source,
199
+ "destination": destination,
200
+ }
201
+ return await self.post_async("/filesystem/move", data=data)
202
+
203
+ async def remove_file_async(
204
+ self,
205
+ path: str,
206
+ ):
207
+ data = {
208
+ "path": path,
209
+ }
210
+ return await self.post_async("/filesystem/remove", data=data)
211
+
212
+ async def list_contexts_async(self):
213
+ return await self.get_async("/contexts")
214
+
215
+ async def create_context_async(
216
+ self,
217
+ language: Optional[CodeLanguage] = CodeLanguage.PYTHON,
218
+ cwd: str = "/home/user",
219
+ ):
220
+ # Validate language parameter
221
+ if language not in ("python", "javascript"):
222
+ raise ValueError(
223
+ f"language must be 'python' or 'javascript', got: {language}"
224
+ )
225
+
226
+ data: Dict[str, Any] = {
227
+ "cwd": cwd,
228
+ "language": language,
229
+ }
230
+ return await self.post_async("/contexts", data=data)
231
+
232
+ async def get_context_async(
233
+ self,
234
+ context_id: str,
235
+ ):
236
+ return await self.get_async(f"/contexts/{context_id}")
237
+
238
+ async def execute_code_async(
239
+ self,
240
+ code: str,
241
+ context_id: Optional[str],
242
+ language: Optional[CodeLanguage] = None,
243
+ timeout: Optional[int] = 30,
244
+ ):
245
+ if language and language not in ("python", "javascript"):
246
+ raise ValueError(
247
+ f"language must be 'python' or 'javascript', got: {language}"
248
+ )
249
+
250
+ data: Dict[str, Any] = {
251
+ "code": code,
252
+ }
253
+ if timeout is not None:
254
+ data["timeout"] = timeout
255
+ if language is not None:
256
+ data["language"] = language
257
+ if context_id is not None:
258
+ data["contextId"] = context_id
259
+ return await self.post_async(f"/contexts/execute", data=data)
260
+
261
+ async def delete_context_async(
262
+ self,
263
+ context_id: str,
264
+ ):
265
+ return await self.delete_async(f"/contexts/{context_id}")
266
+
267
+ async def read_file_async(
268
+ self,
269
+ path: str,
270
+ ):
271
+ query = {
272
+ "path": path,
273
+ }
274
+ return await self.get_async("/files", query=query)
275
+
276
+ async def write_file_async(
277
+ self,
278
+ path: str,
279
+ content: str,
280
+ mode: Optional[str] = "644",
281
+ encoding: Optional[str] = "utf-8",
282
+ create_dir: Optional[bool] = True,
283
+ ):
284
+ data = {
285
+ "path": path,
286
+ "content": content,
287
+ "mode": mode,
288
+ "encoding": encoding,
289
+ "createDir": create_dir,
290
+ }
291
+ return await self.post_async("/files", data=data)
292
+
293
+ async def upload_file_async(
294
+ self,
295
+ local_file_path: str,
296
+ target_file_path: str,
297
+ ):
298
+ return await self.post_file_async(
299
+ path="/filesystem/upload",
300
+ local_file_path=local_file_path,
301
+ target_file_path=target_file_path,
302
+ )
303
+
304
+ async def download_file_async(
305
+ self,
306
+ path: str,
307
+ save_path: str,
308
+ ):
309
+ query = {"path": path}
310
+ return await self.get_file_async(
311
+ path="/filesystem/download", save_path=save_path, query=query
312
+ )
313
+
314
+ async def cmd_async(
315
+ self,
316
+ command: str,
317
+ cwd: str,
318
+ timeout: Optional[int] = 30,
319
+ ):
320
+ data: Dict[str, Any] = {
321
+ "command": command,
322
+ "cwd": cwd,
323
+ }
324
+ if timeout is not None:
325
+ data["timeout"] = timeout
326
+ return await self.post_async("/processes/cmd", data=data)
327
+
328
+ async def list_processes_async(self):
329
+ return await self.get_async("/processes")
330
+
331
+ async def get_process_async(self, pid: str):
332
+ return await self.get_async(f"/processes/{pid}")
333
+
334
+ async def kill_process_async(self, pid: str):
335
+ return await self.delete_async(f"/processes/{pid}")
@@ -0,0 +1,140 @@
1
+ """浏览器沙箱数据API模板 / Browser Sandbox Data API Template
2
+
3
+ 此模板用于生成浏览器沙箱数据API代码。
4
+ This template is used to generate browser sandbox data API code.
5
+ """
6
+
7
+ from typing import Optional
8
+ from urllib.parse import parse_qs, urlencode, urlparse
9
+
10
+ from agentrun.utils.config import Config
11
+
12
+ from .sandbox_data import SandboxDataAPI
13
+
14
+
15
+ class BrowserDataAPI(SandboxDataAPI):
16
+
17
+ def __init__(
18
+ self,
19
+ sandbox_id: str,
20
+ config: Optional[Config] = None,
21
+ ):
22
+ self.sandbox_id = sandbox_id
23
+ super().__init__(
24
+ sandbox_id=sandbox_id,
25
+ config=config,
26
+ )
27
+
28
+ def get_cdp_url(self, record: Optional[bool] = False):
29
+ """
30
+ Generate the WebSocket URL for Chrome DevTools Protocol (CDP) connection.
31
+
32
+ This method constructs a WebSocket URL by:
33
+ 1. Converting the HTTP endpoint to WebSocket protocol (ws://)
34
+ 2. Parsing the existing URL and query parameters
35
+ 3. Adding the session ID to the query parameters
36
+ 4. Reconstructing the complete WebSocket URL
37
+
38
+ Returns:
39
+ str: The complete WebSocket URL for CDP automation connection,
40
+ including the session ID in the query parameters.
41
+
42
+ Example:
43
+ >>> api = BrowserDataAPI("browser123", "session456")
44
+ >>> api.get_cdp_url()
45
+ 'ws://example.com/ws/automation?sessionId=session456'
46
+ """
47
+ cdp_url = self.with_path("/ws/automation").replace("http", "ws")
48
+ u = urlparse(cdp_url)
49
+ query_dict = parse_qs(u.query)
50
+ query_dict["tenantId"] = [self.config.get_account_id()]
51
+ if record:
52
+ query_dict["recording"] = ["true"]
53
+ new_query = urlencode(query_dict, doseq=True)
54
+ new_u = u._replace(query=new_query)
55
+ return new_u.geturl()
56
+
57
+ def get_vnc_url(self, record: Optional[bool] = False):
58
+ """
59
+ Generate the WebSocket URL for VNC (Virtual Network Computing) live view connection.
60
+
61
+ This method constructs a WebSocket URL for real-time browser viewing by:
62
+ 1. Converting the HTTP endpoint to WebSocket protocol (ws://)
63
+ 2. Parsing the existing URL and query parameters
64
+ 3. Adding the session ID to the query parameters
65
+ 4. Reconstructing the complete WebSocket URL
66
+
67
+ Returns:
68
+ str: The complete WebSocket URL for VNC live view connection,
69
+ including the session ID in the query parameters.
70
+
71
+ Example:
72
+ >>> api = BrowserDataAPI("browser123", "session456")
73
+ >>> api.get_vnc_url()
74
+ 'ws://example.com/ws/liveview?sessionId=session456'
75
+ """
76
+ vnc_url = self.with_path("/ws/liveview").replace("http", "ws")
77
+ u = urlparse(vnc_url)
78
+ query_dict = parse_qs(u.query)
79
+ query_dict["tenantId"] = [self.config.get_account_id()]
80
+ if record:
81
+ query_dict["recording"] = ["true"]
82
+ new_query = urlencode(query_dict, doseq=True)
83
+ new_u = u._replace(query=new_query)
84
+ return new_u.geturl()
85
+
86
+ def sync_playwright(
87
+ self,
88
+ browser_type: str = "chrome",
89
+ record: Optional[bool] = False,
90
+ config: Optional[Config] = None,
91
+ ):
92
+ from .playwright_sync import BrowserPlaywrightSync
93
+
94
+ cfg = Config.with_configs(self.config, config)
95
+ _, headers, _ = self.auth(headers=cfg.get_headers(), config=cfg)
96
+ return BrowserPlaywrightSync(
97
+ self.get_cdp_url(record=record),
98
+ browser_type=browser_type,
99
+ headers=headers,
100
+ )
101
+
102
+ def async_playwright(
103
+ self,
104
+ browser_type: str = "chrome",
105
+ record: Optional[bool] = False,
106
+ config: Optional[Config] = None,
107
+ ):
108
+ from .playwright_async import BrowserPlaywrightAsync
109
+
110
+ cfg = Config.with_configs(self.config, config)
111
+ _, headers, _ = self.auth(headers=cfg.get_headers(), config=cfg)
112
+ return BrowserPlaywrightAsync(
113
+ self.get_cdp_url(record=record),
114
+ browser_type=browser_type,
115
+ headers=headers,
116
+ )
117
+
118
+ async def list_recordings_async(self):
119
+ return await self.get_async("/recordings")
120
+
121
+ async def delete_recording_async(self, filename: str):
122
+ return await self.delete_async(f"/recordings/{filename}")
123
+
124
+ async def download_recording_async(self, filename: str, save_path: str):
125
+ """
126
+ Asynchronously download a recording video file and save it to local path.
127
+
128
+ Args:
129
+ filename: The name of the recording file to download
130
+ save_path: Local file path to save the downloaded video file (.mkv)
131
+
132
+ Returns:
133
+ Dictionary with 'saved_path' and 'size' keys
134
+
135
+ Examples:
136
+ >>> await api.download_recording_async("recording.mp4", "/local/video.mkv")
137
+ """
138
+ return await self.get_video_async(
139
+ f"/recordings/{filename}", save_path=save_path
140
+ )
@@ -0,0 +1,206 @@
1
+ """代码解释器沙箱数据API模板 / Code Interpreter Sandbox Data API Template
2
+
3
+ 此模板用于生成代码解释器沙箱数据API代码。
4
+ This template is used to generate code interpreter sandbox data API code.
5
+ """
6
+
7
+ from typing import Any, Dict, Optional
8
+
9
+ from agentrun.sandbox.model import CodeLanguage
10
+ from agentrun.utils.config import Config
11
+
12
+ from .sandbox_data import SandboxDataAPI
13
+
14
+
15
+ class CodeInterpreterDataAPI(SandboxDataAPI):
16
+
17
+ def __init__(
18
+ self,
19
+ sandbox_id: str,
20
+ config: Optional[Config] = None,
21
+ ):
22
+
23
+ super().__init__(
24
+ sandbox_id=sandbox_id,
25
+ config=config,
26
+ )
27
+
28
+ async def list_directory_async(
29
+ self,
30
+ path: Optional[str] = None,
31
+ depth: Optional[int] = None,
32
+ ):
33
+ query = {}
34
+ if path is not None:
35
+ query["path"] = path
36
+ if depth is not None:
37
+ query["depth"] = depth
38
+
39
+ return await self.get_async("/filesystem", query=query)
40
+
41
+ async def stat_async(
42
+ self,
43
+ path: str,
44
+ ):
45
+ query = {
46
+ "path": path,
47
+ }
48
+ return await self.get_async("/filesystem/stat", query=query)
49
+
50
+ async def mkdir_async(
51
+ self,
52
+ path: str,
53
+ parents: Optional[bool] = True,
54
+ mode: Optional[str] = "0755",
55
+ ):
56
+ data = {
57
+ "path": path,
58
+ "parents": parents,
59
+ "mode": mode,
60
+ }
61
+ return await self.post_async("/filesystem/mkdir", data=data)
62
+
63
+ async def move_file_async(
64
+ self,
65
+ source: str,
66
+ destination: str,
67
+ ):
68
+ data = {
69
+ "source": source,
70
+ "destination": destination,
71
+ }
72
+ return await self.post_async("/filesystem/move", data=data)
73
+
74
+ async def remove_file_async(
75
+ self,
76
+ path: str,
77
+ ):
78
+ data = {
79
+ "path": path,
80
+ }
81
+ return await self.post_async("/filesystem/remove", data=data)
82
+
83
+ async def list_contexts_async(self):
84
+ return await self.get_async("/contexts")
85
+
86
+ async def create_context_async(
87
+ self,
88
+ language: Optional[CodeLanguage] = CodeLanguage.PYTHON,
89
+ cwd: str = "/home/user",
90
+ ):
91
+ # Validate language parameter
92
+ if language not in ("python", "javascript"):
93
+ raise ValueError(
94
+ f"language must be 'python' or 'javascript', got: {language}"
95
+ )
96
+
97
+ data: Dict[str, Any] = {
98
+ "cwd": cwd,
99
+ "language": language,
100
+ }
101
+ return await self.post_async("/contexts", data=data)
102
+
103
+ async def get_context_async(
104
+ self,
105
+ context_id: str,
106
+ ):
107
+ return await self.get_async(f"/contexts/{context_id}")
108
+
109
+ async def execute_code_async(
110
+ self,
111
+ code: str,
112
+ context_id: Optional[str],
113
+ language: Optional[CodeLanguage] = None,
114
+ timeout: Optional[int] = 30,
115
+ ):
116
+ if language and language not in ("python", "javascript"):
117
+ raise ValueError(
118
+ f"language must be 'python' or 'javascript', got: {language}"
119
+ )
120
+
121
+ data: Dict[str, Any] = {
122
+ "code": code,
123
+ }
124
+ if timeout is not None:
125
+ data["timeout"] = timeout
126
+ if language is not None:
127
+ data["language"] = language
128
+ if context_id is not None:
129
+ data["contextId"] = context_id
130
+ return await self.post_async(f"/contexts/execute", data=data)
131
+
132
+ async def delete_context_async(
133
+ self,
134
+ context_id: str,
135
+ ):
136
+ return await self.delete_async(f"/contexts/{context_id}")
137
+
138
+ async def read_file_async(
139
+ self,
140
+ path: str,
141
+ ):
142
+ query = {
143
+ "path": path,
144
+ }
145
+ return await self.get_async("/files", query=query)
146
+
147
+ async def write_file_async(
148
+ self,
149
+ path: str,
150
+ content: str,
151
+ mode: Optional[str] = "644",
152
+ encoding: Optional[str] = "utf-8",
153
+ create_dir: Optional[bool] = True,
154
+ ):
155
+ data = {
156
+ "path": path,
157
+ "content": content,
158
+ "mode": mode,
159
+ "encoding": encoding,
160
+ "createDir": create_dir,
161
+ }
162
+ return await self.post_async("/files", data=data)
163
+
164
+ async def upload_file_async(
165
+ self,
166
+ local_file_path: str,
167
+ target_file_path: str,
168
+ ):
169
+ return await self.post_file_async(
170
+ path="/filesystem/upload",
171
+ local_file_path=local_file_path,
172
+ target_file_path=target_file_path,
173
+ )
174
+
175
+ async def download_file_async(
176
+ self,
177
+ path: str,
178
+ save_path: str,
179
+ ):
180
+ query = {"path": path}
181
+ return await self.get_file_async(
182
+ path="/filesystem/download", save_path=save_path, query=query
183
+ )
184
+
185
+ async def cmd_async(
186
+ self,
187
+ command: str,
188
+ cwd: str,
189
+ timeout: Optional[int] = 30,
190
+ ):
191
+ data: Dict[str, Any] = {
192
+ "command": command,
193
+ "cwd": cwd,
194
+ }
195
+ if timeout is not None:
196
+ data["timeout"] = timeout
197
+ return await self.post_async("/processes/cmd", data=data)
198
+
199
+ async def list_processes_async(self):
200
+ return await self.get_async("/processes")
201
+
202
+ async def get_process_async(self, pid: str):
203
+ return await self.get_async(f"/processes/{pid}")
204
+
205
+ async def kill_process_async(self, pid: str):
206
+ return await self.delete_async(f"/processes/{pid}")
@@ -0,0 +1,19 @@
1
+ """Sandbox API 模块 / Sandbox API Module
2
+
3
+ 此模块包含沙箱环境的 API 接口。
4
+ This module contains API interfaces for sandbox environments.
5
+ """
6
+
7
+ from .aio_data import AioDataAPI
8
+ from .browser_data import BrowserDataAPI
9
+ from .code_interpreter_data import CodeInterpreterDataAPI
10
+ from .control import SandboxControlAPI
11
+ from .sandbox_data import SandboxDataAPI
12
+
13
+ __all__ = [
14
+ "SandboxControlAPI",
15
+ "SandboxDataAPI",
16
+ "CodeInterpreterDataAPI",
17
+ "BrowserDataAPI",
18
+ "AioDataAPI",
19
+ ]