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,172 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file is auto generated by the code generation script.
|
|
3
|
+
Do not modify this file manually.
|
|
4
|
+
Use the `make codegen` command to regenerate.
|
|
5
|
+
|
|
6
|
+
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
|
|
7
|
+
使用 `make codegen` 命令重新生成。
|
|
8
|
+
|
|
9
|
+
source: agentrun/sandbox/api/__browser_data_async_template.py
|
|
10
|
+
|
|
11
|
+
浏览器沙箱数据API模板 / Browser Sandbox Data API Template
|
|
12
|
+
|
|
13
|
+
此模板用于生成浏览器沙箱数据API代码。
|
|
14
|
+
This template is used to generate browser sandbox data API code.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import Optional
|
|
18
|
+
from urllib.parse import parse_qs, urlencode, urlparse
|
|
19
|
+
|
|
20
|
+
from agentrun.utils.config import Config
|
|
21
|
+
|
|
22
|
+
from .sandbox_data import SandboxDataAPI
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class BrowserDataAPI(SandboxDataAPI):
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
sandbox_id: str,
|
|
30
|
+
config: Optional[Config] = None,
|
|
31
|
+
):
|
|
32
|
+
self.sandbox_id = sandbox_id
|
|
33
|
+
super().__init__(
|
|
34
|
+
sandbox_id=sandbox_id,
|
|
35
|
+
config=config,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def get_cdp_url(self, record: Optional[bool] = False):
|
|
39
|
+
"""
|
|
40
|
+
Generate the WebSocket URL for Chrome DevTools Protocol (CDP) connection.
|
|
41
|
+
|
|
42
|
+
This method constructs a WebSocket URL by:
|
|
43
|
+
1. Converting the HTTP endpoint to WebSocket protocol (ws://)
|
|
44
|
+
2. Parsing the existing URL and query parameters
|
|
45
|
+
3. Adding the session ID to the query parameters
|
|
46
|
+
4. Reconstructing the complete WebSocket URL
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
str: The complete WebSocket URL for CDP automation connection,
|
|
50
|
+
including the session ID in the query parameters.
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
>>> api = BrowserDataAPI("browser123", "session456")
|
|
54
|
+
>>> api.get_cdp_url()
|
|
55
|
+
'ws://example.com/ws/automation?sessionId=session456'
|
|
56
|
+
"""
|
|
57
|
+
cdp_url = self.with_path("/ws/automation").replace("http", "ws")
|
|
58
|
+
u = urlparse(cdp_url)
|
|
59
|
+
query_dict = parse_qs(u.query)
|
|
60
|
+
query_dict["tenantId"] = [self.config.get_account_id()]
|
|
61
|
+
if record:
|
|
62
|
+
query_dict["recording"] = ["true"]
|
|
63
|
+
new_query = urlencode(query_dict, doseq=True)
|
|
64
|
+
new_u = u._replace(query=new_query)
|
|
65
|
+
return new_u.geturl()
|
|
66
|
+
|
|
67
|
+
def get_vnc_url(self, record: Optional[bool] = False):
|
|
68
|
+
"""
|
|
69
|
+
Generate the WebSocket URL for VNC (Virtual Network Computing) live view connection.
|
|
70
|
+
|
|
71
|
+
This method constructs a WebSocket URL for real-time browser viewing by:
|
|
72
|
+
1. Converting the HTTP endpoint to WebSocket protocol (ws://)
|
|
73
|
+
2. Parsing the existing URL and query parameters
|
|
74
|
+
3. Adding the session ID to the query parameters
|
|
75
|
+
4. Reconstructing the complete WebSocket URL
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
str: The complete WebSocket URL for VNC live view connection,
|
|
79
|
+
including the session ID in the query parameters.
|
|
80
|
+
|
|
81
|
+
Example:
|
|
82
|
+
>>> api = BrowserDataAPI("browser123", "session456")
|
|
83
|
+
>>> api.get_vnc_url()
|
|
84
|
+
'ws://example.com/ws/liveview?sessionId=session456'
|
|
85
|
+
"""
|
|
86
|
+
vnc_url = self.with_path("/ws/liveview").replace("http", "ws")
|
|
87
|
+
u = urlparse(vnc_url)
|
|
88
|
+
query_dict = parse_qs(u.query)
|
|
89
|
+
query_dict["tenantId"] = [self.config.get_account_id()]
|
|
90
|
+
if record:
|
|
91
|
+
query_dict["recording"] = ["true"]
|
|
92
|
+
new_query = urlencode(query_dict, doseq=True)
|
|
93
|
+
new_u = u._replace(query=new_query)
|
|
94
|
+
return new_u.geturl()
|
|
95
|
+
|
|
96
|
+
def sync_playwright(
|
|
97
|
+
self,
|
|
98
|
+
browser_type: str = "chrome",
|
|
99
|
+
record: Optional[bool] = False,
|
|
100
|
+
config: Optional[Config] = None,
|
|
101
|
+
):
|
|
102
|
+
from .playwright_sync import BrowserPlaywrightSync
|
|
103
|
+
|
|
104
|
+
cfg = Config.with_configs(self.config, config)
|
|
105
|
+
_, headers, _ = self.auth(headers=cfg.get_headers(), config=cfg)
|
|
106
|
+
return BrowserPlaywrightSync(
|
|
107
|
+
self.get_cdp_url(record=record),
|
|
108
|
+
browser_type=browser_type,
|
|
109
|
+
headers=headers,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def async_playwright(
|
|
113
|
+
self,
|
|
114
|
+
browser_type: str = "chrome",
|
|
115
|
+
record: Optional[bool] = False,
|
|
116
|
+
config: Optional[Config] = None,
|
|
117
|
+
):
|
|
118
|
+
from .playwright_async import BrowserPlaywrightAsync
|
|
119
|
+
|
|
120
|
+
cfg = Config.with_configs(self.config, config)
|
|
121
|
+
_, headers, _ = self.auth(headers=cfg.get_headers(), config=cfg)
|
|
122
|
+
return BrowserPlaywrightAsync(
|
|
123
|
+
self.get_cdp_url(record=record),
|
|
124
|
+
browser_type=browser_type,
|
|
125
|
+
headers=headers,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
async def list_recordings_async(self):
|
|
129
|
+
return await self.get_async("/recordings")
|
|
130
|
+
|
|
131
|
+
def list_recordings(self):
|
|
132
|
+
return self.get("/recordings")
|
|
133
|
+
|
|
134
|
+
async def delete_recording_async(self, filename: str):
|
|
135
|
+
return await self.delete_async(f"/recordings/{filename}")
|
|
136
|
+
|
|
137
|
+
def delete_recording(self, filename: str):
|
|
138
|
+
return self.delete(f"/recordings/{filename}")
|
|
139
|
+
|
|
140
|
+
async def download_recording_async(self, filename: str, save_path: str):
|
|
141
|
+
"""
|
|
142
|
+
Asynchronously download a recording video file and save it to local path.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
filename: The name of the recording file to download
|
|
146
|
+
save_path: Local file path to save the downloaded video file (.mkv)
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
Dictionary with 'saved_path' and 'size' keys
|
|
150
|
+
|
|
151
|
+
Examples:
|
|
152
|
+
>>> await api.download_recording_async("recording.mp4", "/local/video.mkv")
|
|
153
|
+
"""
|
|
154
|
+
return await self.get_video_async(
|
|
155
|
+
f"/recordings/{filename}", save_path=save_path
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def download_recording(self, filename: str, save_path: str):
|
|
159
|
+
"""
|
|
160
|
+
Synchronously download a recording video file and save it to local path.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
filename: The name of the recording file to download
|
|
164
|
+
save_path: Local file path to save the downloaded video file (.mkv)
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Dictionary with 'saved_path' and 'size' keys
|
|
168
|
+
|
|
169
|
+
Examples:
|
|
170
|
+
>>> api.download_recording("recording.mp4", "/local/video.mkv")
|
|
171
|
+
"""
|
|
172
|
+
return self.get_video(f"/recordings/{filename}", save_path=save_path)
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file is auto generated by the code generation script.
|
|
3
|
+
Do not modify this file manually.
|
|
4
|
+
Use the `make codegen` command to regenerate.
|
|
5
|
+
|
|
6
|
+
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
|
|
7
|
+
使用 `make codegen` 命令重新生成。
|
|
8
|
+
|
|
9
|
+
source: agentrun/sandbox/api/__code_interpreter_data_async_template.py
|
|
10
|
+
|
|
11
|
+
代码解释器沙箱数据API模板 / Code Interpreter Sandbox Data API Template
|
|
12
|
+
|
|
13
|
+
此模板用于生成代码解释器沙箱数据API代码。
|
|
14
|
+
This template is used to generate code interpreter sandbox data API code.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import Any, Dict, Optional
|
|
18
|
+
|
|
19
|
+
from agentrun.sandbox.model import CodeLanguage
|
|
20
|
+
from agentrun.utils.config import Config
|
|
21
|
+
|
|
22
|
+
from .sandbox_data import SandboxDataAPI
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CodeInterpreterDataAPI(SandboxDataAPI):
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
sandbox_id: str,
|
|
30
|
+
config: Optional[Config] = None,
|
|
31
|
+
):
|
|
32
|
+
|
|
33
|
+
super().__init__(
|
|
34
|
+
sandbox_id=sandbox_id,
|
|
35
|
+
config=config,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
async def list_directory_async(
|
|
39
|
+
self,
|
|
40
|
+
path: Optional[str] = None,
|
|
41
|
+
depth: Optional[int] = None,
|
|
42
|
+
):
|
|
43
|
+
query = {}
|
|
44
|
+
if path is not None:
|
|
45
|
+
query["path"] = path
|
|
46
|
+
if depth is not None:
|
|
47
|
+
query["depth"] = depth
|
|
48
|
+
|
|
49
|
+
return await self.get_async("/filesystem", query=query)
|
|
50
|
+
|
|
51
|
+
def list_directory(
|
|
52
|
+
self,
|
|
53
|
+
path: Optional[str] = None,
|
|
54
|
+
depth: Optional[int] = None,
|
|
55
|
+
):
|
|
56
|
+
query = {}
|
|
57
|
+
if path is not None:
|
|
58
|
+
query["path"] = path
|
|
59
|
+
if depth is not None:
|
|
60
|
+
query["depth"] = depth
|
|
61
|
+
|
|
62
|
+
return self.get("/filesystem", query=query)
|
|
63
|
+
|
|
64
|
+
async def stat_async(
|
|
65
|
+
self,
|
|
66
|
+
path: str,
|
|
67
|
+
):
|
|
68
|
+
query = {
|
|
69
|
+
"path": path,
|
|
70
|
+
}
|
|
71
|
+
return await self.get_async("/filesystem/stat", query=query)
|
|
72
|
+
|
|
73
|
+
def stat(
|
|
74
|
+
self,
|
|
75
|
+
path: str,
|
|
76
|
+
):
|
|
77
|
+
query = {
|
|
78
|
+
"path": path,
|
|
79
|
+
}
|
|
80
|
+
return self.get("/filesystem/stat", query=query)
|
|
81
|
+
|
|
82
|
+
async def mkdir_async(
|
|
83
|
+
self,
|
|
84
|
+
path: str,
|
|
85
|
+
parents: Optional[bool] = True,
|
|
86
|
+
mode: Optional[str] = "0755",
|
|
87
|
+
):
|
|
88
|
+
data = {
|
|
89
|
+
"path": path,
|
|
90
|
+
"parents": parents,
|
|
91
|
+
"mode": mode,
|
|
92
|
+
}
|
|
93
|
+
return await self.post_async("/filesystem/mkdir", data=data)
|
|
94
|
+
|
|
95
|
+
def mkdir(
|
|
96
|
+
self,
|
|
97
|
+
path: str,
|
|
98
|
+
parents: Optional[bool] = True,
|
|
99
|
+
mode: Optional[str] = "0755",
|
|
100
|
+
):
|
|
101
|
+
data = {
|
|
102
|
+
"path": path,
|
|
103
|
+
"parents": parents,
|
|
104
|
+
"mode": mode,
|
|
105
|
+
}
|
|
106
|
+
return self.post("/filesystem/mkdir", data=data)
|
|
107
|
+
|
|
108
|
+
async def move_file_async(
|
|
109
|
+
self,
|
|
110
|
+
source: str,
|
|
111
|
+
destination: str,
|
|
112
|
+
):
|
|
113
|
+
data = {
|
|
114
|
+
"source": source,
|
|
115
|
+
"destination": destination,
|
|
116
|
+
}
|
|
117
|
+
return await self.post_async("/filesystem/move", data=data)
|
|
118
|
+
|
|
119
|
+
def move_file(
|
|
120
|
+
self,
|
|
121
|
+
source: str,
|
|
122
|
+
destination: str,
|
|
123
|
+
):
|
|
124
|
+
data = {
|
|
125
|
+
"source": source,
|
|
126
|
+
"destination": destination,
|
|
127
|
+
}
|
|
128
|
+
return self.post("/filesystem/move", data=data)
|
|
129
|
+
|
|
130
|
+
async def remove_file_async(
|
|
131
|
+
self,
|
|
132
|
+
path: str,
|
|
133
|
+
):
|
|
134
|
+
data = {
|
|
135
|
+
"path": path,
|
|
136
|
+
}
|
|
137
|
+
return await self.post_async("/filesystem/remove", data=data)
|
|
138
|
+
|
|
139
|
+
def remove_file(
|
|
140
|
+
self,
|
|
141
|
+
path: str,
|
|
142
|
+
):
|
|
143
|
+
data = {
|
|
144
|
+
"path": path,
|
|
145
|
+
}
|
|
146
|
+
return self.post("/filesystem/remove", data=data)
|
|
147
|
+
|
|
148
|
+
async def list_contexts_async(self):
|
|
149
|
+
return await self.get_async("/contexts")
|
|
150
|
+
|
|
151
|
+
def list_contexts(self):
|
|
152
|
+
return self.get("/contexts")
|
|
153
|
+
|
|
154
|
+
async def create_context_async(
|
|
155
|
+
self,
|
|
156
|
+
language: Optional[CodeLanguage] = CodeLanguage.PYTHON,
|
|
157
|
+
cwd: str = "/home/user",
|
|
158
|
+
):
|
|
159
|
+
# Validate language parameter
|
|
160
|
+
if language not in ("python", "javascript"):
|
|
161
|
+
raise ValueError(
|
|
162
|
+
f"language must be 'python' or 'javascript', got: {language}"
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
data: Dict[str, Any] = {
|
|
166
|
+
"cwd": cwd,
|
|
167
|
+
"language": language,
|
|
168
|
+
}
|
|
169
|
+
return await self.post_async("/contexts", data=data)
|
|
170
|
+
|
|
171
|
+
def create_context(
|
|
172
|
+
self,
|
|
173
|
+
language: Optional[CodeLanguage] = CodeLanguage.PYTHON,
|
|
174
|
+
cwd: str = "/home/user",
|
|
175
|
+
):
|
|
176
|
+
# Validate language parameter
|
|
177
|
+
if language not in ("python", "javascript"):
|
|
178
|
+
raise ValueError(
|
|
179
|
+
f"language must be 'python' or 'javascript', got: {language}"
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
data: Dict[str, Any] = {
|
|
183
|
+
"cwd": cwd,
|
|
184
|
+
"language": language,
|
|
185
|
+
}
|
|
186
|
+
return self.post("/contexts", data=data)
|
|
187
|
+
|
|
188
|
+
async def get_context_async(
|
|
189
|
+
self,
|
|
190
|
+
context_id: str,
|
|
191
|
+
):
|
|
192
|
+
return await self.get_async(f"/contexts/{context_id}")
|
|
193
|
+
|
|
194
|
+
def get_context(
|
|
195
|
+
self,
|
|
196
|
+
context_id: str,
|
|
197
|
+
):
|
|
198
|
+
return self.get(f"/contexts/{context_id}")
|
|
199
|
+
|
|
200
|
+
async def execute_code_async(
|
|
201
|
+
self,
|
|
202
|
+
code: str,
|
|
203
|
+
context_id: Optional[str],
|
|
204
|
+
language: Optional[CodeLanguage] = None,
|
|
205
|
+
timeout: Optional[int] = 30,
|
|
206
|
+
):
|
|
207
|
+
if language and language not in ("python", "javascript"):
|
|
208
|
+
raise ValueError(
|
|
209
|
+
f"language must be 'python' or 'javascript', got: {language}"
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
data: Dict[str, Any] = {
|
|
213
|
+
"code": code,
|
|
214
|
+
}
|
|
215
|
+
if timeout is not None:
|
|
216
|
+
data["timeout"] = timeout
|
|
217
|
+
if language is not None:
|
|
218
|
+
data["language"] = language
|
|
219
|
+
if context_id is not None:
|
|
220
|
+
data["contextId"] = context_id
|
|
221
|
+
return await self.post_async(f"/contexts/execute", data=data)
|
|
222
|
+
|
|
223
|
+
def execute_code(
|
|
224
|
+
self,
|
|
225
|
+
code: str,
|
|
226
|
+
context_id: Optional[str],
|
|
227
|
+
language: Optional[CodeLanguage] = None,
|
|
228
|
+
timeout: Optional[int] = 30,
|
|
229
|
+
):
|
|
230
|
+
if language and language not in ("python", "javascript"):
|
|
231
|
+
raise ValueError(
|
|
232
|
+
f"language must be 'python' or 'javascript', got: {language}"
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
data: Dict[str, Any] = {
|
|
236
|
+
"code": code,
|
|
237
|
+
}
|
|
238
|
+
if timeout is not None:
|
|
239
|
+
data["timeout"] = timeout
|
|
240
|
+
if language is not None:
|
|
241
|
+
data["language"] = language
|
|
242
|
+
if context_id is not None:
|
|
243
|
+
data["contextId"] = context_id
|
|
244
|
+
return self.post(f"/contexts/execute", data=data)
|
|
245
|
+
|
|
246
|
+
async def delete_context_async(
|
|
247
|
+
self,
|
|
248
|
+
context_id: str,
|
|
249
|
+
):
|
|
250
|
+
return await self.delete_async(f"/contexts/{context_id}")
|
|
251
|
+
|
|
252
|
+
def delete_context(
|
|
253
|
+
self,
|
|
254
|
+
context_id: str,
|
|
255
|
+
):
|
|
256
|
+
return self.delete(f"/contexts/{context_id}")
|
|
257
|
+
|
|
258
|
+
async def read_file_async(
|
|
259
|
+
self,
|
|
260
|
+
path: str,
|
|
261
|
+
):
|
|
262
|
+
query = {
|
|
263
|
+
"path": path,
|
|
264
|
+
}
|
|
265
|
+
return await self.get_async("/files", query=query)
|
|
266
|
+
|
|
267
|
+
def read_file(
|
|
268
|
+
self,
|
|
269
|
+
path: str,
|
|
270
|
+
):
|
|
271
|
+
query = {
|
|
272
|
+
"path": path,
|
|
273
|
+
}
|
|
274
|
+
return self.get("/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
|
+
def write_file(
|
|
294
|
+
self,
|
|
295
|
+
path: str,
|
|
296
|
+
content: str,
|
|
297
|
+
mode: Optional[str] = "644",
|
|
298
|
+
encoding: Optional[str] = "utf-8",
|
|
299
|
+
create_dir: Optional[bool] = True,
|
|
300
|
+
):
|
|
301
|
+
data = {
|
|
302
|
+
"path": path,
|
|
303
|
+
"content": content,
|
|
304
|
+
"mode": mode,
|
|
305
|
+
"encoding": encoding,
|
|
306
|
+
"createDir": create_dir,
|
|
307
|
+
}
|
|
308
|
+
return self.post("/files", data=data)
|
|
309
|
+
|
|
310
|
+
async def upload_file_async(
|
|
311
|
+
self,
|
|
312
|
+
local_file_path: str,
|
|
313
|
+
target_file_path: str,
|
|
314
|
+
):
|
|
315
|
+
return await self.post_file_async(
|
|
316
|
+
path="/filesystem/upload",
|
|
317
|
+
local_file_path=local_file_path,
|
|
318
|
+
target_file_path=target_file_path,
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
def upload_file(
|
|
322
|
+
self,
|
|
323
|
+
local_file_path: str,
|
|
324
|
+
target_file_path: str,
|
|
325
|
+
):
|
|
326
|
+
return self.post_file(
|
|
327
|
+
path="/filesystem/upload",
|
|
328
|
+
local_file_path=local_file_path,
|
|
329
|
+
target_file_path=target_file_path,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
async def download_file_async(
|
|
333
|
+
self,
|
|
334
|
+
path: str,
|
|
335
|
+
save_path: str,
|
|
336
|
+
):
|
|
337
|
+
query = {"path": path}
|
|
338
|
+
return await self.get_file_async(
|
|
339
|
+
path="/filesystem/download", save_path=save_path, query=query
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
def download_file(
|
|
343
|
+
self,
|
|
344
|
+
path: str,
|
|
345
|
+
save_path: str,
|
|
346
|
+
):
|
|
347
|
+
query = {"path": path}
|
|
348
|
+
return self.get_file(
|
|
349
|
+
path="/filesystem/download", save_path=save_path, query=query
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
async def cmd_async(
|
|
353
|
+
self,
|
|
354
|
+
command: str,
|
|
355
|
+
cwd: str,
|
|
356
|
+
timeout: Optional[int] = 30,
|
|
357
|
+
):
|
|
358
|
+
data: Dict[str, Any] = {
|
|
359
|
+
"command": command,
|
|
360
|
+
"cwd": cwd,
|
|
361
|
+
}
|
|
362
|
+
if timeout is not None:
|
|
363
|
+
data["timeout"] = timeout
|
|
364
|
+
return await self.post_async("/processes/cmd", data=data)
|
|
365
|
+
|
|
366
|
+
def cmd(
|
|
367
|
+
self,
|
|
368
|
+
command: str,
|
|
369
|
+
cwd: str,
|
|
370
|
+
timeout: Optional[int] = 30,
|
|
371
|
+
):
|
|
372
|
+
data: Dict[str, Any] = {
|
|
373
|
+
"command": command,
|
|
374
|
+
"cwd": cwd,
|
|
375
|
+
}
|
|
376
|
+
if timeout is not None:
|
|
377
|
+
data["timeout"] = timeout
|
|
378
|
+
return self.post("/processes/cmd", data=data)
|
|
379
|
+
|
|
380
|
+
async def list_processes_async(self):
|
|
381
|
+
return await self.get_async("/processes")
|
|
382
|
+
|
|
383
|
+
def list_processes(self):
|
|
384
|
+
return self.get("/processes")
|
|
385
|
+
|
|
386
|
+
async def get_process_async(self, pid: str):
|
|
387
|
+
return await self.get_async(f"/processes/{pid}")
|
|
388
|
+
|
|
389
|
+
def get_process(self, pid: str):
|
|
390
|
+
return self.get(f"/processes/{pid}")
|
|
391
|
+
|
|
392
|
+
async def kill_process_async(self, pid: str):
|
|
393
|
+
return await self.delete_async(f"/processes/{pid}")
|
|
394
|
+
|
|
395
|
+
def kill_process(self, pid: str):
|
|
396
|
+
return self.delete(f"/processes/{pid}")
|