@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
39 lines • 2.5 kB
TypeScript
/**
* Model-scoped rate limits (senpi#2555). An Anthropic subscription rejects a
* request with the unified rate-limit headers, and their representative claim
* names the exceeded window: `five_hour` and `seven_day` bind the account,
* while `seven_day_opus`, `seven_day_sonnet` and `seven_day_overage_included`
* bind one model family. Claude Code renders that claim into the failure text
* ("session limit", "weekly limit", "Opus limit", "Sonnet limit", "Fable
* limit"), so the family name in the limit phrase is the model-scope signal.
* An account-wide window never names a model; everything without a family
* stays account-wide.
*/
/** A model block's expiry, keyed by model family (`fable`) or, failing that, the exact model id. */
export type ModelBlocks = Readonly<Record<string, {
readonly blockedUntil: number;
}>>;
export declare function rateLimitModelFamily(text: string): string | undefined;
/**
* Where a model-scoped block is recorded: the family when the requested model
* belongs to it (one limit covers every Fable model), otherwise the exact model
* id, so a block never leaks onto a model the response did not name.
*/
export declare function modelBlockKey(family: string, modelId: string): string;
/** Whether a model block keyed by `key` (a family name or an exact model id) binds `modelId`. */
export declare function modelBlockApplies(key: string, modelId: string): boolean;
/** The latest live expiry among the blocks that bind `modelId`, or undefined when it is free. */
export declare function activeModelBlockUntil(blocks: ModelBlocks | undefined, modelId: string | undefined, now: number): number | undefined;
/**
* Drops expired entries and, when `servedModelId` is given, the entries that
* bind it (a model that just served is not limited). Undefined when empty, so
* a record never carries an empty map.
*/
export declare function pruneModelBlocks(blocks: ModelBlocks | undefined, now: number, servedModelId?: string): ModelBlocks | undefined;
export declare function withModelBlock(blocks: ModelBlocks | undefined, key: string, blockedUntil: number, now: number): ModelBlocks;
/**
* Union of two block maps, the later expiry winning per key: a failure without a
* reset hint, or a concurrent writer's stale snapshot, never shortens a live block.
*/
export declare function mergeModelBlocks(left: ModelBlocks | undefined, right: ModelBlocks | undefined, now: number): ModelBlocks | undefined;
//# sourceMappingURL=model-scope.d.ts.map