{"version":3,"sources":["../../src/metrics/base.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport type MetricsMetadata = {\n  /** The provider name (e.g., 'openai', 'anthropic'). */\n  modelProvider?: string;\n  /** The model name (e.g., 'gpt-4o', 'claude-3-5-sonnet'). */\n  modelName?: string;\n};\n\nexport type AgentMetrics =\n  | STTMetrics\n  | LLMMetrics\n  | TTSMetrics\n  | VADMetrics\n  | EOUMetrics\n  | EOTInferenceMetrics\n  | RealtimeModelMetrics\n  | InterruptionMetrics\n  | AvatarMetrics;\n\nexport type LLMMetrics = {\n  type: 'llm_metrics';\n  label: string;\n  requestId: string;\n  timestamp: number;\n  /** Duration of the request in milliseconds. */\n  durationMs: number;\n  /** Time to first token in milliseconds. */\n  ttftMs: number;\n  cancelled: boolean;\n  completionTokens: number;\n  promptTokens: number;\n  promptCachedTokens: number;\n  /** Tokens used to write to the prompt cache. Not all providers report this. */\n  cacheCreationTokens?: number;\n  totalTokens: number;\n  tokensPerSecond: number;\n  speechId?: string;\n  /** Metadata for model provider and name tracking. */\n  metadata?: MetricsMetadata;\n};\n\nexport type STTMetrics = {\n  type: 'stt_metrics';\n  label: string;\n  requestId: string;\n  timestamp: number;\n  /**\n   * The request duration in milliseconds, 0.0 if the STT is streaming.\n   */\n  durationMs: number;\n  /**\n   * The duration of the pushed audio in milliseconds.\n   */\n  audioDurationMs: number;\n  /** Input audio tokens (for token-based billing). */\n  inputTokens?: number;\n  /** Output text tokens (for token-based billing). */\n  outputTokens?: number;\n  /**\n   * Whether the STT is streaming (e.g using websocket).\n   */\n  streamed: boolean;\n  /** Metadata for model provider and name tracking. */\n  metadata?: MetricsMetadata;\n};\n\nexport type TTSMetrics = {\n  type: 'tts_metrics';\n  label: string;\n  requestId: string;\n  timestamp: number;\n  /** Time to first byte in milliseconds. */\n  ttfbMs: number;\n  /** Total synthesis duration in milliseconds. */\n  durationMs: number;\n  /** Generated audio duration in milliseconds. */\n  audioDurationMs: number;\n  cancelled: boolean;\n  /** Number of characters synthesized (for character-based billing). */\n  charactersCount: number;\n  /** Input text tokens (for token-based billing, e.g., OpenAI TTS). */\n  inputTokens?: number;\n  /** Output audio tokens (for token-based billing, e.g., OpenAI TTS). */\n  outputTokens?: number;\n  streamed: boolean;\n  segmentId?: string;\n  speechId?: string;\n  /** Metadata for model provider and name tracking. */\n  metadata?: MetricsMetadata;\n};\n\nexport type VADMetrics = {\n  type: 'vad_metrics';\n  label: string;\n  timestamp: number;\n  idleTimeMs: number;\n  inferenceDurationTotalMs: number;\n  inferenceCount: number;\n};\n\nexport type EOUMetrics = {\n  type: 'eou_metrics';\n  timestamp: number;\n  /**\n   * Amount of time between the end of speech from VAD and the decision to end the user's turn.\n   * Set to 0.0 if the end of speech was not detected.\n   */\n  endOfUtteranceDelayMs: number;\n  /**\n   * Time taken to obtain the transcript after the end of the user's speech.\n   * Set to 0.0 if the end of speech was not detected.\n   */\n  transcriptionDelayMs: number;\n  /**\n   * Time taken to invoke the user's `Agent.onUserTurnCompleted` callback.\n   */\n  onUserTurnCompletedDelayMs: number;\n  /**\n   * The time the user stopped speaking.\n   */\n  lastSpeakingTimeMs: number;\n  /**\n   * The ID of the speech handle.\n   */\n  speechId?: string;\n};\n\nexport type RealtimeModelMetricsCachedTokenDetails = {\n  audioTokens: number;\n  textTokens: number;\n  imageTokens: number;\n};\n\nexport type RealtimeModelMetricsInputTokenDetails = {\n  audioTokens: number;\n  textTokens: number;\n  imageTokens: number;\n  cachedTokens: number;\n  cachedTokensDetails?: RealtimeModelMetricsCachedTokenDetails;\n};\n\nexport type RealtimeModelMetricsOutputTokenDetails = {\n  textTokens: number;\n  audioTokens: number;\n  imageTokens: number;\n};\n\nexport type RealtimeModelMetrics = {\n  type: 'realtime_model_metrics';\n  label: string;\n  requestId: string;\n  /**\n   * The timestamp of the response creation.\n   */\n  timestamp: number;\n  /**\n   * The duration of the response from created to done in milliseconds.\n   */\n  durationMs: number;\n  /**\n   * The duration of the session connection in milliseconds (for session-based billing like xAI).\n   */\n  sessionDurationMs?: number;\n  /** Time to acquire the realtime connection, in milliseconds. */\n  acquireTimeMs?: number;\n  /** Whether an existing realtime connection was reused. */\n  connectionReused?: boolean;\n  /**\n   * Time to first audio token in milliseconds. -1 if no audio token was sent.\n   */\n  ttftMs: number;\n  /**\n   * Whether the request was cancelled.\n   */\n  cancelled: boolean;\n  /**\n   * The number of input tokens used in the Response, including text and audio tokens.\n   */\n  inputTokens: number;\n  /**\n   * The number of output tokens sent in the Response, including text and audio tokens.\n   */\n  outputTokens: number;\n  /**\n   * The total number of tokens in the Response.\n   */\n  totalTokens: number;\n  /**\n   * The number of tokens per second.\n   */\n  tokensPerSecond: number;\n  /**\n   * Details about the input tokens used in the Response.\n   */\n  inputTokenDetails: RealtimeModelMetricsInputTokenDetails;\n  /**\n   * Details about the output tokens used in the Response.\n   */\n  outputTokenDetails: RealtimeModelMetricsOutputTokenDetails;\n  /** Metadata for model provider and name tracking. */\n  metadata?: MetricsMetadata;\n};\n\n/**\n * Per-prediction telemetry for the audio EOT (end-of-turn) detector. Emitted\n * by transports on each cloud or local prediction so we can track detection\n * latency and inference time per call.\n */\nexport type EOTInferenceMetrics = {\n  type: 'eot_inference_metrics';\n  timestamp: number;\n  /** Latest RTT time taken to perform inference, in milliseconds. */\n  totalDuration: number;\n  /** Latest time taken by the model side, in milliseconds. */\n  predictionDuration: number;\n  /** Latest total time from audio-frame creation to prediction receive, in milliseconds. */\n  detectionDelay: number;\n  /** Number of prediction requests served (incremental). */\n  numRequests: number;\n  metadata?: MetricsMetadata;\n};\n\nexport type InterruptionMetrics = {\n  type: 'interruption_metrics';\n  timestamp: number;\n  /** Latest RTT time taken to perform inference, in milliseconds. */\n  totalDuration: number;\n  /** Latest time taken by the model side, in milliseconds. */\n  predictionDuration: number;\n  /** Latest total time from onset of speech to final prediction, in milliseconds. */\n  detectionDelay: number;\n  /** Number of interruptions detected (incremental). */\n  numInterruptions: number;\n  /** Number of backchannels detected (incremental). */\n  numBackchannels: number;\n  /** Number of requests sent to the model (incremental). */\n  numRequests: number;\n  metadata?: MetricsMetadata;\n};\n\nexport type AvatarMetrics = {\n  type: 'avatar_metrics';\n  timestamp: number;\n  /** Delay between forwarding the first audio frame to the avatar and playback start. */\n  playbackLatencyMs?: number;\n  /** Time when the avatar session was started. */\n  sessionStartedAt?: number;\n  /** Time when the avatar participant joined and published a video track. */\n  avatarJoinedAt?: number;\n  metadata?: MetricsMetadata;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}