Chat usage limit: Claude Code-style banner with auto-continue; drop the approaching-limit banner
- The usage-limit banner now reads 'Out of usage credits' (or the refusal's own 'You've hit your 5-hour limit'), 'Auto-resuming at <time>', an 'Auto-continue when limits reset' checkbox and Try again, keeping the account switcher's 'Switch to <account>'. - Auto-continue (a shared, persisted preference, on by default) hands the server a durable scheduled prompt (send_at = reset + 1 min) with an idempotent auto-continue-<refusal id> operation id: the refused operator message again, or 'continue' when the refused turn had already worked. Unchecking unqueues it; Try again unqueues it and sends now. - Remove the approaching-limit banner, its SnackBar announcements and their marks; the send-button usage ring replaces them. - Claude Code's rate_limit_event overage fields (overageStatus, isUsingOverage/overageInUse, overageDisabledReason, overageResetsAt) reach clients as usage.account.extra_usage; the ring tooltip and the banner say 'Extra usage available' or 'Using extra usage'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,32 @@ type rateLimitInfo struct {
|
||||
RateLimitType string `json:"rateLimitType"`
|
||||
Utilization *float64 `json:"utilization"`
|
||||
UnifiedWindows map[string]*rateLimitWindowInfo `json:"unifiedWindows"`
|
||||
// Extra usage ("overage"): paid usage credits past the subscription
|
||||
// limits. Claude Code reports whether they would be accepted, whether
|
||||
// they are in use and why they are off; nothing here applies them.
|
||||
OverageStatus string `json:"overageStatus"`
|
||||
OverageResetsAt *float64 `json:"overageResetsAt"`
|
||||
OverageDisabledReason string `json:"overageDisabledReason"`
|
||||
IsUsingOverage *bool `json:"isUsingOverage"`
|
||||
OverageInUse *bool `json:"overageInUse"`
|
||||
}
|
||||
|
||||
// extraUsage is the event's overage state, or nil when it names none.
|
||||
func (info rateLimitInfo) extraUsage() *protocol.ChatExtraUsage {
|
||||
if info.OverageStatus == "" && info.OverageDisabledReason == "" {
|
||||
return nil
|
||||
}
|
||||
inUse := (info.IsUsingOverage != nil && *info.IsUsingOverage) ||
|
||||
(info.OverageInUse != nil && *info.OverageInUse)
|
||||
extra := &protocol.ChatExtraUsage{
|
||||
Status: info.OverageStatus,
|
||||
InUse: inUse,
|
||||
DisabledReason: info.OverageDisabledReason,
|
||||
}
|
||||
if at := info.OverageResetsAt; at != nil && *at > 0 && !math.IsInf(*at, 0) {
|
||||
extra.ResetsAt = int64(*at * 1000)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
// quotaWindowOrder lists the windows Claude Code names, in display order.
|
||||
@@ -119,6 +145,11 @@ func mergeRateLimit(previous *protocol.ChatAccountUsage, raw json.RawMessage, pl
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
// Overage news alone updates a report that already has windows.
|
||||
extra := info.extraUsage()
|
||||
if extra != nil && previous != nil {
|
||||
changed = true
|
||||
}
|
||||
if !changed {
|
||||
return nil
|
||||
}
|
||||
@@ -130,7 +161,12 @@ func mergeRateLimit(previous *protocol.ChatAccountUsage, raw json.RawMessage, pl
|
||||
// A switch stays recorded: the refusal it cleared is still in the
|
||||
// transcript.
|
||||
next.SwitchedAt = previous.SwitchedAt
|
||||
if extra == nil && previous.ExtraUsage != nil {
|
||||
kept := *previous.ExtraUsage
|
||||
extra = &kept
|
||||
}
|
||||
}
|
||||
next.ExtraUsage = extra
|
||||
for _, entry := range quotaWindowOrder {
|
||||
if w, ok := windows[entry.id]; ok {
|
||||
next.Windows = append(next.Windows, w)
|
||||
|
||||
@@ -55,6 +55,36 @@ func TestMergeRateLimitKeepsUnmentionedWindowsAndIgnoresStatusOnly(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeRateLimitCarriesExtraUsage(t *testing.T) {
|
||||
now := time.UnixMilli(1_800_000_000_000)
|
||||
first := mergeRateLimit(nil, json.RawMessage(unifiedRateLimit), "max", now)
|
||||
if first.ExtraUsage != nil {
|
||||
t.Fatalf("no overage fields, extra = %+v", first.ExtraUsage)
|
||||
}
|
||||
// Overage news alone updates a known report.
|
||||
next := mergeRateLimit(first, json.RawMessage(`{"status":"rejected","overageStatus":"allowed","isUsingOverage":true,"overageResetsAt":1901000000}`), "", now)
|
||||
want := &protocol.ChatExtraUsage{Status: "allowed", InUse: true, ResetsAt: 1_901_000_000_000}
|
||||
if next == nil || !reflect.DeepEqual(next.ExtraUsage, want) || len(next.Windows) != 2 {
|
||||
t.Fatalf("merge = %+v", next)
|
||||
}
|
||||
// A later window-only event keeps the last overage state.
|
||||
kept := mergeRateLimit(next, json.RawMessage(`{"status":"allowed","rateLimitType":"five_hour","utilization":0.5,"resetsAt":1899990000}`), "", now)
|
||||
if kept == nil || !reflect.DeepEqual(kept.ExtraUsage, want) {
|
||||
t.Fatalf("kept = %+v", kept)
|
||||
}
|
||||
if clone := kept.Clone(); clone.ExtraUsage == kept.ExtraUsage {
|
||||
t.Fatal("clone shares the extra usage")
|
||||
}
|
||||
off := mergeRateLimit(kept, json.RawMessage(`{"status":"rejected","overageStatus":"rejected","overageDisabledReason":"out_of_credits","isUsingOverage":false}`), "", now)
|
||||
if off == nil || !reflect.DeepEqual(off.ExtraUsage, &protocol.ChatExtraUsage{Status: "rejected", DisabledReason: "out_of_credits"}) {
|
||||
t.Fatalf("off = %+v", off)
|
||||
}
|
||||
// Without a report to attach to, overage alone shows nothing.
|
||||
if got := mergeRateLimit(nil, json.RawMessage(`{"overageStatus":"allowed"}`), "", now); got != nil {
|
||||
t.Fatalf("lone overage = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeAccountIdentity(t *testing.T) {
|
||||
got := decodeAccountIdentity(json.RawMessage(`{"email":"a@example.invalid","organization":"Org","subscriptionType":"max","apiProvider":"firstParty"}`))
|
||||
if got.key == "" || got.plan != "max" {
|
||||
|
||||
Reference in New Issue
Block a user