import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Eye, EyeOff, Key, Trash2 } from "lucide-react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; interface ApiKey { id: string; name: string; value: string; isVisible: boolean; lastUsed?: string; } interface ApiKeySection { title: string; keys: ApiKey[]; } export function APIKeysTab() { const [apiKeySections, setApiKeySections] = useState< Record >({ llms: { title: "LLMs", keys: [ { id: "anthropicApiKey", name: "Anthropic", value: "", isVisible: false, }, { id: "openaiApiKey", name: "OpenAI", value: "", isVisible: false }, { id: "googleApiKey", name: "Google Gen AI", value: "", isVisible: false, }, ], }, infrastructure: { title: "Infrastructure", keys: [ { id: "daytonaApiKey", name: "Daytona", value: "", isVisible: false }, ], }, }); const toggleKeyVisibility = (sectionKey: string, keyId: string) => { setApiKeySections((prev) => ({ ...prev, [sectionKey]: { ...prev[sectionKey], keys: prev[sectionKey].keys.map((key) => key.id === keyId ? { ...key, isVisible: !key.isVisible } : key, ), }, })); }; const updateApiKey = (sectionKey: string, keyId: string, value: string) => { setApiKeySections((prev) => ({ ...prev, [sectionKey]: { ...prev[sectionKey], keys: prev[sectionKey].keys.map((key) => key.id === keyId ? { ...key, value } : key, ), }, })); }; const deleteApiKey = (sectionKey: string, keyId: string) => { setApiKeySections((prev) => ({ ...prev, [sectionKey]: { ...prev[sectionKey], keys: prev[sectionKey].keys.map((key) => key.id === keyId ? { ...key, value: "" } : key, ), }, })); }; return (
{Object.entries(apiKeySections).map(([sectionKey, section]) => ( {section.title} Manage API keys for {section.title.toLowerCase()} services {section.keys.map((apiKey) => (

{apiKey.name}

{apiKey.value && ( Configured )} {apiKey.lastUsed && ( Last used {apiKey.lastUsed} )}
updateApiKey(sectionKey, apiKey.id, e.target.value) } placeholder={`Enter your ${apiKey.name} API key`} className="font-mono text-sm" /> {apiKey.value && ( )}

Your API key is stored securely and encrypted

{apiKey.value && ( )}
))}
))}
); }