import { useState } from 'react'; import { useAssistantStore, getLlmConfig } from '@/stores/assistantStore'; import { testConnection } from '@/lib/llm/client'; import type { LlmProvider } from '@/lib/llm/types'; import { Input, Select, Field } from '@/components/ui/Input'; import { Button } from '@/components/ui/Button'; import { cn } from '@/lib/cn'; const PROVIDER_DEFAULTS: Record = { anthropic: { baseUrl: 'https://api.anthropic.com', model: 'claude-opus-4-8', keyLabel: 'API key (x-api-key)' }, 'openai-compatible': { baseUrl: 'https://api.openai.com/v1', model: 'gpt-4o', keyLabel: 'API key (Bearer token)' }, }; export function AssistantSettings() { const cfg = useAssistantStore(); const setConfig = useAssistantStore((s) => s.setConfig); const [status, setStatus] = useState<{ ok: boolean; text: string } | null>(null); const [testing, setTesting] = useState(false); const onProvider = (provider: LlmProvider) => { const d = PROVIDER_DEFAULTS[provider]; // Swap base URL/model to the new provider's defaults only if the current values // are still a known default (don't clobber a custom endpoint the user typed). const knownUrls = Object.values(PROVIDER_DEFAULTS).map((p) => p.baseUrl); const knownModels = Object.values(PROVIDER_DEFAULTS).map((p) => p.model); setConfig({ provider, ...(knownUrls.includes(cfg.baseUrl) || !cfg.baseUrl ? { baseUrl: d.baseUrl } : {}), ...(knownModels.includes(cfg.model) || !cfg.model ? { model: d.model } : {}), }); }; const runTest = async () => { setTesting(true); setStatus(null); const res = await testConnection(getLlmConfig()); setStatus(res.ok ? { ok: true, text: 'Connection successful.' } : { ok: false, text: res.message }); setTesting(false); }; return (

Assistant (AI)

Optional. Bring your own provider and key to enable AI-grounded tips (encounter balancing, level-up routes). The assistant always works without this — it falls back to deterministic suggestions. Your key is stored only in this browser and is never included in backups.

setConfig({ model: e.target.value })} placeholder="model id" aria-label="Model" /> setConfig({ baseUrl: e.target.value })} placeholder="https://…" aria-label="Base URL" /> setConfig({ apiKey: e.target.value })} placeholder="sk-…" autoComplete="off" aria-label="API key" />
{status && ( {status.text} )}
); }