fix: API-Key Status-Anzeige fuer Anthropic/OpenAI im AI-Provider Bereich
Zeigt im AI-Provider Formular einen Status-Indikator an, ob ein API-Schluessel fuer den gewaehlten Provider (Anthropic/OpenAI) hinterlegt ist. Entfernt Ollama aus dem API-Key Dropdown, da Ollama keine API-Keys benoetigt. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -9,6 +9,11 @@ interface AISettings {
|
||||
ollamaModel: string;
|
||||
}
|
||||
|
||||
interface ApiKeyInfo {
|
||||
provider: string;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export default function AISettingsForm() {
|
||||
const [settings, setSettings] = useState<AISettings>({
|
||||
provider: 'anthropic',
|
||||
@@ -19,6 +24,7 @@ export default function AISettingsForm() {
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [apiKeys, setApiKeys] = useState<ApiKeyInfo[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/settings/ai')
|
||||
@@ -28,6 +34,10 @@ export default function AISettingsForm() {
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => setLoading(false));
|
||||
fetch('/api/settings/api-keys')
|
||||
.then((r) => r.json())
|
||||
.then((data) => setApiKeys(data))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
@@ -82,16 +92,31 @@ export default function AISettingsForm() {
|
||||
</div>
|
||||
|
||||
{settings.provider !== 'ollama' && (
|
||||
<div>
|
||||
<label className="block text-sm text-muted mb-1">Modell (optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={settings.model}
|
||||
onChange={(e) => setSettings({ ...settings, model: e.target.value })}
|
||||
placeholder={settings.provider === 'anthropic' ? 'claude-sonnet-4-20250514' : 'gpt-4o'}
|
||||
className="w-full rounded-lg border border-card-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted/50"
|
||||
/>
|
||||
</div>
|
||||
<>
|
||||
<div>
|
||||
<label className="block text-sm text-muted mb-1">Modell (optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={settings.model}
|
||||
onChange={(e) => setSettings({ ...settings, model: e.target.value })}
|
||||
placeholder={settings.provider === 'anthropic' ? 'claude-sonnet-4-20250514' : 'gpt-4o'}
|
||||
className="w-full rounded-lg border border-card-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted/50"
|
||||
/>
|
||||
</div>
|
||||
{(() => {
|
||||
const activeKey = apiKeys.find(
|
||||
(k) => k.provider === settings.provider && k.isActive,
|
||||
);
|
||||
return (
|
||||
<div className={`flex items-center gap-2 rounded-lg border px-3 py-2 text-sm ${activeKey ? 'border-green-200 bg-green-50 text-green-700' : 'border-amber-200 bg-amber-50 text-amber-700'}`}>
|
||||
<span className={`inline-block w-2 h-2 rounded-full shrink-0 ${activeKey ? 'bg-green-500' : 'bg-amber-500'}`} />
|
||||
{activeKey
|
||||
? `API-Schlüssel für ${settings.provider === 'anthropic' ? 'Anthropic' : 'OpenAI'} ist konfiguriert.`
|
||||
: `Kein API-Schlüssel für ${settings.provider === 'anthropic' ? 'Anthropic' : 'OpenAI'} hinterlegt. Bitte unten unter „API-Schlüssel" einen Schlüssel hinzufügen.`}
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
</>
|
||||
)}
|
||||
|
||||
{settings.provider === 'ollama' && (
|
||||
|
||||
@@ -172,7 +172,6 @@ export default function ApiKeySettings() {
|
||||
>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
<option value="openai">OpenAI</option>
|
||||
<option value="ollama">Ollama</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user