Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Cleanup

Tomas Valenta301f4e19035c
diff --git a/api-service/codegen/tools/playground/playground.py b/api-service/codegen/tools/playground/playground.py
index 6dc530b70..a63c22bf9 100644
--- a/api-service/codegen/tools/playground/playground.py
+++ b/api-service/codegen/tools/playground/playground.py
@@ -26,6 +26,9 @@ class Playground:
port_check_interval = 1 # 1s
max_port_checks = 10
+ rootdir = "/"
+ env_vars = {}
+
mock_data_filename = "index.ts"
def __init__(self, env_id: str):
@@ -61,8 +64,8 @@ class Playground:
def run_command(
self,
cmd: str,
- rootdir: str = "/",
- env_vars: dict[str, str] = {},
+ rootdir = rootdir,
+ env_vars = env_vars,
):
return self.api.start_process(
self.session.id,
@@ -77,17 +80,18 @@ class Playground:
def start_process(
self,
cmd: str,
- rootdir: str = "/",
- env_vars: dict[str, str] = {},
+ rootdir = rootdir,
+ env_vars = env_vars,
):
"""Start process and return the process ID."""
- response = self.api.start_process(
+ return self.api.start_process(
self.session.id,
playground_client.StartProcessParams(
- cmd=cmd, envVars=env_vars, rootdir=rootdir
+ cmd=cmd,
+ envVars=env_vars,
+ rootdir=rootdir,
),
- )
- return response.process_id
+ ).process_id
def stop_process(self, process_id: str):
return self.api.stop_process(
@@ -131,8 +135,8 @@ class Playground:
server_cmd: str,
request_cmd: str,
port: float,
- rootdir: str = "/",
- env_vars: dict[str, str] = {},
+ rootdir = rootdir,
+ env_vars = env_vars,
):
server_process_id = self.start_process(
cmd=server_cmd,
@@ -161,7 +165,6 @@ class NodeJSPlayground(Playground):
run_code_timeout = 5 # 5s
default_javascript_code_file = os.path.join(rootdir, "index.js")
- default_typescript_code_file = os.path.join(rootdir, "index.ts")
def __init__(self, envs: List[EnvVar]):
super().__init__(NodeJSPlayground.node_js_env_id)
@@ -170,7 +173,6 @@ class NodeJSPlayground(Playground):
def run_javascript_code(self, code: str, timeout: float = run_code_timeout):
print(f"Running javascript code: {code}")
self.write_file(self.default_javascript_code_file, code)
-
process_id = self.start_process(
f"node {self.default_javascript_code_file}",
rootdir=self.rootdir,
@@ -184,21 +186,6 @@ class NodeJSPlayground(Playground):
print(result)
return result
- def run_typescript_code(self, code: str, typecheck: bool = False):
- self.write_file(self.default_typescript_code_file, code)
- return self.run_command(
- f"ts-node {'-T' if typecheck else ''} {self.default_typescript_code_file}",
- rootdir=self.rootdir,
- env_vars=self.env_vars,
- )
-
- def check_typescript_code(self, code: str):
- self.write_file(self.default_typescript_code_file, code)
- return self.run_command(
- f"tsc {self.default_typescript_code_file} --noEmit --skipLibCheck",
- rootdir=self.rootdir,
- )
-
def install_dependencies(self, dependencies: str):
return self.run_command(f"npm install {dependencies}", rootdir=self.rootdir)
@@ -219,18 +206,3 @@ class NodeJSPlayground(Playground):
)
print(result)
return result
-
- def run_typescript_server_code_with_request(
- self,
- code: str,
- request_cmd: str,
- port: float,
- ):
- self.write_file(self.default_javascript_code_file, code)
- return self.run_server_with_request(
- server_cmd=f"ts-node {self.default_javascript_code_file}",
- request_cmd=request_cmd,
- port=port,
- rootdir=self.rootdir,
- env_vars=self.env_vars,
- )
diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.py
index 370c357b9..0bbb6e2c1 100644
--- a/api-service/codegen/tools/playground/tools/code.py
+++ b/api-service/codegen/tools/playground/tools/code.py
@@ -25,60 +25,6 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory):
yield install_dependencies
- # This tool is just for executing TypeScript without doing the request to server
- # @tool("RunTypeScriptCode")
- # def run_typescript_code(code: str) -> str:
- # """
- # Run the specified TypeScript code and return errors and output.
- # The input should be a valid TypeScript code.
- # The returned result will be the output and errors returned when executing the code.
- # """
- # output = playground.run_typescript_code(extract_code(code))
- # result = encode_command_output(output)
-
- # return result if len(result) > 0 else "Code execution finished without error"
-
- # # yield run_typescript_code
-
- @tool("RunTypeScriptCode")
- def run_typescript_code(code: str) -> str:
- """
- Execute TypeScript code and make a request to see if server correctly handles needed requests.
- The input should be a valid TypeScript code.
- The server should run on http://localhost:3000.
- The returned result is a the request's output followed by the server code output and errors.
- """
- mock_request_cmd = mock.terminal_command()
-
- port = 3000
- (
- request_output,
- server_output,
- ) = playground.run_typescript_server_code_with_request(
- code=code,
- request_cmd=mock_request_cmd,
- port=port,
- )
-
- request_result = encode_command_output(request_output)
- server_result = encode_command_output(server_output)
-
- return f"Request result:\n{request_result}\nCode execution result:\n{server_result}"
-
- # yield run_typescript_code
-
- @tool("CheckTypeScriptCodeTypes")
- def check_typescript_code_types(code: str) -> str:
- """
- Check TypeScript types in the specified code and return errors.
- """
- output = playground.check_typescript_code(extract_code(code))
- result = encode_command_output(output, only_errors=True)
-
- return result if len(result) > 0 else "Typechecking finished without error"
-
- # yield check_typescript_code_types
-
last_javascript_code: str | None
# TODO: Add timeout that stops the code execution if it doesn't stop after some time
# This tool is just for executing JavaScript without doing the request to server
@@ -88,7 +34,9 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory):
Run JavaScript code and return errors and output.
Input should be a valid JavaScript code.
"""
+ nonlocal last_javascript_code
last_javascript_code = code
+
output = playground.run_javascript_code(extract_code(code))
result = encode_command_output(output)
return result if len(result) > 0 else "Code execution finished without error"
@@ -123,26 +71,3 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory):
)
# yield curl_javascript_server
-
- # @tool("RunJavaScriptCode")
- # def run_javascript_code(code: str) -> str:
- # """
- # Execute JavaScript code and make a request to see if server correctly handles needed requests.
- # The input should be a valid JavaScript code.
- # The server should run on http://localhost:3000.
- # The returned result is a the request's output followed by the server code output and errors.
- # """
-
- # mock_request_cmd = mock.terminal_command()
-
- # port = 3000
- # request_output, server_output = playground.run_javascript_server_code_with_request(
- # code=code, request_cmd=mock_request_cmd, port=port,
- # )
-
- # request_result = encode_command_output(request_output)
- # server_result = encode_command_output(server_output)
-
- # return f"Request result:\n{request_result}\nCode execution result:\n{server_result}"
-
- # yield run_javascript_code