Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix rootdir and escaping problems; Improve tools descriptions
Tomas Valentadfbb6cdfa7a2
diff --git a/api-service/codegen/tools/playground/playground.py b/api-service/codegen/tools/playground/playground.pyindex f13748c42..a03127f3a 100644--- a/api-service/codegen/tools/playground/playground.py+++ b/api-service/codegen/tools/playground/playground.py@@ -1,3 +1,5 @@+import os+import playground_client@@ -29,9 +31,9 @@ class Playground:self.api.delete_session(self.session.id)self.client.close()- def run_command(self, cmd: str, env_vars = {}):+ def run_command(self, cmd: str, rootdir: str = "/", env_vars = {}):return self.api.run_process(- self.session.id, playground_client.RunProcessParams(cmd=cmd, envVars=env_vars)+ self.session.id, playground_client.RunProcessParams(cmd=cmd, envVars=env_vars, rootdir=rootdir))def read_file(self, path: str):@@ -56,30 +58,32 @@ class Playground:class NodeJSPlayground(Playground):- node_js_env_id = "KctyCCI7Ijf9"+ node_js_env_id = "QfqlXmCo5iKl"+ rootdir = "/code"- default_javascript_code_file = "index.js"- default_typescript_code_file = "index.ts"+ default_javascript_code_file = os.path.join(rootdir, "index.js")+ default_typescript_code_file = os.path.join(rootdir, "index.ts")def __init__(self):super().__init__(NodeJSPlayground.node_js_env_id)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}")+ return self.run_command(f"node {self.default_javascript_code_file}", rootdir=self.rootdir)def run_typescript_code(self, code: str):self.write_file(self.default_typescript_code_file, code)- return self.run_command(f"ts-node -T {self.default_typescript_code_file}")+ return self.run_command(f"ts-node -T {self.default_typescript_code_file}", rootdir=self.rootdir)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"+ 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}")+ return self.run_command(f"npm install {dependencies}", rootdir=self.rootdir)# TODO: How to handle endless run_commands?# If we actually run express server, the process will never end.diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.pyindex 2ec682e29..8363593f8 100644--- a/api-service/codegen/tools/playground/tools/code.py+++ b/api-service/codegen/tools/playground/tools/code.py@@ -4,6 +4,9 @@ from codegen.tools.playground.playground import NodeJSPlaygroundfrom codegen.tools.playground.tools.process import encode_command_output+def extract_code(code: str):+ return code.strip().strip("`").strip()+def create_code_tools(playground: NodeJSPlayground):# TODO: Escape command@tool("InstallNPMDependencies")@@ -12,22 +15,22 @@ def create_code_tools(playground: NodeJSPlayground):Install specified dependecies with NPM and return errors.The input should be a list of Node.js dependencies separated by spaces.If there are no errors the returned result will be an empty string.+ If you are using this tool to handle missing dependency error try to run the code again after the installation."""- output = playground.install_dependencies(dependencies)+ output = playground.install_dependencies(extract_code(dependencies))return encode_command_output(output, only_errors=True)yield install_dependencies- # TODO: Escape code+ # # TODO: Escape code@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.- This code will be saved to `index.ts` and executed by `ts-node` CLI tool.The returned result will be the output and errors returned when executing the code."""- output = playground.run_typescript_code(code)+ output = playground.run_typescript_code(extract_code(code))return encode_command_output(output)yield run_typescript_code@@ -37,11 +40,9 @@ def create_code_tools(playground: NodeJSPlayground):def check_typescript_code_types(code: str) -> str:"""Check TypeScript types in the specified code and return errors.- The input should be a valid TypeScript code.- This code will be saved to `index.ts` the `tsc --noEmit` command will be used to check for type errors.If there are no errors the returned result will be an empty string."""- output = playground.check_typescript_code(code)+ output = playground.check_typescript_code(extract_code(code))return encode_command_output(output, only_errors=True)yield check_typescript_code_types@@ -51,11 +52,11 @@ def create_code_tools(playground: NodeJSPlayground):def run_javascript_code(code: str) -> str:"""Run the specified JavaScript code and return errors and output.- The input should be a valid TypeScript code.- This code will be saved to `index.js` and executed by `node` command.- The returned result will be the output and errors returned when executing the code."""- output = playground.run_javascript_code(code)++ print('CODE')+ print(extract_code(code))+ output = playground.run_javascript_code(extract_code(code))return encode_command_output(output)yield run_javascript_code