/** * OpenTelemetry metrics for composer next-message predictions. * * Attributes are low-cardinality and content-free: the outcome, the * `provider/model` that served the request, how many alternatives were offered * (1-4), and which one the user kept, never prompt or prediction text. * Every call is a no-op until OTLP metric export registers a global meter * provider (`OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`). Instruments bind lazily to * the current global provider because the metrics API has no proxy provider: a * meter taken before registration stays a no-op. * * Requests and display are separate series: a request settles on what the model * returned, and an offered prediction counts as shown once the composer first * paints it. Every shown prediction later resolves exactly once, so * `resolved{accepted}` over `shown` is the acceptance rate. */ import { type MeterProvider } from "@opentelemetry/api"; /** * How a prediction request settled: * - `offered`: usable reply, offered to the composer (shown once a frame paints it) * - `skipped`: the model declined (`NO_PREDICTION`) or replied with nothing usable * - `stale`: the conversation moved on before the reply arrived * - `cancelled`: superseded or cancelled (new turn, newer request, setting off) * - `timeout`: no reply before the prediction deadline * - `error`: the side turn failed */ export type PredictionOutcome = "offered" | "skipped" | "stale" | "cancelled" | "timeout" | "error"; /** What became of a shown prediction: one of its alternatives inserted with Tab/Right, or retired without that. */ export type PredictionResolution = { result: "accepted"; rank: number; } | { result: "ignored"; }; /** * Count one settled prediction request and record how long it took, by outcome and serving `provider/model`; * an offered request also carries how many alternatives it offered. */ export declare function recordPredictionRequest(outcome: PredictionOutcome, model: string, durationMs: number, choices: number | undefined, provider?: MeterProvider): void; /** Count one offered prediction, with how many alternatives it carries, on its first painted frame. */ export declare function recordPredictionShown(model: string, choices: number, provider?: MeterProvider): void; /** * Count one shown prediction as accepted or ignored. An accepted one carries the rank (0 is most likely) of * the alternative the user inserted last, and records how long the prediction was displayed before the * first insert. */ export declare function recordPredictionResolved(resolution: PredictionResolution, model: string, choices: number, shownForMs: number, provider?: MeterProvider): void;