import { TraceContext } from "autotel"; //#region src/streaming.d.ts /** Distribution summary of the gaps between streamed output chunks (seconds). */ export interface ChunkIntervalStats { min: number; p10: number; median: number; avg: number; p90: number; max: number; } /** Computed streaming timing for one call. All durations are in **seconds**. */ export interface StreamTiming { /** Seconds from request start to the first streamed chunk. */ timeToFirstChunk?: number; /** Seconds from request start to the final chunk (total response time). */ timeToFinish: number; /** Output tokens ÷ total response time. `undefined` without token counts. */ outputTokensPerSecond?: number; /** * Output tokens ÷ time _after_ the first chunk — the steady-state generation * rate, excluding the initial wait. `undefined` without enough data. */ steadyOutputTokensPerSecond?: number; /** Mean seconds between streamed chunks. */ timePerOutputChunk?: number; /** Number of chunks observed. */ chunkCount: number; /** Distribution of inter-chunk gaps, when chunk timestamps were recorded. */ chunkIntervals?: ChunkIntervalStats; } /** * Summarise the gaps between consecutive chunk timestamps (epoch ms). Returns * `undefined` for fewer than two intervals (no gap to measure). */ export declare function chunkIntervalStats(timestampsMs: readonly number[]): ChunkIntervalStats | undefined; /** Inputs for {@link computeStreamTiming}. Timestamps are epoch ms. */ export interface ComputeStreamTimingInput { /** Request start time (epoch ms). */ startTime: number; /** First-chunk time (epoch ms). Omit for a non-streamed response. */ firstChunkTime?: number; /** Finish time (epoch ms). */ finishTime: number; /** Output tokens generated, for throughput. */ outputTokens?: number; /** Number of chunks observed (defaults to derived from timestamps). */ chunkCount?: number; /** Per-chunk timestamps (epoch ms) for the inter-chunk distribution. */ chunkTimestamps?: readonly number[]; } /** * Compute {@link StreamTiming} from raw timestamps. Pure — no telemetry side * effects. Pair with {@link recordStreamTiming} to record the result. */ export declare function computeStreamTiming(input: ComputeStreamTimingInput): StreamTiming; /** * Record the headline streaming-timing attributes on the active span: * `gen_ai.response.time_to_first_chunk` (spec) plus the autotel extensions * `gen_ai.response.time_to_finish`, `…output_tokens_per_second`, and * `…time_per_output_chunk`. All in seconds. Absent fields are skipped. */ export declare function recordStreamTiming(ctx: Pick, timing: StreamTiming): void; /** A running stream timer. */ export interface StreamTimer { /** * Mark a streamed chunk. The first call also records the first-chunk time. * Cheap to call per chunk. */ chunk(): void; /** Finalise and compute {@link StreamTiming}. */ finish(usage?: { outputTokens?: number; }): StreamTiming; } /** * Create a {@link StreamTimer} that timestamps chunks as they arrive. Call * {@link StreamTimer.chunk} once per streamed chunk and * {@link StreamTimer.finish} when the stream ends. * * @param now Clock injection point, for tests. Defaults to {@link Date.now}. */ export declare function createStreamTimer(now?: () => number): StreamTimer; //#endregion