fix frontend time calculation

This commit is contained in:
Adam Cohen Hillel 2025-04-22 17:15:29 +01:00
parent 3128a8197b
commit bfbfbfb823
1 changed files with 10 additions and 1 deletions

View File

@ -35,10 +35,19 @@ export default async function AccountBillingStatus({ accountId, returnUrl }: Pro
const startOfMonth = new Date(); const startOfMonth = new Date();
startOfMonth.setDate(1); startOfMonth.setDate(1);
startOfMonth.setHours(0, 0, 0, 0); startOfMonth.setHours(0, 0, 0, 0);
// First get threads for this account
const { data: threadsData } = await supabaseClient
.from('threads')
.select('thread_id')
.eq('account_id', accountId);
const threadIds = threadsData?.map(t => t.thread_id) || [];
// Then get agent runs for those threads
const { data: agentRunData, error: agentRunError } = await supabaseClient const { data: agentRunData, error: agentRunError } = await supabaseClient
.from('agent_runs') .from('agent_runs')
.select('started_at, completed_at') .select('started_at, completed_at')
.in('thread_id', threadIds)
.gte('started_at', startOfMonth.toISOString()); .gte('started_at', startOfMonth.toISOString());
let totalSeconds = 0; let totalSeconds = 0;
@ -52,7 +61,7 @@ export default async function AccountBillingStatus({ accountId, returnUrl }: Pro
} }
const hours = Math.floor(totalSeconds / 3600); const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60); const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = Math.floor(totalSeconds % 60); const seconds = Math.floor(totalSeconds % 60);
const usageDisplay = `${hours}h ${minutes}m ${seconds}s`; const usageDisplay = `${hours}h ${minutes}m ${seconds}s`;