import { C as normalizeMediaAttachments, E as isAudioAttachment, S as createMediaAttachmentCache, T as runCapability, w as resolveMediaAttachmentLocalRoots, x as buildProviderRegistry } from "./reply-CvmqbVx1.js";
import { Gc as logVerbose, qc as shouldLogVerbose } from "./runtime-x71O5s-N.js";
import "./github-copilot-token-CVC_19vl.js";
import "./send-BhMMKWOk.js";
import "./fetch-guard-CNvu0czC.js";
import "./ssrf-DHglwD1p.js";
import "./send-DBVp3j7m.js";
import "./send-DY9n8pqC.js";
import "./chunk-CLhP_PY2.js";
import "./ir-wu6kjYKs.js";
import "./target-errors-B4PsZKb0.js";
import "./send-Ba0KNbhf.js";
import "./reply-prefix-BMlximgi.js";
import "./skill-commands-BctYBY9Z.js";
import "./fetch-IDUrNG4h.js";
import "./diagnostic-B18Fb_x_.js";
import "./path-alias-guards-DVDPpKaI.js";
import "./fs-safe-DQ3_54XI.js";
import "./outbound-attachment-sc88JFtf.js";
import "./paths-DPJkB1Zo.js";
import "./channel-activity-C1o4f6CQ.js";
import "./markdown-tables-BPDFC99a.js";
import "./render-DzUFCfck.js";
import "./tables-CBeKgNEN.js";
import "./commands-registry-rxhYCn3h.js";
import "./pi-model-discovery-Bt88hotH.js";
import "./send-DEQVHEZ4.js";
import "./memory-search-BRc1w0pH.js";
import "./manager-DosJYKNm.js";
import "./query-expansion-DMIckuk2.js";
import "./diagnostic-session-state-DLuYVc4W.js";
import "./resolve-route-DlUpOg3_.js";
import "./proxy-BiW7MtYh.js";
import "./replies-ChLqx77a.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 };