feat(seats): an API seat's cycle starts on its own grant day
The ledger reset every API seat's spend on one REVIEW_GATES_API_CYCLE_DAY and cleared every credit-out, an OpenRouter key's too, at that reset. Each API seat's cycle starts on its ANTHROPIC_API_KEY<n>_GRANT_DAY now (1..31, a day past a month's end its last), else the cycle day, also 1..31. A credit-out carries across the rollover, and the run's probe tries a key held out on credit again, as `seats` does an API key: an ok lifts the mark - an API key's is new credits, its cycle restarting from the grant day, or from today when that day is over a week back; an OpenRouter key keeps its cycle's spend, and a key that answers with its cycle's budget spent stays out on that budget. A probe that finds a key out of credit records it, unless the ledger already has it out. Both are decided in one locked update on the file's entry, a mark another driver made since the probe started standing, and the ledger's stamps carry their UTC offset so marks are ordered by instant. `seats` shows the probe's reading beside the driver's verdict (the `probe` and `driver` columns replace `state` and `ledger: out`), each seat's grant day and when its next credits are due, and notes on what the probe changed in the ledger or why the driver's verdict stands; the run logs the days.
This commit is contained in:
parent
c6b4d78245
commit
ceb87f70ef
12 changed files with 774 additions and 83 deletions
|
|
@ -46,13 +46,18 @@ export namespace Crafter::Review::Seats {
|
|||
Json ConfigFromEnv(const std::map<std::string, std::string>& env);
|
||||
std::vector<std::pair<std::int32_t, std::string>> SeatTokensFromEnv(const std::map<std::string, std::string>& env);
|
||||
std::vector<std::pair<std::int32_t, std::string>> ApiKeysFromEnv(const std::map<std::string, std::string>& env);
|
||||
// {n: day}: ANTHROPIC_API_KEY<n>_GRANT_DAY, the day of the month seat n's
|
||||
// organization receives its plan's credits (the Console's
|
||||
// Promotional-credits expiry minus three days), 1..31; anything else is
|
||||
// ignored.
|
||||
std::map<std::int32_t, std::int32_t> ApiGrantDays(const std::map<std::string, std::string>& env);
|
||||
std::vector<std::pair<std::int32_t, std::string>> OpenRouterKeysFromEnv(const std::map<std::string, std::string>& env);
|
||||
// Every `[export ]NAME=value` line of a dotenv text, in order: blanks
|
||||
// around the `=` and the value dropped, one pair of matching quotes
|
||||
// stripped; anything else skipped.
|
||||
std::vector<std::pair<std::string, std::string>> DotenvLines(std::string_view text);
|
||||
// Only the seat lines of those: the OAuth tokens, the numbered API keys
|
||||
// and the OpenRouter keys; everything else ignored.
|
||||
// with their grant days and the OpenRouter keys; everything else ignored.
|
||||
std::map<std::string, std::string> SeatTokensFromEnvFile(std::string_view text);
|
||||
// The REVIEW_GATES_* lines of a dotenv file (quotes and `export`
|
||||
// stripped). SeatPool::SettingsOf lays the placement settings among them
|
||||
|
|
@ -142,7 +147,11 @@ export namespace Crafter::Review::Seats {
|
|||
std::string RenderTable(const std::vector<std::vector<std::string>>& rows);
|
||||
std::string RenderStatusReport(const std::vector<Json>& seats, const Json& config, double now, const Zone& zone, const Json& board = nullptr,
|
||||
const std::map<std::int32_t, std::string>& keys = {});
|
||||
std::string RenderApiReport(const std::vector<Json>& apiSeats, const Json& apiConfig, const Json& board = nullptr,
|
||||
// API-credit seats: the probe's verdict beside the driver's (its ledger
|
||||
// against the budget), the cycle, the grant day and when the next
|
||||
// credits are due - each seat's ledger, ledgerOut, grantDay, nextCredits
|
||||
// and the probe's ledger event as the seats command set them.
|
||||
std::string RenderApiReport(const std::vector<Json>& apiSeats, const Json& apiConfig, double now, const Json& board = nullptr,
|
||||
const std::map<std::int32_t, std::string>& keys = {});
|
||||
std::string RenderDrivers(const Json& board, double now, const Zone& zone);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue