import { useMemo, useCallback } from "preact/hooks"; import { useT } from "../../../shared/i18n/context"; import { CopyButton } from "./CopyButton"; interface AnthropicSetupProps { apiKey: string; selectedModel: string; reasoningEffort: string; serviceTier: string | null; } export function AnthropicSetup({ apiKey, selectedModel, reasoningEffort, serviceTier }: AnthropicSetupProps) { const t = useT(); const origin = typeof window !== "undefined" ? window.location.origin : "http://localhost:8080"; // Build compound model name with suffixes const displayModel = useMemo(() => { let name = selectedModel; if (reasoningEffort && reasoningEffort !== "medium") name += `-${reasoningEffort}`; if (serviceTier === "fast") name += "-fast"; return name; }, [selectedModel, reasoningEffort, serviceTier]); const envLines = useMemo(() => ({ ANTHROPIC_BASE_URL: origin, ANTHROPIC_API_KEY: apiKey, ANTHROPIC_MODEL: displayModel, }), [origin, apiKey, displayModel]); const allEnvText = useMemo( () => Object.entries(envLines).map(([k, v]) => `${k}=${v}`).join("\n"), [envLines], ); const getAllEnv = useCallback(() => allEnvText, [allEnvText]); const getBaseUrl = useCallback(() => envLines.ANTHROPIC_BASE_URL, [envLines]); const getApiKey = useCallback(() => envLines.ANTHROPIC_API_KEY, [envLines]); const getModel = useCallback(() => envLines.ANTHROPIC_MODEL, [envLines]); return (

{t("anthropicSetup")}

{/* Env vars */}
{(["ANTHROPIC_BASE_URL", "ANTHROPIC_API_KEY", "ANTHROPIC_MODEL"] as const).map((key) => { const getter = key === "ANTHROPIC_BASE_URL" ? getBaseUrl : key === "ANTHROPIC_API_KEY" ? getApiKey : getModel; return (
); })}
{/* Copy all button */}
{t("anthropicCopyAllHint")}
); }