# Vercel Setup Guide for BuzzTrail Proxy Server

This guide provides step-by-step instructions for setting up and deploying the BuzzTrail Tavus API proxy server on Vercel.

## 🚀 **Deployment Steps**

### **Step 1: Vercel Project Setup**
1. **Go to [Vercel Dashboard](https://vercel.com/dashboard)**
2. **Click "New Project"**
3. **Import Git Repository**: `BuzzTrail/video-extension`
4. **Configure Project Settings**:
   5. **Team**: `buzztrail`
   6. **Framework Preset**: Other (we'll configure manually)
   7. **Root Directory**: `proxy-server` ⚠️ **CRITICAL: Set this to `proxy-server`**
   8. **Build Command**: `pnpm run build:vercel` (or leave empty - Vercel will use our config)
   9. **Output Directory**: Leave empty (Vercel will use our config)
   10. **Install Command**: `pnpm install`
   11. Click **"Deploy"**

**⚠️ IMPORTANT**: You MUST set the Root Directory to `proxy-server` in the Vercel project settings. If you don't, Vercel will try to build the entire Chrome extension and fail.

**Note**: The deployment will only include the API serverless functions from the proxy-server folder, not the full Chrome extension build.

### **Step 2: Configure Environment Variables**
1. **Go to Vercel Dashboard** → Your project → Settings → Environment Variables
2. **Add**: `TAVUS_API_KEY = 8ff39906dd5840a9bca8c6ce4e15135c`
3. **Add**: `NODE_ENV = production`
4. **Redeploy** the project

### **Step 3: Verify Deployment**
1. **Check the domain**: Should be `buzztrail-proxy.vercel.app`
2. **Test health endpoint**: `https://buzztrail-proxy.vercel.app/api/health`
3. **Verify CORS**: Should allow `http://localhost:8080` for local testing

## 🔄 **Redeploying After Changes**

### **Automatic Redeployment**
- **Git Push**: Any push to the main branch will trigger automatic redeployment
- **Vercel Dashboard**: You can also manually redeploy from the Vercel dashboard

### **Manual Redeployment**
1. **Go to Vercel Dashboard** → Your project
2. **Click "Deployments"** tab
3. **Click "Redeploy"** on the latest deployment
4. **Wait for deployment** to complete (usually 30-60 seconds)

### **After CORS Changes**
If you've updated CORS configuration (like adding localhost support):
1. **Push changes** to the repository
2. **Wait for automatic redeployment** or manually redeploy
3. **Test local development** with `http://localhost:8080`

## 🚨 **Troubleshooting**

### **Common Build Errors**

**Error**: "No Output Directory named 'public' found"
- **Solution**: Ensure Root Directory is set to `proxy-server`

**Error**: "No entrypoints found" or "wxt prepare" errors
- **Solution**: The proxy-server has its own package.json, ensure Root Directory is correct

**Error**: CORS issues with localhost
- **Solution**: Redeploy after CORS changes, ensure localhost:8080 is in allowed origins

### **Environment Variables**
- **Missing API Key**: Add `TAVUS_API_KEY` in Vercel project settings
- **Wrong Environment**: Set `NODE_ENV = production` for full functionality

### **Domain Issues**
- **Custom Domain**: Configure in Vercel project settings if needed
- **SSL**: Automatically handled by Vercel

## 📞 **Testing**

### **Health Check**
```bash
curl https://buzztrail-proxy.vercel.app/api/health
```

### **Create Conversation**
```bash
curl -X POST https://buzztrail-proxy.vercel.app/api/conversations/create \
  -H "Content-Type: application/json" \
  -d '{"personaKey": "buzztrail-researcher"}'
```

### **Local Development**
```bash
pnpm run dev:demos
# Then visit: http://localhost:8080/buzztrail-video-demo/
```

## 🔧 **Configuration**

### **CORS Origins**
The proxy server allows these origins:
- `https://buzztrail.ai`
- `https://www.buzztrail.ai`
- `http://localhost:3000`
- `http://localhost:8080`
- `http://localhost:8083`
- `http://127.0.0.1:3000`
- `http://127.0.0.1:8080`

### **Personas**
- **BuzzTrail Researcher**: `buzztrail-researcher`
- **Sendcloud Lead Qualifier**: `sendcloud-lead-qualifier`

### **Environment Variables**
- `TAVUS_API_KEY`: Your Tavus API key
- `NODE_ENV`: Set to `production` for full functionality
