import { useEffect, useState } from 'react'; import { deleteOpenAIKey, getOpenAIKey, saveOpenAIKey } from '../../lib/jwt.ts'; import { cn } from '../../lib/classname.ts'; import { CloseIcon } from '../ReactIcons/CloseIcon.tsx'; import { useToast } from '../../hooks/use-toast.ts'; import { httpPost } from '../../lib/http.ts'; import { ChevronLeft } from 'lucide-react'; type OpenAISettingsProps = { onClose: () => void; onBack: () => void; }; export function OpenAISettings(props: OpenAISettingsProps) { const { onClose, onBack } = props; const [defaultOpenAIKey, setDefaultOpenAIKey] = useState(''); const [error, setError] = useState(''); const [openaiApiKey, setOpenaiApiKey] = useState(''); const [isLoading, setIsLoading] = useState(false); const toast = useToast(); useEffect(() => { const apiKey = getOpenAIKey(); setOpenaiApiKey(apiKey || ''); setDefaultOpenAIKey(apiKey || ''); }, []); return (

OpenAI Settings

Add your OpenAI API key below to bypass the roadmap generation limits. You can use your existing key or{' '} create a new one here .

{ e.preventDefault(); setError(''); const normalizedKey = openaiApiKey.trim(); if (!normalizedKey) { deleteOpenAIKey(); toast.success('OpenAI API key removed'); onClose(); return; } if (!normalizedKey.startsWith('sk-')) { setError("Invalid OpenAI API key. It should start with 'sk-'"); return; } setIsLoading(true); const { response, error } = await httpPost( `${import.meta.env.PUBLIC_API_URL}/v1-validate-openai-key`, { key: normalizedKey, }, ); if (error) { setError(error.message); setIsLoading(false); return; } // Save the API key to cookies saveOpenAIKey(normalizedKey); toast.success('OpenAI API key saved'); onClose(); }} >
{ setError(''); setOpenaiApiKey((e.target as HTMLInputElement).value); }} /> {openaiApiKey && ( )}

We do not store your API key on our servers.

{error && (

{error}

)} {!defaultOpenAIKey && ( )} {defaultOpenAIKey && ( )}
); }