Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add dashboard [WIP]

Tomas Valenta9783630e4c63
diff --git a/api-service/deployment/manager.py b/api-service/deployment/manager.py
index 07783ae0b..c56ce3162 100644
--- a/api-service/deployment/manager.py
+++ b/api-service/deployment/manager.py
@@ -1,8 +1,10 @@
import os
-from re import L
-from agent.output.work_queue import WorkQueue
+import uuid
import aiohttp
import json
+from datetime import datetime, timedelta, date
+
+from agent.output.work_queue import WorkQueue
from typing import Any, Callable, Coroutine, List
from abc import abstractmethod, ABC
@@ -70,6 +72,9 @@ class AgentEvents:
)
async def add_log(self, log: Any):
+ date = datetime.now()
+ log["timestamp"] = str(date)
+ log["id"] = str(uuid.uuid4())
self.logs.append(log)
self.log_que.schedule(self.logs)
diff --git a/components/AgentDetail.tsx b/components/AgentDetail.tsx
index e9f48ff58..3811d7ae2 100644
--- a/components/AgentDetail.tsx
+++ b/components/AgentDetail.tsx
@@ -1,251 +1,166 @@
-import { Fragment, useState } from 'react'
-import { Dialog, Transition } from '@headlessui/react'
-// import {
-// XMarkIcon,
-// } from '@heroicons/react/24/outline'
-import { ChevronRightIcon } from '@heroicons/react/20/solid'
+import { ChatBubbleLeftEllipsisIcon, TagIcon, UserCircleIcon } from '@heroicons/react/20/solid'
import clsx from 'clsx'
-import { Grid } from 'lucide-react'
import { projects } from 'db/prisma'
import useDeployment from 'hooks/useDeployment'
-const navigation = [
- {
- name: 'Agents', href: '#', icon: Grid, current: false,
- },
-]
-const statuses = {
- offline: 'text-gray-500 bg-gray-100/10',
- online: 'text-green-400 bg-green-400/10',
- error: 'text-rose-400 bg-rose-400/10',
+export interface AgentLogBase {
+ id: string
+ message: string
+ timestamp: string
+ type: 'info' | 'tool' | 'playground' | 'model'
+ properties: {}
}
-const environments = {
- Preview: 'text-gray-400 bg-gray-400/10 ring-gray-400/20',
- Production: 'text-indigo-400 bg-indigo-400/10 ring-indigo-400/30',
+
+export interface AgentToolLog extends AgentLogBase {
+ type: 'tool'
+ properties: {
+ tool: 'filesystem' | 'git'
+ }
+}
+
+export interface AgentModelLog extends AgentLogBase {
+ type: 'model'
+ properties: {
+ model: 'gpt-4'
+ prompt: string
+ result: string
+ }
+}
+
+export interface AgentPlaygroundLog extends AgentLogBase {
+ type: 'playground'
+ properties: {
+ playground: string
+ }
}
-const deployments = [
- {
- id: 1,
- href: '#',
- projectName: 'smol-ai/developer',
- teamName: 'Smol Agent',
- status: 'offline',
- statusText: 'Initiated 1m 32s ago',
- description: 'Deployed to GitHub repository ValentaTomas/test',
- environment: 'PR#11',
- },
- {
- id: 2,
- href: '#',
- projectName: 'smol-ai/developer',
- teamName: 'Smol Agent',
- status: 'online',
- statusText: 'Initiated 1m 32s ago',
- description: 'Deployed to GitHub repository ValentaTomas/test',
- environment: 'PR#12',
- },
-]
export interface Props {
project: projects
}
-export default function AgentDetail({ project }: Props) {
- const [sidebarOpen, setSidebarOpen] = useState(false)
+export function AgentDetail({ project }: Props) {
const deployment = useDeployment(project)
-
return (
- <div>
- <Transition.Root show={sidebarOpen} as={Fragment}>
- <Dialog as="div" className="relative z-50 xl:hidden" onClose={setSidebarOpen}>
- <Transition.Child
- as={Fragment}
- enter="transition-opacity ease-linear duration-300"
- enterFrom="opacity-0"
- enterTo="opacity-100"
- leave="transition-opacity ease-linear duration-300"
- leaveFrom="opacity-100"
- leaveTo="opacity-0"
- >
- <div className="fixed inset-0 bg-gray-900/80" />
- </Transition.Child>
-
- <div className="fixed inset-0 flex">
- <Transition.Child
- as={Fragment}
- enter="transition ease-in-out duration-300 transform"
- enterFrom="-translate-x-full"
- enterTo="translate-x-0"
- leave="transition ease-in-out duration-300 transform"
- leaveFrom="translate-x-0"
- leaveTo="-translate-x-full"
- >
- <Dialog.Panel className="relative mr-16 flex w-full max-w-xs flex-1">
- <Transition.Child
- as={Fragment}
- enter="ease-in-out duration-300"
- enterFrom="opacity-0"
- enterTo="opacity-100"
- leave="ease-in-out duration-300"
- leaveFrom="opacity-100"
- leaveTo="opacity-0"
- >
- <div className="absolute left-full top-0 flex w-16 justify-center pt-5">
- <button type="button" className="-m-2.5 p-2.5" onClick={() => setSidebarOpen(false)}>
- <span className="sr-only">Close sidebar</span>
- {/* <XMarkIcon className="h-6 w-6 text-white" aria-hidden="true" /> */}
- </button>
- </div>
- </Transition.Child>
- {/* Sidebar component, swap this element with another sidebar if you like */}
- <div className="flex grow flex-col gap-y-5 overflow-y-auto bg-gray-900 px-6 ring-1 ring-white/10">
- <div className="flex h-16 shrink-0 items-center">
- <img
- className="h-8 w-auto"
- src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=500"
- alt="Your Company"
- />
- </div>
- <nav className="flex flex-1 flex-col">
- <ul role="list" className="flex flex-1 flex-col gap-y-7">
- <li>
- <ul role="list" className="-mx-2 space-y-1">
- {navigation.map((item) => (
- <li key={item.name}>
+ <div className="flex flex-1 items-center justify-center">
+ <div className="flow-root">
+ <ul role="list" className="-mb-8">
+ {(deployment?.logs as unknown as AgentLogBase[])
+ ?.slice()
+ .reverse()
+ .map((log, idx, logs) => (
+ <li key={log.timestamp}>
+ <div className="relative pb-8">
+ {idx !== logs.length - 1 ? (
+ <span className="absolute left-5 top-5 -ml-px h-full w-0.5 bg-gray-200" aria-hidden="true" />
+ ) : null}
+ <div className="relative flex items-start space-x-3">
+ {log.type === 'info' ? (
+ <>
+ <div className="relative">
+ <span className="absolute -bottom-0.5 -right-1 rounded-tl bg-white px-0.5 py-px">
+ <ChatBubbleLeftEllipsisIcon className="h-5 w-5 text-gray-400" aria-hidden="true" />
+ </span>
+ </div>
+ <div className="min-w-0 flex-1">
+ <div>
+ <div className="text-sm">
+ <a className="font-medium text-gray-900">
+ {log.type}
+ </a>
+ </div>
+ </div>
+ <div className="mt-2 text-sm text-gray-700">
+ <p>{log.message}</p>
+ </div>
+ </div>
+ </>
+ ) : log.type === 'model' ? (
+ <>
+ <div>
+ <div className="relative px-1">
+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 ring-8 ring-white">
+ <UserCircleIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
+ </div>
+ </div>
+ </div>
+ <div className="min-w-0 flex-1 py-1.5">
+ <div className="text-sm text-gray-500">
+ <a className="font-medium text-gray-900">
+ {log.type}
+ </a>{' '}
+ assigned{' '}
+ <a className="font-medium text-gray-900">
+ {/* {log.assigned.name} */}
+ </a>{' '}
+ <span className="whitespace-nowrap">{log.message}</span>
+ </div>
+ </div>
+ </>
+ ) : log.type === 'playground' ? (
+ <>
+ <div>
+ <div className="relative px-1">
+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 ring-8 ring-white">
+ <TagIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
+ </div>
+ </div>
+ </div>
+ <div className="min-w-0 flex-1 py-0">
+ <div className="text-sm leading-8 text-gray-500">
+ <span className="mr-0.5">
+ <a className="font-medium text-gray-900">
+ {log.type}
+ </a>{' '}
+ </span>{' '}
+ <span className="mr-0.5">
<a
- href={item.href}
- className={clsx(
- item.current
- ? 'bg-gray-800 text-white'
- : 'text-gray-400 hover:text-white hover:bg-gray-800',
- 'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
- )}
+ className="inline-flex items-center gap-x-1.5 rounded-full px-2 py-1 text-xs font-medium text-gray-900 ring-1 ring-inset ring-gray-200"
>
- <item.icon className="h-6 w-6 shrink-0" aria-hidden="true" />
- {item.name}
- </a>
- </li>
- ))}
- </ul>
- </li>
- <li className="-mx-6 mt-auto">
- <a
- href="#"
- className="flex items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-white hover:bg-gray-800"
- >
- <span className="sr-only">Your profile</span>
- <span aria-hidden="true">Tom Cook</span>
- </a>
- </li>
- </ul>
- </nav>
- </div>
- </Dialog.Panel>
- </Transition.Child>
- </div>
- </Dialog>
- </Transition.Root>
-
- {/* Static sidebar for desktop */}
- <div className="hidden xl:fixed xl:inset-y-0 xl:z-50 xl:flex xl:w-72 xl:flex-col">
- {/* Sidebar component, swap this element with another sidebar if you like */}
- <div className="flex grow flex-col gap-y-5 overflow-y-auto bg-black/10 px-6 ring-1 ring-white/5">
- <div className="flex h-16 shrink-0 items-center">
- <img
- className="h-8 w-auto"
- src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=500"
- alt="Your Company"
- />
- </div>
- <nav className="flex flex-1 flex-col">
- <ul role="list" className="flex flex-1 flex-col gap-y-7">
- <li>
- <ul role="list" className="-mx-2 space-y-1">
- {navigation.map((item) => (
- <li key={item.name}>
- <a
- href={item.href}
- className={clsx(
- item.current
- ? 'bg-gray-800 text-white'
- : 'text-gray-400 hover:text-white hover:bg-gray-800',
- 'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
- )}
- >
- <item.icon className="h-6 w-6 shrink-0" aria-hidden="true" />
- {item.name}
- </a>
- </li>
- ))}
- </ul>
- </li>
- <li className="-mx-6 mt-auto">
- <a
- href="#"
- className="flex items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-white hover:bg-gray-800"
- >
- <img
- className="h-8 w-8 rounded-full bg-gray-800"
- src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
- alt=""
- />
- <span className="sr-only">Your profile</span>
- <span aria-hidden="true">Tom Cook</span>
- </a>
- </li>
- </ul>
- </nav>
- </div>
- </div>
-
- <div className="xl:pl-72">
- <main className="">
- <header className="flex items-center justify-between border-b border-white/5 p-4 sm:p-6 lg:px-8">
- <h1 className="text-base font-semibold leading-7 text-white">Agents</h1>
- </header>
-
- {/* Deployment list */}
- <ul role="list" className="divide-y divide-white/5">
- {deployments.map((deployment) => (
- <li key={deployment.id} className="relative flex items-center space-x-4 p-4 sm:px-6 lg:px-8">
- <div className="min-w-0 flex-auto">
- <div className="flex items-center gap-x-3">
- <div className={clsx(statuses[deployment.status as keyof typeof statuses], 'flex-none rounded-full p-1')}>
- <div className="h-2 w-2 rounded-full bg-current" />
- </div>
- <h2 className="min-w-0 text-sm font-semibold leading-6 text-white">
- <a href={deployment.href} className="flex gap-x-2">
- <span className="truncate">{deployment.teamName}</span>
- <span className="text-gray-400">-</span>
- <span className="whitespace-nowrap">{deployment.projectName}</span>
- <span className="absolute inset-0" />
- </a>
- </h2>
- </div>
- <div className="mt-3 flex items-center gap-x-2.5 text-xs leading-5 text-gray-400">
- <p className="truncate">{deployment.description}</p>
- <svg viewBox="0 0 2 2" className="h-0.5 w-0.5 flex-none fill-gray-300">
- <circle cx={1} cy={1} r={1} />
- </svg>
- <p className="whitespace-nowrap">{deployment.statusText}</p>
+ <svg
+ className={clsx('h-1.5 w-1.5')}
+ viewBox="0 0 6 6"
+ aria-hidden="true"
+ >
+ <circle cx={3} cy={3} r={3} />
+ </svg>
+ </a>{' '}
+ </span>
+ <span className="whitespace-nowrap">{log.message}</span>
+ </div>
+ </div>
+ </>
+ ) : log.type === 'tool' ? (
+ <>
+ <div>
+ <div className="relative px-1">
+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 ring-8 ring-white">
+ <TagIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
+ </div>
+ </div>
+ </div>
+ <div className="min-w-0 flex-1 py-0">
+ <div className="text-sm leading-8 text-gray-500">
+ <span className="mr-0.5">
+ <a className="font-medium text-gray-900">
+ {log.type}
+ </a>{' '}
+ </span>{' '}
+ <span className="mr-0.5">
+ </span>
+ <span className="whitespace-nowrap">{log.message}</span>
+ </div>
+ </div>
+ </>
+ ) : null}
</div>
</div>
- <div
- className={clsx(
- environments[deployment.environment as keyof typeof environments],
- 'rounded-full flex-none py-1 px-2 text-xs font-medium ring-1 ring-inset'
- )}
- >
- {deployment.environment}
- </div>
- <ChevronRightIcon className="h-5 w-5 flex-none text-gray-400" aria-hidden="true" />
</li>
))}
- </ul>
- </main>
-
+ </ul>
</div>
</div>
)
}
+
+export default AgentDetail
diff --git a/components/AgentOverview.tsx b/components/AgentOverview.tsx
index 75908d8dd..4a95eed00 100644
--- a/components/AgentOverview.tsx
+++ b/components/AgentOverview.tsx
@@ -1,8 +1,5 @@
import { Fragment, useState } from 'react'
import { Dialog, Transition } from '@headlessui/react'
-// import {
-// XMarkIcon,
-// } from '@heroicons/react/24/outline'
import { ChevronRightIcon } from '@heroicons/react/20/solid'
import clsx from 'clsx'
import { Grid } from 'lucide-react'
@@ -14,9 +11,13 @@ import { useRouter } from 'next/router'
const navigation = [
{
- name: 'Agents', href: '#', icon: Grid, current: true,
+ name: 'Agents',
+ href: '#',
+ icon: Grid,
+ current: true,
},
]
+
const statuses = {
disabled: 'text-gray-500 bg-gray-100/10',
enabled: 'text-green-400 bg-green-400/10',
@@ -38,6 +39,11 @@ export default function AgentOverview({ projects }: Props) {
router.push('/sign')
}
+ function selectAgent(projectID: string) {
+ posthog?.capture('selected deployed agent', { projectID: projectID })
+ router.push(`/${projectID}`)
+ }
+
const projectsWithDeployments = projects
.filter(p => {
if (p.deployments.length !== 1) return false
@@ -45,7 +51,7 @@ export default function AgentOverview({ projects }: Props) {
const deployment = p.deployments[0]
const auth = deployment.auth as any
if (!auth) return false
- return true
+ return deployment.enabled
})
.map(p => ({
project: p,
@@ -53,7 +59,7 @@ export default function AgentOverview({ projects }: Props) {
}))
return (
- <div>
+ <div className="overflow-hidden">
<Transition.Root show={sidebarOpen} as={Fragment}>
<Dialog as="div" className="relative z-50 xl:hidden" onClose={setSidebarOpen}>
<Transition.Child
@@ -143,7 +149,6 @@ export default function AgentOverview({ projects }: Props) {
</div>
</Dialog>
</Transition.Root>
-
{/* Static sidebar for desktop */}
<div className="hidden xl:fixed xl:inset-y-0 xl:z-50 xl:flex xl:w-72 xl:flex-col">
{/* Sidebar component, swap this element with another sidebar if you like */}
@@ -195,16 +200,19 @@ export default function AgentOverview({ projects }: Props) {
</div>
<div className="xl:pl-72">
- <main className="">
+ <main className="overflow-hidden">
<header className="flex items-center justify-between border-b border-white/5 p-4 sm:p-6 lg:px-8">
<h1 className="text-base font-semibold leading-7 text-white">Agents</h1>
</header>
{/* Deployment list */}
- <ul role="list" className="divide-y divide-white/5">
+ <ul role="list" className="divide-y divide-white/5 overflow-auto">
{projectsWithDeployments.map((p) => (
<li key={p.project.id} className="relative flex items-center space-x-4 p-4 sm:px-6 lg:px-8">
- <div className="min-w-0 flex-auto">
+ <div
+ className="min-w-0 flex-auto cursor-pointer"
+ onClick={() => selectAgent(p.project.id)}
+ >
<div className="flex items-center gap-x-3">
<div className={clsx(statuses[p.deployment.enabled ? 'enabled' : 'disabled'], 'flex-none rounded-full p-1')}>
<div className="h-2 w-2 rounded-full bg-current" />
@@ -223,23 +231,15 @@ export default function AgentOverview({ projects }: Props) {
<svg viewBox="0 0 2 2" className="h-0.5 w-0.5 flex-none fill-gray-300">
<circle cx={1} cy={1} r={1} />
</svg>
- {/* <p className="whitespace-nowrap">{p.statusText}</p> */}
</div>
</div>
- {/* <div
- className={clsx(
- environments[p.environment as keyof typeof environments],
- 'rounded-full flex-none py-1 px-2 text-xs font-medium ring-1 ring-inset'
- )}
- >
- {p.environment}
- </div> */}
- <ChevronRightIcon className="h-5 w-5 flex-none text-gray-400" aria-hidden="true" />
+ <ChevronRightIcon
+ className="h-5 w-5 flex-none text-gray-400" aria-hidden="true"
+ />
</li>
))}
</ul>
</main>
-
</div>
</div >
)
diff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsx
index 90fed5454..0f69be58d 100644
--- a/pages/agent/smol-developer/setup.tsx
+++ b/pages/agent/smol-developer/setup.tsx
@@ -26,6 +26,7 @@ import { getDefaultModelConfig, getModelArgs, ModelConfig } from 'state/model'
import { GitHubAccount } from 'utils/github'
import { RepoSetup } from 'components/SelectRepository/RepoSetup'
import { nanoid } from 'nanoid'
+import { useRouter } from 'next/router'
export interface PostAgentBody {
// ID of the installation of the GitHub App
@@ -78,6 +79,7 @@ export interface PostAgentResponse {
repo: string
pullURL: string
pullNumber: number
+ projectID: string
}
async function handlePostAgent(url: string, { arg }: { arg: PostAgentBody }) {
@@ -114,6 +116,7 @@ function Setup() {
const [instructions, setInstructions] = useState('')
const [openAIAPIKey, setOpenAIAPIKey] = useState<string>('')
const posthog = usePostHog()
+ const router = useRouter()
const handleMessageEvent = useCallback((event: MessageEvent) => {
if (event.data.accessToken) {
@@ -126,6 +129,7 @@ function Setup() {
const {
trigger: createAgent,
+ data,
} = useSWRMutation('/api/agent', handlePostAgent)
async function deployAgent() {
@@ -151,7 +155,7 @@ function Setup() {
},
})
- await createAgent({
+ const response = await createAgent({
defaultBranch: selectedRepository.defaultBranch,
installationID: selectedRepository.installationID,
owner: selectedRepository.owner,
@@ -163,6 +167,12 @@ function Setup() {
commitMessage: 'Smol dev initial commit',
modelConfig,
})
+
+ // if (response) {
+ // router.push(`/${response.projectID}`)
+ // } else {
+ // console.error('No response from agent creation')
+ // }
}
function nextStep() {
diff --git a/pages/api/agent/index.ts b/pages/api/agent/index.ts
index 874265d00..24d49dcd5 100644
--- a/pages/api/agent/index.ts
+++ b/pages/api/agent/index.ts
@@ -170,6 +170,7 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
issueID,
owner,
repo,
+ projectID: project.id,
}
posthog?.capture({
diff --git a/pages/index.tsx b/pages/index.tsx
index bae398676..157267b80 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -30,6 +30,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
teams: {
include: {
projects: {
+ orderBy: {
+ created_at: 'desc',
+ },
include: {
deployments: true,
},
@@ -92,7 +95,7 @@ interface Props {
}
function Home({ projects }: Props) {
-
+ console.log(projects)
return (
<AgentOverview
projects={projects}
@@ -100,4 +103,4 @@ function Home({ projects }: Props) {
)
}
-export default Home
\ No newline at end of file
+export default Home