feat: enhance token formatting and reset logic for new conversations

This commit is contained in:
Marco Beretta 2025-12-15 23:55:43 +01:00
parent 0b84a25536
commit 01ca9b1655
No known key found for this signature in database
GPG key ID: D918033D8E74CC11
2 changed files with 13 additions and 2 deletions

View file

@ -5,10 +5,10 @@ import { cn } from '~/utils';
function formatTokens(n: number): string {
if (n >= 1000000) {
return `${(n / 1000000).toFixed(1)}M`;
return `${(n / 1000000).toFixed(1).replace(/\.0$/, '')}M`;
}
if (n >= 1000) {
return `${(n / 1000).toFixed(1)}K`;
return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}K`;
}
return n.toString();
}

View file

@ -84,6 +84,17 @@ export function useTokenUsageComputation() {
useEffect(() => {
setTokenUsage(tokenData);
}, [tokenData, setTokenUsage]);
// Reset token usage when starting a new conversation
useEffect(() => {
if (paramId === 'new' && effectiveMessages.length === 0) {
setTokenUsage({
inputTokens: 0,
outputTokens: 0,
maxContext: null,
});
}
}, [paramId, effectiveMessages.length, setTokenUsage]);
}
/**