provider: Kimi Code's monthly allowance shows as a Month window beside 5h and weekly (lidazi2016)
lidazi2016 on Discord (#feedback): a Kimi Code plan has a 5-hour, a
weekly and a monthly limit, and magpie showed only the first two.
Kimi's /coding/v1/usages tells a plan on its monthly allowance in a
third block magpie didn't read: "usages", each entry a share
{"used_ratio", "reset_time"} keyed limit_5h, limit_7d,
limit_month_total and limit_month_code. kimi-cli 1.52.0 (the Python CLI,
latest on PyPI) reads only "usage" and "limits"; Kimi's newer kimi-code
(MoonshotAI/kimi-code, packages/oauth/src/managed-usage.ts and
apps/kimi-code/src/utils/usage/usage-format.ts) reads "usages" and shows
"5h limit", "Weekly limit" and "Monthly limit" from limit_5h, limit_7d
and limit_month_total. limit_month_code is the part of the month code
has used, drawn on limit_month_total, not an allowance of its own.
readKimiCode now reads usages the same way: limit_5h as "5 hours",
limit_7d as "7 days", limit_month_total as "Month" (30-day Span, reset
at its reset_time, the name Volcengine, Tencent, Cline and Ollama's
month windows already use, translated in zh, zh-TW, ja and de), and
leaves limit_month_code out. A window told both ways (the 300-minute
limits[] entry beside limit_5h, the weekly usage beside limit_7d) is the
share's, as kimi-code takes it; a share that isn't a number is skipped
and the counted window stands. The windows come shortest first.
Test: TestReadKimiCodeMonth. Its first body is a live reply of
2026-09-23 posted in narumiruna/pi-extensions#1390 (limits[] + usages
with limit_5h, limit_month_total, limit_month_code, no weekly usage);
the second has every window kimi-code reads, plus usage and limits[];
the third a null used_ratio. With planquota.go put back to origin/main
it fails: "planquota_test.go:462: [{... Name:5 hours Used:44 ...}]", the
month missing; with the change it passes. TestReadKimiCode (the counted
shape) passes unchanged.
Run on mote (mote-run): gofmt -l (nothing), go vet -tags nogui ./...,
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build,
GOOS=linux go build -tags nogui, GOOS=windows go build, and go test
-tags nogui -count=1 -timeout 45m on internal/provider, internal/gui,
internal/tui, internal/cli, internal/usage and internal/usageapi:
all ok (provider 290s, gui 195s, tui 28s, cli 155s, usage 101s, usageapi 2s).
Not run: the whole go test ./... (mote was at load ~99 running two other
sessions' full suites; one suite a machine), and the GUI suite (no
change under internal/gui/assets; "Month" and its translations are
already there). Not tried: a real Kimi Code account or key; the reply
shape is Kimi's own client's parser and a live reply posted by another
user, not one read here.
This commit is contained in:
@@ -57,7 +57,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
|
||||
| Codex's free auto-review | OpenAI made Codex's Auto-review free for users signed in through a ChatGPT account (silverzhou on Discord), so a `codex-auto-review` call through the Codex subscription is priced at nothing (`ListPrice` → `codexReviewFree`, `provider.ChatGPTReviewFree`), not at GPT-5.6 Luna's price (`pricedNames`), and the Requests list names no model it is priced as (`PricedNameFor`). Not on a Free plan, where it spends the allowance (cybercaius), read from the plan Codex is signed in to now; a Codex signed out since counts as a paid plan, as the gateway's caps take it (`freeOnChatGPT`). The same model through an API key, the ChatGPT API subscription or a relay, and a review that followed the session to another model, keep their price; a price the user set wins. Every call is priced as it is read, so rows logged before are free too; the price views' cache keys on each account's plan (`usagePriceCacheKey`). Guarded by `TestAutoReviewFreeOnChatGPTSignIn` and `usage.TestAutoReviewFreeOnChatGPT`. |
|
||||
| A lab's models | models.dev keeps two catalogs: `api.json`, each provider's models with that host's prices, and `models.json`, each lab's models with only what is the model's on every host (name, window, reply limit, thinking, inputs, release), no price. `Sync` keeps the second beside the first as `labs.json` (`LabsPath`, `syncLabs`: best effort, through a rename, a failed fetch keeping the last; a catalog with none beside it is `Stale` once a process, so it comes at the next look). A model only a lab lists, no provider (models.dev took the gated Claude Mythos 5.1 out of anthropic's list in #11327 and kept its lab file), is voted into the same tables as a listed one (`loadGen`, `labs`), so `ContextOf`, `OutputOf`, `NameOf`, `Thinks`, `SeesImages` and every entry built on them know it wherever a vendor's or an account's list has it; a thinking one with no levels takes the levels of the newest of its family a provider gives them (`labKinEfforts`: Mythos 5.1 takes Mythos 5's). A model a provider lists keeps what providers say of it. `catalog.Describe` builds a model from these for a list that names an id alone. `TestLabOnlyModelIsKnown`, `TestLabsLeaveListedModels`, `TestSyncKeepsLabs`, `TestAnthropicKeyGatedModelDescribed` (iebb on Discord). | [`labs.go`](../../internal/catalog/labs.go), [`catalog.go`](../../internal/catalog/catalog.go) |
|
||||
| A Claude account's models | magpie never asks Anthropic with a Claude sign-in, so a Claude account's list is models.dev's anthropic list and what Anthropic told the account's Claude Code beyond it. Claude Code keeps that in its `.claude.json` from its own bootstrap: `additionalModelOptionsCache` (models its /model picker offers beyond its own; a `null` value or a `disabled` one is not a model), `modelAccessCache` (`entitled` per API id) and `additionalModelCostsCache` (Anthropic's prices). `claudeModels` reads the file of Claude Code's own sign-in (`claudeProfilePath`) and of each saved account's directory (`claudeAccountDir`), through `filememo`, and adds each model none of them lists, described by `catalog.Describe` and priced as Anthropic told it. `Account.Lists` for a Claude account goes by its own file (`claudeLists`: the saved directory's, or Claude Code's own when its `oauthAccount` is that account, the one Anthropic answered last): a model it isn't entitled to is out, so routing tries the accounts entitled to a gated model first; with no file, every model is taken to be in, as before. `ListPrice` of a provider whose catalogs include anthropic falls back to that price after every catalog (`claudeCodePrice`). The agent's own Claude Code model picker (`claudeOwn`) offers what `ClaudeCodeModels` gives for the account signed in here; a WSL distro's keeps the catalog's. Not done: a Claude Code that never started on a saved account has no file, so its gated models show only once it has run there. `TestClaudeAccountListsGatedModels`. | [`claude_code_models.go`](../../internal/provider/claude_code_models.go), [`account.go`](../../internal/provider/account.go), [`codex_models.go`](../../internal/provider/codex_models.go), [`claude.go`](../../internal/agent/claude.go) |
|
||||
| A key's own windows | A sub2api key given a spending limit per 5 hours, day or 7 days answers its `/v1/usage` with `rate_limits` and no `remaining` (`readSub2APIKeyLimits`). With the Balance URL set to it, the key's card shows them as the windows *5 hours*, *1 day*, *7 days*, in USD, beside a balance field the user wrote; *Check balance* and `magpie provider show` give what its fullest window has left (`Balance`). A Balance URL at an account query left without its token (a sub2api panel's `/api/v1/user/profile`, new-api's `/api/user/self`, after the token was removed) asks the same panel's query for the key instead, the saved URL untouched (`keyQueryOf`, `BalanceQuery`), unless the user's Headers carry an Authorization or Cookie of their own. A Balance URL of the user's own is asked with GET, or with POST and no body when the provider's `BalanceMethod` says so (#2368: an endpoint that answers only a POST; the editor's GET/POST beside the URL, `balance.method=` on the command line); any other method is refused before anything is sent (`balanceMethodOf`). `KeyAllowance` gives routing the same windows: never waited for, read in the background at most once a minute, a failed read keeping the last, and seeded from the card's last reading (`quotas.json`) after a restart. A key bought as a plan (Kimi Code, GLM Coding Plan and Z.ai, MiniMax Coding Plan, OpenCode Go, Command Code, Ollama Cloud: `planQuotaSourceOf`) gives routing its card's windows the same way (`planKeyWindows`, Zhipu's team quota behind a key with none of its own); the Usage page's read of its card is taken at once (`noteKeyAllowance`), and a key there that turns out pay-as-you-go, with no windows, is asked again only every 30 minutes (`keyNoWindowsAge`). A Command Code plan's key has its month of credits as a *Credits* window beside the 5-hour and weekly ones, as the signed-in subscription's card has (`cmdKeyWindows`, #2451): billing/credits leaves the plan out, so it is the key's billing/subscriptions plan, asked at most every ten minutes and the last one kept while it can't be read; the same reply's period end is the Credits window's reset, left off once it has passed (#2454); a key whose plan was never read has its two windows alone. Ollama Cloud's `ollama.com/api/balance` (#1888, `readOllamaPlan`) tells the plan's included allowance as one window in USD, *Month* when its period is a month long, renewing at `period.until`, and Aside while credits bought on top are left; those credits are the key's balance card (`readOllamaCredits`), and a reply that names none has no balance card rather than $0. StepFun's Step Plan is read through a platform sign-in, not the key, and isn't one of them: the sign-in is the provider's own, kept by provider id in `stepfun-auth.json` (two StepFun providers on one site can be two accounts, #2384), one card per signed-in provider; a file from before that, kept by site, is given on read to the StepFun providers on that site (`stepfunBySite`), and copies of one sign-in are renewed together. Nor are Volcengine Ark's Coding Plan and Agent Plan (#1427): their 5-hour, weekly and monthly windows are told only to the account's access key (`AccessKeyID`, `SecretAccessKey`), asked of `open.volcengineapi.com` (`GetCodingPlanUsage`, `GetAFPUsage`) and signed as Volcengine's own SDK signs (`volcSign`), so they are cards on the Usage page (`volcPlanQuotas` in `PlanQuotas`), never routing's windows. Nor is Tencent Cloud's Token Plan 企业版 (#1574): what a team plan has used of its cycle's credits (专业套餐) or tokens (轻享套餐) is told only to the account's SecretId and SecretKey (kept as `AccessKeyID`, `SecretAccessKey`), asked of `tokenhub.tencentcloudapi.com` (`DescribeTokenPlanList`, `DescribeTokenPlan`, version 2026-03-22) and signed TC3-HMAC-SHA256 (`tc3Sign`), one card per team plan (`tencentPlanQuotas`). | [`sub2api_usage.go`](../../internal/provider/sub2api_usage.go), [`key_allowance.go`](../../internal/provider/key_allowance.go), [`volcengine_usage.go`](../../internal/provider/volcengine_usage.go), [`tencent_usage.go`](../../internal/provider/tencent_usage.go) |
|
||||
| A key's own windows | A sub2api key given a spending limit per 5 hours, day or 7 days answers its `/v1/usage` with `rate_limits` and no `remaining` (`readSub2APIKeyLimits`). With the Balance URL set to it, the key's card shows them as the windows *5 hours*, *1 day*, *7 days*, in USD, beside a balance field the user wrote; *Check balance* and `magpie provider show` give what its fullest window has left (`Balance`). A Balance URL at an account query left without its token (a sub2api panel's `/api/v1/user/profile`, new-api's `/api/user/self`, after the token was removed) asks the same panel's query for the key instead, the saved URL untouched (`keyQueryOf`, `BalanceQuery`), unless the user's Headers carry an Authorization or Cookie of their own. A Balance URL of the user's own is asked with GET, or with POST and no body when the provider's `BalanceMethod` says so (#2368: an endpoint that answers only a POST; the editor's GET/POST beside the URL, `balance.method=` on the command line); any other method is refused before anything is sent (`balanceMethodOf`). `KeyAllowance` gives routing the same windows: never waited for, read in the background at most once a minute, a failed read keeping the last, and seeded from the card's last reading (`quotas.json`) after a restart. A key bought as a plan (Kimi Code, GLM Coding Plan and Z.ai, MiniMax Coding Plan, OpenCode Go, Command Code, Ollama Cloud: `planQuotaSourceOf`) gives routing its card's windows the same way (`planKeyWindows`, Zhipu's team quota behind a key with none of its own); the Usage page's read of its card is taken at once (`noteKeyAllowance`), and a key there that turns out pay-as-you-go, with no windows, is asked again only every 30 minutes (`keyNoWindowsAge`). Kimi Code's `/usages` (`readKimiCode`) is read as kimi-cli and kimi-code read it: the week's `usage` and each `limits[]` window as counts, and the shares in `usages` (`limit_5h`, `limit_7d`, and `limit_month_total` as a *Month* window renewing at its `reset_time`, lidazi2016 on Discord); a window told both ways is the share's, and `limit_month_code`, the part of the month code used, is no window. `TestReadKimiCode`, `TestReadKimiCodeMonth`. A Command Code plan's key has its month of credits as a *Credits* window beside the 5-hour and weekly ones, as the signed-in subscription's card has (`cmdKeyWindows`, #2451): billing/credits leaves the plan out, so it is the key's billing/subscriptions plan, asked at most every ten minutes and the last one kept while it can't be read; the same reply's period end is the Credits window's reset, left off once it has passed (#2454); a key whose plan was never read has its two windows alone. Ollama Cloud's `ollama.com/api/balance` (#1888, `readOllamaPlan`) tells the plan's included allowance as one window in USD, *Month* when its period is a month long, renewing at `period.until`, and Aside while credits bought on top are left; those credits are the key's balance card (`readOllamaCredits`), and a reply that names none has no balance card rather than $0. StepFun's Step Plan is read through a platform sign-in, not the key, and isn't one of them: the sign-in is the provider's own, kept by provider id in `stepfun-auth.json` (two StepFun providers on one site can be two accounts, #2384), one card per signed-in provider; a file from before that, kept by site, is given on read to the StepFun providers on that site (`stepfunBySite`), and copies of one sign-in are renewed together. Nor are Volcengine Ark's Coding Plan and Agent Plan (#1427): their 5-hour, weekly and monthly windows are told only to the account's access key (`AccessKeyID`, `SecretAccessKey`), asked of `open.volcengineapi.com` (`GetCodingPlanUsage`, `GetAFPUsage`) and signed as Volcengine's own SDK signs (`volcSign`), so they are cards on the Usage page (`volcPlanQuotas` in `PlanQuotas`), never routing's windows. Nor is Tencent Cloud's Token Plan 企业版 (#1574): what a team plan has used of its cycle's credits (专业套餐) or tokens (轻享套餐) is told only to the account's SecretId and SecretKey (kept as `AccessKeyID`, `SecretAccessKey`), asked of `tokenhub.tencentcloudapi.com` (`DescribeTokenPlanList`, `DescribeTokenPlan`, version 2026-03-22) and signed TC3-HMAC-SHA256 (`tc3Sign`), one card per team plan (`tencentPlanQuotas`). | [`sub2api_usage.go`](../../internal/provider/sub2api_usage.go), [`key_allowance.go`](../../internal/provider/key_allowance.go), [`volcengine_usage.go`](../../internal/provider/volcengine_usage.go), [`tencent_usage.go`](../../internal/provider/tencent_usage.go) |
|
||||
| Account names and seats | `AccountNames` (by the account, in lower case, like `AccountCaps`) are names the user gives accounts, set by `SetAccountName` (GUI `provider/accountname`, `magpie accounts alias`); they live in providers.json only, never in a vendor's or plugin's sign-in. A GLM Coding Plan read with a key (`glmPlan`) and a ZCode account (built-in or `zcode-plugin`) whose windows' resets agree are one seat (`seatMatch`, #90/#953), shown once, on the account's card (`seatCards`, used by `quotas`, `Allotted` and `CachedCards`). A match is remembered in `seats.json` beside `quotas.json`: a failed read or a window with no reset yet is unknown and keeps the key's card off while the account is signed in; windows that disagree forget it (#1515). Cards carry `Seat` (the key provider's name, and the key's when it has several) and `Alias` (the user's name, else `Seat`), as `/v1/magpie/quotas`, `magpie quota` and `magpie accounts` do. Records (a trace's `who`, usage's `ProviderAccount`) keep the vendor's name, the key the user's name is kept by, and every list of them looks the name up as it is shown (`AccountShown`, `AccountShownOf`, `AccountRef.Shown`), so a request from before a rename reads by the new name too: the Routing page's accounts and requests (`userShown` in `plugins/routing/client.js`, from `/api/providers`' `accountNames`), its Several accounts pools (`onOf`), the Usage page's Accounts and the request log's Account filter (`usageapi`), `magpie usage`, and a gateway key's accounts (`AccountNames`, `/api/caller-keys`). Before plugins#310 (a renamed Kiro account read by its old name on every request after) those showed the vendor's name. | [`account_names.go`](../../internal/provider/account_names.go), [`account_seats.go`](../../internal/provider/account_seats.go) |
|
||||
| Last served | `served.json` records when each account, plan or key last answered, shown as `lastServedAt` (#570) on `/v1/magpie/quotas` and on the Usage page's own cards (`Quotas` → `cardsServed`, this computer's cards only, the caches left alone). The Usage page and the tray panel show the last-answered account in full, and a menu bar card that follows the account in use (`codex|*`) takes the one that answered within the last hour, else `InUseLogin`'s guess, else the one that answered last at all (a plugin's accounts, #1516) (`trayInUseCard`; okingkee on X: A spent, B answering, the menu bar stayed on A). `NoteServed` calls `OnServedMoved` when a provider's answers move to another account or key, and `SwitchLogin` after a switch, so the menu bar reads its cards again at once. | [`served.go`](../../internal/provider/served.go), [`trayusage.go`](../../internal/gui/trayusage.go) |
|
||||
| Partners | Services that pay to be listed first in the add sheet, under a heading of their own ("Partners · magpie's sponsors"). The list is `site/partners.js`, served at `usemagpie.ai/api/partners`: a change reaches users with a deploy, not a release. `Partners` never waits: it returns what was fetched last and fetches again behind the call on a process's first ask, whatever the kept list's age, and hourly after (10 minutes after a failure), keeping the list in `partners.json` in the cache folder. The magpie serving the gateway fetches it when it starts and whenever it is due, asked for or not (`KeepPartnersFresh`), so an app left open on another page still learns of a partner added. The file also says when the last fetch started (`tried`) and, when it failed, why (`error`, logged once until a fetch gets the list again), so a list that stops changing tells a fetch that fails from one that never came back (`tried` after `at`, no error) and from none asked (#3362). Each entry is checked again on every read (`validPartners`): its own id, never a built-in preset's, a name, an endpoint, https only, at most 12; what only magpie's presets may set (a decision API, no key, a user endpoint) is cleared. Its logo is fetched through `FetchIcon` and kept as an uploaded icon, used as it is while its `iconUrl` stays the same; the prune after a save of `providers.json` (`pruneIcons`) leaves the logos of the partners listed now (`keptPartnerIcons`), as it leaves a plugin's. A partner is a preset to the rest of magpie (`Preset`, `FromPreset`, the editor), and one no longer listed still is to the providers added from it (`Seen`), without the sponsored mark. The window lists a partner in the languages it names (`langs`) only and shows its tagline in the page's language (`notes`, else `en`). `MAGPIE_PARTNERS` points it elsewhere, `off` lists none; tests list none unless they name a list. How often each listed partner was shown, opened (its row, its key page) and added is counted per UTC day (`CountPartner`, capped at 20 of each and 5 adds, kept in `partner-counts.json` in the cache folder) and sent with the next day's stats event as `magpie partner` events (`internal/stats`); nothing is counted with the stats or their usage part off. A listed partner the add sheet (or the TUI's, or `magpie providers presets`) hasn't shown yet is new (`NoticePartners` keeps those shown, as `noticed` in `partners.json`, whatever the stats); the window's add button carries a small dot for it, with its name in the title, until the sheet shows it. | [`partners.go`](../../internal/provider/partners.go), [`partner_events.go`](../../internal/provider/partner_events.go), [`site/partners.js`](../../site/partners.js) |
|
||||
|
||||
@@ -405,10 +405,22 @@ func KimiCodeSearch(p Provider) string {
|
||||
//
|
||||
// usage is the week's allowance, each of limits a shorter window; the
|
||||
// numbers come as strings or numbers, used or what remains.
|
||||
//
|
||||
// A plan on Kimi's monthly allowance (lidazi2016 on Discord) is also, or
|
||||
// only, told as shares in usages, as kimi-code reads them
|
||||
// (packages/oauth/src/managed-usage.ts, usage-format.ts):
|
||||
//
|
||||
// "usages":{"limit_5h":{"used_ratio":0.4372,"reset_time":"…"},
|
||||
// "limit_7d":{…},"limit_month_total":{…},"limit_month_code":{…}}
|
||||
//
|
||||
// limit_month_total is the month's allowance; limit_month_code is the
|
||||
// share of it code has used, no allowance of its own, so it isn't shown.
|
||||
// A window told both ways is taken from usages, as kimi-code does.
|
||||
func readKimiCode(b []byte) (string, []QuotaWindow, error) {
|
||||
type row map[string]any
|
||||
var r struct {
|
||||
Usage row `json:"usage"`
|
||||
Usage row `json:"usage"`
|
||||
Usages map[string]row `json:"usages"`
|
||||
Limits []struct {
|
||||
Window row `json:"window"`
|
||||
Detail row `json:"detail"`
|
||||
@@ -484,6 +496,47 @@ func readKimiCode(b []byte) (string, []QuotaWindow, error) {
|
||||
if w, ok := window(r.Usage, "7 days", 7*24*time.Hour); ok {
|
||||
out = append(out, w)
|
||||
}
|
||||
shares := []QuotaWindow{}
|
||||
for _, k := range []struct {
|
||||
key, name string
|
||||
span time.Duration
|
||||
}{{"limit_5h", "5 hours", 5 * time.Hour}, {"limit_7d", "7 days", 7 * 24 * time.Hour}, {"limit_month_total", "Month", 30 * 24 * time.Hour}} {
|
||||
d := r.Usages[k.key]
|
||||
ratio, ok := num(d["used_ratio"])
|
||||
if d == nil || !ok || math.IsNaN(ratio) || math.IsInf(ratio, 0) {
|
||||
continue
|
||||
}
|
||||
w := QuotaWindow{Name: k.name, Span: k.span, Used: max(0, min(100, ratio*100))}
|
||||
if s, _ := d["reset_time"].(string); s != "" {
|
||||
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
|
||||
w.ResetsAt = &t
|
||||
}
|
||||
}
|
||||
shares = append(shares, w)
|
||||
}
|
||||
if len(shares) > 0 {
|
||||
out = slices.DeleteFunc(out, func(w QuotaWindow) bool {
|
||||
return slices.ContainsFunc(shares, func(s QuotaWindow) bool { return s.Span == w.Span })
|
||||
})
|
||||
out = append(out, shares...)
|
||||
// shortest first, as the counted windows come; one of no known
|
||||
// length last
|
||||
span := func(w QuotaWindow) time.Duration {
|
||||
if w.Span == 0 {
|
||||
return math.MaxInt64
|
||||
}
|
||||
return w.Span
|
||||
}
|
||||
slices.SortStableFunc(out, func(a, b QuotaWindow) int {
|
||||
switch sa, sb := span(a), span(b); {
|
||||
case sa < sb:
|
||||
return -1
|
||||
case sa > sb:
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
})
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return "", nil, fmt.Errorf("no usage in the reply")
|
||||
}
|
||||
|
||||
@@ -433,6 +433,55 @@ func TestReadKimiCode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A plan on Kimi's monthly allowance tells it in usages, as shares
|
||||
// (lidazi2016 on Discord: 5h and weekly shown, the month not). The first
|
||||
// body is a live reply of 2026-09-23 (narumiruna/pi-extensions#1390): no
|
||||
// weekly usage, the 5h window told both ways. The second has every
|
||||
// window kimi-code reads (managed-usage.ts); each is taken from usages,
|
||||
// limit_month_code shown not at all.
|
||||
func TestReadKimiCodeMonth(t *testing.T) {
|
||||
_, ws, err := readKimiCode([]byte(`{
|
||||
"limits": [
|
||||
{
|
||||
"window": { "duration": 300, "timeUnit": "TIME_UNIT_MINUTE" },
|
||||
"detail": { "limit": "100", "used": "44", "remaining": "56", "resetTime": "2026-09-23T06:47:09.122865Z" }
|
||||
}
|
||||
],
|
||||
"usages": {
|
||||
"limit_5h": { "used_ratio": 0.4372, "reset_time": "2026-09-23T06:47:08Z" },
|
||||
"limit_month_total": { "used_ratio": 0.7877, "reset_time": "2026-10-17T00:00:00Z" },
|
||||
"limit_month_code": { "used_ratio": 0.7877, "reset_time": "2026-10-17T00:00:00Z" }
|
||||
},
|
||||
"booster_wallet": {}
|
||||
}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ws) != 2 || ws[0].Name != "5 hours" || math.Abs(ws[0].Used-43.72) > 1e-9 || ws[0].Span != 5*time.Hour || ws[0].ResetsAt == nil || ws[0].ResetsAt.Second() != 8 ||
|
||||
ws[1].Name != "Month" || math.Abs(ws[1].Used-78.77) > 1e-9 || ws[1].Span != 30*24*time.Hour || ws[1].ResetsAt == nil || ws[1].ResetsAt.Day() != 17 {
|
||||
t.Fatalf("%+v", ws)
|
||||
}
|
||||
|
||||
_, ws, err = readKimiCode([]byte(`{"usage":{"limit":"100","used":"30","resetTime":"2026-10-31T05:24:18.44Z"},
|
||||
"limits":[{"window":{"duration":300,"timeUnit":"TIME_UNIT_MINUTE"},"detail":{"limit":"100","remaining":"88","resetTime":"2026-10-29T09:00:00Z"}}],
|
||||
"usages":{"limit_month_code":{"used_ratio":0.1},"limit_month_total":{"used_ratio":"0.4","reset_time":"2026-11-18T00:00:00Z"},
|
||||
"limit_7d":{"used_ratio":0.3012,"reset_time":"2026-10-31T05:24:18Z"},"limit_5h":{"used_ratio":0.1234}}}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ws) != 3 || ws[0].Name != "5 hours" || math.Abs(ws[0].Used-12.34) > 1e-9 || ws[0].ResetsAt != nil ||
|
||||
ws[1].Name != "7 days" || math.Abs(ws[1].Used-30.12) > 1e-9 || ws[1].Span != 7*24*time.Hour ||
|
||||
ws[2].Name != "Month" || math.Abs(ws[2].Used-40) > 1e-9 || ws[2].ResetsAt == nil || ws[2].ResetsAt.Day() != 18 {
|
||||
t.Fatalf("%+v", ws)
|
||||
}
|
||||
|
||||
// a share that isn't a number is no window; the counted ones stand
|
||||
_, ws, err = readKimiCode([]byte(`{"usage":{"limit":"100","used":"12"},"usages":{"limit_month_total":{"used_ratio":null},"limit_7d":{"reset_time":"2026-10-31T05:24:18Z"}}}`))
|
||||
if err != nil || len(ws) != 1 || ws[0].Name != "7 days" || ws[0].Used != 12 {
|
||||
t.Fatalf("%+v %v", ws, err)
|
||||
}
|
||||
}
|
||||
|
||||
// An OpenCode Go key whose windows can't be read says why, with the way
|
||||
// out (sakulalalalalal on X: three Go keys, each "Allowance unavailable"
|
||||
// and nothing more). The bodies are OpenCode's own, as zen/go/v1/usage
|
||||
|
||||
Reference in New Issue
Block a user