#!/bin/bash
# Setup Sofiia for NODA2
# This script adds API keys and configures Sofiia agent

set -e

REPO_DIR="/Users/apple/github-projects/microdao-daarion"
ENV_FILE="$REPO_DIR/.env"

echo "🔑 Setting up Sofiia for NODA2..."

# Add Grok API key
if ! grep -q "XAI_API_KEY" "$ENV_FILE" 2>/dev/null; then
    echo "" >> "$ENV_FILE"
    echo "# xAI Grok API (for Sofiia agent)" >> "$ENV_FILE"
    echo "XAI_API_KEY=xai-VsaJjtIDhQdMlez7jRrQ93uAvqBWi0UNrdDhpUO58tnKMgjIp6P0BF6HGWrLe2QXezyvJnjCUD7C9gQ7" >> "$ENV_FILE"
    echo "✅ Added XAI_API_KEY"
else
    echo "⚠️  XAI_API_KEY already exists in .env"
fi

# Add Sofiia Telegram bot token
if ! grep -q "SOFIIA_TELEGRAM_BOT_TOKEN" "$ENV_FILE" 2>/dev/null; then
    echo "" >> "$ENV_FILE"
    echo "# Sofiia Telegram Bot (NODA2)" >> "$ENV_FILE"
    echo "SOFIIA_TELEGRAM_BOT_TOKEN=8589292566:AAEmPvS6nY9e-Y-TZm04CAHWlaFnWVxajE4" >> "$ENV_FILE"
    echo "✅ Added SOFIIA_TELEGRAM_BOT_TOKEN"
else
    echo "⚠️  SOFIIA_TELEGRAM_BOT_TOKEN already exists in .env"
fi

# Add GLM5 API key
if ! grep -q "GLM5_API_KEY" "$ENV_FILE" 2>/dev/null; then
    echo "" >> "$ENV_FILE"
    echo "# GLM5 API Key (Z.AI)" >> "$ENV_FILE"
    echo "GLM5_API_KEY=2f32adb611c54ccf9808062c4442c2b2.Q0BgNNlmH9O9iPGe" >> "$ENV_FILE"
    echo "✅ Added GLM5_API_KEY"
else
    echo "⚠️  GLM5_API_KEY already exists in .env"
fi

echo ""
echo "✅ Sofiia setup complete!"
echo ""
echo "Next steps:"
echo "1. cd $REPO_DIR"
echo "2. docker-compose -f docker-compose.node2.yml up -d"
echo "3. Test: curl http://localhost:9102/v1/agents/sofiia/infer"
