6.7 KiB
6.7 KiB
🎉 Extension → Vibn Integration Complete!
✅ What's Been Implemented
1. API Key Generation
- Unique API keys generated for each user (
vibn_abc123...) - Stored securely in Firebase
- Accessible via
/api/user/api-keyendpoint
2. Session Tracking API
- Endpoint:
POST /api/sessions/track - Validates API keys
- Stores sessions in Firebase
- Returns session ID on success
3. Connections Page
- Shows user's API key (hidden by default)
- Copy to clipboard functionality
- Step-by-step setup instructions
- Visual indication of extension status
4. Firebase Configuration
- API Keys collection created
- Firestore security rules updated
- Indexes created for performance
- Admin SDK configured for server-side operations
🚀 How It Works
┌─────────────────────────────────────────────────┐
│ Cursor Extension │
│ │
│ 1. User configures API key in extension │
│ 2. Extension captures session data │
│ 3. POST to /api/sessions/track │
└─────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Vibn Backend (Firebase) │
│ │
│ 1. Verify API key │
│ 2. Get userId from API key │
│ 3. Store session in Firebase │
│ 4. Return session ID │
└─────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Vibn Dashboard │
│ │
│ User sees real-time session data, │
│ costs, and activity │
└─────────────────────────────────────────────────┘
📝 To Connect Your Extension
Step 1: Get Your API Key
- Go to:
http://localhost:3000/marks-account/connections - Your API key is displayed in the "Cursor Extension" section
- Click the copy icon to copy it
Step 2: Update Extension Code
Use the guide in EXTENSION_INTEGRATION.md to:
- Add settings for API key and API URL
- Implement session tracking
- Send data to Vibn API
Step 3: Configure Extension
- Open Cursor Settings
- Search for "Vibn"
- Paste your API key
- Set API URL to:
http://localhost:3000/api(dev) orhttps://vibnai.com/api(prod)
Step 4: Test
- Code in Cursor with AI
- Extension sends session data
- Check Vibn dashboard to see your sessions
🧪 Testing the API
Test API Key Endpoint
# Get user's API key (requires Firebase auth token)
curl -X GET http://localhost:3000/api/user/api-key \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN"
Test Session Tracking
curl -X POST http://localhost:3000/api/sessions/track \
-H "Content-Type: application/json" \
-d '{
"apiKey": "vibn_abc123...",
"sessionData": {
"startTime": "2025-01-15T10:30:00.000Z",
"endTime": "2025-01-15T11:00:00.000Z",
"duration": 1800,
"model": "claude-sonnet-4",
"tokensUsed": 45000,
"cost": 1.35,
"filesModified": ["/src/test.ts"],
"conversationSummary": "Added test feature"
}
}'
Expected Response:
{
"success": true,
"sessionId": "abc123...",
"message": "Session tracked successfully"
}
📂 Files Created/Modified
New Files:
lib/firebase/api-keys.ts- API key generation and verificationapp/api/user/api-key/route.ts- Get/create API key for userapp/api/sessions/track/route.ts- Track sessions from extensionEXTENSION_INTEGRATION.md- Complete integration guideEXTENSION_SETUP_SUMMARY.md- This file
Modified Files:
app/[workspace]/connections/page.tsx- Display API key and instructionsfirestore.rules- Added API Keys security rulesfirestore.indexes.json- Added API Keys indexespackage.json- Addeduuiddependency
🔐 Security
API Keys:
- ✅ 32-character unique identifiers
- ✅ Stored securely in Firebase
- ✅ Never exposed in client-side code (except connections page)
- ✅ Validated on every request
Firestore Rules:
- ✅ API Keys only accessible via Admin SDK (server-side)
- ✅ Sessions only created via Admin SDK
- ✅ Users can only read their own sessions
- ✅ All writes go through validated API endpoints
Best Practices:
- ✅ API keys transmitted over HTTPS
- ✅ Request timeout (10 seconds)
- ✅ Error handling without exposing sensitive data
- ✅ Rate limiting can be added later
🎯 Next Steps
For Extension:
- Add Vibn settings to extension
- Implement session tracking logic
- Test with localhost API
- Deploy to production
For Vibn Dashboard:
- Create "Sessions" page to display tracked sessions
- Add real-time updates
- Show cost analytics
- Add filters and search
Optional Enhancements:
- Webhook notifications for new sessions
- Real-time dashboard updates (Firestore listeners)
- Export sessions to CSV
- Cost projections and alerts
- Multi-workspace support
🐛 Troubleshooting
"Invalid or inactive API key"
- Check that the API key is copied correctly
- Verify extension settings are saved
- Try regenerating the API key
"Failed to track session"
- Check network connection
- Verify API URL is correct
- Check browser console for errors
Sessions not appearing
- Wait a few seconds (Firebase sync)
- Refresh the dashboard
- Check if API key is active
📚 Documentation
- Full Integration Guide:
EXTENSION_INTEGRATION.md - Firebase Setup:
FIREBASE_SETUP.md - API Documentation: (Coming soon)
🎉 You're All Set!
Your extension can now connect to Vibn and start tracking sessions. Users get:
- ✅ Real-time session tracking
- ✅ Automatic cost calculation
- ✅ AI usage analytics
- ✅ Project management
- ✅ Living documentation
Happy coding! 🚀