#!/usr/bin/env node

/**
 * TapTap MCP Proxy
 * Entry point for NPM executable
 * 
 * Note: Converted to ESM to match package "type": "module"
 */

import { join, dirname } from 'node:path';
import { existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';

// Get current directory in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Get package root directory
const packageRoot = join(__dirname, '..');

// Check if bundled version exists
const distPath = join(packageRoot, 'dist', 'proxy.js');

if (existsSync(distPath)) {
    // Use dynamic import for ES Module
    import(distPath).catch(error => {
        console.error('❌ Failed to start MCP Proxy:', error);
        process.exit(1);
    });
} else {
    console.error('❌ MCP Proxy bundle not found. Please build the project first:');
    console.error('   npm run build');
    process.exit(1);
}
