/* src/components/panels/APIKeysConfig.tsx */ import { useLocalStorage } from "react-use"; import { ChangeEvent, useState, useEffect } from "react"; import { toast } from "react-toastify"; import { FiAlertTriangle } from "react-icons/fi"; type RowProps = { label: string; link: string; storageKey: string; placeholder: string; validator?: (key: string) => boolean; }; function InputRow({ label, link, storageKey, placeholder, validator }: RowProps) { const [value, setValue] = useLocalStorage(storageKey, ""); const [error, setError] = useState(null); const onChange = (e: ChangeEvent) => { const newValue = e.target.value.trim(); setValue(newValue); if (validator && newValue) { const isValid = validator(newValue); if (!isValid) { setError("Formato de chave inválido"); } else { setError(null); } } else { setError(null); } }; return (
{error &&

{error}

}
); } export default function APIKeysConfig() { const validateOpenAI = (key: string) => key.startsWith("sk-"); const validateGemini = (key: string) => key.startsWith("AIza"); const validateHF = (key: string) => key.startsWith("hf_"); const [showQuotaWarning, setShowQuotaWarning] = useState(false); // Verifica se deve mostrar o aviso de quota useEffect(() => { // Busca no localStorage se houve um erro de quota recentemente (armazenado pelo ChatInterface) const hasQuotaError = localStorage.getItem("openai_quota_error") === "true"; setShowQuotaWarning(hasQuotaError); }, []); const testConnections = () => { toast.info("Testando conexões..."); // Aqui poderíamos implementar um teste real de conexão setTimeout(() => toast.success("Chaves salvas com sucesso!"), 1000); }; return (

Configurar chaves de API

{showQuotaWarning && (

Problema de quota detectado

Sua chave da OpenAI (ChatGPT) atingiu o limite de quota. Você pode:

  • Utilizar outra chave de API
  • Aguardar até o próximo ciclo quando sua quota for renovada
  • Atualizar seu plano na OpenAI para obter mais créditos
  • Usar outros agentes que não dependem da API do ChatGPT
)}

As chaves são salvas apenas no localStorage do seu navegador e enviadas ao servidor somente quando você usa o respectivo modelo.

); }