import type { LLMProviders, LLMPurposes } from '../../LLMService.typedefs'; /** * Core LLM metrics that are always collected by the gateway. * These metrics are automatically populated during operations. */ export interface LLMMetrics { provider: LLMProviders; purpose: LLMPurposes; model: string | null; modelConfig: Record | null; method: string; status: 'success' | 'error' | 'cancelled'; tokens: { input: number; output: number; total: number; /** Input size of the single most recent request, unlike `input`, which sums every tool-loop round. */ lastRequestInput?: number; }; costs: { input: number; output: number; total: number; currency: string; }; } /** * Function type for writing LLM metrics. * * @param metrics - The LLM metrics to write * @returns A promise that resolves when the metrics have been written */ export type LLMMetricsWriter = (metrics: LLMMetrics) => Promise; /** * Simplified reporter interface for LLM metrics collection. * * @template ReporterContext - User-defined context schema type */ export interface LLMReporterInterface | undefined = undefined> { /** * Initializes a metrics writer that tracks timing and provides write function. * The returned write function automatically includes duration and can only be called once. * * @param reporterContext - Optional user-defined context to include with metrics * @returns Write function that stops timer and writes metrics */ initWriter(...args: ReporterContext extends undefined ? [] : [reporterContext: ReporterContext]): LLMMetricsWriter; }