import "./paths-CyR9Pa1R.js";
import { X as shouldLogVerbose, q as logVerbose } from "./registry-B3v_dMjW.js";
import "./agent-scope-BqZ_plxe.js";
import "./subsystem-12Cr1qkN.js";
import "./workspace-0LqR5k0Z.js";
import "./normalize-dSQPMpIn.js";
import "./accounts-CFuwD11R.js";
import "./boolean-mcn6kL0s.js";
import "./command-format-CReWasli.js";
import "./bindings-DF9JL0Dp.js";
import "./plugins-B_DoE566.js";
import "./accounts-DNPVzTdb.js";
import "./image-ops-Ds8rFspc.js";
import "./model-auth-4zgXZMu1.js";
import "./github-copilot-token-CLyVfX-X.js";
import "./pi-model-discovery-ClNB73Yn.js";
import "./message-channel-BQffYho-.js";
import "./pi-embedded-helpers-BySjPMDv.js";
import "./config-CudTJ53Z.js";
import "./manifest-registry-RbxxyxZX.js";
import "./chrome-CkaE1kWr.js";
import "./frontmatter-BxXCRA4C.js";
import "./skills-BdnJQmeY.js";
import "./redact-D0zkYqlZ.js";
import "./errors-CmHWtfz2.js";
import "./store-0e53SGRy.js";
import "./thinking-R14Jt_Cj.js";
import "./accounts-Dq4hjKQr.js";
import "./paths-CERkAqHe.js";
import "./tool-images-CNP8ODZw.js";
import "./image-DJzxv2wd.js";
import "./gemini-auth-BZ0z3QdB.js";
import "./fetch-yK5YruMA.js";
import { a as runCapability, l as isAudioAttachment, n as createMediaAttachmentCache, r as normalizeMediaAttachments, t as buildProviderRegistry } from "./runner-CF63WaxF.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);
	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 };