feat(webui): add searchable provider setup panel
This commit is contained in:
1 parent
f4d863a148
commit
f01c925c3e
6 files changed
+291
-104
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { useId, useMemo, useState, type ReactNode } from "react";
|
||||
import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from "react";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Clipboard,
|
||||
Eye,
|
||||
EyeOff,
|
||||
@@ -11,6 +13,7 @@ import {
|
||||
Loader2,
|
||||
Pencil,
|
||||
Plus,
|
||||
Search,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -36,13 +39,16 @@ import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import { SheetContent } from "@/components/ui/sheet";
|
||||
import { FloatingPortalContext } from "@/components/ui/floating-portal";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { useMediaQuery } from "@/hooks/useMediaQuery";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type {
|
||||
@@ -679,6 +685,8 @@ export function ProvidersSettings({
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const [creatingCustomProvider, setCreatingCustomProvider] = useState(false);
|
||||
const [addingProvider, setAddingProvider] = useState(false);
|
||||
const [providerToAdd, setProviderToAdd] = useState<string | null>(null);
|
||||
const [customProviderKeyVisible, setCustomProviderKeyVisible] = useState(false);
|
||||
const [customProviderDraft, setCustomProviderDraft] = useState<CustomProviderDraft>(
|
||||
emptyCustomProviderDraft,
|
||||
@@ -696,6 +704,27 @@ export function ProvidersSettings({
|
||||
const selectedUnconfiguredProvider =
|
||||
unconfiguredProviders.find((provider) => provider.name === expandedProvider) ?? null;
|
||||
const customProviderSaving = providerSaving === CUSTOM_PROVIDER_CREATION_KEY;
|
||||
const selectedProviderToAdd = settings.providers.find((provider) => provider.name === providerToAdd);
|
||||
useEffect(() => {
|
||||
// Existing save/cancel actions own expandedProvider; close the add flow when they finish.
|
||||
if (addingProvider && providerToAdd && expandedProvider !== providerToAdd) {
|
||||
setAddingProvider(false);
|
||||
setProviderToAdd(null);
|
||||
}
|
||||
}, [addingProvider, providerToAdd, expandedProvider]);
|
||||
const closeAddProvider = () => {
|
||||
setAddingProvider(false);
|
||||
setProviderToAdd(null);
|
||||
setCreatingCustomProvider(false);
|
||||
setCustomProviderDraft(emptyCustomProviderDraft());
|
||||
setCustomProviderKeyVisible(false);
|
||||
if (providerToAdd && expandedProvider === providerToAdd) onToggleProvider(providerToAdd);
|
||||
};
|
||||
const backToProviderPicker = () => {
|
||||
setProviderToAdd(null);
|
||||
setCreatingCustomProvider(false);
|
||||
if (providerToAdd && expandedProvider === providerToAdd) onToggleProvider(providerToAdd);
|
||||
};
|
||||
const toggleProvider = (providerName: string) => {
|
||||
setCreatingCustomProvider(false);
|
||||
onToggleProvider(providerName);
|
||||
@@ -710,6 +739,7 @@ export function ProvidersSettings({
|
||||
setCreatingCustomProvider(false);
|
||||
setCustomProviderDraft(emptyCustomProviderDraft());
|
||||
setCustomProviderKeyVisible(false);
|
||||
setAddingProvider(false);
|
||||
};
|
||||
const saveCustomProvider = async () => {
|
||||
if (customProviderSaving) return;
|
||||
@@ -717,8 +747,8 @@ export function ProvidersSettings({
|
||||
cancelCustomProviderCreation();
|
||||
}
|
||||
};
|
||||
const renderProviderRow = (provider: SettingsPayload["providers"][number]) => {
|
||||
const expanded = expandedProvider === provider.name;
|
||||
const renderProviderRow = (provider: SettingsPayload["providers"][number], contentOnly = false) => {
|
||||
const expanded = expandedProvider === provider.name && !addingProvider;
|
||||
const form = providerForms[provider.name] ?? providerFormFromRow(provider);
|
||||
const saving = providerSaving === provider.name;
|
||||
const isOauthProvider = provider.auth_type === "oauth";
|
||||
@@ -761,36 +791,8 @@ export function ProvidersSettings({
|
||||
const supportFeature = supportName
|
||||
? (nanobotFeatures?.features ?? []).find((feature) => feature.name === supportName)
|
||||
: null;
|
||||
return (
|
||||
<Dialog key={provider.name} open={expanded} onOpenChange={(open) => {
|
||||
if (open !== expanded) toggleProvider(provider.name);
|
||||
}}>
|
||||
<DialogTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={provider.label}
|
||||
className="settings-list-row flex w-full items-center justify-between gap-4 py-2.5 text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<ProviderIcon
|
||||
provider={provider.name}
|
||||
showBrandLogos={showBrandLogos}
|
||||
/>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate text-[14px] font-medium leading-5 text-foreground">
|
||||
{provider.label}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
<span className="shrink-0 px-2 py-1 text-[13px] font-normal leading-5 text-muted-foreground">
|
||||
{t("settings.configure")}
|
||||
</span>
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
|
||||
{expanded ? (
|
||||
<DialogContent aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto">
|
||||
<DialogHeader><DialogTitle>{provider.label}</DialogTitle></DialogHeader>
|
||||
const content = (
|
||||
<>
|
||||
{supportFeature && !supportFeature.installed ? (
|
||||
<CapabilityInstallNotice
|
||||
title={tx("settings.capabilities.providerSupport", "Provider dependencies")}
|
||||
@@ -1036,15 +1038,31 @@ export function ProvidersSettings({
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</DialogContent>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
if (contentOnly) return content;
|
||||
return (
|
||||
<Dialog key={provider.name} open={expanded} onOpenChange={(open) => {
|
||||
if (open !== expanded) toggleProvider(provider.name);
|
||||
}}>
|
||||
<DialogTrigger asChild>
|
||||
<button type="button" aria-label={provider.label}
|
||||
className="settings-list-row flex w-full items-center justify-between gap-4 py-2.5 text-left transition-colors settings-hover">
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<ProviderIcon provider={provider.name} showBrandLogos={showBrandLogos} />
|
||||
<span className="truncate text-[14px] font-medium leading-5 text-foreground">{provider.label}</span>
|
||||
</span>
|
||||
<span className="shrink-0 px-2 py-1 text-[13px] font-normal leading-5 text-muted-foreground">{t("settings.configure")}</span>
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
{expanded ? <DialogContent aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto">
|
||||
<DialogHeader><DialogTitle>{provider.label}</DialogTitle></DialogHeader>
|
||||
{content}
|
||||
</DialogContent> : null}
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
const customProviderForm = creatingCustomProvider ? (
|
||||
<Dialog open onOpenChange={(open) => { if (!open) cancelCustomProviderCreation(); }}>
|
||||
<DialogContent aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto">
|
||||
<DialogHeader><DialogTitle>{tx("settings.providers.customProvider", "Custom provider")}</DialogTitle></DialogHeader>
|
||||
<div className="space-y-3">
|
||||
<label className="block space-y-1.5">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
@@ -1161,8 +1179,6 @@ export function ProvidersSettings({
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
) : null;
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -1171,17 +1187,26 @@ export function ProvidersSettings({
|
||||
{tx("settings.providers.title", "Model providers")}
|
||||
</SettingsSectionTitle>
|
||||
<SettingsGroup>
|
||||
{configuredProviders.map(renderProviderRow)}
|
||||
{selectedUnconfiguredProvider
|
||||
{configuredProviders.map((provider) => renderProviderRow(provider))}
|
||||
{selectedUnconfiguredProvider && !addingProvider
|
||||
? renderProviderRow(selectedUnconfiguredProvider)
|
||||
: null}
|
||||
{customProviderForm}
|
||||
{!expandedProvider && !creatingCustomProvider ? (
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<ProviderSetupPanel
|
||||
open={addingProvider}
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
setProviderToAdd(null);
|
||||
setAddingProvider(true);
|
||||
} else closeAddProvider();
|
||||
}}
|
||||
title={creatingCustomProvider
|
||||
? tx("settings.providers.customProvider", "Custom provider")
|
||||
: selectedProviderToAdd?.label ?? tx("settings.providers.addProvider", "Add provider")}
|
||||
onBack={creatingCustomProvider || selectedProviderToAdd ? backToProviderPicker : undefined}
|
||||
trigger={
|
||||
<button
|
||||
type="button"
|
||||
className="group settings-list-row flex w-full items-center justify-between gap-4 py-2.5 text-left transition-colors settings-hover"
|
||||
className="settings-list-row flex w-full items-center gap-3 py-2.5 text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-[9px] bg-muted text-muted-foreground">
|
||||
@@ -1189,61 +1214,153 @@ export function ProvidersSettings({
|
||||
</span>
|
||||
<span className="truncate text-[14px] font-medium text-foreground">
|
||||
{tx(
|
||||
"settings.providers.addOwnProvider",
|
||||
"Add your own model provider",
|
||||
"settings.providers.addProvider",
|
||||
"Add provider",
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
<ChevronDown
|
||||
className="h-4 w-4 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-180"
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
sideOffset={8}
|
||||
className="max-h-[24rem] w-[380px] max-w-[calc(100vw-2rem)] overflow-y-auto scrollbar-thin scrollbar-track-transparent"
|
||||
>
|
||||
<DropdownMenuItem
|
||||
onSelect={beginCustomProviderCreation}
|
||||
className="flex min-h-[54px] cursor-default items-center gap-3 px-2.5 py-2 focus:bg-muted/85 focus:text-foreground"
|
||||
>
|
||||
<ProviderIcon provider="custom" showBrandLogos={showBrandLogos} />
|
||||
<span className="truncate text-[13px] font-medium">
|
||||
{tx("settings.providers.customProvider", "Custom provider")}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
{unconfiguredProviders.length > 0 ? <DropdownMenuSeparator /> : null}
|
||||
{unconfiguredProviders.map((provider) => (
|
||||
<DropdownMenuItem
|
||||
key={provider.name}
|
||||
onSelect={() => {
|
||||
setCreatingCustomProvider(false);
|
||||
if (expandedProvider !== provider.name) {
|
||||
onToggleProvider(provider.name);
|
||||
}
|
||||
}}
|
||||
className="flex min-h-[54px] cursor-default items-center gap-3 px-2.5 py-2 focus:bg-muted/85 focus:text-foreground"
|
||||
>
|
||||
<ProviderIcon
|
||||
provider={provider.name}
|
||||
showBrandLogos={showBrandLogos}
|
||||
/>
|
||||
<span className="truncate text-[13px] font-medium">
|
||||
{provider.label}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
) : null}
|
||||
}
|
||||
>
|
||||
{creatingCustomProvider || selectedProviderToAdd ? (
|
||||
<div className="min-h-0 space-y-4 overflow-y-auto overscroll-contain px-5 pb-5">
|
||||
{creatingCustomProvider ? customProviderForm : renderProviderRow(selectedProviderToAdd!, true)}
|
||||
</div>
|
||||
) : (
|
||||
<ProviderSearchList providers={unconfiguredProviders} showBrandLogos={showBrandLogos}
|
||||
onSelect={(name) => {
|
||||
setProviderToAdd(name);
|
||||
onToggleProvider(name);
|
||||
}}
|
||||
onCustom={beginCustomProviderCreation} onClose={closeAddProvider} />
|
||||
)}
|
||||
</ProviderSetupPanel>
|
||||
</SettingsGroup>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProviderSetupPanel({ open, onOpenChange, title, trigger, onBack, children }: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: string;
|
||||
trigger: ReactNode;
|
||||
onBack?: () => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const mobile = useMediaQuery("(max-width: 639px)");
|
||||
const [container, setContainer] = useState<HTMLDivElement | null>(null);
|
||||
const configuring = Boolean(onBack);
|
||||
useEffect(() => {
|
||||
if (configuring) container?.focus({ preventScroll: true });
|
||||
}, [configuring, container]);
|
||||
const content = <>
|
||||
<div className="flex h-16 shrink-0 items-center gap-2 px-5 pr-12">
|
||||
{onBack ? <Button type="button" variant="ghost" size="icon" onClick={onBack}
|
||||
aria-label={t("settings.providers.backToProviders", { defaultValue: "Back to providers" })}
|
||||
className="-ml-2 h-9 w-9 shrink-0 rounded-full">
|
||||
<ChevronLeft className="h-4 w-4" aria-hidden />
|
||||
</Button> : null}
|
||||
<DialogTitle className="truncate text-base font-semibold">{title}</DialogTitle>
|
||||
</div>
|
||||
{children}
|
||||
</>;
|
||||
const focusOnOpen = (event: Event) => {
|
||||
event.preventDefault();
|
||||
const target = !mobile ? container?.querySelector<HTMLInputElement>("input") : null;
|
||||
(target ?? container)?.focus({ preventScroll: true });
|
||||
};
|
||||
return <Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogTrigger asChild>{trigger}</DialogTrigger>
|
||||
{mobile ? <SheetContent side="bottom" ref={setContainer} aria-describedby={undefined}
|
||||
onOpenAutoFocus={focusOnOpen}
|
||||
className="mx-auto h-[min(36rem,85dvh)] max-w-md gap-0 overflow-hidden rounded-t-3xl pb-[env(safe-area-inset-bottom)] outline-none"
|
||||
closeButtonClassName="grid h-9 w-9 place-items-center right-3 top-3 rounded-full">
|
||||
<FloatingPortalContext.Provider value={container}>{content}</FloatingPortalContext.Provider>
|
||||
</SheetContent> : <DialogContent ref={setContainer} aria-describedby={undefined}
|
||||
onOpenAutoFocus={focusOnOpen}
|
||||
className="flex h-[min(32rem,85dvh)] w-[min(28rem,calc(100vw-2rem))] max-w-none flex-col gap-0 overflow-hidden p-0">
|
||||
{content}
|
||||
</DialogContent>}
|
||||
</Dialog>;
|
||||
}
|
||||
|
||||
const PROVIDER_SEARCH_ALIASES: Record<string, string> = {
|
||||
anthropic: "claude 克劳德 克勞德",
|
||||
deepseek: "深度求索 深度探索",
|
||||
zhipu: "智谱 智譜 glm z.ai",
|
||||
dashscope: "阿里 通义 通義 千问 千問 qwen",
|
||||
moonshot: "月之暗面 kimi",
|
||||
kimi_coding: "月之暗面 kimi coding",
|
||||
volcengine: "火山引擎 豆包 doubao",
|
||||
volcengine_coding_plan: "火山引擎 豆包 doubao",
|
||||
minimax: "海螺 稀宇",
|
||||
minimax_anthropic: "海螺 稀宇",
|
||||
siliconflow: "硅基流动 矽基流動 硅基流動",
|
||||
stepfun: "阶跃星辰 階躍星辰",
|
||||
xiaomi_mimo: "小米 mimo",
|
||||
longcat: "美团 美團",
|
||||
qianfan: "百度 千帆 文心",
|
||||
ant_ling: "蚂蚁 螞蟻 百灵 百靈",
|
||||
};
|
||||
|
||||
function ProviderSearchList({ providers, showBrandLogos, onSelect, onCustom, onClose }: {
|
||||
providers: SettingsPayload["providers"];
|
||||
showBrandLogos: boolean;
|
||||
onSelect: (name: string) => void;
|
||||
onCustom: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [query, setQuery] = useState("");
|
||||
const mobile = useMediaQuery("(max-width: 639px)");
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => {
|
||||
if (!mobile) inputRef.current?.focus({ preventScroll: true });
|
||||
}, [mobile]);
|
||||
const filtered = useMemo(() => {
|
||||
const normalize = (value: string) => value.toLocaleLowerCase().replace(/[\s_.-]+/g, "");
|
||||
return providers.filter((provider) => normalize(
|
||||
`${provider.name} ${provider.label} ${PROVIDER_SEARCH_ALIASES[provider.name] ?? ""}`,
|
||||
).includes(normalize(query)));
|
||||
}, [providers, query]);
|
||||
const values = useMemo(() => filtered.map((provider) => provider.name), [filtered]);
|
||||
const { inputProps, listProps, getOptionProps } = useComboboxNavigation({
|
||||
open: true, values, onSelect, onClose,
|
||||
});
|
||||
const searchLabel = t("settings.providers.searchPlaceholder", { defaultValue: "Search providers" });
|
||||
return <>
|
||||
<div className="relative mx-5 mb-3 shrink-0">
|
||||
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
|
||||
<Input {...inputProps} ref={inputRef} value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
aria-label={searchLabel} placeholder={searchLabel}
|
||||
className="h-10 rounded-xl border-0 bg-muted/60 pl-9 text-sm shadow-none focus-visible:ring-1" />
|
||||
</div>
|
||||
<div {...listProps} aria-label={searchLabel}
|
||||
className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 pb-3 scrollbar-thin scrollbar-track-transparent">
|
||||
{filtered.map((provider) => <ComboboxOption key={provider.name} {...getOptionProps(provider.name)}
|
||||
aria-label={provider.label} className="min-h-11 gap-3 rounded-xl px-3 py-2 text-sm font-normal">
|
||||
<ProviderIcon provider={provider.name} showBrandLogos={showBrandLogos} compact />
|
||||
<span className="min-w-0 flex-1 truncate">{provider.label}</span>
|
||||
<ChevronRight className="h-3.5 w-3.5 shrink-0 text-muted-foreground/50" aria-hidden />
|
||||
</ComboboxOption>)}
|
||||
{filtered.length === 0 ? <p role="status" className="px-3 py-12 text-center text-sm text-muted-foreground">
|
||||
{t("settings.providers.noMatches", { defaultValue: "No matching providers." })}
|
||||
</p> : null}
|
||||
</div>
|
||||
<div className="shrink-0 border-t border-border/50 p-3">
|
||||
<button type="button" onClick={onCustom}
|
||||
className="flex min-h-11 w-full items-center gap-3 rounded-xl px-3 text-left text-sm settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<Plus className="h-6 w-6 shrink-0 p-0.5 text-muted-foreground" aria-hidden />
|
||||
<span className="flex-1">{t("settings.providers.customProvider", { defaultValue: "Custom provider" })}</span>
|
||||
<ChevronRight className="h-3.5 w-3.5 text-muted-foreground/50" aria-hidden />
|
||||
</button>
|
||||
</div>
|
||||
</>;
|
||||
}
|
||||
|
||||
function orderUnconfiguredProviders(
|
||||
providers: SettingsPayload["providers"],
|
||||
): SettingsPayload["providers"] {
|
||||
@@ -1266,9 +1383,11 @@ function providerVisibilityRank(provider: SettingsPayload["providers"][number]):
|
||||
export function ProviderIcon({
|
||||
provider,
|
||||
showBrandLogos,
|
||||
compact = false,
|
||||
}: {
|
||||
provider: string;
|
||||
showBrandLogos: boolean;
|
||||
compact?: boolean;
|
||||
}) {
|
||||
const brand = providerBrand(provider);
|
||||
const Icon = PROVIDER_ICONS[provider] ?? Hexagon;
|
||||
@@ -1281,7 +1400,8 @@ export function ProviderIcon({
|
||||
<span
|
||||
data-testid={`provider-logo-${provider}`}
|
||||
className={cn(
|
||||
"relative grid h-8 w-8 shrink-0 place-items-center overflow-hidden rounded-[9px] text-[11px] font-semibold text-muted-foreground",
|
||||
"relative grid shrink-0 place-items-center overflow-hidden font-semibold text-muted-foreground",
|
||||
compact ? "h-6 w-6 rounded-[7px] text-[9px]" : "h-8 w-8 rounded-[9px] text-[11px]",
|
||||
showLoadedLogo ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted",
|
||||
)}
|
||||
aria-hidden
|
||||
@@ -1306,7 +1426,7 @@ export function ProviderIcon({
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"absolute object-contain transition-opacity duration-150 motion-reduce:transition-none",
|
||||
isLogoTile ? "h-8 w-8" : "h-6 w-6",
|
||||
isLogoTile ? (compact ? "h-6 w-6" : "h-8 w-8") : compact ? "h-[18px] w-[18px]" : "h-6 w-6",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
onLoad={onLogoLoad}
|
||||
|
||||
@@ -880,6 +880,8 @@
|
||||
"searchPlaceholder": "Search providers",
|
||||
"noMatches": "No providers match this search.",
|
||||
"addOwnProvider": "Add your own model provider",
|
||||
"addProvider": "Add provider",
|
||||
"backToProviders": "Back to providers",
|
||||
"customProvider": "Custom provider",
|
||||
"customProviderName": "Provider name",
|
||||
"customProviderNamePlaceholder": "My model provider",
|
||||
|
||||
@@ -880,6 +880,8 @@
|
||||
"searchPlaceholder": "搜索提供商",
|
||||
"noMatches": "没有匹配的提供商。",
|
||||
"addOwnProvider": "添加自定义提供商",
|
||||
"addProvider": "添加提供商",
|
||||
"backToProviders": "返回提供商列表",
|
||||
"customProvider": "自定义提供商",
|
||||
"customProviderName": "提供商名称",
|
||||
"customProviderNamePlaceholder": "例如:公司模型网关",
|
||||
|
||||
@@ -472,6 +472,8 @@
|
||||
"searchPlaceholder": "搜尋供應商",
|
||||
"noMatches": "沒有符合的供應商。",
|
||||
"addOwnProvider": "新增自己的模型供應商",
|
||||
"addProvider": "新增供應商",
|
||||
"backToProviders": "返回供應商列表",
|
||||
"customProvider": "自訂供應商",
|
||||
"customProviderName": "供應商名稱",
|
||||
"customProviderNamePlaceholder": "例如:公司模型閘道",
|
||||
|
||||
@@ -619,7 +619,7 @@ describe("App layout", () => {
|
||||
await screen.findByRole("navigation", { name: "Settings sections" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("Model providers")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Add your own model provider" }))
|
||||
expect(screen.getByRole("button", { name: "Add provider" }))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.queryByRole("dialog", { name: "Choose your AI" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -6,15 +6,76 @@ import { requestMutationMock, jsonResponse, settingsPayload, renderSettingsView,
|
||||
|
||||
|
||||
async function chooseProviderToConfigure(label: string) {
|
||||
fireEvent.pointerDown(
|
||||
await screen.findByRole("button", { name: "Add your own model provider" }),
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: "Add provider" }),
|
||||
);
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: label }));
|
||||
fireEvent.click(await screen.findByRole("option", { name: label }));
|
||||
}
|
||||
|
||||
describe("Settings providers", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it("searches provider aliases and configures in the same dialog without adding an unsaved row", async () => {
|
||||
const user = userEvent.setup();
|
||||
const payload = settingsPayload();
|
||||
payload.providers = [
|
||||
{ name: "deepseek", label: "DeepSeek", configured: true },
|
||||
{ name: "volcengine", label: "VolcEngine", configured: false },
|
||||
{ name: "volcengine_coding_plan", label: "VolcEngine Coding Plan", configured: false },
|
||||
];
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload });
|
||||
const trigger = screen.getByRole("button", { name: "Add provider" });
|
||||
await user.click(trigger);
|
||||
const dialog = screen.getByRole("dialog", { name: "Add provider" });
|
||||
const search = within(dialog).getByRole("combobox", { name: "Search providers" });
|
||||
await waitFor(() => expect(search).toHaveFocus());
|
||||
expect(within(dialog).queryByRole("option", { name: "DeepSeek" })).not.toBeInTheDocument();
|
||||
await user.type(search, "火山");
|
||||
expect(within(dialog).getAllByRole("option")).toHaveLength(2);
|
||||
await user.keyboard("{ArrowDown}{Enter}");
|
||||
expect(screen.getByRole("dialog", { name: "VolcEngine Coding Plan" })).toBe(dialog);
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
expect(within(dialog).getByLabelText("API key", { selector: "input" })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "VolcEngine Coding Plan" })).not.toBeInTheDocument();
|
||||
await user.click(within(dialog).getByRole("button", { name: "Back to providers" }));
|
||||
expect(screen.getByRole("dialog", { name: "Add provider" })).toBe(dialog);
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(trigger).toHaveFocus();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps custom provider creation available for empty searches and discards cancelled drafts", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
await user.type(screen.getByRole("combobox"), "does-not-exist");
|
||||
expect(screen.getByRole("status")).toHaveTextContent("No providers match this search.");
|
||||
await user.click(screen.getByRole("button", { name: "Custom provider", exact: true }));
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
await user.type(screen.getByPlaceholderText("My model provider"), "Unsaved gateway");
|
||||
await user.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
await user.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
expect(screen.getByRole("combobox")).toHaveValue("");
|
||||
await user.click(screen.getByRole("button", { name: "Custom provider", exact: true }));
|
||||
expect(screen.getByPlaceholderText("My model provider")).toHaveValue("");
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses a bottom sheet on mobile without opening the keyboard immediately", async () => {
|
||||
vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
|
||||
matches: query === "(max-width: 639px)", media: query,
|
||||
addEventListener: vi.fn(), removeEventListener: vi.fn(),
|
||||
})));
|
||||
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add provider" }));
|
||||
const dialog = screen.getByRole("dialog", { name: "Add provider" });
|
||||
expect(dialog).toHaveClass("rounded-t-3xl", "bottom-0");
|
||||
expect(screen.getByRole("combobox")).not.toHaveFocus();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Custom provider", exact: true }));
|
||||
expect(screen.getByRole("dialog", { name: "Custom provider" })).toBe(dialog);
|
||||
});
|
||||
|
||||
it("keeps provider labels and keyboard configuration accessible with decorative logos", async () => {
|
||||
const user = userEvent.setup();
|
||||
const payload: SettingsPayload = {
|
||||
@@ -806,11 +867,11 @@ describe("Settings providers", () => {
|
||||
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload });
|
||||
|
||||
fireEvent.pointerDown(
|
||||
screen.getByRole("button", { name: "Add your own model provider" }),
|
||||
fireEvent.click(
|
||||
screen.getByRole("button", { name: "Add provider" }),
|
||||
);
|
||||
const customOption = await screen.findByRole("menuitem", { name: "Custom provider" });
|
||||
const openRouterOption = screen.getByRole("menuitem", { name: "OpenRouter" });
|
||||
const customOption = await screen.findByRole("button", { name: "Custom provider" });
|
||||
const openRouterOption = screen.getByRole("option", { name: "OpenRouter" });
|
||||
expect(customOption.querySelector("svg, img")).not.toBeNull();
|
||||
expect(openRouterOption.querySelector("svg, img")).not.toBeNull();
|
||||
fireEvent.click(customOption);
|
||||
@@ -864,7 +925,7 @@ describe("Settings providers", () => {
|
||||
await screen.findByRole("button", { name: /Company Gateway/ }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Add your own model provider" }),
|
||||
screen.getByRole("button", { name: "Add provider" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user