/** * Port of the Mode-Latency-Benchmark provider table and request builders * (`upstream/Mode-Latency-Benchmark/src/model_latency_benchmark/core.py`, * commit 8123838, Apache-2.0), plus the percentile statistics the plugin * aggregates from measured call durations. * * The upstream tool probes providers over HTTP; the plugin reuses its * `BenchmarkResult` vocabulary (ttft / total time / tokens / error) and adds * `latencyStats` for per-model percentile aggregation over the llm/stream * wrapper. * * @module dsh-budget/estimate/latency-stats */ /** Authentication style of one upstream provider config. */ export type ProviderAuthType = 'bearer' | 'query_param'; /** One provider config entry, verbatim from upstream core.py. */ export interface ProviderSpec { /** Display name. */ name: string; /** HTTP endpoint. */ endpoint: string; /** Environment variable carrying the API key. */ envKey: string; /** Default model id. */ model: string; /** Authentication style. */ authType: ProviderAuthType; /** Terminal color tag. */ color: string; /** Terminal icon. */ icon: string; } /** The upstream provider table (4 entries), verbatim. */ export declare const PROVIDERS: Readonly>; /** One benchmark outcome (upstream BenchmarkResult vocabulary). */ export interface BenchmarkResult { /** Provider table key. */ providerId: string; /** Provider display name. */ providerName: string; /** Time to first token in seconds; null when never reached. */ ttft: number | null; /** Total response time in seconds; null on failure. */ totalTime: number | null; /** Chunk/token count observed. */ tokens: number; /** Failure detail; null on success. */ error: string | null; /** Whether the run completed. */ success: boolean; } /** * Build the request headers for one provider, upstream style. * * @param provider - provider config (reads `authType` only). * @param apiKey - provider API key (used only for bearer auth). * @returns the header map. */ export declare function buildRequestHeaders(provider: Readonly, apiKey: string): Record; /** * Build the request body for one provider, upstream style. * * @param provider - provider config. * @param prompt - the user prompt. * @returns the JSON body object. */ export declare function buildRequestBody(provider: Readonly, prompt: string): Record; /** * Build the request URL for one provider, upstream style (query-param auth * appends the key). * * @param provider - provider config. * @param apiKey - provider API key (used only for query-param auth). * @returns the request URL. */ export declare function buildRequestUrl(provider: Readonly, apiKey: string): string; /** Percentile statistics over one duration sample window (milliseconds). */ export interface LatencyStats { /** Sample count. */ count: number; /** Arithmetic mean (ms). */ mean: number; /** Minimum (ms). */ min: number; /** Maximum (ms). */ max: number; /** 50th percentile (ms). */ p50: number; /** 95th percentile (ms). */ p95: number; /** 99th percentile (ms). */ p99: number; /** Population standard deviation (ms). */ stdev: number; } /** * Aggregate latency statistics over a sample window. Deterministic and pure: * callers own the sample retention policy. * * @param samples - durations in milliseconds (any order, may be empty). * @returns the statistics; every field is 0 for an empty window. */ export declare function latencyStats(samples: readonly number[]): LatencyStats; /** * Format a millisecond duration the way the upstream tool displays it. * * @param ms - duration in milliseconds. * @returns `123ms` for sub-second values, `1.23s` otherwise. */ export declare function formatMs(ms: number): string; //# sourceMappingURL=latency-stats.d.ts.map