Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
UI for creating new repo [wip]
Vasek Mlejnsky2b3db9ca5672
diff --git a/components/AlertError.tsx b/components/AlertError.tsxnew file mode 100644index 000000000..bbe0b3036--- /dev/null+++ b/components/AlertError.tsx@@ -0,0 +1,31 @@+import { XCircle } from 'lucide-react'++export interface Props {+ title: string+ infoItems: string[]+}++function AlertError({+ title,+ infoItems,+}: Props) {+ return (+ <div className="rounded-md bg-red-50 p-4">+ <div className="flex">+ <div className="shrink-0">+ <XCircle className="text-red-400" size={16} aria-hidden="true" />+ </div>+ <div className="ml-3">+ <h3 className="text-sm font-medium text-red-800">{title}</h3>+ <div className="mt-2 text-sm text-red-700">+ <ul role="list" className="list-disc space-y-1 pl-5">+ {infoItems.map(i => <li key={i}>{i}</li>)}+ </ul>+ </div>+ </div>+ </div>+ </div>+ )+}++export default AlertError\ No newline at end of filediff --git a/components/ConfigureGitHubButton.tsx b/components/ConfigureGitHubButton.tsxnew file mode 100644index 000000000..aafa44520--- /dev/null+++ b/components/ConfigureGitHubButton.tsx@@ -0,0 +1,24 @@+import {+ Github,+} from 'lucide-react'++export interface Props {+ onClick: (e: any) => void+}++function ConfigureGitHubButton({+ onClick,+}: Props) {+ return (+ <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={onClick}+ >+ <Github size={16} />+ <span>Configure GitHub Permissions</span>+ </button>+ )+}++export default ConfigureGitHubButton\ No newline at end of filediff --git a/components/Repos.tsx b/components/Repos.tsxindex ed515d283..1726cd561 100644--- a/components/Repos.tsx+++ b/components/Repos.tsx@@ -50,7 +50,7 @@ function Repos({ onRepoSelection }: Props) {await createRepo({ client: gitHub, name })// When we refresh the list of repos now the new repo will be there- // if we gave the GH App permissions to access all the personal repos or repos for the org+ // if we gave the GH App permissions to access all the personal repos or repos for the orgrefetch()}@@ -67,14 +67,14 @@ function Repos({ onRepoSelection }: Props) {const filteredRepos = query && searchEngine ? searchEngine.search(query).map(i => i.item) : repos || []- const handleEvent = useCallback((event: MessageEvent) => {+ const handleMessageEvent = useCallback((event: MessageEvent) => {if (event.data.accessToken) {setAccessToken(event.data.accessToken)} else if (event.data.installationID) {refetch()}}, [refetch, setAccessToken])- useListenOnMessage(handleEvent)+ useListenOnMessage(handleMessageEvent)async function selectRepository(r: Omit<RepoSetup, 'branches' | 'owner' | 'repo'>) {@@ -165,14 +165,14 @@ function Repos({ onRepoSelection }: Props) {{repos && repos.length > 0 &&<div className="- flex- flex-col- scroller- overflow-auto- pl-8- flex-1- pr-6- ">+ flex+ flex-col+ scroller+ overflow-auto+ pl-8+ flex-1+ pr-6+ ">{filteredRepos.map(r => (<divclassName={clsx(diff --git a/components/SelectRepository/ExistingRepositories/index.tsx b/components/SelectRepository/ExistingRepositories/index.tsxindex bdd6e4719..b00f293ca 100644--- a/components/SelectRepository/ExistingRepositories/index.tsx+++ b/components/SelectRepository/ExistingRepositories/index.tsx@@ -1,19 +1,19 @@-import {- Github,-} from 'lucide-react'+++import ConfigureGitHubButton from 'components/ConfigureGitHubButton'import SpinnerIcon from 'components/Spinner'import RepositoriesList from './RepositoriesList'export interface Props {- hasAccessToken: boolean+ accessToken?: stringrepos?: any[]- onConfigureGitHubAppClick: () => void+ onConfigureGitHubAppClick: (e: any) => voidonRepoSelection: (repoID: number) => void}function ExistingRepositories({- hasAccessToken,+ accessToken,repos,onConfigureGitHubAppClick,onRepoSelection,@@ -21,18 +21,13 @@ function ExistingRepositories({return (<div className="overflow-hidden flex-1 flex flex-col items-center justify-center border border-gray-700 rounded-md">- {!hasAccessToken && (- <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"+ {!accessToken && (+ <ConfigureGitHubButtononClick={onConfigureGitHubAppClick}- >- <Github size={16} />- <span>Configure GitHub Permissions</span>- </button>+ />)}- {hasAccessToken && (+ {accessToken && (<>{!repos && (<div className="flex justify-center">@@ -44,14 +39,9 @@ function ExistingRepositories({<span className="mb-2 text-sm text-gray-400 font-semibold">No connected repositories found</span>- <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"+ <ConfigureGitHubButtononClick={onConfigureGitHubAppClick}- >- <Github size={16} />- <span>Configure GitHub Permissions</span>- </button>+ /></>)}{repos && repos.length > 0 && (diff --git a/components/SelectRepository/NewRepository/RepoOwnerSelect.tsx b/components/SelectRepository/NewRepository/RepoAccountSelect.tsxsimilarity index 76%rename from components/SelectRepository/NewRepository/RepoOwnerSelect.tsxrename to components/SelectRepository/NewRepository/RepoAccountSelect.tsxindex 1aa3c805d..1c5ccdac3 100644--- a/components/SelectRepository/NewRepository/RepoOwnerSelect.tsx+++ b/components/SelectRepository/NewRepository/RepoAccountSelect.tsx@@ -1,6 +1,5 @@import {Fragment,- useState,} from 'react'import { Listbox, Transition } from '@headlessui/react'import clsx from 'clsx'@@ -11,18 +10,26 @@ import {Plus,} from 'lucide-react'-export interface Props {- owners: string[]+export interface GitHubAccount {+ name: string+ isOrg: boolean}+export interface Props {+ accounts: GitHubAccount[]+ selectedAccount?: GitHubAccount+ onSelectedAccountChange: (account: GitHubAccount) => void+ onAddGithubAccountClick: () => void+}-function RepoOwnerSelect({- owners,+function RepoAccountSelect({+ accounts,+ selectedAccount,+ onSelectedAccountChange,+ onAddGithubAccountClick,}: Props) {- const [selected, setSelected] = useState(owners[0])-return (- <Listbox value={selected} onChange={setSelected}>+ <Listbox value={selectedAccount} onChange={onSelectedAccountChange}>{({ open }) => (<div className="w-full"><Listbox.Label className="block text-sm font-medium leading-6 text-gray-400">Account</Listbox.Label>@@ -35,7 +42,7 @@ function RepoOwnerSelect({}><div className="flex items-center space-x-2"><Github size={14} />- <span className="block truncate">{selected}</span>+ <span className="block truncate">{selectedAccount?.name}</span></div><span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"><ChevronsUpDown size={16} className="text-gray-400" aria-hidden="true" />@@ -52,22 +59,22 @@ function RepoOwnerSelect({<Listbox.OptionsclassName="p-2 absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-gray-800 text-base shadow-lg border border-gray-400 focus:outline-none sm:text-sm">- {owners.map((owner) => (+ {accounts.map((acc) => (<Listbox.Option- key={owner}+ key={acc.name}className={({ active }) =>clsx(active ? 'bg-gray-700' : '','rounded-md relative cursor-pointer select-none py-2 pl-3 pr-9 text-gray-100')}- value={owner}+ value={acc}>{({ selected, active }) => (<div className="flex items-center space-x-2"><Github size={14} /><span className={clsx(selected ? 'font-semibold' : 'font-normal', 'block truncate')}>- {owner}+ {acc.name}</span>{selected ? (@@ -81,7 +88,10 @@ function RepoOwnerSelect({)}</Listbox.Option>))}- <button className="w-full rounded-md flex items-center space-x-2 py-2 px-3 cursor-pointer text-gray-100 hover:bg-gray-700">+ <button+ className="w-full rounded-md flex items-center space-x-2 py-2 px-3 cursor-pointer text-gray-100 hover:bg-gray-700"+ onClick={onAddGithubAccountClick}+ ><Plus size={14} /><span>Add GitHub Account</span></button>@@ -95,4 +105,4 @@ function RepoOwnerSelect({)}-export default RepoOwnerSelect\ No newline at end of file+export default RepoAccountSelect\ No newline at end of filediff --git a/components/SelectRepository/NewRepository/RepoNameInput.tsx b/components/SelectRepository/NewRepository/RepoNameInput.tsxindex 7e69c61bf..15d9bf405 100644--- a/components/SelectRepository/NewRepository/RepoNameInput.tsx+++ b/components/SelectRepository/NewRepository/RepoNameInput.tsx@@ -1,4 +1,13 @@-function RepoNameInput() {+export interface Props {+ value: string+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => void+}++function RepoNameInput({+ value,+ onChange,+}: Props) {+return (<div className="w-full"><label className="text-sm font-medium leading-6 text-gray-400">@@ -8,6 +17,8 @@ function RepoNameInput() {<inputclassName="bg-gray-800 block w-full rounded-md border-0 px-3 py-1.5 text-gray-100 shadow-sm ring-1 ring-inset ring-gray-400 placeholder:text-gray-400 focus:ring-gray-300 outline-none sm:text-sm sm:leading-6 transition-all"placeholder="new-repo-name"+ value={value}+ onChange={onChange}/></div></div>diff --git a/components/SelectRepository/NewRepository/index.tsx b/components/SelectRepository/NewRepository/index.tsxindex c3259a793..3bae945a3 100644--- a/components/SelectRepository/NewRepository/index.tsx+++ b/components/SelectRepository/NewRepository/index.tsx@@ -1,25 +1,118 @@-import RepoOwnerSelect from './RepoOwnerSelect'+import {+ useState,+ useEffect,+} from 'react'+import clsx from 'clsx'++import ConfigureGitHubButton from 'components/ConfigureGitHubButton'+import AlertError from 'components/AlertError'+import { configureGitHubApp } from 'utils/github'+import { useGitHubClient } from 'hooks/useGitHubClient'+import SpinnerIcon from 'components/Spinner'+import { createRepo } from 'github/repo'++import RepoAccountSelect, { GitHubAccount } from './RepoAccountSelect'import RepoNameInput from './RepoNameInput'export interface Props {- org?: string- name: string+ accessToken?: string+ accounts: GitHubAccount[]+ onConfigureGitHubAppClick: (e: any) => void}function NewRepository({- org,- name,+ accessToken,+ accounts,+ onConfigureGitHubAppClick,}: Props) {+ const [name, setName] = useState('')+ const ghClient = useGitHubClient(accessToken)+ const [selectedAccount, setSelectedAccount] = useState<GitHubAccount | undefined>()+ const [isLoading, setIsLoading] = useState(false)+ const [error, setError] = useState('')++ async function handleCreateClick() {+ if (!selectedAccount || !accessToken || !ghClient) return+ if (!name) return+ if (isLoading) return++ try {+ // TODO: Create a repository+ setError('')+ setIsLoading(true)+ const data = await createRepo({+ client: ghClient,+ org: selectedAccount.isOrg ? selectedAccount.name : undefined,+ name,+ })+ console.log('new repo data', data)++ // TODO: Check if we have permissions to the new repository,+ // if not - present UI that asks user for a permission to the new repository+ // if we do - select the new repo+ } catch (err: any) {+ console.error('Error creating repository', err)+ setError(err.message)+ } finally {+ setIsLoading(false)+ }+ }++ useEffect(function selectDefaultAccount() {+ if (accounts.length > 0) setSelectedAccount(accounts[0])+ }, [accounts])+return (- <div className="flex-1 flex flex-col space-y-4 items-center justify-start rounded-md">- <RepoOwnerSelect- owners={['mlejva', 'e2b-dev']}- />- <RepoNameInput />-- <button- className="rounded bg-white/10 px-2 py-1 text-sm text-white font-medium hover:bg-white/20"- >Create</button>+ <div+ className={clsx(+ 'p-2 flex-1 flex flex-col space-y-4 items-center justify-start rounded-md',+ !accessToken && 'border border-gray-700',+ )}+ >+ {!accessToken && (+ <div className="flex-1 flex flex-col items-center justify-center">+ <span className="mb-2 text-sm text-gray-400 font-semibold text-center">+ We need access to a GitHub account to create new repositories+ </span>+ <ConfigureGitHubButton+ onClick={onConfigureGitHubAppClick}+ />+ </div>+ )}++ {accessToken && (+ <>+ <RepoAccountSelect+ accounts={accounts}+ selectedAccount={selectedAccount}+ onSelectedAccountChange={setSelectedAccount}+ onAddGithubAccountClick={configureGitHubApp}+ />++ <RepoNameInput+ value={name}+ onChange={e => setName(e.target.value)}+ />++ <button+ className="w-8 min-w-[64px] flex items-center justify-center rounded bg-white/10 px-2 py-1 text-sm text-white font-medium hover:bg-white/20"+ onClick={handleCreateClick}+ >+ {isLoading ? (+ <SpinnerIcon />+ ) : (+ <span>Create</span>+ )}+ </button>++ {error && (+ <AlertError+ title="Error creating repository"+ infoItems={[error]}+ />+ )}+ </>+ )}</div>)}diff --git a/components/SelectRepository/RepoSwitch.tsx b/components/SelectRepository/RepoSwitch.tsxindex 65154b23e..f63545dd4 100644--- a/components/SelectRepository/RepoSwitch.tsx+++ b/components/SelectRepository/RepoSwitch.tsx@@ -23,7 +23,7 @@ function RepoSwitch({)}onClick={() => onChange('new')}>- Create new one+ Create New Repository</div><divclassName={clsx(@@ -32,7 +32,7 @@ function RepoSwitch({)}onClick={() => onChange('existing')}>- Select existing+ Select Existing Repository</div></div></div>diff --git a/components/SelectRepository/index.tsx b/components/SelectRepository/index.tsxindex 7ccf52a06..30ced39ee 100644--- a/components/SelectRepository/index.tsx+++ b/components/SelectRepository/index.tsx@@ -1,4 +1,5 @@import {+ useEffect,useState,} from 'react'import {@@ -10,26 +11,49 @@ import {import { configureGitHubApp } 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[]- hasAccessToken: boolean+ accessToken?: stringselectedRepositoryID?: numberonRepoSelection: (repoID: number) => void}function SelectRepository({repos,- hasAccessToken,+ accessToken,selectedRepositoryID,onRepoSelection,}: 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])return (<>@@ -57,7 +81,7 @@ function SelectRepository({/>{selected === 'existing' && (<ExistingRepositories- hasAccessToken={hasAccessToken}+ accessToken={accessToken}repos={repos}onConfigureGitHubAppClick={configureGitHubApp}onRepoSelection={onRepoSelection}@@ -65,8 +89,10 @@ function SelectRepository({)}{selected === 'new' && (<NewRepository- org=""- name=""+ accounts={githubAccounts}+ // onRepoSelection={onRepoSelection}+ accessToken={accessToken}+ onConfigureGitHubAppClick={configureGitHubApp}/>)}<buttondiff --git a/github/repo.ts b/github/repo.tsindex 0a8928b2b..e3cde7e8a 100644--- a/github/repo.ts+++ b/github/repo.ts@@ -24,7 +24,7 @@ export async function createRepo({ client, name, org, isPrivate }: {private: isPrivate,auto_init: true,})- return { repositoryID: data.id }+ return data}const { data } = await client.repos.createForAuthenticatedUser({@@ -32,6 +32,5 @@ export async function createRepo({ client, name, org, isPrivate }: {private: isPrivate,auto_init: true,})-- return { repositoryID: data.id }+ return data}diff --git a/hooks/useRepositories.ts b/hooks/useRepositories.tsindex a72bc774c..8d90467ad 100644--- a/hooks/useRepositories.ts+++ b/hooks/useRepositories.ts@@ -3,10 +3,8 @@ import { GitHubClient } from 'github/client'async function fetchRepos(client: GitHubClient) {const installations = await client.apps.listInstallationsForAuthenticatedUser()-const repos = await Promise.all(installations.data.installations.map(async i => {- console.log('installation', i)try {const repos = await client.apps.listInstallationReposForAuthenticatedUser({installation_id: i.id,diff --git a/pages/agent/smol-developer/setup-old.tsx b/pages/agent/smol-developer/setup-old.tsxnew file mode 100644index 000000000..ce038cb7b--- /dev/null+++ b/pages/agent/smol-developer/setup-old.tsx@@ -0,0 +1,171 @@+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 { nanoid } from 'nanoid'+import { useState } from 'react'++import { serverCreds } from 'db/credentials'+import Repos, { RepoSetup } from 'components/Repos'+import Button from 'components/Button'+import { getDefaultModelConfig, getModelArgs, ModelConfig } from 'state/model'+import { TemplateID } from 'state/template'+import { Creds } from 'hooks/useModelProviderArgs'++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+ modelConfig: ModelConfig+}++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: {} }+}++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 getSmolDevModelConfig(creds: Creds): ModelConfig {+ const templateID = TemplateID.SmolDeveloper+ const modelConfig = getDefaultModelConfig(templateID)+ return {+ name: modelConfig.name,+ provider: modelConfig.provider,+ args: getModelArgs(modelConfig, creds),+ prompt: [],+ }+}++function Repo() {+ const supabaseClient = useSupabaseClient()+ const user = useUser()+ const session = useSession()+ const sessionCtx = useSessionContext()+ const [selectedRepo, setSelectedRepo] = useState<RepoSetup>()+ const [initialPrompt, setInitialPrompt] = useState<string>()+ const [openAIAPIKey, setOpenAIAPIKey] = useState<string>()++ async function signOut() {+ await supabaseClient.auth.signOut()+ location.reload()+ }++ const {+ trigger: createAgent,+ } = useSWRMutation('/api/agent', handlePostAgent)++ async function deployAgent() {+ if (!selectedRepo) return+ if (!initialPrompt) return+ if (!openAIAPIKey) return+ console.log('selectedRepo', selectedRepo)++ const modelConfig = getSmolDevModelConfig({+ OpenAI: {+ creds: {+ openai_api_key: openAIAPIKey,+ },+ },+ })++ await createAgent({+ defaultBranch: selectedRepo.defaultBranch,+ installationID: selectedRepo.installationID,+ owner: selectedRepo.owner,+ repo: selectedRepo.repo,+ repositoryID: selectedRepo.repositoryID,+ title: 'Smol PR',+ branch: `pr/smol-dev/${nanoid(6).toLowerCase()}`,+ body: initialPrompt,+ commitMessage: 'Smol dev initial commit',+ modelConfig,+ })+ }++ return (+ <div+ className="+ p-8+ flex-1+ flex+ flex-col+ space-y-4+ "+ >+ <div+ className="+ max-w-xl+ w-full+ max-h-[400px]+ flex-1+ flex+ flex-col+ self-center+ justify-center+ space-y-4+ "+ >+ {!sessionCtx.isLoading && user && (+ <Button+ text="Sign out"+ onClick={signOut}+ />+ )}+ Select repo+ {user &&+ <Repos+ onRepoSelection={setSelectedRepo}+ />+ }+ </div>+ <Button+ text='Deploy Smol developer'+ onClick={deployAgent}+ />+ </div>+ )+}++export default Repodiff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsxindex ce038cb7b..27656212e 100644--- a/pages/agent/smol-developer/setup.tsx+++ b/pages/agent/smol-developer/setup.tsx@@ -1,20 +1,19 @@-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'+ useState,+ useCallback,+} from 'react'import useSWRMutation from 'swr/mutation'-import { nanoid } from 'nanoid'-import { useState } from 'react'+import type { GetServerSideProps } from 'next'+import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'+import { useSupabaseClient } from '@supabase/auth-helpers-react'+import Steps from 'components/Steps'+import SelectRepository from 'components/SelectRepository'import { serverCreds } from 'db/credentials'-import Repos, { RepoSetup } from 'components/Repos'-import Button from 'components/Button'-import { getDefaultModelConfig, getModelArgs, ModelConfig } from 'state/model'-import { TemplateID } from 'state/template'-import { Creds } from 'hooks/useModelProviderArgs'+import { useGitHubClient } from 'hooks/useGitHubClient'+import { useRepositories } from 'hooks/useRepositories'+import { useLocalStorage } from 'hooks/useLocalStorage'+import useListenOnMessage from 'hooks/useListenOnMessage'export interface PostAgentBody {// ID of the installation of the GitHub App@@ -35,9 +34,25 @@ export interface PostAgentBody {branch: string// Commit message for the PR first empty commitcommitMessage: string- modelConfig: ModelConfig}+// export interface Repository {+// repositoryID: number+// installationID: number+// fullName: string+// branches?: string[]+// defaultBranch: string+// url: string+// owner: string+// name: string+// }++const steps = [+ { name: 'Select Repository', status: 'current' },+ { name: 'Write Instructions', status: 'upcoming' },+ { name: 'Step 3', status: 'upcoming' },+]+export const getServerSideProps: GetServerSideProps = async (ctx) => {const supabase = createServerSupabaseClient(ctx, serverCreds)const {@@ -67,105 +82,96 @@ async function handlePostAgent(url: string, { arg }: { arg: PostAgentBody }) {}).then(r => r.json())}-function getSmolDevModelConfig(creds: Creds): ModelConfig {- const templateID = TemplateID.SmolDeveloper- const modelConfig = getDefaultModelConfig(templateID)- return {- name: modelConfig.name,- provider: modelConfig.provider,- args: getModelArgs(modelConfig, creds),- prompt: [],- }-}--function Repo() {+function Setup() {const supabaseClient = useSupabaseClient()- const user = useUser()- const session = useSession()- const sessionCtx = useSessionContext()- const [selectedRepo, setSelectedRepo] = useState<RepoSetup>()- const [initialPrompt, setInitialPrompt] = useState<string>()- const [openAIAPIKey, setOpenAIAPIKey] = useState<string>()-- async function signOut() {- await supabaseClient.auth.signOut()- location.reload()- }+ const [currentStep, setCurrentStep] = useState(0)+ const [selectedRepositoryID, setSelectedRepositoryID] = useState<number>()+ // 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 handleMessageEvent = useCallback((event: MessageEvent) => {+ if (event.data.accessToken) {+ setAccessToken(event.data.accessToken)+ } else if (event.data.installationID) {+ refetch()+ }+ }, [refetch, setAccessToken])+ useListenOnMessage(handleMessageEvent)const {trigger: createAgent,} = useSWRMutation('/api/agent', handlePostAgent)- async function deployAgent() {- if (!selectedRepo) return- if (!initialPrompt) return- if (!openAIAPIKey) return- console.log('selectedRepo', selectedRepo)-- const modelConfig = getSmolDevModelConfig({- OpenAI: {- creds: {- openai_api_key: openAIAPIKey,- },- },+ // 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,+ // })+ // }++ function handleRepoSelection(repoID: number) {+ setSelectedRepositoryID(repoID)+ setCurrentStep(val => {+ const newVal = val + 1+ steps[val].status = 'complete'+ steps[newVal].status = 'current'+ return newVal})+ }- await createAgent({- defaultBranch: selectedRepo.defaultBranch,- installationID: selectedRepo.installationID,- owner: selectedRepo.owner,- repo: selectedRepo.repo,- repositoryID: selectedRepo.repositoryID,- title: 'Smol PR',- branch: `pr/smol-dev/${nanoid(6).toLowerCase()}`,- body: initialPrompt,- commitMessage: 'Smol dev initial commit',- modelConfig,- })+ async function signOut() {+ await supabaseClient.auth.signOut()+ location.reload()}return (- <div- className="- p-8- flex-1- flex- flex-col- space-y-4- "- >- <div- className="- max-w-xl- w-full- max-h-[400px]- flex-1- flex- flex-col- self-center- justify-center- space-y-4- "- >- {!sessionCtx.isLoading && user && (- <Button- text="Sign out"- onClick={signOut}- />- )}- Select repo- {user &&- <Repos- onRepoSelection={setSelectedRepo}+ <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">+ <span />+ <button+ className="text-sm font-semibold text-white"+ onClick={signOut}+ >+ Log out+ </button>+ </div>+ <div className="overflow-hidden flex-1 mx-auto w-full max-w-lg flex flex-col">+ <Steps steps={steps} />+ <div className="h-px bg-gray-700 my-8" />++ {currentStep === 0 ? (+ <SelectRepository+ repos={repos}+ selectedRepositoryID={selectedRepositoryID}+ onRepoSelection={handleRepoSelection}+ accessToken={accessToken}/>- }+ ) : currentStep === 1 ? (+ <div>prompt</div>+ ) : currentStep === 2 ? (+ <div>keys + deploy</div>+ ) : null}</div>- <Button- text='Deploy Smol developer'- onClick={deployAgent}- /></div>)}-export default Repo+export default Setupdiff --git a/pages/agent/smol-developer/setup2.tsx b/pages/agent/smol-developer/setup2.tsxdeleted file mode 100644index d29ad4914..000000000--- a/pages/agent/smol-developer/setup2.tsx+++ /dev/null@@ -1,177 +0,0 @@-import {- useState,- useCallback,-} 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 Steps from 'components/Steps'-import SelectRepository from 'components/SelectRepository'-import { serverCreds } from 'db/credentials'-import { useGitHubClient } from 'hooks/useGitHubClient'-import { useRepositories } from 'hooks/useRepositories'-import { useLocalStorage } from 'hooks/useLocalStorage'-import useListenOnMessage from 'hooks/useListenOnMessage'--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-}--// export interface Repository {-// repositoryID: number-// installationID: number-// fullName: string-// branches?: string[]-// defaultBranch: string-// url: string-// owner: string-// name: string-// }--const steps = [- { name: 'Select Repository', status: 'current' },- { name: 'Write Instructions', status: 'upcoming' },- { name: 'Step 3', status: 'upcoming' },-]--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: {} }-}--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 Setup() {- const supabaseClient = useSupabaseClient()- const [currentStep, setCurrentStep] = useState(0)- const [selectedRepositoryID, setSelectedRepositoryID] = useState<number>()- // 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 handleMessageEvent = useCallback((event: MessageEvent) => {- if (event.data.accessToken) {- setAccessToken(event.data.accessToken)- } else if (event.data.installationID) {- refetch()- }- }, [refetch, setAccessToken])- useListenOnMessage(handleMessageEvent)-- 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,- // })- // }-- function handleRepoSelection(repoID: number) {- setSelectedRepositoryID(repoID)- setCurrentStep(val => {- const newVal = val + 1- steps[val].status = 'complete'- steps[newVal].status = 'current'- return newVal- })- }-- async function signOut() {- await supabaseClient.auth.signOut()- location.reload()- }-- 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">- <span />- <button- className="text-sm font-semibold text-white"- onClick={signOut}- >- Log out- </button>- </div>- <div className="overflow-hidden flex-1 mx-auto w-full max-w-lg flex flex-col">- <Steps steps={steps} />- <div className="h-px bg-gray-700 my-8" />-- {currentStep === 0 ? (- <SelectRepository- repos={repos}- selectedRepositoryID={selectedRepositoryID}- onRepoSelection={handleRepoSelection}- hasAccessToken={!!accessToken}- />- ) : currentStep === 1 ? (- <div>prompt</div>- ) : currentStep === 2 ? (- <div>keys + deploy</div>- ) : null}- </div>- </div>- )-}--export default Setup