Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix deploying route

Tomas Valenta9e53a87ce461
diff --git a/components/Editor/Routes.tsx b/components/Editor/Routes.tsx
new file mode 100644
index 000000000..9b96caa62
--- /dev/null
+++ b/components/Editor/Routes.tsx
@@ -0,0 +1,82 @@
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import useSWRMutation from 'swr/mutation'
+
+import { Route } from 'state/store'
+import Button from 'components/Button'
+
+interface PostRouteBody {
+ projectID: string
+}
+
+async function handlePostRoute(url: string, { arg }: { arg: PostRouteBody }) {
+ return await fetch(url, {
+ method: 'POST',
+ body: JSON.stringify(arg),
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ }).then(r => r.json())
+}
+
+export interface Props {
+ routes: Route[]
+ projectID: string
+}
+
+function Routes({ routes, projectID }: Props) {
+ const router = useRouter()
+
+ const {
+ trigger: createRoute,
+ } = useSWRMutation('/api/route', handlePostRoute)
+
+ async function handleCreateRoute() {
+ await createRoute({
+ projectID,
+ })
+ }
+
+ return (
+ <div>
+ <Button
+ text="New route"
+ onClick={handleCreateRoute}
+ />
+ <div className="
+ flex
+ flex-col
+ overflow-y-auto
+ text-xs
+ leading-4
+ break-words
+ w-[250px]
+ whitespace-normal
+ space-y-2
+ p-4
+ ">
+ {routes.map(r => {
+ return <Link
+ key={r.id}
+ href={{
+ pathname: router.pathname,
+ query: {
+ ...router.query,
+ route: r.id,
+ }
+ }}
+ shallow
+ >
+ <div className="flex space-x-2 font-bold">
+ {r.method}
+ {r.route}
+ </div>
+ </Link>
+ }
+ )}
+ </div>
+ </div>
+ )
+}
+
+export default Routes
diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx
index ab06ea530..4ec4e5986 100644
--- a/components/Editor/index.tsx
+++ b/components/Editor/index.tsx
@@ -2,8 +2,9 @@ import useSWRMutation from 'swr/mutation'
import { Fragment, useState } from 'react'
import Hotkeys from 'react-hot-keys'
import { projects } from '@prisma/client'
+import { useRouter } from 'next/router'
-import { Block, methods, Method } from 'state/store'
+import { Route, methods, Method } from 'state/store'
import { useStateStore } from 'state/StoreProvider'
import Select from 'components/Select'
import Button from 'components/Button'
@@ -15,7 +16,6 @@ import ConnectionLine from './ConnectionLine'
import AddBlockButton from './AddBlockButton'
import Logs from './Logs'
import Routes from './Routes'
-import { useRouter } from 'next/router'
// TODO: Prod API host
const apiHost = process.env.NODE_ENV === 'development' ?
@@ -30,19 +30,18 @@ export interface Props {
async function handlePostGenerate(url: string, { arg }: {
arg: {
- projectID: string
- blocks: Block[]
- method: Method
- route: string
- },
+ projectID: string,
+ route: Route,
+ }
}) {
return await fetch(url, {
method: 'POST',
body: JSON.stringify({
projectID: arg.projectID,
- blocks: arg.blocks.map(b => b.prompt),
- method: arg.method.toLowerCase(),
- route: arg.route,
+ routeID: arg.route.id,
+ blocks: arg.route.blocks.map(b => b.prompt),
+ method: arg.route.method.toLowerCase(),
+ route: arg.route.route,
}),
headers: {
'Content-Type': 'application/json',
@@ -63,6 +62,7 @@ function Editor({ project }: Props) {
const selectedRoute =
routes.find(r => r.id === router.query.route) ||
(routes.length > 0 ? routes[0] : undefined)
+
const deployment = useLatestDeployment(project, selectedRoute)
const logs = deployment?.logs as Log[] | undefined
@@ -73,10 +73,8 @@ function Editor({ project }: Props) {
if (!selectedRoute) return
const response = await generate({
- blocks: selectedRoute.blocks,
projectID: project.id,
- method: selectedRoute.method,
- route: selectedRoute.route,
+ route: selectedRoute,
})
console.log(response.code)
console.log(response.host)