@@ -14,6 +14,7 @@ import {
1414 paceRemainingPercent ,
1515 remainingPercent ,
1616} from "@t3tools/shared/usageLimits" ;
17+ import { formatUsd } from "@t3tools/shared/usageFormat" ;
1718import type { Popover as PopoverPrimitive } from "@base-ui/react/popover" ;
1819import { AlertTriangleIcon , ExternalLinkIcon , TicketIcon } from "lucide-react" ;
1920import {
@@ -132,6 +133,27 @@ function Row({ label, children }: { readonly label: string; readonly children: R
132133 ) ;
133134}
134135
136+ type MonetaryUsage = NonNullable < LimitAccount [ "limits" ] [ "monetaryUsage" ] > ;
137+
138+ function monetaryUsageOf ( limits : LimitAccount [ "limits" ] ) : MonetaryUsage | null {
139+ const monetary = limits . monetaryUsage ;
140+ if ( ! monetary ) return null ;
141+ const { usedUsd, remainingUsd, limitUsd } = monetary ;
142+ return usedUsd === undefined && remainingUsd === undefined && limitUsd === undefined
143+ ? null
144+ : monetary ;
145+ }
146+
147+ function monetaryUsageText ( monetary : MonetaryUsage ) : string {
148+ return [
149+ monetary . usedUsd !== undefined ? `${ formatUsd ( monetary . usedUsd ) } used` : null ,
150+ monetary . remainingUsd !== undefined ? `${ formatUsd ( monetary . remainingUsd ) } left` : null ,
151+ monetary . limitUsd !== undefined ? `${ formatUsd ( monetary . limitUsd ) } limit` : null ,
152+ ]
153+ . filter ( ( part ) => part !== null )
154+ . join ( " · " ) ;
155+ }
156+
135157function SegmentPopover ( {
136158 account,
137159 window,
@@ -157,6 +179,7 @@ function SegmentPopover({
157179 : account . sourceLabel ;
158180 const credits =
159181 redeem && account . limits . resetCredits ?. availableCount ? account . limits . resetCredits : null ;
182+ const monetary = monetaryUsageOf ( account . limits ) ;
160183 return (
161184 < div className = "flex w-72 max-w-[calc(100vw-3rem)] flex-col gap-2.5 text-xs" >
162185 < div className = "flex min-w-0 flex-col gap-0.5" >
@@ -182,6 +205,19 @@ function SegmentPopover({
182205 < Row label = { account . environments . length > 0 ? "Signed in" : "Via" } > { where } </ Row >
183206 ) : null }
184207 </ div >
208+ { monetary ? (
209+ < div className = "flex flex-col gap-1 border-t border-border/60 pt-2.5" >
210+ { monetary . usedUsd !== undefined ? (
211+ < Row label = "Used" > { formatUsd ( monetary . usedUsd ) } </ Row >
212+ ) : null }
213+ { monetary . remainingUsd !== undefined ? (
214+ < Row label = "Remaining" > { formatUsd ( monetary . remainingUsd ) } </ Row >
215+ ) : null }
216+ { monetary . limitUsd !== undefined ? (
217+ < Row label = "Limit" > { formatUsd ( monetary . limitUsd ) } </ Row >
218+ ) : null }
219+ </ div >
220+ ) : null }
185221 < div className = "flex flex-col gap-1 border-t border-border/60 pt-2.5" >
186222 < Row label = "Left" > { remaining } %</ Row >
187223 { window . resetsAt ? (
@@ -568,6 +604,26 @@ function PoolWindowCard({
568604 ) ;
569605}
570606
607+ function PoolMonetaryAccounts ( { pool } : { readonly pool : LimitPool } ) {
608+ const rows = pool . accounts . flatMap ( ( account ) => {
609+ const monetary = monetaryUsageOf ( account . limits ) ;
610+ return monetary ? [ { account, monetary } ] : [ ] ;
611+ } ) ;
612+ return (
613+ < div className = "flex flex-col gap-2 rounded-lg border border-border/60 p-4" >
614+ < span className = "text-xs text-muted-foreground" > No rate-limit windows reported</ span >
615+ { rows . map ( ( { account, monetary } ) => (
616+ < span key = { account . key } className = "flex items-baseline justify-between gap-3 text-xs" >
617+ < AccountName account = { account } className = "min-w-0 truncate font-medium text-foreground" />
618+ < span className = "shrink-0 text-foreground tabular-nums" >
619+ { monetaryUsageText ( monetary ) }
620+ </ span >
621+ </ span >
622+ ) ) }
623+ </ div >
624+ ) ;
625+ }
626+
571627function PoolSection ( { pool, now } : { readonly pool : LimitPool ; readonly now : number } ) {
572628 const color = barColor ( pool . driver ) ;
573629 const label = providerClients . get ( pool . driver ) ?. label ?? String ( pool . driver ) ;
@@ -584,19 +640,24 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu
584640 />
585641 { label }
586642 </ h2 >
587- { windows . map ( ( window ) => {
588- const details = pool . driver === "cursor" ? cursorUsageWindowDetails ( window . id ) : undefined ;
589- return (
590- < PoolWindowCard
591- key = { `${ window . kind } :${ window . id } ` }
592- pool = { window }
593- color = { color }
594- now = { now }
595- label = { details ?. label }
596- description = { details ?. description }
597- />
598- ) ;
599- } ) }
643+ { windows . length === 0 ? (
644+ < PoolMonetaryAccounts pool = { pool } />
645+ ) : (
646+ windows . map ( ( window ) => {
647+ const details =
648+ pool . driver === "cursor" ? cursorUsageWindowDetails ( window . id ) : undefined ;
649+ return (
650+ < PoolWindowCard
651+ key = { `${ window . kind } :${ window . id } ` }
652+ pool = { window }
653+ color = { color }
654+ now = { now }
655+ label = { details ?. label }
656+ description = { details ?. description }
657+ />
658+ ) ;
659+ } )
660+ ) }
600661 </ section >
601662 ) ;
602663}
0 commit comments