Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Prepare usage page

Vasek Mlejnsky7bcf573ad2b5
diff --git a/apps/docs/src/app/pricing/page.mdx b/apps/docs/src/app/pricing/page.mdx
index 3e3aed98f..0e6576acb 100644
--- a/apps/docs/src/app/pricing/page.mdx
+++ b/apps/docs/src/app/pricing/page.mdx
@@ -22,7 +22,7 @@ Additionally to the usage costs, you can also select a tier that includes dedica
<SwitchToHobbyButton/>
- One-time $100 of usage in credits
- Community support
-- 1 hours max sandbox session length
+- Up to 1 hour sandbox session length
- Up to 20 concurrently running sandboxes
- Hobby sandbox machine specs:
- 2 vCPU
@@ -35,7 +35,7 @@ Additionally to the usage costs, you can also select a tier that includes dedica
- Dedicated Slack channel with live Pro support from our team
- Prioritized features
- Customize your sandbox machine specs based on your needs ([let us know](/getting-help))
-- 24 hours max sandbox session length
+- Up to 24 hours sandbox session length
- Up to 100 concurrently running sandboxes
- Pro sandbox machine specs:
- 4 vCPU
diff --git a/apps/docs/src/app/usage/Credits.tsx b/apps/docs/src/app/usage/Credits.tsx
new file mode 100644
index 000000000..df22892f2
--- /dev/null
+++ b/apps/docs/src/app/usage/Credits.tsx
@@ -0,0 +1,65 @@
+'use client'
+
+import React from 'react'
+import {
+ Ticket,
+} from 'lucide-react'
+
+import { useUsage } from '@/utils/useUsage'
+
+function usedCredits(totalCosts: number, unpaidCosts: number) {
+ return totalCosts - unpaidCosts
+}
+
+function formatCurrency(value: number) {
+ return value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
+}
+
+function Credits() {
+ // TODO: If not logged in, show a message to log in
+ // TODO: Show user their plan
+ // TODO: Add "switch tier"/"manage billing" button
+ const { credits, costs } = useUsage()
+
+ return (
+ <div className="flex flex-col justify-start items-start">
+ <div className="flex flex-col justify-start items-start gap-1">
+ <div className="flex items-center gap-1">
+ <Ticket size={20} />
+ <span className="font-medium">Credits left</span>
+ </div>
+ <span className="text-sm font-mono text-green-300/80">${credits}</span>
+ </div>
+
+ <div className="flex flex-col justify-start items-start gap-1">
+ {costs.map((cost, index) => (
+ <React.Fragment key={index}>
+ <h3 className="text-xl">
+ {new Date(cost.year, cost.month - 1).toLocaleDateString('en-US', { month: 'long', year: 'numeric' })}
+ </h3>
+
+ <div className="flex flex-col justify-start items-start gap-4">
+ <div className="flex flex-col items-start justify-start gap-1">
+ <span className="font-bold">Total costs</span>
+ <span className="text-sm font-mono">${formatCurrency(cost.total_costs)}</span>
+ </div>
+
+ <div className="flex flex-col items-start justify-start gap-1">
+ <span className="font-bold">{new Date().getMonth() + 1 === cost.month ? 'To pay' : 'Paid'}</span>
+ <div className="flex items-center gap-3">
+ <span className="text-sm font-mono">${formatCurrency(cost.unpaid_costs)}</span>
+ {usedCredits(cost.total_costs, cost.unpaid_costs) > 0 &&
+ <span className="text-sm font-mono text-green-300/80">(${formatCurrency(usedCredits(cost.total_costs, cost.unpaid_costs))} credits used)</span>
+ }
+ </div>
+ </div>
+ </div>
+ </React.Fragment>
+ ))}
+ </div>
+
+ </div>
+ )
+}
+
+export default Credits
\ No newline at end of file
diff --git a/apps/docs/src/app/usage/page.mdx b/apps/docs/src/app/usage/page.mdx
new file mode 100644
index 000000000..952a55797
--- /dev/null
+++ b/apps/docs/src/app/usage/page.mdx
@@ -0,0 +1,7 @@
+import Credits from './Credits'
+
+# Usage
+
+Your sandbox usage for the past 3 months
+
+<Credits/>
\ No newline at end of file
diff --git a/apps/docs/src/components/Navigation/routes.tsx b/apps/docs/src/components/Navigation/routes.tsx
index 7968a3e97..16e0e52d7 100644
--- a/apps/docs/src/components/Navigation/routes.tsx
+++ b/apps/docs/src/components/Navigation/routes.tsx
@@ -20,7 +20,9 @@ import {
ShieldQuestion,
TerminalSquare,
Timer,
- Variable, HardDrive,
+ Variable,
+ HardDrive,
+ BarChart,
} from 'lucide-react'
import logoOpenAI from '@/images/logos/openai.svg'
@@ -33,23 +35,33 @@ export const routes = [
{ title: 'Introduction', href: '/' },
{
icon: (
- <HeartHandshake
+ <DollarSign
strokeWidth={1}
size={20}
/>
),
- title: 'Open source',
- href: '/open-source',
+ title: 'Pricing',
+ href: '/pricing',
},
{
icon: (
- <DollarSign
+ <BarChart
strokeWidth={1}
size={20}
/>
),
- title: 'Pricing',
- href: '/pricing',
+ title: 'Your Usage',
+ href: '/usage',
+ },
+ {
+ icon: (
+ <HeartHandshake
+ strokeWidth={1}
+ size={20}
+ />
+ ),
+ title: 'Open source',
+ href: '/open-source',
},
{
icon: (
diff --git a/apps/docs/src/utils/useUsage.tsx b/apps/docs/src/utils/useUsage.tsx
new file mode 100644
index 000000000..eaf430e18
--- /dev/null
+++ b/apps/docs/src/utils/useUsage.tsx
@@ -0,0 +1,66 @@
+'use client'
+
+import {
+ useEffect,
+ useState,
+ useCallback,
+} from 'react'
+
+import { useUser } from '@/utils/useUser'
+import { createPagesBrowserClient } from '@supabase/auth-helpers-nextjs'
+
+export interface MonthlyCosts {
+ month: number
+ year: number
+ total_costs: number
+ unpaid_costs: number
+}
+
+export function useUsage() {
+ const { user } = useUser()
+ const [credits, setCredits] = useState(null)
+ const [costs, setCosts] = useState<MonthlyCosts[]>([])
+ const supabase = createPagesBrowserClient()
+
+ const fetchCredits = useCallback(async function fetchCredits() {
+ if (!user) return
+ const { teams } = user
+ if (!teams || !supabase) return
+ if (teams.length === 0) return
+
+ // const teamID = teams[0].id
+
+ // TODO: Fetch from API server
+ setCredits(100)
+ setCosts([
+ {
+ month: 2,
+ year: 2024,
+ total_costs: 23.85,
+ unpaid_costs: 23.85,
+ },
+ {
+ month: 1,
+ year: 2024,
+ total_costs: 232,
+ unpaid_costs: 0,
+ },
+ {
+ month: 12,
+ year: 2023,
+ total_costs: 32.221,
+ unpaid_costs: 0,
+ },
+ ])
+
+ }, [user, supabase])
+
+ useEffect(function () {
+ fetchCredits()
+ }, [fetchCredits])
+
+ return {
+ credits,
+ costs,
+ }
+}
\ No newline at end of file
diff --git a/apps/docs/src/utils/useUser.tsx b/apps/docs/src/utils/useUser.tsx
index 4417d1b69..81f94cac6 100644
--- a/apps/docs/src/utils/useUser.tsx
+++ b/apps/docs/src/utils/useUser.tsx
@@ -5,7 +5,7 @@ import { User } from '@supabase/supabase-auth-helpers/react'
import { createPagesBrowserClient } from '@supabase/auth-helpers-nextjs'
import { type Session } from '@supabase/supabase-js'
import * as Sentry from '@sentry/nextjs'
-import { useSandboxStore } from './useSandbox'
+import { useSandboxStore } from '@/utils/useSandbox'
type Team = {
id: string