/**
 * Cross-Machine Communication Types
 *
 * Types for Slack-based cross-machine orchestrator communication.
 * Two Crewly instances in the same Slack workspace can exchange messages
 * through a designated Slack channel, enabling cross-machine task delegation.
 *
 * @module types/cross-machine
 */
/**
 * Slack message prefix used to identify cross-machine messages.
 * The bridge checks for this prefix to distinguish cross-machine
 * messages from regular user messages.
 */
export const CROSS_MACHINE_PREFIX = '🔗 [X-MACHINE]';
/**
 * Parse a Slack message text to determine if it's a cross-machine message.
 *
 * @param text - Raw Slack message text
 * @returns Parsed CrossMachineMessage or null if not a cross-machine message
 */
export function parseCrossMachineMessage(text) {
    if (!text.startsWith(CROSS_MACHINE_PREFIX)) {
        return null;
    }
    try {
        const jsonPart = text.slice(CROSS_MACHINE_PREFIX.length).trim();
        const parsed = JSON.parse(jsonPart);
        if (parsed.protocol !== 'crewly-x-machine' || !parsed.from || !parsed.to || !parsed.type) {
            return null;
        }
        return parsed;
    }
    catch {
        return null;
    }
}
/**
 * Serialize a cross-machine message for sending via Slack.
 *
 * @param message - The message to serialize
 * @returns Formatted string with prefix + JSON
 */
export function serializeCrossMachineMessage(message) {
    return `${CROSS_MACHINE_PREFIX} ${JSON.stringify(message)}`;
}
//# sourceMappingURL=cross-machine.types.js.map