import { h as __exportAll } from "./pi-embedded-utils-CPkknmhn.js";
import { n as loadConfig } from "./config-CCV5uD38.js";
import { u as readStringParam } from "./common-D7lLwt9D.js";
import { n as SILENT_REPLY_TOKEN } from "./tokens-CFbBnfQY.js";
import { b as textToSpeech } from "./tts-B7WgbKJ9.js";
import { Type } from "@sinclair/typebox";

//#region src/agents/tools/media/tts-tool.ts
var tts_tool_exports = /* @__PURE__ */ __exportAll({ createTtsTool: () => createTtsTool });
const TtsToolSchema = Type.Object({
	text: Type.String({ description: "Text to convert to speech." }),
	channel: Type.Optional(Type.String({ description: "Optional channel id to pick output format (e.g. telegram)." }))
});
function createTtsTool(opts) {
	return {
		label: "TTS",
		name: "tts",
		description: `Convert text to speech. Audio is delivered automatically from the tool result — reply with ${SILENT_REPLY_TOKEN} after a successful call to avoid duplicate messages.`,
		parameters: TtsToolSchema,
		execute: async (_toolCallId, args) => {
			const params = args;
			const text = readStringParam(params, "text", { required: true });
			const channel = readStringParam(params, "channel");
			const result = await textToSpeech({
				text,
				cfg: opts?.config ?? loadConfig(),
				channel: channel ?? opts?.agentChannel
			});
			if (result.success && result.audioPath) {
				const lines = [];
				if (result.voiceCompatible) lines.push("[[audio_as_voice]]");
				lines.push(`MEDIA:${result.audioPath}`);
				return {
					content: [{
						type: "text",
						text: lines.join("\n")
					}],
					details: {
						audioPath: result.audioPath,
						provider: result.provider
					}
				};
			}
			return {
				content: [{
					type: "text",
					text: result.error ?? "TTS conversion failed"
				}],
				details: { error: result.error }
			};
		}
	};
}

//#endregion
export { tts_tool_exports as n, createTtsTool as t };