/** * Routing telemetry emitter — T039; bounded split SP-276 (#143). * * Maintains an append-only rolling window of routing decisions for * observability and audit. Window bounds: 168 hours (7 days), max 1111 entries. * * SP-275 (#143 partial): the reason-code vocabulary, pure observability * builders, and the emitter port are domain-owned; infrastructure re-exports * them for import-path stability. * * SP-276 (#143): the SAAR/pin-economics builders moved to * `pin-economics-telemetry.ts`, planning-delegate fields to * `planning-delegate-telemetry.ts`, default/derived scalars and record * updates to `telemetry-scalar-fields.ts`, and the explain/log payload * builders to `routing-decision-log.ts`. This module keeps the rolling-window * emitter plus the cost estimator and re-exports the split symbols so * existing import paths stay stable. */ import type { ContextFitConfig } from '../../domain/routing/context-fit.js'; import type { SessionPinner } from '../../domain/pinning/session-pinner.js'; import type { ModelProfile, PriceCatalog, RoutingDecision, RoutingRequest, RoutingTelemetry, SaarConfig } from '../../domain/types/index.js'; import type { QuotaWindowPosition } from '../../domain/types/entities.js'; import type { VirtualCostV2Config } from '../../domain/types/schemas.js'; import { type CostCalibrationPrior } from '../../domain/routing/expected-cost.js'; import { type PeakPricingOptions } from '../../domain/pricing/peak-pricing.js'; import { type PeakPricingTelemetryFields, type RoutePathTelemetryExtras, type RoutingCostEstimator } from '../../domain/ports/telemetry-emitter-port.js'; export { CONTEXT_FIT_PASS, CONTEXT_FIT_REJECTED_ALL, CONTEXT_OVERFLOW_PIN_BREAK, HIGH_INTENSITY_STRUCTURAL, LOCAL_ZERO_DISABLED, LOW_INTENSITY_STRUCTURAL, PLANNING_DELEGATE, PLANNING_DELEGATE_DISABLED, PLANNING_DIRECT_FRONTIER, P_SUCCESS_CHEAP, P_SUCCESS_UNCERTAIN, THROUGHPUT_BELOW_THRESHOLD, TOOL_USE_CAPABILITY_SHORTFALL, buildContextFitObservability, buildLocalZeroSkipReasons, buildTierSelectionObservability, createPlanningDelegateObservability, enrichRoutingDecisionWithContextFit, enrichRoutingDecisionWithTierSelection, resolveTierSelectionReasonCode, } from '../../domain/ports/telemetry-emitter-port.js'; export type { ContextFitObservabilityInput, PeakPricingTelemetryFields, RoutePathTelemetryExtras, RoutingCostEstimator, TelemetryEmitterPort, TierSelectionObservabilityInput, } from '../../domain/ports/telemetry-emitter-port.js'; export { BREAKEVEN_BLOCKED, BREAKEVEN_PASS, DEFAULT_BREAKEVEN_TELEMETRY_FIELDS, DEFAULT_SAAR_TELEMETRY_FIELDS, FLIP_FLOP_TIER_FLIP, FLIP_FLOP_TIER_PINNED, SAAR_BUFFER_ACTIVE, SAAR_HARD_LOCK, buildBreakevenObservability, buildFlipFlopObservability, buildSaarObservability, enrichRoutingDecisionWithPinEconomics, } from './pin-economics-telemetry.js'; export type { BreakevenObservabilityV2, FlipFlopObservability, PinEconomicsObservabilityInput, } from './pin-economics-telemetry.js'; export { DEFAULT_PLANNING_DELEGATE_TELEMETRY_FIELDS, PLANNING_DELEGATE_TIMEOUT, PLANNING_DELEGATE_UNAVAILABLE, buildPlanningDelegateObservability, enrichRoutingDecisionWithPlanningDelegate, } from './planning-delegate-telemetry.js'; export { DEFAULT_CONTEXT_FIT_DATASET_FIELDS, DEFAULT_CONTEXT_FIT_TELEMETRY_FIELDS, DEFAULT_EMBEDDING_DATASET_FIELDS, DEFAULT_PEAK_PRICING_TELEMETRY_FIELDS, DEFAULT_PIN_ONLY_FALLBACK_TELEMETRY_FIELDS, DEFAULT_PREWARM_TELEMETRY_FIELDS, DEFAULT_TIER_SELECTION_DATASET_FIELDS, DEFAULT_TIER_SELECTION_TELEMETRY_FIELDS, DEFAULT_USAGE_ACTUALS_TELEMETRY_FIELDS, PIN_ONLY_FALLBACK, applyReasoningTelemetry, applyUsageActuals, extractUsageActuals, prewarmTelemetryFromDecision, resolvePinOnlyFallbackActive, } from './telemetry-scalar-fields.js'; export { buildPeakPricingObservability, buildRoutingDecisionLogPayload, enrichRoutingDecisionForExplain, } from './routing-decision-log.js'; export type { ExplainEnrichmentOptions, PeakPricingObservability, RoutingDecisionLogDelegate, } from './routing-decision-log.js'; export { DEFAULT_HISTORY_LIMIT, MAX_HISTORY_LIMIT, TELEMETRY_MAX_ENTRIES, TELEMETRY_WINDOW_HOURS, TELEMETRY_WINDOW_MS, } from './telemetry-limits.js'; /** * Estimate per-request routing cost in USD from resolved model pricing (SP-085). * Uses estimated_input_tokens when present, otherwise prompt_text length as a token proxy. * * SP-242 (#164): an optional rolling calibration prior (built from SP-241 * usage actuals) soft-biases the catalog rate by the warm actual/estimate * ratio (model bucket first, tier bucket fallback). Cold / missing prior or * bucket resolves ratio 1 — catalog estimate unchanged (fail open). * * SP-243 (#165): the peak/off-peak schedule adapters (Z.ai, DeepSeek) * soft-bias the resolved rate by the current pricing window — pass * `peak.now` in tests to freeze the clock. Non-target providers and any * adapter failure resolve multiplier 1 (fail open); no hard ban. */ export declare function estimateRoutingCost(model: ModelProfile, request: RoutingRequest, catalog: PriceCatalog | null, calibration?: CostCalibrationPrior | null, peak?: PeakPricingOptions): number; /** Default {@link RoutingCostEstimator} — wired by the composition root (SP-275, #143). */ export declare const defaultRoutingCostEstimator: RoutingCostEstimator; export interface TelemetryEmitterOptions { readonly maxEntries?: number; readonly windowMs?: number; readonly clock?: () => string; readonly onRecord?: (record: RoutingTelemetry) => void; readonly fleet?: readonly ModelProfile[]; readonly contextFitConfig?: ContextFitConfig; readonly sessionPinner?: SessionPinner; readonly saarConfig?: SaarConfig; readonly priceCatalog?: PriceCatalog | null; readonly quotaWindowPosition?: QuotaWindowPosition; readonly virtualCostV2Config?: VirtualCostV2Config; } export declare class RoutingTelemetryEmitter { private readonly entries; private readonly maxEntries; private readonly windowMs; private readonly clock; private readonly onRecord; private readonly fleet; private readonly contextFitConfig; private readonly sessionPinner; private readonly saarConfig; private readonly priceCatalog; private readonly quotaWindowPosition; private readonly virtualCostV2Config; constructor(options?: TelemetryEmitterOptions); /** * Emit a telemetry record from a completed routing decision. * Enforces the rolling window (time + count) before appending. */ emit(request: RoutingRequest, decision: RoutingDecision, extras?: RoutePathTelemetryExtras): RoutingTelemetry & PeakPricingTelemetryFields; /** * Emit telemetry when a pipeline stage throws and routing degrades to safe default. */ emitPipelineError(request: RoutingRequest, failedStage: string, fallback: RoutingDecision, extras?: RoutePathTelemetryExtras): RoutingTelemetry & PeakPricingTelemetryFields; private appendRecord; /** Current number of retained entries. */ get size(): number; /** Snapshot of all retained entries (newest last). */ snapshot(): readonly RoutingTelemetry[]; /** * Pricing window for the selected model (SP-243, #165). Fail open: unknown * models or non-target providers record 'none'. */ private resolvePricingWindow; } //# sourceMappingURL=routing-telemetry.d.ts.map