feat: derive monthly (billing period) usage window

- Add FetchUsageSummaryRaw calling /internal/usage/summary which returns
  billing-period totals (periodBasis=billing-period)
- Derive monthly window: used=totalMonthlyCredits, cap=totalMonthlyCredits
  + monthlyCredits remaining (≈ plan monthly total), remaining=monthlyCredits
- Add monthly card to quota resource page (HTML + JS rendering)
- Skip monthly card when summary unavailable
This commit is contained in:
2026-09-04 14:13:08 +08:00
parent 4ce221c22a
commit 688a7f395f
5 changed files with 173 additions and 9 deletions
+12
View File
@@ -256,8 +256,20 @@ type UsageWindowLimitData struct {
ResetInSeconds int64 `json:"reset_in_seconds"`
}
// UpstreamUsageSummaryResponse reflects Command Code's /internal/usage/summary payload,
// which aggregates usage over the current billing period (monthly).
type UpstreamUsageSummaryResponse struct {
TotalCount int64 `json:"totalCount"`
TotalCost float64 `json:"totalCost"`
TotalCredits float64 `json:"totalCredits"`
TotalMonthlyCredits float64 `json:"totalMonthlyCredits"`
TotalPurchasedCredits float64 `json:"totalPurchasedCredits"`
PeriodBasis string `json:"periodBasis"`
}
// UsageWindowLimitsData contains both windows.
type UsageWindowLimitsData struct {
Monthly UsageWindowLimitData `json:"monthly"`
FiveHour UsageWindowLimitData `json:"five_hour"`
Weekly UsageWindowLimitData `json:"weekly"`
}