repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources15d ago| #1 | #!/bin/bash |
| #2 | |
| #3 | # ═══════════════════════════════════════════════════════════════ |
| #4 | # AI AGENT API - CLOUDFLARE SETUP SCRIPT |
| #5 | # Automates the setup of D1, KV, and deployment |
| #6 | # ═══════════════════════════════════════════════════════════════ |
| #7 | |
| #8 | set -e |
| #9 | |
| #10 | echo "╔════════════════════════════════════════════════════════════╗" |
| #11 | echo "║ AI AGENT API - Cloudflare Workers Setup ║" |
| #12 | echo "╚════════════════════════════════════════════════════════════╝" |
| #13 | echo "" |
| #14 | |
| #15 | # Check if wrangler is installed |
| #16 | if ! command -v wrangler &> /dev/null; then |
| #17 | echo "❌ Wrangler CLI not found. Installing..." |
| #18 | npm install -g wrangler |
| #19 | fi |
| #20 | |
| #21 | # Check if logged in |
| #22 | echo "🔐 Checking Cloudflare authentication..." |
| #23 | if ! wrangler whoami &> /dev/null; then |
| #24 | echo "Please login to Cloudflare:" |
| #25 | wrangler login |
| #26 | fi |
| #27 | |
| #28 | echo "" |
| #29 | echo "📦 Installing dependencies..." |
| #30 | npm install |
| #31 | |
| #32 | echo "" |
| #33 | echo "🗄️ Creating D1 Database..." |
| #34 | DB_OUTPUT=$(wrangler d1 create agent-db 2>&1 || true) |
| #35 | |
| #36 | # Extract database ID |
| #37 | DB_ID=$(echo "$DB_OUTPUT" | grep -o 'database_id = "[^"]*"' | cut -d'"' -f2) |
| #38 | |
| #39 | if [ -z "$DB_ID" ]; then |
| #40 | echo "⚠️ Database may already exist. Trying to get existing ID..." |
| #41 | DB_ID=$(wrangler d1 list --json | node -e "let s='';process.stdin.on('data',d=>s+=d);process.stdin.on('end',()=>{const db=JSON.parse(s).find(d=>d.name==='agent-db'); if (db) console.log(db.uuid || db.id);})" || echo "") |
| #42 | fi |
| #43 | |
| #44 | if [ -z "$DB_ID" ]; then |
| #45 | echo "❌ Could not get database ID. Please create manually:" |
| #46 | echo " wrangler d1 list --json" |
| #47 | exit 1 |
| #48 | fi |
| #49 | |
| #50 | echo "✅ Database ID: $DB_ID" |
| #51 | |
| #52 | echo "" |
| #53 | echo "📦 Creating KV Namespaces..." |
| #54 | |
| #55 | # Create Sessions KV |
| #56 | SESSIONS_OUTPUT=$(wrangler kv namespace create SESSIONS 2>&1 || true) |
| #57 | SESSIONS_ID=$(echo "$SESSIONS_OUTPUT" | grep -o 'id = "[^"]*"' | cut -d'"' -f2) |
| #58 | |
| #59 | if [ -z "$SESSIONS_ID" ]; then |
| #60 | echo "⚠️ Sessions KV may already exist. Trying to get existing ID..." |
| #61 | SESSIONS_ID=$(wrangler kv namespace list | node -e "let s='';process.stdin.on('data',d=>s+=d);process.stdin.on('end',()=>{const ns=JSON.parse(s).find(n=>n.title==='agent-api-SESSIONS' || n.title==='SESSIONS'); if (ns) console.log(ns.id);})" || echo "") |
| #62 | fi |
| #63 | |
| #64 | echo "✅ Sessions KV ID: $SESSIONS_ID" |
| #65 | |
| #66 | # Create Rate Limits KV |
| #67 | RATE_OUTPUT=$(wrangler kv namespace create RATE_LIMITS 2>&1 || true) |
| #68 | RATE_ID=$(echo "$RATE_OUTPUT" | grep -o 'id = "[^"]*"' | cut -d'"' -f2) |
| #69 | |
| #70 | if [ -z "$RATE_ID" ]; then |
| #71 | echo "⚠️ Rate Limits KV may already exist. Trying to get existing ID..." |
| #72 | RATE_ID=$(wrangler kv namespace list | node -e "let s='';process.stdin.on('data',d=>s+=d);process.stdin.on('end',()=>{const ns=JSON.parse(s).find(n=>n.title==='agent-api-RATE_LIMITS' || n.title==='RATE_LIMITS'); if (ns) console.log(ns.id);})" || echo "") |
| #73 | fi |
| #74 | |
| #75 | echo "✅ Rate Limits KV ID: $RATE_ID" |
| #76 | |
| #77 | echo "" |
| #78 | echo "📝 Updating wrangler.toml..." |
| #79 | |
| #80 | # Update wrangler.toml with actual IDs |
| #81 | if [ -n "$DB_ID" ]; then |
| #82 | sed -i.bak "s/YOUR_DATABASE_ID_HERE/$DB_ID/g" wrangler.toml |
| #83 | fi |
| #84 | |
| #85 | if [ -n "$SESSIONS_ID" ]; then |
| #86 | sed -i.bak "s/YOUR_KV_ID_HERE/$SESSIONS_ID/g" wrangler.toml |
| #87 | fi |
| #88 | |
| #89 | if [ -n "$RATE_ID" ]; then |
| #90 | sed -i.bak "s/YOUR_RATE_LIMIT_KV_ID_HERE/$RATE_ID/g" wrangler.toml |
| #91 | fi |
| #92 | |
| #93 | rm -f wrangler.toml.bak |
| #94 | |
| #95 | echo "✅ wrangler.toml updated" |
| #96 | |
| #97 | echo "" |
| #98 | echo "🗃️ Running database migration..." |
| #99 | wrangler d1 execute agent-db --remote --file=./schema.sql |
| #100 | |
| #101 | echo "" |
| #102 | echo "🔑 Setting up secrets..." |
| #103 | echo "Please enter your Crossmint Server-side API Key:" |
| #104 | wrangler secret put CROSSMINT_SERVERSIDE_API_KEY |
| #105 | |
| #106 | echo "" |
| #107 | echo "🚀 Deploying to Cloudflare Workers..." |
| #108 | wrangler deploy |
| #109 | |
| #110 | echo "" |
| #111 | echo "╔════════════════════════════════════════════════════════════╗" |
| #112 | echo "║ ✅ SETUP COMPLETE! ║" |
| #113 | echo "╚════════════════════════════════════════════════════════════╝" |
| #114 | echo "" |
| #115 | echo "Your API is now live at:" |
| #116 | echo " https://agent-api.<YOUR_SUBDOMAIN>.workers.dev" |
| #117 | echo "" |
| #118 | echo "Test it with:" |
| #119 | echo " curl https://agent-api.<YOUR_SUBDOMAIN>.workers.dev/health" |
| #120 | echo "" |
| #121 | echo "Register an agent:" |
| #122 | echo " curl -X POST https://agent-api.<YOUR_SUBDOMAIN>.workers.dev/api/agents/register \\" |
| #123 | echo " -H 'Content-Type: application/json' \\" |
| #124 | echo " -d '{\"name\": \"My Trading Bot\"}'" |
| #125 | echo "" |
| #126 |