//#region src/capacity-tracker.d.ts /** * Client-side estimate of the organization's queue capacity, driven by the * `X-Task-Priority` / `X-P1-Capacity` / `X-P2-Capacity` / `X-P3-Capacity` * headers that pipe0's run-creating endpoints return on every response. * * The server never rejects below the hard ceiling — submissions just enter at * a worse priority — so pacing must be capacity-led rather than error-led: * the last create's headers are the authoritative baseline, records the SDK * observes completing (via its own polls or cancels) are credited back, and * any drift from other clients consuming capacity self-corrects at the next * create response. */ /** Estimated remaining records per priority window (P1 ≤ P2 ≤ P3). */ interface CapacitySnapshot { /** Priority the most recently observed run was admitted at. */ taskPriority: 1 | 2 | 3; /** Records that can still be submitted at priority 1. */ p1: number; /** Records that can still be submitted at priority 2 or better. */ p2: number; /** Records that can still be submitted at all — at 0, submissions 429. */ p3: number; /** When the underlying headers were observed (ms epoch). */ observedAt: number; } declare class CapacityTracker { /** Last authoritative header observation; null until the first create. */ private base; /** Records of creates issued whose response has not settled yet. */ private pending; /** Records credited back (completions/cancels) since `base` was observed. */ private credited; /** runId → records, for crediting terminal runs exactly once. */ private runRecords; /** * Re-baseline from a response's headers. Returns the adjusted snapshot, or * null when the response carries no capacity headers (e.g. an * `org-rate-limited` 429 emitted by middleware before the handler ran). */ observeHeaders(headers: Headers): CapacitySnapshot | null; /** Call synchronously BEFORE issuing a create — prevents two concurrent submitters from double-spending the same estimate. */ onCreateIssued(records: number): void; /** Call after the create response settled (the middleware has re-baselined by then). */ onCreateSettled(records: number): void; /** Remember a run's record weight so its completion can be credited back. */ registerRun(runId: string, records: number): void; /** * Credit a run's records back to every window estimate. The Map delete * makes double-crediting (cancel + a later poll observing "canceled") * impossible. Returns the credited record count (0 if unknown/already credited). */ creditTerminal(runId: string): number; /** * Estimated remaining records in the given priority window. Null when no * create has been observed yet — callers treat that as "gate open". */ estimate(floor: 1 | 2 | 3): number | null; /** The current adjusted snapshot, or null before the first observation. */ snapshot(): CapacitySnapshot | null; } //#endregion export { CapacitySnapshot, CapacityTracker }; //# sourceMappingURL=capacity-tracker.d.mts.map