Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
refactor
Vasek Mlejnsky93153628c030
diff --git a/components/SelectRepository/ExistingRepositories/RepositoriesList.tsx b/components/SelectRepository/ExistingRepositories/RepositoriesList.tsxindex 5090ea584..4eef18c83 100644--- a/components/SelectRepository/ExistingRepositories/RepositoriesList.tsx+++ b/components/SelectRepository/ExistingRepositories/RepositoriesList.tsx@@ -14,7 +14,7 @@ function RepositoriesList({return (<ul role="list" className="w-full overflow-auto divide-y divide-gray-700">{repos.map((r) => (- <li key={r.id} className="px-2 flex items-center justify-between py-5 h-[70px]">+ <li key={r.id} className="px-2 flex items-center justify-between h-[60px]"><div className="flex flex-col items-start justify-start"><div className="flex items-center space-x-1"><Github color="#fff" size={14} />diff --git a/components/SelectRepository/ExistingRepositories/index.tsx b/components/SelectRepository/ExistingRepositories/index.tsxindex 3f198fbef..1f4f03685 100644--- a/components/SelectRepository/ExistingRepositories/index.tsx+++ b/components/SelectRepository/ExistingRepositories/index.tsx@@ -1,3 +1,4 @@+import clsx from 'clsx'import ConfigureGitHubButton from 'components/ConfigureGitHubButton'import SpinnerIcon from 'components/Spinner'import RepositoriesList from './RepositoriesList'@@ -17,7 +18,10 @@ function ExistingRepositories({}: Props) {return (- <div className="overflow-hidden flex-1 flex flex-col items-center justify-center border border-gray-700 rounded-md">+ <div className={clsx(+ repos && repos.length > 0 ? 'justify-start' : 'justify-center',+ 'overflow-hidden flex-1 flex flex-col items-center border border-gray-700 rounded-md'+ )}>{!accessToken && (<ConfigureGitHubButtononClick={onConfigureGitHubAppClick}diff --git a/components/SelectRepository/NewRepository/PermissionsModal.tsx b/components/SelectRepository/NewRepository/PermissionsModal.tsxnew file mode 100644index 000000000..19eb1c9a3--- /dev/null+++ b/components/SelectRepository/NewRepository/PermissionsModal.tsx@@ -0,0 +1,69 @@+import { Fragment, useState } from 'react'++import { Dialog, Transition } from '@headlessui/react'++function PermissionsModal() {+ const [open, setOpen] = useState(true)++ return (+ <Transition.Root show={open} as={Fragment}>+ <Dialog as="div" className="relative z-10" onClose={setOpen}>+ <Transition.Child+ as={Fragment}+ enter="ease-out duration-300"+ enterFrom="opacity-0"+ enterTo="opacity-100"+ leave="ease-in duration-200"+ leaveFrom="opacity-100"+ leaveTo="opacity-0"+ >+ <div className="fixed inset-0 bg-gray-500/75 transition-opacity" />+ </Transition.Child>++ <div className="fixed inset-0 z-10 overflow-y-auto">+ <div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">+ <Transition.Child+ as={Fragment}+ enter="ease-out duration-300"+ enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"+ enterTo="opacity-100 translate-y-0 sm:scale-100"+ leave="ease-in duration-200"+ leaveFrom="opacity-100 translate-y-0 sm:scale-100"+ leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"+ >+ <Dialog.Panel className="relative overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6">+ <div>+ <div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">+ <span>icon</span>+ {/* <CheckIcon className="h-6 w-6 text-green-600" aria-hidden="true" /> */}+ </div>+ <div className="mt-3 text-center sm:mt-5">+ <Dialog.Title as="h3" className="text-base font-semibold leading-6 text-gray-900">+ Payment successful+ </Dialog.Title>+ <div className="mt-2">+ <p className="text-sm text-gray-500">+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </p>+ </div>+ </div>+ </div>+ <div className="mt-5 sm:mt-6">+ <button+ type="button"+ className="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"+ onClick={() => setOpen(false)}+ >+ Go back to dashboard+ </button>+ </div>+ </Dialog.Panel>+ </Transition.Child>+ </div>+ </div>+ </Dialog>+ </Transition.Root>+ )+}++export default PermissionsModal\ No newline at end of filediff --git a/components/SelectRepository/NewRepository/RepoAccountSelect.tsx b/components/SelectRepository/NewRepository/RepoAccountSelect.tsxindex 0e9d412d5..455483d28 100644--- a/components/SelectRepository/NewRepository/RepoAccountSelect.tsx+++ b/components/SelectRepository/NewRepository/RepoAccountSelect.tsx@@ -10,10 +10,7 @@ import {Plus,} from 'lucide-react'-export interface GitHubAccount {- name: string- isOrg: boolean-}+import { GitHubAccount } from 'utils/github'export interface Props {accounts: GitHubAccount[]diff --git a/components/SelectRepository/NewRepository/index.tsx b/components/SelectRepository/NewRepository/index.tsxindex 64b56f002..06ce3834f 100644--- a/components/SelectRepository/NewRepository/index.tsx+++ b/components/SelectRepository/NewRepository/index.tsx@@ -6,14 +6,17 @@ import clsx from 'clsx'import ConfigureGitHubButton from 'components/ConfigureGitHubButton'import AlertError from 'components/AlertError'-import { configureGitHubApp } from 'utils/github'+import {+ configureGitHubApp,+ GitHubAccount,+} from 'utils/github'import { useGitHubClient } from 'hooks/useGitHubClient'import SpinnerIcon from 'components/Spinner'import { createRepo } from 'github/repo'-import { fetchRepos } from 'hooks/useRepositories'-import RepoAccountSelect, { GitHubAccount } from './RepoAccountSelect'+import RepoAccountSelect from './RepoAccountSelect'import RepoNameInput from './RepoNameInput'+import PermissionsModal from './PermissionsModal'import {creationReducer,ActionType,@@ -26,7 +29,6 @@ export interface Props {onRepoSelection: (repo: any) => void}-function NewRepository({accessToken,accounts,@@ -38,6 +40,7 @@ function NewRepository({name: '',account: null,isCreating: false,+ requiresPermissions: false,})async function handleCreateClick() {@@ -47,27 +50,14 @@ function NewRepository({if (state.isCreating) returntry {- // Create a repositorydispatch({ type: ActionType.Create, payload: {} })- const { id: newRepoID } = await createRepo({+ const newRepo = await createRepo({client: ghClient,org: state.account.isOrg ? state.account.name : undefined,name: state.name,})- // Check if we have permissions to the new repository,- // if not - present UI that asks user for a permission to the new repository- // if yes - select the new repo- const repos = await fetchRepos(ghClient)- // Check if newly created repo is in the list of repos we have access to.- const newRepo = repos.find(r => r.id === newRepoID)-- if (newRepo) {- dispatch({ type: ActionType.Success, payload: {} })- onRepoSelection(newRepo)- } else {- // TODO- console.log('DO NOT HAVE ACCESS TO REPO', newRepo)- }+ dispatch({ type: ActionType.Success, payload: {} })+ onRepoSelection(newRepo)} catch (err: any) {console.error('Error creating repository', err)dispatch({ type: ActionType.Fail, payload: { error: err } })@@ -122,6 +112,11 @@ function NewRepository({)}</button>++ {state.requiresPermissions && (+ <PermissionsModal />+ )}+{state.error && (<AlertErrortitle="Error creating repository"diff --git a/components/SelectRepository/NewRepository/newRepoState.ts b/components/SelectRepository/NewRepository/newRepoState.tsindex 1e0a40525..1422f8ec0 100644--- a/components/SelectRepository/NewRepository/newRepoState.ts+++ b/components/SelectRepository/NewRepository/newRepoState.ts@@ -69,6 +69,7 @@ export interface State {error?: Error// TODO: Maybe pass the whole repo?selectedRepo?: number+ requiresPermissions: boolean}export function creationReducer(state: State, action: Action) {@@ -104,6 +105,7 @@ export function creationReducer(state: State, action: Action) {case ActionType.RequestPermissions:return {...state,+ requiresPermissions: true,}case ActionType.SelectRepo:return {diff --git a/components/SelectRepository/index.tsx b/components/SelectRepository/index.tsxindex 4ec71944a..4338a3600 100644--- a/components/SelectRepository/index.tsx+++ b/components/SelectRepository/index.tsx@@ -1,5 +1,4 @@import {- useEffect,useState,} from 'react'import {@@ -9,49 +8,31 @@ import {useUser,} from '@supabase/auth-helpers-react'-import { configureGitHubApp } from 'utils/github'+import {+ configureGitHubApp,+ GitHubAccount,+} from 'utils/github'import SpinnerIcon from 'components/Spinner'-import { useGitHubClient } from 'hooks/useGitHubClient'import RepoSwitch from './RepoSwitch'import ExistingRepositories from './ExistingRepositories'import NewRepository from './NewRepository'-import { GitHubAccount } from './NewRepository/RepoAccountSelect'export interface Props {repos?: any[]accessToken?: stringonRepoSelection: (repo: any) => void+ githubAccounts: GitHubAccount[]}function SelectRepository({repos,accessToken,onRepoSelection,+ githubAccounts,}: Props) {- const user = useUser()const [selected, setSelected] = useState<'existing' | 'new'>('new')- const ghClient = useGitHubClient(accessToken)- const [githubAccounts, setGitHubAccounts] = useState<GitHubAccount[]>([])-- useEffect(function getGitHubAccounts() {- async function getAccounts() {- if (!ghClient) return- const installations = await ghClient?.apps.listInstallationsForAuthenticatedUser()- const accounts: GitHubAccount[] = []- installations.data.installations.forEach(i => {- if (i.account) {- const ghAccType = (i.account as any)['type']- const ghLogin = (i.account as any)['login']- // Filter out user accounts that are not the current user (when a user has access to repos that aren't theirs)- if (ghAccType === 'User' && ghLogin !== user?.user_metadata?.user_name) return- accounts.push({ name: ghLogin, isOrg: ghAccType === 'Organization' })- }- })- setGitHubAccounts(accounts)- }- getAccounts()- }, [ghClient, user])+ const user = useUser()return (<>diff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsxindex 558d239c8..550ebaa80 100644--- a/pages/agent/smol-developer/setup.tsx+++ b/pages/agent/smol-developer/setup.tsx@@ -1,11 +1,15 @@import {useState,useCallback,+ useEffect,} from 'react'import useSWRMutation from 'swr/mutation'import type { GetServerSideProps } from 'next'import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'-import { useSupabaseClient } from '@supabase/auth-helpers-react'+import {+ useUser,+ useSupabaseClient,+} from '@supabase/auth-helpers-react'import Steps from 'components/Steps'import SelectRepository from 'components/SelectRepository'@@ -14,6 +18,7 @@ import { useGitHubClient } from 'hooks/useGitHubClient'import { useRepositories } from 'hooks/useRepositories'import { useLocalStorage } from 'hooks/useLocalStorage'import useListenOnMessage from 'hooks/useListenOnMessage'+import { GitHubAccount } from 'utils/github'export interface PostAgentBody {// ID of the installation of the GitHub App@@ -83,17 +88,14 @@ async function handlePostAgent(url: string, { arg }: { arg: PostAgentBody }) {}function Setup() {+ const user = useUser()const supabaseClient = useSupabaseClient()+ const [accessToken, setAccessToken] = useLocalStorage<string | undefined>('gh_access_token', undefined)+ const github = useGitHubClient(accessToken)+ const [githubAccounts, setGitHubAccounts] = useState<GitHubAccount[]>([])const [currentStep, setCurrentStep] = useState(0)const [selectedRepository, setSelectedRepository] = useState<any | undefined>()- // const supabaseClient = useSupabaseClient()- // const session = useSession()- // const sessionCtx = useSessionContext()- // const [selectedRepo, setSelectedRepo] = useState<RepoSetup>()-- const [accessToken, setAccessToken] = useLocalStorage<string | undefined>('gh_access_token', undefined)- const gitHub = useGitHubClient(accessToken)- const { repos, refetch } = useRepositories(gitHub)+ const { repos, refetch } = useRepositories(github)const handleMessageEvent = useCallback((event: MessageEvent) => {if (event.data.accessToken) {@@ -143,6 +145,26 @@ function Setup() {location.reload()}+ useEffect(function getGitHubAccounts() {+ async function getAccounts() {+ if (!github) return+ const installations = await github.apps.listInstallationsForAuthenticatedUser()+ const accounts: GitHubAccount[] = []+ installations.data.installations.forEach(i => {+ if (i.account) {+ const ghAccType = (i.account as any)['type']+ const ghLogin = (i.account as any)['login']+ // Filter out user accounts that are not the current user (when a user has access to repos that aren't theirs)+ if (ghAccType === 'User' && ghLogin !== user?.user_metadata?.user_name) return+ accounts.push({ name: ghLogin, isOrg: ghAccType === 'Organization' })+ }+ })+ setGitHubAccounts(accounts)+ }+ getAccounts()+ }, [github, user])++return (<div className="h-full flex flex-col items-center justify-start bg-gray-800 py-8 px-6"><div className="mb-4 w-full flex items-center justify-between">@@ -163,6 +185,7 @@ function Setup() {repos={repos}onRepoSelection={handleRepoSelection}accessToken={accessToken}+ githubAccounts={githubAccounts}/>) : currentStep === 1 ? (<div>prompt</div>diff --git a/utils/github.ts b/utils/github.tsindex 9a3f56cf2..afd8a4333 100644--- a/utils/github.ts+++ b/utils/github.ts@@ -1,5 +1,10 @@import { openPopupModal } from 'utils/popupModal'+export interface GitHubAccount {+ name: string+ isOrg: boolean+}+export function configureGitHubApp() {const url = new URL('https://github.com/apps/e2b-for-github/installations/new')openPopupModal(url)