Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Improve editor UI [WIP]

Tomas Valenta08fc447fbde8
diff --git a/api-service/database/database.py b/api-service/database/database.py
index 8c9223dad..a3427015a 100644
--- a/api-service/database/database.py
+++ b/api-service/database/database.py
@@ -1,7 +1,7 @@
from typing import List
from enum import Enum
-from codegen.agent.base import ThoughtLog, ToolLog
+from codegen.agent.parsing import ThoughtLog, ToolLog
from database.client import Client
from session.env import EnvVar
diff --git a/components/Editor/AddBlockButton.tsx b/components/Editor/AddBlockButton.tsx
deleted file mode 100644
index b148a8d63..000000000
--- a/components/Editor/AddBlockButton.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import clsx from 'clsx'
-import { Plus } from 'lucide-react'
-
-export interface Props {
- addBlock: () => void
-}
-
-function AddBlockButton({ addBlock }: Props) {
- return (
- <button
- onMouseDown={addBlock}
- type="submit"
- className={clsx(
- 'items-center',
- 'justify-center',
- 'transition-all',
- 'rounded-full',
- 'bg-green-800/60',
- 'hover:bg-green-800',
- 'text-white',
- 'py-1.5',
- 'px-1.5',
- )}
- >
- <Plus size="18px" />
- </button>
- )
-}
-
-export default AddBlockButton
diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx
deleted file mode 100644
index 90429456b..000000000
--- a/components/Editor/index.tsx
+++ /dev/null
@@ -1,187 +0,0 @@
-import useSWRMutation from 'swr/mutation'
-import { Fragment, useEffect, useState } from 'react'
-import { projects } from '@prisma/client'
-
-import { Route, methods, Method } from 'state/store'
-import { useStateStore } from 'state/StoreProvider'
-import Select from 'components/Select'
-import Text from 'components/Text'
-
-import ConnectionLine from './ConnectionLine'
-import RightSidebar from './RightSidebar'
-import Routes from './Routes'
-import Link from 'next/link'
-import RequestBodyEditor from './RequestBodyEditor'
-import Tiptap from 'components/Tiptap'
-
-const apiHost = process.env.NODE_ENV === 'development'
- ? 'http://0.0.0.0:5000'
- : 'https://ai-api-service-7d2cl2hooq-uc.a.run.app'
-
-export interface Props {
- project: projects
-}
-
-async function handlePostGenerate(url: string, { arg }: {
- arg: {
- projectID: string,
- route: Route,
- envs: { key: string, value: string }[],
- }
-}) {
- return await fetch(url, {
- method: 'POST',
- body: JSON.stringify({
- projectID: arg.projectID,
- routeID: arg.route.id,
- blocks: arg.route.blocks,
- method: arg.route.method.toLowerCase(),
- route: arg.route.route,
- envs: arg.envs,
- }),
- headers: {
- 'Content-Type': 'application/json',
- },
- }).then(r => r.json())
-}
-
-function Editor({ project }: Props) {
- const store = useStateStore()
-
- const routes = store.use.routes()
- const changeBlock = store.use.changeBlock()
- const deleteRoute = store.use.deleteRoute()
- const changeRoute = store.use.changeRoute()
- const addRoute = store.use.addRoute()
- const envs = store.use.envs()
-
- const [selectedRouteID, setSelectedRouteID] = useState(() => routes.length > 0 ? routes[0].id : undefined)
- const selectedRoute = routes.find(s => s.id === selectedRouteID)
- const [deploymentURL, setDeploymentURL] = useState<string>()
-
- useEffect(function selectDefaultRoute() {
- if (selectedRoute?.id || routes.length === 0) return
- setSelectedRouteID(routes[0].id)
- }, [routes, selectedRoute?.id])
-
- function handleDeleteRoute(id: string) {
- deleteRoute(id)
- setSelectedRouteID(r => {
- if (r === id) {
- return routes.length > 0 ? routes[0].id : undefined
- }
- })
- }
-
- const [focusedBlock, setFocusedBlock] = useState({ index: 0 })
- const {
- trigger: generate,
- isMutating: isDeployRequestRunning,
- } = useSWRMutation(`${apiHost}/generate`, handlePostGenerate)
-
- async function deploy() {
- if (!selectedRoute) return
- await generate({
- projectID: project.id,
- route: selectedRoute,
- envs,
- })
- }
-
- return (
- <div className="
- flex
- flex-row
- overflow-hidden
- flex-1
- ">
- <Routes
- routes={routes}
- selectRoute={setSelectedRouteID}
- selectedRouteID={selectedRoute?.id}
- deleteRoute={handleDeleteRoute}
- addRoute={addRoute}
- />
- {selectedRoute &&
- <>
- <div className="
- flex
- flex-1
- p-8
- flex-col
- items-center
- overflow-auto
- scroller
- relative
- ">
- <div className="flex items-center space-x-2">
- <Text
- text="Incoming"
- className='font-bold'
- />
- <Select
- direction="left"
- selectedValue={{ key: selectedRoute.method, title: selectedRoute.method.toUpperCase() }}
- values={methods.map(m => ({ key: m, title: m.toUpperCase() }))}
- onChange={m => changeRoute(selectedRoute.id, { method: m.key as Method })}
- />
- <Text
- text="Request"
- className='font-bold'
- />
- </div>
- <div className="
- flex
- flex-col
- items-center
- transition-all
- ">
- {selectedRoute.blocks.map((b, i) =>
- <Fragment
- key={b.id}
- >
- <ConnectionLine className='h-4' />
- <RequestBodyEditor
- block={b}
- onChange={(b) => {
- changeBlock(selectedRoute.id, i, b)
- }}
- index={i}
- focus={focusedBlock}
- onFocus={() => { setFocusedBlock({ index: i }) }}
- />
- </Fragment>
- )}
- <Tiptap />
- </div>
- <ConnectionLine className='min-h-[16px]' />
- {deploymentURL &&
- <Link
- href={deploymentURL}
- className="
- mt-6
- underline
- "
- target="_blank" rel="noopener noreferrer"
- >
- <Text
- text={deploymentURL.substring('https://'.length)}
- size={Text.size.S3}
- />
- </Link>
- }
- </div>
- <RightSidebar
- project={project}
- route={selectedRoute}
- isDeployRequestRunning={isDeployRequestRunning}
- deploy={deploy}
- setDeployURL={setDeploymentURL}
- />
- </>
- }
- </div>
- )
-}
-
-export default Editor
diff --git a/components/Tiptap.tsx b/components/ProjectBoard/RouteEditor/PromptEditor.tsx
similarity index 100%
rename from components/Tiptap.tsx
rename to components/ProjectBoard/RouteEditor/PromptEditor.tsx
diff --git a/components/Editor/RequestBodyEditor.tsx b/components/ProjectBoard/RouteEditor/RequestBodyEditor.tsx
similarity index 100%
rename from components/Editor/RequestBodyEditor.tsx
rename to components/ProjectBoard/RouteEditor/RequestBodyEditor.tsx
diff --git a/components/Editor/Routes.tsx b/components/ProjectBoard/RouteEditor/Routes.tsx
similarity index 100%
rename from components/Editor/Routes.tsx
rename to components/ProjectBoard/RouteEditor/Routes.tsx
diff --git a/components/ProjectBoard/RouteEditor/index.tsx b/components/ProjectBoard/RouteEditor/index.tsx
new file mode 100644
index 000000000..b8b81ebfd
--- /dev/null
+++ b/components/ProjectBoard/RouteEditor/index.tsx
@@ -0,0 +1,109 @@
+import Select from 'components/Select'
+import { Link } from 'lucide-react'
+import { Fragment } from 'react'
+import { methods, Method } from 'state/store'
+import ConnectionLine from '../Sidebar/Logs/ConnectionLine'
+import Tiptap from './PromptEditor'
+import RequestBodyEditor from './RequestBodyEditor'
+import Text from 'components/Text'
+
+export interface Props {
+
+}
+
+function RouteEditor() {
+
+
+ useEffect(function selectDefaultRoute() {
+ if (selectedRoute?.id || routes.length === 0) return
+ setSelectedRouteID(routes[0].id)
+ }, [routes, selectedRoute?.id])
+
+ function handleDeleteRoute(id: string) {
+ deleteRoute(id)
+ setSelectedRouteID(r => {
+ if (r === id) {
+ return routes.length > 0 ? routes[0].id : undefined
+ }
+ })
+ }
+
+ // <Routes
+ // routes={routes}
+ // selectRoute={setSelectedRouteID}
+ // selectedRouteID={selectedRoute?.id}
+ // deleteRoute={handleDeleteRoute}
+ // addRoute={addRoute}
+ // />
+ return (
+ <div className="
+ flex
+ flex-1
+ p-8
+ flex-col
+ items-center
+ overflow-auto
+ scroller
+ relative
+ ">
+ <div className="flex items-center space-x-2">
+ <Text
+ text="Incoming"
+ className='font-bold'
+ />
+ <Select
+ direction="left"
+ selectedValue={{ key: selectedRoute.method, title: selectedRoute.method.toUpperCase() }}
+ values={methods.map(m => ({ key: m, title: m.toUpperCase() }))}
+ onChange={m => changeRoute(selectedRoute.id, { method: m.key as Method })}
+ />
+ <Text
+ text="Request"
+ className='font-bold'
+ />
+ </div>
+ <div className="
+ flex
+ flex-col
+ items-center
+ transition-all
+ ">
+ {selectedRoute.blocks.map((b, i) =>
+ <Fragment
+ key={b.id}
+ >
+ <ConnectionLine className='h-4' />
+ <RequestBodyEditor
+ block={b}
+ onChange={(b) => {
+ changeBlock(selectedRoute.id, i, b)
+ }}
+ index={i}
+ focus={focusedBlock}
+ onFocus={() => { setFocusedBlock({ index: i }) }}
+ />
+ </Fragment>
+ )}
+ <Tiptap />
+ </div>
+ <ConnectionLine className='min-h-[16px]' />
+ {deploymentURL &&
+ <Link
+ href={deploymentURL}
+ className="
+ mt-6
+ underline
+ "
+ target="_blank" rel="noopener noreferrer"
+ >
+ <Text
+ text={deploymentURL.substring('https://'.length)}
+ size={Text.size.S3}
+ />
+ </Link>
+ }
+ </div>
+ )
+}
+
+export default RouteEditor
diff --git a/components/Editor/RightSidebar/DeployButton.tsx b/components/ProjectBoard/Sidebar/DeployButton.tsx
similarity index 100%
rename from components/Editor/RightSidebar/DeployButton.tsx
rename to components/ProjectBoard/Sidebar/DeployButton.tsx
diff --git a/components/Editor/RightSidebar/Envs.tsx b/components/ProjectBoard/Sidebar/Envs.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Envs.tsx
rename to components/ProjectBoard/Sidebar/Envs.tsx
diff --git a/components/Editor/ConnectionLine.tsx b/components/ProjectBoard/Sidebar/Logs/ConnectionLine.tsx
similarity index 100%
rename from components/Editor/ConnectionLine.tsx
rename to components/ProjectBoard/Sidebar/Logs/ConnectionLine.tsx
diff --git a/components/Editor/RightSidebar/Logs/LogEntry.tsx b/components/ProjectBoard/Sidebar/Logs/LogEntry.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/LogEntry.tsx
rename to components/ProjectBoard/Sidebar/Logs/LogEntry.tsx
diff --git a/components/Editor/RightSidebar/Logs/LogStream.tsx b/components/ProjectBoard/Sidebar/Logs/LogStream.tsx
similarity index 95%
rename from components/Editor/RightSidebar/Logs/LogStream.tsx
rename to components/ProjectBoard/Sidebar/Logs/LogStream.tsx
index 171d6afb7..e5056a3a6 100644
--- a/components/Editor/RightSidebar/Logs/LogStream.tsx
+++ b/components/ProjectBoard/Sidebar/Logs/LogStream.tsx
@@ -1,9 +1,9 @@
import { Fragment, useEffect, useRef } from 'react'
import ReactMarkdown from 'react-markdown'
-import ConnectionLine from 'components/Editor/ConnectionLine'
import { Log, } from 'db/types'
+import ConnectionLine from './ConnectionLine'
import LogEntry from './LogEntry'
export interface Props {
diff --git a/components/Editor/RightSidebar/Logs/Thought.tsx b/components/ProjectBoard/Sidebar/Logs/Thought.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Thought.tsx
rename to components/ProjectBoard/Sidebar/Logs/Thought.tsx
diff --git a/components/Editor/RightSidebar/Logs/Tool/AskHuman.tsx b/components/ProjectBoard/Sidebar/Logs/Tool/AskHuman.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Tool/AskHuman.tsx
rename to components/ProjectBoard/Sidebar/Logs/Tool/AskHuman.tsx
diff --git a/components/Editor/RightSidebar/Logs/Tool/Base.tsx b/components/ProjectBoard/Sidebar/Logs/Tool/Base.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Tool/Base.tsx
rename to components/ProjectBoard/Sidebar/Logs/Tool/Base.tsx
diff --git a/components/Editor/RightSidebar/Logs/Tool/CurlServer.tsx b/components/ProjectBoard/Sidebar/Logs/Tool/CurlServer.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Tool/CurlServer.tsx
rename to components/ProjectBoard/Sidebar/Logs/Tool/CurlServer.tsx
diff --git a/components/Editor/RightSidebar/Logs/Tool/InstallNPMDeps.tsx b/components/ProjectBoard/Sidebar/Logs/Tool/InstallNPMDeps.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Tool/InstallNPMDeps.tsx
rename to components/ProjectBoard/Sidebar/Logs/Tool/InstallNPMDeps.tsx
diff --git a/components/Editor/RightSidebar/Logs/Tool/RunCode.tsx b/components/ProjectBoard/Sidebar/Logs/Tool/RunCode.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Tool/RunCode.tsx
rename to components/ProjectBoard/Sidebar/Logs/Tool/RunCode.tsx
diff --git a/components/Editor/RightSidebar/Logs/Tool/index.tsx b/components/ProjectBoard/Sidebar/Logs/Tool/index.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/Tool/index.tsx
rename to components/ProjectBoard/Sidebar/Logs/Tool/index.tsx
diff --git a/components/Editor/RightSidebar/Logs/index.tsx b/components/ProjectBoard/Sidebar/Logs/index.tsx
similarity index 100%
rename from components/Editor/RightSidebar/Logs/index.tsx
rename to components/ProjectBoard/Sidebar/Logs/index.tsx
diff --git a/components/Editor/RightSidebar/index.tsx b/components/ProjectBoard/Sidebar/index.tsx
similarity index 65%
rename from components/Editor/RightSidebar/index.tsx
rename to components/ProjectBoard/Sidebar/index.tsx
index fe54196a6..dc5288bd0 100644
--- a/components/Editor/RightSidebar/index.tsx
+++ b/components/ProjectBoard/Sidebar/index.tsx
@@ -1,8 +1,8 @@
import { projects } from '@prisma/client'
import Link from 'next/link'
import { useEffect, useState } from 'react'
+import clsx from 'clsx'
-import Sidebar from 'components/Sidebar'
import Text from 'components/Text'
import { Route } from 'state/store'
import { useLatestDeployment } from 'hooks/useLatestDeployment'
@@ -20,15 +20,60 @@ export interface Props {
route?: Route
}
-function RightSidebar({
+const apiHost = process.env.NODE_ENV === 'development'
+ ? 'http://0.0.0.0:5000'
+ : 'https://ai-api-service-7d2cl2hooq-uc.a.run.app'
+
+ async function handlePostGenerate(url: string, { arg }: {
+ arg: {
+ projectID: string,
+ route: Route,
+ envs: { key: string, value: string }[],
+ }
+ }) {
+ return await fetch(url, {
+ method: 'POST',
+ body: JSON.stringify({
+ projectID: arg.projectID,
+ routeID: arg.route.id,
+ blocks: arg.route.blocks,
+ method: arg.route.method.toLowerCase(),
+ route: arg.route.route,
+ envs: arg.envs,
+ }),
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ }).then(r => r.json())
+ }
+
+
+function Sidebar({
isDeployRequestRunning,
- deploy,
project,
route,
setDeployURL,
}: Props) {
const deployment = useLatestDeployment(project, route)
+ const {
+ trigger: generate,
+ isMutating: isDeployRequestRunning,
+ } = useSWRMutation(`${apiHost}/generate`, handlePostGenerate)
+
+ const store = useStateStore()
+ const envs = store.use.envs()
+
+
+ async function deploy() {
+ if (!selectedRoute) return
+ await generate({
+ projectID: project.id,
+ route: selectedRoute,
+ envs,
+ })
+ }
+
useEffect(function updateURL() {
setDeployURL(deployment?.url ? deployment.url : undefined)
}, [deployment?.url, setDeployURL])
@@ -46,13 +91,18 @@ function RightSidebar({
}, [isDeployRequestRunning])
return (
- <Sidebar
- side={Sidebar.side.Right}
- className="
- flex
- flex-col
- min-h-0
- "
+ <div
+ className={clsx(
+ `
+ flex
+ border-slate-200
+ bg-white
+ border-l
+ flex
+ flex-col
+ min-h-0
+ `,
+ )}
>
<div
className="
@@ -113,8 +163,8 @@ function RightSidebar({
<Logs
deployment={deployment}
/>
- </Sidebar>
+ </div>
)
}
-export default RightSidebar
+export default Sidebar
diff --git a/components/ProjectBoard/index.tsx b/components/ProjectBoard/index.tsx
new file mode 100644
index 000000000..87df69e9f
--- /dev/null
+++ b/components/ProjectBoard/index.tsx
@@ -0,0 +1,59 @@
+import useSWRMutation from 'swr/mutation'
+import { Fragment, useEffect, useState } from 'react'
+import { projects } from '@prisma/client'
+import Link from 'next/link'
+import Splitter, { SplitDirection, GutterTheme } from '@devbookhq/splitter'
+
+import { Route, methods, Method } from 'state/store'
+import { useStateStore } from 'state/StoreProvider'
+import Select from 'components/Select'
+import Text from 'components/Text'
+
+import ConnectionLine from './Sidebar/Logs/ConnectionLine'
+import Sidebar from './Sidebar'
+import Routes from './RouteEditor/Routes'
+import RequestBodyEditor from './RouteEditor/RequestBodyEditor'
+import Tiptap from './RouteEditor/PromptEditor'
+
+
+export interface Props {
+ project: projects
+}
+
+
+function Editor({ project }: Props) {
+ const store = useStateStore()
+
+ const routes = store.use.routes()
+ const envs = store.use.envs()
+
+ const [selectedRouteID, setSelectedRouteID] = useState(() => routes.length > 0 ? routes[0].id : undefined)
+ const selectedRoute = routes.find(s => s.id === selectedRouteID)
+
+
+ return (
+ <div className="
+ flex
+ flex-row
+ overflow-hidden
+ flex-1
+ ">
+ <Splitter
+ gutterTheme={GutterTheme.Light}
+
+ >
+ <div>EDITOR</div>
+ {/* <RouteEditor /> */}
+ <Sidebar
+ project={project}
+ route={selectedRoute}
+ isDeployRequestRunning={isDeployRequestRunning}
+ deploy={deploy}
+ setDeployURL={setDeploymentURL}
+ />
+ </Splitter>
+ </div>
+ )
+}
+
+export default Editor
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
deleted file mode 100644
index 6764dff58..000000000
--- a/components/Sidebar.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import clsx from 'clsx'
-import { PropsWithChildren } from 'react'
-
-export enum Side {
- Left,
- Right,
-}
-
-export interface Props {
- side: Side
- className?: string
-}
-
-function Sidebar({ children, side, className }: PropsWithChildren<Props>) {
- return (
- <div
- className={clsx(
- `
- flex
- ${side === Side.Left ? 'w-[200px]' : 'w-[650px]'}
- border-slate-200
- bg-white
- `,
- {
- 'border-r': side === Side.Left,
- 'border-l': side === Side.Right,
- },
- className,
- )}
- >
- {children}
- </div>
- )
-}
-
-Sidebar.side = Side
-
-export default Sidebar
diff --git a/package.json b/package.json
index d8b404887..e86c75440 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"postinstall": "yarn db:generate"
},
"dependencies": {
+ "@devbookhq/splitter": "^1.4.0",
"@prisma/client": "^4.11.0",
"@supabase/auth-helpers-nextjs": "^0.5.5",
"@supabase/auth-helpers-react": "^0.3.1",
diff --git a/pages/[projectID].tsx b/pages/[projectID].tsx
index 5e9be2b30..c196ad11b 100644
--- a/pages/[projectID].tsx
+++ b/pages/[projectID].tsx
@@ -4,7 +4,7 @@ import { useSupabaseClient } from '@supabase/auth-helpers-react'
import type { ParsedUrlQuery } from 'querystring'
import { prisma, projects } from 'db/prisma'
-import Editor from 'components/Editor'
+import Editor from 'components/ProjectBoard'
import { StoreProvider } from 'state/StoreProvider'
import { Database } from 'db/supabase'
diff --git a/yarn.lock b/yarn.lock
index 54037c956..6d90cdd2e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -9,6 +9,13 @@
dependencies:
regenerator-runtime "^0.13.11"
+"@devbookhq/splitter@^1.4.0":
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/@devbookhq/splitter/-/splitter-1.4.0.tgz#50592d080b91277c6ff94a923fc56df61bf2f438"
+ integrity sha512-/Wfh8YqbV9o0Dm2tNOshulZKGmN1ObcUYU0qsc8h1OlcvX62YGcINWRH9zZN70zGK7EflDkyiNPR5u7wOyY0Vg==
+ dependencies:
+ react-is "^17.0.2"
+
"@eslint/eslintrc@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.0.0.tgz#943309d8697c52fc82c076e90c1c74fbbe69dbff"
@@ -3516,6 +3523,11 @@ react-is@^16.13.1, react-is@^16.7.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
+react-is@^17.0.2:
+ version "17.0.2"
+ resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
+ integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
+
react-is@^18.0.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"