import { filterZeroValues } from "../metrics/model_usage.js";
function createSessionReport(opts) {
  const timestamp = opts.timestamp ?? Date.now();
  const audioRecordingStartedAt = opts.audioRecordingStartedAt;
  return {
    jobId: opts.jobId,
    roomId: opts.roomId,
    room: opts.room,
    options: opts.options,
    events: opts.events,
    chatHistory: opts.chatHistory,
    enableRecording: opts.enableRecording ?? false,
    recordingOptions: opts.recordingOptions ?? {
      audio: false,
      traces: false,
      logs: false,
      transcript: false
    },
    startedAt: opts.startedAt ?? Date.now(),
    timestamp,
    audioRecordingPath: opts.audioRecordingPath,
    audioRecordingStartedAt,
    duration: audioRecordingStartedAt !== void 0 ? timestamp - audioRecordingStartedAt : void 0,
    modelUsage: opts.modelUsage
  };
}
function sessionReportToJSON(report) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  const events = [];
  const options = report.options;
  const interruptionConfig = (_a = options.turnHandling) == null ? void 0 : _a.interruption;
  const endpointingConfig = (_b = options.turnHandling) == null ? void 0 : _b.endpointing;
  const allowInterruptions = (interruptionConfig == null ? void 0 : interruptionConfig.enabled) !== void 0 ? interruptionConfig.enabled : (interruptionConfig == null ? void 0 : interruptionConfig.mode) !== void 0 ? true : options.allowInterruptions ?? ((_c = options.voiceOptions) == null ? void 0 : _c.allowInterruptions);
  const discardAudioIfUninterruptible = (interruptionConfig == null ? void 0 : interruptionConfig.discardAudioIfUninterruptible) ?? options.discardAudioIfUninterruptible ?? ((_d = options.voiceOptions) == null ? void 0 : _d.discardAudioIfUninterruptible);
  const minInterruptionDuration = (interruptionConfig == null ? void 0 : interruptionConfig.minDuration) ?? options.minInterruptionDuration ?? ((_e = options.voiceOptions) == null ? void 0 : _e.minInterruptionDuration);
  const minInterruptionWords = (interruptionConfig == null ? void 0 : interruptionConfig.minWords) ?? options.minInterruptionWords ?? ((_f = options.voiceOptions) == null ? void 0 : _f.minInterruptionWords);
  const minEndpointingDelay = (endpointingConfig == null ? void 0 : endpointingConfig.minDelay) ?? options.minEndpointingDelay ?? ((_g = options.voiceOptions) == null ? void 0 : _g.minEndpointingDelay);
  const maxEndpointingDelay = (endpointingConfig == null ? void 0 : endpointingConfig.maxDelay) ?? options.maxEndpointingDelay ?? ((_h = options.voiceOptions) == null ? void 0 : _h.maxEndpointingDelay);
  for (const event of report.events) {
    if (event.type === "metrics_collected" || event.type === "session_usage_updated") {
      continue;
    }
    events.push({ ...event });
  }
  return {
    job_id: report.jobId,
    room_id: report.roomId,
    room: report.room,
    events,
    options: {
      allow_interruptions: allowInterruptions,
      discard_audio_if_uninterruptible: discardAudioIfUninterruptible,
      min_interruption_duration: minInterruptionDuration,
      min_interruption_words: minInterruptionWords,
      min_endpointing_delay: minEndpointingDelay,
      max_endpointing_delay: maxEndpointingDelay,
      max_tool_steps: options.maxToolSteps,
      preemptive_generation: ((_i = options.turnHandling) == null ? void 0 : _i.preemptiveGeneration) ?? {}
    },
    chat_history: report.chatHistory.toJSON({ excludeTimestamp: false }),
    enable_user_data_training: report.enableRecording,
    timestamp: report.timestamp,
    usage: report.modelUsage ? report.modelUsage.map(filterZeroValues) : null
  };
}
export {
  createSessionReport,
  sessionReportToJSON
};
//# sourceMappingURL=report.js.map