Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add envs

Vasek Mlejnsky2595af4d1361
diff --git a/api-service/app.py b/api-service/app.py
index 33b0535c5..30dd21dd1 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -43,6 +43,9 @@ def generate():
blocks = body["blocks"]
method = body["method"]
route = body["route"]
+ envs = body["envs"]
+ print("ENVS")
+ print(envs)
db.create_deployment(run_id=run_id, project_id=project_id, route_id=route_id)
diff --git a/api-service/cf-worker-template/index.js b/api-service/cf-worker-template/index.js
index f0a21b24d..2903bfa33 100644
--- a/api-service/cf-worker-template/index.js
+++ b/api-service/cf-worker-template/index.js
@@ -1,23 +1 @@
-import { Router } from 'itty-router'
-
-const router = Router()
-
-async function handlepostRequest(request) {
- 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));
- }
-}
-
-router.post('/', handlepostRequest)
-router.get('*', () => new Response('Not found', { status: 404 }))
-
-export default {
- fetch: router.handle
-}
\ No newline at end of file
+The code above satisfies the prompt.
\ No newline at end of file
diff --git a/api-service/cf-worker-template/wrangler.toml b/api-service/cf-worker-template/wrangler.toml
index 86af7b877..5f1abf473 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 = "currency-conversion"
+name = "meteo"
main = "./index.js"
# route = ''
compatibility_date = "2022-05-03"
diff --git a/components/Editor/Logs/index.tsx b/components/Editor/Logs/index.tsx
index 5c0794f88..c33d32146 100644
--- a/components/Editor/Logs/index.tsx
+++ b/components/Editor/Logs/index.tsx
@@ -1,4 +1,8 @@
-import { useEffect } from 'react'
+import {
+ useEffect,
+ useState,
+ useCallback,
+} from 'react'
import ReactMarkdown from 'react-markdown'
import hljs from 'highlight.js'
import { deployment_state } from '@prisma/client'
@@ -6,6 +10,7 @@ import { deployment_state } from '@prisma/client'
import { Log } from 'db/types'
import Sidebar from 'components/Sidebar'
import Text from 'components/Text'
+import Button from 'components/Button'
import DeployButton from './DeployButton'
@@ -15,6 +20,7 @@ export interface Props {
deployedURL?: string | null
deployStatus?: deployment_state | null
isInitializingDeploy?: boolean
+ onEnvsChange: (envs: { key: string, value: string }[]) => void
}
function Logs({
@@ -23,7 +29,43 @@ function Logs({
deployedURL,
deployStatus,
isInitializingDeploy,
+ onEnvsChange,
}: Props) {
+ const [envs, setEnvs] = useState<{ key: string, value: string }[]>([{ key: '', value: '' }])
+
+ const handleEnvKeyChange = useCallback((event: any, idx: number) => {
+ setEnvs(current => {
+ current[idx].key = event.target.value
+ const newEnvs = [...current]
+ onEnvsChange(newEnvs)
+ return newEnvs
+ })
+ }, [onEnvsChange])
+
+ const handleEnvValueChange = useCallback((event: any, idx: number) => {
+ setEnvs(current => {
+ current[idx].value = event.target.value
+ const newEnvs = [...current]
+ onEnvsChange(newEnvs)
+ return newEnvs
+ })
+ }, [onEnvsChange])
+
+ const addNewEnv = useCallback(() => {
+ setEnvs(current => {
+ const newEnvs = [...current, { key: '', value: '' }]
+ onEnvsChange(newEnvs)
+ return newEnvs
+ })
+ }, [onEnvsChange])
+
+ const deleteEnv = useCallback((delIdx: number) => {
+ setEnvs(current => {
+ const newEnvs = [...current.filter((_, idx) => idx !== delIdx)]
+ onEnvsChange(newEnvs)
+ return newEnvs
+ })
+ }, [onEnvsChange])
useEffect(function highlightCode() {
hljs.highlightAll()
@@ -92,6 +134,76 @@ function Logs({
/>
}
</div>
+ <div className="
+ max-w-full
+ flex
+ flex-col
+ border-b
+ p-4
+ space-y-4
+ ">
+ <Text
+ text="Envs"
+ size={Text.size.S2}
+ className="
+ uppercase
+ text-slate-400
+ font-semibold
+ "
+ />
+ {envs.map((env, idx) =>
+ <div
+ key={env.key}
+ className="
+ flex
+ items-center
+ justify-evenly
+ space-x-2
+ "
+ >
+ <input
+ className="
+ flex-1
+ p-1.5
+ text-xs
+ font-mono
+ rounded
+ border
+ outline-none
+ focus:border-green-600
+ "
+ placeholder="KEY"
+ value={env.key}
+ onChange={event => handleEnvKeyChange(event, idx)}
+ />
+ <input
+ className="
+ flex-1
+ p-1.5
+ text-xs
+ font-mono
+ rounded
+ border
+ outline-none
+ focus:border-green-600
+ "
+ placeholder="VALUE"
+ value={env.value}
+ onChange={event => handleEnvValueChange(event, idx)}
+ />
+ {envs.length > 1 &&
+ <Button
+ text="Delete"
+ onClick={() => deleteEnv(idx)}
+ />
+ }
+ </div>
+ )}
+ <Button
+ text="Add another"
+ onClick={addNewEnv}
+ />
+ </div>
<div className="
max-w-full
flex
diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx
index 93fa8f6e5..e698ee7f1 100644
--- a/components/Editor/index.tsx
+++ b/components/Editor/index.tsx
@@ -18,8 +18,8 @@ import Routes from './Routes'
// TODO: Prod API host
const apiHost = process.env.NODE_ENV === 'development'
- ? 'https://ai-api-service-7d2cl2hooq-uc.a.run.app'
- : 'http://0.0.0.0:5000'
+ ? 'http://0.0.0.0:5000'
+ : 'https://ai-api-service-7d2cl2hooq-uc.a.run.app'
export interface Props {
project: projects
@@ -29,6 +29,7 @@ async function handlePostGenerate(url: string, { arg }: {
arg: {
projectID: string,
route: Route,
+ envs: { key: string, value: string }[],
}
}) {
return await fetch(url, {
@@ -39,6 +40,7 @@ async function handlePostGenerate(url: string, { arg }: {
blocks: arg.route.blocks.map(b => b.prompt),
method: arg.route.method.toLowerCase(),
route: arg.route.route,
+ envs: arg.envs,
}),
headers: {
'Content-Type': 'application/json',
@@ -57,6 +59,7 @@ function Editor({ project }: Props) {
const changeRoute = store.use.changeRoute()
const addRoute = store.use.addRoute()
+ const [envs, setEnvs] = useState<{ key: string, value: string }[]>([{ key: '', value: '' }])
const [isInitializingDeploy, setIsInitializingDeploy] = useState(false)
const [selectedRouteID, setSelectedRouteID] = useState(() => routes.length > 0 ? routes[0].id : undefined)
const selectedRoute = routes.find(s => s.id === selectedRouteID)
@@ -92,6 +95,7 @@ function Editor({ project }: Props) {
await generate({
projectID: project.id,
route: selectedRoute,
+ envs,
})
}
@@ -214,6 +218,7 @@ function Editor({ project }: Props) {
logs={logs}
deploy={deploy}
deployedURL={deployment?.url}
+ onEnvsChange={(envs) => setEnvs(envs)}
/>
</>
}
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
index e44980340..2f2bb1a72 100644
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@ -17,7 +17,7 @@ function Sidebar({ children, side, className }: PropsWithChildren<Props>) {
className={clsx(
`
flex
- ${side === Side.Left ? 'w-[200px]' : 'w-[400px]'}
+ ${side === Side.Left ? 'w-[200px]' : 'w-[480px]'}
border-slate-200
bg-white
`,