import { Es as shouldLogVerbose, ws as logVerbose } from "./agent-scope-DVw8mi_i.js";
import "./github-copilot-token-DYrFvncE.js";
import "./send-6RE7ZD_B.js";
import "./send-DD6K3WP6.js";
import { F as resolveMediaAttachmentLocalRoots, I as runCapability, L as isAudioAttachment, M as buildProviderRegistry, N as createMediaAttachmentCache, P as normalizeMediaAttachments } from "./pi-embedded-Bapdl5Mb.js";
import "./diagnostic-DWKSfm_q.js";
import "./diagnostic-session-state-CexmAKza.js";
import "./send-BVmNzYrR.js";
import "./media-D4nEnyX9.js";
import "./pi-model-discovery-DpUv4v_r.js";
import "./paths-0bvQb_LS.js";
import "./ssrf-DYsl9qoS.js";
import "./reply-prefix-CteprwTK.js";
import "./path-alias-guards-BgsaoH-B.js";
import "./fs-safe--dkmYAev.js";
import "./skill-commands-_zLgADck.js";
import "./chunk-BFGwq8HC.js";
import "./markdown-tables-7kI-7mng.js";
import "./send-BAtDZt7a.js";
import "./fetch-guard-Ztzfiio9.js";
import "./outbound-attachment-BnC5ITTB.js";
import "./fetch-DyKd0D6V.js";
import "./memory-search-Z2b0d-jA.js";
import "./manager-XJq9ONvb.js";
import "./query-expansion-LNmYRPvI.js";
import "./target-errors-DrHV8jza.js";
import "./render-BRr7caFG.js";
import "./commands-registry-C7qLmjBS.js";
import "./config-eval-CG37crOn.js";
import "./send-BG45zdAY.js";
import "./resolve-route-Twc4mQV7.js";
import "./channel-activity-D2IwnDWk.js";
import "./tables-Dtfop_e5.js";
import "./proxy-DkRPPIHD.js";
import "./config-CtKjZZ4x.js";
import "./replies-D0__mn7d.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, { localPathRoots: resolveMediaAttachmentLocalRoots({
		cfg,
		ctx
	}) });
	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 };