Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix empty thought logs; Improve Agent logs; Add Menu sidebar [WIP]

Tomas Valenta87fe07e658b2
diff --git a/components/Editor/Sidebar/Logs/ConnectionLine.tsx b/components/Editor/Sidebar/Agent/ConnectionLine.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/ConnectionLine.tsx
rename to components/Editor/Sidebar/Agent/ConnectionLine.tsx
diff --git a/components/Editor/Sidebar/Logs/LogEntry.tsx b/components/Editor/Sidebar/Agent/LogEntry.tsx
similarity index 84%
rename from components/Editor/Sidebar/Logs/LogEntry.tsx
rename to components/Editor/Sidebar/Agent/LogEntry.tsx
index f54d8cf15..7b96277f1 100644
--- a/components/Editor/Sidebar/Logs/LogEntry.tsx
+++ b/components/Editor/Sidebar/Agent/LogEntry.tsx
@@ -15,12 +15,14 @@ export interface Props {
function LogEntry({ log, onAnswer }: Props) {
return (
<div className={`
- rounded-lg
p-3
- border
+ border-l-4
+ rounded
+ shadow-sm
+ bg-white
${log.type === LogType.Tool ? 'border-green-300' : 'border-blue-300'}
`}>
- {log.type === 'thought' &&
+ {log.type === 'thought' && log.content.trim() &&
<Thought
log={log}
/>
diff --git a/components/Editor/Sidebar/Logs/LogStream.tsx b/components/Editor/Sidebar/Agent/LogStream.tsx
similarity index 55%
rename from components/Editor/Sidebar/Logs/LogStream.tsx
rename to components/Editor/Sidebar/Agent/LogStream.tsx
index 2de41f9b0..a95d017b0 100644
--- a/components/Editor/Sidebar/Logs/LogStream.tsx
+++ b/components/Editor/Sidebar/Agent/LogStream.tsx
@@ -1,10 +1,11 @@
-import { Fragment, useEffect, useRef } from 'react'
+import { useEffect, useMemo, useRef } from 'react'
import ReactMarkdown from 'react-markdown'
-import { Log, ToolName, } from 'db/types'
+import { Log, LogType, ToolName, } from 'db/types'
+import { notEmpty } from 'utils/notEmpty'
-import ConnectionLine from './ConnectionLine'
import LogEntry from './LogEntry'
+import Text from 'components/Text'
export interface Props {
logs?: Log[]
@@ -35,6 +36,29 @@ function LogStream({
ref.current.scrollIntoView({ behavior: 'auto' })
}, [logs, isDeployRequestRunning])
+ const trimmedLogs = useMemo(() => {
+ return logs
+ ?.map(l => {
+ switch (l.type) {
+ case LogType.Thought:
+ const content = l.content
+ .replaceAll('\nAction:', '')
+ .replaceAll('Action:', '')
+ .replaceAll('Thought:', '')
+ .trim()
+ return content
+ ? {
+ ...l,
+ content,
+ }
+ : undefined
+ default:
+ return l
+ }
+ })
+ .filter(notEmpty)
+ }, [logs])
+
return (
<div
className="
@@ -48,6 +72,8 @@ function LogStream({
py-4
flex
flex-col
+ bg-slate-50
+ space-y-4
px-2
">
{rawLogs &&
@@ -55,18 +81,21 @@ function LogStream({
{rawLogs}
</ReactMarkdown>
}
- {logs && logs.map((l, i, a) =>
- <Fragment key={i}>
+ {trimmedLogs && trimmedLogs.map((l, i) =>
+ <div
+ key={i}
+ className="flex flex-col space-y-1"
+ >
+ <Text
+ size={Text.size.S3}
+ className="text-slate-400"
+ text={`Step ${i + 1}`}
+ />
<LogEntry
onAnswer={onAnswer}
log={l}
/>
- {i < a.length - 1 &&
- <div className="flex items-center flex-col">
- <ConnectionLine className="h-4" />
- </div>
- }
- </Fragment>
+ </div>
)}
<div ref={ref} />
</div>
diff --git a/components/Editor/Sidebar/Logs/Thought.tsx b/components/Editor/Sidebar/Agent/Thought.tsx
similarity index 50%
rename from components/Editor/Sidebar/Logs/Thought.tsx
rename to components/Editor/Sidebar/Agent/Thought.tsx
index cf98be321..e958d4879 100644
--- a/components/Editor/Sidebar/Logs/Thought.tsx
+++ b/components/Editor/Sidebar/Agent/Thought.tsx
@@ -1,5 +1,3 @@
-import { useMemo } from 'react'
-
import { ThoughtLog } from 'db/types'
export interface Props {
@@ -9,14 +7,6 @@ export interface Props {
function Thought({
log,
}: Props) {
- const content = useMemo(() => {
- return log.content
- .replaceAll('\nAction:', '')
- .replaceAll('Action:', '')
- .replaceAll('Thought:', '')
- .trim()
- }, [log.content])
-
return (
<div className="
leading-[24px]
@@ -25,7 +15,7 @@ function Thought({
text-sm
text-slate-500
">
- {content}
+ {log.content}
</div>
)
}
diff --git a/components/Editor/Sidebar/Logs/Tool/AskHuman.tsx b/components/Editor/Sidebar/Agent/Tool/AskHuman.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/AskHuman.tsx
rename to components/Editor/Sidebar/Agent/Tool/AskHuman.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/Base.tsx b/components/Editor/Sidebar/Agent/Tool/Base.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/Base.tsx
rename to components/Editor/Sidebar/Agent/Tool/Base.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/Curl.tsx b/components/Editor/Sidebar/Agent/Tool/Curl.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/Curl.tsx
rename to components/Editor/Sidebar/Agent/Tool/Curl.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/InstallNPMDeps.tsx b/components/Editor/Sidebar/Agent/Tool/InstallNPMDeps.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/InstallNPMDeps.tsx
rename to components/Editor/Sidebar/Agent/Tool/InstallNPMDeps.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx b/components/Editor/Sidebar/Agent/Tool/LetHumanChoose.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx
rename to components/Editor/Sidebar/Agent/Tool/LetHumanChoose.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/RunSavedCode.tsx b/components/Editor/Sidebar/Agent/Tool/RunSavedCode.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/RunSavedCode.tsx
rename to components/Editor/Sidebar/Agent/Tool/RunSavedCode.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/WriteCode.tsx b/components/Editor/Sidebar/Agent/Tool/WriteCode.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/WriteCode.tsx
rename to components/Editor/Sidebar/Agent/Tool/WriteCode.tsx
diff --git a/components/Editor/Sidebar/Logs/Tool/index.tsx b/components/Editor/Sidebar/Agent/Tool/index.tsx
similarity index 100%
rename from components/Editor/Sidebar/Logs/Tool/index.tsx
rename to components/Editor/Sidebar/Agent/Tool/index.tsx
diff --git a/components/Editor/Sidebar/Logs/index.tsx b/components/Editor/Sidebar/Agent/index.tsx
similarity index 84%
rename from components/Editor/Sidebar/Logs/index.tsx
rename to components/Editor/Sidebar/Agent/index.tsx
index a6cbb86c3..1e3e38086 100644
--- a/components/Editor/Sidebar/Logs/index.tsx
+++ b/components/Editor/Sidebar/Agent/index.tsx
@@ -1,6 +1,6 @@
import { useState } from 'react'
// import hljs from 'highlight.js'
-import { deployments } from '@prisma/client'
+import { deployment_state, deployments } from '@prisma/client'
import Text from 'components/Text'
import { useTabs } from 'components/Tabs/useTabs'
@@ -12,6 +12,7 @@ import { useSupabaseClient } from '@supabase/auth-helpers-react'
import { Database, Json } from 'db/supabase'
import { deploymentsTable } from 'db/tables'
import produce from 'immer'
+import RunButton from '../RunButton'
const tabsProps = {
tabs: [
@@ -29,11 +30,16 @@ const tabsProps = {
export interface Props {
deployment?: deployments
isDeployRequestRunning?: boolean
+ deploy: () => void
+ deployStatus?: deployment_state | null
+ isInitializingDeploy?: boolean
}
-function Logs({
+function Agent({
deployment,
isDeployRequestRunning,
+ deploy,
+ isInitializingDeploy,
}: Props) {
const [selectedTab, setSelectedTab] = useState(0)
const client = useSupabaseClient<Database>()
@@ -67,6 +73,7 @@ function Logs({
max-w-full
flex
flex-col
+ bg-slate-50
overflow-hidden
">
<div className="
@@ -95,6 +102,12 @@ function Logs({
setSelectedTab={setSelectedTab}
/>
)}
+ <RunButton
+ deploy={deploy}
+ isDeployRequestRunning={isDeployRequestRunning}
+ isInitializingDeploy={isInitializingDeploy}
+ deployStatus={deployment?.state}
+ />
</div>
{selectedTab === 0 &&
<LogStream
@@ -113,4 +126,4 @@ function Logs({
)
}
-export default Logs
+export default Agent
diff --git a/components/Editor/Sidebar/Context.tsx b/components/Editor/Sidebar/Context.tsx
new file mode 100644
index 000000000..ceb24f9ed
--- /dev/null
+++ b/components/Editor/Sidebar/Context.tsx
@@ -0,0 +1,45 @@
+import Text from 'components/Text'
+import { useStateStore } from 'state/StoreProvider'
+
+export interface Props {
+}
+
+function Context({
+
+}: Props) {
+ const [selector] = useStateStore()
+
+
+ return (
+ <div className="
+ max-w-full
+ flex
+ flex-col
+ bg-slate-50
+ overflow-hidden
+ ">
+ <div className="
+ flex
+ items-center
+ justify-between
+ border-b
+ py-3.5
+ pr-4
+ ">
+ <Text
+ text="Context"
+ size={Text.size.S2}
+ className="
+ uppercase
+ text-slate-400
+ font-semibold
+ px-4
+ "
+ />
+
+ </div>
+ </div>
+ )
+}
+
+export default Context
diff --git a/components/Editor/Sidebar/DeployButton.tsx b/components/Editor/Sidebar/RunButton.tsx
similarity index 98%
rename from components/Editor/Sidebar/DeployButton.tsx
rename to components/Editor/Sidebar/RunButton.tsx
index 317d4cd5c..c317f61f7 100644
--- a/components/Editor/Sidebar/DeployButton.tsx
+++ b/components/Editor/Sidebar/RunButton.tsx
@@ -39,7 +39,7 @@ function getDeploymentRepresentation(deployStatus: deployment_state | null | und
case deployment_state.finished:
default:
return {
- text: 'Deploy',
+ text: 'Run',
icon: null,
}
}
diff --git a/components/Editor/Sidebar/index.tsx b/components/Editor/Sidebar/index.tsx
index cb808cde7..efdc48c6c 100644
--- a/components/Editor/Sidebar/index.tsx
+++ b/components/Editor/Sidebar/index.tsx
@@ -10,13 +10,21 @@ import { useLatestDeployment } from 'hooks/useLatestDeployment'
import { useStateStore } from 'state/StoreProvider'
import { html2markdown } from 'editor/schema'
-import DeployButton from './DeployButton'
-import Logs from './Logs'
+import Agent from './Agent'
import Envs from './Envs'
+import Context from './Context'
export interface Props {
project: projects
route?: Route
+ activeMenuSection?: MenuSection
+}
+
+export enum MenuSection {
+ Agent = 'Agent',
+ Envs = 'Envs',
+ Context = 'Context',
+ Deploy = 'Deploy',
}
const apiHost = process.env.NODE_ENV === 'development'
@@ -63,6 +71,7 @@ async function handlePostGenerate(url: string, { arg }: {
function Sidebar({
project,
route,
+ activeMenuSection,
}: Props) {
const deployment = useLatestDeployment(project, route)
@@ -106,8 +115,9 @@ function Sidebar({
`,
)}
>
- <div
- className="
+ {activeMenuSection === MenuSection.Deploy &&
+ <div
+ className="
flex
px-4
py-2
@@ -115,59 +125,62 @@ function Sidebar({
border-b
flex-col
"
- >
- <div
- className="
+ >
+ <div
+ className="
flex
flex-1
items-center
justify-between
"
- >
- <Text
- text="Latest Deployment"
- className="
+ >
+ <Text
+ text="Latest Deployment"
+ className="
font-semibold
uppercase
text-slate-400
"
- size={Text.size.S2}
- />
- <DeployButton
- deploy={deploy}
- isDeployRequestRunning={isDeployRequestRunning}
- isInitializingDeploy={isInitializingDeploy}
- deployStatus={deployment?.state}
- />
- </div>
- {deployment?.url &&
- <Link
- href={deployment.url}
- className="underline"
- target="_blank"
- rel="noopener noreferrer"
- >
+ size={Text.size.S2}
+ />
+ </div>
+ {deployment?.url &&
+ <Link
+ href={deployment.url}
+ className="underline"
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ <Text
+ size={Text.size.S3}
+ text={deployment.url.substring('https://'.length)}
+ />
+ </Link>
+ }
+ {!deployment?.url &&
<Text
+ text="No deployment URL found"
size={Text.size.S3}
- text={deployment.url.substring('https://'.length)}
+ className="text-slate-400"
/>
- </Link>
- }
- {!deployment?.url &&
- <Text
- text="No deployment URL found"
- size={Text.size.S3}
- className="text-slate-400"
- />
- }
- </div>
- <Envs />
- <Logs
- deployment={deployment}
- isDeployRequestRunning={isDeployRequestRunning}
- />
+ }
+ </div>
+ }
+ {activeMenuSection === MenuSection.Context &&
+ <Context />
+ }
+ {activeMenuSection === MenuSection.Envs &&
+ <Envs />
+ }
+ {activeMenuSection === MenuSection.Agent &&
+ <Agent
+ deploy={deploy}
+ isDeployRequestRunning={isDeployRequestRunning}
+ isInitializingDeploy={isInitializingDeploy}
+ deployment={deployment}
+ />
+ }
</div>
)
}
-
export default Sidebar
diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx
index f38342aac..08f5672f7 100644
--- a/components/Editor/index.tsx
+++ b/components/Editor/index.tsx
@@ -6,7 +6,7 @@ import { useLocalStorage } from 'usehooks-ts'
import { useStateStore } from 'state/StoreProvider'
import Routes from './Routes'
-import Sidebar from './Sidebar'
+import Sidebar, { MenuSection } from './Sidebar'
import RouteEditor from './RouteEditor'
export interface Props {
@@ -17,6 +17,8 @@ function Editor({ project }: Props) {
const [selectors] = useStateStore()
const ref = useRef<HTMLDivElement | null>(null)
+ const [selectedMenuSection, setSelectedMenuSection] = useState(MenuSection.Agent)
+
// TODO: Handle editor state differently so we don't rerender this component on each editor edit.
const routes = selectors.use.routes()
const deleteRoute = selectors.use.deleteRoute()
@@ -87,10 +89,32 @@ function Editor({ project }: Props) {
/>
</div>
<Sidebar
+ activeMenuSection={selectedMenuSection}
project={project}
route={selectedRoute}
/>
</Splitter>
+ <div className="
+ w-16
+ flex
+ py-4
+ text-sm
+ border-l
+ bg-white
+ flex-col
+ space-y-2
+ items-center
+ "
+ >
+ {Object.values(MenuSection).map(m =>
+ <button
+ key={m}
+ onClick={() => setSelectedMenuSection(m)}
+ >
+ {m.toString()}
+ </button>
+ )}
+ </div>
</div>
)
}
diff --git a/components/Tabs/index.tsx b/components/Tabs/index.tsx
index f43e51f62..9aec9f641 100644
--- a/components/Tabs/index.tsx
+++ b/components/Tabs/index.tsx
@@ -114,16 +114,14 @@ function Tab({
items-center
justify-center
h-8
- px-2
- lg:px-4
z-20
bg-transparent
- text-sm
+ text-xs
cursor-pointer
select-none
transition-colors
border-green-800
- w-[80px]
+ px-2
`,
{
'text-slate-400': hoveredTabIndex !== i && selectedTabIndex !== i,
@@ -149,7 +147,6 @@ function Tab({
left-0
rounded-md
bg-green-400
- transition-[width]
"
style={hoverStyles}
/>
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 53b611936..d93182fe5 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -5,7 +5,6 @@ import { SessionContextProvider, Session } from '@supabase/auth-helpers-react'
import { useState } from 'react'
import { useRouter } from 'next/router'
import clsx from 'clsx'
-import { Toaster } from 'sonner'
import { projects } from '@prisma/client'
import 'styles/global.css'
@@ -43,7 +42,6 @@ function App({ Component, pageProps }: AppProps<{ initialSession: Session, proje
{!isSignIn && !isSignUp &&
<Header project={pageProps.project} />
}
- <Toaster />
<Component {...pageProps} />
</SessionContextProvider>
</main>