import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Plus, Trash2, Pencil } from "lucide-react"; import type { Provider } from "@/lib/types"; import { useProviders, useProviderMutations } from "@/lib/queries"; import { useToast } from "@/components/toast"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ProviderForm, type ProviderSubmitInput } from "@/components/ProviderForm"; export default function Providers() { const { t } = useTranslation(); const { data, isLoading, isError } = useProviders("claude"); const mutations = useProviderMutations(); const { show } = useToast(); const [editing, setEditing] = useState<{ provider: Provider | null } | null>(null); const [lastAppliedEnv, setLastAppliedEnv] = useState | null>(null); const providers = data?.items ?? []; const submitForm = (input: ProviderSubmitInput) => { const target = editing?.provider ?? null; const onSuccess = () => { show(target ? t("providers.updated") : t("providers.created")); setEditing(null); }; const onError = (err: Error) => show(err.message, "error"); if (target) { mutations.update.mutate({ id: target.id, input }, { onSuccess, onError }); } else { mutations.create.mutate(input, { onSuccess, onError }); } }; const apply = (provider: Provider) => { mutations.apply.mutate( { id: provider.id, target: "claude" }, { onSuccess: (result) => { setLastAppliedEnv(result.env ?? null); show(`${t("providers.activated")}: ${provider.name}`); }, onError: (err: Error) => show(err.message, "error"), }, ); }; if (isLoading) return
{t("common.loading")}
; if (isError) return
{t("common.error")}
; return (

{t("providers.title")}

{editing && ( setEditing(null)} /> )} {lastAppliedEnv && ( {t("providers.appliedEnv")}
    {Object.entries(lastAppliedEnv) .filter(([key]) => key.startsWith("ANTHROPIC_")) .sort(([a], [b]) => a.localeCompare(b)) .map(([key, value]) => (
  • {key} = {value}
  • ))}
)} {providers.length === 0 ? ( {t("providers.empty")} ) : (
{providers.map((provider) => (
{provider.name} {provider.enabled_for_claude && ( {t("providers.activated")} )} {provider.preset && {provider.preset}}
{provider.base_url}
))}
)}
); }