Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add playground actions; Format
Tomáš Valenta44cef5ca6156
diff --git a/api-service/playground_client/main.py b/api-service/playground_client/main.pyindex dab949057..3123039a3 100644--- a/api-service/playground_client/main.py+++ b/api-service/playground_client/main.py@@ -5,26 +5,32 @@ from typing import TypedDict, Unionconfiguration = openapi_client.Configuration(- host = 'https://localhost:9001',+ host="https://localhost:9001",)+class FilesystemEntryType(Enum):- FILE = 'file'- DIR = 'directory'+ FILE = "file"+ DIR = "directory"+class FilesystemEntry(TypedDict):name: strtype: FilesystemEntryType+class CommandOutput(TypedDict):error: Union[str, None]output: str+class Playground:def __init__(self, env_id: str):self.client = openapi_client.ApiClient(configuration)self.api = openapi_client.DefaultApi(self.client)- self.session = self.api.create_session(openapi_client.CreateSessionParams(env_id))+ self.session = self.api.create_session(+ openapi_client.CreateSessionParams(env_id)+ )self.is_closed = Falsedef __del__(self):@@ -37,13 +43,15 @@ class Playground:self.client.close()def run_command(self, cmd: str):- result = self.api.run_process(self.session.id, openapi_client.RunProcessParams(cmd))+ result = self.api.run_process(+ self.session.id, openapi_client.RunProcessParams(cmd)+ )err_lines = [err.line for err in result.stderr]out_lines = [out.line for out in result.stdout]return CommandOutput(- error=err_lines.join('\n') if len(err_lines) > 0 else None,- output='\n'.join(out_lines)+ error=err_lines.join("\n") if len(err_lines) > 0 else None,+ output="\n".join(out_lines),)def read_file(self, path: str):@@ -55,8 +63,10 @@ class Playground:return [FilesystemEntry(name=entry.name,- type=FilesystemEntryType.DIR if entry.is_dir else FilesystemEntryType.FILE- )+ type=FilesystemEntryType.DIR+ if entry.is_dir+ else FilesystemEntryType.FILE,+ )for entry in result.entries]@@ -67,19 +77,43 @@ class Playground:self.api.delete_filesystem_entry(self.session.id, path)def write_file(self, path: str, content: str):- self.api.write_filesystem_file(self.session.id, path, openapi_client.WriteFilesystemFileParams(content))+ self.api.write_filesystem_file(+ self.session.id, path, openapi_client.WriteFilesystemFileParams(content)+ )def make_dir(self, path: str):self.api.make_filesystem_dir(self.session.id, path)class NodeJSPlayground(Playground):- node_js_env_id = 'rVGhg9SdIzZ2'- default_code_file = 'index.js'+ # TODO: Check if node 18 is used+ node_js_env_id = "rVGhg9SdIzZ2"++ default_javascript_code_file = "index.js"+ default_typescript_code_file = "index.ts"def __init__(self):super().__init__(NodeJSPlayground.node_js_env_id)- def run_code(self, code: str):- self.write_file(self.default_code_file, code)- return self.run_command(f'node {self.default_code_file}')+ def run_javascript_code(self, code: str):+ self.write_file(self.default_javascript_code_file, code)+ return self.run_command(f"node {self.default_javascript_code_file}")++ # TODO: Install `ts-node` in the env+ def run_typescript_code(self, code: str):+ self.write_file(self.default_typescript_code_file, code)+ return self.run_command(f"ts-node {self.default_typescript_code_file}")++ # TODO: Install `tsc` in the env+ 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"+ )++ def install_dependencies(self, dependencies: str):+ return self.run_command(f"npm install {dependencies}")++ # TODO: How to handle endless run_commands?+ # If we actually run express server, the process will never end.+ # Can we somehow start server and make a request so we check if it works? This is tests, right?