import "./accounts-CoCj5YmU.js";
import { G as shouldLogVerbose, H as logVerbose } from "./registry-B-QyqbFJ.js";
import "./paths-k3PPLtQp.js";
import "./model-selection-Cj40UPdW.js";
import "./config-ZyEcvTXw.js";
import "./ssrf-brPY_0TB.js";
import "./subsystem-BQD2CPhi.js";
import "./agent-scope-CC2TZqM4.js";
import "./tool-images-CMcGamXm.js";
import "./skills-Bgls21wf.js";
import "./redact-B6slI2xA.js";
import "./errors-C8rcftvC.js";
import "./fetch-C20bBvxs.js";
import "./chrome-U2wVoB-5.js";
import "./command-format-DTFESrCo.js";
import "./thinking-CS_t4xez.js";
import "./normalize-CfjNMyDj.js";
import "./bindings-CyV4fB9D.js";
import "./plugins-8t7YtJYS.js";
import "./message-channel-BtJmyAyC.js";
import "./pi-embedded-helpers-_qKMg6wS.js";
import "./github-copilot-token-DjZVdIgw.js";
import "./manifest-registry-pD8HkKsD.js";
import "./paths-BQslnOSd.js";
import { a as runCapability, l as isAudioAttachment, n as createMediaAttachmentCache, r as normalizeMediaAttachments, t as buildProviderRegistry } from "./runner-BiZfo6ke.js";
import "./image-D0qMjh_0.js";
import "./pi-model-discovery-C3Rabij-.js";
import "./api-key-rotation-C6NdVpc5.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 };