Skip to content

armgit / E2B

Public Imported from GitHub
0

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

new setup page for smol developer

Vasek Mlejnsky1558ff8757d0
diff --git a/components/Repos.tsx b/components/Repos.tsx
index 76749c376..de98c996e 100644
--- a/components/Repos.tsx
+++ b/components/Repos.tsx
@@ -3,10 +3,10 @@ import { GithubIcon, SearchIcon } from 'lucide-react'
import clsx from 'clsx'
import Fuse from 'fuse.js'
-import { useGitHubClient } from 'hooks/useGitHubClient'
-import useListenMessage from 'hooks/useListenMessage'
+import useListenOnMessage from 'hooks/useListenOnMessage'
import Button from 'components/Button'
import Text from 'components/Text'
+import { useGitHubClient } from 'hooks/useGitHubClient'
import { useRepositories } from 'hooks/useRepositories'
import { openPopupModal } from 'utils/popupModal'
@@ -60,7 +60,7 @@ function Repos({ onRepoSelection }: Props) {
refetch()
}
}, [refetch, setAccessToken])
- useListenMessage(handleEvent)
+ useListenOnMessage(handleEvent)
async function selectRepository(r: Omit<RepoSetup, 'branches' | 'owner' | 'repo'>) {
diff --git a/components/RepositoriesList.tsx b/components/RepositoriesList.tsx
new file mode 100644
index 000000000..db7d8d4f5
--- /dev/null
+++ b/components/RepositoriesList.tsx
@@ -0,0 +1,84 @@
+const people = [
+ {
+ name: 'Leslie Alexander',
+ email: '[email protected]',
+ role: 'Co-Founder / CEO',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Michael Foster',
+ email: '[email protected]',
+ role: 'Co-Founder / CTO',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1519244703995-f4e0f30006d5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Dries Vincent',
+ email: '[email protected]',
+ role: 'Business Relations',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: null,
+ },
+ {
+ name: 'Lindsay Walton',
+ email: '[email protected]',
+ role: 'Front-end Developer',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1517841905240-472988babdf9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Courtney Henry',
+ email: '[email protected]',
+ role: 'Designer',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Tom Cook',
+ email: '[email protected]',
+ role: 'Director of Product',
+ imageUrl:
+ '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',
+ lastSeen: null,
+ },
+]
+
+function RepositoriesList() {
+ return (
+ <ul role="list" className="overflow-auto divide-y divide-gray-800">
+ {people.map((person) => (
+ <li key={person.email} className="px-2 flex items-center justify-between py-5">
+ <div className="flex gap-x-4">
+ <img
+ className="h-12 w-12 flex-none rounded-full bg-gray-800"
+ src={person.imageUrl}
+ alt=""
+ />
+ <div className="min-w-0 flex-auto">
+ <p className="text-sm font-semibold leading-6 text-white">{person.name}</p>
+ <p className="mt-1 truncate text-xs leading-5 text-gray-400">{person.email}</p>
+ </div>
+ </div>
+ <button
+ type="button"
+ className="rounded bg-white/10 px-2 py-1 text-sm font-semibold text-white shadow-sm hover:bg-white/20"
+ >
+ Select
+ </button>
+ </li>
+ ))}
+ </ul>
+ )
+}
+
+export default RepositoriesList
\ No newline at end of file
diff --git a/components/Steps.tsx b/components/Steps.tsx
new file mode 100644
index 000000000..9190d1cb7
--- /dev/null
+++ b/components/Steps.tsx
@@ -0,0 +1,40 @@
+const steps = [
+ { name: 'Step 1', href: '#repo', status: 'current' },
+ { name: 'Step 2', href: '#instructions', status: 'upcoming' },
+ { name: 'Step 3', href: '#keys', status: 'upcoming' },
+]
+
+function Steps() {
+ return (
+ <nav className="flex items-center justify-center" aria-label="Progress">
+ <ol role="list" className="ml-8 flex items-center space-x-5">
+ <p className="text-gray-400 text-sm font-medium">
+ Step {steps.findIndex((step) => step.status === 'current') + 1} of {steps.length}
+ </p>
+ {steps.map((step) => (
+ <li key={step.name}>
+ {step.status === 'complete' ? (
+ <a href={step.href} className="block h-2.5 w-2.5 rounded-full bg-indigo-500">
+ <span className="sr-only">{step.name}</span>
+ </a>
+ ) : step.status === 'current' ? (
+ <a href={step.href} className="relative flex items-center justify-center" aria-current="step">
+ <span className="absolute flex h-5 w-5 p-px" aria-hidden="true">
+ <span className="h-full w-full rounded-full bg-indigo-600/30 ring-1 ring-inset ring-indigo-500/20" />
+ </span>
+ <span className="relative block h-2.5 w-2.5 rounded-full bg-indigo-500" aria-hidden="true" />
+ <span className="sr-only">{step.name}</span>
+ </a>
+ ) : (
+ <a href={step.href} className="block h-2.5 w-2.5 rounded-full bg-white/5 ring-1 ring-white/10 hover:bg-gray-500 transition-all">
+ <span className="sr-only">{step.name}</span>
+ </a>
+ )}
+ </li>
+ ))}
+ </ol>
+ </nav>
+ )
+}
+
+export default Steps
\ No newline at end of file
diff --git a/hooks/useListenMessage.ts b/hooks/useListenOnMessage.ts
similarity index 66%
rename from hooks/useListenMessage.ts
rename to hooks/useListenOnMessage.ts
index d7b285617..57e832442 100644
--- a/hooks/useListenMessage.ts
+++ b/hooks/useListenOnMessage.ts
@@ -2,7 +2,7 @@ import {
useEffect,
} from 'react'
-function useListenMessage(callback: (event: MessageEvent<any>) => void) {
+function useListenOnMessage(callback: (event: MessageEvent<any>) => void) {
useEffect(function register() {
window.addEventListener('message', callback)
return () => {
@@ -11,4 +11,4 @@ function useListenMessage(callback: (event: MessageEvent<any>) => void) {
}, [callback])
}
-export default useListenMessage
+export default useListenOnMessage
diff --git a/pages/agent/smol-developer/index.tsx b/pages/agent/smol-developer/index.tsx
index d9dd9381f..4f97bb91e 100644
--- a/pages/agent/smol-developer/index.tsx
+++ b/pages/agent/smol-developer/index.tsx
@@ -148,7 +148,8 @@ function SmolDeveloper({
className="flex items-center space-x-2 rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
onClick={signInWithGitHub}
>
- <Github size={16} /> <span>Continue with GitHub</span>
+ <Github size={16} />
+ <span>Continue with GitHub</span>
</button>
}
<a href="#" className="text-sm font-semibold leading-6 text-white">
diff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsx
index 92429f77d..1f84e688a 100644
--- a/pages/agent/smol-developer/setup.tsx
+++ b/pages/agent/smol-developer/setup.tsx
@@ -124,6 +124,61 @@ function Repo() {
})
}
+ const people = [
+ {
+ name: 'Leslie Alexander',
+ email: '[email protected]',
+ role: 'Co-Founder / CEO',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Michael Foster',
+ email: '[email protected]',
+ role: 'Co-Founder / CTO',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1519244703995-f4e0f30006d5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Dries Vincent',
+ email: '[email protected]',
+ role: 'Business Relations',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: null,
+ },
+ {
+ name: 'Lindsay Walton',
+ email: '[email protected]',
+ role: 'Front-end Developer',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1517841905240-472988babdf9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Courtney Henry',
+ email: '[email protected]',
+ role: 'Designer',
+ imageUrl:
+ 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
+ lastSeen: '3h ago',
+ lastSeenDateTime: '2023-01-23T13:23Z',
+ },
+ {
+ name: 'Tom Cook',
+ email: '[email protected]',
+ role: 'Director of Product',
+ imageUrl:
+ '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',
+ lastSeen: null,
+ },
+ ]
+
return (
<div
className="
@@ -138,7 +193,7 @@ function Repo() {
className="
max-w-xl
w-full
- max-h-[800px]
+ max-h-[400px]
flex-1
flex
flex-col
diff --git a/pages/agent/smol-developer/setup2.tsx b/pages/agent/smol-developer/setup2.tsx
new file mode 100644
index 000000000..b299b0e53
--- /dev/null
+++ b/pages/agent/smol-developer/setup2.tsx
@@ -0,0 +1,187 @@
+import {
+ useState,
+ useCallback,
+} from 'react'
+import {
+ Github,
+} from 'lucide-react'
+import type { GetServerSideProps } from 'next'
+import { useSessionContext, useSupabaseClient } from '@supabase/auth-helpers-react'
+import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'
+import {
+ useUser,
+ useSession,
+} from '@supabase/auth-helpers-react'
+import useSWRMutation from 'swr/mutation'
+
+import { serverCreds } from 'db/credentials'
+import { openPopupModal } from 'utils/popupModal'
+import useListenOnMessage from 'hooks/useListenOnMessage'
+import { useGitHubClient } from 'hooks/useGitHub'
+import { useRepositories } from 'hooks/useRepositories'
+import { RepoSetup } from 'components/Repos'
+import RepositoriesList from 'components/RepositoriesList'
+import { useLocalStorage } from 'hooks/useLocalStorage'
+import SpinnerIcon from 'components/Spinner'
+import Steps from 'components/Steps'
+
+export const getServerSideProps: GetServerSideProps = async (ctx) => {
+ const supabase = createServerSupabaseClient(ctx, serverCreds)
+ const {
+ data: { session },
+ } = await supabase.auth.getSession()
+
+ if (!session) {
+ return {
+ redirect: {
+ destination: '/agent/smol-developer',
+ permanent: false,
+ },
+ }
+ }
+
+ return { props: {} }
+}
+
+export interface PostAgentBody {
+ // ID of the installation of the GitHub App
+ installationID: number
+ // ID of the repository
+ repositoryID: number
+ // Title of the PR
+ title: string
+ // Default branch against which to create the PR
+ defaultBranch: string
+ // Initial prompt used as a body text for the PR (can be markdown)
+ body: string
+ // Owner of the repo (user or org)
+ owner: string
+ // Name of the repo
+ repo: string
+ // Name of the branch created for the PR
+ branch: string
+ // Commit message for the PR first empty commit
+ commitMessage: string
+}
+
+async function handlePostAgent(url: string, { arg }: { arg: PostAgentBody }) {
+ return await fetch(url, {
+ method: 'POST',
+ body: JSON.stringify(arg),
+
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ }).then(r => r.json())
+}
+
+function Repo() {
+ const [accessToken, setAccessToken] = useLocalStorage<string | undefined>('gh_access_token', undefined)
+ const gitHub = useGitHubClient(accessToken)
+ const { repos, refetch } = useRepositories(gitHub)
+ const supabaseClient = useSupabaseClient()
+ const user = useUser()
+ const session = useSession()
+ const sessionCtx = useSessionContext()
+ const [selectedRepo, setSelectedRepo] = useState<RepoSetup>()
+
+
+ const ghUsername: string = user?.user_metadata['user_name'] || ''
+
+ const handleMessageEvent = useCallback((event: MessageEvent) => {
+ if (event.data.accessToken) {
+ setAccessToken(event.data.accessToken)
+ } else if (event.data.installationID) {
+ refetch()
+ }
+ }, [refetch, setAccessToken])
+ useListenOnMessage(handleMessageEvent)
+
+ function configureGitHubApp() {
+ const url = new URL('https://github.com/apps/e2b-for-github/installations/new')
+ openPopupModal(url)
+ }
+
+ const {
+ trigger: createAgent,
+ } = useSWRMutation('/api/agent', handlePostAgent)
+
+ async function deployAgent() {
+ if (!selectedRepo) return
+ console.log('selectedRepo', selectedRepo)
+
+
+ return
+ await createAgent({
+ defaultBranch: selectedRepo.defaultBranch,
+ installationID: selectedRepo.installationID,
+ owner: selectedRepo.owner,
+ repo: selectedRepo.repo,
+ repositoryID: selectedRepo.repositoryID,
+ title,
+ branch,
+ body,
+ commitMessage,
+ })
+ }
+
+
+ return (
+ <div className="h-full flex flex-col items-center justify-start bg-gray-800 py-8 px-6">
+ <Steps />
+ {/* Horizontal separator */}
+
+ <div className="flex-1 mx-auto max-w-lg flex flex-col">
+ <div className="h-px bg-gray-700 my-8" />
+ <h2 className="text-3xl font-bold tracking-tight text-white sm:text-4xl">
+ Select Git Repository
+ </h2>
+ <p className="mt-2 mb-6 text-lg leading-8 text-gray-400">
+ Select a git repository to which you want to give the AI developer access.
+ </p>
+
+ {!user && (
+ <div
+ className="
+ flex
+ justify-center
+ "
+ >
+ <SpinnerIcon className="text-slate-400" />
+ </div>
+ )}
+
+ {user && (
+ <>
+ {ghUsername && (
+ <span className="mb-1 text-xs text-gray-400 font-semibold">
+ {ghUsername}{ghUsername.endsWith('s') ? "'" : "'s"} repositories
+ </span>
+ )}
+ <div className="flex-1 flex flex-col items-center justify-center border border-gray-700 rounded-md">
+ {!accessToken && (
+ <button
+ type="button"
+ className="flex items-center space-x-2 rounded-md bg-white/10 px-3.5 py-2 text-sm font-semibold text-white shadow-sm hover:bg-white/20 transition-all"
+ onClick={configureGitHubApp}
+ >
+ <Github size={16} />
+ <span>Configure GitHub Permissions</span>
+ </button>
+ )}
+
+ {accessToken && (
+ <>
+ <RepositoriesList />
+ </>
+ )}
+ </div>
+ </>
+ )}
+
+ </div>
+ </div>
+ )
+}
+
+export default Repo
diff --git a/pages/api/github/oauth.ts b/pages/api/github/oauth.ts
index 8b26e0e3b..68d061e7d 100644
--- a/pages/api/github/oauth.ts
+++ b/pages/api/github/oauth.ts
@@ -5,6 +5,7 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
+
if (!req.url) {
res.writeHead(400, { 'Content-Type': 'text/html' })
res.end('No request URL')
@@ -29,10 +30,10 @@ export default async function handler(
Accept: 'application/json',
}
})
- const { access_token }: { access_token: string } = await response.json()
const redirectionURL = new URL('github/callback', `${process.env.NODE_ENV === 'production' ? 'https' : 'http'}://${req.headers.host}`)
+ const { access_token }: { access_token: string } = await response.json()
redirectionURL.searchParams.set('gha_access_token', access_token)
res.writeHead(302, { 'Location': redirectionURL.toString() })