import "./paths-D7t4DWPT.js";
import { X as shouldLogVerbose, q as logVerbose } from "./registry-BAroooHo.js";
import "./agent-scope-vwdi_iPU.js";
import "./subsystem-CT4qQN_5.js";
import "./workspace-BfiC270B.js";
import "./plugins-CKverisB.js";
import "./accounts-D_f61n_2.js";
import "./boolean-B8-BqKGQ.js";
import "./command-format-B1Qy0nEy.js";
import "./bindings-B2zCGVlh.js";
import "./accounts-DjS9pck5.js";
import "./fetch-zQFnmTQp.js";
import "./model-auth-JizwQYrQ.js";
import { a as runCapability, l as isAudioAttachment, n as createMediaAttachmentCache, r as normalizeMediaAttachments, t as buildProviderRegistry } from "./runner-C1FeLLBX.js";
import "./message-channel-B2_fQxU-.js";
import "./config-CuIQfnYC.js";
import "./chrome-D1MdAC58.js";
import "./frontmatter-DeJqLCGD.js";
import "./redact-CvtgU1ru.js";
import "./errors-DTJD7QVU.js";
import "./store-CHKRvmCy.js";
import "./accounts-D0MI8r0c.js";
import "./paths-DPyv1NZk.js";
import "./gemini-auth-BkihAcak.js";
import "./tool-images-CN0uVQmf.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 };