"use client"; import { useEffect, useState } from "react"; import { Check, ChevronsUpDown, Loader2 } from "lucide-react"; import { Button } from "./ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "./ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover"; import { cn } from "@/lib/utils"; import { toast } from "sonner"; import { Switch } from "./ui/switch"; interface AnthropicConfigProps { anthropicApiKey: string; anthropicModel: string; extendedReasoning: boolean; webGrounding?: boolean; onInputChange: (value: string | boolean, field: string) => void; } export default function AnthropicConfig({ anthropicApiKey, anthropicModel, extendedReasoning, webGrounding, onInputChange, }: AnthropicConfigProps) { const [openModelSelect, setOpenModelSelect] = useState(false); const [availableModels, setAvailableModels] = useState([]); const [modelsLoading, setModelsLoading] = useState(false); const [modelsChecked, setModelsChecked] = useState(false); const [apiKey, setApiKey] = useState(anthropicApiKey); useEffect(() => { setAvailableModels([]); setModelsChecked(false); onInputChange("", "anthropic_model"); }, [apiKey]); const onApiKeyChange = (value: string) => { setApiKey(value); onInputChange(value, "anthropic_api_key"); }; const fetchAvailableModels = async () => { if (!anthropicApiKey) return; setModelsLoading(true); try { const response = await fetch('/api/v1/ppt/anthropic/models/available', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ api_key: anthropicApiKey }), }); if (response.ok) { const data = await response.json(); setAvailableModels(data); setModelsChecked(true); onInputChange("claude-sonnet-4-20250514", "anthropic_model"); } else { console.error('Failed to fetch models'); setAvailableModels([]); setModelsChecked(true); } } catch (error) { console.error('Error fetching models:', error); toast.error('Error fetching models'); setAvailableModels([]); setModelsChecked(true); } finally { setModelsLoading(false); } }; return (
{/* API Key Input */}
onApiKeyChange(e.target.value)} className="w-full px-4 py-2.5 outline-none border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 transition-colors" placeholder="Enter your Anthropic API key" />

Your API key will be stored locally and never shared

{/* Extended Reasoning Toggle */} {/*
onInputChange(checked, "extended_reasoning")} />

Enable extended reasoning for more detailed and thorough responses

*/} {/* Check for available models button - show when no models checked or no models found */} {(!modelsChecked || (modelsChecked && availableModels.length === 0)) && (
)} {/* Show message if no models found */} {modelsChecked && availableModels.length === 0 && (

No models found. Please make sure your API key is valid and has access to Anthropic models.

)} {/* Model Selection - only show if models are available */} {modelsChecked && availableModels.length > 0 ? (
No model found. {availableModels.map((model, index) => ( { onInputChange(value, "anthropic_model"); setOpenModelSelect(false); }} >
{model}
))}
) : null} {/* Web Grounding Toggle - at the end, below models dropdown */}
onInputChange(checked, "web_grounding")} />

If enabled, the model can use web search grounding when available.

); }