Skip to content

armgit / E2B

Public Imported from GitHub
0

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

commit

Vasek Mlejnskyf11548cd5d33
diff --git a/api-service/app.py b/api-service/app.py
index 1bfd2dee6..933631bc5 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -44,6 +44,8 @@ def generate():
method = body["method"]
route = body["route"]
+ db.update_state(run_id=run_id, state=DeploymentState.Generating)
+
final_prompt, js_code = generate_req_handler(
run_id=run_id,
db=db,
@@ -83,11 +85,14 @@ def generate():
db.update_state(run_id=run_id, state=DeploymentState.Finished)
+ api_url = f"https://{project_id}.devbook.workers.dev"
+ db.update_url(run_id=run_id, url=api_url)
+
# TODO: Report back the URL of deployed API
return {
"code": js_code.strip("`").strip(),
"prompt": final_prompt,
- "url": f"https://{project_id}.devbook.workers.dev",
+ "url": api_url,
}
diff --git a/api-service/cf-worker-template/index.js b/api-service/cf-worker-template/index.js
index cb8c2ed58..f0a21b24d 100644
--- a/api-service/cf-worker-template/index.js
+++ b/api-service/cf-worker-template/index.js
@@ -3,15 +3,16 @@ import { Router } from 'itty-router'
const router = Router()
async function handlepostRequest(request) {
- const body = await request.json()
- const { email } = body
- const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- if (!regex.test(String(email).toLowerCase())) {
- return new Response(JSON.stringify({ error: 'Invalid email' }), { status: 400 })
+ const { value, from, to } = request.json();
+ const app_id = "79d294dc12da4ff4921bb943b1a7a45c";
+ const url = `https://openexchangerates.org/api/convert/${value}/${from}/${to}?app_id=${app_id}`;
+ try {
+ const response = await fetch(url);
+ const data = await response.json();
+ return new Response(JSON.stringify(data));
+ } catch (err) {
+ return new Response(JSON.stringify(err));
}
- // save email to Supabase DB
- // respond with "Ok" message
- return new Response(JSON.stringify({ message: 'Ok' }), { status: 200 })
}
router.post('/', handlepostRequest)
diff --git a/api-service/cf-worker-template/wrangler.toml b/api-service/cf-worker-template/wrangler.toml
index 6120e7819..86af7b877 100644
--- a/api-service/cf-worker-template/wrangler.toml
+++ b/api-service/cf-worker-template/wrangler.toml
@@ -1,6 +1,6 @@
# This wrangler file will be injected withl values during runtime and saved as wrangler.toml
-name = "460355b3"
+name = "currency-conversion"
main = "./index.js"
# route = ''
compatibility_date = "2022-05-03"
diff --git a/api-service/codegen/db/base.py b/api-service/codegen/db/base.py
index 310bba224..0a7435d35 100644
--- a/api-service/codegen/db/base.py
+++ b/api-service/codegen/db/base.py
@@ -24,7 +24,6 @@ class Database:
"logs": logs,
"project_id": project_id,
"route_id": route_id,
- "state": DeploymentState.Generating.value,
},
).execute()
@@ -34,3 +33,10 @@ class Database:
"state": state.value,
}
).eq("id", run_id).execute()
+
+ def update_url(self, run_id: str, url: str) -> None:
+ self.client.table("deployments").update(
+ {
+ "url": url,
+ }
+ ).eq("id", run_id).execute()