Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Refactorize
Vasek Mlejnsky62779e47c0b4
diff --git a/components/DashboardHome.tsx b/components/DashboardHome.tsxnew file mode 100644index 000000000..205eca46a--- /dev/null+++ b/components/DashboardHome.tsx@@ -0,0 +1,127 @@+import {+ useState,+} from 'react'+import {+ Zap,+ ListEnd,+ Menu,+} from 'lucide-react'+import { useRouter } from 'next/router'+import { usePostHog } from 'posthog-js/react'+import { useSupabaseClient } from '@supabase/auth-helpers-react'++import { deployments, projects } from 'db/prisma'+import AgentList from 'components/AgentList'+import AgentRunsList from 'components/AgentRunsList'+import DashboardDesktopSidebar from 'components/Sidebar/DashboardDesktopSidebar'+import DashboardMobileSidebar from 'components/Sidebar/DashboardMobileSidebar'+import FeedbackButton from 'components/FeedbackButton'++const navigation = [+ {+ name: 'Deployed Agents',+ view: 'deployed',+ icon: Zap,+ },+ {+ name: 'Agent Runs',+ view: 'runs',+ icon: ListEnd,+ },+]++export interface Props {+ projects: (projects & { deployments: deployments[] })[]+}++function DashboardHome({+ projects,+}: Props) {+ const supabaseClient = useSupabaseClient()+ const router = useRouter()+ const [isSidebarOpen, setIsSidebarOpen] = useState(false)+ const posthog = usePostHog()++ const view = router.query.view as string | undefined+ const selectedAgentInstanceID = router.query.projectID as string | undefined++ async function signOut() {+ await supabaseClient.auth.signOut()+ posthog?.reset(true)+ router.push('/sign')+ }++ function selectAgent(e: any, projectID: string) {+ e.preventDefault()+ posthog?.capture('selected deployed agent', { projectID: projectID })+ router.push(`/?view=runs&projectID=${projectID}`, undefined, { shallow: true })+ }++ const projectsWithDeployments = projects+ .filter(p => {+ if (p.deployments.length !== 1) return false++ const deployment = p.deployments[0]+ const auth = deployment.auth as any+ if (!auth) return false+ return deployment.enabled+ })+ .map(p => ({+ project: p,+ deployment: p.deployments[0],+ }))++ return (+ <div className="overflow-hidden">+ <DashboardMobileSidebar+ isSidebarOpen={isSidebarOpen}+ onSetSidebarOpen={setIsSidebarOpen}+ onSignOut={signOut}+ navigation={navigation}+ />++ <DashboardDesktopSidebar+ onSignOut={signOut}+ navigation={navigation}+ />++ <div className="xl:pl-72 flex flex-col max-h-full">+ {/* Mobile menu icon */}+ <div className="xl:hidden sticky top-0 z-40 flex justify-between h-16 shrink-0 items-center gap-x-6 border-b border-white/5 bg-gray-900 px-4 shadow-sm sm:px-6 lg:px-8">+ <button type="button" className="-m-2.5 p-2.5 text-white xl:hidden" onClick={() => setIsSidebarOpen(true)}>+ <span className="sr-only">Open sidebar</span>+ <Menu aria-hidden="true" />+ </button>++ <div className="xl:hidden">+ <FeedbackButton+ onClick={() => { console.log('todo') }}+ />+ </div>+ </div>++ <div className="hidden xl:flex py-2 px-6 border-b border-white/5">+ <FeedbackButton+ onClick={() => { console.log('todo') }}+ />+ </div>++ {view === 'deployed' ? (+ <AgentList+ agents={projectsWithDeployments}+ onSelectAgent={selectAgent}+ />+ ) : view === 'runs' ? (+ <AgentRunsList+ allDeployedAgents={projectsWithDeployments}+ initialSelectedAgentID={selectedAgentInstanceID}+ />+ ) : (+ <span>404</span>+ )}+ </div>+ </div >+ )+}++export default DashboardHome\ No newline at end of filediff --git a/components/FeedbackButton.tsx b/components/FeedbackButton.tsxnew file mode 100644index 000000000..c07decf77--- /dev/null+++ b/components/FeedbackButton.tsx@@ -0,0 +1,23 @@+import {+ MessageCircle,+} from 'lucide-react'++export interface Props {+ onClick: (e: any) => void+}++function FeedbackButton({+ onClick,+}: Props) {+ return (+ <button+ className="group ml-auto flex items-center space-x-1 cursor-pointer transition-all py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10"+ onClick={onClick}+ >+ <MessageCircle size={14} className="text-gray-400 group-hover:text-gray-100 transition-all" />+ <span className="text-sm text-gray-400 group-hover:text-gray-100 transition-all">Send feedback to CEO</span>+ </button>+ )+}++export default FeedbackButton\ No newline at end of filediff --git a/components/Sidebar/DashboardDesktopSidebar.tsx b/components/Sidebar/DashboardDesktopSidebar.tsxnew file mode 100644index 000000000..363ff7d4f--- /dev/null+++ b/components/Sidebar/DashboardDesktopSidebar.tsx@@ -0,0 +1,76 @@+import clsx from 'clsx'+import Link from 'next/link'+import { useRouter } from 'next/router'++import { Navigation } from './types'++export interface Props {+ onSignOut: () => void+ navigation: Navigation+}++function DashboardDesktopSidebar({+ onSignOut,+ navigation,+}: Props) {+ const router = useRouter()+ const view = router.query.view as string | undefined++ return (+ <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 border-r border-white/5">+ {/* Logo */}+ {/* <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 space-y-6 py-[22px]">+ <div className="font-bold text-gray-100">+ Arken+ </div>+ <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}>+ <Link+ href={`/?view=${item.view}`}+ className={clsx(+ item.view === view+ ? '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'+ )}+ shallow+ >+ <item.icon size={16} className="shrink-0" aria-hidden="true" />+ {item.name}+ </Link>+ </li>+ ))}+ </ul>+ </li>+ <li className="-mx-6 mt-auto">+ <div+ className="flex items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-white"+ >+ <button+ className="text-sm font-semibold text-white"+ onClick={onSignOut}+ >+ Sign Out+ </button>+ </div>+ </li>+ </ul>+ </nav>+ </div>+ </div>+ )+}++export default DashboardDesktopSidebar\ No newline at end of filediff --git a/components/Sidebar/DashboardMobileSidebar.tsx b/components/Sidebar/DashboardMobileSidebar.tsxnew file mode 100644index 000000000..a19e6252a--- /dev/null+++ b/components/Sidebar/DashboardMobileSidebar.tsx@@ -0,0 +1,126 @@+import { Fragment } from 'react'+import Link from 'next/link'+import { Dialog, Transition } from '@headlessui/react'+import clsx from 'clsx'+import {+ X,+} from 'lucide-react'+import { useRouter } from 'next/router'++import { Navigation } from './types'++export interface Props {+ isSidebarOpen?: boolean+ onSetSidebarOpen: (isOpened: boolean) => void+ onSignOut: () => void+ navigation: Navigation+}++function DashboardMobileSidebar({+ isSidebarOpen,+ onSetSidebarOpen,+ onSignOut,+ navigation,+}: Props) {+ const router = useRouter()+ const view = router.query.view as string | undefined++ return (+ <Transition.Root show={isSidebarOpen} as={Fragment}>+ <Dialog as="div" className="relative z-50 xl:hidden" onClose={onSetSidebarOpen}>+ <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={() => onSetSidebarOpen(false)}>+ <span className="sr-only">Close sidebar</span>+ <X className="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">+ {/* Logo */}+ {/* <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}>+ <Link+ href={`/?view=${item.view}`}+ className={clsx(+ item.view === view+ ? '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'+ )}+ shallow+ >+ <item.icon size={16} className="shrink-0" aria-hidden="true" />+ {item.name}+ </Link>+ </li>+ ))}+ </ul>+ </li>+ <li className="-mx-6 mt-auto">+ <div+ className="flex items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-white"+ >+ <button+ className="text-sm font-semibold text-white"+ onClick={onSignOut}+ >+ Sign Out+ </button>+ </div>+ </li>+ </ul>+ </nav>+ </div>+ </Dialog.Panel>+ </Transition.Child>+ </div>+ </Dialog>+ </Transition.Root>+ )+}++export default DashboardMobileSidebar\ No newline at end of filediff --git a/components/Sidebar/types.ts b/components/Sidebar/types.tsnew file mode 100644index 000000000..ba6d0480e--- /dev/null+++ b/components/Sidebar/types.ts@@ -0,0 +1,9 @@+import {+ LucideIcon,+} from 'lucide-react'++export type Navigation = {+ name: string+ view: string+ icon: LucideIcon+}[]\ No newline at end of filediff --git a/pages/index.tsx b/pages/index.tsxindex 62f45e411..0421a5696 100644--- a/pages/index.tsx+++ b/pages/index.tsx@@ -1,37 +1,11 @@-import { useState, Fragment } from 'react'import type { GetServerSideProps, Redirect } from 'next'-import Link from 'next/link'import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'-import { Dialog, Transition } from '@headlessui/react'-import clsx from 'clsx'-import {- Zap,- ListEnd,- X,- Menu,- MessageCircle,-} from 'lucide-react'-import { useRouter } from 'next/router'-import { usePostHog } from 'posthog-js/react'-import { useSupabaseClient } from '@supabase/auth-helpers-react'++import { deployments, prisma, projects } from 'db/prisma'import { serverCreds } from 'db/credentials'-import AgentList from 'components/AgentList'-import AgentRunsList from 'components/AgentRunsList'--const navigation = [- {- name: 'Deployed Agents',- view: 'deployed',- icon: Zap,- },- {- name: 'Agent Runs',- view: 'runs',- icon: ListEnd,- },-]+import DashboardHome from 'components/DashboardHome'export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {const supabase = createServerSupabaseClient(ctx, serverCreds)@@ -129,231 +103,15 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {}}-interface Props {+export interface Props {projects: (projects & { deployments: deployments[] })[]}function Home({ projects }: Props) {- const supabaseClient = useSupabaseClient()- const router = useRouter()- const [sidebarOpen, setSidebarOpen] = useState(false)- const posthog = usePostHog()-- const view = router.query.view as string | undefined- const selectedAgentInstanceID = router.query.projectID as string | undefined-- async function signOut() {- await supabaseClient.auth.signOut()- posthog?.reset(true)- router.push('/sign')- }-- function selectAgent(e: any, projectID: string) {- e.preventDefault()- posthog?.capture('selected deployed agent', { projectID: projectID })- router.push(`/?view=runs&projectID=${projectID}`, undefined, { shallow: true })- }-- const projectsWithDeployments = projects- .filter(p => {- if (p.deployments.length !== 1) return false-- const deployment = p.deployments[0]- const auth = deployment.auth as any- if (!auth) return false- return deployment.enabled- })- .map(p => ({- project: p,- deployment: p.deployments[0],- }))-return (- <div className="overflow-hidden">- {/* Mobile sidebar */}- <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>- <X className="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">- {/* Logo */}- {/* <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}>- <Link- href={`/?view=${item.view}`}- className={clsx(- item.view === view- ? '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'- )}- shallow- >- <item.icon size={16} className="shrink-0" aria-hidden="true" />- {item.name}- </Link>- </li>- ))}- </ul>- </li>- <li className="-mx-6 mt-auto">- <div- className="flex items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-white"- >- <button- className="text-sm font-semibold text-white"- onClick={signOut}- >- Log out- </button>- </div>- </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 border-r border-white/5">- {/* Logo */}- {/* <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 space-y-6 py-[22px]">- <div className="font-bold text-gray-100">- Arken- </div>- <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}>- <Link- href={`/?view=${item.view}`}- className={clsx(- item.view === view- ? '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'- )}- shallow- >- <item.icon size={16} className="shrink-0" aria-hidden="true" />- {item.name}- </Link>- </li>- ))}- </ul>- </li>- <li className="-mx-6 mt-auto">- <div- className="flex items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-white"- >- <button- className="text-sm font-semibold text-white"- onClick={signOut}- >- Log out- </button>- </div>- </li>- </ul>- </nav>- </div>- </div>-- <div className="xl:pl-72 flex flex-col max-h-full">- {/* Mobile menu icon */}- <div className="xl:hidden sticky top-0 z-40 flex h-16 shrink-0 items-center gap-x-6 border-b border-white/5 bg-gray-900 px-4 shadow-sm sm:px-6 lg:px-8">- <button type="button" className="-m-2.5 p-2.5 text-white xl:hidden" onClick={() => setSidebarOpen(true)}>- <span className="sr-only">Open sidebar</span>- <Menu aria-hidden="true" />- </button>- </div>-- <div className="flex py-2 px-6 border-b border-white/5">- <button- className="group ml-auto flex items-center space-x-1 cursor-pointer transition-all py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10"- >- <MessageCircle size={14} className="text-gray-400 group-hover:text-gray-100 transition-all" />- <span className="text-sm text-gray-400 group-hover:text-gray-100 transition-all">Complain to the CEO</span>- </button>- </div>-- {view === 'deployed' ? (- <AgentList- agents={projectsWithDeployments}- onSelectAgent={selectAgent}- />- ) : view === 'runs' ? (- <AgentRunsList- allDeployedAgents={projectsWithDeployments}- initialSelectedAgentID={selectedAgentInstanceID}- />- ) : (- <span>404</span>- )}- </div>- </div >+ <DashboardHome+ projects={projects}+ />)}