Skip to content

armgit / E2B

Public Imported from GitHub
0

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

small changes and cleanups

ErikKaumkd01bee731cc4
diff --git a/apps/docs/src/app/(main)/dashboard/page.tsx b/apps/docs/src/app/(main)/dashboard/page.tsx
index 8375c3b8b..6d84c480b 100644
--- a/apps/docs/src/app/(main)/dashboard/page.tsx
+++ b/apps/docs/src/app/(main)/dashboard/page.tsx
@@ -1,11 +1,10 @@
'use client'
import { useState } from 'react'
-import { ChevronRight, CreditCard, LayoutPanelTop, LucideIcon, Package, PlusCircle, Settings, Users } from 'lucide-react'
+import { ChevronRight, CreditCard, Key, LucideIcon, PlusCircle, Settings, Users } from 'lucide-react'
import { GeneralContent } from '@/components/Dashboard/General'
import { BillingContent } from '@/components/Dashboard/Billing'
-import { SandboxesContent } from '@/components/Dashboard/Sandboxes'
import { TeamContent } from '@/components/Dashboard/Team'
import {
@@ -17,14 +16,16 @@ import {
} from '@/components/ui/dropdown-menu'
import { useUser } from '@/utils/useUser'
import { User } from '@supabase/supabase-js'
+import { KeysContent } from '@/components/Dashboard/Keys'
-const menuLabels = ['General', 'Billing', 'Sandboxes', 'Team', 'Templates'] as const
+// TODO: Sandbox and Templates tab deleted for now
+const menuLabels = ['General', 'Keys' ,'Billing', 'Team',] as const
type MenuLabel = typeof menuLabels[number]
export default function Dashboard() {
const { user, isLoading, error } = useUser()
- const [selectedItem, setSelectedItem] = useState<MenuLabel>('Billing')
+ const [selectedItem, setSelectedItem] = useState<MenuLabel>('General')
if (error) {
return <div>Error: {error.message}</div>
@@ -57,30 +58,24 @@ const Sidebar = ({ selectedItem, setSelectedItem, user }) => (
selected={selectedItem === 'General'}
onClick={() => setSelectedItem('General')}
/>
+ <MenuItem
+ icon={Key}
+ label="Keys"
+ selected={selectedItem === 'Keys'}
+ onClick={() => setSelectedItem('Keys')}
+ />
<MenuItem
icon={CreditCard}
label="Billing"
selected={selectedItem === 'Billing'}
onClick={() => setSelectedItem('Billing')}
/>
- <MenuItem
- icon={Package}
- label="Sandboxes"
- selected={selectedItem === 'Sandboxes'}
- onClick={() => setSelectedItem('Sandboxes')}
- />
<MenuItem
icon={Users}
label="Team"
selected={selectedItem === 'Team'}
onClick={() => setSelectedItem('Team')}
/>
- <MenuItem
- icon={LayoutPanelTop}
- label="Templates"
- selected={selectedItem === 'Templates'}
- onClick={() => setSelectedItem('Templates')}
- />
</div>
)
@@ -135,19 +130,16 @@ const MainContent = ({ selectedItem, user }: { selectedItem: MenuLabel, user: Us
switch (selectedItem) {
case 'General':
return <GeneralContent user={user} />
+ case 'Keys':
+ return <KeysContent user={user} />
case 'Billing':
return <BillingContent />
- case 'Sandboxes':
- return <SandboxesContent user={user} />
case 'Team':
return <TeamContent />
- case 'Templates':
- return <TemplatesContent />
default:
return <ErrorContent />
}
}
-const TemplatesContent = () => <div>Templates Content</div>
const ErrorContent = () => <div>Error Content</div>
diff --git a/apps/docs/src/components/Auth.tsx b/apps/docs/src/components/Auth.tsx
index eea8d6dc1..2ab324598 100644
--- a/apps/docs/src/components/Auth.tsx
+++ b/apps/docs/src/components/Auth.tsx
@@ -1,52 +1,16 @@
'use client'
-import clsx from 'clsx'
import Link from 'next/link'
import { LogOutIcon } from 'lucide-react'
import { useRouter } from 'next/navigation'
import { Button } from '@/components/Button'
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'
-import { useApiKey, useUser } from '@/utils/useUser'
-import { CopyButton } from '@/components/CopyButton'
-import { HeaderSeparator } from '@/components/HeaderUtils'
+import { useUser } from '@/utils/useUser'
import { usePostHog } from 'posthog-js/react'
-import { obfuscateSecret } from '@/utils/obfuscate'
-
-function CopyableSecret({
- secret = '',
- onAfterCopy,
- obfuscateStart,
- obfuscateEnd,
-}: {
- secret: string;
- onAfterCopy: () => void;
- obfuscateStart?: number;
- obfuscateEnd?: number;
-}) {
- return (
- <>
- <span className="whitespace-nowrap font-mono text-yellow-400 group-hover:opacity-25">
- {obfuscateSecret(secret, obfuscateStart, obfuscateEnd)}
- </span>
- <span className="absolute inset-0">
- <CopyButton
- code={secret}
- onAfterCopy={onAfterCopy}
- customPositionClassNames={clsx(
- 'top-[-2px] bottom-[2px]' /* nudge 2px up*/,
- 'left-[-6px] right-[-6px]' /* widen a little to fit nicely */,
- 'min-h-[28px]',
- )}
- />
- </span>
- </>
- )
-}
export const Auth = function () {
const { user, isLoading, error } = useUser()
- const apiKey = useApiKey()
const posthog = usePostHog()
const router = useRouter()
const supabase = createClientComponentClient()
@@ -93,22 +57,6 @@ export const Auth = function () {
<>
{user ? (
<div className="flex flex-col items-center gap-4 min-[540px]:flex-row">
- <div
- className="
- group relative flex
- flex-row
- gap-2 text-xs
- "
- >
- <span className="whitespace-nowrap font-bold text-zinc-400 group-hover:opacity-25">
- API Key
- </span>
- <CopyableSecret
- secret={apiKey}
- onAfterCopy={() => posthog?.capture('copied API key')}
- />
- </div>
- <HeaderSeparator />
<div className="flex items-center gap-2">
<div className="whitespace-nowrap text-xs font-bold">
{user.email}
diff --git a/apps/docs/src/components/Dashboard/Billing.tsx b/apps/docs/src/components/Dashboard/Billing.tsx
index f7add0fce..963f0691c 100644
--- a/apps/docs/src/components/Dashboard/Billing.tsx
+++ b/apps/docs/src/components/Dashboard/Billing.tsx
@@ -1,4 +1,3 @@
-import { ResponsiveBar } from '@nivo/bar'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useUser } from '@/utils/useUser'
@@ -14,6 +13,11 @@ export const BillingContent = () => {
return (
<div className="flex flex-col w-full h-full">
+ <div className='flex items-center space-x-4'>
+ <h2 className='font-bold text-xl'>Make changes to your billing</h2>
+ <ManageBilling />
+ </div>
+
{credits && (
<div className='flex flex-col space-y-2 pb-10'>
<h2 className='font-bold text-xl'>Credits left</h2>
@@ -25,71 +29,11 @@ export const BillingContent = () => {
<div>
<h2 className='font-bold pb-10 text-xl'>Billing history</h2>
</div>
- <BarChart className="aspect-[6/3] w-2/3 pb-10"/>
- <div className='flex items-center space-x-4'>
- <h2 className='font-bold text-xl'>Make changes to your billing</h2>
- <ManageBilling />
- </div>
</div>
)
}
-function BarChart(props: any) {
- return (
- <div {...props}>
- <ResponsiveBar
- data={[
- { name: 'Jan', amount: 111 },
- { name: 'Feb', amount: 157 },
- { name: 'Mar', amount: 129 },
- { name: 'Apr', amount: 150 },
- { name: 'May', amount: 119 },
- { name: 'Jun', amount: 72 },
- ]}
- keys={['amount']}
- indexBy="name"
- margin={{ top: 0, right: 0, bottom: 40, left: 40 }}
- padding={0.2}
- colors={['#FFAF78']}
- axisBottom={{
- tickSize: 0,
- tickPadding: 16,
- }}
- axisLeft={{
- tickSize: 0,
- tickValues: 4,
- tickPadding: 16,
- }}
- gridYValues={4}
- theme={{
- tooltip: {
- chip: {
- borderRadius: '9999px',
- },
- container: {
- fontSize: '12px',
- borderRadius: '6px',
- color: 'black',
- },
- },
- grid: {
- line: {
- stroke: '#f3f4f6',
- },
- },
- }}
- borderRadius={4} // Apply a border radius to the top corners of the bars
- tooltipLabel={({ id }) => `${id}`}
- enableLabel={false}
- role="application"
- ariaLabel="A bar chart showing data"
- />
- </div>
- )
-}
-
-
const ManageBilling = () => {
const { user } = useUser()
const [url, setURL] = useState('')
diff --git a/apps/docs/src/components/Dashboard/General.tsx b/apps/docs/src/components/Dashboard/General.tsx
index 4749adfaf..1c5215f65 100644
--- a/apps/docs/src/components/Dashboard/General.tsx
+++ b/apps/docs/src/components/Dashboard/General.tsx
@@ -1,137 +1,60 @@
'use client'
-import { useState } from 'react'
import { useToast } from '../ui/use-toast'
-import { v4 as uuidv4 } from 'uuid'
-import { Copy, Delete } from 'lucide-react'
import { Button } from '../Button'
-
-import {
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
- AlertDialogTrigger,
-} from '@/components/ui/alert-dialog'
import { User } from '@supabase/supabase-js'
import { createPagesBrowserClient } from '@supabase/auth-helpers-nextjs'
export const GeneralContent = ({user}: {user: User}) => {
const { toast } = useToast()
- const [isDialogOpen, setIsDialogOpen] = useState(false)
- const [currentKeyId, setCurrentKeyId] = useState<string | null>(null)
- const [hoveredKeyId, setHoveredKeyId] = useState<string | null>(null)
-
- //@ts-ignore
- const [apiKeys, setApiKeys] = useState<{ id: string, key: string, createdAt: string }[]>(user?.apiKeys.map((apiKey: any, index: any) => ({
- id: String(index + 1),
- key: apiKey.api_key,
- createdAt: apiKey.created_at,
- })) || [])
- const closeDialog = () => setIsDialogOpen(false)
- const openDialog = (id: string) => {
- setCurrentKeyId(id)
- setIsDialogOpen(true)
- }
-
- const deleteApiKey = () => {
- setApiKeys(apiKeys.filter(apiKey => apiKey.id !== currentKeyId))
- closeDialog()
- }
-
- const addApiKey = async() => {
+ const updateUserEmail = async() => {
const supabase = createPagesBrowserClient()
const res = await supabase
- .from('team_api_keys')
- .insert({
- team_id: user.id,
- api_key: uuidv4(),
- created_at: new Date().toISOString(),
+ .from('users')
+ .update({
+ email: user.email,
})
console.log(res)
toast({
- title: 'API key created',
- })
-
- const newKey = {
- id: uuidv4(),
- key: uuidv4(),
- createdAt: new Date().toISOString(),
- updatedAt: new Date().toISOString(),
- }
- setApiKeys([...apiKeys, newKey])
- }
-
- const copyToClipboard = (text: string) => {
- navigator.clipboard.writeText(text)
- toast({
- title: 'API Key copied to clipboard',
+ title: 'Email updated',
})
}
- const maskApiKey = (key: string) => {
- const firstFour = key.slice(0, 4)
- const lastTwo = key.slice(-2)
- const stars = '*'.repeat(key.length - 6) // use fixed-width character
- return `${firstFour}${stars}${lastTwo}`
- }
-
return(
<div className="flex flex-col w-full h-full">
- <div className="flex flex-col w-fit h-full">
+ <div className="flex flex-col h-full">
<h1 className="font-bold pb-10 text-xl">
- API Keys
+ Personal info
</h1>
-
- <p className='text-neutral-300 pb-2'>Active keys:</p>
-
- {apiKeys.map((apiKey) => (
- <div
- key={apiKey.id}
- className='flex w-full justify-between items-center border border-white/5 rounded-lg p-2 mb-4 space-x-4'
- onMouseEnter={() => setHoveredKeyId(apiKey.id)}
- onMouseLeave={() => setHoveredKeyId(null)}
- >
- <div className="font-mono text-sm">{hoveredKeyId === apiKey.id ? apiKey.key : maskApiKey(apiKey.key)}</div> {/* Use a monospace font */}
- <div className='flex items-center space-x-2'>
- <Copy className='hover:cursor-pointer' width={18} height={18} onClick={() => copyToClipboard(apiKey.key)} />
- <Delete className='hover:cursor-pointer' color='red' width={20} height={20} onClick={() => openDialog(apiKey.id)} />
- </div>
- </div>
- ))}
-
- <Button className='w-fit' onClick={addApiKey}>Add API Key</Button>
-
+ <span className='text-neutral-300 pb-2'>Email:</span>
+ <div className='flex w-full items-center space-x-2 pb-10'>
+ <input
+ type="text"
+ className="w-1/2 border border-white/10 text-sm focus:outline-none outline-none rounded-md p-2"
+ placeholder={user.email}
+ value={user.email}
+ onSubmit={updateUserEmail}
+ />
+ <Button variant='outline'>Save changes</Button>
</div>
- <AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
- <AlertDialogTrigger asChild>
- <Button variant="outline" style={{ display: 'none' }}>Show Dialog</Button>
- </AlertDialogTrigger>
- <AlertDialogContent className="bg-inherit text-white border-black">
- <AlertDialogHeader>
- <AlertDialogTitle>You are about to delete an API key</AlertDialogTitle>
- <AlertDialogDescription className='text-white/90'>
- This action cannot be undone. This will permanently delete the
- API key with immediate effect.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel className='border-white/10' onClick={closeDialog}>Cancel</AlertDialogCancel>
- <AlertDialogAction className='bg-red-500 text-white hover:bg-red-600' onClick={deleteApiKey}>Continue</AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
-
+ <span className='text-neutral-300 pb-2'>Change password:</span>
+ <div className='flex items-center space-x-2 pb-10'>
+ <input
+ type="text"
+ className="w-1/2 border border-white/10 text-sm focus:outline-none outline-none rounded-md p-2"
+ placeholder={user.email}
+ value={user.email}
+ onSubmit={updateUserEmail}
+ />
+ <Button variant='outline'>Change password</Button>
+ </div>
+ </div>
</div>
)
}
diff --git a/apps/docs/src/components/Dashboard/Keys.tsx b/apps/docs/src/components/Dashboard/Keys.tsx
new file mode 100644
index 000000000..8cc105068
--- /dev/null
+++ b/apps/docs/src/components/Dashboard/Keys.tsx
@@ -0,0 +1,133 @@
+import { Button } from '../Button'
+
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+} from '@/components/ui/alert-dialog'
+import { Copy, Delete } from 'lucide-react'
+import { useState } from 'react'
+import { useToast } from '../ui/use-toast'
+import { createPagesBrowserClient } from '@supabase/auth-helpers-nextjs'
+import { User } from '@supabase/supabase-js'
+import { v4 as uuidv4 } from 'uuid'
+
+
+export const KeysContent = ({user}: {user: User}) => {
+ const { toast } = useToast()
+ const [isDialogOpen, setIsDialogOpen] = useState(false)
+ const [currentKeyId, setCurrentKeyId] = useState<string | null>(null)
+ const [hoveredKeyId, setHoveredKeyId] = useState<string | null>(null)
+
+ //@ts-ignore
+ const [apiKeys, setApiKeys] = useState<{ id: string, key: string, createdAt: string }[]>(user?.apiKeys.map((apiKey: any, index: any) => ({
+ id: String(index + 1),
+ key: apiKey.api_key,
+ createdAt: apiKey.created_at,
+ })) || [])
+ const closeDialog = () => setIsDialogOpen(false)
+ const openDialog = (id: string) => {
+ setCurrentKeyId(id)
+ setIsDialogOpen(true)
+ }
+
+ const deleteApiKey = () => {
+ setApiKeys(apiKeys.filter(apiKey => apiKey.id !== currentKeyId))
+ closeDialog()
+ }
+
+ const addApiKey = async() => {
+ const supabase = createPagesBrowserClient()
+ const res = await supabase
+ .from('team_api_keys')
+ .insert({
+ team_id: user.id,
+ api_key: uuidv4(),
+ created_at: new Date().toISOString(),
+ })
+
+ console.log(res)
+
+ toast({
+ title: 'API key created',
+ })
+
+ const newKey = {
+ id: uuidv4(),
+ key: uuidv4(),
+ createdAt: new Date().toISOString(),
+ updatedAt: new Date().toISOString(),
+ }
+ setApiKeys([...apiKeys, newKey])
+ }
+
+ const copyToClipboard = (text: string) => {
+ navigator.clipboard.writeText(text)
+ toast({
+ title: 'API Key copied to clipboard',
+ })
+ }
+
+ const maskApiKey = (key: string) => {
+ const firstFour = key.slice(0, 4)
+ const lastTwo = key.slice(-2)
+ const stars = '*'.repeat(key.length - 6) // use fixed-width character
+ return `${firstFour}${stars}${lastTwo}`
+ }
+
+ return (
+ <div className="flex flex-col w-full h-full">
+ <div className="flex flex-col w-fit h-full">
+
+ <div className='flex flex-col w-full pb-10'>
+ <Button className='w-fit' onClick={addApiKey}>Add API Key</Button>
+ </div>
+
+ <p className='text-neutral-300 pb-2'>Active keys:</p>
+
+ {apiKeys.map((apiKey) => (
+ <div
+ key={apiKey.id}
+ className='flex w-full justify-between items-center border border-white/5 rounded-lg p-2 mb-4 space-x-4'
+ onMouseEnter={() => setHoveredKeyId(apiKey.id)}
+ onMouseLeave={() => setHoveredKeyId(null)}
+ >
+ <div className="font-mono text-sm">{hoveredKeyId === apiKey.id ? apiKey.key : maskApiKey(apiKey.key)}</div> {/* Use a monospace font */}
+ <div className='flex items-center space-x-2'>
+ <Copy className='hover:cursor-pointer' width={18} height={18} onClick={() => copyToClipboard(apiKey.key)} />
+ <Delete className='hover:cursor-pointer' color='red' width={20} height={20} onClick={() => openDialog(apiKey.id)} />
+ </div>
+ </div>
+ ))}
+
+
+ </div>
+
+ <AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
+ <AlertDialogTrigger asChild>
+ <Button variant="outline" style={{ display: 'none' }}>Show Dialog</Button>
+ </AlertDialogTrigger>
+ <AlertDialogContent className="bg-inherit text-white border-black">
+ <AlertDialogHeader>
+ <AlertDialogTitle>You are about to delete an API key</AlertDialogTitle>
+ <AlertDialogDescription className='text-white/90'>
+ This action cannot be undone. This will permanently delete the
+ API key with immediate effect.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel className='border-white/10' onClick={closeDialog}>Cancel</AlertDialogCancel>
+ <AlertDialogAction className='bg-red-500 text-white hover:bg-red-600' onClick={deleteApiKey}>Continue</AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+
+ </div>
+ )
+}
\ No newline at end of file