Add Monthly Usage + Monthly Reset Timer widgets (stacked on #505)#506
Open
TiansuYu wants to merge 2 commits into
Open
Add Monthly Usage + Monthly Reset Timer widgets (stacked on #505)#506TiansuYu wants to merge 2 commits into
TiansuYu wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds dedicated Monthly Usage and Monthly Reset Timer widgets.
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'sunit:6token window to them.Changes
UsageData/RenderUsageData: newmonthlyUsage/monthlyResetAtfieldsusage-windows:resolveMonthlyUsageWindow(uses a 30-day window to size the progress-bar elapsed %)usage-fetch: ZAIunit:6now maps tomonthlyUsage/monthlyResetAt(was weekly)MonthlyUsageandMonthlyResetTimer, mirroring the weekly variantsmonthly-usage,monthly-reset-timer)The Monthly widgets are schema-driven and provider-agnostic — they render whenever
monthlyUsageis 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 assertunit:6maps tomonthlyUsage, notweeklyUsage)bun run build✅