import { log } from "../log.js";
function roundTwoDecimals(value) {
  return Math.round(value * 100) / 100;
}
const logMetrics = (metrics) => {
  var _a, _b;
  const logger = log();
  if (metrics.type === "llm_metrics") {
    logger.child({
      ttftMs: roundTwoDecimals(metrics.ttftMs),
      inputTokens: metrics.promptTokens,
      promptCachedTokens: metrics.promptCachedTokens,
      outputTokens: metrics.completionTokens,
      tokensPerSecond: roundTwoDecimals(metrics.tokensPerSecond)
    }).info("LLM metrics");
  } else if (metrics.type === "realtime_model_metrics") {
    logger.child({
      ttftMs: roundTwoDecimals(metrics.ttftMs),
      input_tokens: metrics.inputTokens,
      cached_input_tokens: metrics.inputTokenDetails.cachedTokens,
      output_tokens: metrics.outputTokens,
      total_tokens: metrics.totalTokens,
      tokens_per_second: roundTwoDecimals(metrics.tokensPerSecond)
    }).info("RealtimeModel metrics");
  } else if (metrics.type === "tts_metrics") {
    logger.child({
      ttfbMs: roundTwoDecimals(metrics.ttfbMs),
      audioDurationMs: Math.round(metrics.audioDurationMs)
    }).info("TTS metrics");
  } else if (metrics.type === "eou_metrics") {
    logger.child({
      endOfUtteranceDelayMs: roundTwoDecimals(metrics.endOfUtteranceDelayMs),
      transcriptionDelayMs: roundTwoDecimals(metrics.transcriptionDelayMs),
      onUserTurnCompletedDelayMs: roundTwoDecimals(metrics.onUserTurnCompletedDelayMs)
    }).info("EOU metrics");
  } else if (metrics.type === "vad_metrics") {
    logger.child({
      idleTimeMs: Math.round(metrics.idleTimeMs),
      inferenceDurationTotalMs: Math.round(metrics.inferenceDurationTotalMs),
      inferenceCount: metrics.inferenceCount
    }).info("VAD metrics");
  } else if (metrics.type === "stt_metrics") {
    logger.child({
      audioDurationMs: Math.round(metrics.audioDurationMs)
    }).info("STT metrics");
  } else if (metrics.type === "interruption_metrics") {
    logger.child({
      totalDurationMs: roundTwoDecimals(metrics.totalDuration),
      predictionDurationMs: roundTwoDecimals(metrics.predictionDuration),
      detectionDelayMs: roundTwoDecimals(metrics.detectionDelay),
      numInterruptions: metrics.numInterruptions,
      numBackchannels: metrics.numBackchannels,
      numRequests: metrics.numRequests
    }).info("Interruption metrics");
  } else if (metrics.type === "avatar_metrics") {
    const extra = {};
    if ((_a = metrics.metadata) == null ? void 0 : _a.modelProvider) extra.modelProvider = metrics.metadata.modelProvider;
    if ((_b = metrics.metadata) == null ? void 0 : _b.modelName) extra.modelName = metrics.metadata.modelName;
    if (metrics.sessionStartedAt !== void 0 && metrics.avatarJoinedAt !== void 0) {
      extra.avatarJoinLatencyMs = roundTwoDecimals(
        metrics.avatarJoinedAt - metrics.sessionStartedAt
      );
    }
    if (metrics.playbackLatencyMs !== void 0) {
      extra.playbackLatencyMs = roundTwoDecimals(metrics.playbackLatencyMs);
    }
    logger.child(extra).info("Avatar metrics");
  }
};
export {
  logMetrics
};
//# sourceMappingURL=utils.js.map