Files
magpie/internal/gateway/image_rest.go
T
yetone 0706d7a35a usage: a ChatGPT card has an image row: used up until the refusal's reset, else unknown (#6160, hqqqqqqqh on X)
ChatGPT's image generation has a quota apart from the 5-hour and weekly
windows. Neither /wham/usage (additional_rate_limits is null) nor the reply
headers (x-codex-primary-*, x-codex-secondary-*) tell it, so no remaining
count exists to show. Each Codex account's card (Usage page, magpie quota
--json, /v1/magpie/quotas, /v1/magpie/quotas/cards) now has an "Image
generation" row (provider.WithImageLane, Lane "images", Text and Aside so
routing, holds, history, tray and statusline never see it): "Used up" with
the reset time while the image model rests on that account after a refusal
(the #2244 drawing-lane rest, whose time is the refusal's resets_at), and
"Unknown" otherwise. Never a share or a count. Shown in en, zh, zh-TW, ja, de.

app.js: a Text row's display now goes through t(), a same-length change, as
the core script budget has 1 byte of room.

Run (on mote): go test -count=1 -run 'TestWithImageLane|TestCodexImageRow'
./internal/provider ./internal/gateway ok; codex-image-row.test.cjs in
chromium and webkit at 900 and 390px in all five languages ok;
TestCoreScriptBudget ok; go vet darwin, windows, linux nogui on provider and
gateway ok; gofmt clean; 158 GUI files matching i18n/quota/usage/balance
names in both engines (result in the follow-up).
Broken by hand: the GUI test is red with app.js's display line put back to
the old form; the Go row tests are red with imageRestOf returning false.
Not tried: a real ChatGPT account hitting its image quota (the row is
driven by a faked refusal's rest); the generated-image count the issue also
asks for is not built.
2026-11-11 21:59:36 +08:00

33 lines
1.1 KiB
Go

package gateway
import (
"strings"
"time"
"github.com/yetone/magpie/internal/provider"
)
func init() { provider.ImageRest = imageRestOf }
// imageRestOf is when the ChatGPT account user draws again, as the refusal
// that rested its image model said (restDrawer; usage_limit_reached's
// resets_at), while that rest holds. It is the only thing magpie learns of
// the account's image allowance, which the backend shows no share of
// (provider.ImageLane, #6160), and it is only that: not when the allowance
// began, nor what it counted. The latest of several resting image models
// (a rest per model) is the one that says when drawing is back.
func imageRestOf(agent, user string, now time.Time) (time.Time, bool) {
restingUntil.Lock()
defer restingUntil.Unlock()
var last time.Time
for k, r := range restingUntil.note {
if r.agent != agent || !strings.EqualFold(r.user, user) || !strings.HasPrefix(r.Model, codexDrawerFamily) {
continue
}
if until := restingUntil.m[k]; until.After(now) && until.After(last) {
last = until
}
}
return last, !last.IsZero()
}