Estimates token usage and plans batches for AI decision requests.
// Source: https://github.com/garrytan/gbrain | License: MIT | Copyright 2026 Garry Tan
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Packing planner and bounded batch runner (generalized from the #5178
* TypeSafe reranker adapter).
*
* Shared state is sent once per batch, one question per candidate/segment.
* Token estimates are conservative (2x the local estimate, with a digit floor
* because some tokenizers split digits individually). Batches are split BEFORE
* any transport call; evidence is never truncated. Limits: 64k tokens per
* request (state + all questions) and 32k for state + the longest question.
*/
import { estimateTokens } from '../../chunkers/token-estimate.ts';
import { DecideError, type DecideLane, type DecideQuestion, type DecideSlot } f
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key