import { describe, expect, it } from "vitest";
import { ChatContext } from "../llm/chat_context.js";
import { initializeLogger } from "../log.js";
import { AudioRecognition } from "./audio_recognition.js";
import { BaseEndpointing } from "./turn_config/endpointing.js";
function createHooks() {
  return {
    onInterruption: () => {
    },
    onStartOfSpeech: () => {
    },
    onVADInferenceDone: () => {
    },
    onEndOfSpeech: () => {
    },
    onInterimTranscript: () => {
    },
    onFinalTranscript: () => {
    },
    onPreemptiveGeneration: () => {
    },
    onAgentBackchannelOpportunity: () => {
    },
    retrieveChatCtx: () => ChatContext.empty(),
    onEndOfTurn: async () => true
  };
}
class RecordingEndpointing extends BaseEndpointing {
  speechStarts = [];
  onStartOfSpeech(startedAt, overlapping = false) {
    super.onStartOfSpeech(startedAt, overlapping);
    this.speechStarts.push({ startedAt, overlapping });
  }
}
describe("AudioRecognition endpointing integration", () => {
  initializeLogger({ pretty: false, level: "silent" });
  it("marks endpointing overlap when audio activity starts while the agent is speaking", async () => {
    const endpointing = new RecordingEndpointing({ minDelay: 300, maxDelay: 3e3 });
    const recognition = new AudioRecognition({
      recognitionHooks: createHooks(),
      endpointing
    });
    await recognition.onStartOfAgentSpeech(1e3);
    await recognition.onStartOfOverlapSpeech(0, 1200);
    await recognition.onStartOfOverlapSpeech(0, 1300);
    expect(endpointing.speechStarts).toEqual([{ startedAt: 1200, overlapping: true }]);
    expect(endpointing.overlapping).toBe(true);
  });
});
//# sourceMappingURL=audio_recognition_endpointing.test.js.map