import { useState, useEffect } from 'react' import { X, Eye, EyeOff } from 'lucide-react' import { getApiConfig, setApiConfig, type ApiConfig } from '../services/api-config' interface ApiSettingsProps { open: boolean onClose: () => void } export default function ApiSettings({ open, onClose }: ApiSettingsProps) { const [config, setConfig] = useState(getApiConfig) const [showKey, setShowKey] = useState(false) const [saved, setSaved] = useState(false) // 每次打开时从 localStorage 同步最新配置 useEffect(() => { if (open) { setConfig(getApiConfig()) setSaved(false) } }, [open]) if (!open) return null const handleSave = () => { setApiConfig(config) setSaved(true) setTimeout(() => { onClose() }, 600) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Escape') onClose() } return (
{ if (e.target === e.currentTarget) onClose() }} onKeyDown={handleKeyDown} >
{/* Header */}

API 设置

{/* Form */}
{/* Base URL */}
setConfig({ ...config, baseUrl: e.target.value })} placeholder="https://api.openai.com/v1" className="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300" />

OpenAI 兼容的 API 端点地址

{/* API Key */}
setConfig({ ...config, apiKey: e.target.value })} placeholder="sk-..." className="w-full rounded-lg border border-gray-200 pl-3 pr-9 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300" />

密钥仅保存在浏览器 localStorage 中

{/* Model */}
setConfig({ ...config, model: e.target.value })} placeholder="gpt-4-turbo" className="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300" />
{/* Footer */}
配置保存在本地浏览器中
) }