mirror of https://github.com/kortix-ai/suna.git
Merge pull request #382 from escapade-mckv/bug/fix
chore(dev): second attempt to fix billing checks
This commit is contained in:
commit
419ac731d6
|
@ -1013,38 +1013,32 @@ export default function ThreadPage({
|
||||||
}
|
}
|
||||||
}, [project?.account_id, billingStatusQuery]);
|
}, [project?.account_id, billingStatusQuery]);
|
||||||
|
|
||||||
// Check billing when agent status changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const previousStatus = previousAgentStatus.current;
|
let timeoutId: NodeJS.Timeout;
|
||||||
|
const shouldCheckBilling =
|
||||||
|
project?.account_id &&
|
||||||
|
(initialLoadCompleted.current ||
|
||||||
|
(messagesLoadedRef.current && !isLoading) ||
|
||||||
|
(previousAgentStatus.current === 'running' && agentStatus === 'idle'));
|
||||||
|
|
||||||
// Check if agent just completed (status changed from running to idle)
|
if (shouldCheckBilling) {
|
||||||
if (previousStatus === 'running' && agentStatus === 'idle') {
|
timeoutId = setTimeout(() => {
|
||||||
checkBillingLimits();
|
checkBillingLimits();
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store current status for next comparison
|
|
||||||
previousAgentStatus.current = agentStatus;
|
previousAgentStatus.current = agentStatus;
|
||||||
}, [agentStatus, checkBillingLimits]);
|
|
||||||
|
|
||||||
// Check billing on initial load
|
return () => {
|
||||||
useEffect(() => {
|
if (timeoutId) {
|
||||||
if (project?.account_id && initialLoadCompleted.current) {
|
clearTimeout(timeoutId);
|
||||||
console.log('Checking billing status on page load');
|
}
|
||||||
checkBillingLimits();
|
};
|
||||||
}
|
|
||||||
}, [project?.account_id, checkBillingLimits, initialLoadCompleted]);
|
|
||||||
|
|
||||||
// Check billing after messages loaded
|
|
||||||
useEffect(() => {
|
|
||||||
if (messagesLoadedRef.current && project?.account_id && !isLoading) {
|
|
||||||
console.log('Checking billing status after messages loaded');
|
|
||||||
checkBillingLimits();
|
|
||||||
}
|
|
||||||
}, [
|
}, [
|
||||||
messagesLoadedRef.current,
|
|
||||||
checkBillingLimits,
|
|
||||||
project?.account_id,
|
project?.account_id,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
agentStatus,
|
||||||
|
checkBillingLimits
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Check for debug mode in URL on initial load and when URL changes
|
// Check for debug mode in URL on initial load and when URL changes
|
||||||
|
|
Loading…
Reference in New Issue