import type { PipelineTraceStep } from '../pipeline/types.js'; /** Where metrics go: counters, histograms, and gauges, labelled. */ export interface MetricsSink { /** Adds to a counter. */ increment(name: string, value?: number, labels?: Record): void | Promise; /** Records a value in a histogram, such as a latency. */ observe(name: string, value: number, labels?: Record): void | Promise; /** Sets a gauge. */ gauge?(name: string, value: number, labels?: Record): void | Promise; } /** Metrics collection for a client. */ export interface MetricsConfig { /** Turns collection on. Off by default, and then nothing is recorded. */ enabled?: boolean; /** * Where metrics go. Defaults to an in-memory sink, readable through `getMetricsSnapshot()` and * `getPrometheusMetrics()`. */ sink?: MetricsSink; /** Prefix for metric names. Defaults to `nexus_ai`. */ prefix?: string; /** * Ignored: Prometheus text is always available from `getPrometheusMetrics()`. * * @deprecated Has never been read. It will be removed in 2.0. */ prometheus?: boolean; } /** Keeps metrics in memory, for a snapshot or a Prometheus scrape. */ export declare class InMemoryMetrics implements MetricsSink { private counters; private histograms; private gauges; /** Adds to a counter. */ increment(name: string, value?: number, labels?: Record): void; /** Records a value in a histogram. */ observe(name: string, value: number, labels?: Record): void; /** Sets a gauge. */ gauge(name: string, value: number, labels?: Record): void; /** Every metric as plain data: counters, histogram count, average and maximum, and gauges. */ snapshot(): Record; /** Every metric in Prometheus text exposition format. */ toPrometheus(prefix?: string): string; private key; } /** The part of an OpenTelemetry meter the metrics sink uses. */ export interface OpenTelemetryLikeMeter { /** Creates a counter. */ createCounter(name: string): { add(value: number, labels?: Record): void; }; /** Creates a histogram. */ createHistogram(name: string): { record(value: number, labels?: Record): void; }; /** Creates an observable gauge. */ createObservableGauge?: (name: string) => unknown; } /** Sends metrics to OpenTelemetry through a meter. */ export declare class OpenTelemetryMetricsSink implements MetricsSink { private meter; private counters; private histograms; constructor(meter: OpenTelemetryLikeMeter); /** Adds to a counter, creating it on first use. */ increment(name: string, value?: number, labels?: Record): void; /** Records a value in a histogram, creating it on first use. */ observe(name: string, value: number, labels?: Record): void; } /** * Records request, response, error, and pipeline-step metrics for a client, when metrics are * enabled. */ export declare class MetricsCollector { private config; private memory; private sink?; private prefix; constructor(config?: MetricsConfig); /** Counts a request. */ recordRequest(labels: Record): Promise; /** Counts an error. */ recordError(labels: Record): Promise; /** Counts a response and records its latency and cost. */ recordResponse(labels: Record, latencyMs: number, cost?: number): Promise; /** Records how long a pipeline stage took. */ recordStep(step: PipelineTraceStep): Promise; /** The in-memory metrics, as plain data. */ snapshot(): Record; /** The in-memory metrics, in Prometheus text format. */ toPrometheus(): string; }