Show OpenWeather API call usage in the app
OpenWeather reports no remaining quota (only 429 when over), so add an in-app gauge that counts the calls PilotVault itself makes and shows them against the plan's per-minute limit. - Plugin: process-wide usage store bucketed per API key (hashed) into the current minute and UTC day; a do() wrapper counts each request that reaches OpenWeather (transport errors consume no quota, so uncounted). Health and Invoke both route through it. - New callsPerMinute config field (default 60) that cascades global -> org -> user; plugin contract gains plugins.HealthUsage on Health. - Web App: a "Calls per minute limit" field and an "API call usage" meter in the OpenWeather card, shown after Test connection and cached. - Counts reset on restart and cover only PilotVault's own calls (noted in the UI); the account dashboard stays authoritative. - Tests for per-key counting and minute/day rollover; rebuilt frontend. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
285551fe8a
commit
6d73c89cc8
@@ -113,6 +113,18 @@ type Health struct {
|
||||
LatencyMs int64 `json:"latencyMs,omitempty"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
Credits *HealthCredits `json:"credits,omitempty"`
|
||||
Usage *HealthUsage `json:"usage,omitempty"`
|
||||
}
|
||||
|
||||
// HealthUsage is optional call-usage accounting a plugin may report when its
|
||||
// upstream does NOT expose remaining quota (e.g. OpenWeather). Unlike
|
||||
// HealthCredits — which reflects a balance the upstream reports — these are
|
||||
// process-local counts of the calls this server has made, bucketed into the
|
||||
// current minute and day, so the UI can render an approximate usage gauge.
|
||||
type HealthUsage struct {
|
||||
MinuteUsed int `json:"minuteUsed"` // calls made in the current minute
|
||||
MinuteLimit int `json:"minuteLimit,omitempty"` // the plan's per-minute limit
|
||||
DayUsed int `json:"dayUsed"` // calls made so far today (UTC)
|
||||
}
|
||||
|
||||
// HealthCredits is optional structured rate-limit/credit accounting a plugin may
|
||||
|
||||
Reference in New Issue
Block a user