ac4af582301a4e8a29245dbba767eba31334ddf9
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
37df73b1bb |
balance: a key holds several credits that expire, each added and removed on its own
tenacious_eagle_96548 (Discord, 11-08) has two promotional credits on one
key, one ending tomorrow and one the day after. v0.1.3305 kept one grant
per key, and its form showed the date only after Enter or a blur, with no
button to confirm.
- OwnBalance.Expiring is now a list (`expirings`, up to 20). Spending
goes to the grant that ends soonest first (ties by when it was typed),
and each grant drops out at its day. A write prunes ended grants.
- The pill and the menu say "Expires in N days" per grant, amber from 7
days. The menu has a Remove item per grant, "Add credit that
expires…" and "No credit that expires" to clear them all.
- The form shows the amount and the last day together, the day filled in
30 days ahead, with an Add button; Enter adds, Escape cancels, a bad
amount or a past day is refused in place. The app's own menu, no
native select, no stripes. A pill with two or more grants wraps at a
grant on a narrow row (a class, not :has(), for Safari before 15.4).
- CLI: `--expiring amount@day` can be given several times, `--expiring
off` clears all, `--expiring-remove [amount@]day` removes one. --help
prints usage; a day that isn't a date, or is past, is refused.
- /api/provider/keyexpiring adds `{expiring:{amount,until}}`, removes
`{expiring:{at,until},remove:true}`, clears `{expiring:null}`.
Old data: a v0.1.3305 single `expiring` grant is read as the first grant
and saved as `expirings` on the next write, for every user. An older
magpie reading the new file sees no grants (the balance itself stays).
Run on mote at
|
||
|
|
c736906b17 |
providers: part of a key's typed balance may expire on a day
tenacious_eagle_96548 (Discord, #general): some vendors split a balance
into money that stays and credit good until a date. A key's balance typed
by hand can now carry that part (`expiring`: {amount, until, at}, in the
balance's currency, until = the last day it counts).
- Spending order: the expiring part is spent first, as DeepSeek spends
its granted balance before money topped up. It takes the spend from its
`at` up to its end (midnight after `until`, local time) or now; only
what it took after `From` comes off the rest, so a refill or typing the
balance again doesn't count it twice.
- Left is the whole balance. From its end the remainder counts no more,
and unspent credit is gone.
- Typing the balance again keeps the part in the same currency and drops
it in the other, where its amount would mean another sum.
- A balance saved before has no part and reads exactly as it did
(TestTypedBalanceSavedBeforeExpiring).
- Set from the pill's menu: "Credit that expires…" asks the amount, then
the last day (a day gone by, or the other currency's sign, refused);
"No credit that expires" takes it off. GUI route provider/keyexpiring;
CLI `magpie provider key-balance <id> <key> --expiring amount@yyyy-mm-dd|off`.
- Shown: the pill "≈$100.00 left · $30.00 expires in 30 days", the Usage
page and panel line "Expires in 30 days ≈$30.00", amber from 7 days;
TUI and `magpie quota` "($30.00 until Dec 7)". New strings in zh,
zh-TW, ja and de.
Run (mote):
- go test of internal/provider, internal/gui, internal/cli (with
TestCoreScriptBudget: the days' lines in app.js are paid for by five
balance comments cut there, no raise; core 1,533,559 of 1,533,802); the new tests
again with TZ=UTC and TZ=Pacific/Kiritimati (every clock held);
gofmt -l clean; GOOS=linux and GOOS=windows go vet of those packages.
- GUI: key-balance-expiring.test.cjs 20/20 (chromium and webkit, 400px,
en/zh/zh-TW/ja/de), with every balance-*, key-*, i18n-* file: 768
pass, 6 red, each red the same alone on origin/main
|
||
|
|
0fc3455e2a |
providers: a key's typed balance may be in yuan and refill each month or week
tenacious_eagle_96548 asked, after v0.1.3281's typed balance, to type it
in RMB and to have it refill (e.g. $10 a month, on the 1st).
- A balance may be typed in yuan ("¥100", "100元", or a bare number while
Settings shows costs in CNY). What magpie counts spent stays in USD and
is turned into yuan at fx.Known(): the rate internal/fx last fetched
(cached 12h, fetched again in the background, never on a request).
fx.Known never returns fx.Fallback, so with no rate fetched and
something spent, what is left is unknown (left null; the card says
why), not a guess.
- An optional refill: monthly on day 1-31 (past a month's end, its last
day) or weekly on a weekday, at midnight in the user's local time.
Nothing is stored on a refill: the spend counts from the last boundary
after the balance was typed. Typing the amount again keeps the refill.
- GUI: the pill's menu gains Refills each month… (a day, in place),
Refills each week… (the app's menu of weekdays) and Never refills;
provider/keybalancerefill; keyownbalance takes currency cny. CLI:
magpie provider key-balance <id> <key> [usd|¥cny|off]
[--refill monthly[:day]|weekly[:mon…sun]|off]. Strings in zh, zh-TW,
ja, de. docs/subsystems/providers-accounts.md updated.
Run on mote at this tree (base origin/main
|
||
|
|
f8525323dd |
providers: a key with no balance URL takes a balance typed by hand, counted down by magpie's own usage
Some API-key providers tell no balance magpie can read (no Balance URL, no relay query found), so their keys showed none. Now the user types what the vendor's page says is left, on the key's row in the provider editor (Set balance) or with `magpie provider key-balance <id> [key [usd|off]]`. The key's card shows that less what magpie's usage priced the calls it sent on the key since it was typed (usage.KeySpent, the spend caps' count), marked as an estimate: "≈$12.50", the pill "≈$12.50 left", its title saying what was typed, when, and what was counted since. Typing it again counts from then; No balance takes it off. A balance the vendor tells always wins: a provider with a Balance URL, a plan source, Cline's or OpenCode Zen's card takes none typed, and a relay whose query is found shows its own; when the probe finds none (errNoBalance) the typed one is shown. A typed balance stays saved as the user left it: the editor's save keeps it, a key's replaced value carries it. An estimate is never kept in the balance history and tells routing nothing (the routing allowances cache is left alone). keybalance.js is loaded by keyspend.js (itself loaded when the editor draws a key) for a provider that takes one, so app.js and the core's script budget are unchanged. Words in zh, zh-TW, ja and de. Run at this tree (mote): - go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... at base 46b10af87; at this tree go vet of gui, provider, cli and usage; - go test -tags nogui -count=1 ./internal/gui ./internal/provider ./internal/cli ./internal/usage: provider and usage ok; gui and cli red only on #5644 below; TestCoreScriptBudget ok (1,533,747, as main) - the provider tests under -race -count=3; - GUI: key-own-balance (new: Chromium and WebKit, en zh zh-TW ja de, 900 and 400px, 20/20), key-spend-cap, old-webkit, i18n-keys, gui-de, gui-ja, gui-zh-tw, balance-found, key-balance-card, i18n-en-no-cjk: 104 pass, 1 fail, i18n-keys "a plugin's words are its own", red the same on origin/main |