Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add smol dev deployments UI [WIP]

Tomas Valenta7dd9d2b0446a
diff --git a/components/DashboardHome.tsx b/components/DashboardHome.tsx
index 0453b6ddd..55b32797c 100644
--- a/components/DashboardHome.tsx
+++ b/components/DashboardHome.tsx
@@ -1,42 +1,21 @@
-import { useRouter } from 'next/router'
-import { usePostHog } from 'posthog-js/react'
-import { useSupabaseClient } from '@supabase/auth-helpers-react'
-
-import AgentList from 'components/AgentList'
-import AgentRunsList from 'components/AgentRunsList'
import AgentLogFilesList from 'components/AgentLogFilesList'
import { deployments, projects } from 'db/prisma'
+import { useMemo } from 'react'
import { LiteLogUpload } from 'utils/agentLogs'
export interface Props {
projects: (projects & { log_uploads: LiteLogUpload[], deployments: deployments[] })[]
defaultProjectID: string
+ view: 'deployments' | 'uploads'
}
function DashboardHome({
projects,
defaultProjectID,
+ view,
}: Props) {
- const supabaseClient = useSupabaseClient()
- const router = useRouter()
- const posthog = usePostHog()
-
- const view = router.query.view as string | undefined
- const selectedAgentInstanceID = router.query.projectID as string | undefined
-
- async function signOut() {
- await supabaseClient.auth.signOut()
- posthog?.reset(true)
- router.push('/sign')
- }
-
- function selectAgent(e: any, projectID: string) {
- e.preventDefault()
- posthog?.capture('selected deployed agent', { projectID: projectID })
- router.push(`/?view=runs&projectID=${projectID}`, undefined, { shallow: true })
- }
- const projectsWithDeployments = projects
+ const projectsWithDeployments = useMemo(() => projects
.filter(p => {
if (p.deployments.length !== 1) return false
@@ -48,30 +27,24 @@ function DashboardHome({
.map(p => ({
project: p,
deployment: p.deployments[0],
- }))
+ })), [projects])
return (
<>
- {view === 'deployed' ? (
- <AgentList
- agents={projectsWithDeployments}
- onSelectAgent={selectAgent}
- />
- ) : view === 'runs' ? (
- <AgentRunsList
- allDeployedAgents={projectsWithDeployments}
- initialSelectedAgentID={selectedAgentInstanceID}
+ {view === 'deployments' &&
+ <AgentLogFilesList
+ logUploads={projects.flatMap(p => p.deployments)}
+ defaultProjectID={defaultProjectID}
/>
- ) : view === 'logs' ? (
+ }
+ {view === 'uploads' &&
<AgentLogFilesList
logUploads={projects.flatMap(p => p.log_uploads)}
defaultProjectID={defaultProjectID}
/>
- ) : (
- <span>404</span>
- )}
+ }
</>
)
}
-export default DashboardHome
\ No newline at end of file
+export default DashboardHome
diff --git a/components/Layout.tsx b/components/Layout.tsx
index 44c0d076b..f96433be4 100644
--- a/components/Layout.tsx
+++ b/components/Layout.tsx
@@ -48,8 +48,6 @@ function Layout({ children }: PropsWithChildren) {
const router = useRouter()
const [isSidebarOpen, setIsSidebarOpen] = useState(false)
- const view = router.query.view as string | undefined
-
async function signOut() {
await supabaseClient.auth.signOut()
posthog?.reset(true)
@@ -109,7 +107,11 @@ function Layout({ children }: PropsWithChildren) {
<div className="xl:pl-48 flex flex-col flex-1 max-h-full">
{/* Mobile menu icon */}
<div className="xl:hidden sticky top-0 z-40 flex justify-between h-16 shrink-0 items-center gap-x-6 border-b border-white/5 bg-gray-900 px-4 shadow-sm sm:px-6 lg:px-8">
- <button type="button" className="-m-2.5 p-2.5 text-white xl:hidden" onClick={() => setIsSidebarOpen(true)}>
+ <button
+ type="button"
+ className="-m-2.5 p-2.5 text-white xl:hidden"
+ onClick={() => setIsSidebarOpen(true)}
+ >
<span className="sr-only">Open sidebar</span>
<Menu aria-hidden="true" />
</button>
diff --git a/pages/index.tsx b/pages/index.tsx
index 405bb8fb5..f05e68879 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -11,6 +11,7 @@ import { AgentNextActionLog, AgentPromptLogs, LiteLogUpload } from 'utils/agentL
export interface Props {
projects: (projects & { log_uploads: LiteLogUpload[], deployments: deployments[] })[]
defaultProjectID: string
+ view: 'deployments' | 'uploads'
}
function getLastTwoDirsAndFile(fullPath: string): string {
@@ -23,7 +24,7 @@ function getLastTwoDirsAndFile(fullPath: string): string {
return path.join(lastTwoDirs, fileName)
}
-function formatLogFileContent(logFile: Omit<log_files, 'project_id' | 'type' | 'size' | 'last_modified' | 'deployment_id'>) {
+function formatLogFileContent(logFile: log_files) {
const relativePath = getLastTwoDirsAndFile(logFile.relativePath)
if (logFile.filename.includes('user_input')) {
@@ -64,17 +65,8 @@ function formatLogFileContent(logFile: Omit<log_files, 'project_id' | 'type' | '
}
export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
- // Select the 'deployed' view by default.
- const view = ctx.query['view'] as string
const defaultNewTeamID = process.env.DEFAULT_NEW_TEAM_ID as string | undefined
- if (!view) {
- return {
- redirect: {
- destination: '/?view=logs',
- permanent: false,
- }
- }
- }
+ const showUploadedLogs = process.env.NEXT_PUBLIC_SHOW_UPLOADED_LOGS === '1'
const supabase = createServerSupabaseClient(ctx, serverCreds)
const {
@@ -107,20 +99,13 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
},
include: {
log_uploads: {
- select: {
- display_name: true,
- id: true,
- created_at: true,
- log_files: {
- select: {
- id: true,
- log_upload_id: true,
- created_at: true,
- filename: true,
- relativePath: true,
- content: true,
- },
- },
+ include: {
+ log_files: true,
+ },
+ },
+ deployments: {
+ include: {
+ log_files: true,
},
},
},
@@ -157,6 +142,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
log_files: true,
},
},
+ deployments: {
+ include: {
+ log_files: true,
+ },
+ },
},
},
},
@@ -170,6 +160,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
log_files: true,
},
},
+ deployments: {
+ include: {
+ log_files: true,
+ },
+ },
},
},
},
@@ -215,17 +210,27 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
log_files: true,
},
},
+ deployments: {
+ include: {
+ log_files: true,
+ },
+ },
},
})
+
+
+
return {
props: {
+ view: showUploadedLogs ? 'uploads' : 'deployments',
defaultProjectID: defaultProject.id,
- projects: [defaultProject]
+ projects: [
+ defaultProject,
+ ...teams.flatMap(t => t.projects),
+ ]
.map(p => ({
...p,
- // Don't send any deployments to the client but keep the props structure so we don't have to change the component now.
- deployments: [],
log_uploads: p
.log_uploads
.map<LiteLogUpload>(u => ({
@@ -237,11 +242,10 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
}
}
-function Home({ projects, defaultProjectID }: Props) {
-
-
+function Home({ projects, defaultProjectID, view }: Props) {
return (
<DashboardHome
+ view={view}
defaultProjectID={defaultProjectID}
projects={projects}
/>
diff --git a/utils/agentLogs.ts b/utils/agentLogs.ts
index 9c934c7dc..ddef5c611 100644
--- a/utils/agentLogs.ts
+++ b/utils/agentLogs.ts
@@ -1,10 +1,10 @@
import { log_files, log_uploads } from 'db/prisma'
-export interface LiteLogFile extends Omit<log_files, 'project_id' | 'type' | 'size' | 'content' | 'last_modified' | 'deployment_id'> {
+export interface LiteLogFile extends Omit<log_files, 'content'> {
content: AgentPromptLogs | AgentNextActionLog | string
}
-export interface LiteLogUpload extends Omit<log_uploads, 'log_files' | 'project_id'> {
+export interface LiteLogUpload extends Omit<log_uploads, 'log_files'> {
log_files: LiteLogFile[]
}