import { Ss as logVerbose, ws as shouldLogVerbose } from "./agent-scope-VtywltNx.js";
import "./github-copilot-token-CNsqwfnE.js";
import "./send-BIYMEcFp.js";
import "./send-vYtmO4dA.js";
import { F as resolveMediaAttachmentLocalRoots, I as runCapability, L as isAudioAttachment, M as buildProviderRegistry, N as createMediaAttachmentCache, P as normalizeMediaAttachments } from "./pi-embedded-DlBsi5bC.js";
import "./reply-prefix-bCs4xRE_.js";
import "./diagnostic-BkUPEf9c.js";
import "./diagnostic-session-state-CL_QxyRg.js";
import "./send-DwTjxUii.js";
import "./media-D-hf-lm_.js";
import "./pi-model-discovery-DswPX2EG.js";
import "./paths-BxKqczZV.js";
import "./ssrf-9SwDSKOO.js";
import "./path-alias-guards-Cft6Dvfn.js";
import "./fs-safe-Dvm0de7n.js";
import "./skill-commands-DdI626I1.js";
import "./chunk-C4GUMfww.js";
import "./markdown-tables-COQvZ5rT.js";
import "./send-CfvjaKPG.js";
import "./fetch-guard-DoMsBx9n.js";
import "./outbound-attachment-CMdFsG1D.js";
import "./fetch-Dfo7JOVm.js";
import "./memory-search-BSGlctM2.js";
import "./manager-DjuMfhv2.js";
import "./query-expansion-C72CBz8f.js";
import "./target-errors-9e3Vynjs.js";
import "./render-BRr7caFG.js";
import "./commands-registry-CPfTuaTy.js";
import "./send-8yvseOvW.js";
import "./resolve-route-DZl4xR-2.js";
import "./channel-activity-BVMB9zBC.js";
import "./tables-B07E2H8r.js";
import "./proxy-BiW7MtYh.js";
import "./replies-Brezusw6.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 };