Skip to content

armgit / E2B

Public Imported from GitHub
0

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

update progress

ErikKaumk0f9da4c98788
diff --git a/apps/docs/src/components/Dashboard/Billing.tsx b/apps/docs/src/components/Dashboard/Billing.tsx
index 050a8157b..dfa087ef6 100644
--- a/apps/docs/src/components/Dashboard/Billing.tsx
+++ b/apps/docs/src/components/Dashboard/Billing.tsx
@@ -29,7 +29,7 @@ export const BillingContent = () => {
const res = await fetch(invoiceUrl, {
headers: {
// TODO, figure out how data is passed here to get api key
- 'X-Team-API-Key': '',
+ 'X-Team-API-Key': 'e2b_ee29899a1aab99d4955a78eae32078a5c8aeee9f',
},
})
const invoices = await res.json() as Invoice[]
diff --git a/apps/docs/src/components/Dashboard/Chart.tsx b/apps/docs/src/components/Dashboard/Chart.tsx
index b6806444a..1a785d422 100644
--- a/apps/docs/src/components/Dashboard/Chart.tsx
+++ b/apps/docs/src/components/Dashboard/Chart.tsx
@@ -1,19 +1,27 @@
import { ResponsiveBar } from '@nivo/bar'
+const generateTicks = (minValue: number, maxValue: number, numTicks: number) => {
+ const range = maxValue - minValue
+ const step = range / (numTicks - 1)
+ return Array.from({ length: numTicks }, (_, i) => (minValue + i * step).toFixed(2))
+}
+
// If you wonder how to style this chart, I highly recommend this interactive tool: https://nivo.rocks/bar/
-export default function BarChart({ ...props }) {
+export default function BarChart({ usages, ...props }) {
+
+ const allValues = usages.data.flatMap((item: any) =>
+ Object.values(item).filter((value) => typeof value === 'number')
+ )
+ let maxValue = Math.max(...allValues)
+ maxValue += maxValue * 0.1 // add a 10% buffer
+
+ const ticks = generateTicks(0, maxValue, 5)
+
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']}
+ data={usages.data}
+ keys={usages.keys}
indexBy="name"
margin={{ top: 40, right: 40, bottom: 40, left: 40 }}
padding={0.2}
@@ -24,10 +32,9 @@ export default function BarChart({ ...props }) {
}}
axisLeft={{
tickSize: 0,
- tickValues: 4,
tickPadding: 16,
}}
- gridYValues={4}
+ gridYValues={ticks}
theme={{
axis: {
ticks: {
@@ -44,13 +51,16 @@ export default function BarChart({ ...props }) {
},
}}
isInteractive={false}
- borderRadius={4} // Apply a border radius to the top corners of the bars
+ borderRadius={4}
tooltipLabel={({ id }) => `${id}`}
+ label={(d) => `${d.value!.toFixed(4)}`}
enableLabel={true}
+ labelSkipWidth={12}
+ labelSkipHeight={12}
+ maxValue={maxValue}
role="application"
- ariaLabel="A bar chart showing data"
+ ariaLabel={`A bar chart showing ${props.type}-hours per month broken down by template`}
/>
</div>
)
}
-
diff --git a/apps/docs/src/components/Dashboard/Usage.tsx b/apps/docs/src/components/Dashboard/Usage.tsx
index aee0b35bc..2d029798f 100644
--- a/apps/docs/src/components/Dashboard/Usage.tsx
+++ b/apps/docs/src/components/Dashboard/Usage.tsx
@@ -1,20 +1,112 @@
+import { useEffect, useState } from 'react'
import { Card, CardContent } from '../ui/card'
import BarChart from './Chart'
+import { LoaderIcon } from 'lucide-react'
+const usageUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`
export const UsageContent = () => {
+ const [vcpuData, setVcpuData] = useState<any>(null)
+ const [ramData, setRamData] = useState<any>(null)
+
+ useEffect(() => {
+ const getUsage = async () => {
+ const response = await fetch(usageUrl, {
+ headers: {
+ 'X-Team-API-Key': ''
+ }
+ })
+ const data = await response.json()
+ console.log(data)
+ const { vcpuData, ramData, vcpuKeys, ramKeys } = transformData(data.usages)
+
+ setVcpuData({
+ data: vcpuData,
+ keys: vcpuKeys,
+ })
+ setRamData({
+ data: ramData,
+ keys: ramKeys,
+ })
+
+ }
+ getUsage()
+ }, [])
return (
- <div className="flex flex-col w-full h-full">
- <div>
- <h2 className='font-bold pb-10 text-xl'>Usage history</h2>
+ <div className="flex flex-col w-full h-full pb-10">
+ <div className='pb-10'>
+ <h2 className='font-bold pb-4 text-xl'>Usage history</h2>
+ <p>
+ The graphs shows monthly vCPU-hours and RAM-hours used by the team. <br/>
+ If you have several teamplates, the bar is broken down by the teamplate id.
+ </p>
</div>
-
- <Card className="w-2/3 bg-inherit/10 border border-white/20">
- <CardContent>
- <BarChart className="aspect-[4/3]"/>
- </CardContent>
- </Card>
+
+ {vcpuData && ramData ? (
+ <>
+ <h2 className='font-bold pb-4 text-xl'>vCPU hours</h2>
+ <Card className="w-2/3 bg-inherit/10 border border-white/20 mb-10">
+ <CardContent>
+ <BarChart className="aspect-[4/3]" usages={vcpuData} type="vCPU" />
+ </CardContent>
+ </Card>
+
+ <h2 className='font-bold pb-4 text-xl'>RAM hours</h2>
+ <Card className="w-2/3 bg-inherit/10 border border-white/20 mb-10">
+ <CardContent>
+ <BarChart className="aspect-[4/3]" usages={ramData} type="RAM" />
+ </CardContent>
+ </Card>
+ </>
+ ) : (
+ <div className='flex items-center justify-center w-2/3'>
+ <LoaderIcon className="animate-spin" />
+ </div>
+ )}
</div>
)
-}
\ No newline at end of file
+}
+
+
+const transformData = (usages: any) => {
+ const vcpuData = usages.map((usage: any) => {
+ const monthData = {
+ name: `${usage.month}/${usage.year}`,
+ }
+ usage.template_usage.forEach((template: any) => {
+ monthData[`vCPU_${template.alias}`] = template.vcpu_hours
+ })
+ return monthData
+ })
+
+ const ramData = usages.map((usage: any) => {
+ const monthData = {
+ name: `${usage.month}/${usage.year}`,
+ }
+ usage.template_usage.forEach((template: any) => {
+ monthData[`RAM_${template.alias}`] = template.ram_gb_hours
+ })
+ return monthData
+ })
+
+ // Extract keys for the bar charts
+ const vcpuKeys = new Set()
+ const ramKeys = new Set()
+ usages.forEach((usage: any) => {
+ usage.template_usage.forEach((template: any) => {
+ vcpuKeys.add(`vCPU_${template.alias}`)
+ ramKeys.add(`RAM_${template.alias}`)
+ })
+ })
+
+ console.log(vcpuData)
+
+ return {
+ vcpuData,
+ ramData,
+ vcpuKeys: Array.from(vcpuKeys),
+ ramKeys: Array.from(ramKeys),
+ }
+}
+