fix(platform): use round() for cache weights, accept string dates in UsageLimits

This commit is contained in:
Zamil Majdy
2026-03-13 17:38:25 +07:00
parent c81ab1fc3b
commit 5966d3669d
2 changed files with 9 additions and 5 deletions

View File

@@ -193,7 +193,9 @@ async def record_token_usage(
cache_creation_tokens: Tokens written to prompt cache (25% cost).
"""
weighted_input = (
prompt_tokens + int(cache_creation_tokens * 0.25) + int(cache_read_tokens * 0.1)
prompt_tokens
+ round(cache_creation_tokens * 0.25)
+ round(cache_read_tokens * 0.1)
)
total = weighted_input + completion_tokens
if total <= 0:

View File

@@ -8,9 +8,11 @@ import { Button } from "@/components/ui/button";
import { ChartBar } from "@phosphor-icons/react";
import { useUsageLimits } from "./useUsageLimits";
function formatResetTime(resetsAt: Date): string {
function formatResetTime(resetsAt: Date | string): string {
const resetDate =
typeof resetsAt === "string" ? new Date(resetsAt) : resetsAt;
const now = new Date();
const diffMs = resetsAt.getTime() - now.getTime();
const diffMs = resetDate.getTime() - now.getTime();
if (diffMs <= 0) return "now";
const hours = Math.floor(diffMs / (1000 * 60 * 60));
@@ -23,7 +25,7 @@ function formatResetTime(resetsAt: Date): string {
}
// Over 24h: show day and time in local timezone ("Mon 12:00 AM PST")
return resetsAt.toLocaleString(undefined, {
return resetDate.toLocaleString(undefined, {
weekday: "short",
hour: "numeric",
minute: "2-digit",
@@ -40,7 +42,7 @@ function UsageBar({
label: string;
used: number;
limit: number;
resetsAt: Date;
resetsAt: Date | string;
}) {
if (limit <= 0) return null;