AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
Collapse AI model settings by default
tianma-ifccc03d756327
diff --git a/apps/web/src/components/settings/AiModelCard.tsx b/apps/web/src/components/settings/AiModelCard.tsxindex b5ac1edb..aec85e77 100644--- a/apps/web/src/components/settings/AiModelCard.tsx+++ b/apps/web/src/components/settings/AiModelCard.tsx@@ -1,14 +1,16 @@import { useEffect, useState, type FormEvent, type ReactNode } from "react";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import type { AiProvider } from "@edgeever/shared";-import { CheckCircle2, Loader2, Sparkles, TriangleAlert } from "lucide-react";+import { CheckCircle2, ChevronDown, Loader2, Sparkles, TriangleAlert } from "lucide-react";import { useTranslation } from "react-i18next";import { Button } from "@/components/ui/button";import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";+import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";import { Input } from "@/components/ui/input";import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";import { Switch } from "@/components/ui/switch";import { ApiRequestError, api } from "@/lib/api";+import { cn } from "@/lib/utils";const providerDefaults: Record<AiProvider, { displayName: string; baseUrl: string; modelId: string }> = {"openai-compatible": { displayName: "OpenAI-compatible", baseUrl: "https://api.openai.com/v1", modelId: "gpt-4.1-mini" },@@ -26,6 +28,7 @@ export const AiModelCard = ({ demoMode }: { demoMode: boolean }) => {const [modelId, setModelId] = useState(providerDefaults["openai-compatible"].modelId);const [apiKey, setApiKey] = useState("");const [isEnabled, setIsEnabled] = useState(true);+ const [expanded, setExpanded] = useState(false);useEffect(() => {const settings = settingsQuery.data?.settings;@@ -79,55 +82,66 @@ export const AiModelCard = ({ demoMode }: { demoMode: boolean }) => {};return (- <Card className="w-full min-w-0 overflow-hidden shadow-none">- <CardHeader className="p-4 sm:p-5">- <CardTitle className="flex items-center gap-2 text-sm"><Sparkles className="h-4 w-4 text-emerald-700" />{t("aiModel.title")}</CardTitle>- <CardDescription>{t("aiModel.description")}</CardDescription>- </CardHeader>- <CardContent className="p-4 pt-0 sm:px-5 sm:pb-5">- {settingsQuery.isLoading ? (- <p className="flex items-center gap-2 text-sm text-slate-500"><Loader2 className="h-4 w-4 animate-spin" />{t("common.loading")}</p>- ) : (- <form className="grid gap-4" onSubmit={submit}>- {!encryptionConfigured ? (- <p className="flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 p-3 text-xs leading-5 text-amber-800">- <TriangleAlert className="mt-0.5 h-4 w-4 shrink-0" />{t("aiModel.encryptionKeyMissing")}- </p>- ) : null}- <div className="grid gap-4 sm:grid-cols-2">- <Field label={t("aiModel.provider")}>- <Select value={provider} onValueChange={(value) => handleProviderChange(value as AiProvider)}>- <SelectTrigger><SelectValue /></SelectTrigger>- <SelectContent>- <SelectItem value="openai-compatible">{t("aiModel.providers.openai-compatible")}</SelectItem>- <SelectItem value="anthropic">{t("aiModel.providers.anthropic")}</SelectItem>- <SelectItem value="google">{t("aiModel.providers.google")}</SelectItem>- </SelectContent>- </Select>- </Field>- <Field label={t("aiModel.displayName")}><Input value={displayName} onChange={(event) => setDisplayName(event.target.value)} required maxLength={80} /></Field>- <Field label={t("aiModel.baseUrl")}><Input value={baseUrl} onChange={(event) => setBaseUrl(event.target.value)} required inputMode="url" /></Field>- <Field label={t("aiModel.modelId")}><Input value={modelId} onChange={(event) => setModelId(event.target.value)} required /></Field>- <Field label={t("aiModel.apiKey")} hint={hasSavedKey ? t("aiModel.apiKeySavedHint") : undefined}>- <Input type="password" value={apiKey} onChange={(event) => setApiKey(event.target.value)} required={!hasSavedKey} autoComplete="new-password" placeholder={hasSavedKey ? "••••••••••••" : ""} />- </Field>- <label className="flex items-center justify-between gap-3 rounded-lg border border-slate-200 bg-white px-3 py-2.5 text-sm font-medium text-slate-700">- <span><span className="block">{t("aiModel.enabled")}</span><span className="mt-0.5 block text-xs font-normal text-slate-500">{t("aiModel.enabledHint")}</span></span>- <Switch checked={isEnabled} onCheckedChange={setIsEnabled} />- </label>- </div>- {testMutation.isSuccess ? <p className="flex items-center gap-1.5 text-xs font-medium text-emerald-700"><CheckCircle2 className="h-4 w-4" />{t("aiModel.testSucceeded")}</p> : null}- {saveMutation.isSuccess ? <p className="flex items-center gap-1.5 text-xs font-medium text-emerald-700"><CheckCircle2 className="h-4 w-4" />{t("aiModel.saved")}</p> : null}- {testMutation.isError ? <p className="text-xs font-medium text-rose-600" role="alert">{errorMessage(testMutation.error)}</p> : null}- {saveMutation.isError ? <p className="text-xs font-medium text-rose-600" role="alert">{errorMessage(saveMutation.error)}</p> : null}- <div className="flex flex-wrap justify-end gap-2">- <Button type="button" variant="outline" disabled={testMutation.isPending || saveMutation.isPending || (!apiKey && !hasSavedKey)} onClick={() => testMutation.mutate()}>{testMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("aiModel.test")}</Button>- <Button type="submit" disabled={demoMode || saveMutation.isPending || !encryptionConfigured || (!apiKey && !hasSavedKey)}>{saveMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("common.save")}</Button>- </div>- </form>- )}- </CardContent>- </Card>+ <Collapsible open={expanded} onOpenChange={setExpanded} asChild>+ <Card className="w-full min-w-0 overflow-hidden shadow-none">+ <CardHeader className="p-4 sm:p-5">+ <CollapsibleTrigger asChild>+ <button className="flex w-full min-w-0 items-start justify-between gap-3 text-left" type="button">+ <span className="min-w-0">+ <CardTitle className="flex items-center gap-2 text-sm"><Sparkles className="h-4 w-4 text-emerald-700" />{t("aiModel.title")}</CardTitle>+ <CardDescription className="mt-1">{t("aiModel.description")}</CardDescription>+ </span>+ <ChevronDown className={cn("mt-0.5 h-4 w-4 shrink-0 text-slate-400 transition-transform", expanded ? "rotate-180" : "rotate-0")} />+ </button>+ </CollapsibleTrigger>+ </CardHeader>+ <CollapsibleContent asChild>+ <CardContent className="p-4 pt-0 sm:px-5 sm:pb-5">+ {settingsQuery.isLoading ? (+ <p className="flex items-center gap-2 text-sm text-slate-500"><Loader2 className="h-4 w-4 animate-spin" />{t("common.loading")}</p>+ ) : (+ <form className="grid gap-4" onSubmit={submit}>+ {!encryptionConfigured ? (+ <p className="flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 p-3 text-xs leading-5 text-amber-800">+ <TriangleAlert className="mt-0.5 h-4 w-4 shrink-0" />{t("aiModel.encryptionKeyMissing")}+ </p>+ ) : null}+ <div className="grid gap-4 sm:grid-cols-2">+ <Field label={t("aiModel.provider")}>+ <Select value={provider} onValueChange={(value) => handleProviderChange(value as AiProvider)}>+ <SelectTrigger><SelectValue /></SelectTrigger>+ <SelectContent>+ <SelectItem value="openai-compatible">{t("aiModel.providers.openai-compatible")}</SelectItem>+ <SelectItem value="anthropic">{t("aiModel.providers.anthropic")}</SelectItem>+ <SelectItem value="google">{t("aiModel.providers.google")}</SelectItem>+ </SelectContent>+ </Select>+ </Field>+ <Field label={t("aiModel.displayName")}><Input value={displayName} onChange={(event) => setDisplayName(event.target.value)} required maxLength={80} /></Field>+ <Field label={t("aiModel.baseUrl")}><Input value={baseUrl} onChange={(event) => setBaseUrl(event.target.value)} required inputMode="url" /></Field>+ <Field label={t("aiModel.modelId")}><Input value={modelId} onChange={(event) => setModelId(event.target.value)} required /></Field>+ <Field label={t("aiModel.apiKey")} hint={hasSavedKey ? t("aiModel.apiKeySavedHint") : undefined}>+ <Input type="password" value={apiKey} onChange={(event) => setApiKey(event.target.value)} required={!hasSavedKey} autoComplete="new-password" placeholder={hasSavedKey ? "••••••••••••" : ""} />+ </Field>+ <label className="flex items-center justify-between gap-3 rounded-lg border border-slate-200 bg-white px-3 py-2.5 text-sm font-medium text-slate-700">+ <span><span className="block">{t("aiModel.enabled")}</span><span className="mt-0.5 block text-xs font-normal text-slate-500">{t("aiModel.enabledHint")}</span></span>+ <Switch checked={isEnabled} onCheckedChange={setIsEnabled} />+ </label>+ </div>+ {testMutation.isSuccess ? <p className="flex items-center gap-1.5 text-xs font-medium text-emerald-700"><CheckCircle2 className="h-4 w-4" />{t("aiModel.testSucceeded")}</p> : null}+ {saveMutation.isSuccess ? <p className="flex items-center gap-1.5 text-xs font-medium text-emerald-700"><CheckCircle2 className="h-4 w-4" />{t("aiModel.saved")}</p> : null}+ {testMutation.isError ? <p className="text-xs font-medium text-rose-600" role="alert">{errorMessage(testMutation.error)}</p> : null}+ {saveMutation.isError ? <p className="text-xs font-medium text-rose-600" role="alert">{errorMessage(saveMutation.error)}</p> : null}+ <div className="flex flex-wrap justify-end gap-2">+ <Button type="button" variant="outline" disabled={testMutation.isPending || saveMutation.isPending || (!apiKey && !hasSavedKey)} onClick={() => testMutation.mutate()}>{testMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("aiModel.test")}</Button>+ <Button type="submit" disabled={demoMode || saveMutation.isPending || !encryptionConfigured || (!apiKey && !hasSavedKey)}>{saveMutation.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null}{t("common.save")}</Button>+ </div>+ </form>+ )}+ </CardContent>+ </CollapsibleContent>+ </Card>+ </Collapsible>);};