import "./accounts-D3i4dzIq.js";
import "./registry-fCoherJU.js";
import "./paths-eMcMXQYZ.js";
import "./model-selection-DJoM_Qjj.js";
import "./config-UTxVx3Wg.js";
import "./fetch-CvjskjQc.js";
import "./subsystem-C_q3dfX9.js";
import "./agent-scope-DetWUmvK.js";
import "./tool-images-DZuyPhOq.js";
import { i as jsonResult, l as readStringParam, o as readReactionParams, t as createActionGate } from "./common-Y7uXoPWx.js";
import "./command-format-DhLoTeW3.js";
import "./plugins-Bv6mWYA0.js";
import "./bindings-op8Qk9BU.js";
import "./message-channel-CfB6q11f.js";
import "./active-listener-DS0uW5mJ.js";
import "./render-DLkRUjc4.js";
import "./chunk-U4bkBOZ2.js";
import "./markdown-tables-D39g0wu2.js";
import { r as sendReactionWhatsApp } from "./outbound-CAF_pHqC.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 };