"use client"; import { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Github, CheckCircle2, Download, Copy, Check, Eye, EyeOff } from "lucide-react"; import { CursorIcon } from "@/components/icons/custom-icons"; import { toast } from "sonner"; import { auth } from "@/lib/firebase/config"; import type { User } from "firebase/auth"; import { MCPConnectionCard } from "@/components/mcp-connection-card"; import { ChatGPTImportCard } from "@/components/chatgpt-import-card"; export default function ConnectionsPage() { const [githubConnected, setGithubConnected] = useState(false); const [extensionInstalled] = useState(false); // Future use: track extension installation const [copiedApiKey, setCopiedApiKey] = useState(false); const [showApiKey, setShowApiKey] = useState(false); const [apiKey, setApiKey] = useState(null); const [loadingApiKey, setLoadingApiKey] = useState(true); const [apiUrl, setApiUrl] = useState('https://vibnai.com'); // Set API URL on client side to avoid hydration mismatch useEffect(() => { if (typeof window !== 'undefined') { setApiUrl(window.location.origin); } }, []); // Fetch API key on mount useEffect(() => { async function fetchApiKey(user: User) { try { console.log('[Client] Getting ID token for user:', user.uid); const token = await user.getIdToken(); console.log('[Client] Token received, length:', token.length); const response = await fetch('/api/user/api-key', { headers: { 'Authorization': `Bearer ${token}`, }, }); console.log('[Client] Response status:', response.status); if (response.ok) { const data = await response.json(); console.log('[Client] API key received'); setApiKey(data.apiKey); } else { const errorData = await response.json(); console.error('[Client] Failed to fetch API key:', response.status, errorData); } } catch (error) { console.error('[Client] Error fetching API key:', error); } finally { setLoadingApiKey(false); } } // Listen for auth state changes const unsubscribe = auth.onAuthStateChanged((user) => { if (user) { fetchApiKey(user); } else { setLoadingApiKey(false); } }); return () => unsubscribe(); }, []); const handleConnectGitHub = async () => { // TODO: Implement GitHub OAuth flow toast.success("GitHub connected successfully!"); setGithubConnected(true); }; const handleInstallExtension = () => { // Link to Cursor Monitor extension (update with actual marketplace URL when published) window.open("https://marketplace.visualstudio.com/items?itemName=cursor-monitor", "_blank"); }; const handleCopyApiKey = () => { if (apiKey) { navigator.clipboard.writeText(apiKey); setCopiedApiKey(true); toast.success("API key copied to clipboard!"); setTimeout(() => setCopiedApiKey(false), 2000); } }; return (
{/* Header */}

Connect Your Tools

Set up your development tools to unlock the full power of Vib'n

{/* Connection Cards */}
{/* Cursor Extension */}
Cursor Monitor Extension {extensionInstalled && ( )}
Automatically track your coding sessions, AI usage, and costs
{!extensionInstalled ? ( ) : ( )}

What it does:

  • Tracks your coding sessions in real-time
  • Monitors AI model usage and token consumption
  • Logs file changes and conversation history
  • Calculates costs automatically
{!extensionInstalled && ( <>

Installation Steps:

  1. Install the Cursor Monitor extension from the marketplace
  2. Restart Cursor to activate the extension
  3. Configure your API key (see instructions below)
  4. Start coding - sessions will be tracked automatically!

Your API Key

{!loadingApiKey && apiKey && (
)}
{loadingApiKey ? (
Loading...
) : apiKey ? ( <>

Add this key to your extension settings to connect it to your Vibn account.

) : (

Sign in to generate your API key

)}

Configure Cursor Monitor Extension:

  1. Open Cursor Settings (Cmd/Ctrl + ,)
  2. Search for "Cursor Monitor"
  3. Find "Cursor Monitor: Vibn Api Key"
  4. Paste your API key (from above)
  5. Verify "Cursor Monitor: Vibn Api Url" is set to: {apiUrl}/api
  6. Make sure "Cursor Monitor: Vibn Enabled" is checked
  7. Reload Cursor to start tracking
)} {extensionInstalled && (

✓ Extension is installed and tracking your sessions

)}
{/* GitHub Connection */}
GitHub {githubConnected && ( )}
Connect your repositories for automatic analysis
{!githubConnected ? ( ) : ( )}

What we'll access:

  • Read your repository code and structure
  • Access repository metadata and commit history
  • Analyze tech stack and dependencies
  • Identify project architecture patterns
{!githubConnected && (

Why connect GitHub?

Our AI will analyze your codebase to understand your tech stack, architecture, and features. This helps generate better documentation and provides smarter insights.

)} {githubConnected && (

✓ GitHub connected - Your repositories are ready for analysis

)}
{/* ChatGPT (MCP) Connection */} {/* ChatGPT Import */}
{/* Status Summary */} {(githubConnected || extensionInstalled) && ( Connection Status
Cursor Extension {extensionInstalled ? ( Installed ) : ( Not installed )}
GitHub {githubConnected ? ( Connected ) : ( Not connected )}
)}
); }