#!/bin/bash
cd /home/ubuntu/loopuman-backend

# Add logging after AI user creation
sed -i '/const aiUser = await getOrCreateAIUser/a\  console.log(`   👤 AI User created: ${aiUser ? aiUser.id.substring(0,8) : "FAILED"}`);' ai-agents.js

# Add logging before API call
sed -i '/Generating AI response/a\  console.log(`   🤖 Calling Gemini API...`);' ai-agents.js

# Add logging after submission
sed -i '/Insert submission into database/a\  console.log(`   💾 Submitting to database...`);' ai-agents.js

pm2 restart ai-agents
sleep 15
pm2 logs ai-agents --lines 60 --nostream
