Skip to content

armgit / E2B

Public Imported from GitHub
0

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

wip

Vasek Mlejnsky7e5540d894c8
diff --git a/apps/docs/src/app/getting-started/api-key/APIKey.tsx b/apps/docs/src/app/getting-started/api-key/APIKey.tsx
index 883032cbd..04460fe7d 100644
--- a/apps/docs/src/app/getting-started/api-key/APIKey.tsx
+++ b/apps/docs/src/app/getting-started/api-key/APIKey.tsx
@@ -59,6 +59,7 @@ function SecretBlock({ name, description, secret, posthog, tip }) {
</div>
);
}
+
function APIKey() {
const signIn = useSignIn();
const { user } = useUser();
@@ -104,15 +105,15 @@ function APIKey() {
tip={
<Note>
<div className="flex flex-col">
- <span>To authenticate without the browser, you can set <code>E2B_ACCESS_TOKEN</code> as an environment variable.</span>
- <span>This can be useful for CI/CD pipelines.</span>
+ <span>To authenticate without the browser, you can set <code>E2B_ACCESS_TOKEN</code> as an environment variable.</span>
+ <span>This can be useful for CI/CD pipelines.</span>
</div>
</Note>
}
/>
</div>
) : (
- <div className="mt-6">
+ <div className="flex flex-col items-start justiy-start gap-4 mt-6">
<span>You can get your API key by signing up.</span>
<Button onClick={() => signIn()}>Sign up to get your API key</Button>
</div>
diff --git a/apps/docs/src/app/layout.tsx b/apps/docs/src/app/layout.tsx
index 72b51f37a..8a6f8272d 100644
--- a/apps/docs/src/app/layout.tsx
+++ b/apps/docs/src/app/layout.tsx
@@ -8,6 +8,7 @@ import { Layout } from '@/components/Layout'
import '@/styles/tailwind.css'
import { PostHogAnalytics } from '@/utils/usePostHog'
import { Section } from '@/components/SectionProvider'
+import { Banner } from '@/components/Banner'
export const metadata: Metadata = {
title: {
@@ -41,17 +42,18 @@ export default async function RootLayout({ children }) {
className="h-full"
suppressHydrationWarning
>
- <body className="flex min-h-full bg-white antialiased dark:bg-zinc-900">
- <Providers>
- <div className="w-full">
- <Layout allSections={allSections}>
- {children}
- <PostHogAnalytics/>
- <Analytics/>
- </Layout>
- </div>
- </Providers>
- </body>
+ <body className="flex min-h-full bg-white antialiased dark:bg-zinc-900">
+ <Providers>
+ <div className="w-full">
+ <Banner />
+ <Layout allSections={allSections}>
+ {children}
+ <PostHogAnalytics />
+ <Analytics />
+ </Layout>
+ </div>
+ </Providers>
+ </body>
</html>
)
}
diff --git a/apps/docs/src/app/pricing/Promo.tsx b/apps/docs/src/app/pricing/Promo.tsx
new file mode 100644
index 000000000..4d99e8083
--- /dev/null
+++ b/apps/docs/src/app/pricing/Promo.tsx
@@ -0,0 +1,70 @@
+'use client'
+
+import { useState } from 'react'
+import { Button } from '@/components/Button'
+import { useSignIn } from '@/utils/useSignIn'
+import { useUser } from '@/utils/useUser'
+
+function sendPromoCode(promoCode: string, teamID: string) {
+ return fetch('/docs/pricing/promo', {
+ method: 'POST',
+ body: JSON.stringify({
+ teamID,
+ promoCode,
+ }),
+ })
+}
+
+function Promo() {
+ const [code, setCode] = useState('')
+ const [error, setError] = useState('')
+ const { user } = useUser()
+ const signIn = useSignIn()
+
+ async function applyPromoCode() {
+ if (!code) return
+ if (!user) {
+ setError('You must be signed in to apply a promo code')
+ }
+
+ // TODO: Actually apply the promo code
+ const response = await sendPromoCode(code, user.teams[0].id)
+ const responseData = await response.json()
+
+ console.log('repsonseData', responseData)
+ if (responseData.error) {
+ console.error('Error applying promo code:', responseData.error)
+ setError(responseData.error)
+ } else {
+ // TODO: We applied the promo code, what now?
+ console.log('Promo code applied successfully')
+
+ setCode('')
+ }
+ }
+
+ return (
+ <div className="flex flex-col items-start justify-start gap-1">
+ <div className="flex items-center justify-start gap-2">
+ <div className="flex flex-col items-start justify-start">
+ <input
+ className="p-2 min-w-[300px] bg-transparent text-zinc-900 outline-none placeholder:text-zinc-500 dark:text-white sm:text-sm border border-gray-800 rounded-lg"
+ placeholder="Enter promo code to unlock Pro tier"
+ value={code}
+ onChange={e => setCode(e.target.value)}
+ />
+ </div>
+ <Button
+ onClick={applyPromoCode}
+ >
+ Apply
+ </Button>
+ </div>
+ {error && (
+ <span className="text-red-500 font-medium">{error}</span>
+ )}
+ </div>
+ )
+}
+
+export default Promo
\ No newline at end of file
diff --git a/apps/docs/src/app/pricing/page.mdx b/apps/docs/src/app/pricing/page.mdx
index fbfbfdc02..60dc675b3 100644
--- a/apps/docs/src/app/pricing/page.mdx
+++ b/apps/docs/src/app/pricing/page.mdx
@@ -1,3 +1,5 @@
+import Promo from './Promo'
+
# Pricing
## Hobby tier (free)
@@ -8,6 +10,9 @@
- Up to 20 concurrently running sandboxes {{ className: 'lead' }}
## Pro tier (paid)
+
+<Promo/>
+
- 4 vCPU {{ className: 'lead' }}
- 4 GB RAM {{ className: 'lead' }}
- 5 GB free disk storage {{ className: 'lead' }}
diff --git a/apps/docs/src/app/pricing/promo/route.ts b/apps/docs/src/app/pricing/promo/route.ts
new file mode 100644
index 000000000..887067347
--- /dev/null
+++ b/apps/docs/src/app/pricing/promo/route.ts
@@ -0,0 +1,69 @@
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient(
+ process.env.NEXT_PUBLIC_SUPABASE_URL,
+ process.env.SUPABASE_SERVICE_ROLE_KEY,
+)
+
+export const dynamic = 'force-dynamic' // defaults to force-static
+export async function POST(request: Request) {
+
+ // Read json data from request
+ const { promoCode, teamID } = await request.json()
+
+ if (!promoCode) {
+ return new Response('Missing promo code', { status: 400 })
+ }
+
+ if (!teamID) {
+ return new Response('Missing team ID', { status: 400 })
+ }
+
+ // Check if there's associated tier with promo code
+ const { data: tiersData, error: tiersError } = await supabase
+ .from('tiers')
+ .select('id, promo_code, promo_valid_from, promo_valid_to')
+ .eq('promo_code', promoCode)
+
+ if (tiersError) {
+ return new Response(tiersError.message, { status: 500 })
+ }
+
+ if (tiersData.length === 0) {
+ return Response.json({
+ error: `Invalid promo code '${promoCode}'`,
+ })
+ }
+
+
+ const { data: teamData, error: teamError } = await supabase
+ .from('teams')
+ .select('tier')
+ .eq('id', teamID)
+
+ if (tiersError) {
+ return new Response(teamError.message, { status: 500 })
+ }
+
+ if (teamData.length === 0) {
+ return Response.json({
+ error: `Invalid team ID '${teamID}' - team not found`,
+ })
+ }
+
+ const teamTier: string = teamData[0].tier
+
+ // If team tier isn't a pro tier already, apply the promo tier
+ if (teamTier.startsWith('free')) {
+ await supabase
+ .from('teams')
+ .update({ tier: tiersData[0].id })
+ .eq('id', teamID)
+ } else {
+ console.log('Team doesn\'t have a free tier, not applying promo')
+ }
+
+ return Response.json({
+ message: `Applied promo code '${promoCode}' to team '${teamID}'`,
+ })
+}
\ No newline at end of file
diff --git a/apps/docs/src/components/Banner.tsx b/apps/docs/src/components/Banner.tsx
new file mode 100644
index 000000000..19e1de15a
--- /dev/null
+++ b/apps/docs/src/components/Banner.tsx
@@ -0,0 +1,19 @@
+'use client'
+import { useState } from 'react'
+import { useUser } from '@/utils/useUser'
+export function Banner() {
+ const [promoEnd, setPromoEnd] = useState(100)
+ const { user } = useUser()
+
+ console.log('user', user)
+
+
+ if (!user?.pricingTier.isPromo) return null;
+
+ return (
+ <div className="p-2">
+ <span>You&apos;re on a trial Pro tier. Your trial will end on {promoEnd}.</span>
+ <span>Please reach if you want to stay on the Pro tier</span>
+ </div>
+ )
+}
diff --git a/apps/docs/src/utils/useUser.tsx b/apps/docs/src/utils/useUser.tsx
index 34cb4fd51..b8d342d12 100644
--- a/apps/docs/src/utils/useUser.tsx
+++ b/apps/docs/src/utils/useUser.tsx
@@ -17,17 +17,21 @@ type UserContextType = {
isLoading: boolean;
session: Session | null;
user:
- | (User & {
+ | (User & {
teams: Team[];
apiKeys: any[];
accessToken: string;
defaultTeamId: string;
+ pricingTier: {
+ id: string,
+ isPromo: boolean,
+ endsAt: string
+ }
})
- | null;
+ | null;
error: Error | null;
};
-
export const UserContext = createContext(undefined)
export const CustomUserContextProvider = (props) => {
@@ -99,8 +103,30 @@ export const CustomUserContextProvider = (props) => {
if (teamsError) Sentry.captureException(teamsError)
// TODO: Adjust when user can be part of multiple teams
// @ts-ignore
- const teams = userTeams?.map(userTeam=> userTeam.teams as Team)
- const defaultTeam= teams?.filter(team => team.is_default)?.[0]
+ const teams = userTeams?.map(userTeam => userTeam.teams as Team)
+ const defaultTeam = teams?.filter(team => team.is_default)?.[0]
+
+
+ // Fetch user's pricing tier
+ const { data, error: pricingTierError } = await supabase
+ .from('teams')
+ .select('tier')
+ .eq('id', teams[0].id)
+ if (pricingTierError) Sentry.captureException(pricingTierError)
+ const pricingTier: string = data?.[0]?.tier
+ const isPromoTier = pricingTier.startsWith('promo')
+ let promoEndsAt: string | null = null
+ // Fetch promo end date
+ if (isPromoTier) {
+ console.log('pricingTier', pricingTier)
+ const { data: promoData, error: promoError } = await supabase
+ .from('tiers')
+ .select('promo_ends_at')
+ .eq('id', pricingTier)
+ if (promoError) Sentry.captureException(promoError)
+ console.log('promoData', promoData)
+ promoEndsAt = promoData?.[0]?.promo_ends_at
+ }
const { data: apiKeys, error: apiKeysError } = await supabase
.from('team_api_keys')
@@ -132,6 +158,11 @@ export const CustomUserContextProvider = (props) => {
accessToken: accessToken?.access_token,
defaultTeamId,
error: teamsError || apiKeysError,
+ pricingTier: {
+ id: pricingTier,
+ isPromo: isPromoTier,
+ endsAt: promoEndsAt,
+ },
})
setIsLoading(false)
}