mirror of
https://github.com/bitbaum/ai-kit.git
synced 2026-12-05 09:41:21 +01:00
Three pure modules extracted from FleetCrown, where each was written after the
matching failure had already happened in production:
chain — a fallback list ACROSS VENDORS. A single pinned free model is a
scheduled outage, and stepping down to a smaller model at the
SAME vendor buys nothing: it draws on the same org-wide daily
budget, so when the day runs dry every link is already dead.
limits — the three kinds of 429 share a status, a `type` and a `code`, and
need OPPOSITE responses. Only the body separates them. Treating
`size` as `capacity` broke a tool loop on every single turn;
treating `daily` as `capacity` is the same mistake one level
deeper.
fair-share — divide a fixed daily pool across users active TODAY, paced through
the day, with a one-turn floor so nobody's first question is
refused. The goal is not throughput; it is that every active user
gets a usable amount every day.
No HTTP client on purpose. Every consumer already has its own calling
conventions, retries and logging; replacing those is a rewrite rather than an
adoption. This package supplies the decisions and leaves the fetch alone.
Two things fixed in the extraction rather than carried over:
- `humanizeWait`'s singular hour was unreachable. With the boundary at 90
minutes, anything reaching the hours branch divided to at least 1.5, which
rounds to 2 — so "about 1 hour" could never print and an hour-long wait was
announced as two. Boundary moved to 60 and the case is now tested.
- The fair-share header quoted a 10k turn cost. A measured turn was ~16k, so the
worked example understated the squeeze by nearly half.
Tests import the package BY NAME rather than reaching into dist/, so a broken
`exports` map or a `files` list that forgets to ship dist/ fails here instead of
at the first consumer's install.
31 tests, all green via `npm run verify`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
22 lines
1.0 KiB
Plaintext
22 lines
1.0 KiB
Plaintext
MIT License
|
|
|
|
Copyright (c) 2026 Mao Nakamoto
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|