Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Allow passing full curl command to CurlJavaScriptServer; add db method for fetching env vars

Vasek Mlejnskyfa0f973d9c68
diff --git a/api-service/app.py b/api-service/app.py
index 4e4156937..c77b6e6a3 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -47,8 +47,14 @@ async def generate():
blocks = body["blocks"]
method = body["method"]
route = body["route"]
+
+ # TODO: STOP SENDING ENVS FROM FRONTEND BECAUSE WE FETCH THEM FROM DB
envs: List[EnvVar] = body["envs"]
+ # `get_env_vars()` returns a list of dicts. See the docstring comment inside `get_env_vars`
+ env = await db.get_env_vars(project_id)
+ # TODO: ------------------
+
await db.create_deployment(run_id=run_id, project_id=project_id, route_id=route_id)
playground = None
try:
@@ -75,6 +81,7 @@ async def generate():
# Generate the code
print("Generating...", flush=True)
await cg.generate(
+ project_id=project_id,
run_id=run_id,
route=route,
method=method,
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index 7b79becf5..16d04e5c8 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -102,7 +102,6 @@ class Codegen(BaseModel):
for tool in custom_tools:
tool.callback_manager = callback_manager
-
# Create the LLM
llm = ChatOpenAI(
streaming=True,
@@ -139,7 +138,9 @@ class Codegen(BaseModel):
blocks: List[Dict],
):
self._callback_manager.add_handler(
- LogsCallbackHandler(database=self._database, run_id=run_id, tool_names=self.tool_names())
+ LogsCallbackHandler(
+ database=self._database, run_id=run_id, tool_names=self.tool_names()
+ )
)
input_vars = {
diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.py
index 09f289b17..fd8881c7d 100644
--- a/api-service/codegen/tools/playground/tools/code.py
+++ b/api-service/codegen/tools/playground/tools/code.py
@@ -49,19 +49,26 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory, **
yield run_javascript_code
- @async_tool("CurlJavaScriptServer")
- async def curl_javascript_server(empty: str) -> str:
+ @async_tool("CurlJavascriptServer")
+ async def curl_javascript_server(curl_command: str) -> str:
"""
- 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:
+ Make a curl request. The input should be the `curl` command. Example usage:
```
- <action tool="CurlJavaScriptServer">
+ <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>
+ # ```"""
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()
+ # mock_request_cmd = mock.terminal_command()
port = 3000
(
@@ -69,7 +76,8 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory, **
server_output,
) = playground.run_javascript_server_code_with_request(
code=last_javascript_code,
- request_cmd=mock_request_cmd,
+ # request_cmd=mock_request_cmd,
+ request_cmd=curl_command.strip(),
port=port,
)
diff --git a/api-service/database/database.py b/api-service/database/database.py
index 93cd73822..2b13b9b26 100644
--- a/api-service/database/database.py
+++ b/api-service/database/database.py
@@ -13,7 +13,8 @@ class DeploymentState(Enum):
Error = "error"
-deploymentsTable = "deployments"
+tableDeployments = "deployments"
+tableProjects = "projects"
class Database:
@@ -23,7 +24,7 @@ class Database:
async def create_deployment(
self, run_id: str, project_id: str, route_id: str
) -> None:
- await self.client.table(deploymentsTable).insert(
+ await self.client.table(tableDeployments).insert(
{
"id": run_id,
"project_id": project_id,
@@ -34,7 +35,7 @@ class Database:
async def push_logs(self, run_id: str, logs: List[Dict[str, str]]) -> None:
if len(logs) > 0:
- await self.client.table(deploymentsTable).update(
+ await self.client.table(tableDeployments).update(
{
"logs": logs,
}
@@ -42,14 +43,14 @@ class Database:
async def push_raw_logs(self, run_id: str, logs_raw: str) -> None:
if logs_raw:
- await self.client.table(deploymentsTable).update(
+ await self.client.table(tableDeployments).update(
{
"logs_raw": logs_raw,
}
).eq("id", run_id).execute()
async def update_state(self, run_id: str, state: DeploymentState) -> None:
- await self.client.table(deploymentsTable).update(
+ await self.client.table(tableDeployments).update(
{
"state": state.value,
}
@@ -64,6 +65,34 @@ class Database:
if url is not None:
update["url"] = url
- await self.client.table(deploymentsTable).update(update).eq(
+ await self.client.table(tableDeployments).update(update).eq(
"id", run_id
).execute()
+
+ async def get_env_vars(self, project_id: str) -> List[Dict[str, str]]:
+ """The return value is a list of dicts with the following keys:
+ - key: The name of an env var
+ - value: The value of an env var
+
+ Example of a return value:
+ [
+ {
+ "key": "",
+ "value": "",
+ },
+ {
+ "key": "MY_TOKEN",
+ "value": "my-token-value",
+ }
+ ]
+ """
+ result = (
+ await self.client.table(tableProjects)
+ .select("data")
+ .eq("id", project_id)
+ .execute()
+ )
+ state = result.data[0]["data"]["state"]
+ if "envs" in state:
+ return state["envs"]
+ return []