
const { createClient } = require('@supabase/supabase-js');
const dotenv = require('dotenv');
const path = require('path');
const fs = require('fs');

const envPaths = [path.join(__dirname, '.env'), path.join(__dirname, '..', '.env')];
for (const p of envPaths) { if (fs.existsSync(p)) dotenv.config({ path: p }); }

const supabaseUrl = process.env.SUPABASE_URL || 'https://dtaegtkfdwgdbyolcxht.supabase.co';
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

async function checkMessages() {
    const { data, error } = await supabase
        .from('messages')
        .select('*')
        .order('created_at', { ascending: false })
        .limit(10);

    if (error) {
        console.error('Error fetching messages:', error);
        return;
    }

    data.forEach(msg => {
        console.log(`[${msg.created_at}] ID: ${msg.id} Role: ${msg.role} Status: ${msg.status} Content: ${msg.content ? msg.content.substring(0, 50).replace(/\n/g, ' ') : 'NULL'}...`);
    });
}
checkMessages();
