"use strict";
var import_vitest = require("vitest");
var import_chat_context = require("../llm/chat_context.cjs");
var import_log = require("../log.cjs");
var import_stt = require("../stt/stt.cjs");
var import_audio_recognition = require("./audio_recognition.cjs");
function createHooks() {
  return {
    onInterruption: import_vitest.vi.fn(),
    onStartOfSpeech: import_vitest.vi.fn(),
    onVADInferenceDone: import_vitest.vi.fn(),
    onEndOfSpeech: import_vitest.vi.fn(),
    onInterimTranscript: import_vitest.vi.fn(),
    onFinalTranscript: import_vitest.vi.fn(),
    onPreemptiveGeneration: import_vitest.vi.fn(),
    onAgentBackchannelOpportunity: import_vitest.vi.fn(),
    retrieveChatCtx: () => import_chat_context.ChatContext.empty(),
    onEndOfTurn: import_vitest.vi.fn(async () => true)
  };
}
(0, import_vitest.describe)("AudioRecognition interruption buffering", () => {
  (0, import_log.initializeLogger)({ pretty: false, level: "silent" });
  (0, import_vitest.it)("does not keep buffering final transcripts after agent speech end begins", async () => {
    const hooks = createHooks();
    hooks.onEndOfTurn = import_vitest.vi.fn(async () => false);
    const recognition = new import_audio_recognition.AudioRecognition({
      recognitionHooks: hooks,
      minEndpointingDelay: 0,
      maxEndpointingDelay: 0
    });
    await recognition.onStartOfAgentSpeech(Date.now());
    const internals = recognition;
    internals.isInterruptionEnabled = true;
    internals.trySendInterruptionSentinel = import_vitest.vi.fn(() => new Promise(() => {
    }));
    void recognition.onEndOfAgentSpeech(Date.now());
    const finalTranscript = {
      type: import_stt.SpeechEventType.FINAL_TRANSCRIPT,
      alternatives: [{ text: "still listening", confidence: 0.9 }]
    };
    await internals.onSTTEvent(finalTranscript);
    (0, import_vitest.expect)(hooks.onFinalTranscript).toHaveBeenCalledTimes(1);
    (0, import_vitest.expect)(recognition.currentTranscript).toBe("still listening");
    (0, import_vitest.expect)(internals.transcriptBuffer).toHaveLength(0);
  });
});
//# sourceMappingURL=audio_recognition_interruption.test.cjs.map