import type { UsageMessage } from "./usage.js"; export interface PerformanceSummary { tps?: number; tpsEstimated?: boolean; /** Average time to first token, in milliseconds. */ ttft?: number; } export interface FirstTokenObservation { messageID: string; sessionID: string; started: number; first: number; } export interface PerformanceEvent { type: string; data: unknown; id?: string; created?: number; } export interface StreamSample { time: number; bytes: number; } export declare const LIVE_WINDOW_MS = 2000; export declare const LIVE_MIN_SPAN_MS = 500; export declare const LIVE_SAMPLE_MS = 100; export declare const LIVE_MIN_TOKENS = 20; export declare const LIVE_MIN_BATCHES = 3; export declare const LIVE_EWMA_ALPHA = 0.35; export declare const LIVE_BYTES_PER_TOKEN = 4; /** Quiet streams need a server liveness check, not a maximum tool-wait duration. */ export declare const ACTIVITY_CHECK_MS = 60000; export type ReadActiveSessions = (signal: AbortSignal) => Promise>; export interface PerformanceOptions { retention?: number; monotonic?: () => number; active?: ReadActiveSessions | undefined; } /** Requires three merged batches; the first is a baseline, not newly generated bytes. */ export declare function estimatedLiveTps(samples: readonly StreamSample[]): number | undefined; /** Time-based EWMA: elapsed time determines the weight, never delta count. */ export declare function smoothLiveTps(previous: number | undefined, raw: number, elapsed?: number): number; export interface PreparedPerformance { tps?: number; ttftSum: number; ttftCount: number; historical: ReadonlyMap; } export type PerformanceSubscribe = (listener: (event: PerformanceEvent) => void) => () => void; export type PerformanceListener = (sessionID: string) => void; /** Exact completed-run TPS and the average of only measurable TTFT samples. */ export declare function historicalPerformance(messages: Iterable, observations?: Iterable): PerformanceSummary; /** The immutable part of a snapshot is scanned once, then reused for stream updates. */ export declare function preparePerformance(messages: Iterable): PreparedPerformance; /** Captures streaming performance for every session for one plugin lifetime. */ export declare class PerformanceMonitor { private active; private observed; private listeners; private cleanupTimer; private synchronization; private disposed; private readonly unsubscribe; private readonly retention; private readonly monotonic; private readonly readActive; constructor(subscribe?: PerformanceSubscribe, options?: PerformanceOptions); listen(listener: PerformanceListener): () => void; dispose(): void; private key; private publish; private deleteSession; private resetLive; private touch; private finish; /** One shared, history-free read covers offscreen sessions too. Failures are not idle. */ private checkActivity; private prune; private scheduleCleanup; handle(event: PerformanceEvent): boolean; reconcile(messages: Iterable, sessionIDs: Iterable): void; summary(messages: Iterable, sessionIDs: Iterable): PerformanceSummary; summaryPrepared(prepared: PreparedPerformance, sessionIDs: Iterable): PerformanceSummary; }