"use client" import type React from "react" import { useState } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { storeOpenAIKey } from "@/utils/openai" interface OpenAIKeyModalProps { open: boolean onOpenChange: (open: boolean) => void onKeySubmit: () => void } export function OpenAIKeyModal({ open, onOpenChange, onKeySubmit }: OpenAIKeyModalProps) { const [apiKey, setApiKey] = useState("") const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState(null) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsSubmitting(true) setError(null) try { if (!apiKey.trim()) { throw new Error("API key is required") } // Simple validation - OpenAI keys typically start with "sk-" if (!apiKey.trim().startsWith("sk-")) { throw new Error("Invalid API key format. OpenAI keys typically start with 'sk-'") } // Store the API key storeOpenAIKey(apiKey.trim()) // Call the onKeySubmit callback onKeySubmit() // Close the modal onOpenChange(false) } catch (error) { setError(error instanceof Error ? error.message : "An unknown error occurred") } finally { setIsSubmitting(false) } } return ( OpenAI API Key Required To use AI features, please enter your OpenAI API key. This key will be stored securely in your browser for future use.
setApiKey(e.target.value)} placeholder="sk-..." className="bg-[#0a0e14] border-[#1e2a3a] focus-visible:ring-[#4cc9ff]" required /> {error &&

{error}

}

Your API key is stored locally in your browser and is never sent to our servers. You can get an API key from{" "} OpenAI's website .

) }