From 10b688bd8905dcb382fac3ac6e2940e2d0ba778d Mon Sep 17 00:00:00 2001 From: MFCo Date: Tue, 26 Aug 2025 14:40:33 +0200 Subject: [PATCH] Add PAT login --- README.md | 14 +++++++++++++- app/api/create-ai-sandbox/route.ts | 22 +++++++++++++++++++--- env.sample | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 env.sample diff --git a/README.md b/README.md index b7a51d1..a5c9800 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,23 @@ npm install ``` 2. **Add `.env.local`** + ```env # Required -VERCEL_TEAM_ID=your_team_id # Your Vercel team ID for sandbox access FIRECRAWL_API_KEY=your_firecrawl_api_key # Get from https://firecrawl.dev (Web scraping) +# Vercel Sandbox Authentication (choose one method) +# See: https://vercel.com/docs/vercel-sandbox#authentication + +# Method 1: OIDC Token (recommended for development) +# Run `vercel link` then `vercel env pull` to get VERCEL_OIDC_TOKEN automatically +# VERCEL_OIDC_TOKEN=auto_generated_by_vercel_env_pull + +# Method 2: Personal Access Token (for production or when OIDC unavailable) +# VERCEL_TEAM_ID=team_xxxxxxxxx # Your Vercel team ID +# VERCEL_PROJECT_ID=prj_xxxxxxxxx # Your Vercel project ID +# VERCEL_TOKEN=vercel_xxxxxxxxxxxx # Personal access token from Vercel dashboard + # Optional (need at least one AI provider) ANTHROPIC_API_KEY=your_anthropic_api_key # Get from https://console.anthropic.com OPENAI_API_KEY=your_openai_api_key # Get from https://platform.openai.com (GPT-5) diff --git a/app/api/create-ai-sandbox/route.ts b/app/api/create-ai-sandbox/route.ts index 3bb1bcb..6fc9ebe 100644 --- a/app/api/create-ai-sandbox/route.ts +++ b/app/api/create-ai-sandbox/route.ts @@ -35,13 +35,29 @@ export async function POST() { global.existingFiles = new Set(); } - // Create Vercel sandbox + // Create Vercel sandbox with flexible authentication console.log(`[create-ai-sandbox] Creating Vercel sandbox with ${appConfig.vercelSandbox.timeoutMinutes} minute timeout...`); - sandbox = await Sandbox.create({ + + // Prepare sandbox configuration + const sandboxConfig: any = { timeout: appConfig.vercelSandbox.timeoutMs, runtime: appConfig.vercelSandbox.runtime, ports: [appConfig.vercelSandbox.devPort] - }); + }; + + // Add authentication parameters if using personal access token + if (process.env.VERCEL_TOKEN && process.env.VERCEL_TEAM_ID && process.env.VERCEL_PROJECT_ID) { + console.log('[create-ai-sandbox] Using personal access token authentication'); + sandboxConfig.teamId = process.env.VERCEL_TEAM_ID; + sandboxConfig.projectId = process.env.VERCEL_PROJECT_ID; + sandboxConfig.token = process.env.VERCEL_TOKEN; + } else if (process.env.VERCEL_OIDC_TOKEN) { + console.log('[create-ai-sandbox] Using OIDC token authentication'); + } else { + console.log('[create-ai-sandbox] No authentication found - relying on default Vercel authentication'); + } + + sandbox = await Sandbox.create(sandboxConfig); const sandboxId = sandbox.sandboxId; console.log(`[create-ai-sandbox] Sandbox created: ${sandboxId}`); diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..0836fc4 --- /dev/null +++ b/env.sample @@ -0,0 +1,21 @@ +# Required +FIRECRAWL_API_KEY=your_firecrawl_api_key # Get from https://firecrawl.dev (Web scraping) + +# Vercel Sandbox Authentication (choose one method) +# See: https://vercel.com/docs/vercel-sandbox#authentication + +# Method 1: OIDC Token (recommended for development) +# Run `vercel env pull` to get VERCEL_OIDC_TOKEN automatically +# VERCEL_OIDC_TOKEN=auto_generated_by_vercel_env_pull + +# Method 2: Personal Access Token (for production or when OIDC unavailable) +# Get these values from your Vercel dashboard +# VERCEL_TEAM_ID=team_xxxxxxxxx +# VERCEL_PROJECT_ID=prj_xxxxxxxxx +# VERCEL_TOKEN=vercel_xxxxxxxxxxxx + +# Optional AI providers (need at least one) +ANTHROPIC_API_KEY=your_anthropic_api_key # Get from https://console.anthropic.com +OPENAI_API_KEY=your_openai_api_key # Get from https://platform.openai.com (GPT-5) +GEMINI_API_KEY=your_gemini_api_key # Get from https://aistudio.google.com/app/apikey +GROQ_API_KEY=your_groq_api_key # Get from https://console.groq.com (Fast inference)