Files
wp-agentic-writer/downloads/start-proxy.sh

93 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
echo "🚀 Starting Agentic Writer Local Backend..."
echo ""
# Check dependencies
if ! command -v node &> /dev/null; then
echo "❌ Node.js not found. Install from https://nodejs.org/"
exit 1
fi
if ! command -v claude &> /dev/null; then
echo "❌ Claude CLI not found. Install and configure first."
echo " Check: https://claude.ai/code or https://z.ai"
exit 1
fi
# Auto-install express if needed
if [ ! -d "node_modules" ]; then
echo "📦 Installing dependencies..."
npm install
fi
# Load environment variables from .env file if it exists
if [ -f .env ]; then
echo "📋 Loading environment from .env file..."
set -a # automatically export all variables created
source .env
set +a # stop auto-export
fi
# Detect local IP
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
LOCAL_IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null || echo "127.0.0.1")
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
LOCAL_IP=$(ip route get 1 | awk '{print $7;exit}' 2>/dev/null || echo "127.0.0.1")
else
# Windows/other
LOCAL_IP="127.0.0.1"
fi
echo "✅ Dependencies OK"
echo "✅ Claude CLI found: $(which claude)"
echo ""
echo "Starting proxy server..."
echo ""
# Start server in background
nohup node claude-proxy.js > proxy.log 2>&1 &
PID=$!
echo $PID > proxy.pid
# Wait for server to boot
sleep 2
# Test if running
if kill -0 $PID 2>/dev/null; then
echo "═══════════════════════════════════════════════════"
echo "✅ Local Backend Running!"
echo "═══════════════════════════════════════════════════"
echo ""
echo "Your Configuration:"
echo " Base URL: http://$LOCAL_IP:8080"
echo " API Key: dummy"
echo " Model: claude-local"
echo ""
if [ -n "$BRAVE_SEARCH_API_KEY" ]; then
echo "Brave Search: ✅ CONFIGURED"
else
echo "Brave Search: ⚠️ NOT SET (web search disabled)"
echo " To enable: Add BRAVE_SEARCH_API_KEY to .env file"
fi
echo ""
echo "Next Steps:"
echo " 1. Open your WordPress Admin"
echo " 2. Go to Agentic Writer → Settings → Local Backend"
echo " 3. Paste the Base URL above"
echo " 4. Click 'Test Connection'"
echo ""
echo "Commands:"
echo " Logs: tail -f proxy.log"
echo " Stop: ./stop-proxy.sh"
echo " Test: ./test-connection.sh"
echo "═══════════════════════════════════════════════════"
else
echo "❌ Failed to start. Check proxy.log for errors."
cat proxy.log
rm -f proxy.pid
exit 1
fi