Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix actions, add toast messages
Jakub Novak250ca7fe930c
diff --git a/apps/docs/src/app/(dashboard)/api/get-user-info/route.ts b/apps/docs/src/app/(dashboard)/api/get-user-info/route.tsindex c12e231a3..2a233bdf3 100644--- a/apps/docs/src/app/(dashboard)/api/get-user-info/route.ts+++ b/apps/docs/src/app/(dashboard)/api/get-user-info/route.ts@@ -10,12 +10,12 @@ const supabase = createClient(export async function POST(request: Request) {- const { data, error } = await supabase.auth.getUser()+ const { data: { user }, error } = await supabase.auth.getUser()if (error) {console.log(error)return new Response(error.message, { status: 500 })}- if (!data) {+ if (!user) {return new Response('Not logged in', { status: 401 })}@@ -28,6 +28,10 @@ export async function POST(request: Request) {const usersResults = await Promise.all(userPromises)+ if (!usersResults.some(({data}) => data.user.id === user.id)) {+ return new Response('Unauthorized', { status: 401 })+ }+const userInfos = usersResults.map(({ data, error }) => {if (error) {console.log(error)diff --git a/apps/docs/src/app/(docs)/docs/pricing/SwitchToProButton.tsx b/apps/docs/src/app/(docs)/docs/pricing/SwitchToProButton.tsxindex 1cbd2688c..3fe39e08f 100644--- a/apps/docs/src/app/(docs)/docs/pricing/SwitchToProButton.tsx+++ b/apps/docs/src/app/(docs)/docs/pricing/SwitchToProButton.tsx@@ -70,9 +70,6 @@ function SwitchTierButton({ team }: { team: Team }) {{team.tier === tiers.pro.id && (<TierActiveTag />)}---{team.tier !== tiers.pro.id && (<ButtononClick={createCheckoutSession}diff --git a/apps/docs/src/app/(docs)/docs/usage/Credits.tsx b/apps/docs/src/app/(docs)/docs/usage/Credits.tsxdeleted file mode 100644index 51024237a..000000000--- a/apps/docs/src/app/(docs)/docs/usage/Credits.tsx+++ /dev/null@@ -1,76 +0,0 @@-'use client'--import React from 'react'-import {- Ticket,-} from 'lucide-react'-import Link from 'next/link'--import SpinnerIcon from '@/components/Spinner'-import ManageBilling from '@/components/ManageBilling'-import { useUsage } from '@/utils/useUsage'-import { useUser } from '@/utils/useUser'--function formatCurrency(value: number) {- return value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })-}--function Credits() {- const { user } = useUser()- const { credits, usage, isLoading } = useUsage()-- if (!user) {- return (- <div>- <span>Sign in to see your usage</span>- </div>- )- }-- return (- <div className="flex flex-col justify-start items-start gap-3">- <ManageBilling />- <div className="flex items-center justify-start gap-1">- <Link href="/pricing">Change plan</Link>- </div>-- <div className="flex flex-col justify-start items-start gap-1">- <div className="flex items-center gap-1">- <Ticket className="text-white" size={20} />- <span className="font-medium text-white">Credits left</span>- </div>- <span className="text-sm">Will be used when generating invoice</span>- {isLoading && <SpinnerIcon />}- {!isLoading && credits !== null && (- <span className="text-sm font-mono text-green-300/80">${formatCurrency(credits)}</span>- )}- </div>-- <div className="flex flex-col justify-start items-start gap-1">- {usage.reverse().map((u, index) => (- <React.Fragment key={index}>- <h3 className="text-xl">- {new Date(u.year, u.month - 1).toLocaleDateString('en-US', { month: 'long', year: 'numeric' })}- {u.year === 2024 && u.month === 2 ? ' (calculated from the 21st onwards)' : ''}- </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(u.total_cost)}</span>- </div>-- <div className="flex flex-col items-start justify-start gap-1">- <span className="font-bold">{new Date().getMonth() + 1 === u.month ? 'To pay' : 'Paid'}</span>- <span className="text-sm font-mono">${formatCurrency(u.unpaid_cost)}</span>- </div>- </div>- </React.Fragment>- ))}- </div>-- </div>- )-}--export default Creditsdiff --git a/apps/docs/src/app/(docs)/docs/usage/page.mdx b/apps/docs/src/app/(docs)/docs/usage/page.mdxdeleted file mode 100644index 09dabbc4f..000000000--- a/apps/docs/src/app/(docs)/docs/usage/page.mdx+++ /dev/null@@ -1,5 +0,0 @@-import Credits from './Credits'--# Usage--<Credits/>\ No newline at end of filediff --git a/apps/docs/src/components/Dashboard/AccountSelector.tsx b/apps/docs/src/components/Dashboard/AccountSelector.tsxindex 08c10a60f..cfe2e4e79 100644--- a/apps/docs/src/components/Dashboard/AccountSelector.tsx+++ b/apps/docs/src/components/Dashboard/AccountSelector.tsx@@ -32,6 +32,7 @@ export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setTconst res = await fetch(createTeamUrl, {method: 'POST',headers: {+ 'Content-Type': 'application/json','X-User-Access-Token': user.accessToken,},body: JSON.stringify({@@ -40,6 +41,10 @@ export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setT})if (!res.ok) {// TODO: Add sentry event here+ toast({+ title: 'An error occurred',+ description: 'We were unable to create the team',+ })return}@@ -51,6 +56,7 @@ export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setTsetTeams([...teams, team])setCurrentTeam(team)+ setTeamName('')}return(@@ -96,4 +102,4 @@ export const AccountSelector = ({ teams, user, currentTeam, setCurrentTeam, setT</AlertDialog></>)-}\ No newline at end of file+}diff --git a/apps/docs/src/components/Dashboard/Billing.tsx b/apps/docs/src/components/Dashboard/Billing.tsxindex 79ea2e04a..8dbc61306 100644--- a/apps/docs/src/components/Dashboard/Billing.tsx+++ b/apps/docs/src/components/Dashboard/Billing.tsx@@ -65,7 +65,7 @@ export const BillingContent = ({ currentApiKey, team }: { currentApiKey: string<div className='flex flex-col space-y-2 pb-10'><h2 className='font-bold text-xl'>Credits left</h2>- <span className="text-sm">Credits automatically are used to bill your team</span>+ <span className="text-sm">Credits are used to bill your team automatically</span>{credits === null ? (<span className="text-sm font-mono text-neutral-400">Loading...</span>) : (diff --git a/apps/docs/src/components/Dashboard/Keys.tsx b/apps/docs/src/components/Dashboard/Keys.tsxindex bdd38a5cd..2899af297 100644--- a/apps/docs/src/components/Dashboard/Keys.tsx+++ b/apps/docs/src/components/Dashboard/Keys.tsx@@ -53,6 +53,13 @@ export const KeysContent = ({ user, currentTeam, currentApiKey }: { user: User,if (error) {// TODO: Add sentry event here+ toast(+ {+ title: 'An error occurred',+ description: 'We were unable to delete the API key',++ },+ )console.log(error)return}@@ -77,6 +84,10 @@ export const KeysContent = ({ user, currentTeam, currentApiKey }: { user: User,})if (!res.ok) {+ toast({+ title: 'An error occurred',+ description: 'We were unable to create the API key',+ })// TODO: Add sentry event herereturn}@@ -160,4 +171,4 @@ export const KeysContent = ({ user, currentTeam, currentApiKey }: { user: User,</div>)-}\ No newline at end of file+}diff --git a/apps/docs/src/components/Dashboard/Personal.tsx b/apps/docs/src/components/Dashboard/Personal.tsxindex 9d44a195b..b651319d7 100644--- a/apps/docs/src/components/Dashboard/Personal.tsx+++ b/apps/docs/src/components/Dashboard/Personal.tsx@@ -3,19 +3,37 @@import { useToast } from '../ui/use-toast'import { Button } from '../Button'import { User } from '@supabase/supabase-js'-import { createPagesBrowserClient } from '@supabase/auth-helpers-nextjs'import Link from 'next/link'+import { useState } from 'react'-export const PersonalContent = ({user}: {user: User}) => {++const updateUserUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/users`++export const PersonalContent = ({user, accessToken}: {user: User, accessToken: string}) => {const { toast } = useToast()+ const [email, setEmail] = useState(user.email)const updateUserEmail = async() => {- const supabase = createPagesBrowserClient()- await supabase- .from('users')- .update({- email: user.email,+ if (!accessToken) {+ return+ }+++ const res = await fetch(updateUserUrl, {+ method: 'PATCH',+ headers: {+ 'Content-Type': 'application/json',+ Authorization: `Bearer ${accessToken}`,+ },+ })++ if (!res.ok) {+ toast({+ title: 'An error occurred',+ description: 'We were unable to update the email',})+ return+ }toast({title: 'Email updated',@@ -35,7 +53,8 @@ export const PersonalContent = ({user}: {user: User}) => {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}+ value={email}+ onChange={(e) => setEmail(e.target.value)}onSubmit={updateUserEmail}/><Button variant='outline'>Save changes</Button>diff --git a/apps/docs/src/components/Dashboard/Team.tsx b/apps/docs/src/components/Dashboard/Team.tsxindex 83b2d20fa..eddc23353 100644--- a/apps/docs/src/components/Dashboard/Team.tsx+++ b/apps/docs/src/components/Dashboard/Team.tsx@@ -68,6 +68,10 @@ export const TeamContent = ({ team, user, teams, setTeams, setCurrentTeam }: { tif (error) {// TODO: Add sentry event here+ toast({+ title: 'An error occurred',+ description: 'We were unable to delete the member from the team',+ })console.log(error)return}@@ -83,6 +87,10 @@ export const TeamContent = ({ team, user, teams, setTeams, setCurrentTeam }: { tif (error) {// TODO: Add sentry event here+ toast({+ title: 'An error occurred',+ description: 'We were unable to change the team name',+ })console.log(error)return}@@ -102,6 +110,10 @@ export const TeamContent = ({ team, user, teams, setTeams, setCurrentTeam }: { tif (error) {// TODO: Add sentry event here+ toast({+ title: 'There was an error adding the user to the team',+ description: 'Please make sure the user id is correct.',+ })console.log(error)return}@@ -211,4 +223,4 @@ export const TeamContent = ({ team, user, teams, setTeams, setCurrentTeam }: { t</div>)-}\ No newline at end of file+}diff --git a/apps/docs/src/components/Dashboard/Usage.tsx b/apps/docs/src/components/Dashboard/Usage.tsxindex 596ffffbd..8aa70a608 100644--- a/apps/docs/src/components/Dashboard/Usage.tsx+++ b/apps/docs/src/components/Dashboard/Usage.tsx@@ -2,19 +2,26 @@ import { useEffect, useState } from 'react'import { Card, CardContent } from '../ui/card'import { LoaderIcon } from 'lucide-react'import LineChart from './Chart'-import { MonthlyCosts, useUsage } from '@/utils/useUsage'+import { toast } from '@/components/ui/use-toast'++type Usage = {+ month: number+ year: number+ unpaid_cost: number+}const usageUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }) => {const [vcpuData, setVcpuData] = useState<any>(null)const [ramData, setRamData] = useState<any>(null)- const { usage: costUsage } = useUsage()+ const [ costUsage, setUsage ] = useState<Usage[]>([])useEffect(() => {const getUsage = async (apiKey: string) => {setVcpuData(null)setRamData(null)+ setUsage([])const response = await fetch(usageUrl, {headers: {@@ -23,6 +30,10 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }})if (!response.ok) {// TODO: Add sentry event here+ toast({+ title: 'An error occurred',+ description: 'We were unable to fetch the usage data',+ })console.log(response)return}@@ -31,6 +42,7 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }const { vcpuSeries, ramSeries } = transformData(data.usages)+ setUsage(data.usages)setVcpuData(vcpuSeries)setRamData(ramSeries)}@@ -41,7 +53,7 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }return (- <div className="flex flex-col w-full h-full pb-10">+ <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>@@ -54,27 +66,27 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }<div className='flex flex-col w-full md:w-2/3'><h2 className='font-bold pb-4 text-xl'>Costs in USD</h2>- <Card className="w-full bg-inherit/10 border border-white/20 mb-10">+ <Card className='w-full bg-inherit/10 border border-white/20 mb-10'><CardContent>- <LineChart className="aspect-[4/3]" series={transformCostData(costUsage)} type="Cost" />+ <LineChart className='aspect-[4/3]' series={transformCostData(costUsage)} type='Cost' /></CardContent></Card></div><div className='flex flex-col w-full md:w-2/3'><h2 className='font-bold pb-4 text-xl'>vCPU hours</h2>- <Card className="w-full bg-inherit/10 border border-white/20 mb-10">+ <Card className='w-full bg-inherit/10 border border-white/20 mb-10'><CardContent>- <LineChart className="aspect-[4/3]" series={vcpuData} type="vCPU" />+ <LineChart className='aspect-[4/3]' series={vcpuData} type='vCPU' /></CardContent></Card></div><div className='flex flex-col w-full md:w-2/3'><h2 className='font-bold pb-4 text-xl'>RAM hours</h2>- <Card className="w-full bg-inherit/10 border border-white/20 mb-10">+ <Card className='w-full bg-inherit/10 border border-white/20 mb-10'><CardContent>- <LineChart className="aspect-[4/3]" series={ramData} type="RAM" />+ <LineChart className='aspect-[4/3]' series={ramData} type='RAM' /></CardContent></Card></div>@@ -82,18 +94,20 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }</div>) : (<div className='flex items-center justify-center w-2/3'>- <LoaderIcon className="animate-spin" />+ <LoaderIcon className='animate-spin' /></div>)}</div>)}-const transformCostData = (costUsage: MonthlyCosts[]) => {- const costData = costUsage.map((usage: MonthlyCosts) => {+const transformCostData = (usage: any) => {+ const costData = usage.map((usage: any) => {return {x: `${String(usage.month).padStart(2, '0')}/${usage.year}`,- y: usage.total_cost,+ y: usage.template_usage.length > 0+ ? usage.template_usage.reduce((acc: number, template: any) => acc + template.ram_gb_hours, 0)+ : 0,}})