2026-09-20 15:42:17 +08:00
|
|
|
|
import { useEffect, useId, useMemo, useRef, useState, type ComponentProps } from "react";
|
2026-08-10 19:33:52 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Check,
|
|
|
|
|
|
CircleAlert,
|
|
|
|
|
|
Hexagon,
|
|
|
|
|
|
Pencil,
|
2026-10-11 04:30:43 +08:00
|
|
|
|
Plus,
|
2026-08-10 19:33:52 +08:00
|
|
|
|
} from "lucide-react";
|
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
|
2026-10-11 04:30:43 +08:00
|
|
|
|
import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus";
|
2026-08-10 19:33:52 +08:00
|
|
|
|
import { Button } from "@/components/ui/button";
|
2026-10-09 17:05:10 +08:00
|
|
|
|
import { ControlChevron } from "@/components/ui/control-chevron";
|
2026-08-10 19:33:52 +08:00
|
|
|
|
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
2026-10-11 04:30:43 +08:00
|
|
|
|
import { Select, SelectContent, SelectItem, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
|
|
|
|
import { SearchInput } from "@/components/ui/input";
|
|
|
|
|
|
import { Popover, PopoverAnchor, PopoverContent } from "@/components/ui/popover";
|
2026-08-10 19:33:52 +08:00
|
|
|
|
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
2026-10-11 04:30:43 +08:00
|
|
|
|
import { useProviderModelCatalog } from "@/hooks/useProviderModelCatalog";
|
|
|
|
|
|
import { formatContextWindow } from "@/lib/model-context-format";
|
2026-08-10 19:33:52 +08:00
|
|
|
|
import { providerBrand } from "@/lib/provider-brand";
|
2026-10-11 04:30:43 +08:00
|
|
|
|
import { PROVIDER_ICONS } from "@/lib/provider-icons";
|
2026-08-10 19:33:52 +08:00
|
|
|
|
import type { ProviderModelsPayload, SettingsPayload } from "@/lib/types";
|
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
2026-10-11 04:30:43 +08:00
|
|
|
|
export { formatContextWindow, formatModelContextWindow } from "@/lib/model-context-format";
|
|
|
|
|
|
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const DEFERRED_MODEL_LIST_PROVIDERS = new Set([
|
|
|
|
|
|
"aihubmix",
|
|
|
|
|
|
"atomic_chat",
|
|
|
|
|
|
"byteplus",
|
|
|
|
|
|
"byteplus_coding_plan",
|
|
|
|
|
|
"huggingface",
|
|
|
|
|
|
"lm_studio",
|
|
|
|
|
|
"modelscope",
|
|
|
|
|
|
"novita",
|
|
|
|
|
|
"ollama",
|
|
|
|
|
|
"openrouter",
|
2026-08-11 06:09:52 +08:00
|
|
|
|
"orcarouter",
|
2026-08-10 19:33:52 +08:00
|
|
|
|
"ovms",
|
|
|
|
|
|
"siliconflow",
|
|
|
|
|
|
"vllm",
|
|
|
|
|
|
"volcengine",
|
|
|
|
|
|
"volcengine_coding_plan",
|
|
|
|
|
|
]);
|
|
|
|
|
|
const DEFERRED_MODEL_LIST_QUERY_MIN_LENGTH = 2;
|
|
|
|
|
|
|
|
|
|
|
|
export function normalizeContextWindowTokens(value: number | null | undefined): number {
|
|
|
|
|
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 200_000;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-24 18:26:03 +08:00
|
|
|
|
export function parseContextWindowTokens(value: string): number {
|
|
|
|
|
|
const match = /^(\d+(?:\.\d+)?)\s*([km]?)$/i.exec(value.trim());
|
|
|
|
|
|
if (!match) return NaN;
|
|
|
|
|
|
const exponent = { k: 3, m: 6 }[match[2].toLowerCase()] ?? 0;
|
|
|
|
|
|
const tokens = Number(`${match[1]}e${exponent}`);
|
|
|
|
|
|
return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : NaN;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function formatContextWindowInput(tokens: number): string {
|
|
|
|
|
|
if (!Number.isFinite(tokens)) return "";
|
|
|
|
|
|
if (tokens % 1_000_000 === 0) return `${tokens / 1_000_000}m`;
|
|
|
|
|
|
if (tokens % 1_000 === 0) return `${tokens / 1_000}k`;
|
|
|
|
|
|
return String(tokens);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-10 19:33:52 +08:00
|
|
|
|
function settingsProviderRow(
|
|
|
|
|
|
payload: SettingsPayload,
|
|
|
|
|
|
provider: string | null | undefined,
|
|
|
|
|
|
): SettingsPayload["providers"][number] | null {
|
|
|
|
|
|
if (!provider) return null;
|
|
|
|
|
|
return payload.providers.find((row) => row.name === provider) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function settingsProviderConfigured(
|
|
|
|
|
|
payload: SettingsPayload,
|
|
|
|
|
|
provider: string | null | undefined,
|
|
|
|
|
|
resolvedProvider?: string | null,
|
|
|
|
|
|
): boolean {
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const concreteProvider = provider === "auto"
|
|
|
|
|
|
? resolvedProvider ?? payload.agent.resolved_provider ?? payload.agent.provider
|
|
|
|
|
|
: provider;
|
|
|
|
|
|
return settingsProviderRow(payload, concreteProvider)?.configured ?? false;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function ProviderPicker({
|
|
|
|
|
|
providers,
|
|
|
|
|
|
value,
|
2026-09-10 11:10:51 +08:00
|
|
|
|
triggerProps,
|
2026-08-10 19:33:52 +08:00
|
|
|
|
emptyLabel,
|
|
|
|
|
|
showProviderLogos = false,
|
|
|
|
|
|
onChange,
|
2026-10-11 04:30:43 +08:00
|
|
|
|
onAddProvider,
|
|
|
|
|
|
onConfigureProvider,
|
2026-08-10 19:33:52 +08:00
|
|
|
|
}: {
|
|
|
|
|
|
providers: Array<{ name: string; label: string }>;
|
|
|
|
|
|
value: string;
|
2026-09-10 11:10:51 +08:00
|
|
|
|
triggerProps?: Pick<ComponentProps<typeof Button>, "id" | "aria-label" | "aria-describedby" | "aria-invalid" | "disabled">;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
emptyLabel: string;
|
|
|
|
|
|
showProviderLogos?: boolean;
|
|
|
|
|
|
onChange: (provider: string) => void;
|
2026-10-11 04:30:43 +08:00
|
|
|
|
onAddProvider?: (trigger: HTMLButtonElement | null) => void;
|
|
|
|
|
|
onConfigureProvider?: (provider: string, trigger: HTMLButtonElement | null) => void;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
}) {
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
|
|
|
|
const openingProviderSetup = useRef(false);
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const selectedProvider = providers.find((provider) => provider.name === value) ?? null;
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const disabled = !!triggerProps?.disabled || (providers.length === 0 && !onAddProvider);
|
2026-08-10 19:33:52 +08:00
|
|
|
|
|
|
|
|
|
|
return (
|
2026-10-11 04:30:43 +08:00
|
|
|
|
<Select value={value} onValueChange={(provider) => {
|
|
|
|
|
|
if (provider === ":add-provider") {
|
|
|
|
|
|
openingProviderSetup.current = true;
|
|
|
|
|
|
onAddProvider?.(triggerRef.current);
|
|
|
|
|
|
} else if (provider === ":configure-provider") {
|
|
|
|
|
|
openingProviderSetup.current = true;
|
|
|
|
|
|
onConfigureProvider?.(value, triggerRef.current);
|
|
|
|
|
|
} else onChange(provider);
|
|
|
|
|
|
}} disabled={disabled}>
|
2026-09-10 11:10:51 +08:00
|
|
|
|
<SelectTrigger
|
2026-10-11 04:30:43 +08:00
|
|
|
|
ref={triggerRef}
|
2026-09-10 11:10:51 +08:00
|
|
|
|
{...triggerProps}
|
|
|
|
|
|
aria-label={triggerProps?.["aria-label"] ?? selectedProvider?.label ?? emptyLabel}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
type="button"
|
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
|
className={cn(
|
2026-10-09 17:05:10 +08:00
|
|
|
|
"w-full justify-between rounded-full border-input bg-background text-[13px] font-normal shadow-none",
|
2026-09-10 11:10:51 +08:00
|
|
|
|
"settings-hover focus-visible:ring-2 focus-visible:ring-ring",
|
2026-08-10 19:33:52 +08:00
|
|
|
|
disabled && "text-muted-foreground",
|
|
|
|
|
|
)}
|
|
|
|
|
|
>
|
2026-09-10 11:10:51 +08:00
|
|
|
|
<SelectValue placeholder={emptyLabel}><span className="flex min-w-0 items-center gap-2">
|
2026-08-10 19:33:52 +08:00
|
|
|
|
{selectedProvider && showProviderLogos ? (
|
|
|
|
|
|
<ProviderPickerIcon
|
|
|
|
|
|
provider={selectedProvider.name}
|
|
|
|
|
|
showBrandLogos={showProviderLogos}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
<span className="truncate">{selectedProvider?.label ?? emptyLabel}</span>
|
2026-09-10 11:10:51 +08:00
|
|
|
|
</span></SelectValue>
|
|
|
|
|
|
</SelectTrigger>
|
2026-10-11 04:30:43 +08:00
|
|
|
|
<SelectContent onCloseAutoFocus={(event) => {
|
|
|
|
|
|
if (openingProviderSetup.current) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
openingProviderSetup.current = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}}>
|
2026-08-10 19:33:52 +08:00
|
|
|
|
{providers.map((provider) => {
|
|
|
|
|
|
return (
|
2026-09-10 11:10:51 +08:00
|
|
|
|
<SelectItem
|
2026-08-10 19:33:52 +08:00
|
|
|
|
key={provider.name}
|
2026-09-10 11:10:51 +08:00
|
|
|
|
value={provider.name}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
>
|
|
|
|
|
|
<span className="flex min-w-0 items-center gap-2">
|
|
|
|
|
|
{showProviderLogos ? (
|
|
|
|
|
|
<ProviderPickerIcon
|
|
|
|
|
|
provider={provider.name}
|
|
|
|
|
|
showBrandLogos={showProviderLogos}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
<span className="truncate">{provider.label}</span>
|
|
|
|
|
|
</span>
|
2026-09-10 11:10:51 +08:00
|
|
|
|
</SelectItem>
|
2026-08-10 19:33:52 +08:00
|
|
|
|
);
|
|
|
|
|
|
})}
|
2026-10-11 04:30:43 +08:00
|
|
|
|
{onAddProvider || onConfigureProvider ? <>
|
|
|
|
|
|
{providers.length > 0 ? <SelectSeparator className="my-1 h-px bg-border" /> : null}
|
|
|
|
|
|
{onConfigureProvider && selectedProvider ? <SelectItem value=":configure-provider">
|
|
|
|
|
|
<span className="flex items-center gap-2">
|
|
|
|
|
|
<Pencil className="h-4 w-4 text-muted-foreground" aria-hidden />
|
|
|
|
|
|
{t("settings.providers.configureProvider", { provider: selectedProvider.label })}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</SelectItem> : null}
|
|
|
|
|
|
{onAddProvider ? <SelectItem value=":add-provider">
|
|
|
|
|
|
<span className="flex items-center gap-2">
|
|
|
|
|
|
<Plus className="h-4 w-4 text-muted-foreground" aria-hidden />
|
|
|
|
|
|
{t("settings.providers.addProvider", { defaultValue: "Add provider" })}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</SelectItem> : null}
|
|
|
|
|
|
</> : null}
|
2026-09-10 11:10:51 +08:00
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
2026-08-10 19:33:52 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function ModelIdPicker({
|
|
|
|
|
|
token,
|
|
|
|
|
|
settings,
|
|
|
|
|
|
provider,
|
|
|
|
|
|
models,
|
|
|
|
|
|
value,
|
|
|
|
|
|
showProviderLogos,
|
|
|
|
|
|
emptyLabel,
|
|
|
|
|
|
searchPlaceholder,
|
|
|
|
|
|
emptyMessage,
|
2026-09-20 15:42:17 +08:00
|
|
|
|
onProviderOAuthLogin,
|
|
|
|
|
|
providerSigningIn = false,
|
2026-08-10 19:33:52 +08:00
|
|
|
|
onChange,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
token: string;
|
|
|
|
|
|
settings: SettingsPayload;
|
|
|
|
|
|
provider: string;
|
|
|
|
|
|
models?: string[];
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
showProviderLogos: boolean;
|
|
|
|
|
|
emptyLabel?: string;
|
|
|
|
|
|
searchPlaceholder?: string;
|
|
|
|
|
|
emptyMessage?: string;
|
2026-09-20 15:42:17 +08:00
|
|
|
|
onProviderOAuthLogin?: (provider: string) => void;
|
|
|
|
|
|
providerSigningIn?: boolean;
|
2026-10-11 04:30:43 +08:00
|
|
|
|
onChange: (model: string, info?: ProviderModelsPayload["models"][number]) => void;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
}) {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
const [query, setQuery] = useState("");
|
2026-09-20 15:42:17 +08:00
|
|
|
|
const catalogNoticeId = useId();
|
2026-09-20 17:27:16 +08:00
|
|
|
|
const catalogSignInRef = useRef<HTMLButtonElement>(null);
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
|
const restoreInputOnClose = useRef(false);
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const effectiveProvider =
|
|
|
|
|
|
provider === "auto" ? settings.agent.resolved_provider ?? provider : provider;
|
|
|
|
|
|
const hasConcreteProvider = Boolean(effectiveProvider && effectiveProvider !== "auto");
|
|
|
|
|
|
const hasStaticModels = models !== undefined;
|
|
|
|
|
|
const providerRow = settingsProviderRow(settings, effectiveProvider);
|
|
|
|
|
|
const providerConfigured = settingsProviderConfigured(settings, effectiveProvider);
|
|
|
|
|
|
const providerRequiresConfiguration =
|
|
|
|
|
|
!hasStaticModels && hasConcreteProvider && !providerConfigured;
|
2026-08-29 16:06:07 +08:00
|
|
|
|
const providerHasManagedModels = ["builtin", "hybrid"].includes(
|
|
|
|
|
|
providerRow?.model_catalog ?? "",
|
|
|
|
|
|
);
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const providerUsesManualModelIds =
|
|
|
|
|
|
!hasStaticModels &&
|
|
|
|
|
|
hasConcreteProvider &&
|
|
|
|
|
|
providerConfigured &&
|
|
|
|
|
|
providerRow?.auth_type === "oauth" &&
|
2026-08-29 16:06:07 +08:00
|
|
|
|
!providerHasManagedModels;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const canFetchModels =
|
|
|
|
|
|
!hasStaticModels &&
|
|
|
|
|
|
hasConcreteProvider && providerConfigured && !providerUsesManualModelIds;
|
|
|
|
|
|
const normalizedQuery = query.trim().toLowerCase();
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const defersModelList = DEFERRED_MODEL_LIST_PROVIDERS.has(effectiveProvider);
|
|
|
|
|
|
const hasDeferredSearchQuery =
|
|
|
|
|
|
normalizedQuery.length >= DEFERRED_MODEL_LIST_QUERY_MIN_LENGTH;
|
|
|
|
|
|
const shouldFetchModels =
|
|
|
|
|
|
canFetchModels && (!defersModelList || hasDeferredSearchQuery);
|
|
|
|
|
|
const { payload, loading, refreshing, failed, needsSignIn, retry } = useProviderModelCatalog({
|
|
|
|
|
|
revision: providerRow ?? settings,
|
|
|
|
|
|
token,
|
|
|
|
|
|
provider: effectiveProvider,
|
|
|
|
|
|
enabled: open && shouldFetchModels,
|
|
|
|
|
|
});
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const providerModels: ProviderModelsPayload["models"] = useMemo(
|
|
|
|
|
|
() => hasStaticModels
|
|
|
|
|
|
? (models?.map((id) => ({ id })) ?? [])
|
|
|
|
|
|
: (payload?.models ?? []),
|
|
|
|
|
|
[hasStaticModels, models, payload?.models],
|
|
|
|
|
|
);
|
|
|
|
|
|
const visibleModels = useMemo(
|
|
|
|
|
|
() => providerModels
|
|
|
|
|
|
.filter((model) => {
|
|
|
|
|
|
if (!normalizedQuery) return true;
|
|
|
|
|
|
return [model.id, model.label ?? "", model.description ?? "", model.owned_by ?? ""]
|
|
|
|
|
|
.some((field) => field.toLowerCase().includes(normalizedQuery));
|
|
|
|
|
|
})
|
|
|
|
|
|
.slice(0, 80),
|
|
|
|
|
|
[normalizedQuery, providerModels],
|
|
|
|
|
|
);
|
|
|
|
|
|
const isCatalog = payload?.catalog_kind === "catalog";
|
|
|
|
|
|
const waitingForModelSearch =
|
|
|
|
|
|
open && canFetchModels && defersModelList && !hasDeferredSearchQuery;
|
|
|
|
|
|
const hasModelList = hasStaticModels || payload?.status === "available";
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const catalogNeedsSignIn = !hasStaticModels && needsSignIn;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const showModels = Boolean(
|
2026-09-20 17:27:16 +08:00
|
|
|
|
!catalogNeedsSignIn && hasModelList
|
|
|
|
|
|
&& (hasStaticModels || (payload && (!isCatalog || normalizedQuery))),
|
2026-08-10 19:33:52 +08:00
|
|
|
|
);
|
|
|
|
|
|
const customCandidate = query.trim();
|
2026-09-20 17:27:16 +08:00
|
|
|
|
const allowCustomModel = !providerRequiresConfiguration && !catalogNeedsSignIn;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const exactQueryMatch = providerModels.some((model) => model.id === customCandidate);
|
|
|
|
|
|
const showCustomModel = Boolean(
|
|
|
|
|
|
allowCustomModel && customCandidate && !exactQueryMatch && customCandidate !== value,
|
|
|
|
|
|
);
|
|
|
|
|
|
const providerModelCount = payload?.model_count ?? providerModels.length;
|
|
|
|
|
|
const modelUnconfigured = !value.trim() || !providerConfigured;
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const showCatalogNotice = !hasStaticModels && (catalogNeedsSignIn
|
|
|
|
|
|
|| (open && shouldFetchModels && !refreshing && failed));
|
2026-09-20 17:27:16 +08:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-10-11 04:30:43 +08:00
|
|
|
|
if (!open || loading) return;
|
|
|
|
|
|
if (catalogNeedsSignIn) catalogSignInRef.current?.focus();
|
|
|
|
|
|
else searchInputRef.current?.focus();
|
2026-09-20 17:27:16 +08:00
|
|
|
|
}, [open, catalogNeedsSignIn, loading]);
|
2026-08-10 19:33:52 +08:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setQuery(providerUsesManualModelIds || !hasConcreteProvider ? value : "");
|
2026-10-11 04:30:43 +08:00
|
|
|
|
}, [effectiveProvider, hasConcreteProvider, providerUsesManualModelIds, value]);
|
2026-08-10 19:33:52 +08:00
|
|
|
|
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const openPicker = (nextQuery?: string) => {
|
|
|
|
|
|
if (nextQuery !== undefined || !open) {
|
|
|
|
|
|
setQuery(nextQuery ?? (providerUsesManualModelIds || !hasConcreteProvider ? value : ""));
|
2026-08-10 19:33:52 +08:00
|
|
|
|
}
|
2026-10-11 04:30:43 +08:00
|
|
|
|
restoreInputOnClose.current = false;
|
|
|
|
|
|
setOpen(true);
|
|
|
|
|
|
};
|
2026-08-10 19:33:52 +08:00
|
|
|
|
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const closePicker = (restoreFocus = false) => {
|
|
|
|
|
|
restoreInputOnClose.current = restoreFocus;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
setOpen(false);
|
|
|
|
|
|
};
|
2026-10-11 04:30:43 +08:00
|
|
|
|
const selectModel = (model: string) => {
|
|
|
|
|
|
const info = providerModels.find((entry) => entry.id === model);
|
|
|
|
|
|
if (info) onChange(model, info);
|
|
|
|
|
|
else onChange(model);
|
|
|
|
|
|
closePicker(true);
|
|
|
|
|
|
};
|
2026-08-10 19:33:52 +08:00
|
|
|
|
const navigationValues = useMemo(
|
|
|
|
|
|
() => [
|
|
|
|
|
|
...(showModels ? visibleModels.map((model) => model.id) : []),
|
|
|
|
|
|
...(showCustomModel ? [customCandidate] : []),
|
|
|
|
|
|
],
|
|
|
|
|
|
[customCandidate, showCustomModel, showModels, visibleModels],
|
|
|
|
|
|
);
|
|
|
|
|
|
const navigation = useComboboxNavigation({
|
|
|
|
|
|
open,
|
|
|
|
|
|
values: navigationValues,
|
|
|
|
|
|
selectedValue: value,
|
|
|
|
|
|
onSelect: selectModel,
|
2026-10-11 04:30:43 +08:00
|
|
|
|
onClose: () => closePicker(true),
|
2026-08-10 19:33:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const renderModelRow = (
|
|
|
|
|
|
model: ProviderModelsPayload["models"][number],
|
|
|
|
|
|
options: { selected?: boolean } = {},
|
|
|
|
|
|
) => (
|
|
|
|
|
|
<ComboboxOption
|
|
|
|
|
|
key={model.id}
|
|
|
|
|
|
{...navigation.getOptionProps(model.id)}
|
|
|
|
|
|
className={cn(
|
2026-08-14 07:07:09 +09:00
|
|
|
|
"flex cursor-default items-center justify-between gap-2 rounded-control px-2 py-1.5 text-[12px]",
|
2026-08-10 19:33:52 +08:00
|
|
|
|
options.selected && "text-foreground",
|
|
|
|
|
|
)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className="flex min-w-0 items-center gap-2">
|
|
|
|
|
|
<ProviderPickerIcon
|
|
|
|
|
|
provider={effectiveProvider}
|
|
|
|
|
|
showBrandLogos={showProviderLogos}
|
|
|
|
|
|
unconfigured={!providerConfigured}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span className="min-w-0">
|
|
|
|
|
|
<span className="block truncate font-medium text-foreground">
|
|
|
|
|
|
{model.label ?? model.id}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
{model.description || (model.label && model.label !== model.id) ? (
|
2026-10-07 15:19:55 +08:00
|
|
|
|
<span className="mt-0.5 flex min-w-0 flex-wrap gap-x-2 text-[10.5px] text-muted-foreground">
|
|
|
|
|
|
{model.label && model.label !== model.id ? <span className="truncate font-mono">{model.id}</span> : null}{" "}
|
|
|
|
|
|
{model.description ? <span className="truncate">{model.description}</span> : null}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span className="ml-2 flex shrink-0 items-center gap-2 text-[11px] text-muted-foreground">
|
|
|
|
|
|
{model.context_window ? <span>{formatContextWindow(model.context_window)}</span> : null}
|
|
|
|
|
|
{options.selected ? <Check className="h-3.5 w-3.5 text-foreground" aria-hidden /> : null}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</ComboboxOption>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Popover open={open} onOpenChange={setOpen}>
|
2026-10-11 04:30:43 +08:00
|
|
|
|
<PopoverAnchor asChild>
|
|
|
|
|
|
<div className="relative w-full">
|
|
|
|
|
|
<span className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2">
|
2026-08-10 19:33:52 +08:00
|
|
|
|
<ProviderPickerIcon
|
|
|
|
|
|
provider={effectiveProvider}
|
|
|
|
|
|
showBrandLogos={showProviderLogos}
|
|
|
|
|
|
unconfigured={modelUnconfigured}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</span>
|
2026-10-11 04:30:43 +08:00
|
|
|
|
<SearchInput
|
|
|
|
|
|
ref={searchInputRef}
|
|
|
|
|
|
type="search"
|
|
|
|
|
|
name="model-search"
|
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
|
autoCorrect="off"
|
|
|
|
|
|
spellCheck={false}
|
|
|
|
|
|
value={open && !catalogNeedsSignIn ? query : value}
|
|
|
|
|
|
readOnly={catalogNeedsSignIn}
|
|
|
|
|
|
onClick={() => openPicker()}
|
|
|
|
|
|
onChange={(event) => openPicker(event.target.value)}
|
|
|
|
|
|
{...navigation.inputProps}
|
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
|
if (event.nativeEvent.isComposing) return;
|
|
|
|
|
|
if (!open && ["ArrowDown", "ArrowUp", "Enter"].includes(event.key)) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
openPicker();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
navigation.inputProps.onKeyDown(event);
|
|
|
|
|
|
}}
|
|
|
|
|
|
placeholder={open
|
|
|
|
|
|
? searchPlaceholder || tx("settings.models.searchModels", "Search or type model ID")
|
|
|
|
|
|
: emptyLabel || tx("settings.models.selectModel", "Select model")}
|
|
|
|
|
|
aria-label={emptyLabel || tx("settings.models.selectModel", "Select model")}
|
|
|
|
|
|
aria-expanded={open}
|
|
|
|
|
|
aria-describedby={showCatalogNotice ? catalogNoticeId : undefined}
|
|
|
|
|
|
className="h-9 appearance-none pl-9 pr-9 text-[13px] font-medium [&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span className="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2">
|
|
|
|
|
|
<ControlChevron />
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</PopoverAnchor>
|
2026-08-10 19:33:52 +08:00
|
|
|
|
<PopoverContent
|
|
|
|
|
|
align="end"
|
2026-10-11 04:30:43 +08:00
|
|
|
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
|
|
|
|
onCloseAutoFocus={(event) => {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
if (restoreInputOnClose.current) {
|
|
|
|
|
|
restoreInputOnClose.current = false;
|
|
|
|
|
|
searchInputRef.current?.focus({ preventScroll: true });
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
onEscapeKeyDown={() => { restoreInputOnClose.current = true; }}
|
|
|
|
|
|
onInteractOutside={(event) => {
|
|
|
|
|
|
if (event.target === searchInputRef.current) event.preventDefault();
|
|
|
|
|
|
else restoreInputOnClose.current = false;
|
|
|
|
|
|
}}
|
2026-09-10 11:10:51 +08:00
|
|
|
|
className="w-[var(--radix-popover-trigger-width)] max-w-[calc(100vw-2rem)] p-1.5"
|
2026-08-10 19:33:52 +08:00
|
|
|
|
>
|
|
|
|
|
|
|
2026-09-20 15:42:17 +08:00
|
|
|
|
{showCatalogNotice ? (
|
2026-09-20 17:27:16 +08:00
|
|
|
|
<div className="mx-1 mb-1.5 flex items-start gap-2 rounded-control bg-muted/60 px-2.5 py-2 text-[11px] leading-4">
|
|
|
|
|
|
{catalogNeedsSignIn ? <ProviderPickerIcon
|
|
|
|
|
|
provider={effectiveProvider}
|
|
|
|
|
|
showBrandLogos={showProviderLogos}
|
|
|
|
|
|
/> : null}
|
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
|
<div id={catalogNoticeId} role="status">
|
|
|
|
|
|
<p className="font-medium text-foreground">
|
|
|
|
|
|
{catalogNeedsSignIn
|
|
|
|
|
|
? tx("settings.models.catalogAuthRequired", "Authorization expired. Please sign in again.")
|
2026-10-11 04:30:43 +08:00
|
|
|
|
: <button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className="rounded-sm text-left underline decoration-foreground/30 underline-offset-2 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
void retry();
|
|
|
|
|
|
searchInputRef.current?.focus();
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{tx("settings.models.catalogUnavailable", "Refresh failed. Click to retry")}
|
|
|
|
|
|
</button>}
|
2026-09-20 17:27:16 +08:00
|
|
|
|
</p>
|
2026-10-11 04:30:43 +08:00
|
|
|
|
{!catalogNeedsSignIn && payload?.status === "available" ? <p className="mt-1 text-muted-foreground">
|
|
|
|
|
|
{payload.source !== "fallback"
|
|
|
|
|
|
? tx("settings.models.catalogStale", "Cached list may be out of date.")
|
|
|
|
|
|
: tx("settings.models.catalogFallback", "Built-in list may be out of date.")}
|
2026-09-20 17:27:16 +08:00
|
|
|
|
</p> : null}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{catalogNeedsSignIn && onProviderOAuthLogin && providerRow?.oauth_login_supported ? (
|
|
|
|
|
|
<Button
|
|
|
|
|
|
ref={catalogSignInRef}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="mt-2 h-7 rounded-full px-2.5 text-[11px]"
|
|
|
|
|
|
disabled={providerSigningIn}
|
|
|
|
|
|
aria-describedby={catalogNoticeId}
|
|
|
|
|
|
onClick={() => {
|
2026-10-11 04:30:43 +08:00
|
|
|
|
closePicker();
|
2026-09-20 17:27:16 +08:00
|
|
|
|
onProviderOAuthLogin(effectiveProvider);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{providerSigningIn
|
|
|
|
|
|
? tx("settings.oauth.signingIn", "Signing in...")
|
|
|
|
|
|
: tx("settings.oauth.signInAgain", "Sign in again")}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
) : null}
|
2026-09-20 15:42:17 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
2026-09-20 17:27:16 +08:00
|
|
|
|
{catalogNeedsSignIn ? null : providerRequiresConfiguration ? (
|
2026-08-10 19:33:52 +08:00
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
|
|
|
|
|
{tx("settings.models.providerNotConfigured", "Configure this provider before loading models.")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : hasStaticModels && !providerModels.length ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
|
|
|
|
|
{emptyMessage || tx("settings.models.unsupportedModelList", "Type a model ID manually.")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : providerUsesManualModelIds ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
|
|
|
|
|
{tx("settings.models.unsupportedModelList", "Type a model ID manually.")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : !canFetchModels ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
2026-09-10 11:10:51 +08:00
|
|
|
|
{tx("settings.models.autoProviderCustomOnly", "Enter a model ID manually when using automatic provider selection.")}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
) : waitingForModelSearch ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
2026-09-10 11:10:51 +08:00
|
|
|
|
{tx("settings.models.searchCatalog", "Search this provider’s model catalog.")}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
) : loading ? (
|
2026-10-11 04:30:43 +08:00
|
|
|
|
<SkeletonStatus
|
|
|
|
|
|
label={tx("settings.models.loadingModels", "Loading models...")}
|
2026-10-19 15:57:32 +08:00
|
|
|
|
className="text-[12px]"
|
2026-10-11 04:30:43 +08:00
|
|
|
|
>
|
|
|
|
|
|
{["w-3/5", "w-4/5", "w-1/2"].map((width) => (
|
2026-10-19 15:57:32 +08:00
|
|
|
|
<div key={width} className="flex items-center justify-between gap-2 px-2 py-1.5">
|
|
|
|
|
|
<div className="h-5 w-5 shrink-0 rounded-md bg-muted-foreground/20" />
|
2026-10-11 04:30:43 +08:00
|
|
|
|
<div className="min-w-0 flex-1">
|
2026-10-19 15:57:32 +08:00
|
|
|
|
<div className="flex h-[1.5em] items-center">
|
|
|
|
|
|
<div className={cn("h-3 rounded bg-muted-foreground/20", width)} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{providerHasManagedModels ? <div className="mt-0.5 flex h-[1.5em] items-center text-[10.5px]">
|
|
|
|
|
|
<div className="h-2.5 w-2/5 rounded bg-muted-foreground/10" />
|
|
|
|
|
|
</div> : null}
|
2026-10-11 04:30:43 +08:00
|
|
|
|
</div>
|
2026-10-19 15:57:32 +08:00
|
|
|
|
<div className="ml-2 h-2.5 w-7 shrink-0 rounded bg-muted-foreground/10" />
|
2026-10-11 04:30:43 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</SkeletonStatus>
|
2026-08-10 19:33:52 +08:00
|
|
|
|
) : payload?.status === "not_configured" ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
|
|
|
|
|
{tx("settings.models.providerNotConfigured", "Configure this provider before loading models.")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : payload?.status === "unsupported" || payload?.status === "missing_api_base" ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
|
|
|
|
|
{payload.message || tx("settings.models.unsupportedModelList", "Type a model ID manually.")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : isCatalog && !normalizedQuery ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
2026-09-10 11:10:51 +08:00
|
|
|
|
{tx("settings.models.searchCatalog", "Search this provider’s model catalog.")}
|
|
|
|
|
|
{providerModelCount ? <> {t("settings.models.availableCount", {
|
|
|
|
|
|
defaultValue: "Models available: {{count}}",
|
|
|
|
|
|
count: providerModelCount,
|
|
|
|
|
|
})}</> : null}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
{navigationValues.length ? (
|
|
|
|
|
|
<div
|
|
|
|
|
|
{...navigation.listProps}
|
|
|
|
|
|
aria-label={searchPlaceholder || tx("settings.models.selectModel", "Select model")}
|
2026-10-11 04:30:43 +08:00
|
|
|
|
className="max-h-[16rem] overflow-y-auto scrollbar-thin"
|
2026-08-10 19:33:52 +08:00
|
|
|
|
>
|
|
|
|
|
|
{showModels
|
|
|
|
|
|
? visibleModels.map((model) =>
|
|
|
|
|
|
renderModelRow(model, { selected: model.id === value }),
|
|
|
|
|
|
)
|
|
|
|
|
|
: null}
|
|
|
|
|
|
{showCustomModel ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{showModels && visibleModels.length ? (
|
|
|
|
|
|
<div role="separator" className="-mx-1.5 my-1.5 h-px bg-border/50" />
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
<ComboboxOption
|
|
|
|
|
|
{...navigation.getOptionProps(customCandidate)}
|
2026-08-14 07:07:09 +09:00
|
|
|
|
className="flex cursor-default items-center gap-2 rounded-control px-2 py-1.5 text-[12px]"
|
2026-08-10 19:33:52 +08:00
|
|
|
|
>
|
|
|
|
|
|
<span className="grid h-5 w-5 shrink-0 place-items-center rounded-md bg-muted/80 text-muted-foreground">
|
|
|
|
|
|
<Pencil className="h-3 w-3" aria-hidden />
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span className="min-w-0 truncate">
|
|
|
|
|
|
{tx("settings.models.useCustomModel", "Use")}{" "}
|
|
|
|
|
|
<span className="font-medium text-foreground">“{customCandidate}”</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</ComboboxOption>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : showModels ? (
|
|
|
|
|
|
<div className="px-2 py-1.5 text-[11px] text-muted-foreground">
|
|
|
|
|
|
{tx("settings.models.noModelResults", "No matching models.")}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
|
</Popover>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function ProviderPickerIcon({
|
|
|
|
|
|
provider,
|
|
|
|
|
|
showBrandLogos,
|
|
|
|
|
|
unconfigured = false,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
provider: string;
|
|
|
|
|
|
showBrandLogos: boolean;
|
|
|
|
|
|
unconfigured?: boolean;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
const brand = providerBrand(provider);
|
|
|
|
|
|
const Icon = PROVIDER_ICONS[provider] ?? Hexagon;
|
2026-09-19 14:24:23 +08:00
|
|
|
|
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
|
|
|
|
|
const isLogoTile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
|
2026-08-10 19:33:52 +08:00
|
|
|
|
|
|
|
|
|
|
if (unconfigured) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<span
|
|
|
|
|
|
data-testid="provider-picker-unconfigured-icon"
|
|
|
|
|
|
className="grid h-5 w-5 shrink-0 place-items-center text-amber-700 dark:text-amber-200"
|
|
|
|
|
|
aria-hidden
|
|
|
|
|
|
>
|
|
|
|
|
|
<CircleAlert className="h-4 w-4" strokeWidth={1.8} />
|
|
|
|
|
|
</span>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (showBrandLogos && logoUrl) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<span
|
|
|
|
|
|
data-testid={`provider-picker-logo-${provider}`}
|
2026-09-19 14:24:23 +08:00
|
|
|
|
className={cn(
|
|
|
|
|
|
"grid h-5 w-5 shrink-0 place-items-center overflow-hidden rounded-md",
|
|
|
|
|
|
logoLoaded ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted",
|
|
|
|
|
|
)}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
aria-hidden
|
|
|
|
|
|
>
|
2026-10-01 14:10:45 +08:00
|
|
|
|
<span
|
|
|
|
|
|
className={cn(
|
|
|
|
|
|
"col-start-1 row-start-1 grid h-full w-full place-items-center rounded-md text-[7.5px] font-semibold text-white",
|
|
|
|
|
|
logoLoaded ? "opacity-0" : "opacity-100",
|
|
|
|
|
|
)}
|
|
|
|
|
|
style={{ backgroundColor: brand?.color }}
|
|
|
|
|
|
>
|
|
|
|
|
|
{brand?.initials}
|
|
|
|
|
|
</span>
|
2026-08-10 19:33:52 +08:00
|
|
|
|
<img
|
|
|
|
|
|
src={logoUrl}
|
|
|
|
|
|
alt=""
|
|
|
|
|
|
decoding="async"
|
|
|
|
|
|
loading="lazy"
|
2026-09-19 14:24:23 +08:00
|
|
|
|
referrerPolicy="no-referrer"
|
|
|
|
|
|
draggable={false}
|
|
|
|
|
|
className={cn(
|
2026-10-01 14:10:45 +08:00
|
|
|
|
"col-start-1 row-start-1 object-contain",
|
2026-09-19 14:24:23 +08:00
|
|
|
|
isLogoTile ? "h-5 w-5" : "h-3.5 w-3.5",
|
|
|
|
|
|
logoLoaded ? "opacity-100" : "opacity-0",
|
|
|
|
|
|
)}
|
2026-08-10 19:33:52 +08:00
|
|
|
|
onLoad={onLogoLoad}
|
|
|
|
|
|
onError={onLogoError}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (showBrandLogos && brand) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<span
|
|
|
|
|
|
data-testid={`provider-picker-logo-fallback-${provider}`}
|
|
|
|
|
|
className="grid h-5 w-5 shrink-0 place-items-center rounded-md text-[7.5px] font-semibold text-white"
|
|
|
|
|
|
style={{ backgroundColor: brand.color }}
|
|
|
|
|
|
aria-hidden
|
|
|
|
|
|
>
|
|
|
|
|
|
{brand.initials}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<span
|
|
|
|
|
|
className="grid h-5 w-5 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground"
|
|
|
|
|
|
aria-hidden
|
|
|
|
|
|
>
|
|
|
|
|
|
<Icon className="h-3 w-3" strokeWidth={2} />
|
|
|
|
|
|
</span>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function optionRowsWithCurrent(
|
|
|
|
|
|
options: Array<{ name: string; label: string }>,
|
|
|
|
|
|
value: string,
|
|
|
|
|
|
): Array<{ name: string; label: string }> {
|
|
|
|
|
|
if (!value || options.some((option) => option.name === value)) return options;
|
|
|
|
|
|
return [{ name: value, label: value }, ...options];
|
|
|
|
|
|
}
|
|
|
|
|
|
|