import "./paths-8iumfmbO.js";
import { G as logVerbose, J as shouldLogVerbose } from "./registry-CQ7Og3i6.js";
import "./agent-scope-DA6b8wn_.js";
import "./subsystem-CZoSiR9C.js";
import "./model-selection-Cptd9W8L.js";
import "./env-CsBwMMMT.js";
import "./plugins-CCqgCyMB.js";
import "./accounts-CNotrY5a.js";
import "./bindings-CGFdSdCt.js";
import { a as runCapability, l as isAudioAttachment, n as createMediaAttachmentCache, r as normalizeMediaAttachments, t as buildProviderRegistry } from "./runner-Cn9zG-NB.js";
import "./fetch-CK3qSrBi.js";
import "./message-channel-D2k8sQSZ.js";
import "./config-8OAHWwif.js";
import "./chrome-CuAjVLNX.js";
import "./redact-CMASoSS9.js";
import "./errors-B1XodB6r.js";
import "./paths-BsA_ZEQ5.js";
import "./gemini-auth-9Xfuw296.js";
import "./tool-images-CHypUbb0.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 };