"use strict";
var import_vitest = require("vitest");
var import_chat_context = require("../llm/chat_context.cjs");
var import_events = require("./events.cjs");
var import_report = require("./report.cjs");
function baseOptions() {
  return {
    maxToolSteps: 3,
    userAwayTimeout: 15,
    useTtsAlignedTranscript: true,
    turnHandling: {
      preemptiveGeneration: { enabled: false }
    }
  };
}
function serializeOptions(options) {
  const report = (0, import_report.createSessionReport)({
    jobId: "job",
    roomId: "room-id",
    room: "room",
    options,
    events: [],
    chatHistory: import_chat_context.ChatContext.empty(),
    enableRecording: false,
    timestamp: 0,
    startedAt: 0
  });
  const payload = (0, import_report.sessionReportToJSON)(report);
  return payload.options;
}
(0, import_vitest.describe)("sessionReportToJSON", () => {
  (0, import_vitest.it)("serializes interruption and endpointing values from turnHandling", () => {
    const options = baseOptions();
    options.turnHandling = {
      interruption: {
        mode: "adaptive",
        discardAudioIfUninterruptible: false,
        minDuration: 1200,
        minWords: 2
      },
      endpointing: {
        minDelay: 900,
        maxDelay: 4500
      }
    };
    const serialized = serializeOptions(options);
    (0, import_vitest.expect)(serialized).toMatchObject({
      allow_interruptions: true,
      discard_audio_if_uninterruptible: false,
      min_interruption_duration: 1200,
      min_interruption_words: 2,
      min_endpointing_delay: 900,
      max_endpointing_delay: 4500,
      max_tool_steps: 3
    });
  });
  (0, import_vitest.it)("prefers turnHandling values over deprecated flat fields", () => {
    const options = baseOptions();
    options.allowInterruptions = false;
    options.discardAudioIfUninterruptible = true;
    options.minInterruptionDuration = 400;
    options.minInterruptionWords = 1;
    options.minEndpointingDelay = 500;
    options.maxEndpointingDelay = 2500;
    options.turnHandling = {
      interruption: {
        mode: "vad",
        discardAudioIfUninterruptible: false,
        minDuration: 1400,
        minWords: 4
      },
      endpointing: {
        minDelay: 700,
        maxDelay: 3900
      }
    };
    const serialized = serializeOptions(options);
    (0, import_vitest.expect)(serialized).toMatchObject({
      allow_interruptions: true,
      discard_audio_if_uninterruptible: false,
      min_interruption_duration: 1400,
      min_interruption_words: 4,
      min_endpointing_delay: 700,
      max_endpointing_delay: 3900,
      max_tool_steps: 3
    });
  });
  (0, import_vitest.it)("serializes allow_interruptions from interruption.enabled when present", () => {
    const options = baseOptions();
    options.allowInterruptions = true;
    options.turnHandling = {
      interruption: {
        enabled: false,
        mode: "adaptive"
      }
    };
    const serialized = serializeOptions(options);
    (0, import_vitest.expect)(serialized).toMatchObject({
      allow_interruptions: false,
      max_tool_steps: 3
    });
  });
  (0, import_vitest.it)("falls back to deprecated flat fields when turnHandling values are absent", () => {
    const options = baseOptions();
    options.allowInterruptions = false;
    options.discardAudioIfUninterruptible = false;
    options.minInterruptionDuration = 600;
    options.minInterruptionWords = 3;
    options.minEndpointingDelay = 1e3;
    options.maxEndpointingDelay = 5e3;
    const serialized = serializeOptions(options);
    (0, import_vitest.expect)(serialized).toMatchObject({
      allow_interruptions: false,
      discard_audio_if_uninterruptible: false,
      min_interruption_duration: 600,
      min_interruption_words: 3,
      min_endpointing_delay: 1e3,
      max_endpointing_delay: 5e3,
      max_tool_steps: 3
    });
  });
  (0, import_vitest.it)("serializes model usage as usage", () => {
    const usage = [
      {
        type: "tts_usage",
        provider: "elevenlabs",
        model: "eleven_flash_v2_5",
        inputTokens: 0,
        outputTokens: 0,
        charactersCount: 42,
        audioDurationMs: 1200
      }
    ];
    const report = (0, import_report.createSessionReport)({
      jobId: "job",
      roomId: "room-id",
      room: "room",
      options: baseOptions(),
      events: [],
      chatHistory: import_chat_context.ChatContext.empty(),
      enableRecording: false,
      timestamp: 0,
      startedAt: 0,
      modelUsage: usage
    });
    const payload = (0, import_report.sessionReportToJSON)(report);
    (0, import_vitest.expect)(payload.usage).toEqual([
      {
        type: "tts_usage",
        provider: "elevenlabs",
        model: "eleven_flash_v2_5",
        charactersCount: 42,
        audioDurationMs: 1200
      }
    ]);
  });
  (0, import_vitest.it)("omits session usage update events from serialized events", () => {
    const report = (0, import_report.createSessionReport)({
      jobId: "job",
      roomId: "room-id",
      room: "room",
      options: baseOptions(),
      events: [
        (0, import_events.createSessionUsageUpdatedEvent)({
          usage: {
            modelUsage: [
              {
                type: "tts_usage",
                provider: "elevenlabs",
                model: "eleven_flash_v2_5"
              }
            ]
          },
          createdAt: 123
        })
      ],
      chatHistory: import_chat_context.ChatContext.empty(),
      enableRecording: false,
      timestamp: 0,
      startedAt: 0
    });
    const payload = (0, import_report.sessionReportToJSON)(report);
    (0, import_vitest.expect)(payload.events).toEqual([]);
  });
  (0, import_vitest.it)("exports AgentSessionUsage from the voice barrel", () => {
    const usage = { modelUsage: [] };
    const eventType = import_events.AgentSessionEventTypes.SessionUsageUpdated;
    (0, import_vitest.expect)(usage.modelUsage).toEqual([]);
    (0, import_vitest.expect)(eventType).toBe("session_usage_updated");
  });
});
(0, import_vitest.describe)("createSessionReport recordingOptions", () => {
  function makeReport(recordingOptions) {
    return (0, import_report.createSessionReport)({
      jobId: "job",
      roomId: "room-id",
      room: "room",
      options: baseOptions(),
      events: [],
      chatHistory: import_chat_context.ChatContext.empty(),
      recordingOptions
    });
  }
  (0, import_vitest.it)("defaults every recording category to off when omitted", () => {
    (0, import_vitest.expect)(makeReport().recordingOptions).toEqual({
      audio: false,
      traces: false,
      logs: false,
      transcript: false
    });
  });
  (0, import_vitest.it)("passes provided recording options through", () => {
    const recordingOptions = {
      audio: true,
      traces: false,
      logs: true,
      transcript: false
    };
    (0, import_vitest.expect)(makeReport(recordingOptions).recordingOptions).toEqual(recordingOptions);
  });
});
//# sourceMappingURL=report.test.cjs.map