import "./paths-B4BZAPZh.js";
import { F as shouldLogVerbose, M as logVerbose } from "./utils-h12D6i3s.js";
import "./theme-CvDUwCeH.js";
import "./thinking-B3X4Pu2T.js";
import "./registry-CEok6CBD.js";
import "./subsystem-CptcaHdG.js";
import "./exec-KZG5pigM.js";
import "./agent-scope-DuRxDIxP.js";
import "./model-selection-Ci1X7yz4.js";
import "./github-copilot-token-BZDGcFI5.js";
import "./boolean-BsqeuxE6.js";
import "./env-Du80aeH-.js";
import "./config-DpEIy1Iq.js";
import "./manifest-registry-DP5prNZc.js";
import { a as runCapability, n as createMediaAttachmentCache, o as isAudioAttachment, r as normalizeMediaAttachments, t as buildProviderRegistry } from "./runner-B8-WBmYS.js";
import "./image-B5SB0tN4.js";
import "./models-config-BvUgiLNT.js";
import "./pi-model-discovery-BXtQTdf5.js";
import "./pi-embedded-helpers-Dt-sU2cn.js";
import "./sandbox-DaCbovTo.js";
import "./chrome-C2U0x_vA.js";
import "./tailscale-CRbgJwcF.js";
import "./auth-lS4wOBFo.js";
import "./server-context-B-YCUG7A.js";
import "./frontmatter-DrdSsH4-.js";
import "./skills-AD616ijL.js";
import "./routes-Cv9WOuy_.js";
import "./redact-CjJyQlVU.js";
import "./errors-CdJjJ1Jq.js";
import "./paths-WCTMjONe.js";
import "./ssrf-BT0IElaU.js";
import "./image-ops-BP1giyhy.js";
import "./store-q26Wtsy_.js";
import "./ports-CTzsGOMF.js";
import "./trash-BeFHeovG.js";
import "./sessions-C_NwV0mt.js";
import "./dock-kPWc7D0x.js";
import "./message-channel-CP2gEtPf.js";
import "./normalize-DqxNnJHS.js";
import "./accounts-DOhECffI.js";
import "./accounts-C1lp0M2X.js";
import "./accounts-BEp1f-Fs.js";
import "./bindings-OUZ-uS5k.js";
import "./logging-D3KTM1pH.js";
import "./plugins-DXhAnLR9.js";
import "./paths-gjLMn4eA.js";
import "./tool-images-DJNWvX-X.js";
import "./tool-display-u8k8a1Tt.js";
import "./fetch-guard-ZRDg55CN.js";
import "./api-key-rotation-uNbQP6UQ.js";
import "./fetch-Dzzhxfkw.js";
import "./model-catalog-CvWJHJCg.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 };