import "./paths-8iumfmbO.js";
import "./registry-CQ7Og3i6.js";
import "./agent-scope-DA6b8wn_.js";
import "./subsystem-CZoSiR9C.js";
import "./model-selection-Cptd9W8L.js";
import "./env-CsBwMMMT.js";
import "./plugins-CCqgCyMB.js";
import "./accounts-CNotrY5a.js";
import "./bindings-CGFdSdCt.js";
import "./fetch-CK3qSrBi.js";
import "./message-channel-D2k8sQSZ.js";
import "./config-8OAHWwif.js";
import "./tool-images-CHypUbb0.js";
import { i as jsonResult, l as readStringParam, o as readReactionParams, t as createActionGate } from "./common-CeSCoU0C.js";
import "./chunk-UvPwlQrH.js";
import "./markdown-tables-CYGI2O5v.js";
import "./render-BzKFqza9.js";
import "./active-listener-CJHdw02A.js";
import { r as sendReactionWhatsApp } from "./outbound-NQyRObck.js";

//#region src/agents/tools/whatsapp-actions.ts
async function handleWhatsAppAction(params, cfg) {
	const action = readStringParam(params, "action", { required: true });
	const isActionEnabled = createActionGate(cfg.channels?.whatsapp?.actions);
	if (action === "react") {
		if (!isActionEnabled("reactions")) throw new Error("WhatsApp reactions are disabled.");
		const chatJid = readStringParam(params, "chatJid", { required: true });
		const messageId = readStringParam(params, "messageId", { required: true });
		const { emoji, remove, isEmpty } = readReactionParams(params, { removeErrorMessage: "Emoji is required to remove a WhatsApp reaction." });
		const participant = readStringParam(params, "participant");
		const accountId = readStringParam(params, "accountId");
		const fromMeRaw = params.fromMe;
		await sendReactionWhatsApp(chatJid, messageId, remove ? "" : emoji, {
			verbose: false,
			fromMe: typeof fromMeRaw === "boolean" ? fromMeRaw : void 0,
			participant: participant ?? void 0,
			accountId: accountId ?? void 0
		});
		if (!remove && !isEmpty) return jsonResult({
			ok: true,
			added: emoji
		});
		return jsonResult({
			ok: true,
			removed: true
		});
	}
	throw new Error(`Unsupported WhatsApp action: ${action}`);
}

//#endregion
export { handleWhatsAppAction };