Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix agent deployments page; Add agent deployment log page [WIP]

Tomas Valentaf508d43ac54e
diff --git a/components/AgentDeploymentLogList.tsx b/components/AgentDeploymentLogList.tsx
index dbc374010..1f24d2c4b 100644
--- a/components/AgentDeploymentLogList.tsx
+++ b/components/AgentDeploymentLogList.tsx
@@ -11,7 +11,7 @@ import {
LiteDeployment,
} from 'utils/agentLogs'
-import UploadTree from './UploadFiletree'
+import DeploymentTree from './DeploymentTree'
export interface Props {
deployments: LiteDeployment[]
@@ -45,7 +45,7 @@ function AgentDeploymentLogList({
return (
<main className="overflow-hidden flex flex-col max-h-full flex-1 border-white/5 border rounded-md">
- <header className="flex items-center justify-between p-4 sm:p-6 lg:px-8 min-h-[88px]">
+ <header className="flex items-center justify-between py-4 sm:px-6 lg:px-8 border-b border-b-white/5">
<h1 className="text-2xl font-semibold text-white">Agent Deployments</h1>
</header>
{sortedDeployments.length === 0 && (
@@ -57,7 +57,7 @@ function AgentDeploymentLogList({
)}
{sortedDeployments.length > 0 && (
- <div className="flex-col space-y-4 py-2 sm:px-4 lg:px-8 flex-1 flex pr-2 overflow-auto">
+ <div className="my-4 flex-col space-y-4 py-2 sm:px-4 lg:px-8 flex-1 flex pr-2 overflow-auto">
{sortedDeployments.map(deployment => (
<div
key={deployment.id}
@@ -81,27 +81,38 @@ function AgentDeploymentLogList({
openDeployments[deployment.id] && 'rotate-90',
)} />
</button>
- <span
+ <div
className={clsx(
'text-sm',
'font-semibold',
'text-gray-200',
+ 'flex',
+ 'space-x-2',
'whitespace-nowrap',
)}
// This prevents hydration warning for timestamps rendered via SSR
suppressHydrationWarning
>
- {deployment.enabled}
- <span>
+ <div className="flex items-center">
+ <div className={clsx({
+ 'text-green-400 bg-green-400/10': deployment.enabled, 'text-gray-500 bg-gray-100/10': !deployment.enabled
+ }, 'flex-none rounded-full flex p-1')}>
+ <div className="h-2 w-2 rounded-full bg-current" />
+ </div>
+ </div>
+ <span className="text-gray-200 font-normal">
{deployment.projects.name}
</span>
- </span>
+ <span className="text-gray-600 font-normal">
+ {deployment.projects.slug}
+ </span>
+ </div>
</div>
{openDeployments[deployment.id] && (
<div className="flex flex-col space-y-3 border-l border-white/5 pl-2 ml-[11px] flex-1">
- <UploadTree
- log={deployment}
+ <DeploymentTree
+ deployment={deployment}
/>
</div>
)}
diff --git a/components/AgentRunLogContent.tsx b/components/AgentRunLogContent.tsx
index 158b543fb..86b8d3bde 100644
--- a/components/AgentRunLogContent.tsx
+++ b/components/AgentRunLogContent.tsx
@@ -29,14 +29,13 @@ function AgentRunLogContent({
setSplitterSizes(sizes)
}, [setSplitterSizes])
- if (!log) return null
-
return (
- <main className="overflow-hidden flex flex-col max-h-full flex-1">
- <header className="flex items-center justify-between p-4 sm:p-6 lg:px-8 min-h-[88px]">
- <h1 className="text-2xl font-semibold text-white">Agent run logs</h1>
+ <main className="overflow-hidden flex flex-col max-h-full flex-1 border-white/5 border rounded-md">
+ <header className="flex items-center py-4 sm:px-6 lg:px-8 border-b border-b-white/5">
+ <h1 className="text-2xl font-semibold text-white">Agent Run Logs</h1>
+ <div className="text-base text-gray-400 self-center">Log</div>
</header>
- <div className="flex-1 flex space-x-2 items-start justify-start overflow-hidden">
+ <div className="flex-1 flex space-x-2 items-start justify-start overflow-hidden my-4">
<Splitter
gutterClassName={clsx(
'bg-gray-900 hover:bg-[#6366F1] transition-all delay-75 duration-[400ms] px-0.5 rounded-sm group',
diff --git a/components/DashboardHome.tsx b/components/DashboardHome.tsx
index 3c4c8757b..e474be16a 100644
--- a/components/DashboardHome.tsx
+++ b/components/DashboardHome.tsx
@@ -1,8 +1,10 @@
+import { useMemo } from 'react'
+import { useRouter } from 'next/router'
+
import AgentLogFilesList from 'components/AgentLogFilesList'
import { projects } from 'db/prisma'
-import { useRouter } from 'next/router'
-import { useMemo } from 'react'
import { LiteDeployment, LiteLogUpload } from 'utils/agentLogs'
+
import AgentDeploymentLogList from './AgentDeploymentLogList'
export interface Props {
diff --git a/components/DeploymentTree.tsx b/components/DeploymentTree.tsx
new file mode 100644
index 000000000..dfa5677f4
--- /dev/null
+++ b/components/DeploymentTree.tsx
@@ -0,0 +1,46 @@
+import { useCallback } from 'react'
+
+import Filesystem, { FileInfo } from 'components/Filesystem'
+import { LiteDeployment } from 'utils/agentLogs'
+import { FiletreeProvider } from 'hooks/useFiletree'
+import RunItem from './RunItem'
+
+export interface Props {
+ deployment: LiteDeployment
+}
+
+function DeploymentTree({
+ deployment,
+}: Props) {
+ const fetchLogDirContent = useCallback<(dirpath: string) => (FileInfo & { href?: any })[]>(_ => {
+ return deployment.log_files.map((f, i, a) => {
+ const slug = `${deployment.projects.slug}-${a.length - i - 1}`
+ return {
+ name: f.filename,
+ timestamp: f.created_at,
+ isDir: false,
+ id: slug,
+ href: {
+ pathname: '/logs/[slug]',
+ query: {
+ slug,
+ },
+ },
+ }
+ })
+ }, [deployment])
+
+ return (
+ <div className="flex flex-col items-start justify-start">
+ <FiletreeProvider>
+ <Filesystem
+ file={RunItem}
+ rootPath='/'
+ fetchContent={fetchLogDirContent}
+ />
+ </FiletreeProvider>
+ </div>
+ )
+}
+
+export default DeploymentTree
diff --git a/components/Feedback/FeedbackModal.tsx b/components/Feedback/FeedbackModal.tsx
index 1dd39d8ee..07480a5e1 100644
--- a/components/Feedback/FeedbackModal.tsx
+++ b/components/Feedback/FeedbackModal.tsx
@@ -53,7 +53,7 @@ function FeedbackModal({ isOpen, onClose, onSend }: Props) {
mt-1
border
z-50
- bg-transparent
+ bg-gray-900
border-white/5
w-[400px]
shadow-lg
diff --git a/components/Filesystem/index.tsx b/components/Filesystem/index.tsx
index 8cfd804ad..e6f9dd65e 100644
--- a/components/Filesystem/index.tsx
+++ b/components/Filesystem/index.tsx
@@ -8,6 +8,7 @@ import path from 'path-browserify'
import FilesystemPrimitive, {
DirNode,
FileNode,
+ FileProps,
NodeType,
SelectHandler,
useFilesystem,
@@ -27,8 +28,9 @@ export interface Props {
rootPath: string
ignore?: string[]
onFiletreeClick?: (path: string, type: NodeType) => void
- fetchContent: (dirpath: string) => (FileInfo & { id?: string })[]
+ fetchContent: (dirpath: string) => (FileInfo & { href?: any, id?: string, timestamp?: Date })[]
expandedPath?: string
+ file?: React.ComponentType<FileProps>
}
function Filesystem({
@@ -38,6 +40,7 @@ function Filesystem({
fetchContent,
onFiletreeClick,
expandedPath,
+ file,
}: Props) {
const fs = useFilesystem({ rootPath })
const fetchDirContent = useCallback(async (dirpath: string) => {
@@ -46,13 +49,9 @@ function Filesystem({
? new DirNode({ name: f.name })
: new FileNode({
name: f.name, metadata: {
- href: {
- pathname: '/',
- query: {
- view: 'logs',
- logFileID: f.id,
- }
- }
+ href: f.href,
+ id: f.id,
+ timestamp: f.timestamp,
}
})))
fs.add(dirpath, ns, ignore)
@@ -139,7 +138,7 @@ function Filesystem({
className,
)}
dir={Dir}
- file={File}
+ file={file || File}
fs={fs}
onSelect={handleNodeSelect}
/>
diff --git a/components/FilesystemTree.tsx b/components/FilesystemTree.tsx
index daf691ad4..7b351b599 100644
--- a/components/FilesystemTree.tsx
+++ b/components/FilesystemTree.tsx
@@ -44,6 +44,7 @@ export interface Props {
file?: React.ComponentType<FileProps>
dir?: React.ComponentType<DirProps>
onSelect?: SelectHandler
+ emptyPlaceholder?: string
}
function FilesystemTree({
@@ -52,6 +53,7 @@ function FilesystemTree({
file,
dir,
onSelect,
+ emptyPlaceholder = 'Empty directory',
}: Props) {
const nodeChildren = useChildren(fs, fs.root.path, true)
const UserFile = useMemo(() => (file ? memo(file) : () => null), [file])
@@ -73,7 +75,7 @@ function FilesystemTree({
<Text
className="text-center text-gray-500"
size={Text.size.S3}
- text="Empty directory"
+ text={emptyPlaceholder}
/>
}
diff --git a/components/Layout.tsx b/components/Layout.tsx
index 4436f7336..ca9b3d473 100644
--- a/components/Layout.tsx
+++ b/components/Layout.tsx
@@ -79,6 +79,16 @@ function Layout({ children }: PropsWithChildren) {
)
}
+ const view = process.env.NEXT_PUBLIC_SHOW_UPLOADED_LOGS === '1'
+ const showView = router.query['view'] === 'logs' ? 'logs' : view
+
+ const navigation = [
+ {
+ name: showView === 'logs' ? 'Agent Logs' : 'Agent Deployments',
+ icon: List,
+ },
+ ]
+
return (
<div className={clsx(
inter.variable,
diff --git a/components/RunItem.tsx b/components/RunItem.tsx
new file mode 100644
index 000000000..27d7ab949
--- /dev/null
+++ b/components/RunItem.tsx
@@ -0,0 +1,68 @@
+import clsx from 'clsx'
+import Link from 'next/link'
+
+import {
+ FileProps,
+} from '../filesystem'
+
+function RunItem({
+ name,
+ path: filePath,
+ onSelect,
+ isSelected,
+ metadata,
+}: FileProps) {
+ return (
+ <Link
+ href={metadata['href']}
+ className={
+ clsx(
+ 'px-2',
+ 'py-2',
+ 'rounded-md',
+ 'cursor-pointer',
+ 'flex',
+ 'items-center',
+ 'space-x-2',
+ 'bg-[#1F2437]',
+ 'border',
+ 'border-[#2A3441]',
+ 'hover:bg-[#262C40]',
+ 'w-full',
+ 'justify-between',
+ )}
+ >
+ <span className="flex space-x-2">
+ <span
+ className="
+ text-sm
+ whitespace-nowrap
+ text-gray-200
+ "
+ >
+ Run
+ </span >
+ <span
+ className="
+ text-sm
+ whitespace-nowrap
+ text-gray-500
+ "
+ >
+ {metadata['id']}
+ </span>
+ </span>
+ <span
+ className="
+ text-sm
+ whitespace-nowrap
+ text-gray-500
+ "
+ >
+ {metadata['timestamp'].toLocaleString()}
+ </span>
+ </Link>
+ )
+}
+
+export default RunItem
diff --git a/components/Sidebar/DashboardDesktopSidebar.tsx b/components/Sidebar/DashboardDesktopSidebar.tsx
index 271be9724..da989808e 100644
--- a/components/Sidebar/DashboardDesktopSidebar.tsx
+++ b/components/Sidebar/DashboardDesktopSidebar.tsx
@@ -14,12 +14,9 @@ function DashboardDesktopSidebar({
navigation,
}: Props) {
const router = useRouter()
- const view = router.query.view as string | undefined
- const isOnRunDetail = router.pathname.startsWith('/deployed/[projectID]/run/[runID]')
- const isOnLogDetail = router.pathname.startsWith('/log/[logFileID]')
return (
- <div className="hidden xl:self-stretch xl:z-50 xl:flex xl:w-48 xl:flex-col">
+ <div className="hidden xl:self-stretch xl:z-50 xl:flex xl:w-[220px] xl:flex-col">
<div className="flex grow flex-col gap-y-5 overflow-y-auto bg-gray-900 px-6 border border-white/5 rounded-md">
{/* Logo */}
{/* <div className="flex h-16 shrink-0 items-center">
@@ -39,9 +36,9 @@ function DashboardDesktopSidebar({
{navigation.map((item) => (
<li key={item.name}>
<Link
- href={`/?view=${item.view}`}
+ href={'/'}
className={clsx(
- item.view === view || (isOnRunDetail && item.view === 'runs') || (isOnLogDetail && item.view === 'logs')
+ router.pathname === '/'
? 'bg-[#1F2437] text-white'
: 'text-gray-400 hover:text-white hover:bg-[#1F2437]',
'group gap-x-3 rounded-md px-2 py-1 text-sm leading-6 font-semibold flex items-center'
diff --git a/components/Sidebar/DashboardMobileSidebar.tsx b/components/Sidebar/DashboardMobileSidebar.tsx
index f4391db1b..0591a7354 100644
--- a/components/Sidebar/DashboardMobileSidebar.tsx
+++ b/components/Sidebar/DashboardMobileSidebar.tsx
@@ -23,9 +23,6 @@ function DashboardMobileSidebar({
navigation,
}: Props) {
const router = useRouter()
- const view = router.query.view as string | undefined
- const isOnRunDetail = router.pathname.startsWith('/deployed/[projectID]/run/[runID]')
- const isOnLogDetail = router.pathname.startsWith('/log/[logFileID]')
return (
<Transition.Root show={isSidebarOpen} as={Fragment}>
@@ -86,9 +83,9 @@ function DashboardMobileSidebar({
{navigation.map((item) => (
<li key={item.name}>
<Link
- href={`/?view=${item.view}`}
+ href={'/'}
className={clsx(
- item.view === view || (isOnRunDetail && item.view === 'runs') || (isOnLogDetail && item.view === 'logs')
+ router.pathname === '/'
? 'bg-gray-800 text-white'
: 'text-gray-400 hover:text-white hover:bg-gray-800',
'group gap-x-3 rounded-md px-2 py-1 text-sm leading-6 font-semibold flex items-center'
@@ -119,9 +116,9 @@ function DashboardMobileSidebar({
</div>
</Dialog.Panel>
</Transition.Child>
- </div>
- </Dialog>
- </Transition.Root>
+ </div >
+ </Dialog >
+ </Transition.Root >
)
}
diff --git a/components/Sidebar/types.ts b/components/Sidebar/types.ts
index ba6d0480e..145fbdeb3 100644
--- a/components/Sidebar/types.ts
+++ b/components/Sidebar/types.ts
@@ -4,6 +4,5 @@ import {
export type Navigation = {
name: string
- view: string
icon: LucideIcon
}[]
\ No newline at end of file
diff --git a/components/UploadFiletree.tsx b/components/UploadFiletree.tsx
index 6d4e863a8..638dc573c 100644
--- a/components/UploadFiletree.tsx
+++ b/components/UploadFiletree.tsx
@@ -14,7 +14,7 @@ function UploadTree({
log: logUpload,
selectedLogFile,
}: Props) {
- const fetchLogDirContent = useCallback<(dirpath: string) => (FileInfo & { id?: string })[]>(dirpath => {
+ const fetchLogDirContent = useCallback<(dirpath: string) => (FileInfo & { href?: any })[]>(dirpath => {
const currentDir = dirpath.slice(1)
const childFiles = logUpload
.log_files
@@ -46,7 +46,13 @@ function UploadTree({
...childFiles.map(f => ({
name: f.filename,
isDir: false,
- id: f.id,
+ href: {
+ pathname: '/',
+ query: {
+ view: 'logs',
+ logFileID: f.id,
+ },
+ },
})),
...Array.from(childDirs).map(dir => ({
name: dir,
diff --git a/github/webhooks.ts b/github/webhooks.ts
index ff1b34f58..21c09c2d5 100644
--- a/github/webhooks.ts
+++ b/github/webhooks.ts
@@ -9,7 +9,13 @@ import { client as posthog } from 'utils/posthog'
import { TemplateID } from 'state/template'
import { DeploymentAuthData } from 'pages/api/agent'
-import { disableAgentDeployment, getDeploymentsForPR, getGHAccessToken, getPromptFromPR, triggerSmolDevAgentRun } from './pullRequest'
+import {
+ disableAgentDeployment,
+ getDeploymentsForPR,
+ getGHAccessToken,
+ getPromptFromPR,
+ triggerSmolDevAgentRun,
+} from './pullRequest'
import { getGHInstallationClient } from './installationClient'
export async function getGitHubWebhooksMiddleware() {
diff --git a/pages/api/agent/index.ts b/pages/api/agent/index.ts
index 89cdf2d1d..bc34700ff 100644
--- a/pages/api/agent/index.ts
+++ b/pages/api/agent/index.ts
@@ -118,7 +118,6 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
})
const appInfo = await appInfoPromise
-
const authData: DeploymentAuthData = {
github: {
app_name: appInfo.name,
@@ -136,10 +135,12 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
},
}
+ const slug = `smoldev-${owner}-${repo}-pr${pullNumber}`.toLowerCase()
const project = await prisma.projects.create({
data: {
id: nanoid(),
name: 'Smol developer',
+ slug,
deployments: {
create: {
auth: authData as any,
@@ -180,7 +181,6 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
config: modelConfig as any,
})
-
const deployment = project.deployments[0]
// We started the process of getting the token earlier but we await it only now because we need in now
const accessToken = await accessTokenPromise
diff --git a/pages/api/feedback/index.ts b/pages/api/feedback.ts
similarity index 100%
rename from pages/api/feedback/index.ts
rename to pages/api/feedback.ts
diff --git a/pages/index.tsx b/pages/index.tsx
index 73d803ae5..6e6a2b943 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -119,6 +119,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
deployments: {
include: {
log_files: {
+ orderBy: {
+ created_at: 'desc',
+ },
select: {
id: true,
relativePath: true,
@@ -129,6 +132,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
},
projects: {
select: {
+ slug: true,
name: true,
},
},
@@ -171,6 +175,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
deployments: {
include: {
log_files: {
+ orderBy: {
+ created_at: 'desc',
+ },
select: {
id: true,
relativePath: true,
@@ -181,6 +188,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
},
projects: {
select: {
+ slug: true,
name: true,
},
},
@@ -202,6 +210,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
deployments: {
include: {
log_files: {
+ orderBy: {
+ created_at: 'desc',
+ },
select: {
id: true,
relativePath: true,
@@ -212,6 +223,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
},
projects: {
select: {
+ slug: true,
name: true,
},
},
@@ -265,6 +277,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
deployments: {
include: {
log_files: {
+ orderBy: {
+ created_at: 'desc',
+ },
select: {
id: true,
relativePath: true,
@@ -275,6 +290,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
},
projects: {
select: {
+ slug: true,
name: true,
},
},
diff --git a/pages/logs/[logID].tsx b/pages/logs/[slug].tsx
similarity index 72%
rename from pages/logs/[logID].tsx
rename to pages/logs/[slug].tsx
index 2c44119a1..41c0d411f 100644
--- a/pages/logs/[logID].tsx
+++ b/pages/logs/[slug].tsx
@@ -8,12 +8,12 @@ import { LiteDeploymentLog } from 'utils/agentLogs'
import AgentRunLogContent from 'components/AgentRunLogContent'
interface PathProps extends ParsedUrlQuery {
- logID: string
+ slug: string
}
export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (ctx) => {
- const logID = ctx.params?.logID
- if (!logID) {
+ const slug = ctx.params?.slug
+ if (!slug) {
return {
redirect: {
destination: '/',
@@ -36,9 +36,24 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c
}
}
+ const splittedLogSlug = slug.split('-')
+ const projectSlug = splittedLogSlug.slice(0, splittedLogSlug.length - 1).join('-')
+ const logNumber = parseInt(splittedLogSlug.length > 1 ? splittedLogSlug[splittedLogSlug.length - 1] : '0')
+
const log = await prisma.log_files.findFirst({
+ orderBy: {
+ created_at: 'asc',
+ },
+ skip: logNumber,
where: {
- id: logID,
+ deployments: {
+ projects: {
+ slug: {
+ equals: projectSlug,
+ mode: 'insensitive',
+ }
+ }
+ },
projects: {
teams: {
users_teams: {
@@ -62,7 +77,6 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c
},
})
-
if (!log || !log.deployments) {
return {
notFound: true,
@@ -83,13 +97,9 @@ interface Props {
log: LiteDeploymentLog
}
-function ProjectPage({
- log,
-}: Props) {
+function ProjectPage({ log }: Props) {
return (
- <AgentRunLogContent
- log={log}
- />
+ <AgentRunLogContent log={log} />
)
}
diff --git a/utils/agentLogs.ts b/utils/agentLogs.ts
index 79adf3431..d5212ba64 100644
--- a/utils/agentLogs.ts
+++ b/utils/agentLogs.ts
@@ -6,9 +6,10 @@ export interface LiteDeploymentLog extends Omit<log_files, 'content'> {
}
export interface LiteDeployment extends deployments {
- log_files: Pick<log_files, 'id' | 'created_at' | 'log_upload_id' | 'relativePath' | 'filename'>[]
+ log_files: (Pick<log_files, 'id' | 'created_at' | 'log_upload_id' | 'relativePath' | 'filename'>)[]
projects: {
name: string
+ slug: string | null
}
}