import { Ds as shouldLogVerbose, Ts as logVerbose } from "./context-ZGnpCM_T.js";
import "./github-copilot-token-BMocqO3v.js";
import "./send-BQNCWVsm.js";
import "./send-BlzW_qBs.js";
import { A as buildProviderRegistry, F as isAudioAttachment, M as normalizeMediaAttachments, N as resolveMediaAttachmentLocalRoots, P as runCapability, j as createMediaAttachmentCache } from "./status-DsTgMPSP.js";
import "./paths-eIxEUaFJ.js";
import "./ssrf-CZsNT0Hn.js";
import "./reply-prefix-D0bfWZMK.js";
import "./media-C0K8I3U6.js";
import "./path-alias-guards-M022a3mt.js";
import "./fs-safe-n9u6ywAG.js";
import "./diagnostic-DFcKcXVe.js";
import "./skill-commands-DaykMBAp.js";
import "./chunk-DEv5ArR9.js";
import "./markdown-tables-0j7C7Eis.js";
import "./send-Dq1CUBdq.js";
import "./fetch-guard-DtEt9l4H.js";
import "./outbound-attachment-BRzuwuFu.js";
import "./fetch-D7zaokpd.js";
import "./target-errors-ClS0Okd6.js";
import "./commands-registry-BlWoTczC.js";
import "./memory-search-euBOXQ7V.js";
import "./manager-H2RoB5YE.js";
import "./query-expansion-CAYokESR.js";
import "./render-CiikiGbn.js";
import "./diagnostic-session-state-C9jKr8qI.js";
import "./send-1jc8vUf3.js";
import "./pi-model-discovery-BoNO1bUO.js";
import "./send-oHeXHeKM.js";
import "./resolve-route-ByuOzYs3.js";
import "./channel-activity-BOzkTWw2.js";
import "./tables-r3i_KIPN.js";
import "./proxy-BiW7MtYh.js";
import "./replies-BFtNuTYs.js";

//#region src/media-understanding/audio-preflight.ts
/**
* Transcribes the first audio attachment BEFORE mention checking.
* This allows voice notes to be processed in group chats with requireMention: true.
* Returns the transcript or undefined if transcription fails or no audio is found.
*/
async function transcribeFirstAudio(params) {
	const { ctx, cfg } = params;
	const audioConfig = cfg.tools?.media?.audio;
	if (!audioConfig || audioConfig.enabled === false) return;
	const attachments = normalizeMediaAttachments(ctx);
	if (!attachments || attachments.length === 0) return;
	const firstAudio = attachments.find((att) => att && isAudioAttachment(att) && !att.alreadyTranscribed);
	if (!firstAudio) return;
	if (shouldLogVerbose()) logVerbose(`audio-preflight: transcribing attachment ${firstAudio.index} for mention check`);
	const providerRegistry = buildProviderRegistry(params.providers);
	const cache = createMediaAttachmentCache(attachments, { localPathRoots: resolveMediaAttachmentLocalRoots({
		cfg,
		ctx
	}) });
	try {
		const result = await runCapability({
			capability: "audio",
			cfg,
			ctx,
			attachments: cache,
			media: attachments,
			agentDir: params.agentDir,
			providerRegistry,
			config: audioConfig,
			activeModel: params.activeModel
		});
		if (!result || result.outputs.length === 0) return;
		const audioOutput = result.outputs.find((output) => output.kind === "audio.transcription");
		if (!audioOutput || !audioOutput.text) return;
		firstAudio.alreadyTranscribed = true;
		if (shouldLogVerbose()) logVerbose(`audio-preflight: transcribed ${audioOutput.text.length} chars from attachment ${firstAudio.index}`);
		return audioOutput.text;
	} catch (err) {
		if (shouldLogVerbose()) logVerbose(`audio-preflight: transcription failed: ${String(err)}`);
		return;
	} finally {
		await cache.cleanup();
	}
}

//#endregion
export { transcribeFirstAudio };