"use strict";
var import_vitest = require("vitest");
var import_log = require("../../log.cjs");
var import_agent_session = require("../agent_session.cjs");
var import_endpointing = require("./endpointing.cjs");
var import_interruption = require("./interruption.cjs");
var import_preemptive_generation = require("./preemptive_generation.cjs");
var import_turn_handling = require("./turn_handling.cjs");
var import_user_turn_limit = require("./user_turn_limit.cjs");
var import_utils = require("./utils.cjs");
(0, import_vitest.beforeAll)(() => {
  (0, import_log.initializeLogger)({ pretty: true, level: "info" });
});
(0, import_vitest.describe)("migrateLegacyOptions", () => {
  (0, import_vitest.it)("should return all defaults when no options are provided", () => {
    const { agentSessionOptions: result } = (0, import_utils.migrateLegacyOptions)({});
    (0, import_vitest.expect)(result.turnHandling).toEqual({
      turnDetection: import_turn_handling.defaultTurnHandlingOptions.turnDetection,
      // omitted turnDetection auto-provisions a streaming detector → streaming defaults
      endpointing: import_endpointing.streamingEndpointingOptions,
      endpointingOverrides: {},
      interruption: import_interruption.defaultInterruptionOptions,
      preemptiveGeneration: import_preemptive_generation.defaultPreemptiveGenerationOptions,
      userTurnLimit: import_user_turn_limit.defaultUserTurnLimitOptions
    });
    (0, import_vitest.expect)(result.maxToolSteps).toBe(import_agent_session.defaultAgentSessionOptions.maxToolSteps);
    (0, import_vitest.expect)(result.userAwayTimeout).toBe(import_agent_session.defaultAgentSessionOptions.userAwayTimeout);
  });
  (0, import_vitest.it)("should migrate legacy flat fields into nested turnHandling config", () => {
    const { agentSessionOptions: result } = (0, import_utils.migrateLegacyOptions)({
      voiceOptions: {
        minInterruptionDuration: 1e3,
        minInterruptionWords: 3,
        discardAudioIfUninterruptible: false,
        minEndpointingDelay: 800,
        maxEndpointingDelay: 5e3
      }
    });
    (0, import_vitest.expect)(result.turnHandling.interruption.minDuration).toBe(1e3);
    (0, import_vitest.expect)(result.turnHandling.interruption.minWords).toBe(3);
    (0, import_vitest.expect)(result.turnHandling.interruption.discardAudioIfUninterruptible).toBe(false);
    (0, import_vitest.expect)(result.turnHandling.endpointing.minDelay).toBe(800);
    (0, import_vitest.expect)(result.turnHandling.endpointing.maxDelay).toBe(5e3);
  });
  (0, import_vitest.it)("should set interruption.enabled to false when allowInterruptions is false", () => {
    const { agentSessionOptions: result } = (0, import_utils.migrateLegacyOptions)({
      voiceOptions: { allowInterruptions: false }
    });
    (0, import_vitest.expect)(result.turnHandling.interruption.enabled).toBe(false);
  });
  (0, import_vitest.it)("should give top-level fields precedence over voiceOptions", () => {
    const { agentSessionOptions: result } = (0, import_utils.migrateLegacyOptions)({
      voiceOptions: {
        minInterruptionDuration: 1e3,
        maxEndpointingDelay: 5e3,
        maxToolSteps: 10
      },
      turnHandling: {
        interruption: {
          minDuration: 2e3
        },
        endpointing: {
          maxDelay: 8e3
        }
      },
      maxToolSteps: 5
    });
    (0, import_vitest.expect)(result.turnHandling.interruption.minDuration).toBe(2e3);
    (0, import_vitest.expect)(result.turnHandling.endpointing.maxDelay).toBe(8e3);
    (0, import_vitest.expect)(result.maxToolSteps).toBe(5);
  });
  (0, import_vitest.it)("should preserve top-level turnDetection in the result", () => {
    const { agentSessionOptions: result } = (0, import_utils.migrateLegacyOptions)({
      turnDetection: "vad"
    });
    (0, import_vitest.expect)(result.turnHandling.turnDetection).toBe("vad");
  });
});
(0, import_vitest.describe)("migrateTurnHandling", () => {
  (0, import_vitest.it)("should return empty partial when no deprecated Agent fields are given", () => {
    const result = (0, import_utils.migrateTurnHandling)({});
    (0, import_vitest.expect)(result).toEqual({});
  });
  (0, import_vitest.it)("should set interruption.enabled to false when allowInterruptions is false", () => {
    const result = (0, import_utils.migrateTurnHandling)({ allowInterruptions: false });
    (0, import_vitest.expect)(result.interruption).toEqual({ enabled: false });
    (0, import_vitest.expect)(result.endpointing).toBeUndefined();
    (0, import_vitest.expect)(result.turnDetection).toBeUndefined();
  });
  (0, import_vitest.it)("should not set interruption when allowInterruptions is true or undefined", () => {
    (0, import_vitest.expect)((0, import_utils.migrateTurnHandling)({ allowInterruptions: true })).toEqual({});
    (0, import_vitest.expect)((0, import_utils.migrateTurnHandling)({ allowInterruptions: void 0 })).toEqual({});
  });
  (0, import_vitest.it)("should map minEndpointingDelay to endpointing.minDelay", () => {
    const result = (0, import_utils.migrateTurnHandling)({ minEndpointingDelay: 800 });
    (0, import_vitest.expect)(result.endpointing).toEqual({ minDelay: 800 });
  });
  (0, import_vitest.it)("should map maxEndpointingDelay to endpointing.maxDelay", () => {
    const result = (0, import_utils.migrateTurnHandling)({ maxEndpointingDelay: 5e3 });
    (0, import_vitest.expect)(result.endpointing).toEqual({ maxDelay: 5e3 });
  });
  (0, import_vitest.it)("should pass through turnDetection", () => {
    const result = (0, import_utils.migrateTurnHandling)({ turnDetection: "vad" });
    (0, import_vitest.expect)(result.turnDetection).toBe("vad");
  });
  (0, import_vitest.it)("should combine all deprecated Agent fields", () => {
    const result = (0, import_utils.migrateTurnHandling)({
      turnDetection: "stt",
      allowInterruptions: false,
      minEndpointingDelay: 400,
      maxEndpointingDelay: 3e3
    });
    (0, import_vitest.expect)(result.turnDetection).toBe("stt");
    (0, import_vitest.expect)(result.interruption).toEqual({ enabled: false });
    (0, import_vitest.expect)(result.endpointing).toEqual({ minDelay: 400, maxDelay: 3e3 });
  });
  (0, import_vitest.it)("should map preemptiveGeneration boolean to preemptiveGeneration.enabled", () => {
    const resultTrue = (0, import_utils.migrateTurnHandling)({ preemptiveGeneration: true });
    (0, import_vitest.expect)(resultTrue.preemptiveGeneration).toEqual({ enabled: true });
    const resultFalse = (0, import_utils.migrateTurnHandling)({ preemptiveGeneration: false });
    (0, import_vitest.expect)(resultFalse.preemptiveGeneration).toEqual({ enabled: false });
  });
  (0, import_vitest.it)("should ignore deprecated Agent fields when explicit turnHandling is provided", () => {
    const turnHandling = {
      endpointing: { minDelay: 999, maxDelay: 4e3 },
      interruption: { enabled: true },
      turnDetection: "vad"
    };
    const result = (0, import_utils.migrateTurnHandling)({
      turnHandling,
      turnDetection: "stt",
      allowInterruptions: false,
      minEndpointingDelay: 100,
      maxEndpointingDelay: 200
    });
    (0, import_vitest.expect)(result).toEqual(turnHandling);
  });
});
//# sourceMappingURL=utils.test.cjs.map