Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
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.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/ConnectionLine.tsxrename to components/Editor/Sidebar/Agent/ConnectionLine.tsxdiff --git a/components/Editor/Sidebar/Logs/LogEntry.tsx b/components/Editor/Sidebar/Agent/LogEntry.tsxsimilarity index 84%rename from components/Editor/Sidebar/Logs/LogEntry.tsxrename to components/Editor/Sidebar/Agent/LogEntry.tsxindex 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-lgp-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() &&<Thoughtlog={log}/>diff --git a/components/Editor/Sidebar/Logs/LogStream.tsx b/components/Editor/Sidebar/Agent/LogStream.tsxsimilarity index 55%rename from components/Editor/Sidebar/Logs/LogStream.tsxrename to components/Editor/Sidebar/Agent/LogStream.tsxindex 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 (<divclassName="@@ -48,6 +72,8 @@ function LogStream({py-4flexflex-col+ bg-slate-50+ space-y-4px-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}`}+ /><LogEntryonAnswer={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.tsxsimilarity index 50%rename from components/Editor/Sidebar/Logs/Thought.tsxrename to components/Editor/Sidebar/Agent/Thought.tsxindex 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-smtext-slate-500">- {content}+ {log.content}</div>)}diff --git a/components/Editor/Sidebar/Logs/Tool/AskHuman.tsx b/components/Editor/Sidebar/Agent/Tool/AskHuman.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/AskHuman.tsxrename to components/Editor/Sidebar/Agent/Tool/AskHuman.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/Base.tsx b/components/Editor/Sidebar/Agent/Tool/Base.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/Base.tsxrename to components/Editor/Sidebar/Agent/Tool/Base.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/Curl.tsx b/components/Editor/Sidebar/Agent/Tool/Curl.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/Curl.tsxrename to components/Editor/Sidebar/Agent/Tool/Curl.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/InstallNPMDeps.tsx b/components/Editor/Sidebar/Agent/Tool/InstallNPMDeps.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/InstallNPMDeps.tsxrename to components/Editor/Sidebar/Agent/Tool/InstallNPMDeps.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx b/components/Editor/Sidebar/Agent/Tool/LetHumanChoose.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsxrename to components/Editor/Sidebar/Agent/Tool/LetHumanChoose.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/RunSavedCode.tsx b/components/Editor/Sidebar/Agent/Tool/RunSavedCode.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/RunSavedCode.tsxrename to components/Editor/Sidebar/Agent/Tool/RunSavedCode.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/WriteCode.tsx b/components/Editor/Sidebar/Agent/Tool/WriteCode.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/WriteCode.tsxrename to components/Editor/Sidebar/Agent/Tool/WriteCode.tsxdiff --git a/components/Editor/Sidebar/Logs/Tool/index.tsx b/components/Editor/Sidebar/Agent/Tool/index.tsxsimilarity index 100%rename from components/Editor/Sidebar/Logs/Tool/index.tsxrename to components/Editor/Sidebar/Agent/Tool/index.tsxdiff --git a/components/Editor/Sidebar/Logs/index.tsx b/components/Editor/Sidebar/Agent/index.tsxsimilarity index 84%rename from components/Editor/Sidebar/Logs/index.tsxrename to components/Editor/Sidebar/Agent/index.tsxindex 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?: deploymentsisDeployRequestRunning?: 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-fullflexflex-col+ bg-slate-50overflow-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 Agentdiff --git a/components/Editor/Sidebar/Context.tsx b/components/Editor/Sidebar/Context.tsxnew file mode 100644index 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 Contextdiff --git a/components/Editor/Sidebar/DeployButton.tsx b/components/Editor/Sidebar/RunButton.tsxsimilarity index 98%rename from components/Editor/Sidebar/DeployButton.tsxrename to components/Editor/Sidebar/RunButton.tsxindex 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 | undcase deployment_state.finished:default:return {- text: 'Deploy',+ text: 'Run',icon: null,}}diff --git a/components/Editor/Sidebar/index.tsx b/components/Editor/Sidebar/index.tsxindex 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: projectsroute?: 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="flexpx-4py-2@@ -115,59 +125,62 @@ function Sidebar({border-bflex-col"- >- <div- className="+ >+ <div+ className="flexflex-1items-centerjustify-between"- >- <Text- text="Latest Deployment"- className="+ >+ <Text+ text="Latest Deployment"+ className="font-semibolduppercasetext-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 Sidebardiff --git a/components/Editor/index.tsx b/components/Editor/index.tsxindex 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.tsxindex f43e51f62..9aec9f641 100644--- a/components/Tabs/index.tsx+++ b/components/Tabs/index.tsx@@ -114,16 +114,14 @@ function Tab({items-centerjustify-centerh-8- px-2- lg:px-4z-20bg-transparent- text-sm+ text-xscursor-pointerselect-nonetransition-colorsborder-green-800- w-[80px]+ px-2`,{'text-slate-400': hoveredTabIndex !== i && selectedTabIndex !== i,@@ -149,7 +147,6 @@ function Tab({left-0rounded-mdbg-green-400- transition-[width]"style={hoverStyles}/>diff --git a/pages/_app.tsx b/pages/_app.tsxindex 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>