import "./github-copilot-token-Dy7Y_jbI.js";
import { As as shouldLogVerbose, Os as logVerbose } from "./paths-tN5PnNK1.js";
import { A as createMediaAttachmentCache, M as resolveMediaAttachmentLocalRoots, N as runCapability, P as isAudioAttachment, j as normalizeMediaAttachments, k as buildProviderRegistry } from "./auth-Bfgwy6TQ.js";
import "./send-DwNxlwDd.js";
import "./send-TMsshhGX.js";
import "./skill-commands-Bp7DhFz2.js";
import "./chrome-DAM8TRPD.js";
import "./ssrf-CuVKDM2Y.js";
import "./send-k_WYi4l6.js";
import "./reply-prefix-08UBqy-V.js";
import "./media-CiB_ZNRr.js";
import "./path-alias-guards-wcDpnDMK.js";
import "./fs-safe-Dh6gZOHN.js";
import "./diagnostic-DJJ0htzO.js";
import "./chunk-CXulQvJz.js";
import "./markdown-tables-DkC120tS.js";
import "./send-DdceKSIl.js";
import "./fetch-guard-ChQqwbiJ.js";
import "./outbound-attachment-LjQpxfc4.js";
import "./fetch-b672JwUb.js";
import "./target-errors-DbLEgzAN.js";
import "./commands-registry-BpxMk5vv.js";
import "./memory-search-DDk5DIi5.js";
import "./manager-BbAMWCLZ.js";
import "./query-expansion-DNpmsa-Q.js";
import "./render-DSLzcBxk.js";
import "./diagnostic-session-state-CoTMypVf.js";
import "./pi-model-discovery-C9LtKZzX.js";
import "./send-CvRo7Mq0.js";
import "./resolve-route-DUryxO3-.js";
import "./channel-activity-B5E4mryV.js";
import "./tables-GYHjBB4n.js";
import "./proxy-BiW7MtYh.js";
import "./replies-BSY4LN7v.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 };