import "./run-with-concurrency-KRm2JLiI.js";
import "./paths-BANciGCS.js";
import { p as shouldLogVerbose, u as logVerbose } from "./subsystem-CgTeEziN.js";
import "./workspace-Cf_FbQuR.js";
import "./logger-n2Gpq0AH.js";
import "./model-selection-BkYBmupV.js";
import "./github-copilot-token-DG2sYnVk.js";
import "./legacy-names-DEoEk9jn.js";
import "./thinking-BSAfU9e5.js";
import "./accounts-yr7rL--h.js";
import "./plugins-DE02D3EJ.js";
import "./accounts-kYYknnjO.js";
import "./image-ops-CH-bKC6L.js";
import "./pi-embedded-helpers-CIxZUqQl.js";
import "./chrome-ANFAbsTM.js";
import "./frontmatter-BqvyjOGD.js";
import "./skills-GUmCCgYD.js";
import "./path-alias-guards-Bj2dz01O.js";
import "./redact-Asry9UBT.js";
import "./errors-DtMXuwMd.js";
import "./fs-safe-DLFU_2Jt.js";
import "./proxy-env-yOHn3u7d.js";
import "./store-Dm9ec8nX.js";
import "./accounts-D_3bkTzM.js";
import "./paths-DiVFtCJv.js";
import "./tool-images-DiQlk_40.js";
import "./image-BE5qITiS.js";
import { g as isAudioAttachment, i as normalizeMediaAttachments, o as resolveMediaAttachmentLocalRoots, t as runAudioTranscription } from "./audio-transcription-runner-XipAmvqa.js";
import "./fetch-DCzFGsuQ.js";
import "./fetch-guard-DZlxlct6.js";
import "./api-key-rotation-BAaWeojM.js";
import "./proxy-fetch-D8ON61si.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`);
	try {
		const { transcript } = await runAudioTranscription({
			ctx,
			cfg,
			attachments,
			agentDir: params.agentDir,
			providers: params.providers,
			activeModel: params.activeModel,
			localPathRoots: resolveMediaAttachmentLocalRoots({
				cfg,
				ctx
			})
		});
		if (!transcript) return;
		firstAudio.alreadyTranscribed = true;
		if (shouldLogVerbose()) logVerbose(`audio-preflight: transcribed ${transcript.length} chars from attachment ${firstAudio.index}`);
		return transcript;
	} catch (err) {
		if (shouldLogVerbose()) logVerbose(`audio-preflight: transcription failed: ${String(err)}`);
		return;
	}
}

//#endregion
export { transcribeFirstAudio };