Skip to content

Add Monthly Usage + Monthly Reset Timer widgets (stacked on #505)#506

Open
TiansuYu wants to merge 2 commits into
sirmalloc:mainfrom
TiansuYu:feat/monthly-usage-widgets
Open

Add Monthly Usage + Monthly Reset Timer widgets (stacked on #505)#506
TiansuYu wants to merge 2 commits into
sirmalloc:mainfrom
TiansuYu:feat/monthly-usage-widgets

Conversation

@TiansuYu

Copy link
Copy Markdown

Summary

Adds dedicated Monthly Usage and Monthly Reset Timer widgets.

Stacked on #505 (ZAI / GLM quota provider). Until #505 merges, this PR's diff will also show the ZAI provider commit; it will narrow to just the Monthly widgets once #505 is merged. Please review/merge #505 first.

Motivation

#505 temporarily maps ZAI's 1-month token window onto the existing Weekly (7-day) widget, which mislabels a monthly budget as "Weekly" (e.g. Weekly: 10% with a ~1-month reset countdown). This PR fixes that by adding proper Monthly widgets and routing ZAI's unit:6 token window to them.

Changes

  • UsageData / RenderUsageData: new monthlyUsage / monthlyResetAt fields
  • usage-windows: resolveMonthlyUsageWindow (uses a 30-day window to size the progress-bar elapsed %)
  • usage-fetch: ZAI unit:6 now maps to monthlyUsage / monthlyResetAt (was weekly)
  • New widgets MonthlyUsage and MonthlyResetTimer, mirroring the weekly variants
  • Registered in the widget manifest and usage-prefetch (monthly-usage, monthly-reset-timer)

The Monthly widgets are schema-driven and provider-agnostic — they render whenever monthlyUsage is present, so they're a no-op for Anthropic accounts (which don't expose a monthly window).

Testing

  • bun run lint
  • bun test ✅ (unit tests assert unit:6 maps to monthlyUsage, not weeklyUsage)
  • bun run build

TiansuYu added 2 commits July 15, 2026 16:39
Add a ZAI provider branch to usage-fetch alongside the Anthropic OAuth
path. When ANTHROPIC_BASE_URL points at z.ai / bigmodel, fetch quota from
ZAI's /api/monitor/usage/quota/limit endpoint (raw-token auth via
ANTHROPIC_AUTH_TOKEN) and map all three windows into UsageData:

- 5-hour token (unit:3) -> sessionUsage / sessionResetAt
- 1-month token (unit:6) -> weeklyUsage / weeklyResetAt (placeholder)
- monthly MCP (TIME_LIMIT) -> extraUsageUtilization

Fingerprints ANTHROPIC_AUTH_TOKEN for the cache key on ZAI so token
rotation invalidates the cache. Anthropic path unchanged.
ZAI/GLM exposes a 1-month token window that was previously mapped onto
the Weekly (7-day) widget, mislabeling a monthly budget as weekly. Add
dedicated Monthly widgets and route ZAI's unit:6 token window to them:

- UsageData: monthlyUsage / monthlyResetAt fields (+ RenderUsageData)
- usage-windows: resolveMonthlyUsageWindow (30-day window for bar %)
- usage-fetch: map ZAI unit:6 -> monthlyUsage/monthlyResetAt (was weekly)
- widgets: MonthlyUsage, MonthlyReset Timer (mirror the weekly variants)
- prefetch + manifest: register monthly-usage / monthly-reset-timer

Adds unit tests for parseZaiQuotaResponse covering the window mapping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant