Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Rename tools
Vasek Mlejnsky2cffd0c1ff78
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.pyindex 1905d7230..704512f53 100644--- a/api-service/codegen/codegen.py+++ b/api-service/codegen/codegen.py@@ -164,6 +164,9 @@ class Codegen(BaseModel):inst = instruction["content"].format(*values)instructions = instructions + "\n" + f"{inst_idx}. {inst}"+ print("+++ BLOCKS")+ print(blocks)+ print("--- BLOCKS")for block in blocks:if block.get("type") == "Basic":inst_idx += 1diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.pyindex 35a8d65be..0f5dddd92 100644--- a/api-service/codegen/prompt.py+++ b/api-service/codegen/prompt.py@@ -49,7 +49,9 @@ import express from 'express';const app = express();const port = 3000;app.use(express.json())-// TODO: Implement the {0} handlers here++// TODO: Implement the {0} handler here+app.listen(port, async () => {{console.log(`Server listening on port ${{port}}`)}})diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.pyindex 08a157a98..7b0fdbf92 100644--- a/api-service/codegen/tools/playground/tools/code.py+++ b/api-service/codegen/tools/playground/tools/code.py@@ -9,6 +9,8 @@ def extract_code(code: str):def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory, **kwargs):+ last_javascript_code: str | None = None+# Ensure that the function is a generator even if no tools are yieldedyield from ()@@ -25,50 +27,69 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory, **yield install_dependencies- last_javascript_code: str | None = None-- # This tool is just for executing JavaScript without doing the request to server- @async_tool("RunJavaScriptCode")- async def run_javascript_code(code: str) -> str:+ # A tool for executing index.mjs file+ @async_tool("RunSavedCode")+ async def run_saved_code(empty: str) -> str:+ """Run JavaScript code that is inside the index.mjs. The tool takes no input. Example usage:+ <action tool="RunSavedCode">+ </action>"""- Run JavaScript code as ECMAScript module and return output.- Input should be a valid JavaScript code. Example usage:- <action tool="RunJavaScriptCode">- console.log('hello world')+ output = await playground.run_saved_javascript_code()+ return encode_command_output(output)++ yield run_saved_code++ # A tool for writing JavaScript code specifically to the index.mjs file+ @async_tool("WriteJavaScriptCode")+ async def write_javascript_code(code: str) -> str:+ """Write JavaScript code to the index.mjs file. The input should be valid JavaScript code. Example usage:+ <action tool="WriteJavaScriptCode">+ import process from 'process'+ console.log(process.env)</action>"""- await playground.update_envs()-nonlocal last_javascript_codelast_javascript_code = code- output = await playground.run_javascript_code(code)- result = encode_command_output(output)- return result if len(result) > 0 else "Code execution finished without error"+ await playground.write_javascript_code(extract_code(code))+ return "Code written to index.mjs"++ yield write_javascript_code++ # # This tool is just for executing JavaScript without doing the request to server+ # @async_tool("RunJavaScriptCode")+ # async def run_javascript_code(code: str) -> str:+ # """+ # Run JavaScript code as ECMAScript module and return output.+ # Input should be a valid JavaScript code. Example usage:+ # <action tool="RunJavaScriptCode">+ # console.log('hello world')+ # </action>+ # """+ # await playground.update_envs()- yield run_javascript_code+ # nonlocal last_javascript_code+ # last_javascript_code = code- @async_tool("CurlJavaScriptServer")- async def curl_javascript_server(curl_command: str) -> str:+ # output = await playground.run_javascript_code(code)+ # result = encode_command_output(output)+ # return result if len(result) > 0 else "Code execution finished without error"++ # yield run_javascript_code++ @async_tool("Curl")+ async def curl(curl_command: str) -> str:"""Make a curl request. The input should be the `curl` command. Example usage:<action tool="CurlJavaScriptServer">curl --no-progress-meter -X POST -H "Content-Type: application/json" -d '{{"key": "value"}}' http://localhost:3000/</action>"""- # """- # Make a request to check if the previously run JavaScript code is a server that can handle the needed request. This tool has no input. Example usage:- # ```- # <action tool="CurlJavaScriptServer">- # </action>- # ```"""await playground.update_envs()nonlocal last_javascript_codeif last_javascript_code is None:- return "Cannot curl, you need to run code first"-- # mock_request_cmd = mock.terminal_command()+ return "Cannot curl, you need to write code first"port = 3000(@@ -86,4 +107,44 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory, **return f"Curl output:\n{request_result}\nServer output:\n{server_result}"- yield curl_javascript_server+ yield curl++ # @async_tool("CurlJavaScriptServer")+ # async def curl_javascript_server(curl_command: str) -> str:+ # """+ # Make a curl request. The input should be the `curl` command. Example usage:+ # <action tool="CurlJavaScriptServer">+ # curl --no-progress-meter -X POST -H "Content-Type: application/json" -d '{{"key": "value"}}' http://localhost:3000/+ # </action>+ # """+ # # """+ # # Make a request to check if the previously run JavaScript code is a server that can handle the needed request. This tool has no input. Example usage:+ # # ```+ # # <action tool="CurlJavaScriptServer">+ # # </action>+ # # ```"""+ # await playground.update_envs()++ # nonlocal last_javascript_code+ # if last_javascript_code is None:+ # return "Cannot curl, you need to run code first"++ # # mock_request_cmd = mock.terminal_command()++ # port = 3000+ # (+ # request_output,+ # server_output,+ # ) = await playground.run_javascript_server_code_with_request(+ # code=last_javascript_code,+ # # request_cmd=mock_request_cmd,+ # request_cmd=curl_command.strip(),+ # port=port,+ # )++ # request_result = encode_command_output(request_output)+ # server_result = encode_command_output(server_output)++ # return f"Curl output:\n{request_result}\nServer output:\n{server_result}"++ # yield curl_javascript_serverdiff --git a/api-service/session/playground/nodejs.py b/api-service/session/playground/nodejs.pyindex 0e8a089b5..2d4bfaadd 100644--- a/api-service/session/playground/nodejs.py+++ b/api-service/session/playground/nodejs.py@@ -13,20 +13,29 @@ class NodeJSPlayground(Playground):def __init__(self, get_envs: GetEnvs):super().__init__(NodeJSPlayground.node_js_env_id, get_envs)- async def run_javascript_code(self, code: str):- # print(f"Running javascript code...")- await self.write_file(self.default_javascript_code_file, code)+ # async def run_javascript_code(self, code: str):+ # # print(f"Running javascript code...")+ # await self.write_file(self.default_javascript_code_file, code)+ # result = await self.run_command(+ # f"node {self.default_javascript_code_file}",+ # rootdir=self.rootdir,+ # timeout=self.run_code_timeout,+ # )+ # # pprint.pprint(f"Result: {result}")+ # return result+ async def run_saved_javascript_code(self):result = await self.run_command(f"node {self.default_javascript_code_file}",rootdir=self.rootdir,timeout=self.run_code_timeout,)- # pprint.pprint(f"Result: {result}")return resultasync def install_dependencies(self, dependencies: str):# print(f"Installing dependencies: {dependencies}")- result = await self.run_command(f"npm install {dependencies}", rootdir=self.rootdir)+ result = await self.run_command(+ f"npm install {dependencies}", rootdir=self.rootdir+ )# pprint.pprint(f"Result: {result}")return result@@ -46,3 +55,6 @@ class NodeJSPlayground(Playground):)# pprint.pprint(f"Result: {result}")return result++ async def write_javascript_code(self, code: str):+ await self.write_file(self.default_javascript_code_file, code)diff --git a/components/Editor/RightSidebar/Logs/Tool/CurlServer.tsx b/components/Editor/RightSidebar/Logs/Tool/Curl.tsxsimilarity index 63%rename from components/Editor/RightSidebar/Logs/Tool/CurlServer.tsxrename to components/Editor/RightSidebar/Logs/Tool/Curl.tsxindex 4b7ceaa55..999c2f80b 100644--- a/components/Editor/RightSidebar/Logs/Tool/CurlServer.tsx+++ b/components/Editor/RightSidebar/Logs/Tool/Curl.tsx@@ -2,7 +2,7 @@ import {ReactNode} from 'react'import {- TerminalSquare,+ Terminal,} from 'lucide-react'import { ToolName, ToolLog } from 'db/types'@@ -14,10 +14,10 @@ export interface Props {log: ToolLog}-function CurlServer({+function Curl({log,}: Props) {- if (log.tool_name !== ToolName.CurlJavaScriptServer) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.CurlJavaScriptServer}' tool`)+ if (log.tool_name !== ToolName.Curl) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.Curl}' tool`)let body: ReactNode = nullif (log.tool_input.trim()) {@@ -35,10 +35,10 @@ function CurlServer({return (<Baselog={log}- icon={<TerminalSquare size="16px" />}+ icon={<Terminal size="16px" />}body={body}/>)}-export default CurlServer\ No newline at end of file+export default Curl\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/RunCode.tsx b/components/Editor/RightSidebar/Logs/Tool/RunSavedCode.tsxsimilarity index 70%rename from components/Editor/RightSidebar/Logs/Tool/RunCode.tsxrename to components/Editor/RightSidebar/Logs/Tool/RunSavedCode.tsxindex acda4eea6..a4babc2ed 100644--- a/components/Editor/RightSidebar/Logs/Tool/RunCode.tsx+++ b/components/Editor/RightSidebar/Logs/Tool/RunSavedCode.tsx@@ -14,10 +14,10 @@ export interface Props {log: ToolLog}-function RunCode({+function RunSavedCode({log,}: Props) {- if (log.tool_name !== ToolName.RunJavaScriptCode) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.RunJavaScriptCode}' tool`)+ if (log.tool_name !== ToolName.RunSavedCode) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.WriteJavaScriptCode}' tool`)let body: ReactNode = nullif (log.tool_input.trim()) {@@ -41,4 +41,4 @@ function RunCode({)}-export default RunCode\ No newline at end of file+export default RunSavedCode\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/WriteCode.tsx b/components/Editor/RightSidebar/Logs/Tool/WriteCode.tsxnew file mode 100644index 000000000..ba021a14f--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Tool/WriteCode.tsx@@ -0,0 +1,44 @@+import {+ ReactNode+} from 'react'+import {+ FileEdit,+} from 'lucide-react'++import { ToolName, ToolLog } from 'db/types'++import Base from './Base'+++export interface Props {+ log: ToolLog+}++function WriteCode({+ log,+}: Props) {+ if (log.tool_name !== ToolName.WriteJavaScriptCode) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.WriteJavaScriptCode}' tool`)++ let body: ReactNode = null+ if (log.tool_input.trim()) {+ body = (+ <div className="+ pt-2+ ">+ <pre>+ {log.tool_input.trim()}+ </pre>+ </div>+ )+ }++ return (+ <Base+ log={log}+ icon={<FileEdit size="16px" />}+ body={body}+ />+ )+}++export default WriteCode\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/index.tsx b/components/Editor/RightSidebar/Logs/Tool/index.tsxindex d7dcc42ae..c6f75d4ef 100644--- a/components/Editor/RightSidebar/Logs/Tool/index.tsx+++ b/components/Editor/RightSidebar/Logs/Tool/index.tsx@@ -1,9 +1,10 @@import { ToolLog, ToolName } from 'db/types'import AskHuman from './AskHuman'-import CurlServer from './CurlServer'+import Curl from './Curl'import InstallNPMDeps from './InstallNPMDeps'-import RunCode from './RunCode'+import WriteCode from './WriteCode'+import RunSavedCode from './RunSavedCode'export interface Props {log: ToolLog@@ -15,16 +16,18 @@ function Tool({onAnswer,}: Props) {switch (log.tool_name) {- case ToolName.CurlJavaScriptServer:- return <CurlServer log={log} />+ case ToolName.Curl:+ return <Curl log={log} />case ToolName.InstallNPMDependencies:return <InstallNPMDeps log={log} />- case ToolName.RunJavaScriptCode:- return <RunCode log={log} />+ case ToolName.WriteJavaScriptCode:+ return <WriteCode log={log} />+ case ToolName.RunSavedCode:+ return <RunSavedCode log={log} />case ToolName.AskHuman:return <AskHuman log={log} onAnswer={onAnswer} />default:- return <div>Unknown tool {log.tool_name}</div>+ return <div>Cannot render frontend component - unknown tol {log.tool_name}</div>}}diff --git a/db/types.ts b/db/types.tsindex 58f7969ef..572792dbf 100644--- a/db/types.ts+++ b/db/types.ts@@ -6,8 +6,9 @@ export enum LogType {export enum ToolName {AskHuman = 'AskHuman',InstallNPMDependencies = 'InstallNPMDependencies',- RunJavaScriptCode = 'RunJavaScriptCode',- CurlJavaScriptServer = 'CurlJavaScriptServer',+ WriteJavaScriptCode = 'WriteJavaScriptCode',+ RunSavedCode = 'RunSavedCode',+ Curl = 'Curl',}interface BaseLog {