import { parseSlashCommand } from "../../chat-commands/command-parse.js";
//#region src/agent/messaging/message-router.ts
var MessageRouter = class {
	/**
	* Route an inbound message and determine handling strategy
	*/
	async routeMessage(msg) {
		const sessionKey = this.resolveSessionKey(msg);
		const context = {
			channel: msg.channel,
			chatId: msg.chat_id,
			sessionKey,
			senderId: msg.metadata?.senderId || msg.sender_id,
			isGroup: msg.metadata?.isGroup || false
		};
		const commandInfo = parseSlashCommand(msg.content);
		return {
			context,
			isCommand: commandInfo !== null,
			command: commandInfo?.command,
			commandArgs: commandInfo?.args
		};
	}
	/**
	* Resolve session key from message metadata or derive from channel/chat_id
	*/
	resolveSessionKey(msg) {
		if (msg.metadata?.sessionKey) return msg.metadata.sessionKey;
		if (msg.channel === "system") {
			if (msg.chat_id.includes(":")) {
				const [ch, ...rest] = msg.chat_id.split(":");
				return `${ch}:${rest.join(":")}`;
			}
		}
		return `${msg.channel}:${msg.chat_id}`;
	}
};
//#endregion
export { MessageRouter };

//# sourceMappingURL=message-router.js.map