agentscope-runtime 1.0.3__py3-none-any.whl → 1.0.4__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.
- agentscope_runtime/adapters/agentscope/stream.py +2 -9
- agentscope_runtime/adapters/ms_agent_framework/__init__.py +0 -0
- agentscope_runtime/adapters/ms_agent_framework/message.py +205 -0
- agentscope_runtime/adapters/ms_agent_framework/stream.py +418 -0
- agentscope_runtime/adapters/utils.py +6 -0
- agentscope_runtime/cli/commands/deploy.py +371 -0
- agentscope_runtime/common/container_clients/knative_client.py +466 -0
- agentscope_runtime/engine/__init__.py +4 -0
- agentscope_runtime/engine/constant.py +1 -0
- agentscope_runtime/engine/deployers/__init__.py +12 -0
- agentscope_runtime/engine/deployers/adapter/a2a/__init__.py +26 -51
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +19 -10
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_registry.py +4 -201
- agentscope_runtime/engine/deployers/adapter/a2a/nacos_a2a_registry.py +134 -25
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2 -2
- agentscope_runtime/engine/deployers/fc_deployer.py +1506 -0
- agentscope_runtime/engine/deployers/knative_deployer.py +290 -0
- agentscope_runtime/engine/runner.py +12 -0
- agentscope_runtime/engine/services/agent_state/redis_state_service.py +2 -2
- agentscope_runtime/engine/services/memory/redis_memory_service.py +2 -2
- agentscope_runtime/engine/services/session_history/redis_session_history_service.py +2 -2
- agentscope_runtime/engine/tracing/wrapper.py +18 -4
- agentscope_runtime/sandbox/__init__.py +14 -6
- agentscope_runtime/sandbox/box/base/__init__.py +2 -2
- agentscope_runtime/sandbox/box/base/base_sandbox.py +51 -1
- agentscope_runtime/sandbox/box/browser/__init__.py +2 -2
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +198 -2
- agentscope_runtime/sandbox/box/filesystem/__init__.py +2 -2
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +99 -2
- agentscope_runtime/sandbox/box/gui/__init__.py +2 -2
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +117 -1
- agentscope_runtime/sandbox/box/mobile/__init__.py +2 -2
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +247 -100
- agentscope_runtime/sandbox/box/sandbox.py +98 -65
- agentscope_runtime/sandbox/box/shared/routers/generic.py +36 -29
- agentscope_runtime/sandbox/client/__init__.py +6 -1
- agentscope_runtime/sandbox/client/async_http_client.py +339 -0
- agentscope_runtime/sandbox/client/base.py +74 -0
- agentscope_runtime/sandbox/client/http_client.py +108 -329
- agentscope_runtime/sandbox/enums.py +7 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +264 -4
- agentscope_runtime/sandbox/manager/server/app.py +7 -1
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-1.0.3.dist-info → agentscope_runtime-1.0.4.dist-info}/METADATA +102 -28
- {agentscope_runtime-1.0.3.dist-info → agentscope_runtime-1.0.4.dist-info}/RECORD +49 -40
- {agentscope_runtime-1.0.3.dist-info → agentscope_runtime-1.0.4.dist-info}/WHEEL +0 -0
- {agentscope_runtime-1.0.3.dist-info → agentscope_runtime-1.0.4.dist-info}/entry_points.txt +0 -0
- {agentscope_runtime-1.0.3.dist-info → agentscope_runtime-1.0.4.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-1.0.3.dist-info → agentscope_runtime-1.0.4.dist-info}/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import io
|
|
3
3
|
import sys
|
|
4
4
|
import logging
|
|
5
|
-
import
|
|
5
|
+
import asyncio
|
|
6
6
|
import traceback
|
|
7
7
|
from contextlib import redirect_stderr, redirect_stdout
|
|
8
8
|
|
|
@@ -44,26 +44,33 @@ async def run_ipython_cell(
|
|
|
44
44
|
stdout_buf = io.StringIO()
|
|
45
45
|
stderr_buf = io.StringIO()
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
def thread_target():
|
|
48
|
+
with redirect_stdout(stdout_buf), redirect_stderr(stderr_buf):
|
|
49
|
+
preprocessing_exc_tuple = None
|
|
50
|
+
try:
|
|
51
|
+
transformed_cell = ipy.transform_cell(code)
|
|
52
|
+
except Exception:
|
|
53
|
+
transformed_cell = code
|
|
54
|
+
preprocessing_exc_tuple = sys.exc_info()
|
|
55
|
+
|
|
56
|
+
if transformed_cell is None:
|
|
57
|
+
raise HTTPException(
|
|
58
|
+
status_code=500,
|
|
59
|
+
detail=(
|
|
60
|
+
"IPython cell transformation failed: "
|
|
61
|
+
"transformed_cell is None."
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
asyncio.run(
|
|
66
|
+
ipy.run_cell_async(
|
|
67
|
+
code,
|
|
68
|
+
transformed_cell=transformed_cell,
|
|
69
|
+
preprocessing_exc_tuple=preprocessing_exc_tuple,
|
|
70
|
+
),
|
|
60
71
|
)
|
|
61
72
|
|
|
62
|
-
|
|
63
|
-
code,
|
|
64
|
-
transformed_cell=transformed_cell,
|
|
65
|
-
preprocessing_exc_tuple=preprocessing_exc_tuple,
|
|
66
|
-
)
|
|
73
|
+
await asyncio.to_thread(thread_target)
|
|
67
74
|
|
|
68
75
|
stdout_content = stdout_buf.getvalue()
|
|
69
76
|
stderr_content = stderr_buf.getvalue()
|
|
@@ -128,16 +135,16 @@ async def run_shell_command(
|
|
|
128
135
|
if not command:
|
|
129
136
|
raise HTTPException(status_code=400, detail="Command is required.")
|
|
130
137
|
|
|
131
|
-
|
|
138
|
+
proc = await asyncio.create_subprocess_shell(
|
|
132
139
|
command,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
stderr=subprocess.PIPE,
|
|
136
|
-
text=True,
|
|
137
|
-
check=False,
|
|
140
|
+
stdout=asyncio.subprocess.PIPE,
|
|
141
|
+
stderr=asyncio.subprocess.PIPE,
|
|
138
142
|
)
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
|
|
144
|
+
stdout_bytes, stderr_bytes = await proc.communicate()
|
|
145
|
+
|
|
146
|
+
stdout_content = stdout_bytes.decode()
|
|
147
|
+
stderr_content = stderr_bytes.decode()
|
|
141
148
|
|
|
142
149
|
content_list = []
|
|
143
150
|
|
|
@@ -161,7 +168,7 @@ async def run_shell_command(
|
|
|
161
168
|
content_list.append(
|
|
162
169
|
TextContent(
|
|
163
170
|
type="text",
|
|
164
|
-
text=str(
|
|
171
|
+
text=str(proc.returncode),
|
|
165
172
|
description="returncode",
|
|
166
173
|
),
|
|
167
174
|
)
|
|
@@ -173,7 +180,7 @@ async def run_shell_command(
|
|
|
173
180
|
+ "\n"
|
|
174
181
|
+ stderr_content
|
|
175
182
|
+ "\n"
|
|
176
|
-
+ str(
|
|
183
|
+
+ str(proc.returncode),
|
|
177
184
|
description="output",
|
|
178
185
|
),
|
|
179
186
|
)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
from .http_client import SandboxHttpClient
|
|
3
3
|
from .training_client import TrainingSandboxClient
|
|
4
|
+
from .async_http_client import SandboxHttpAsyncClient
|
|
4
5
|
|
|
5
|
-
__all__ = [
|
|
6
|
+
__all__ = [
|
|
7
|
+
"SandboxHttpClient",
|
|
8
|
+
"SandboxHttpAsyncClient",
|
|
9
|
+
"TrainingSandboxClient",
|
|
10
|
+
]
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# pylint: disable=unused-argument
|
|
3
|
+
import logging
|
|
4
|
+
import asyncio
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from pydantic import Field
|
|
9
|
+
|
|
10
|
+
from .base import SandboxHttpBase
|
|
11
|
+
from ..model import ContainerModel
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SandboxHttpAsyncClient(SandboxHttpBase):
|
|
17
|
+
"""
|
|
18
|
+
A Python async client for interacting with the runtime API.
|
|
19
|
+
Connect directly to the container.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
model: Optional[ContainerModel] = None,
|
|
25
|
+
timeout: int = 60,
|
|
26
|
+
domain: str = "localhost",
|
|
27
|
+
) -> None:
|
|
28
|
+
"""
|
|
29
|
+
Initialize the Python async client.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
model (ContainerModel): The pydantic model representing the
|
|
33
|
+
runtime sandbox.
|
|
34
|
+
"""
|
|
35
|
+
super().__init__(model, timeout, domain)
|
|
36
|
+
self.client = httpx.AsyncClient(
|
|
37
|
+
timeout=self.timeout,
|
|
38
|
+
headers=self.headers,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
async def __aenter__(self):
|
|
42
|
+
# Wait for the runtime api server to be healthy
|
|
43
|
+
await self.wait_until_healthy()
|
|
44
|
+
return self
|
|
45
|
+
|
|
46
|
+
async def __aexit__(self, exc_type, exc_value, traceback):
|
|
47
|
+
await self.client.aclose()
|
|
48
|
+
|
|
49
|
+
async def _request(self, method: str, url: str, **kwargs):
|
|
50
|
+
return await self.client.request(method, url, **kwargs)
|
|
51
|
+
|
|
52
|
+
async def safe_request(self, method: str, url: str, **kwargs):
|
|
53
|
+
"""
|
|
54
|
+
Unified HTTP request method with async exception handling.
|
|
55
|
+
Returns JSON if possible, otherwise plain text.
|
|
56
|
+
"""
|
|
57
|
+
try:
|
|
58
|
+
r = await self._request(method, url, **kwargs)
|
|
59
|
+
r.raise_for_status()
|
|
60
|
+
try:
|
|
61
|
+
return r.json()
|
|
62
|
+
except ValueError:
|
|
63
|
+
return r.text
|
|
64
|
+
except httpx.RequestError as e:
|
|
65
|
+
logger.error(f"HTTP error: {e}")
|
|
66
|
+
return {
|
|
67
|
+
"isError": True,
|
|
68
|
+
"content": [{"type": "text", "text": str(e)}],
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async def check_health(self) -> bool:
|
|
72
|
+
"""
|
|
73
|
+
Check if the runtime service is running by verifying the health
|
|
74
|
+
endpoint.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
bool: True if the service is reachable, False otherwise.
|
|
78
|
+
"""
|
|
79
|
+
try:
|
|
80
|
+
r = await self._request(
|
|
81
|
+
"get",
|
|
82
|
+
f"{self.base_url}/healthz",
|
|
83
|
+
)
|
|
84
|
+
return r.status_code == 200
|
|
85
|
+
except httpx.RequestError:
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
async def wait_until_healthy(self) -> None:
|
|
89
|
+
"""
|
|
90
|
+
Wait until the runtime service is running for a specified timeout.
|
|
91
|
+
"""
|
|
92
|
+
start_time = asyncio.get_event_loop().time()
|
|
93
|
+
while (
|
|
94
|
+
asyncio.get_event_loop().time() - start_time < self.start_timeout
|
|
95
|
+
):
|
|
96
|
+
if await self.check_health():
|
|
97
|
+
return
|
|
98
|
+
await asyncio.sleep(1)
|
|
99
|
+
raise TimeoutError(
|
|
100
|
+
"Runtime service did not start within the specified timeout.",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
async def add_mcp_servers(self, server_configs, overwrite=False):
|
|
104
|
+
"""
|
|
105
|
+
Add MCP servers to runtime.
|
|
106
|
+
"""
|
|
107
|
+
endpoint = f"{self.base_url}/mcp/add_servers"
|
|
108
|
+
return await self.safe_request(
|
|
109
|
+
"post",
|
|
110
|
+
endpoint,
|
|
111
|
+
json={"server_configs": server_configs, "overwrite": overwrite},
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
async def list_tools(self, tool_type=None, **kwargs) -> dict:
|
|
115
|
+
"""
|
|
116
|
+
List available MCP tools plus generic built-in tools.
|
|
117
|
+
"""
|
|
118
|
+
data = await self.safe_request(
|
|
119
|
+
"get",
|
|
120
|
+
f"{self.base_url}/mcp/list_tools",
|
|
121
|
+
)
|
|
122
|
+
if isinstance(data, dict) and "isError" not in data:
|
|
123
|
+
data["generic"] = self.generic_tools
|
|
124
|
+
if tool_type:
|
|
125
|
+
return {tool_type: data.get(tool_type, {})}
|
|
126
|
+
return data
|
|
127
|
+
|
|
128
|
+
async def call_tool(
|
|
129
|
+
self,
|
|
130
|
+
name: str,
|
|
131
|
+
arguments: Optional[dict[str, Any]] = None,
|
|
132
|
+
) -> dict:
|
|
133
|
+
"""
|
|
134
|
+
Call a specific MCP tool.
|
|
135
|
+
|
|
136
|
+
If it's a generic tool, call the corresponding local method.
|
|
137
|
+
"""
|
|
138
|
+
if arguments is None:
|
|
139
|
+
arguments = {}
|
|
140
|
+
if name in self.generic_tools:
|
|
141
|
+
if name == "run_ipython_cell":
|
|
142
|
+
return await self.run_ipython_cell(**arguments)
|
|
143
|
+
elif name == "run_shell_command":
|
|
144
|
+
return await self.run_shell_command(**arguments)
|
|
145
|
+
|
|
146
|
+
return await self.safe_request(
|
|
147
|
+
"post",
|
|
148
|
+
f"{self.base_url}/mcp/call_tool",
|
|
149
|
+
json={"tool_name": name, "arguments": arguments},
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
async def run_ipython_cell(
|
|
153
|
+
self,
|
|
154
|
+
code: str = Field(description="IPython code to execute"),
|
|
155
|
+
) -> dict:
|
|
156
|
+
"""
|
|
157
|
+
Run an IPython cell.
|
|
158
|
+
"""
|
|
159
|
+
return await self.safe_request(
|
|
160
|
+
"post",
|
|
161
|
+
f"{self.base_url}/tools/run_ipython_cell",
|
|
162
|
+
json={"code": code},
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
async def run_shell_command(
|
|
166
|
+
self,
|
|
167
|
+
command: str = Field(description="Shell command to execute"),
|
|
168
|
+
) -> dict:
|
|
169
|
+
"""
|
|
170
|
+
Run a shell command.
|
|
171
|
+
"""
|
|
172
|
+
return await self.safe_request(
|
|
173
|
+
"post",
|
|
174
|
+
f"{self.base_url}/tools/run_shell_command",
|
|
175
|
+
json={"command": command},
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
async def commit_changes(
|
|
179
|
+
self,
|
|
180
|
+
commit_message: str = "Automated commit",
|
|
181
|
+
) -> dict:
|
|
182
|
+
"""
|
|
183
|
+
Commit the uncommitted changes with a given commit message.
|
|
184
|
+
"""
|
|
185
|
+
return await self.safe_request(
|
|
186
|
+
"post",
|
|
187
|
+
f"{self.base_url}/watcher/commit_changes",
|
|
188
|
+
json={"commit_message": commit_message},
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
async def generate_diff(
|
|
192
|
+
self,
|
|
193
|
+
commit_a: Optional[str] = None,
|
|
194
|
+
commit_b: Optional[str] = None,
|
|
195
|
+
) -> dict:
|
|
196
|
+
"""
|
|
197
|
+
Generate the diff between two commits or between uncommitted changes
|
|
198
|
+
and the latest commit.
|
|
199
|
+
"""
|
|
200
|
+
return await self.safe_request(
|
|
201
|
+
"post",
|
|
202
|
+
f"{self.base_url}/watcher/generate_diff",
|
|
203
|
+
json={"commit_a": commit_a, "commit_b": commit_b},
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
async def git_logs(self) -> dict:
|
|
207
|
+
"""
|
|
208
|
+
Retrieve the git logs.
|
|
209
|
+
"""
|
|
210
|
+
return await self.safe_request(
|
|
211
|
+
"get",
|
|
212
|
+
f"{self.base_url}/watcher/git_logs",
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
# -------- Workspace File APIs --------
|
|
216
|
+
|
|
217
|
+
async def get_workspace_file(self, file_path: str) -> dict:
|
|
218
|
+
"""
|
|
219
|
+
Retrieve a file from the /workspace directory.
|
|
220
|
+
"""
|
|
221
|
+
try:
|
|
222
|
+
endpoint = f"{self.base_url}/workspace/files"
|
|
223
|
+
params = {"file_path": file_path}
|
|
224
|
+
r = await self._request("get", endpoint, params=params)
|
|
225
|
+
r.raise_for_status()
|
|
226
|
+
|
|
227
|
+
# Check for empty content
|
|
228
|
+
if r.headers.get("Content-Length") == "0":
|
|
229
|
+
logger.warning(f"The file {file_path} is empty.")
|
|
230
|
+
return {"data": b""}
|
|
231
|
+
|
|
232
|
+
# Accumulate the content in chunks
|
|
233
|
+
file_content = bytearray()
|
|
234
|
+
async for chunk in r.aiter_bytes():
|
|
235
|
+
file_content.extend(chunk)
|
|
236
|
+
|
|
237
|
+
return {"data": bytes(file_content)}
|
|
238
|
+
except httpx.RequestError as e:
|
|
239
|
+
logger.error(f"An error occurred while retrieving the file: {e}")
|
|
240
|
+
return {
|
|
241
|
+
"isError": True,
|
|
242
|
+
"content": [{"type": "text", "text": str(e)}],
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async def create_or_edit_workspace_file(
|
|
246
|
+
self,
|
|
247
|
+
file_path: str,
|
|
248
|
+
content: str,
|
|
249
|
+
) -> dict:
|
|
250
|
+
"""
|
|
251
|
+
Create or edit a file within the /workspace directory.
|
|
252
|
+
"""
|
|
253
|
+
return await self.safe_request(
|
|
254
|
+
"post",
|
|
255
|
+
f"{self.base_url}/workspace/files",
|
|
256
|
+
params={"file_path": file_path},
|
|
257
|
+
json={"content": content},
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
async def list_workspace_directories(
|
|
261
|
+
self,
|
|
262
|
+
directory: str = "/workspace",
|
|
263
|
+
) -> dict:
|
|
264
|
+
"""
|
|
265
|
+
List files in the specified directory within the /workspace.
|
|
266
|
+
"""
|
|
267
|
+
return await self.safe_request(
|
|
268
|
+
"get",
|
|
269
|
+
f"{self.base_url}/workspace/list-directories",
|
|
270
|
+
params={"directory": directory},
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
async def create_workspace_directory(self, directory_path: str) -> dict:
|
|
274
|
+
"""
|
|
275
|
+
Create a directory within the /workspace directory.
|
|
276
|
+
"""
|
|
277
|
+
return await self.safe_request(
|
|
278
|
+
"post",
|
|
279
|
+
f"{self.base_url}/workspace/directories",
|
|
280
|
+
params={"directory_path": directory_path},
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
async def delete_workspace_file(self, file_path: str) -> dict:
|
|
284
|
+
"""
|
|
285
|
+
Delete a file within the /workspace directory.
|
|
286
|
+
"""
|
|
287
|
+
return await self.safe_request(
|
|
288
|
+
"delete",
|
|
289
|
+
f"{self.base_url}/workspace/files",
|
|
290
|
+
params={"file_path": file_path},
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
async def delete_workspace_directory(
|
|
294
|
+
self,
|
|
295
|
+
directory_path: str,
|
|
296
|
+
recursive: bool = False,
|
|
297
|
+
) -> dict:
|
|
298
|
+
"""
|
|
299
|
+
Delete a directory within the /workspace directory.
|
|
300
|
+
"""
|
|
301
|
+
return await self.safe_request(
|
|
302
|
+
"delete",
|
|
303
|
+
f"{self.base_url}/workspace/directories",
|
|
304
|
+
params={"directory_path": directory_path, "recursive": recursive},
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
async def move_or_rename_workspace_item(
|
|
308
|
+
self,
|
|
309
|
+
source_path: str,
|
|
310
|
+
destination_path: str,
|
|
311
|
+
) -> dict:
|
|
312
|
+
"""
|
|
313
|
+
Move or rename a file or directory within the /workspace directory.
|
|
314
|
+
"""
|
|
315
|
+
return await self.safe_request(
|
|
316
|
+
"put",
|
|
317
|
+
f"{self.base_url}/workspace/move",
|
|
318
|
+
params={
|
|
319
|
+
"source_path": source_path,
|
|
320
|
+
"destination_path": destination_path,
|
|
321
|
+
},
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
async def copy_workspace_item(
|
|
325
|
+
self,
|
|
326
|
+
source_path: str,
|
|
327
|
+
destination_path: str,
|
|
328
|
+
) -> dict:
|
|
329
|
+
"""
|
|
330
|
+
Copy a file or directory within the /workspace directory.
|
|
331
|
+
"""
|
|
332
|
+
return await self.safe_request(
|
|
333
|
+
"post",
|
|
334
|
+
f"{self.base_url}/workspace/copy",
|
|
335
|
+
params={
|
|
336
|
+
"source_path": source_path,
|
|
337
|
+
"destination_path": destination_path,
|
|
338
|
+
},
|
|
339
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import logging
|
|
3
|
+
from urllib.parse import urljoin
|
|
4
|
+
|
|
5
|
+
DEFAULT_TIMEOUT = 60
|
|
6
|
+
|
|
7
|
+
logging.basicConfig(level=logging.INFO)
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SandboxHttpBase:
|
|
12
|
+
_generic_tools = {
|
|
13
|
+
"run_ipython_cell": {
|
|
14
|
+
"name": "run_ipython_cell",
|
|
15
|
+
"json_schema": {
|
|
16
|
+
"type": "function",
|
|
17
|
+
"function": {
|
|
18
|
+
"name": "run_ipython_cell",
|
|
19
|
+
"description": "Run an IPython cell.",
|
|
20
|
+
"parameters": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"code": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "IPython code to execute",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
"required": ["code"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
"run_shell_command": {
|
|
34
|
+
"name": "run_shell_command",
|
|
35
|
+
"json_schema": {
|
|
36
|
+
"type": "function",
|
|
37
|
+
"function": {
|
|
38
|
+
"name": "run_shell_command",
|
|
39
|
+
"description": "Run a shell command.",
|
|
40
|
+
"parameters": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"properties": {
|
|
43
|
+
"command": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"description": "Shell command to execute",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
"required": ["command"],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
def __init__(self, model, timeout: int = 60, domain: str = "localhost"):
|
|
56
|
+
self.base_url = urljoin(
|
|
57
|
+
model.url.replace("localhost", domain),
|
|
58
|
+
"fastapi",
|
|
59
|
+
)
|
|
60
|
+
self.start_timeout = timeout
|
|
61
|
+
self.timeout = model.timeout or DEFAULT_TIMEOUT
|
|
62
|
+
self.secret = model.runtime_token
|
|
63
|
+
|
|
64
|
+
self.headers = {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"x-agentrun-session-id": "s" + model.container_id,
|
|
67
|
+
"x-agentscope-runtime-session-id": "s" + model.container_id,
|
|
68
|
+
}
|
|
69
|
+
if self.secret:
|
|
70
|
+
self.headers["Authorization"] = f"Bearer {self.secret}"
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def generic_tools(self) -> dict:
|
|
74
|
+
return self._generic_tools
|