@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
39 lines • 2.15 kB
TypeScript
import type { LimitWindow } from "./limit-windows.ts";
export interface CachedReading {
readonly windows: readonly LimitWindow[];
readonly plan?: string;
readonly error?: string;
/** When the provider answered (or refused). */
readonly updatedAt: number;
/** Not asked again before this: the freshness window on success, the backoff on failure. */
readonly nextAt: number;
/**
* No answer yet: there was nothing to ask with (a claude CLI account on macOS, an expired token). It only
* schedules the next look and is never handed to the limit store, so it cannot blank windows a turn recorded.
*/
readonly pending?: true;
}
interface FetchClaim {
readonly claimedAt: number;
readonly token: string;
}
export interface UsageCacheFile {
readonly accounts: Readonly<Record<string, CachedReading>>;
readonly fetching: Readonly<Record<string, FetchClaim>>;
}
export declare const CLAIM_MS = 30000;
export declare function usageKey(provider: string, account: string): string;
/**
* Due at its scheduled time, or, given `minAgeMs`, once a healthy reading is that old. A failed reading keeps its
* schedule, so an endpoint that asked to be left alone is never asked early. Never due while another claim is live.
*/
export declare function isDue(cache: UsageCacheFile, key: string, now: number, minAgeMs?: number): boolean;
export declare function withClaims(cache: UsageCacheFile, keys: readonly string[], now: number, token: string): UsageCacheFile;
export declare function claimedBy(cache: UsageCacheFile, keys: readonly string[], token: string): string[];
/** Folds this process's results in and releases its claims; a failure keeps the last windows beside it. */
export declare function withResults(cache: UsageCacheFile, results: ReadonlyMap<string, CachedReading>, token: string): UsageCacheFile;
export declare function readUsageCache(path: string): UsageCacheFile;
/** Atomic replace, last writer wins: right for a cache, and lock-free. */
export declare function writeUsageCache(path: string, cache: UsageCacheFile): void;
export {};
//# sourceMappingURL=usage-cache.d.ts.map