feat(webui): improve model and provider settings UX (#6145)
* feat(webui): improve model and provider settings UX * refactor(webui): organize provider forms and model picker interactions * fix(webui): separate OAuth credentials from provider configuration * fix(webui): stabilize shared combobox navigation * refactor(config): store provider connections as sparse entries * fix(webui): preserve provider validation and isolate catalog tests * refactor(config): manage explicit provider connections * refactor(webui): decouple settings UX from provider removal * fix(webui): select current combobox options during rapid input * feat(webui): refine model preset and provider management * style(webui): refine preset footer actions * fix(webui): align model settings with responsive layout rules * refactor(webui): finalize preset dialogs and simplify provider state * fix(webui): keep fallback heading stable while sorting presets Animate card dimensions without changing layout height and keep the section heading outside sortable cards. Remove proxy normalization from this PR. * docs: update WebUI model and provider setup instructions * docs: start model setup from new preset * docs: remove duplicate WebUI model setup instructions
This commit is contained in:
1 parent
8080ea843a
commit
9261e731ce
88 files changed
+2854
-1734
No files matched your search
@@ -9,7 +9,7 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactElement, ReactNode } from "react";
|
||||
import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactNode } from "react";
|
||||
import {
|
||||
Archive,
|
||||
ArchiveRestore,
|
||||
@@ -44,10 +44,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
HoverHint,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { MAX_WORKBENCH_PANES } from "@/components/workbench/workbench-model";
|
||||
import {
|
||||
@@ -120,23 +117,6 @@ function SidebarActionMenuContent({
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarItemTooltip({
|
||||
label,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
children: ReactElement;
|
||||
}) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
||||
<TooltipContent side="top" align="start" className="max-w-80 break-words">
|
||||
{label}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarSessionHandle({ handle }: { handle: ChatSummary["handle"] }) {
|
||||
if (!handle) return null;
|
||||
return (
|
||||
@@ -665,7 +645,6 @@ export const ChatList = memo(function ChatList({
|
||||
closeDeleteSelection();
|
||||
};
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<div ref={scrollViewportRef} className="sidebar-scroll-fade sidebar-scrollbar h-full min-h-0 min-w-0 overflow-x-hidden overflow-y-auto overscroll-contain pb-2">
|
||||
<SidebarSelectionHighlight
|
||||
scope="chats"
|
||||
@@ -990,7 +969,7 @@ export const ChatList = memo(function ChatList({
|
||||
actionMenus.openFromContextMenu(event, actionMenuId)
|
||||
)}
|
||||
className={cn(
|
||||
"group flex min-w-0 max-w-full items-center gap-1 rounded-xl px-2 text-[13px] font-normal leading-5",
|
||||
"group flex min-w-0 max-w-full items-center gap-1 rounded-control px-2 text-[13px] font-normal leading-5",
|
||||
SIDEBAR_SELECTION_ITEM_CLASS,
|
||||
compact ? "min-h-7" : "min-h-8",
|
||||
topicActive
|
||||
@@ -1182,7 +1161,7 @@ export const ChatList = memo(function ChatList({
|
||||
{deleteSelectionMode ? (
|
||||
<div
|
||||
data-testid="delete-selection-bar"
|
||||
className="sticky bottom-2 z-30 mx-1 mt-3 flex min-h-11 items-center gap-2 rounded-2xl border border-sidebar-border/80 bg-popover/95 p-1.5 pl-2 shadow-[0_10px_30px_rgba(15,23,42,0.14)] backdrop-blur-xl"
|
||||
className="sticky bottom-2 z-30 mx-1 mt-3 flex min-h-11 items-center gap-2 rounded-floating border border-sidebar-border/80 bg-popover/95 p-1.5 pl-2 shadow-[0_10px_30px_rgba(15,23,42,0.14)] backdrop-blur-xl"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
@@ -1213,7 +1192,6 @@ export const ChatList = memo(function ChatList({
|
||||
) : null}
|
||||
</SidebarSelectionHighlight>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1261,12 +1239,12 @@ function WorkbenchTabHeader({
|
||||
data-workbench-tab
|
||||
onContextMenu={(event) => actionMenus.openFromContextMenu(event, actionMenuId)}
|
||||
className={cn(
|
||||
"group/tab flex min-h-8 min-w-0 items-center gap-0.5 rounded-xl px-2",
|
||||
"group/tab flex min-h-8 min-w-0 items-center gap-0.5 rounded-control px-2",
|
||||
active ? "text-sidebar-foreground" : "text-sidebar-content",
|
||||
)}
|
||||
>
|
||||
{!deleteSelectionMode ? (
|
||||
<SidebarItemTooltip label={disclosureLabel}>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-80 break-words" content={disclosureLabel}>
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={!collapsed}
|
||||
@@ -1289,9 +1267,9 @@ function WorkbenchTabHeader({
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</SidebarItemTooltip>
|
||||
</HoverHint>
|
||||
) : null}
|
||||
<SidebarItemTooltip label={title}>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-80 break-words" content={title}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
@@ -1315,7 +1293,7 @@ function WorkbenchTabHeader({
|
||||
) : null}
|
||||
<span className="min-w-0 flex-1 truncate">{title}</span>
|
||||
</button>
|
||||
</SidebarItemTooltip>
|
||||
</HoverHint>
|
||||
{!deleteSelectionMode ? (
|
||||
<>
|
||||
<DropdownMenu
|
||||
@@ -1463,7 +1441,7 @@ function ActivePaneRows({
|
||||
actionMenus.openFromContextMenu(event, actionMenuId)
|
||||
)}
|
||||
className={cn(
|
||||
"group/pane flex min-w-0 max-w-full items-center gap-1 rounded-xl px-2 text-[13px] font-normal leading-5",
|
||||
"group/pane flex min-w-0 max-w-full items-center gap-1 rounded-control px-2 text-[13px] font-normal leading-5",
|
||||
SIDEBAR_SELECTION_ITEM_CLASS,
|
||||
compact ? "min-h-7" : "min-h-8",
|
||||
active
|
||||
@@ -1679,7 +1657,7 @@ function TemporaryChatSection({
|
||||
data-temporary-chat-row={session.key}
|
||||
data-chat-row={session.key}
|
||||
className={cn(
|
||||
"group flex min-h-8 min-w-0 max-w-full items-center gap-2 rounded-xl px-2 text-[13px] font-normal leading-5",
|
||||
"group flex min-h-8 min-w-0 max-w-full items-center gap-2 rounded-control px-2 text-[13px] font-normal leading-5",
|
||||
SIDEBAR_SELECTION_ITEM_CLASS,
|
||||
active
|
||||
? "text-sidebar-accent-foreground"
|
||||
@@ -1752,7 +1730,7 @@ function ProjectGroupHeader({
|
||||
aria-expanded={!collapsed}
|
||||
onClick={onToggle}
|
||||
className={cn(
|
||||
"flex min-w-0 flex-1 items-center gap-2 rounded-lg py-1 text-left transition-colors media-hover:hover:text-sidebar-foreground",
|
||||
"flex min-w-0 flex-1 items-center gap-2 rounded-control py-1 text-left transition-colors media-hover:hover:text-sidebar-foreground",
|
||||
active ? "font-medium text-sidebar-foreground" : "font-normal",
|
||||
)}
|
||||
>
|
||||
@@ -1766,9 +1744,9 @@ function ProjectGroupHeader({
|
||||
onContextMenu={onRequestRename || onNewChat
|
||||
? (event) => actionMenus.openFromContextMenu(event, actionMenuId)
|
||||
: undefined}
|
||||
className="group flex min-h-8 min-w-0 items-center gap-0.5 rounded-xl px-2 text-[13px] leading-5 text-sidebar-content"
|
||||
className="group flex min-h-8 min-w-0 items-center gap-0.5 rounded-control px-2 text-[13px] leading-5 text-sidebar-content"
|
||||
>
|
||||
<SidebarItemTooltip label={disclosureLabel}>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-80 break-words" content={disclosureLabel}>
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={!collapsed}
|
||||
@@ -1791,14 +1769,11 @@ function ProjectGroupHeader({
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</SidebarItemTooltip>
|
||||
</HoverHint>
|
||||
{path ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{projectButton}</TooltipTrigger>
|
||||
<TooltipContent side="top" align="start" className="max-w-72 break-words">
|
||||
{path}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-72 break-words" content={path}>
|
||||
{projectButton}
|
||||
</HoverHint>
|
||||
) : projectButton}
|
||||
{updatedAt ? (
|
||||
<span className="shrink-0 text-[11px] text-sidebar-muted-foreground">
|
||||
@@ -1884,7 +1859,7 @@ function ChatsFoldFooter({
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggle}
|
||||
className="h-7 w-full rounded-xl text-left text-[12px] font-medium text-sidebar-muted-foreground transition-colors media-hover:hover:bg-sidebar-accent/50 media-hover:hover:text-sidebar-muted-foreground"
|
||||
className="h-7 w-full rounded-control text-left text-[12px] font-medium text-sidebar-muted-foreground transition-colors media-hover:hover:bg-sidebar-accent/50 media-hover:hover:text-sidebar-muted-foreground"
|
||||
>
|
||||
<span className="px-2">
|
||||
{folded
|
||||
@@ -1911,7 +1886,7 @@ function SessionActivityIndicator({
|
||||
defaultValue: "This conversation needs your attention",
|
||||
});
|
||||
return (
|
||||
<SidebarItemTooltip label={label}>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-80 break-words" content={label}>
|
||||
<span
|
||||
role="img"
|
||||
aria-label={label}
|
||||
@@ -1919,14 +1894,14 @@ function SessionActivityIndicator({
|
||||
>
|
||||
<AlertTriangle className="h-3.5 w-3.5" strokeWidth={2} aria-hidden />
|
||||
</span>
|
||||
</SidebarItemTooltip>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
|
||||
if (state === "running") {
|
||||
const label = t("chat.activity.running");
|
||||
return (
|
||||
<SidebarItemTooltip label={label}>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-80 break-words" content={label}>
|
||||
<span
|
||||
role="img"
|
||||
aria-label={label}
|
||||
@@ -1934,14 +1909,14 @@ function SessionActivityIndicator({
|
||||
>
|
||||
<span className="h-3 w-3 animate-spin rounded-full border border-blue-500/25 border-t-blue-500 [animation-duration:1.4s] motion-reduce:animate-none dark:border-blue-400/25 dark:border-t-blue-400" />
|
||||
</span>
|
||||
</SidebarItemTooltip>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
|
||||
if (state === "updated") {
|
||||
const label = t("chat.activity.updated");
|
||||
return (
|
||||
<SidebarItemTooltip label={label}>
|
||||
<HoverHint side="top" align="start" contentClassName="max-w-80 break-words" content={label}>
|
||||
<span
|
||||
role="img"
|
||||
aria-label={label}
|
||||
@@ -1949,7 +1924,7 @@ function SessionActivityIndicator({
|
||||
>
|
||||
<span className="h-2 w-2 rounded-full bg-[#ff8a3d] shadow-[0_0_0_2px_rgba(255,138,61,0.16)]" />
|
||||
</span>
|
||||
</SidebarItemTooltip>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,7 @@ import { SlashCommandText } from "@/components/SlashCommandText";
|
||||
import { ReasoningRow } from "@/components/thread/activity/ReasoningRow";
|
||||
import { ContextCompactionNotice } from "@/components/thread/ContextCompactionNotice";
|
||||
import { UserMessageText } from "@/components/UserMessageText";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { HoverHint } from "@/components/ui/tooltip";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { formatMessageEndTime } from "@/lib/format";
|
||||
@@ -124,7 +119,7 @@ export function MessageCopyButton({ message, className }: { message: UIMessage;
|
||||
const content = messageCopyContent(message, t);
|
||||
const { copied, label, onCopy } = useMessageCopy(content);
|
||||
if (!content.trim()) return null;
|
||||
return <TooltipProvider><Tooltip><TooltipTrigger asChild><button type="button" data-message-block-copy-action
|
||||
return <HoverHint content={label} side="top" align="center"><button type="button" data-message-block-copy-action
|
||||
data-assistant-copy-action={message.role === "assistant" || undefined}
|
||||
onClick={onCopy} aria-label={label}
|
||||
className={cn(
|
||||
@@ -135,7 +130,7 @@ export function MessageCopyButton({ message, className }: { message: UIMessage;
|
||||
)}>
|
||||
{copied ? <Check className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden />
|
||||
: <Copy className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden />}
|
||||
</button></TooltipTrigger><TooltipContent side="top" align="center">{label}</TooltipContent></Tooltip></TooltipProvider>;
|
||||
</button></HoverHint>;
|
||||
}
|
||||
|
||||
interface MessageBlockMenuActivity {
|
||||
@@ -185,7 +180,6 @@ export function MessageBlockMenuActions({
|
||||
: "";
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<div
|
||||
data-message-block-menu-actions
|
||||
className={cn("flex max-w-full flex-col items-start gap-1", sheet ? "w-full" : "w-max")}
|
||||
@@ -199,8 +193,7 @@ export function MessageBlockMenuActions({
|
||||
<div className="flex min-h-[var(--message-block-control-size)] items-center gap-0.5">
|
||||
{!sheet && hasText ? <MessageCopyButton message={message} /> : null}
|
||||
{showFork ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<HoverHint content={t("message.forkFromHere")} side="top" align="center">
|
||||
<button
|
||||
type="button"
|
||||
data-message-block-fork-action
|
||||
@@ -219,11 +212,7 @@ export function MessageBlockMenuActions({
|
||||
<ForkArrowIcon className="h-3.5 w-3.5" />
|
||||
{sheet ? <span>{t("message.forkFromHere")}</span> : null}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="center">
|
||||
{t("message.forkFromHere")}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</HoverHint>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
@@ -298,7 +287,6 @@ export function MessageBlockMenuActions({
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -355,8 +343,15 @@ function UserDeliveryStatus({
|
||||
const { title, body } = deliveryErrorCopy(errorKind, t);
|
||||
return (
|
||||
<>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<HoverHint
|
||||
side="top"
|
||||
align="end"
|
||||
contentClassName="max-w-72 px-3 py-2.5 text-left"
|
||||
content={<>
|
||||
<p className="font-medium text-popover-foreground">{title}</p>
|
||||
<p className="mt-1 leading-relaxed text-muted-foreground">{body}</p>
|
||||
</>}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`${label}: ${title}`}
|
||||
@@ -370,16 +365,7 @@ function UserDeliveryStatus({
|
||||
<CircleAlert className="h-3.5 w-3.5" aria-hidden />
|
||||
{label}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="top"
|
||||
align="end"
|
||||
className="max-w-72 px-3 py-2.5 text-left"
|
||||
>
|
||||
<p className="font-medium text-popover-foreground">{title}</p>
|
||||
<p className="mt-1 leading-relaxed text-muted-foreground">{body}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</HoverHint>
|
||||
<span role="alert" aria-live="assertive" className="sr-only">
|
||||
{title}. {body}
|
||||
</span>
|
||||
@@ -526,14 +512,12 @@ export function MessageBubble({
|
||||
</p>
|
||||
) : null}
|
||||
{showDeliveryStatus ? (
|
||||
<TooltipProvider>
|
||||
<div className="flex min-h-8 items-center justify-end gap-1.5 text-muted-foreground">
|
||||
<UserDeliveryStatus
|
||||
status={message.deliveryStatus}
|
||||
errorKind={message.deliveryErrorKind}
|
||||
/>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useState } from "react";
|
||||
import { ArrowRightLeft, Hexagon } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { HoverHint } from "@/components/ui/tooltip";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
import type { ResponseSource } from "@/lib/types";
|
||||
@@ -20,13 +20,11 @@ export function FallbackResponseSources({
|
||||
const fallbacks = sources?.filter((source) => source.fallback === true) ?? [];
|
||||
if (fallbacks.length === 0) return null;
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<div className={cn("flex min-w-0 max-w-full flex-wrap items-center gap-x-2 gap-y-1", className)}>
|
||||
{fallbacks.map((source) => (
|
||||
<ResponseSourceBadge key={JSON.stringify(source)} source={source} className={badgeClassName} />
|
||||
))}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,8 +44,8 @@ function ResponseSourceBadge({
|
||||
const tile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<Tooltip open={open ? false : undefined}>
|
||||
<TooltipTrigger asChild>
|
||||
<HoverHint content={description} enabled={!open} side="top" align="end"
|
||||
contentClassName="max-w-[min(18rem,calc(100vw-2rem))]">
|
||||
<PopoverTrigger asChild>
|
||||
<button type="button" aria-label={description} className={cn(
|
||||
"touch-target inline-flex min-h-8 min-w-0 max-w-full items-center gap-1.5 rounded-control px-1.5 text-xs",
|
||||
@@ -57,7 +55,7 @@ function ResponseSourceBadge({
|
||||
)}>
|
||||
<ArrowRightLeft aria-hidden className="size-3 shrink-0 opacity-70" />
|
||||
<span aria-hidden className={cn(
|
||||
"relative grid size-4 shrink-0 place-items-center overflow-hidden rounded-[4px]",
|
||||
"relative grid size-4 shrink-0 place-items-center overflow-hidden rounded-mark",
|
||||
logoLoaded && !tile ? "bg-white" : "bg-transparent",
|
||||
)}>
|
||||
{logoUrl ? <img src={logoUrl} alt="" loading="lazy" decoding="async" referrerPolicy="no-referrer"
|
||||
@@ -68,11 +66,7 @@ function ResponseSourceBadge({
|
||||
<span className="min-w-0 max-w-48 truncate">{source.preset}</span>
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" align="end" className="max-w-[min(18rem,calc(100vw-2rem))] break-words">
|
||||
{description}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</HoverHint>
|
||||
<PopoverContent side="top" align="end" aria-label={description}
|
||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||
className="max-w-[min(18rem,calc(100vw-2rem))] rounded-control px-3 py-2 text-xs leading-relaxed break-words">
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
SidebarSelectionHighlight,
|
||||
} from "@/components/SidebarSelectionHighlight";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { HoverHint } from "@/components/ui/tooltip";
|
||||
import type {
|
||||
ChatSummary,
|
||||
SidebarViewState,
|
||||
@@ -149,7 +149,6 @@ export function Sidebar(props: SidebarProps) {
|
||||
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<nav
|
||||
ref={props.containActionMenus ? setMenuPortalContainer : undefined}
|
||||
aria-label={t("sidebar.navigation")}
|
||||
@@ -174,7 +173,7 @@ export function Sidebar(props: SidebarProps) {
|
||||
onClick={collapsed ? props.onExpand : undefined}
|
||||
tabIndex={collapsed ? 0 : -1}
|
||||
className={cn(
|
||||
"host-no-drag flex h-8 w-8 shrink-0 items-center justify-center rounded-xl transition-colors",
|
||||
"host-no-drag flex h-8 w-8 shrink-0 items-center justify-center rounded-control transition-colors",
|
||||
props.hostChromeInset && "mt-5",
|
||||
!collapsed && "pointer-events-none",
|
||||
)}
|
||||
@@ -333,7 +332,6 @@ export function Sidebar(props: SidebarProps) {
|
||||
<HostSwitcher collapsed={collapsed} portalContainer={props.containActionMenus ? menuPortalContainer : undefined} />
|
||||
</div>
|
||||
</nav>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -376,11 +374,11 @@ function SidebarActionButton({
|
||||
onFocus={onIntent}
|
||||
onPointerEnter={onIntent}
|
||||
className={cn(
|
||||
"touch-target group h-8 min-w-0 gap-2 overflow-hidden rounded-xl font-normal",
|
||||
"touch-target group h-8 min-w-0 gap-2 overflow-hidden rounded-control font-normal",
|
||||
SIDEBAR_SELECTION_ACTION_ITEM_CLASS,
|
||||
collapsed
|
||||
? "w-8 justify-center gap-0 px-0"
|
||||
: iconOnly ? "w-8 shrink-0 justify-center gap-0 rounded-xl px-0"
|
||||
: iconOnly ? "w-8 shrink-0 justify-center gap-0 rounded-control px-0"
|
||||
: "w-full justify-start gap-2 px-2 text-[13px] leading-5 [&_svg]:h-[18px] [&_svg]:w-[18px] [&_svg]:stroke-[1.75]",
|
||||
active
|
||||
? "text-sidebar-accent-foreground"
|
||||
@@ -399,12 +397,11 @@ function SidebarActionButton({
|
||||
</Button>
|
||||
);
|
||||
return compact || shortcut ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent side={collapsed ? "right" : "bottom"} className="flex items-center gap-4">
|
||||
<span>{label}</span>
|
||||
{shortcut ? <kbd className="whitespace-nowrap font-sans text-muted-foreground">{shortcut}</kbd> : null}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<HoverHint side={collapsed ? "right" : "bottom"} contentClassName="flex items-center gap-4" content={<>
|
||||
<span>{label}</span>
|
||||
{shortcut ? <kbd className="whitespace-nowrap font-sans text-muted-foreground">{shortcut}</kbd> : null}
|
||||
</>}>
|
||||
{button}
|
||||
</HoverHint>
|
||||
) : button;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ export function SidebarSelectionHighlight({
|
||||
data-testid={`${scope}-selection-highlight`}
|
||||
data-active-id={activeId ?? undefined}
|
||||
aria-hidden="true"
|
||||
className={cn("pointer-events-none absolute left-0 top-0 z-0 !mt-0 rounded-xl bg-sidebar-foreground/[0.055] opacity-0 transition-[transform,width,height] duration-300 ease-out will-change-transform motion-reduce:transition-none dark:bg-white/[0.07]", highlightClassName)}
|
||||
className={cn("pointer-events-none absolute left-0 top-0 z-0 !mt-0 rounded-control bg-sidebar-foreground/[0.055] opacity-0 transition-[transform,width,height] duration-300 ease-out will-change-transform motion-reduce:transition-none dark:bg-white/[0.07]", highlightClassName)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ChevronLeft, Loader2 } from "lucide-react";
|
||||
import { useCallback, useEffect, useState, type ReactNode } from "react";
|
||||
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogLayoutContext, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { SettingsExitGuard } from "@/components/settings/contracts";
|
||||
@@ -18,8 +18,9 @@ import {
|
||||
import {
|
||||
ProviderOAuthLoginDialog,
|
||||
ProvidersSettings,
|
||||
providerFormFromRow,
|
||||
type ProviderSettingsEntry,
|
||||
} from "@/components/settings/models/ProviderSettings";
|
||||
import { providerFormFromRow } from "@/components/settings/models/providerForm";
|
||||
import { AboutSettings, AppearanceSettings, OverviewSettings } from "@/components/settings/overview/OverviewSettings";
|
||||
import { SettingsSidebar, standaloneSectionTitle } from "@/components/settings/SettingsSidebar";
|
||||
import {
|
||||
@@ -88,6 +89,12 @@ export function SettingsPage({
|
||||
}: SettingsPageProps) {
|
||||
const [dialogLayoutAnchor, setDialogLayoutAnchor] = useState<HTMLDivElement | null>(null);
|
||||
const [mcpSetupName, setMcpSetupName] = useState<string | null>(null);
|
||||
const presetDeletedCallback = useRef<(() => void) | null>(null);
|
||||
const [providerPanel, setProviderPanel] = useState<ProviderSettingsEntry | null>(null);
|
||||
const providerSetupOrigin = useRef<{
|
||||
trigger: HTMLButtonElement | null;
|
||||
onAdded?: (provider: string) => void;
|
||||
} | null>(null);
|
||||
const [pendingExit, setPendingExit] = useState<(() => void) | null>(null);
|
||||
const [automationDetailReturn, setAutomationDetailReturn] =
|
||||
useState<SessionAutomationJob | null>(null);
|
||||
@@ -118,10 +125,10 @@ export function SettingsPage({
|
||||
closeProviderOAuthFlow,
|
||||
completeProviderOAuthResponse,
|
||||
createCustomProvider,
|
||||
providerOperation,
|
||||
customMcpForm,
|
||||
editingProviderKeys,
|
||||
error,
|
||||
expandedProvider,
|
||||
featureCatalog,
|
||||
form,
|
||||
handleApiServiceAction,
|
||||
@@ -140,7 +147,7 @@ export function SettingsPage({
|
||||
handleMigrateModelConfigurations,
|
||||
handleNanobotFeatureAction,
|
||||
handleSaveCustomMcp,
|
||||
handleToggleProvider,
|
||||
resetProviderDraft,
|
||||
handleWebSearchProviderChange,
|
||||
hostEngineApplying,
|
||||
imageGenerationDirty,
|
||||
@@ -361,9 +368,22 @@ export function SettingsPage({
|
||||
orderSaving={modelCallOrderSaving || modelConfigurationSaving}
|
||||
migrationSaving={modelMigrationSaving}
|
||||
showBrandLogos={localPrefs.brandLogos}
|
||||
providerSaving={providerSaving}
|
||||
providerSaving={providerOperation?.action === "login" ? providerSaving : null}
|
||||
onChangeCallOrder={changeModelCallOrder}
|
||||
onProviderOAuthLogin={(provider) => runProviderOAuth(provider, "login")}
|
||||
onAddProvider={(trigger, onAdded) => {
|
||||
providerSetupOrigin.current = { trigger, onAdded };
|
||||
setProviderPanel({ kind: "add" });
|
||||
}}
|
||||
onConfigureProvider={(provider, trigger) => {
|
||||
providerSetupOrigin.current = { trigger };
|
||||
resetProviderDraft(provider);
|
||||
setProviderPanel({ kind: "edit", provider });
|
||||
}}
|
||||
onManageProviders={(trigger) => {
|
||||
providerSetupOrigin.current = { trigger };
|
||||
setProviderPanel({ kind: "manage" });
|
||||
}}
|
||||
onSave={saveModelSettings}
|
||||
onMigrate={handleMigrateModelConfigurations}
|
||||
onBeginCreate={beginModelPresetCreation}
|
||||
@@ -375,43 +395,54 @@ export function SettingsPage({
|
||||
setModelPresetNameError(null);
|
||||
modelPresetBeforeCreateRef.current = null;
|
||||
}}
|
||||
onDeleteConfiguration={setModelPresetPendingDelete}
|
||||
onDeleteConfiguration={(preset, onDeleted) => {
|
||||
presetDeletedCallback.current = onDeleted;
|
||||
setModelPresetPendingDelete(preset);
|
||||
}}
|
||||
/>
|
||||
<ProvidersSettings
|
||||
{providerPanel ? <ProvidersSettings
|
||||
entry={providerPanel}
|
||||
onClose={() => setProviderPanel(null)}
|
||||
onProviderAdded={providerSetupOrigin.current?.onAdded
|
||||
? (provider) => providerSetupOrigin.current?.onAdded?.(provider)
|
||||
: undefined}
|
||||
onCloseAutoFocus={(event) => {
|
||||
if (providerSetupOrigin.current) {
|
||||
event.preventDefault();
|
||||
providerSetupOrigin.current.trigger?.focus({ preventScroll: true });
|
||||
providerSetupOrigin.current = null;
|
||||
}
|
||||
}}
|
||||
settings={settings}
|
||||
nanobotFeatures={nanobotFeatures}
|
||||
featureAction={nanobotFeatureAction}
|
||||
capabilityError={nanobotFeaturesError}
|
||||
expandedProvider={expandedProvider}
|
||||
providerForms={providerForms}
|
||||
visibleProviderKeys={visibleProviderKeys}
|
||||
editingProviderKeys={editingProviderKeys}
|
||||
providerSaving={providerSaving}
|
||||
showBrandLogos={localPrefs.brandLogos}
|
||||
remoteBrowserAccess={remoteBrowserAccess}
|
||||
onToggleProvider={handleToggleProvider}
|
||||
onResetProviderDraft={resetProviderDraft}
|
||||
onToggleProviderKey={toggleProviderKeyVisibility}
|
||||
onToggleProviderKeyEditing={toggleProviderKeyEditing}
|
||||
onChangeProviderForm={(provider, value) =>
|
||||
onChangeProviderForm={(provider, value) => {
|
||||
const row = settings.providers.find((item) => item.name === provider);
|
||||
if (!row) return;
|
||||
setProviderForms((prev) => ({
|
||||
...prev,
|
||||
[provider]: {
|
||||
...(prev[provider] ?? providerFormFromRow(
|
||||
settings.providers.find((row) => row.name === provider) ?? {
|
||||
name: provider,
|
||||
label: provider,
|
||||
configured: false,
|
||||
},
|
||||
)),
|
||||
...(prev[provider] ?? providerFormFromRow(row)),
|
||||
...value,
|
||||
},
|
||||
}))
|
||||
}
|
||||
}));
|
||||
}}
|
||||
onSaveProvider={saveProvider}
|
||||
onCreateCustomProvider={createCustomProvider}
|
||||
providerOperation={providerOperation}
|
||||
onProviderOAuthLogin={(provider) => runProviderOAuth(provider, "login")}
|
||||
onProviderOAuthLogout={(provider) => runProviderOAuth(provider, "logout")}
|
||||
/>
|
||||
/> : null}
|
||||
</div>
|
||||
);
|
||||
case "image":
|
||||
@@ -678,9 +709,17 @@ export function SettingsPage({
|
||||
preset={modelPresetPendingDelete}
|
||||
deleting={saving}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setModelPresetPendingDelete(null);
|
||||
if (!open) {
|
||||
setModelPresetPendingDelete(null);
|
||||
presetDeletedCallback.current = null;
|
||||
}
|
||||
}}
|
||||
onConfirm={async () => {
|
||||
if (await handleDeleteModelConfiguration()) {
|
||||
presetDeletedCallback.current?.();
|
||||
presetDeletedCallback.current = null;
|
||||
}
|
||||
}}
|
||||
onConfirm={handleDeleteModelConfiguration}
|
||||
/>
|
||||
|
||||
<ProviderOAuthLoginDialog
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Disclosure } from "@/components/ui/disclosure";
|
||||
import { ExpandableText } from "@/components/ui/expandable-text";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SearchInput } from "@/components/ui/input";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { Sheet, SheetContent, SheetDescription, SheetTitle } from "@/components/ui/sheet";
|
||||
import { SkillsMarketplace } from "@/components/settings/SkillsMarketplace";
|
||||
@@ -113,7 +113,7 @@ export function SkillsCatalogSettings({ skills, loading = false, error = false }
|
||||
className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<Input
|
||||
<SearchInput
|
||||
value={installedQuery}
|
||||
onChange={(event) => setInstalledQuery(event.target.value)}
|
||||
placeholder={t("settings.skills.searchInstalled", {
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SearchInput } from "@/components/ui/input";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import {
|
||||
fetchMarketplaceSkillTrends,
|
||||
@@ -200,7 +200,7 @@ export function SkillsMarketplace({
|
||||
className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<Input
|
||||
<SearchInput
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder={t("settings.skills.marketplaceSearchPlaceholder", {
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { ProviderIcon } from "@/components/settings/models/ProviderSettings";
|
||||
import { ProviderIcon } from "@/components/settings/shared/ProviderIcon";
|
||||
import { ModelAPIControl } from "@/components/settings/models/ModelAPIControl";
|
||||
import { useAutomaticModelAPI } from "@/components/settings/models/useAutomaticModelAPI";
|
||||
import { useModelPresetDrag } from "@/components/settings/models/useModelPresetDrag";
|
||||
import { ReasoningEffortPicker } from "@/components/settings/models/ReasoningEffortPicker";
|
||||
import { RemoveActionButton } from "@/components/settings/shared/RemoveActionButton";
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import { useEffect, useId, useRef, useState, type Dispatch, type SetStateAction } from "react";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
import {
|
||||
GripVertical,
|
||||
ListOrdered,
|
||||
Loader2,
|
||||
Plus,
|
||||
Trash2,
|
||||
Pencil,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -33,7 +34,8 @@ import {
|
||||
StatusPill,
|
||||
} from "@/components/settings/shared/SettingsControls";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ControlChevron } from "@/components/ui/control-chevron";
|
||||
import { HoverHint } from "@/components/ui/hover-hint";
|
||||
import { TruncatedTextTooltip } from "@/components/ui/truncated-text-tooltip";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -41,6 +43,7 @@ import {
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -200,6 +203,9 @@ export function ModelsSettings({
|
||||
providerSaving,
|
||||
onChangeCallOrder,
|
||||
onProviderOAuthLogin,
|
||||
onAddProvider,
|
||||
onConfigureProvider,
|
||||
onManageProviders,
|
||||
onSave,
|
||||
onMigrate,
|
||||
onBeginCreate,
|
||||
@@ -225,19 +231,23 @@ export function ModelsSettings({
|
||||
providerSaving: string | null;
|
||||
onChangeCallOrder: (order: string[]) => void;
|
||||
onProviderOAuthLogin: (provider: string) => void;
|
||||
onAddProvider: (trigger: HTMLButtonElement | null, onAdded: (provider: string) => void) => void;
|
||||
onConfigureProvider: (provider: string, trigger: HTMLButtonElement | null) => void;
|
||||
onManageProviders: (trigger: HTMLButtonElement) => void;
|
||||
onSave: () => void;
|
||||
onMigrate: () => void;
|
||||
onBeginCreate: () => void;
|
||||
onCancelCreate: () => void;
|
||||
onClearPresetNameError: () => void;
|
||||
onSelectConfiguration: (name: string) => void;
|
||||
onDeleteConfiguration: (preset: SettingsPayload["model_presets"][number]) => void;
|
||||
onDeleteConfiguration: (preset: SettingsPayload["model_presets"][number], onDeleted: () => void) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
useAutoSave(form, dirty, saving, onSave, !creating && !!form.model.trim());
|
||||
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
|
||||
t(key, { defaultValue: fallback, ...(values ?? {}) });
|
||||
const [editorOpen, setEditorOpen] = useState(false);
|
||||
const [hideEditorReturnFocus, setHideEditorReturnFocus] = useState(false);
|
||||
const [advancedOpen, setAdvancedOpen] = useState(false);
|
||||
const resolvedAutomaticAPI = useAutomaticModelAPI({
|
||||
token,
|
||||
@@ -251,21 +261,17 @@ export function ModelsSettings({
|
||||
const editorTriggerRef = useRef<HTMLElement | null>(null);
|
||||
const presetNameInputRef = useRef<HTMLInputElement>(null);
|
||||
const suggestedPresetNameRef = useRef<string | null>(null);
|
||||
const presetContextInitializedRef = useRef(false);
|
||||
const [editorRowKey, setEditorRowKey] = useState<string | null>(null);
|
||||
const advancedId = useId();
|
||||
const [draggedCallOrderIndex, setDraggedCallOrderIndex] = useState<number | null>(null);
|
||||
const [dragOverCallOrderIndex, setDragOverCallOrderIndex] = useState<number | null>(null);
|
||||
const [draggedRowHeight, setDraggedRowHeight] = useState(0);
|
||||
const dragStartY = useRef(0);
|
||||
const pendingDrag = useRef<number | null>(null);
|
||||
const suppressDragClick = useRef(false);
|
||||
const [draggedOffset, setDraggedOffset] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (presetNameError) presetNameInputRef.current?.focus();
|
||||
}, [presetNameError]);
|
||||
useEffect(() => {
|
||||
if (!creating) suggestedPresetNameRef.current = null;
|
||||
if (!creating) {
|
||||
suggestedPresetNameRef.current = null;
|
||||
presetContextInitializedRef.current = false;
|
||||
}
|
||||
}, [creating]);
|
||||
const namedPresets = settings.model_presets.filter((preset) => !preset.is_default);
|
||||
const namedPresetsByName = new Map(namedPresets.map((preset) => [preset.name, preset]));
|
||||
@@ -311,6 +317,21 @@ export function ModelsSettings({
|
||||
const providerValue = providerOptions.some((provider) => provider.name === form.provider)
|
||||
? form.provider
|
||||
: "";
|
||||
const selectProvider = (provider: string) => {
|
||||
const clearSuggestedName =
|
||||
creating &&
|
||||
provider !== form.provider &&
|
||||
suggestedPresetNameRef.current !== null &&
|
||||
form.modelPreset === suggestedPresetNameRef.current;
|
||||
if (clearSuggestedName) suggestedPresetNameRef.current = null;
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
provider,
|
||||
model: provider === prev.provider ? prev.model : "",
|
||||
api: provider === prev.provider ? prev.api : null,
|
||||
modelPreset: clearSuggestedName ? "" : prev.modelPreset,
|
||||
}));
|
||||
};
|
||||
const selectedProviderNeedsSignIn =
|
||||
selectedProvider?.auth_type === "oauth" && !selectedProvider.configured;
|
||||
const selectedProviderSigningIn = providerSaving === selectedProvider?.name;
|
||||
@@ -323,17 +344,26 @@ export function ModelsSettings({
|
||||
!form.model.trim() ||
|
||||
!form.provider.trim() ||
|
||||
!form.modelPreset.trim() ||
|
||||
!Number.isSafeInteger(form.maxTokens) ||
|
||||
form.maxTokens <= 0 ||
|
||||
!Number.isSafeInteger(form.contextWindowTokens) ||
|
||||
form.contextWindowTokens <= 0 ||
|
||||
form.temperature < 0 ||
|
||||
form.temperature > 2;
|
||||
const selectedPresetReferenced = Boolean(
|
||||
selectedPreset && callOrder[0] === selectedPreset.name,
|
||||
);
|
||||
const callOrderBusy = orderSaving || saving;
|
||||
const presetDrag = useModelPresetDrag({
|
||||
keys: presetRows.filter((row) => row.orderIndex >= 0).map((row) => row.key),
|
||||
disabled: callOrderBusy,
|
||||
onReorder: (keys) => onChangeCallOrder(keys.map((key) => presetRows.find((row) => row.key === key)!.name)),
|
||||
});
|
||||
const selectPreset = (
|
||||
preset: SettingsPayload["model_presets"][number],
|
||||
rowKey: string,
|
||||
) => {
|
||||
setHideEditorReturnFocus(false);
|
||||
editorTriggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
const toggleCurrentPreset =
|
||||
!creating && selectedPreset?.name === preset.name && activeEditorRowKey === rowKey;
|
||||
@@ -371,34 +401,11 @@ export function ModelsSettings({
|
||||
onChangeCallOrder(callOrder.filter((_, itemIndex) => itemIndex !== index));
|
||||
};
|
||||
|
||||
const dropCallOrderItem = (targetIndex: number) => {
|
||||
if (
|
||||
callOrderBusy ||
|
||||
draggedCallOrderIndex === null ||
|
||||
draggedCallOrderIndex === targetIndex
|
||||
) {
|
||||
setDraggedCallOrderIndex(null);
|
||||
setDragOverCallOrderIndex(null);
|
||||
return;
|
||||
}
|
||||
const next = [...callOrder];
|
||||
const moved = next.splice(draggedCallOrderIndex, 1)[0];
|
||||
if (!moved) {
|
||||
setDraggedCallOrderIndex(null);
|
||||
setDragOverCallOrderIndex(null);
|
||||
return;
|
||||
}
|
||||
next.splice(targetIndex, 0, moved);
|
||||
setDraggedCallOrderIndex(null);
|
||||
setDragOverCallOrderIndex(null);
|
||||
onChangeCallOrder(next);
|
||||
};
|
||||
|
||||
const renderPresetEditor = () => (
|
||||
<div
|
||||
id="model-preset-editor"
|
||||
data-testid="model-preset-editor"
|
||||
className="space-y-1 pb-4"
|
||||
className="space-y-1 pb-4 [&_.settings-row>div:first-child]:pl-3"
|
||||
>
|
||||
<SettingsRow
|
||||
title={tx("settings.models.presetName", "Preset name")}
|
||||
@@ -449,22 +456,9 @@ export function ModelsSettings({
|
||||
value={providerValue}
|
||||
emptyLabel={t("settings.byok.noConfiguredProviders")}
|
||||
showProviderLogos={showBrandLogos}
|
||||
onChange={(provider) => {
|
||||
const providerChanged = provider !== form.provider;
|
||||
const clearSuggestedName =
|
||||
creating &&
|
||||
providerChanged &&
|
||||
suggestedPresetNameRef.current !== null &&
|
||||
form.modelPreset === suggestedPresetNameRef.current;
|
||||
if (clearSuggestedName) suggestedPresetNameRef.current = null;
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
provider,
|
||||
model: provider === prev.provider ? prev.model : "",
|
||||
api: provider === prev.provider ? prev.api : null,
|
||||
modelPreset: clearSuggestedName ? "" : prev.modelPreset,
|
||||
}));
|
||||
}}
|
||||
onAddProvider={(trigger) => onAddProvider(trigger, selectProvider)}
|
||||
onConfigureProvider={selectedProvider ? onConfigureProvider : undefined}
|
||||
onChange={selectProvider}
|
||||
/>
|
||||
</SettingsRow>
|
||||
{selectedProviderNeedsSignIn ? (
|
||||
@@ -500,7 +494,11 @@ export function ModelsSettings({
|
||||
showProviderLogos={showBrandLogos}
|
||||
onProviderOAuthLogin={onProviderOAuthLogin}
|
||||
providerSigningIn={selectedProviderSigningIn}
|
||||
onChange={(model) => {
|
||||
onChange={(model, info) => {
|
||||
const contextWindow = info?.context_window;
|
||||
const initializeContext = creating && !presetContextInitializedRef.current
|
||||
&& typeof contextWindow === "number" && Number.isSafeInteger(contextWindow) && contextWindow > 0;
|
||||
if (creating) presetContextInitializedRef.current = true;
|
||||
const canSuggestName =
|
||||
creating &&
|
||||
(!form.modelPreset.trim() || form.modelPreset === suggestedPresetNameRef.current);
|
||||
@@ -511,65 +509,77 @@ export function ModelsSettings({
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
model,
|
||||
contextWindowTokens: initializeContext ? contextWindow : prev.contextWindowTokens,
|
||||
api: model === prev.model ? prev.api : null,
|
||||
modelPreset: canSuggestName ? suggestion : prev.modelPreset,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={advancedOpen}
|
||||
aria-controls={advancedId}
|
||||
onClick={() => setAdvancedOpen((value) => !value)}
|
||||
className="settings-disclosure-row w-full text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-[14px] font-medium text-foreground">
|
||||
{tx("settings.models.advancedOptions", "Advanced options")}
|
||||
</span>
|
||||
<span className="mt-0.5 flex flex-wrap gap-x-3 text-[12px] tabular-nums text-muted-foreground">
|
||||
<span>{tx("settings.models.contextSummary", "Context {{context}}", {
|
||||
context: Number.isFinite(form.contextWindowTokens) ? formatModelContextWindow(form.contextWindowTokens) : "—",
|
||||
})}</span>{" "}
|
||||
<span>{tx("settings.models.outputSummary", "Max {{max}} tokens", {
|
||||
max: formatContextWindow(form.maxTokens),
|
||||
})}</span>
|
||||
</span>
|
||||
</span>
|
||||
<span className="settings-control">
|
||||
<span className="control-layout justify-end border-transparent">
|
||||
<ControlChevron
|
||||
className={cn(
|
||||
"transition-transform duration-200 motion-reduce:transition-none",
|
||||
advancedOpen && "rotate-180",
|
||||
<SettingsRow title={tx("settings.models.reasoningEffort", "Reasoning effort")}>
|
||||
<ReasoningEffortPicker
|
||||
token={token}
|
||||
provider={selectedProvider ?? settings.providers.find((provider) => provider.name === selectedPreset?.resolved_provider)}
|
||||
model={form.model}
|
||||
savedValues={form.model === selectedPreset?.model && form.provider === selectedPreset.provider
|
||||
? selectedPreset.reasoning_effort_values : undefined}
|
||||
value={form.reasoningEffort}
|
||||
onChange={(reasoningEffort) => setForm((prev) => ({ ...prev, reasoningEffort }))}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<Dialog open={advancedOpen} onOpenChange={setAdvancedOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="settings-disclosure-row w-full text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="min-w-0 pl-3">
|
||||
<span className="block text-[14px] font-medium text-foreground">
|
||||
{tx("settings.models.advancedOptions", "Advanced options")}
|
||||
</span>
|
||||
<span className="mt-0.5 flex flex-wrap gap-x-3 text-[12px] tabular-nums text-muted-foreground">
|
||||
<span>{tx("settings.models.contextSummary", "Context {{context}}", {
|
||||
context: Number.isFinite(form.contextWindowTokens) ? formatModelContextWindow(form.contextWindowTokens) : "—",
|
||||
})}</span>{" "}
|
||||
<span>{tx("settings.models.outputSummary", "Max {{max}} tokens", {
|
||||
max: Number.isFinite(form.maxTokens) ? formatContextWindow(form.maxTokens) : "—",
|
||||
})}</span>
|
||||
</span>
|
||||
</span>
|
||||
<span className="settings-control">
|
||||
<span className="control-layout justify-end border-transparent">
|
||||
<Pencil className="h-4 w-4 text-muted-foreground" aria-hidden />
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
<DialogContent aria-describedby={undefined}
|
||||
className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none gap-0 overflow-y-auto p-0">
|
||||
<DialogHeader className="px-6 pb-2 pt-6 pr-12 text-left">
|
||||
<DialogTitle>{tx("settings.models.advancedOptions", "Advanced options")}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="settings-grid !px-0 pb-4 [&_.settings-row>div:first-child]:pl-3">
|
||||
<ModelAPIControl
|
||||
provider={selectedProvider ?? settings.providers.find(
|
||||
(provider) => provider.name === (resolvedAutomaticAPI?.provider ?? selectedPreset?.resolved_provider),
|
||||
)}
|
||||
automaticAPI={resolvedAutomaticAPI?.api}
|
||||
value={form.api}
|
||||
onChange={(api) => setForm((prev) => ({ ...prev, api }))}
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
<DisclosureContent id={advancedId} open={advancedOpen}>
|
||||
<div className="bg-muted/12">
|
||||
<ModelAPIControl
|
||||
provider={selectedProvider ?? settings.providers.find(
|
||||
(provider) => provider.name === (resolvedAutomaticAPI?.provider ?? selectedPreset?.resolved_provider),
|
||||
)}
|
||||
automaticAPI={resolvedAutomaticAPI?.api}
|
||||
value={form.api}
|
||||
onChange={(api) => setForm((prev) => ({ ...prev, api }))}
|
||||
/>
|
||||
<div className="px-4 py-4 sm:px-5">
|
||||
<ModelAdvancedFields
|
||||
maxTokens={form.maxTokens}
|
||||
contextWindowTokens={form.contextWindowTokens}
|
||||
temperature={form.temperature}
|
||||
reasoningEffort={form.reasoningEffort}
|
||||
onChange={(value) => setForm((prev) => ({ ...prev, ...value }))}
|
||||
onChange={(value) => {
|
||||
if (creating && value.contextWindowTokens !== undefined) presetContextInitializedRef.current = true;
|
||||
setForm((prev) => ({ ...prev, ...value }));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</DisclosureContent>
|
||||
<div className="flex min-h-[58px] flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:px-5">
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<div className="settings-list-inset flex min-h-[58px] flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
{creating ? (
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -585,27 +595,33 @@ export function ModelsSettings({
|
||||
</Button>
|
||||
) : selectedPreset ? (
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="rounded-full text-muted-foreground hover:text-destructive"
|
||||
disabled={selectedPresetReferenced || saving || orderSaving}
|
||||
aria-describedby={
|
||||
selectedPresetReferenced ? "model-preset-delete-hint" : undefined
|
||||
}
|
||||
onClick={() => onDeleteConfiguration(selectedPreset)}
|
||||
<HoverHint
|
||||
enabled={selectedPresetReferenced}
|
||||
content={tx("settings.models.removeBeforeDelete", "Cannot delete the primary model")}
|
||||
>
|
||||
<Trash2 className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
{tx("settings.actions.delete", "Delete")}
|
||||
</Button>
|
||||
<span className="inline-flex">
|
||||
<RemoveActionButton
|
||||
disabled={selectedPresetReferenced || saving || orderSaving}
|
||||
aria-describedby={
|
||||
selectedPresetReferenced ? "model-preset-delete-hint" : undefined
|
||||
}
|
||||
onClick={() => onDeleteConfiguration(selectedPreset, () => {
|
||||
setEditorOpen(false);
|
||||
setEditorRowKey(null);
|
||||
})}
|
||||
>
|
||||
{tx("settings.actions.delete", "Delete")}
|
||||
</RemoveActionButton>
|
||||
</span>
|
||||
</HoverHint>
|
||||
{selectedPresetReferenced ? (
|
||||
<span
|
||||
id="model-preset-delete-hint"
|
||||
className="text-[11px] leading-4 text-muted-foreground"
|
||||
className="sr-only"
|
||||
>
|
||||
{tx(
|
||||
"settings.models.removeBeforeDelete",
|
||||
"Choose another primary preset before deleting this one.",
|
||||
"Cannot delete the primary model",
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
@@ -634,15 +650,15 @@ export function ModelsSettings({
|
||||
</div>
|
||||
);
|
||||
|
||||
const showMigration = !settings.model_call_order_editable
|
||||
&& settings.model_configuration_migratable !== false;
|
||||
|
||||
return (
|
||||
<div className="settings-stack">
|
||||
<section>
|
||||
<SettingsSectionTitle>
|
||||
{tx("settings.models.presets", "Model presets")}
|
||||
</SettingsSectionTitle>
|
||||
<SettingsGroup>
|
||||
{!settings.model_call_order_editable &&
|
||||
settings.model_configuration_migratable !== false ? (
|
||||
<SettingsSectionTitle>{t("settings.models.presets")}</SettingsSectionTitle>
|
||||
{showMigration ? (
|
||||
<SettingsGroup>
|
||||
<div className="flex flex-col gap-4 px-4 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-5">
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-control bg-muted text-muted-foreground">
|
||||
@@ -675,227 +691,205 @@ export function ModelsSettings({
|
||||
: tx("settings.models.convertAction", "Convert to presets")}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div role="list">
|
||||
{presetRows.map(({ key, name, orderIndex, preset }) => {
|
||||
const ordered = orderIndex >= 0;
|
||||
const provider = preset
|
||||
? modelPresetProviderKey(preset, settings)
|
||||
: settings.agent.resolved_provider ?? settings.agent.provider;
|
||||
const presetConfigured = preset
|
||||
? settingsProviderConfigured(
|
||||
settings,
|
||||
preset.provider,
|
||||
preset.resolved_provider,
|
||||
)
|
||||
: true;
|
||||
let dragOffset = 0;
|
||||
const isDragging = ordered && draggedCallOrderIndex === orderIndex;
|
||||
if (ordered && draggedCallOrderIndex !== null && dragOverCallOrderIndex !== null) {
|
||||
if (isDragging) dragOffset = draggedOffset;
|
||||
if (orderIndex > draggedCallOrderIndex && orderIndex <= dragOverCallOrderIndex) dragOffset = -draggedRowHeight;
|
||||
if (orderIndex < draggedCallOrderIndex && orderIndex >= dragOverCallOrderIndex) dragOffset = draggedRowHeight;
|
||||
}
|
||||
const isSelected =
|
||||
editorOpen &&
|
||||
!creating &&
|
||||
activeEditorRowKey === key &&
|
||||
selectedPreset?.name === name;
|
||||
const presetRow = (
|
||||
<div
|
||||
tabIndex={ordered ? 0 : -1}
|
||||
onDragStart={(event) => event.preventDefault()}
|
||||
aria-label={
|
||||
ordered
|
||||
? `${name}. ${tx(
|
||||
"settings.models.dragToReorder",
|
||||
"Drag to reorder",
|
||||
)}`
|
||||
: name
|
||||
}
|
||||
data-testid={`model-call-order-row-${name}`}
|
||||
onPointerDown={(event) => {
|
||||
if (!ordered || callOrderBusy || event.button !== 0 || (event.target as HTMLElement).closest('[role="switch"]')) return;
|
||||
pendingDrag.current = orderIndex;
|
||||
suppressDragClick.current = false;
|
||||
dragStartY.current = event.clientY;
|
||||
setDraggedOffset(0);
|
||||
const wrapper = event.currentTarget.parentElement;
|
||||
setDraggedRowHeight(wrapper?.getBoundingClientRect().height || 60);
|
||||
}}
|
||||
onPointerMove={(event) => {
|
||||
if (!event.buttons) { pendingDrag.current = null; return; }
|
||||
if (pendingDrag.current !== orderIndex || callOrderBusy) return;
|
||||
const offset = event.clientY - dragStartY.current;
|
||||
if (draggedCallOrderIndex === null && Math.abs(offset) < 5) return;
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
suppressDragClick.current = true;
|
||||
setDraggedCallOrderIndex(orderIndex);
|
||||
const target = Math.max(0, Math.min(callOrder.length - 1, orderIndex + Math.round(offset / draggedRowHeight)));
|
||||
setDragOverCallOrderIndex(target);
|
||||
setDraggedOffset(Math.max(-orderIndex * draggedRowHeight, Math.min((callOrder.length - orderIndex - 1) * draggedRowHeight, offset)));
|
||||
}}
|
||||
onPointerUp={() => {
|
||||
pendingDrag.current = null;
|
||||
if (draggedCallOrderIndex !== null) dropCallOrderItem(dragOverCallOrderIndex ?? orderIndex);
|
||||
}}
|
||||
onPointerCancel={() => {
|
||||
pendingDrag.current = null;
|
||||
setDraggedCallOrderIndex(null);
|
||||
setDragOverCallOrderIndex(null);
|
||||
}}
|
||||
onClickCapture={(event) => {
|
||||
if (suppressDragClick.current) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
suppressDragClick.current = false;
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.currentTarget !== event.target) return;
|
||||
if (ordered && event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
moveCallOrderItem(orderIndex, -1);
|
||||
} else if (ordered && event.key === "ArrowDown") {
|
||||
event.preventDefault();
|
||||
moveCallOrderItem(orderIndex, 1);
|
||||
} else if ((event.key === "Enter" || event.key === " ") && preset) {
|
||||
event.preventDefault();
|
||||
selectPreset(preset, key);
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"settings-list-row group relative flex select-none items-center gap-3 py-2 outline-none transition-colors duration-150",
|
||||
ordered &&
|
||||
(callOrderBusy
|
||||
? "cursor-wait"
|
||||
: "cursor-grab active:cursor-grabbing"),
|
||||
!isDragging && "settings-hover",
|
||||
isDragging && "bg-settings-surface shadow-md",
|
||||
isSelected && "bg-muted/45 settings-hover",
|
||||
"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={selectedPreset?.name === name}
|
||||
aria-haspopup="dialog"
|
||||
disabled={!preset}
|
||||
onClick={() => preset && selectPreset(preset, key)}
|
||||
className="flex min-w-0 flex-1 items-center gap-3 rounded-control text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
{presetConfigured ? (
|
||||
<ProviderIcon provider={provider} showBrandLogos={showBrandLogos} />
|
||||
) : (
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center">
|
||||
<ProviderPickerIcon provider={provider} showBrandLogos={showBrandLogos} unconfigured />
|
||||
</span>
|
||||
)}
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span className="truncate text-[14px] font-medium text-foreground">
|
||||
{name}
|
||||
</span>
|
||||
{orderIndex === 0 ? (
|
||||
<StatusPill tone="success">
|
||||
{tx("settings.models.primary", "Primary")}
|
||||
</StatusPill>
|
||||
) : null}
|
||||
{!presetConfigured ? (
|
||||
<span className="text-[11px] font-medium text-amber-700 dark:text-amber-300">
|
||||
{tx(
|
||||
"settings.models.providerSetupRequired",
|
||||
"Provider setup required",
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</span>
|
||||
<span className="shrink-0 px-2 py-1 text-[13px] font-normal leading-5 text-muted-foreground">
|
||||
{t("settings.configure")}
|
||||
</span>
|
||||
</button>
|
||||
{ordered ? (
|
||||
<GripVertical
|
||||
className="h-4 w-4 shrink-0 touch-none text-muted-foreground/40 transition-colors group-hover:text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
) : (
|
||||
<span className="h-4 w-4 shrink-0" aria-hidden />
|
||||
)}
|
||||
<ToggleButton
|
||||
checked={ordered}
|
||||
label={
|
||||
ordered
|
||||
? tx("settings.models.removeFromOrder", "Disable preset")
|
||||
: tx("settings.models.addToOrder", "Enable preset")
|
||||
}
|
||||
disabled={callOrderBusy || (ordered && callOrder.length <= 1)}
|
||||
onChange={() => {
|
||||
if (ordered) {
|
||||
removeCallOrderItem(orderIndex);
|
||||
} else if (preset) {
|
||||
onChangeCallOrder([...callOrder, preset.name]);
|
||||
</SettingsGroup>
|
||||
) : presetRows.length ? (
|
||||
<div ref={presetDrag.listRef} {...presetDrag.listProps} className="flex flex-col"
|
||||
role="list" aria-label={t("settings.models.callOrder")}>
|
||||
{callOrder.length > 0 && presetRows.length > 1 ? (
|
||||
<div role="presentation" className="order-1 mt-6">
|
||||
<SettingsSectionTitle>{t("settings.models.otherPresets")}</SettingsSectionTitle>
|
||||
</div>
|
||||
) : null}
|
||||
{/* Keep card nodes stable while previewing their order. */}
|
||||
{presetRows.map(({ key, name, preset }, rowIndex) => {
|
||||
const orderIndex = presetDrag.previewKeys.indexOf(key);
|
||||
const ordered = orderIndex >= 0;
|
||||
const primary = orderIndex === 0;
|
||||
const provider = preset ? modelPresetProviderKey(preset, settings) : "";
|
||||
const presetConfigured = preset
|
||||
? settingsProviderConfigured(settings, preset.provider, preset.resolved_provider)
|
||||
: true;
|
||||
const isDragging = key === presetDrag.draggedKey;
|
||||
const isSelected = editorOpen && !creating && activeEditorRowKey === key
|
||||
&& selectedPreset?.name === name;
|
||||
return (
|
||||
<div key={key} role="listitem" data-call-order-index={orderIndex} data-preset-sort-key={key}
|
||||
style={{ order: (ordered ? orderIndex : rowIndex) * 2 }} className={cn(!primary && "mb-2")}>
|
||||
<div data-preset-sort-surface={key}
|
||||
className={cn("relative origin-top-left rounded-panel", isDragging && "z-10 shadow-md ring-1 ring-border/50")}>
|
||||
<SettingsGroup>
|
||||
<div
|
||||
tabIndex={ordered ? 0 : -1}
|
||||
onDragStart={(event) => event.preventDefault()}
|
||||
aria-label={ordered ? `${name}. ${t("settings.models.dragToReorder")}` : name}
|
||||
data-testid={`model-call-order-row-${name}`}
|
||||
onPointerDown={(event) => {
|
||||
setHideEditorReturnFocus(false);
|
||||
presetDrag.start(event, key);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Escape") setHideEditorReturnFocus(false);
|
||||
if (event.currentTarget !== event.target) return;
|
||||
if (ordered && event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
moveCallOrderItem(orderIndex, -1);
|
||||
} else if (ordered && event.key === "ArrowDown") {
|
||||
event.preventDefault();
|
||||
moveCallOrderItem(orderIndex, 1);
|
||||
} else if ((event.key === "Enter" || event.key === " ") && preset) {
|
||||
event.preventDefault();
|
||||
selectPreset(preset, key);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div key={key} role="listitem" data-call-order-index={orderIndex}>
|
||||
<div className={cn("relative", isDragging ? "z-10" : "transition-transform duration-150 ease-out motion-reduce:transition-none")}
|
||||
style={{ transform: `translateY(${dragOffset}px)` }}>
|
||||
{presetRow}
|
||||
className={cn(
|
||||
"settings-list-inset group relative grid grid-cols-[auto_minmax(0,1fr)_auto_auto_auto] items-center gap-x-3 select-none outline-none transition-colors [transition-duration:240ms] motion-reduce:transition-none",
|
||||
primary ? "py-5 [--preset-title-size:1.375rem] sm:py-6 sm:[--preset-title-size:1.625rem]" : "py-4",
|
||||
ordered && (callOrderBusy ? "cursor-wait" : "cursor-grab active:cursor-grabbing"),
|
||||
!isDragging && "settings-hover",
|
||||
isSelected && "bg-muted/45",
|
||||
!hideEditorReturnFocus && "focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<div className="contents">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={selectedPreset?.name === name}
|
||||
aria-haspopup="dialog"
|
||||
disabled={!preset}
|
||||
onClick={() => preset && selectPreset(preset, key)}
|
||||
className={cn("col-span-2 grid min-w-0 grid-cols-subgrid items-center rounded-control text-left outline-none",
|
||||
!hideEditorReturnFocus && "focus-visible:ring-2 focus-visible:ring-ring")}
|
||||
>
|
||||
{presetConfigured ? (
|
||||
<span className={cn("relative aspect-square min-w-8", primary ? "w-[calc(var(--preset-title-size)*1.375+1.5rem)]" : "h-8")}>
|
||||
<span className="absolute inset-0">
|
||||
<ProviderIcon provider={provider} showBrandLogos={showBrandLogos} fill />
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center">
|
||||
<ProviderPickerIcon provider={provider} showBrandLogos={showBrandLogos} unconfigured />
|
||||
</span>
|
||||
)}
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex min-w-0 items-center gap-x-2">
|
||||
<TruncatedTextTooltip text={name} className={cn("font-medium text-foreground",
|
||||
primary ? "text-[length:var(--preset-title-size)] leading-snug tracking-tight" : "text-[14px]")} />
|
||||
{primary ? (
|
||||
<span className="shrink-0 whitespace-nowrap"><StatusPill tone="success">{t("settings.models.primary")}</StatusPill></span>
|
||||
) : !ordered ? (
|
||||
<span className="text-[11px] leading-5 text-muted-foreground">
|
||||
{t("settings.models.disabled")}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
{preset ? (
|
||||
<TruncatedTextTooltip
|
||||
text={primary
|
||||
? `${preset.model} ${formatModelContextWindow(preset.context_window_tokens)} ${preset.reasoning_effort || t("settings.values.default")}`
|
||||
: preset.model}
|
||||
className={cn("mt-1 block whitespace-pre text-muted-foreground", primary ? "text-[13px] leading-5" : "text-[12px]")} />
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
<Button type="button" variant="link" size="sm"
|
||||
className="h-auto px-0 text-[13px] font-normal text-muted-foreground hover:text-foreground hover:no-underline"
|
||||
disabled={!preset}
|
||||
onClick={() => preset && selectPreset(preset, key)}>
|
||||
<span className="sr-only sm:not-sr-only">{t("settings.configure")}</span>
|
||||
<Pencil className="h-4 w-4 sm:hidden" aria-hidden />
|
||||
</Button>
|
||||
{ordered ? (
|
||||
<GripVertical
|
||||
className="h-4 w-4 shrink-0 touch-none text-muted-foreground/40 transition-colors group-hover:text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
) : (
|
||||
<span className="h-4 w-4 shrink-0" aria-hidden />
|
||||
)}
|
||||
<ToggleButton
|
||||
checked={ordered}
|
||||
label={t(ordered ? "settings.models.removeFromOrder" : "settings.models.addToOrder")}
|
||||
disabled={callOrderBusy || (ordered && callOrder.length <= 1)}
|
||||
onChange={() => {
|
||||
if (ordered) removeCallOrderItem(orderIndex);
|
||||
else if (preset) onChangeCallOrder([...callOrder, preset.name]);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{!presetConfigured ? (
|
||||
<p className="col-[2/-1] mt-1 text-[11px] font-medium text-amber-700 dark:text-amber-300">
|
||||
{t("settings.models.providerSetupRequired")}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{!creating ? (
|
||||
<button
|
||||
type="button"
|
||||
className="flex min-h-[58px] w-full items-center justify-between gap-3 settings-list-inset py-3 text-left outline-none transition-colors settings-hover focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={callOrderBusy}
|
||||
onClick={(event) => {
|
||||
editorTriggerRef.current = event.currentTarget;
|
||||
setEditorRowKey(null);
|
||||
setEditorOpen(true);
|
||||
onBeginCreate();
|
||||
}}
|
||||
>
|
||||
<span className="inline-flex items-center gap-3 text-[14px] font-medium">
|
||||
<span className="grid w-10 shrink-0 place-items-center"><Plus className="h-5 w-5" aria-hidden /></span>
|
||||
{tx("settings.models.newPreset", "New model preset")}
|
||||
</span>
|
||||
{orderSaving ? (
|
||||
<SettingsStatusMessage>
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
{tx("settings.actions.saving", "Saving...")}
|
||||
</span>
|
||||
</SettingsStatusMessage>
|
||||
) : null}
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</SettingsGroup>
|
||||
</SettingsGroup>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<SettingsGroup>
|
||||
<div className="settings-list-inset py-8">
|
||||
<p className="text-[14px] font-medium text-foreground">{t("settings.models.noPresets")}</p>
|
||||
<p className="mt-2 text-[13px] leading-5 text-muted-foreground">{t("settings.models.newPresetHelp")}</p>
|
||||
</div>
|
||||
</SettingsGroup>
|
||||
)}
|
||||
<div className="settings-footer flex flex-wrap justify-end gap-2">
|
||||
{orderSaving ? (
|
||||
<span role="status" className="order-last w-full text-[12px] text-muted-foreground">
|
||||
<SettingsStatusMessage>
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
{t("settings.actions.saving")}
|
||||
</span>
|
||||
</SettingsStatusMessage>
|
||||
</span>
|
||||
) : null}
|
||||
{!showMigration ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="link"
|
||||
size="sm"
|
||||
className={cn("mr-auto h-11 gap-2 text-[13px] font-normal text-muted-foreground hover:font-semibold hover:text-orange-700 hover:no-underline dark:hover:text-orange-400 sm:h-9",
|
||||
hideEditorReturnFocus && "focus-visible:ring-0 focus-visible:ring-offset-0")}
|
||||
onKeyDown={(event) => { if (event.key !== "Escape") setHideEditorReturnFocus(false); }}
|
||||
disabled={callOrderBusy}
|
||||
onClick={(event) => {
|
||||
editorTriggerRef.current = event.currentTarget;
|
||||
setHideEditorReturnFocus(false);
|
||||
setEditorRowKey(null);
|
||||
setEditorOpen(true);
|
||||
onBeginCreate();
|
||||
}}
|
||||
>
|
||||
{tx("settings.models.newPreset", "New preset")}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button type="button" variant="link" size="sm"
|
||||
className="h-11 shrink-0 text-[13px] font-normal text-muted-foreground hover:font-semibold hover:text-orange-700 hover:no-underline dark:hover:text-orange-400 sm:h-9"
|
||||
onClick={(event) => onManageProviders(event.currentTarget)}>
|
||||
{t("settings.providers.manageProviders")}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
<Dialog open={editorOpen && (creating || selectedPreset !== null)} onOpenChange={(open) => {
|
||||
setEditorOpen(open);
|
||||
if (!open && creating) onCancelCreate();
|
||||
}}>
|
||||
<DialogContent aria-describedby={undefined}
|
||||
onEscapeKeyDown={() => setHideEditorReturnFocus(true)}
|
||||
className="relative max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none gap-0 overflow-y-auto p-0"
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
editorTriggerRef.current?.focus();
|
||||
}}>
|
||||
<DialogHeader className="px-6 pb-2 pt-5 pr-12">
|
||||
<DialogTitle>{creating ? tx("settings.models.newPreset", "New model preset") : selectedPreset?.name}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="settings-grid !px-0">{renderPresetEditor()}</div>
|
||||
<DialogTitle className="sr-only">
|
||||
{creating ? tx("settings.models.newPreset", "New model preset") : selectedPreset?.name}
|
||||
</DialogTitle>
|
||||
<div className="settings-grid !px-0 pt-8">{renderPresetEditor()}</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
@@ -906,107 +900,90 @@ function ModelAdvancedFields({
|
||||
maxTokens,
|
||||
contextWindowTokens,
|
||||
temperature,
|
||||
reasoningEffort,
|
||||
onChange,
|
||||
}: {
|
||||
maxTokens: number;
|
||||
contextWindowTokens: number;
|
||||
temperature: number;
|
||||
reasoningEffort: string;
|
||||
onChange: (
|
||||
value: Partial<
|
||||
Pick<
|
||||
AgentSettingsDraft,
|
||||
"maxTokens" | "contextWindowTokens" | "temperature" | "reasoningEffort"
|
||||
"maxTokens" | "contextWindowTokens" | "temperature"
|
||||
>
|
||||
>,
|
||||
) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const [contextDraft, setContextDraft] = useState<{ text: string; tokens: number } | null>(null);
|
||||
const contextWindowInputId = useId();
|
||||
const contextWindowHintId = `${contextWindowInputId}-hint`;
|
||||
const contextWindowValid = Number.isSafeInteger(contextWindowTokens) && contextWindowTokens > 0;
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<label className="block">
|
||||
<span className="mb-1.5 block text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.models.maxTokens", "Max output tokens")}
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
value={maxTokens}
|
||||
onChange={(event) => {
|
||||
const value = Number(event.target.value);
|
||||
if (Number.isFinite(value)) onChange({ maxTokens: value });
|
||||
}}
|
||||
className="h-9 text-[13px]"
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="mb-1.5 block text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.models.temperature", "Temperature")}
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={2}
|
||||
step={0.1}
|
||||
value={temperature}
|
||||
onChange={(event) => {
|
||||
const value = Number(event.target.value);
|
||||
if (Number.isFinite(value)) onChange({ temperature: value });
|
||||
}}
|
||||
className="h-9 text-[13px]"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor={contextWindowInputId} className="mb-1.5 block text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.rows.contextWindow", "Context window")}
|
||||
</label>
|
||||
<>
|
||||
<ModelTokenBudgetRow
|
||||
label={tx("settings.models.maxTokens", "Max output tokens")}
|
||||
value={maxTokens}
|
||||
onChange={(value) => onChange({ maxTokens: value })}
|
||||
/>
|
||||
<SettingsRow title={tx("settings.models.temperature", "Temperature")}>
|
||||
<Input
|
||||
id={contextWindowInputId}
|
||||
aria-label={tx("settings.models.temperature", "Temperature")}
|
||||
type="number"
|
||||
min={0}
|
||||
max={2}
|
||||
step={0.1}
|
||||
value={temperature}
|
||||
onChange={(event) => {
|
||||
const value = Number(event.target.value);
|
||||
if (Number.isFinite(value)) onChange({ temperature: value });
|
||||
}}
|
||||
className="h-9 text-[13px]"
|
||||
/>
|
||||
</SettingsRow>
|
||||
<ModelTokenBudgetRow
|
||||
label={tx("settings.rows.contextWindow", "Context window")}
|
||||
value={contextWindowTokens}
|
||||
onChange={(value) => onChange({ contextWindowTokens: value })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ModelTokenBudgetRow({ label, value, onChange }: {
|
||||
label: string;
|
||||
value: number;
|
||||
onChange: (value: number) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [draft, setDraft] = useState<{ text: string; tokens: number } | null>(null);
|
||||
const hintId = useId();
|
||||
const valid = Number.isSafeInteger(value) && value > 0;
|
||||
const hint = valid
|
||||
? t("settings.models.contextWindowHint", { tokens: value.toLocaleString() })
|
||||
: t("settings.models.contextWindowError");
|
||||
return (
|
||||
<SettingsRow title={label} description={valid ? hint : undefined}>
|
||||
<div className="w-full">
|
||||
<Input
|
||||
aria-label={label}
|
||||
type="text"
|
||||
autoCapitalize="none"
|
||||
spellCheck={false}
|
||||
required
|
||||
value={contextDraft && Object.is(contextDraft.tokens, contextWindowTokens)
|
||||
? contextDraft.text : formatContextWindowInput(contextWindowTokens)}
|
||||
value={draft && Object.is(draft.tokens, value) ? draft.text : formatContextWindowInput(value)}
|
||||
onChange={(event) => {
|
||||
const text = event.target.value;
|
||||
const tokens = parseContextWindowTokens(text);
|
||||
setContextDraft({ text, tokens });
|
||||
onChange({ contextWindowTokens: tokens });
|
||||
setDraft({ text, tokens });
|
||||
onChange(tokens);
|
||||
}}
|
||||
aria-invalid={!contextWindowValid}
|
||||
aria-describedby={contextWindowHintId}
|
||||
aria-invalid={!valid}
|
||||
aria-describedby={hintId}
|
||||
className="h-9 text-[13px]"
|
||||
/>
|
||||
<p id={contextWindowHintId} className={cn("mt-1.5 text-[12px]", contextWindowValid ? "text-muted-foreground" : "text-destructive")}>
|
||||
{contextWindowValid
|
||||
? t("settings.models.contextWindowHint", { tokens: contextWindowTokens.toLocaleString(), defaultValue: "{{tokens}} tokens" })
|
||||
: tx("settings.models.contextWindowError", "Enter a positive token count, such as 200k, 1m, or 131072.")}
|
||||
<p id={hintId} className={valid ? "sr-only" : "mt-1.5 px-3 text-[12px] text-destructive"}>
|
||||
{hint}
|
||||
</p>
|
||||
</div>
|
||||
<label className="block">
|
||||
<span className="mb-1.5 block text-[12px] font-medium text-muted-foreground">
|
||||
{tx("settings.models.reasoningEffort", "Reasoning effort")}
|
||||
</span>
|
||||
<Input
|
||||
value={reasoningEffort}
|
||||
onChange={(event) => onChange({ reasoningEffort: event.target.value })}
|
||||
placeholder={tx("settings.values.default", "Default")}
|
||||
autoCapitalize="none"
|
||||
spellCheck={false}
|
||||
className="h-9 text-[13px]"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</SettingsRow>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export function ProviderAPIControl({ value, onChange }: {
|
||||
const preferred = value?.preferred_api ?? supported[0];
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<fieldset className="space-y-3 rounded-xl border border-border/60 p-3">
|
||||
<fieldset className="space-y-3 rounded-floating border border-border/60 p-3">
|
||||
<legend className="px-1 text-[12px] font-medium text-muted-foreground">
|
||||
<SettingsHint description={t("settings.providers.supportedAPIsDescription")}>
|
||||
{t("settings.providers.supportedAPIs")}
|
||||
@@ -40,7 +40,7 @@ export function ProviderAPIControl({ value, onChange }: {
|
||||
})}
|
||||
</fieldset>
|
||||
<div className="space-y-1.5">
|
||||
<span className="text-[12px] font-medium text-muted-foreground">
|
||||
<span className="block px-3 text-[12px] font-medium text-muted-foreground">
|
||||
<SettingsHint description={t("settings.providers.defaultAPIDescription")}>
|
||||
{t("settings.providers.defaultAPI")}
|
||||
</SettingsHint>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
parseProviderObject,
|
||||
type ProviderAdvancedField,
|
||||
type ProviderForm,
|
||||
} from "@/components/settings/models/providerForm";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
|
||||
const PARAMETER_FIELDS = [
|
||||
{ field: "extra_headers", formKey: "extraHeaders", titleKey: "settings.providers.extraHeaders", placeholder: '{"X-Header":"value"}' },
|
||||
{ field: "extra_query", formKey: "extraQuery", titleKey: "settings.providers.extraQuery", placeholder: '{"api-version":"2024-02-01"}' },
|
||||
{ field: "extra_body", formKey: "extraBody", titleKey: "settings.providers.extraBody", placeholder: '{"service_tier":"priority"}' },
|
||||
] as const;
|
||||
|
||||
function parameterSummary(value: string, t: TFunction): string {
|
||||
if (!value.trim()) return t("settings.values.notConfigured");
|
||||
const parsed = parseProviderObject(value);
|
||||
return parsed
|
||||
? t("settings.providers.parameterCount", { count: Object.keys(parsed).length })
|
||||
: t("settings.values.configured");
|
||||
}
|
||||
|
||||
export function ProviderParameterFields({ fields, form, onChange }: {
|
||||
fields: ProviderAdvancedField[];
|
||||
form: ProviderForm;
|
||||
onChange: (value: Partial<ProviderForm>) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const visible = PARAMETER_FIELDS.filter((item) => fields.includes(item.field));
|
||||
if (!visible.length) return null;
|
||||
|
||||
return (
|
||||
<div className="min-w-0 overflow-hidden rounded-floating border border-border/60 md:col-span-2">
|
||||
{visible.map((item) => {
|
||||
const title = t(item.titleKey);
|
||||
return (
|
||||
<SettingsTextEditor key={item.field} title={title}
|
||||
value={form[item.formKey]} placeholder={item.placeholder}
|
||||
onSave={(value) => onChange({ [item.formKey]: value })}
|
||||
trigger={
|
||||
<button type="button" className="settings-hover flex min-h-12 w-full items-center gap-3 border-b border-border/60 px-3 py-3 text-left last:border-b-0">
|
||||
<span className="min-w-0 flex-1 text-[13px] font-medium">{title}</span>
|
||||
<span className="shrink-0 text-[12px] text-muted-foreground">{parameterSummary(form[item.formKey], t)}</span>
|
||||
<span className="shrink-0 text-[13px] text-muted-foreground">{t("settings.actions.edit")}</span>
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { useEffect, useId, useMemo, useRef } from "react";
|
||||
import { Plus, Search } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ProviderIcon } from "@/components/settings/shared/ProviderIcon";
|
||||
import { TruncatedTextTooltip } from "@/components/ui/tooltip";
|
||||
import { SearchInput } from "@/components/ui/input";
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import { useMediaQuery } from "@/hooks/useMediaQuery";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
|
||||
const PROVIDER_GROUPS = [
|
||||
{ id: "oauth", labelKey: "settings.providers.providerGroupOAuth", label: "OAuth" },
|
||||
{ id: "api_key", labelKey: "settings.providers.providerGroupApiKey", label: "API Key" },
|
||||
{ id: "local", labelKey: "settings.providers.providerGroupLocal", label: "Local" },
|
||||
] as const;
|
||||
|
||||
|
||||
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: "蚂蚁 螞蟻 百灵 百靈",
|
||||
};
|
||||
|
||||
export function ProviderSearchList({ providers, showBrandLogos, query, onQueryChange, onSelect, onCustom, onClose }: {
|
||||
providers: SettingsPayload["providers"];
|
||||
showBrandLogos: boolean;
|
||||
query: string;
|
||||
onQueryChange: (query: string) => void;
|
||||
onSelect: (name: string) => void;
|
||||
onCustom: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const mobile = useMediaQuery("(max-width: 639px)");
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const groupId = useId();
|
||||
useEffect(() => {
|
||||
if (!mobile) inputRef.current?.focus({ preventScroll: true });
|
||||
}, [mobile]);
|
||||
const filtered = useMemo(() => {
|
||||
const normalize = (value: string) => value.toLocaleLowerCase().replace(/[\s_.-]+/g, "");
|
||||
const normalizedQuery = normalize(query);
|
||||
return providers.filter((provider) => normalize(
|
||||
`${provider.name} ${provider.label} ${PROVIDER_SEARCH_ALIASES[provider.name] ?? ""}`,
|
||||
).includes(normalizedQuery));
|
||||
}, [providers, query]);
|
||||
const groups = useMemo(() => PROVIDER_GROUPS.map((group) => ({
|
||||
...group,
|
||||
providers: filtered.filter((provider) => providerGroup(provider) === group.id),
|
||||
})).filter((group) => group.providers.length > 0), [filtered]);
|
||||
const values = useMemo(
|
||||
() => groups.flatMap((group) => group.providers.map((provider) => provider.name)),
|
||||
[groups],
|
||||
);
|
||||
const { inputProps, listProps, getOptionProps } = useComboboxNavigation({
|
||||
open: true, values, onSelect, onClose,
|
||||
});
|
||||
const searchLabel = t("settings.providers.searchPlaceholder", { defaultValue: "Search providers" });
|
||||
return <>
|
||||
<div className="mb-3 shrink-0 overflow-y-auto px-5 scrollbar-thin scrollbar-track-transparent">
|
||||
<div className="relative">
|
||||
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
|
||||
<SearchInput {...inputProps} ref={inputRef} value={query} onChange={(event) => onQueryChange(event.target.value)}
|
||||
aria-label={searchLabel} placeholder={searchLabel}
|
||||
className="rounded-xl border-transparent bg-muted/60 pl-9" />
|
||||
</div>
|
||||
</div>
|
||||
<div {...listProps} aria-label={searchLabel}
|
||||
className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 pb-3 scrollbar-thin scrollbar-track-transparent">
|
||||
<div className="space-y-4">
|
||||
{groups.map((group) => (
|
||||
<div key={group.id} role="group" aria-labelledby={`${groupId}-${group.id}`}>
|
||||
<div id={`${groupId}-${group.id}`} className="px-2 pb-1 text-[11px] font-medium text-muted-foreground sm:px-3">
|
||||
{t(group.labelKey, { defaultValue: group.label })}
|
||||
</div>
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(100%,9rem),1fr))] gap-x-2 gap-y-0.5">
|
||||
{group.providers.map((provider) => <ComboboxOption key={provider.name} {...getOptionProps(provider.name)}
|
||||
aria-label={provider.label}
|
||||
className="min-h-11 min-w-0 gap-2 rounded-xl px-2 py-2 text-[13px] font-normal sm:gap-3 sm:px-3 sm:text-sm">
|
||||
<ProviderIcon provider={provider.name} showBrandLogos={showBrandLogos} compact />
|
||||
<TruncatedTextTooltip text={provider.label} className="flex-1" />
|
||||
</ComboboxOption>)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{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 overflow-y-auto border-t border-border/50 px-5 py-3 scrollbar-thin scrollbar-track-transparent">
|
||||
<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>
|
||||
</button>
|
||||
</div>
|
||||
</>;
|
||||
}
|
||||
|
||||
function providerGroup(provider: SettingsPayload["providers"][number]): typeof PROVIDER_GROUPS[number]["id"] {
|
||||
if (provider.auth_type === "oauth") return "oauth";
|
||||
return provider.model_catalog === "local" ? "local" : "api_key";
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,103 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { Check } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Popover, PopoverAnchor, PopoverContent } from "@/components/ui/popover";
|
||||
import { useProviderModelCatalog } from "@/hooks/useProviderModelCatalog";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
|
||||
const NO_PROVIDER = {};
|
||||
const DEFAULT_VALUE = ":default";
|
||||
|
||||
export function ReasoningEffortPicker({ token, provider, model, savedValues, value, onChange }: {
|
||||
token: string;
|
||||
provider: SettingsPayload["providers"][number] | undefined;
|
||||
model: string;
|
||||
savedValues?: string[];
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const typing = useRef(false);
|
||||
const restoreFocus = useRef(false);
|
||||
const { payload } = useProviderModelCatalog({
|
||||
revision: provider ?? NO_PROVIDER,
|
||||
token,
|
||||
provider: provider?.name ?? "",
|
||||
enabled: open && !!model && !!provider?.configured && provider.model_catalog !== "unsupported",
|
||||
});
|
||||
const efforts = payload?.models.find((entry) => entry.id === model)?.reasoning_efforts ?? savedValues ?? [];
|
||||
const values = [DEFAULT_VALUE, ...new Set(efforts.filter(Boolean))];
|
||||
const close = () => { restoreFocus.current = true; setOpen(false); };
|
||||
const navigation = useComboboxNavigation({
|
||||
open,
|
||||
values,
|
||||
selectedValue: value || DEFAULT_VALUE,
|
||||
onSelect: (selected) => { onChange(selected === DEFAULT_VALUE ? "" : selected); close(); },
|
||||
onClose: close,
|
||||
});
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverAnchor asChild>
|
||||
<div className="w-full">
|
||||
<Input
|
||||
ref={input}
|
||||
{...navigation.inputProps}
|
||||
aria-label={t("settings.models.reasoningEffort")}
|
||||
value={value}
|
||||
placeholder={t("settings.values.default")}
|
||||
autoComplete="off"
|
||||
autoCapitalize="none"
|
||||
spellCheck={false}
|
||||
onClick={() => { typing.current = false; setOpen(true); }}
|
||||
onChange={(event) => { typing.current = true; onChange(event.target.value); }}
|
||||
onKeyDown={(event) => {
|
||||
if (event.nativeEvent.isComposing) return;
|
||||
if (!open && ["ArrowDown", "ArrowUp", "Enter"].includes(event.key)) {
|
||||
event.preventDefault();
|
||||
typing.current = false;
|
||||
setOpen(true);
|
||||
return;
|
||||
}
|
||||
if (!open) return;
|
||||
if (event.key === "Enter" && typing.current) {
|
||||
event.preventDefault();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (["ArrowDown", "ArrowUp"].includes(event.key)) typing.current = false;
|
||||
navigation.inputProps.onKeyDown(event);
|
||||
}}
|
||||
className="h-9 text-[13px]"
|
||||
/>
|
||||
</div>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent
|
||||
align="end"
|
||||
className="w-[var(--radix-popover-trigger-width)] max-w-[calc(100vw-2rem)] p-1.5"
|
||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
if (restoreFocus.current) input.current?.focus({ preventScroll: true });
|
||||
restoreFocus.current = false;
|
||||
}}
|
||||
onEscapeKeyDown={() => { restoreFocus.current = true; }}
|
||||
onInteractOutside={(event) => { if (event.target === input.current) event.preventDefault(); }}
|
||||
>
|
||||
<div {...navigation.listProps}>
|
||||
{values.map((effort) => (
|
||||
<ComboboxOption key={effort} {...navigation.getOptionProps(effort)}
|
||||
className="flex items-center justify-between gap-2 px-3 py-2 text-[13px]">
|
||||
<span>{effort === DEFAULT_VALUE ? t("settings.values.default") : effort}</span>
|
||||
{effort === (value || DEFAULT_VALUE) ? <Check className="h-4 w-4" aria-hidden /> : null}
|
||||
</ComboboxOption>
|
||||
))}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { ModelAPIConfig, SettingsPayload } from "@/lib/types";
|
||||
|
||||
export type ProviderAdvancedField = NonNullable<
|
||||
SettingsPayload["providers"][number]["advanced_fields"]
|
||||
>[number];
|
||||
export type ProviderForm = {
|
||||
displayName: string;
|
||||
apiKey: string;
|
||||
apiBase: string;
|
||||
api: ModelAPIConfig | null;
|
||||
proxy: string;
|
||||
extraHeaders: string;
|
||||
extraBody: string;
|
||||
extraQuery: string;
|
||||
thinkingStyle: string;
|
||||
region: string;
|
||||
profile: string;
|
||||
};
|
||||
export type CustomProviderDraft = ProviderForm & { name: string };
|
||||
export const CUSTOM_PROVIDER_CREATION_KEY = "__custom_provider__";
|
||||
|
||||
export function providerJsonValue(value: Record<string, unknown> | null | undefined): string {
|
||||
return value && Object.keys(value).length > 0 ? JSON.stringify(value, null, 2) : "";
|
||||
}
|
||||
|
||||
export function parseProviderObject(value: string): Record<string, unknown> | null {
|
||||
if (!value.trim()) return {};
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(value);
|
||||
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
||||
? parsed as Record<string, unknown>
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function providerFormFromRow(
|
||||
provider: SettingsPayload["providers"][number],
|
||||
): ProviderForm {
|
||||
return {
|
||||
displayName: provider.is_custom ? provider.label : "",
|
||||
apiKey: "",
|
||||
apiBase: provider.api_base ?? provider.default_api_base ?? "",
|
||||
api: provider.api ?? null,
|
||||
proxy: provider.proxy ?? "",
|
||||
extraHeaders: providerJsonValue(provider.extra_headers),
|
||||
extraBody: providerJsonValue(provider.extra_body),
|
||||
extraQuery: providerJsonValue(provider.extra_query),
|
||||
thinkingStyle: provider.thinking_style ?? "",
|
||||
region: provider.region ?? "",
|
||||
profile: provider.profile ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
export function emptyCustomProviderDraft(): CustomProviderDraft {
|
||||
return {
|
||||
name: "",
|
||||
displayName: "",
|
||||
apiKey: "",
|
||||
apiBase: "",
|
||||
api: { supported_apis: ["chat_completions"], preferred_api: "chat_completions" },
|
||||
proxy: "",
|
||||
extraHeaders: "",
|
||||
extraBody: "",
|
||||
extraQuery: "",
|
||||
thinkingStyle: "",
|
||||
region: "",
|
||||
profile: "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type PointerEvent } from "react";
|
||||
|
||||
interface PresetDrag {
|
||||
key: string;
|
||||
surface: HTMLElement;
|
||||
pointerId: number;
|
||||
startY: number;
|
||||
pointerY: number;
|
||||
grabOffset: number;
|
||||
active: boolean;
|
||||
keys: string[];
|
||||
}
|
||||
|
||||
export function useModelPresetDrag({
|
||||
keys, disabled, onReorder,
|
||||
}: {
|
||||
keys: string[];
|
||||
disabled: boolean;
|
||||
onReorder: (keys: string[]) => void;
|
||||
}) {
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
const drag = useRef<PresetDrag | null>(null);
|
||||
const frame = useRef<number>();
|
||||
const suppressClick = useRef(false);
|
||||
const positions = useRef<Map<string, DOMRect> | null>(null);
|
||||
const animations = useRef(new Map<string, Animation>());
|
||||
const [preview, setPreview] = useState<{ key: string; keys: string[] } | null>(null);
|
||||
|
||||
const surfaces = () => Array.from(
|
||||
listRef.current?.querySelectorAll<HTMLElement>("[data-preset-sort-surface]") ?? [],
|
||||
);
|
||||
const rememberPositions = () => {
|
||||
positions.current = new Map(surfaces().map((element) => [
|
||||
element.dataset.presetSortSurface!, element.getBoundingClientRect(),
|
||||
]));
|
||||
for (const animation of animations.current.values()) animation.cancel();
|
||||
animations.current.clear();
|
||||
};
|
||||
const followPointer = () => {
|
||||
const current = drag.current;
|
||||
if (!current?.active) return;
|
||||
const surface = current.surface;
|
||||
const top = surface.parentElement!.getBoundingClientRect().top;
|
||||
surface.style.transform = `translateY(${current.pointerY - current.grabOffset - top}px)`;
|
||||
};
|
||||
const trackPointer = () => {
|
||||
followPointer();
|
||||
frame.current = requestAnimationFrame(trackPointer);
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const previous = positions.current;
|
||||
if (!previous) return;
|
||||
positions.current = null;
|
||||
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
for (const element of surfaces()) {
|
||||
const key = element.dataset.presetSortSurface!;
|
||||
const dragging = key === drag.current?.key && drag.current.active;
|
||||
if (!dragging) element.style.transform = "";
|
||||
const before = previous.get(key);
|
||||
if (!before || reduceMotion || typeof element.animate !== "function") continue;
|
||||
const after = element.getBoundingClientRect();
|
||||
const offset = dragging ? 0 : before.top - after.top;
|
||||
const resized = Math.abs(before.height - after.height) >= 0.5;
|
||||
if (Math.abs(offset) < 0.5 && !resized) continue;
|
||||
// Animate visual size, not layout height, so section headings stay still.
|
||||
// Pointer tracking owns the dragged card's translation throughout.
|
||||
const from: Keyframe = { scale: `1 ${before.height / after.height}` };
|
||||
const to: Keyframe = { scale: "1 1" };
|
||||
if (!dragging) {
|
||||
from.transform = `translateY(${offset}px)`;
|
||||
to.transform = "translateY(0)";
|
||||
}
|
||||
const animation = element.animate(
|
||||
[from, to],
|
||||
{ duration: 240, easing: "cubic-bezier(0.2, 0, 0, 1)" },
|
||||
);
|
||||
animations.current.set(key, animation);
|
||||
animation.addEventListener("finish", () => {
|
||||
if (animations.current.get(key) === animation) animations.current.delete(key);
|
||||
}, { once: true });
|
||||
}
|
||||
followPointer();
|
||||
}, [preview]);
|
||||
|
||||
useEffect(() => () => {
|
||||
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
||||
for (const animation of animations.current.values()) animation.cancel();
|
||||
}, []);
|
||||
|
||||
const finish = (save: boolean) => {
|
||||
const current = drag.current;
|
||||
if (!current) return;
|
||||
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
||||
if (current.active) rememberPositions();
|
||||
drag.current = null;
|
||||
if (listRef.current?.hasPointerCapture(current.pointerId)) {
|
||||
listRef.current.releasePointerCapture(current.pointerId);
|
||||
}
|
||||
if (!current.active) return;
|
||||
setPreview(null);
|
||||
if (save && !disabled) onReorder(current.keys);
|
||||
};
|
||||
|
||||
return {
|
||||
listRef,
|
||||
previewKeys: preview?.keys ?? keys,
|
||||
draggedKey: preview?.key,
|
||||
start: (event: PointerEvent, key: string) => {
|
||||
if (disabled || event.button !== 0 || !keys.includes(key)
|
||||
|| (event.target as HTMLElement).closest('[role="switch"]')) return;
|
||||
const surface = surfaces().find((element) => element.dataset.presetSortSurface === key)!;
|
||||
drag.current = {
|
||||
key, surface, pointerId: event.pointerId, startY: event.clientY, pointerY: event.clientY,
|
||||
grabOffset: event.clientY - surface.getBoundingClientRect().top,
|
||||
active: false, keys,
|
||||
};
|
||||
},
|
||||
listProps: {
|
||||
onPointerDownCapture: () => { suppressClick.current = false; },
|
||||
onPointerMove: (event: PointerEvent<HTMLDivElement>) => {
|
||||
const current = drag.current;
|
||||
if (!current || current.pointerId !== event.pointerId || disabled) return;
|
||||
if (!event.buttons) { finish(false); return; }
|
||||
current.pointerY = event.clientY;
|
||||
if (!current.active) {
|
||||
if (Math.abs(current.pointerY - current.startY) < 5) return;
|
||||
rememberPositions();
|
||||
current.active = true;
|
||||
suppressClick.current = true;
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
setPreview({ key: current.key, keys: current.keys });
|
||||
trackPointer();
|
||||
}
|
||||
event.preventDefault();
|
||||
const otherRows = Array.from(event.currentTarget.querySelectorAll<HTMLElement>("[data-preset-sort-key]"))
|
||||
.filter((element) => element.dataset.presetSortKey !== current.key
|
||||
&& keys.includes(element.dataset.presetSortKey!));
|
||||
const index = otherRows.filter((element) => {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return current.pointerY > rect.top + rect.height / 2;
|
||||
}).length;
|
||||
if (index !== current.keys.indexOf(current.key)) {
|
||||
rememberPositions();
|
||||
const next = current.keys.filter((key) => key !== current.key);
|
||||
next.splice(index, 0, current.key);
|
||||
current.keys = next;
|
||||
setPreview({ key: current.key, keys: next });
|
||||
}
|
||||
followPointer();
|
||||
},
|
||||
onPointerUp: () => finish(true),
|
||||
onPointerCancel: () => finish(false),
|
||||
onLostPointerCapture: () => finish(false),
|
||||
onClickCapture: (event: MouseEvent) => {
|
||||
if (!suppressClick.current) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
suppressClick.current = false;
|
||||
},
|
||||
onKeyDownCapture: (event: KeyboardEvent) => {
|
||||
suppressClick.current = false;
|
||||
if (event.key === "Escape" && drag.current?.active) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
finish(false);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
CUSTOM_PROVIDER_CREATION_KEY,
|
||||
providerFormFromRow,
|
||||
type CustomProviderDraft,
|
||||
} from "@/components/settings/models/ProviderSettings";
|
||||
} from "@/components/settings/models/providerForm";
|
||||
import type { ModelSettingsState } from "@/components/settings/models/useModelSettingsState";
|
||||
import { normalizeContextWindowTokens } from "@/components/settings/shared/ModelControls";
|
||||
import {
|
||||
@@ -90,7 +90,6 @@ export function useModelSettingsActions({
|
||||
return () => { oauthMounted.current = false; };
|
||||
}, []);
|
||||
const {
|
||||
expandedProvider,
|
||||
form,
|
||||
modelCallOrder,
|
||||
modelCallOrderSaving,
|
||||
@@ -107,7 +106,6 @@ export function useModelSettingsActions({
|
||||
providerSaving,
|
||||
saving,
|
||||
setEditingProviderKeys,
|
||||
setExpandedProvider,
|
||||
setForm,
|
||||
setModelCallOrder,
|
||||
setModelCallOrderSaving,
|
||||
@@ -122,7 +120,7 @@ export function useModelSettingsActions({
|
||||
setProviderOAuthDialogError,
|
||||
setProviderOAuthFlow,
|
||||
setProviderOAuthResponse,
|
||||
setProviderSaving,
|
||||
setProviderOperation,
|
||||
setSaving,
|
||||
setVisibleProviderKeys,
|
||||
visibleProviderKeys,
|
||||
@@ -161,6 +159,8 @@ export function useModelSettingsActions({
|
||||
saving ||
|
||||
modelCallOrderSaving ||
|
||||
modelConfigurationSaving ||
|
||||
!Number.isSafeInteger(form.maxTokens) ||
|
||||
form.maxTokens <= 0 ||
|
||||
!Number.isSafeInteger(form.contextWindowTokens) ||
|
||||
form.contextWindowTokens <= 0
|
||||
) {
|
||||
@@ -367,7 +367,7 @@ export function useModelSettingsActions({
|
||||
modelCallOrderSaving ||
|
||||
modelConfigurationSaving
|
||||
) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
@@ -375,33 +375,34 @@ export function useModelSettingsActions({
|
||||
applyPayload(payload);
|
||||
setModelPresetPendingDelete(null);
|
||||
setError(null);
|
||||
return true;
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
return false;
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveProvider = async (providerName: string) => {
|
||||
if (providerSaving) return;
|
||||
const saveProvider = async (providerName: string): Promise<boolean> => {
|
||||
if (providerSaving) return false;
|
||||
const provider = settings?.providers.find((item) => item.name === providerName);
|
||||
if (!provider) return;
|
||||
if (!provider) return false;
|
||||
const isOauthProvider = provider.auth_type === "oauth";
|
||||
const providerForm = providerForms[providerName] ?? providerFormFromRow(provider);
|
||||
const apiKey = providerForm.apiKey.trim();
|
||||
const apiKeyRequired = provider.api_key_required ?? true;
|
||||
if (!isOauthProvider && !provider.configured && apiKeyRequired && !apiKey) {
|
||||
if (!isOauthProvider && !provider.configured && (provider.api_key_required ?? true) && !apiKey) {
|
||||
setError(t("settings.byok.apiKeyRequired"));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
setProviderSaving(providerName);
|
||||
setProviderOperation({ provider: providerName, action: "save" });
|
||||
try {
|
||||
const supportName = providerName === "bedrock"
|
||||
? "bedrock"
|
||||
: providerName === "azure_openai"
|
||||
? "azure"
|
||||
: null;
|
||||
if (supportName && !(await installCapabilities([supportName]))) return;
|
||||
if (supportName && !(await installCapabilities([supportName]))) return false;
|
||||
const update: ProviderSettingsUpdate = { provider: providerName };
|
||||
if (!isOauthProvider) {
|
||||
update.apiKey = apiKey || undefined;
|
||||
@@ -423,38 +424,31 @@ export function useModelSettingsActions({
|
||||
if (field === "profile") update.profile = providerForm.profile.trim();
|
||||
}
|
||||
const payload = await updateProviderSettings(client, update);
|
||||
applyPayload(payload);
|
||||
applyPayload(payload, { preserveAgentForm: true });
|
||||
if (payload.requires_restart) {
|
||||
setPendingRestartSections((prev) => ({ ...prev, image: true }));
|
||||
}
|
||||
await maybeRestartHostEngine(payload);
|
||||
setProviderForms((prev) => ({
|
||||
...prev,
|
||||
[providerName]: {
|
||||
...providerForm,
|
||||
displayName: providerForm.displayName.trim(),
|
||||
apiKey: "",
|
||||
apiBase: providerForm.apiBase.trim(),
|
||||
proxy: providerForm.proxy.trim(),
|
||||
thinkingStyle: providerForm.thinkingStyle.trim(),
|
||||
region: providerForm.region.trim(),
|
||||
profile: providerForm.profile.trim(),
|
||||
},
|
||||
}));
|
||||
setProviderForms((prev) => {
|
||||
const next = { ...prev };
|
||||
delete next[providerName];
|
||||
return next;
|
||||
});
|
||||
setVisibleProviderKeys((prev) => ({ ...prev, [providerName]: false }));
|
||||
setEditingProviderKeys((prev) => ({ ...prev, [providerName]: false }));
|
||||
if (!isOauthProvider) setExpandedProvider(null);
|
||||
setError(null);
|
||||
return true;
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
return false;
|
||||
} finally {
|
||||
setProviderSaving(null);
|
||||
setProviderOperation(null);
|
||||
}
|
||||
};
|
||||
|
||||
const createCustomProvider = async (draft: CustomProviderDraft): Promise<boolean> => {
|
||||
if (providerSaving) return false;
|
||||
setProviderSaving(CUSTOM_PROVIDER_CREATION_KEY);
|
||||
const createCustomProvider = async (draft: CustomProviderDraft): Promise<SettingsPayload | null> => {
|
||||
if (providerSaving) return null;
|
||||
setProviderOperation({ provider: CUSTOM_PROVIDER_CREATION_KEY, action: "create" });
|
||||
try {
|
||||
const payload = await createProviderSettings(client, {
|
||||
name: draft.name.trim(),
|
||||
@@ -467,15 +461,14 @@ export function useModelSettingsActions({
|
||||
extraQuery: draft.extraQuery.trim(),
|
||||
thinkingStyle: draft.thinkingStyle.trim(),
|
||||
});
|
||||
applyPayload(payload);
|
||||
setExpandedProvider(null);
|
||||
applyPayload(payload, { preserveAgentForm: true });
|
||||
setError(null);
|
||||
return true;
|
||||
return payload;
|
||||
} catch (err) {
|
||||
setError((err as Error).message);
|
||||
return false;
|
||||
return null;
|
||||
} finally {
|
||||
setProviderSaving(null);
|
||||
setProviderOperation(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -494,7 +487,7 @@ export function useModelSettingsActions({
|
||||
popup = null;
|
||||
}
|
||||
}
|
||||
setProviderSaving(providerName);
|
||||
setProviderOperation({ provider: providerName, action });
|
||||
try {
|
||||
const payload =
|
||||
action === "login"
|
||||
@@ -523,13 +516,13 @@ export function useModelSettingsActions({
|
||||
}
|
||||
popup?.close();
|
||||
closeProviderOAuthFlow(false);
|
||||
applyPayload(payload, { preserveAgentForm: action === "login" });
|
||||
applyPayload(payload, { preserveAgentForm: true });
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
popup?.close();
|
||||
setError((err as Error).message);
|
||||
} finally {
|
||||
setProviderSaving(null);
|
||||
setProviderOperation(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -571,30 +564,21 @@ export function useModelSettingsActions({
|
||||
setEditingProviderKeys((prev) => ({ ...prev, [providerName]: false }));
|
||||
}, [settings]);
|
||||
|
||||
const handleToggleProvider = useCallback((providerName: string) => {
|
||||
if (expandedProvider) resetProviderDraft(expandedProvider);
|
||||
setExpandedProvider(expandedProvider === providerName ? null : providerName);
|
||||
}, [expandedProvider, resetProviderDraft]);
|
||||
|
||||
const toggleProviderKeyVisibility = (providerName: string) => {
|
||||
const isVisible = visibleProviderKeys[providerName];
|
||||
setVisibleProviderKeys((prev) => ({ ...prev, [providerName]: !isVisible }));
|
||||
};
|
||||
|
||||
const toggleProviderKeyEditing = (providerName: string) => {
|
||||
const provider = settings?.providers.find((row) => row.name === providerName);
|
||||
if (!provider) return;
|
||||
setEditingProviderKeys((prev) => {
|
||||
const nextEditing = !prev[providerName];
|
||||
if (!nextEditing) {
|
||||
setProviderForms((forms) => ({
|
||||
...forms,
|
||||
[providerName]: {
|
||||
...(forms[providerName] ?? providerFormFromRow(
|
||||
settings?.providers.find((provider) => provider.name === providerName) ?? {
|
||||
name: providerName,
|
||||
label: providerName,
|
||||
configured: false,
|
||||
},
|
||||
)),
|
||||
...(forms[providerName] ?? providerFormFromRow(provider)),
|
||||
apiKey: "",
|
||||
},
|
||||
}));
|
||||
@@ -612,7 +596,6 @@ export function useModelSettingsActions({
|
||||
createCustomProvider,
|
||||
handleDeleteModelConfiguration,
|
||||
handleMigrateModelConfigurations,
|
||||
handleToggleProvider,
|
||||
resetProviderDraft,
|
||||
runProviderOAuth,
|
||||
saveModelSettings,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, type Dispatch, type SetStateAction } from "react";
|
||||
|
||||
import type { ApplySettingsPayload } from "@/components/settings/contracts";
|
||||
import { providerFormFromRow } from "@/components/settings/models/ProviderSettings";
|
||||
import { providerFormFromRow } from "@/components/settings/models/providerForm";
|
||||
import type { ModelSettingsState } from "@/components/settings/models/useModelSettingsState";
|
||||
import { cancelProviderOAuth, completeProviderOAuth } from "@/lib/api";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
@@ -91,9 +91,9 @@ export function useProviderFormsSync(
|
||||
useEffect(() => {
|
||||
if (!settings) return;
|
||||
setProviderForms((prev) => {
|
||||
const next = { ...prev };
|
||||
const next: typeof prev = {};
|
||||
for (const provider of settings.providers) {
|
||||
next[provider.name] = next[provider.name] ?? providerFormFromRow(provider);
|
||||
next[provider.name] = prev[provider.name] ?? providerFormFromRow(provider);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
|
||||
@@ -5,9 +5,14 @@ import {
|
||||
agentDraftFromPayload,
|
||||
type AgentSettingsDraft,
|
||||
} from "@/components/settings/models/ModelsSettings";
|
||||
import type { ProviderForm } from "@/components/settings/models/ProviderSettings";
|
||||
import type { ProviderForm } from "@/components/settings/models/providerForm";
|
||||
import type { ProviderOAuthAuthorizationRequired, SettingsPayload } from "@/lib/types";
|
||||
|
||||
export interface ProviderOperation {
|
||||
provider: string;
|
||||
action: "save" | "create" | "login" | "logout";
|
||||
}
|
||||
|
||||
export function useModelSettingsState(initialSettings: SettingsPayload | null) {
|
||||
const initialForm = initialSettings
|
||||
? agentDraftFromPayload(initialSettings)
|
||||
@@ -21,14 +26,14 @@ export function useModelSettingsState(initialSettings: SettingsPayload | null) {
|
||||
const [modelPresetPendingDelete, setModelPresetPendingDelete] =
|
||||
useState<SettingsPayload["model_presets"][number] | null>(null);
|
||||
const modelPresetBeforeCreateRef = useRef<string | null>(null);
|
||||
const [providerSaving, setProviderSaving] = useState<string | null>(null);
|
||||
const [providerOperation, setProviderOperation] = useState<ProviderOperation | null>(null);
|
||||
const providerSaving = providerOperation?.provider ?? null;
|
||||
const [providerOAuthFlow, setProviderOAuthFlow] =
|
||||
useState<ProviderOAuthAuthorizationRequired | null>(null);
|
||||
const providerOAuthFlowRef = useRef<ProviderOAuthAuthorizationRequired | null>(null);
|
||||
const [providerOAuthResponse, setProviderOAuthResponse] = useState("");
|
||||
const [providerOAuthCompleting, setProviderOAuthCompleting] = useState(false);
|
||||
const [providerOAuthDialogError, setProviderOAuthDialogError] = useState<string | null>(null);
|
||||
const [expandedProvider, setExpandedProvider] = useState<string | null>(null);
|
||||
const [providerForms, setProviderForms] = useState<Record<string, ProviderForm>>({});
|
||||
const [visibleProviderKeys, setVisibleProviderKeys] = useState<Record<string, boolean>>({});
|
||||
const [editingProviderKeys, setEditingProviderKeys] = useState<Record<string, boolean>>({});
|
||||
@@ -42,7 +47,6 @@ export function useModelSettingsState(initialSettings: SettingsPayload | null) {
|
||||
|
||||
return {
|
||||
editingProviderKeys,
|
||||
expandedProvider,
|
||||
form,
|
||||
modelCallOrder,
|
||||
modelCallOrderSaving,
|
||||
@@ -60,9 +64,9 @@ export function useModelSettingsState(initialSettings: SettingsPayload | null) {
|
||||
providerOAuthFlowRef,
|
||||
providerOAuthResponse,
|
||||
providerSaving,
|
||||
providerOperation,
|
||||
saving,
|
||||
setEditingProviderKeys,
|
||||
setExpandedProvider,
|
||||
setForm,
|
||||
setModelCallOrder,
|
||||
setModelCallOrderSaving,
|
||||
@@ -77,7 +81,7 @@ export function useModelSettingsState(initialSettings: SettingsPayload | null) {
|
||||
setProviderOAuthDialogError,
|
||||
setProviderOAuthFlow,
|
||||
setProviderOAuthResponse,
|
||||
setProviderSaving,
|
||||
setProviderOperation,
|
||||
setSaving,
|
||||
setVisibleProviderKeys,
|
||||
visibleProviderKeys,
|
||||
|
||||
@@ -1,41 +1,31 @@
|
||||
import { useEffect, useId, useMemo, useRef, useState, type ComponentProps } from "react";
|
||||
import {
|
||||
Bot,
|
||||
Brain,
|
||||
Check,
|
||||
CircleAlert,
|
||||
Cloud,
|
||||
Cpu,
|
||||
Database,
|
||||
Gem,
|
||||
Grid3X3,
|
||||
Hexagon,
|
||||
Layers,
|
||||
Loader2,
|
||||
Moon,
|
||||
Orbit,
|
||||
Pencil,
|
||||
Search,
|
||||
Sparkles,
|
||||
Triangle,
|
||||
Waves,
|
||||
Zap,
|
||||
type LucideIcon,
|
||||
Plus,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ControlChevron } from "@/components/ui/control-chevron";
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
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";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { fetchProviderModels } from "@/lib/api";
|
||||
import { useProviderModelCatalog } from "@/hooks/useProviderModelCatalog";
|
||||
import { formatContextWindow } from "@/lib/model-context-format";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
import { PROVIDER_ICONS } from "@/lib/provider-icons";
|
||||
import type { ProviderModelsPayload, SettingsPayload } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export { formatContextWindow, formatModelContextWindow } from "@/lib/model-context-format";
|
||||
export { PROVIDER_ICONS } from "@/lib/provider-icons";
|
||||
|
||||
const DEFERRED_MODEL_LIST_PROVIDERS = new Set([
|
||||
"aihubmix",
|
||||
"atomic_chat",
|
||||
@@ -88,16 +78,10 @@ export function settingsProviderConfigured(
|
||||
provider: string | null | undefined,
|
||||
resolvedProvider?: string | null,
|
||||
): boolean {
|
||||
const row = settingsProviderRow(payload, provider);
|
||||
if (row) return row.configured;
|
||||
if (provider === "auto") {
|
||||
const resolvedRow = settingsProviderRow(
|
||||
payload,
|
||||
resolvedProvider ?? payload.agent.resolved_provider ?? payload.agent.provider,
|
||||
);
|
||||
if (resolvedRow) return resolvedRow.configured;
|
||||
}
|
||||
return payload.agent.has_api_key;
|
||||
const concreteProvider = provider === "auto"
|
||||
? resolvedProvider ?? payload.agent.resolved_provider ?? payload.agent.provider
|
||||
: provider;
|
||||
return settingsProviderRow(payload, concreteProvider)?.configured ?? false;
|
||||
}
|
||||
|
||||
export function ProviderPicker({
|
||||
@@ -107,6 +91,8 @@ export function ProviderPicker({
|
||||
emptyLabel,
|
||||
showProviderLogos = false,
|
||||
onChange,
|
||||
onAddProvider,
|
||||
onConfigureProvider,
|
||||
}: {
|
||||
providers: Array<{ name: string; label: string }>;
|
||||
value: string;
|
||||
@@ -114,13 +100,27 @@ export function ProviderPicker({
|
||||
emptyLabel: string;
|
||||
showProviderLogos?: boolean;
|
||||
onChange: (provider: string) => void;
|
||||
onAddProvider?: (trigger: HTMLButtonElement | null) => void;
|
||||
onConfigureProvider?: (provider: string, trigger: HTMLButtonElement | null) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
const openingProviderSetup = useRef(false);
|
||||
const selectedProvider = providers.find((provider) => provider.name === value) ?? null;
|
||||
const disabled = !!triggerProps?.disabled || providers.length === 0;
|
||||
const disabled = !!triggerProps?.disabled || (providers.length === 0 && !onAddProvider);
|
||||
|
||||
return (
|
||||
<Select value={value} onValueChange={onChange} disabled={disabled}>
|
||||
<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}>
|
||||
<SelectTrigger
|
||||
ref={triggerRef}
|
||||
{...triggerProps}
|
||||
aria-label={triggerProps?.["aria-label"] ?? selectedProvider?.label ?? emptyLabel}
|
||||
type="button"
|
||||
@@ -141,7 +141,12 @@ export function ProviderPicker({
|
||||
<span className="truncate">{selectedProvider?.label ?? emptyLabel}</span>
|
||||
</span></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectContent onCloseAutoFocus={(event) => {
|
||||
if (openingProviderSetup.current) {
|
||||
event.preventDefault();
|
||||
openingProviderSetup.current = false;
|
||||
}
|
||||
}}>
|
||||
{providers.map((provider) => {
|
||||
return (
|
||||
<SelectItem
|
||||
@@ -160,6 +165,21 @@ export function ProviderPicker({
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
{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}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
@@ -190,19 +210,16 @@ export function ModelIdPicker({
|
||||
emptyMessage?: string;
|
||||
onProviderOAuthLogin?: (provider: string) => void;
|
||||
providerSigningIn?: boolean;
|
||||
onChange: (model: string) => void;
|
||||
onChange: (model: string, info?: ProviderModelsPayload["models"][number]) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const tokenRef = useRef(token);
|
||||
tokenRef.current = token;
|
||||
const [open, setOpen] = useState(false);
|
||||
const [query, setQuery] = useState("");
|
||||
const [payload, setPayload] = useState<ProviderModelsPayload | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const catalogNoticeId = useId();
|
||||
const catalogSignInRef = useRef<HTMLButtonElement>(null);
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
const restoreInputOnClose = useRef(false);
|
||||
const effectiveProvider =
|
||||
provider === "auto" ? settings.agent.resolved_provider ?? provider : provider;
|
||||
const hasConcreteProvider = Boolean(effectiveProvider && effectiveProvider !== "auto");
|
||||
@@ -224,6 +241,17 @@ export function ModelIdPicker({
|
||||
!hasStaticModels &&
|
||||
hasConcreteProvider && providerConfigured && !providerUsesManualModelIds;
|
||||
const normalizedQuery = query.trim().toLowerCase();
|
||||
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,
|
||||
});
|
||||
const providerModels: ProviderModelsPayload["models"] = useMemo(
|
||||
() => hasStaticModels
|
||||
? (models?.map((id) => ({ id })) ?? [])
|
||||
@@ -241,15 +269,10 @@ export function ModelIdPicker({
|
||||
[normalizedQuery, providerModels],
|
||||
);
|
||||
const isCatalog = payload?.catalog_kind === "catalog";
|
||||
const defersModelList = DEFERRED_MODEL_LIST_PROVIDERS.has(effectiveProvider);
|
||||
const hasDeferredSearchQuery =
|
||||
normalizedQuery.length >= DEFERRED_MODEL_LIST_QUERY_MIN_LENGTH;
|
||||
const shouldFetchModels =
|
||||
canFetchModels && (!defersModelList || hasDeferredSearchQuery);
|
||||
const waitingForModelSearch =
|
||||
open && canFetchModels && defersModelList && !hasDeferredSearchQuery;
|
||||
const hasModelList = hasStaticModels || payload?.status === "available";
|
||||
const catalogNeedsSignIn = !hasStaticModels && payload?.error_kind === "auth_required";
|
||||
const catalogNeedsSignIn = !hasStaticModels && needsSignIn;
|
||||
const showModels = Boolean(
|
||||
!catalogNeedsSignIn && hasModelList
|
||||
&& (hasStaticModels || (payload && (!isCatalog || normalizedQuery))),
|
||||
@@ -262,50 +285,37 @@ export function ModelIdPicker({
|
||||
);
|
||||
const providerModelCount = payload?.model_count ?? providerModels.length;
|
||||
const modelUnconfigured = !value.trim() || !providerConfigured;
|
||||
const showCatalogNotice = payload && (catalogNeedsSignIn
|
||||
|| (!loading && payload.status === "available"
|
||||
&& (payload.source === "stale" || payload.source === "fallback")));
|
||||
const showCatalogNotice = !hasStaticModels && (catalogNeedsSignIn
|
||||
|| (open && shouldFetchModels && !refreshing && failed));
|
||||
|
||||
useEffect(() => {
|
||||
if (open && catalogNeedsSignIn && !loading) catalogSignInRef.current?.focus();
|
||||
if (!open || loading) return;
|
||||
if (catalogNeedsSignIn) catalogSignInRef.current?.focus();
|
||||
else searchInputRef.current?.focus();
|
||||
}, [open, catalogNeedsSignIn, loading]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setQuery(providerUsesManualModelIds || !hasConcreteProvider ? value : "");
|
||||
}, [open, effectiveProvider, hasConcreteProvider, providerUsesManualModelIds, value]);
|
||||
}, [effectiveProvider, hasConcreteProvider, providerUsesManualModelIds, value]);
|
||||
|
||||
useEffect(() => {
|
||||
// Reopening does not restore authorization. Keep a confirmed rejection until
|
||||
// discovery completes, without carrying it into another provider's picker.
|
||||
setPayload((current) => shouldFetchModels && current?.provider === effectiveProvider
|
||||
&& current.error_kind === "auth_required" ? current : null);
|
||||
setError(null);
|
||||
setLoading(open && shouldFetchModels);
|
||||
if (!open || !shouldFetchModels) {
|
||||
return;
|
||||
const openPicker = (nextQuery?: string) => {
|
||||
if (nextQuery !== undefined || !open) {
|
||||
setQuery(nextQuery ?? (providerUsesManualModelIds || !hasConcreteProvider ? value : ""));
|
||||
}
|
||||
let cancelled = false;
|
||||
fetchProviderModels(tokenRef.current, effectiveProvider)
|
||||
.then((nextPayload) => {
|
||||
if (!cancelled) setPayload(nextPayload);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (!cancelled) setError((err as Error).message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
// Successful OAuth completion replaces the settings row even for the same account.
|
||||
}, [effectiveProvider, open, shouldFetchModels, providerRow]);
|
||||
restoreInputOnClose.current = false;
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const selectModel = (model: string) => {
|
||||
onChange(model);
|
||||
const closePicker = (restoreFocus = false) => {
|
||||
restoreInputOnClose.current = restoreFocus;
|
||||
setOpen(false);
|
||||
};
|
||||
const selectModel = (model: string) => {
|
||||
const info = providerModels.find((entry) => entry.id === model);
|
||||
if (info) onChange(model, info);
|
||||
else onChange(model);
|
||||
closePicker(true);
|
||||
};
|
||||
const navigationValues = useMemo(
|
||||
() => [
|
||||
...(showModels ? visibleModels.map((model) => model.id) : []),
|
||||
@@ -318,7 +328,7 @@ export function ModelIdPicker({
|
||||
values: navigationValues,
|
||||
selectedValue: value,
|
||||
onSelect: selectModel,
|
||||
onClose: () => setOpen(false),
|
||||
onClose: () => closePicker(true),
|
||||
});
|
||||
|
||||
const renderModelRow = (
|
||||
@@ -360,59 +370,67 @@ export function ModelIdPicker({
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="control"
|
||||
className={cn(
|
||||
"w-full justify-between rounded-full border-input bg-background text-[13px] font-normal shadow-none",
|
||||
"settings-hover focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<PopoverAnchor asChild>
|
||||
<div className="relative w-full">
|
||||
<span className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2">
|
||||
<ProviderPickerIcon
|
||||
provider={effectiveProvider}
|
||||
showBrandLogos={showProviderLogos}
|
||||
unconfigured={modelUnconfigured}
|
||||
/>
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 truncate font-medium",
|
||||
value ? "text-foreground" : "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{value || emptyLabel || tx("settings.models.selectModel", "Select model")}
|
||||
</span>
|
||||
</span>
|
||||
<ControlChevron />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<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>
|
||||
<PopoverContent
|
||||
align="end"
|
||||
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;
|
||||
}}
|
||||
className="w-[var(--radix-popover-trigger-width)] max-w-[calc(100vw-2rem)] p-1.5"
|
||||
>
|
||||
{!catalogNeedsSignIn ? <div className="p-1 pb-1.5">
|
||||
<div className="relative">
|
||||
<Search
|
||||
className="pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
{...navigation.inputProps}
|
||||
placeholder={
|
||||
searchPlaceholder || tx("settings.models.searchModels", "Search or type model ID")
|
||||
}
|
||||
aria-label={
|
||||
searchPlaceholder || tx("settings.models.searchModels", "Search or type model ID")
|
||||
}
|
||||
aria-describedby={showCatalogNotice ? catalogNoticeId : undefined}
|
||||
className="h-8 rounded-full pl-8 pr-3 text-[12px]"
|
||||
/>
|
||||
</div>
|
||||
</div> : null}
|
||||
|
||||
{showCatalogNotice ? (
|
||||
<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">
|
||||
@@ -425,12 +443,21 @@ export function ModelIdPicker({
|
||||
<p className="font-medium text-foreground">
|
||||
{catalogNeedsSignIn
|
||||
? tx("settings.models.catalogAuthRequired", "Authorization expired. Please sign in again.")
|
||||
: tx("settings.models.catalogUnavailable", "Could not refresh models. Try again later.")}
|
||||
: <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>}
|
||||
</p>
|
||||
{!catalogNeedsSignIn ? <p className="mt-1 text-muted-foreground">
|
||||
{payload.source === "stale"
|
||||
? tx("settings.models.catalogStale", "Showing cached models; the list may be out of date.")
|
||||
: tx("settings.models.catalogFallback", "Showing built-in models; the list may be out of date.")}
|
||||
{!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.")}
|
||||
</p> : null}
|
||||
</div>
|
||||
{catalogNeedsSignIn && onProviderOAuthLogin && providerRow?.oauth_login_supported ? (
|
||||
@@ -443,7 +470,7 @@ export function ModelIdPicker({
|
||||
disabled={providerSigningIn}
|
||||
aria-describedby={catalogNoticeId}
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
closePicker();
|
||||
onProviderOAuthLogin(effectiveProvider);
|
||||
}}
|
||||
>
|
||||
@@ -477,14 +504,20 @@ export function ModelIdPicker({
|
||||
{tx("settings.models.searchCatalog", "Search this provider’s model catalog.")}
|
||||
</div>
|
||||
) : loading ? (
|
||||
<div className="flex items-center gap-2 px-2 py-1.5 text-[11px] text-muted-foreground">
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
{tx("settings.models.loadingModels", "Loading models...")}
|
||||
</div>
|
||||
) : error || payload?.status === "error" ? (
|
||||
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
||||
{payload?.message || error || tx("settings.models.loadFailed", "Model list unavailable.")}
|
||||
</div>
|
||||
<SkeletonStatus
|
||||
label={tx("settings.models.loadingModels", "Loading models...")}
|
||||
className="space-y-0.5 py-1"
|
||||
>
|
||||
{["w-3/5", "w-4/5", "w-1/2"].map((width) => (
|
||||
<div key={width} className="flex items-center gap-2 px-2 py-1.5">
|
||||
<div className="h-3.5 w-3.5 shrink-0 rounded-full bg-muted-foreground/20" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className={cn("h-3 rounded bg-muted-foreground/20", width)} />
|
||||
<div className="mt-1.5 h-2.5 w-2/5 rounded bg-muted-foreground/10" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</SkeletonStatus>
|
||||
) : 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.")}
|
||||
@@ -507,7 +540,7 @@ export function ModelIdPicker({
|
||||
<div
|
||||
{...navigation.listProps}
|
||||
aria-label={searchPlaceholder || tx("settings.models.selectModel", "Select model")}
|
||||
className="max-h-[16rem] overflow-y-auto pr-0.5 scrollbar-thin scrollbar-track-transparent"
|
||||
className="max-h-[16rem] overflow-y-auto scrollbar-thin"
|
||||
>
|
||||
{showModels
|
||||
? visibleModels.map((model) =>
|
||||
@@ -545,25 +578,6 @@ export function ModelIdPicker({
|
||||
);
|
||||
}
|
||||
|
||||
export function formatContextWindow(tokens: number): string {
|
||||
if (tokens >= 1_000_000) {
|
||||
const value = tokens / 1_000_000;
|
||||
return `${Number.isInteger(value) ? value.toFixed(0) : value.toFixed(1)}M`;
|
||||
}
|
||||
if (tokens >= 1_000) {
|
||||
const value = tokens / 1_000;
|
||||
return `${Number.isInteger(value) ? value.toFixed(0) : value.toFixed(1)}K`;
|
||||
}
|
||||
return String(tokens);
|
||||
}
|
||||
|
||||
export function formatModelContextWindow(tokens: number): string {
|
||||
if (tokens === 65_536) return "64K";
|
||||
if (tokens === 262_144) return "256K";
|
||||
if (tokens === 1_048_576) return "1M";
|
||||
return formatContextWindow(tokens);
|
||||
}
|
||||
|
||||
export function ProviderPickerIcon({
|
||||
provider,
|
||||
showBrandLogos,
|
||||
@@ -659,47 +673,3 @@ export function optionRowsWithCurrent(
|
||||
return [{ name: value, label: value }, ...options];
|
||||
}
|
||||
|
||||
export const PROVIDER_ICONS: Record<string, LucideIcon> = {
|
||||
custom: Hexagon,
|
||||
openrouter: Sparkles,
|
||||
orcarouter: Sparkles,
|
||||
skywork: Sparkles,
|
||||
aihubmix: Triangle,
|
||||
anthropic: Brain,
|
||||
openai: Bot,
|
||||
deepseek: Waves,
|
||||
zhipu: Grid3X3,
|
||||
dashscope: Cloud,
|
||||
modelscope: Layers,
|
||||
moonshot: Moon,
|
||||
minimax: Zap,
|
||||
minimax_anthropic: Brain,
|
||||
groq: Cpu,
|
||||
huggingface: Layers,
|
||||
gemini: Gem,
|
||||
mistral: Orbit,
|
||||
siliconflow: Layers,
|
||||
volcengine: Cloud,
|
||||
volcengine_coding_plan: Cloud,
|
||||
byteplus: Cloud,
|
||||
byteplus_coding_plan: Cloud,
|
||||
qianfan: Database,
|
||||
ant_ling: Sparkles,
|
||||
azure_openai: Cloud,
|
||||
bedrock: Database,
|
||||
bocha: Search,
|
||||
brave: Search,
|
||||
duckduckgo: Search,
|
||||
exa: Search,
|
||||
jina: Search,
|
||||
kagi: Search,
|
||||
olostep: Search,
|
||||
searxng: Search,
|
||||
tavily: Search,
|
||||
vllm: Cpu,
|
||||
ollama: Cpu,
|
||||
lm_studio: Cpu,
|
||||
atomic_chat: Cpu,
|
||||
ovms: Cpu,
|
||||
nvidia: Zap,
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Hexagon } from "lucide-react";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
import { PROVIDER_ICONS } from "@/lib/provider-icons";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function ProviderIcon({
|
||||
provider,
|
||||
showBrandLogos,
|
||||
compact = false,
|
||||
fill = false,
|
||||
}: {
|
||||
provider: string;
|
||||
showBrandLogos: boolean;
|
||||
compact?: boolean;
|
||||
fill?: boolean;
|
||||
}) {
|
||||
const brand = providerBrand(provider);
|
||||
const Icon = PROVIDER_ICONS[provider] ?? Hexagon;
|
||||
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const showRemoteLogo = showBrandLogos && Boolean(logoUrl);
|
||||
const showLoadedLogo = showRemoteLogo && logoLoaded;
|
||||
const isLogoTile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
|
||||
|
||||
return (
|
||||
<span
|
||||
data-testid={`provider-logo-${provider}`}
|
||||
className={cn(
|
||||
"relative grid shrink-0 place-items-center overflow-hidden font-semibold text-muted-foreground",
|
||||
fill ? "h-full w-full rounded-[9px] text-[11px]" : 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
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"transition-opacity duration-150 motion-reduce:transition-none",
|
||||
fill && "grid h-3/4 w-3/4 place-items-center",
|
||||
showLoadedLogo ? "opacity-0" : "opacity-100",
|
||||
)}
|
||||
>
|
||||
{showBrandLogos && brand
|
||||
? brand.initials
|
||||
: <Icon className={fill ? "h-full w-full" : "h-5 w-5"} strokeWidth={2} />}
|
||||
</span>
|
||||
{showRemoteLogo ? (
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt=""
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"absolute object-contain transition-opacity duration-150 motion-reduce:transition-none",
|
||||
fill ? (isLogoTile ? "h-full w-full" : "h-3/4 w-3/4") : 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}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ComponentProps } from "react";
|
||||
import { Trash2 } from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function RemoveActionButton({ children, className, ...props }: ComponentProps<typeof Button>) {
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
{...props}
|
||||
className={cn("rounded-full text-muted-foreground hover:text-destructive", className)}
|
||||
>
|
||||
<Trash2 className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { forwardRef, type ButtonHTMLAttributes, type ReactNode } from "react";
|
||||
import { Plus } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const SettingsAddButton = forwardRef<HTMLButtonElement,
|
||||
ButtonHTMLAttributes<HTMLButtonElement> & { trailing?: ReactNode }
|
||||
>(({ children, trailing, className, type = "button", ...props }, ref) => (
|
||||
<button {...props} ref={ref} type={type}
|
||||
className={cn("settings-list-row flex w-full items-center gap-3 py-2.5 text-left transition-colors settings-hover disabled:cursor-not-allowed disabled:opacity-50", className)}>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-[9px] bg-muted text-muted-foreground">
|
||||
<Plus className="h-5 w-5" aria-hidden />
|
||||
</span>
|
||||
<span className="truncate text-[14px] font-medium text-foreground">{children}</span>
|
||||
</span>
|
||||
{trailing}
|
||||
</button>
|
||||
));
|
||||
SettingsAddButton.displayName = "SettingsAddButton";
|
||||
@@ -17,10 +17,8 @@ import { isNativeRuntime } from "@/lib/runtime";
|
||||
import type { NanobotFeatureInfo } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const SETTINGS_SEARCH_INPUT_CLASS = cn(
|
||||
"border-border/45 bg-settings-surface transition-colors hover:border-border/70",
|
||||
"focus-visible:border-border/70 focus-visible:bg-background",
|
||||
);
|
||||
export const SETTINGS_SEARCH_INPUT_CLASS =
|
||||
"border-border/45 bg-settings-surface transition-colors hover:border-border/70";
|
||||
|
||||
export function CapabilityInstallNotice({
|
||||
title,
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { useRef, useState, type ReactElement } from "react";
|
||||
import { SquarePen } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { HoverHint } from "@/components/ui/tooltip";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
|
||||
export function SettingsTextEditor({ id, title, description, value, placeholder, disabled, onSave }: {
|
||||
export function SettingsTextEditor({ id, title, description, value, placeholder, disabled, trigger, onSave }: {
|
||||
id?: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
value: string;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
trigger?: ReactElement;
|
||||
onSave: (value: string) => void | Promise<void>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
@@ -41,15 +42,14 @@ export function SettingsTextEditor({ id, title, description, value, placeholder,
|
||||
if (next) { setDraft(value); setError(""); }
|
||||
setOpen(next);
|
||||
}}>
|
||||
<TooltipProvider><Tooltip>
|
||||
<TooltipTrigger asChild><DialogTrigger asChild>
|
||||
{trigger ? <DialogTrigger asChild id={id} disabled={disabled}>{trigger}</DialogTrigger> : <HoverHint content={t("settings.actions.edit")}>
|
||||
<DialogTrigger asChild>
|
||||
<Button size="icon" id={id} type="button" variant="ghost" disabled={disabled} aria-label={title}
|
||||
className="ml-auto flex h-9 w-9 shrink-0 rounded-full p-0 text-muted-foreground">
|
||||
<SquarePen className="h-4 w-4" aria-hidden />
|
||||
</Button>
|
||||
</DialogTrigger></TooltipTrigger>
|
||||
<TooltipContent>{t("settings.actions.edit")}</TooltipContent>
|
||||
</Tooltip></TooltipProvider>
|
||||
</DialogTrigger>
|
||||
</HoverHint>}
|
||||
<DialogContent className="max-w-xl" showCloseButton={!saving}
|
||||
{...(hasDescription ? {} : { "aria-describedby": undefined })}
|
||||
onOpenAutoFocus={(event) => { event.preventDefault(); editor.current?.focus(); }}
|
||||
@@ -62,7 +62,7 @@ export function SettingsTextEditor({ id, title, description, value, placeholder,
|
||||
<Textarea ref={editor} aria-label={title} value={draft} placeholder={placeholder} disabled={saving}
|
||||
aria-invalid={Boolean(error)} spellCheck={false}
|
||||
onChange={(event) => { setDraft(event.target.value); setError(""); }}
|
||||
className="h-[min(40vh,280px)] min-h-24 resize-none rounded-xl font-mono text-[13px] leading-6" />
|
||||
className="h-[min(40vh,280px)] min-h-24 resize-none rounded-control font-mono text-[13px] leading-6" />
|
||||
{error && <p role="alert" className="break-words text-[13px] text-destructive">{error}</p>}
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" disabled={saving} onClick={() => setOpen(false)}>{t("settings.actions.cancel")}</Button>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SearchInput } from "@/components/ui/input";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
|
||||
export function TimezonePicker({ value, onChange, ...triggerProps }: {
|
||||
@@ -48,7 +48,7 @@ export function TimezonePicker({ value, onChange, ...triggerProps }: {
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" className="w-80 max-w-[calc(100vw-2rem)] p-1.5">
|
||||
<Input {...navigation.inputProps} value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
<SearchInput {...navigation.inputProps} value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
aria-label={t("sidebar.searchAria")} placeholder={t("sidebar.searchPlaceholder")}
|
||||
className="mb-1.5 h-9 rounded-full" />
|
||||
<div {...navigation.listProps} aria-label={triggerProps["aria-label"]} className="max-h-64 overflow-y-auto">
|
||||
|
||||
@@ -50,7 +50,7 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Input, SearchInput } from "@/components/ui/input";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
@@ -259,7 +259,7 @@ export function AppsCatalogSettings({
|
||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-center">
|
||||
<div className="relative flex-1">
|
||||
<Search className="pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
|
||||
<Input
|
||||
<SearchInput
|
||||
value={query}
|
||||
onChange={(event) => onQueryChange(event.target.value)}
|
||||
placeholder={tx("settings.apps.searchPlaceholder", "Search Apps")}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
||||
import { Search, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SearchInput } from "@/components/ui/input";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { SETTINGS_SEARCH_INPUT_CLASS } from "@/components/settings/shared/SettingsControls";
|
||||
import { CatalogSkeleton } from "@/components/settings/shared/CatalogSkeleton";
|
||||
@@ -102,7 +102,7 @@ export function ChannelsSettings({
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
<div className="relative min-w-0 flex-1">
|
||||
<Search className="pointer-events-none absolute start-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
|
||||
<Input type="search" value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
<SearchInput type="search" value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
aria-label={t("settings.channels.search")}
|
||||
placeholder={t("settings.channels.search")}
|
||||
className={`h-12 ps-11 text-[15px] ${SETTINGS_SEARCH_INPUT_CLASS}`} />
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
DialogDescription,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Input, SearchInput } from "@/components/ui/input";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import type { McpPresetInfo } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -432,7 +432,7 @@ function ToolsPanel({
|
||||
<label className="relative min-w-0 flex-1">
|
||||
<span className="sr-only">{tx("settings.mcp.searchTools", "Search tools")}</span>
|
||||
<Search className="pointer-events-none absolute left-3.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" aria-hidden />
|
||||
<Input
|
||||
<SearchInput
|
||||
value={query}
|
||||
onChange={(event) => onQueryChange(event.target.value)}
|
||||
placeholder={tx("settings.mcp.searchToolsPlaceholder", "Search tools")}
|
||||
|
||||
@@ -98,12 +98,12 @@ export function useSettingsController({
|
||||
const [localPrefs, setLocalPrefs] = useState<LocalPreferences>(() => readLocalPreferences());
|
||||
const modelState = useModelSettingsState(initialSettings);
|
||||
const {
|
||||
editingProviderKeys, expandedProvider, form, modelCallOrder, modelCallOrderSaving,
|
||||
editingProviderKeys, form, modelCallOrder, modelCallOrderSaving,
|
||||
modelConfigurationSaving, modelMigrationSaving, modelPresetBeforeCreateRef,
|
||||
modelPresetCreating, modelPresetEditingName, modelPresetNameError, modelPresetPendingDelete,
|
||||
providerForms, providerOAuthCompleting,
|
||||
providerOAuthDialogError, providerOAuthFlow, providerOAuthFlowRef, providerOAuthResponse,
|
||||
providerSaving, saving, setForm,
|
||||
providerSaving, providerOperation, saving, setForm,
|
||||
setModelCallOrder, setModelPresetCreating, setModelPresetEditingName, setModelPresetNameError,
|
||||
setModelPresetPendingDelete,
|
||||
setProviderForms, setProviderOAuthCompleting, setProviderOAuthDialogError,
|
||||
@@ -450,7 +450,7 @@ export function useSettingsController({
|
||||
createCustomProvider,
|
||||
handleDeleteModelConfiguration,
|
||||
handleMigrateModelConfigurations,
|
||||
handleToggleProvider,
|
||||
resetProviderDraft,
|
||||
runProviderOAuth,
|
||||
saveModelSettings,
|
||||
saveProvider,
|
||||
@@ -523,7 +523,6 @@ export function useSettingsController({
|
||||
customMcpForm,
|
||||
editingProviderKeys,
|
||||
error,
|
||||
expandedProvider,
|
||||
featureCatalog,
|
||||
form,
|
||||
handleApiServiceAction,
|
||||
@@ -542,7 +541,7 @@ export function useSettingsController({
|
||||
handleMigrateModelConfigurations,
|
||||
handleNanobotFeatureAction,
|
||||
handleSaveCustomMcp,
|
||||
handleToggleProvider,
|
||||
resetProviderDraft,
|
||||
handleWebSearchProviderChange,
|
||||
hostEngineApplying,
|
||||
imageGenerationDirty,
|
||||
@@ -588,6 +587,7 @@ export function useSettingsController({
|
||||
providerOAuthFlow,
|
||||
providerOAuthResponse,
|
||||
providerSaving,
|
||||
providerOperation,
|
||||
remoteBrowserAccess,
|
||||
resetWebSearchDraft,
|
||||
restartViaSettingsSurface,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { formatModelContextWindow } from "@/lib/model-context-format";
|
||||
import {
|
||||
ModelsIcon,
|
||||
} from "@/components/icons/product-icons";
|
||||
@@ -79,6 +80,8 @@ function compactModelName(model?: string | null): string | null {
|
||||
|
||||
export interface ModelPresetOption {
|
||||
name: string;
|
||||
contextWindowTokens?: number;
|
||||
reasoningEffort?: string | null;
|
||||
model?: string | null;
|
||||
provider?: string | null;
|
||||
}
|
||||
@@ -133,6 +136,10 @@ export function ModelPresetBadge({
|
||||
label,
|
||||
modelDetail,
|
||||
providerLabel,
|
||||
[
|
||||
activePreset.contextWindowTokens ? formatModelContextWindow(activePreset.contextWindowTokens) : null,
|
||||
activePreset.reasoningEffort,
|
||||
].filter(Boolean).join(" "),
|
||||
].filter((part): part is string => Boolean(part)))];
|
||||
const presets = !activeName
|
||||
? modelPresets
|
||||
@@ -290,8 +297,8 @@ export function ModelPresetBadge({
|
||||
type={opensSetup ? "button" : undefined}
|
||||
onClick={opensSetup ? onClick : undefined}
|
||||
className={cn(
|
||||
"thread-composer-model-badge group inline-flex w-fit min-w-0 max-w-[min(18rem,44vw)] appearance-none border-0 bg-transparent p-0 shadow-none",
|
||||
opensSetup && "cursor-pointer focus-visible:outline-none",
|
||||
"thread-composer-model-badge group inline-flex w-fit min-w-0 max-w-[min(18rem,44vw)] appearance-none border-0 bg-transparent p-0 shadow-none focus-visible:outline-none",
|
||||
opensSetup && "cursor-pointer",
|
||||
isHero ? "h-8" : "h-9",
|
||||
)}
|
||||
>
|
||||
@@ -462,7 +469,7 @@ export function ModelPresetBadge({
|
||||
<Tooltip open={tooltipParts.length > 1 && tooltipOpen && !open && !motion} onOpenChange={setTooltipOpen}>
|
||||
{badge}
|
||||
<TooltipContent side="top" className="max-w-[min(24rem,calc(100vw-2rem))] space-y-1 break-words">
|
||||
{tooltipParts.map((part, index) => <p key={part} className={index === 0 ? "font-medium" : "text-xs text-muted-foreground"}>{part}{index < tooltipParts.length - 1 ? " " : ""}</p>)}
|
||||
{tooltipParts.map((part, index) => <p key={part} className={index === 0 ? "font-medium" : "whitespace-pre-wrap text-xs text-muted-foreground"}>{part}{index < tooltipParts.length - 1 ? " " : ""}</p>)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Search } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { formControlFocusClassName } from "@/components/ui/form-control";
|
||||
import { SearchInput } from "@/components/ui/input";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
@@ -56,7 +56,7 @@ export function PromptNavigator({
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn(
|
||||
"host-no-drag h-8 w-8 rounded-xl text-muted-foreground/80",
|
||||
"host-no-drag h-8 w-8 rounded-control text-muted-foreground/80",
|
||||
"hover:text-foreground",
|
||||
)}
|
||||
aria-label={t("thread.promptNavigator.open")}
|
||||
@@ -80,16 +80,12 @@ export function PromptNavigator({
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
|
||||
/>
|
||||
<input
|
||||
<SearchInput
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
aria-label={t("thread.promptNavigator.search")}
|
||||
placeholder={t("thread.promptNavigator.search")}
|
||||
className={cn(
|
||||
"touch-text-input h-10 w-full rounded-full border border-border bg-background pl-9 pr-3 text-sm",
|
||||
"transition-colors",
|
||||
formControlFocusClassName,
|
||||
)}
|
||||
className="h-10 rounded-full border-border bg-background pl-9 pr-3 text-sm transition-colors"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -135,7 +131,7 @@ function PromptNavigatorRow({
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"w-full rounded-xl px-3 py-3 text-left transition",
|
||||
"w-full rounded-control px-3 py-3 text-left transition",
|
||||
"hover:bg-accent focus-visible:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/30",
|
||||
)}
|
||||
aria-label={t("thread.promptNavigator.jumpTo", { label: prompt.label })}
|
||||
|
||||
@@ -146,7 +146,7 @@ export function SessionInfoPopover({ client, sessionKey, token, title }: Session
|
||||
size="icon"
|
||||
aria-label={t("thread.header.sessionInfo")}
|
||||
className={cn(
|
||||
"host-no-drag h-8 w-8 rounded-xl text-muted-foreground/85",
|
||||
"host-no-drag h-8 w-8 rounded-control text-muted-foreground/85",
|
||||
"hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -65,6 +65,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
floatingItemClassName,
|
||||
floatingItemFocusClassName,
|
||||
floatingSurfaceElevationClassName,
|
||||
floatingSurfaceVisualClassName,
|
||||
} from "@/components/ui/floating-surface";
|
||||
@@ -3185,6 +3186,7 @@ function CliAppMentionPalette({
|
||||
}}
|
||||
className={cn(
|
||||
floatingItemClassName,
|
||||
floatingItemFocusClassName,
|
||||
"touch-target flex min-h-10 w-full items-center gap-2.5 px-2.5 py-1.5 text-left transition-colors",
|
||||
selected
|
||||
? "bg-foreground/[0.055] text-foreground"
|
||||
@@ -3333,6 +3335,7 @@ function SlashCommandPalette({
|
||||
}}
|
||||
className={cn(
|
||||
floatingItemClassName,
|
||||
floatingItemFocusClassName,
|
||||
"flex min-h-[44px] w-full items-center gap-3 px-3 py-2 text-left transition-colors",
|
||||
selected
|
||||
? "bg-foreground/[0.065] text-foreground dark:bg-white/[0.09]"
|
||||
|
||||
@@ -87,7 +87,7 @@ export function ThreadHeader({
|
||||
aria-label={t("thread.header.toggleSidebar")}
|
||||
onClick={onToggleSidebar}
|
||||
className={cn(
|
||||
"h-7 w-7 rounded-xl text-muted-foreground hover:text-foreground",
|
||||
"h-7 w-7 rounded-control text-muted-foreground hover:text-foreground",
|
||||
hideSidebarToggleForHostChrome && "lg:hidden",
|
||||
)}
|
||||
>
|
||||
@@ -127,7 +127,7 @@ export function ThreadHeader({
|
||||
aria-pressed={temporaryChatEnabled}
|
||||
onClick={() => onTemporaryChatEnabledChange(!temporaryChatEnabled)}
|
||||
className={cn(
|
||||
"host-no-drag h-8 w-8 shrink-0 rounded-xl text-muted-foreground hover:text-foreground",
|
||||
"host-no-drag h-8 w-8 shrink-0 rounded-control text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<TemporaryChatIcon
|
||||
@@ -145,7 +145,7 @@ export function ThreadHeader({
|
||||
<TooltipContent
|
||||
side="bottom"
|
||||
align="end"
|
||||
className="max-w-72 rounded-xl border border-border/70 bg-popover px-3 py-2 text-[12px]/[1.4] text-popover-foreground shadow-[0_8px_24px_rgba(15,23,42,0.13)] dark:border-white/10"
|
||||
className="max-w-72 rounded-control border border-border/70 bg-popover px-3 py-2 text-[12px]/[1.4] text-popover-foreground shadow-[0_8px_24px_rgba(15,23,42,0.13)] dark:border-white/10"
|
||||
>
|
||||
<div className="font-medium">{t("temporaryChat.title")}</div>
|
||||
<div className="mt-1 text-muted-foreground">
|
||||
@@ -191,7 +191,7 @@ function ThemeButton({
|
||||
aria-label={label}
|
||||
onClick={onToggleTheme}
|
||||
className={cn(
|
||||
"host-no-drag h-8 w-8 rounded-xl text-muted-foreground/85 hover:text-foreground",
|
||||
"host-no-drag h-8 w-8 rounded-control text-muted-foreground/85 hover:text-foreground",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -6,8 +6,8 @@ import { useTranslation } from "react-i18next";
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { floatingItemClassName, floatingItemFocusClassName } from "@/components/ui/floating-surface";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { HoverHint } from "@/components/ui/tooltip";
|
||||
import { Input, SearchInput } from "@/components/ui/input";
|
||||
import { Dialog, DialogContent, DialogTrigger, DialogTitle, DialogDescription } from "@/components/ui/dialog";
|
||||
import { SidebarSelectionHighlight, SIDEBAR_SELECTION_ITEM_CLASS } from "@/components/SidebarSelectionHighlight";
|
||||
import type { WorkspaceScopePayload, ProjectDirectory, WorkspaceDirectoriesPayload, WorkspacesPayload } from "@/lib/types";
|
||||
@@ -22,13 +22,13 @@ function WorkspaceFavoriteButton({ path, pinned, busy, onToggle }: {
|
||||
const { t } = useTranslation();
|
||||
const label = t(pinned ? "workspace.picker.unpin" : "workspace.picker.pin", { name: projectNameFromPath(path) });
|
||||
return (
|
||||
<WorkspacePickerTooltip label={label}>
|
||||
<HoverHint content={label}>
|
||||
<button type="button" aria-label={label} aria-pressed={pinned} disabled={busy}
|
||||
onMouseDown={event => event.preventDefault()} onClick={onToggle}
|
||||
className="workspace-picker-favorite touch-target absolute right-1 top-1/2 inline-flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-control text-muted-foreground outline-none hover:bg-foreground/[0.055] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none">
|
||||
<Star className={cn("h-3.5 w-3.5", pinned && "fill-current text-foreground")} />
|
||||
</button>
|
||||
</WorkspacePickerTooltip>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,22 +42,13 @@ function directoryVisit(path: string, ancestors: PickerAncestor[] = [], scrollTo
|
||||
return { path, ancestors: ancestors.map(({ path, parent, selectedPath }) => ({ path, parent, selectedPath })), filter: "", scrollLeft: null, scrollTops };
|
||||
}
|
||||
|
||||
function WorkspacePickerTooltip({ label, children }: { label: string; children: ReactElement }) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
||||
<TooltipContent className="max-w-[min(28rem,calc(100vw-2rem))] whitespace-pre-line break-all">{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
function PickerToolButton({ label, disabled, onClick, children }: {
|
||||
label: string; disabled?: boolean; onClick: () => void; children: ReactElement;
|
||||
}) {
|
||||
return <WorkspacePickerTooltip label={label}>
|
||||
return <HoverHint content={label}>
|
||||
<Button type="button" variant="ghost" size="icon" aria-label={label} disabled={disabled} onClick={onClick}
|
||||
className="h-11 w-11 shrink-0 rounded-control text-muted-foreground sm:h-9 sm:w-9">{children}</Button>
|
||||
</WorkspacePickerTooltip>;
|
||||
</HoverHint>;
|
||||
}
|
||||
|
||||
const DIRECTORY_ROW_HEIGHT = 44;
|
||||
@@ -555,23 +546,22 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
{compact && <Button variant="ghost" size="sm" aria-expanded={showLocations} onClick={() => setShowLocations(value => !value)} className="h-11 shrink-0 gap-1.5 rounded-control px-2 text-[13px] leading-5"><Star className="h-3.5 w-3.5" />{t("workspace.picker.shortcuts")}</Button>}
|
||||
<div className="relative min-w-0 flex-1">
|
||||
<Search className="pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input aria-label={t("workspace.picker.filter")} placeholder={t("workspace.picker.filter")} value={filterQuery} disabled={pickingFolder || editingPath || compact && showLocations} onChange={event => { setFilterQuery(event.target.value); setActiveIndex(0); setActiveColumn(currentColumnIndex); setHighlightActive(false); }} className={cn("h-11 rounded-[var(--picker-field-radius)] border-transparent focus-visible:ring-0 pl-8 text-[16px] leading-5 shadow-none sm:h-9 sm:text-[13px]", compact ? "bg-muted/60" : "bg-background/80")} />
|
||||
<SearchInput aria-label={t("workspace.picker.filter")} placeholder={t("workspace.picker.filter")} value={filterQuery} disabled={pickingFolder || editingPath || compact && showLocations} onChange={event => { setFilterQuery(event.target.value); setActiveIndex(0); setActiveColumn(currentColumnIndex); setHighlightActive(false); }} className={cn("h-11 rounded-[var(--picker-field-radius)] border-transparent pl-8 text-[16px] leading-5 shadow-none sm:h-9 sm:text-[13px]", compact ? "bg-muted/60" : "bg-background/80")} />
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
if (!visible || !defaultScope || !onChange) return null;
|
||||
return (
|
||||
<div className="inline-flex min-w-0 max-w-[11rem] shrink items-center">
|
||||
<TooltipProvider>
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<WorkspacePickerTooltip label={`${t("workspace.picker.switchDirectory")}\n${displayedScope?.project_path ?? ""}`}>
|
||||
<HoverHint content={`${t("workspace.picker.switchDirectory")}\n${displayedScope?.project_path ?? ""}`}>
|
||||
<DialogTrigger asChild>
|
||||
<button ref={triggerRef} onClick={event => { openedWithKeyboard.current = event.detail === 0; }} onPointerDown={() => setKeyboardInteraction(false)} onKeyDown={() => setKeyboardInteraction(true)} type="button" disabled={disabled} aria-label={t("workspace.picker.switchDirectory")} className="thread-composer-workspace touch-target inline-flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-control px-2 text-[12px] font-medium text-muted-foreground outline-none transition-colors hover:bg-foreground/[0.055] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55">
|
||||
<WorkspaceIcon className="h-3.5 w-3.5 shrink-0" />
|
||||
<span className="min-w-0 truncate">{projectLabel}</span>
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
</WorkspacePickerTooltip>
|
||||
</HoverHint>
|
||||
<DialogContent showCloseButton={false} layoutAnchor={layoutAnchor} centerInLayoutAnchor className="flex h-[min(37rem,calc(100%-2rem))] max-w-5xl flex-col gap-0 overflow-hidden p-0 text-[13px] leading-5 [--picker-sidebar-width:11rem] [--picker-toolbar-inset:0.75rem] [--picker-field-radius:calc(var(--radius-modal)_-_var(--picker-toolbar-inset))] sm:[--picker-toolbar-inset:1rem] dark:bg-background"
|
||||
onOpenAutoFocus={event => { event.preventDefault(); if (canBrowse) focusDirectory(); else inputRef.current?.focus(); }}
|
||||
onPointerDownCapture={() => setKeyboardInteraction(false)}
|
||||
@@ -610,10 +600,10 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
<button type="button" disabled={pickingFolder} aria-current={index === breadcrumbs.length - 1 ? "location" : undefined} onClick={() => navigate(crumb.path)}
|
||||
className="h-11 max-w-48 cursor-pointer truncate rounded-[var(--picker-field-radius)] px-2 text-muted-foreground outline-none hover:bg-foreground/[0.055] focus-visible:ring-2 focus-visible:ring-ring aria-[current=location]:font-medium aria-[current=location]:text-foreground sm:h-9">{crumb.name}</button>
|
||||
</span>)}
|
||||
<WorkspacePickerTooltip label={t("workspace.picker.editPath")}>
|
||||
<HoverHint content={t("workspace.picker.editPath")}>
|
||||
<button type="button" disabled={pickingFolder} aria-label={`${t("workspace.picker.editPath")}: ${currentPath}`} onClick={editPath}
|
||||
className="min-w-8 flex-1 cursor-text self-stretch rounded-[var(--picker-field-radius)] outline-none focus-visible:ring-2 focus-visible:ring-ring" />
|
||||
</WorkspacePickerTooltip>
|
||||
</HoverHint>
|
||||
</nav>}
|
||||
</div>
|
||||
{!compact && filterToolbar}
|
||||
@@ -647,7 +637,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
<div className={cn("mr-[var(--picker-toolbar-inset)] flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-[var(--picker-field-radius)] bg-[#fcfcfc] dark:bg-muted", compact && showLocations && canBrowse && "hidden")}>
|
||||
<div ref={attachColumns} data-workspace-columns className="sidebar-scrollbar flex flex-1 min-h-0 min-w-0 overflow-x-auto overscroll-x-contain">
|
||||
{columns.map((column, columnIndex) => (!compact || columnIndex === currentColumnIndex) && <WorkspaceDirectoryColumn key={columnIndex} options={column.options} selectedPath={column.selectedPath} initialScrollTop={previewingPath ? 0 : currentVisit.scrollTops[columnIndex] ?? 0} visitRevision={history.revision} activeIndex={highlightActive && columnIndex === activeColumn ? activeOption : null}
|
||||
id={`${optionsId}-${columnIndex}`} data-workspace-column={columnIndex} data-current-directory={columnIndex === currentColumnIndex ? "" : undefined} role="listbox" tabIndex={0} aria-activedescendant={highlightActive && columnIndex === activeColumn && column.options.length ? `${optionsId}-${columnIndex}-${activeOption}` : undefined} aria-label={column.path || t("thread.composer.workspace.projectAria")} aria-busy={columnIndex === currentColumnIndex && loading} style={{ width: `${compact ? 100 : 100 / columnCount}%` }} className="sidebar-scrollbar relative min-w-0 shrink-0 overflow-x-hidden overflow-y-auto px-2 outline-none"
|
||||
id={`${optionsId}-${columnIndex}`} data-workspace-column={columnIndex} data-current-directory={columnIndex === currentColumnIndex ? "" : undefined} role="listbox" tabIndex={0} aria-activedescendant={highlightActive && columnIndex === activeColumn && column.options.length ? `${optionsId}-${columnIndex}-${activeOption}` : undefined} aria-label={column.path || t("thread.composer.workspace.projectAria")} aria-busy={columnIndex === currentColumnIndex && loading} style={{ width: `${compact ? 100 : 100 / columnCount}%` }} className="sidebar-scrollbar relative min-w-0 shrink-0 overflow-x-hidden overflow-y-auto px-2 outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/50"
|
||||
onFocus={event => { if (event.target === event.currentTarget) { setActiveColumn(columnIndex); setActiveIndex(0); } }}
|
||||
onKeyDown={event => {
|
||||
if (event.target !== event.currentTarget || event.altKey || event.metaKey || event.ctrlKey || pickingFolder) return;
|
||||
@@ -685,7 +675,6 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</TooltipProvider>
|
||||
{error && !open && <span role="alert" className="ml-2 min-w-0 truncate text-[11.5px] font-medium text-destructive">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
@@ -716,9 +705,8 @@ export function WorkspaceAccessToggle({
|
||||
const accessAriaLabel = `${t("thread.composer.workspace.accessAria")}: ${accessLabel}`;
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<HoverHint side="top" contentClassName="w-max max-w-[calc(100vw-2rem)] text-left leading-relaxed"
|
||||
content={t(isFull ? "thread.composer.workspace.fullDescription" : "thread.composer.workspace.defaultDescription")}>
|
||||
<Button
|
||||
type="button"
|
||||
variant={null}
|
||||
@@ -746,11 +734,6 @@ export function WorkspaceAccessToggle({
|
||||
{shortAccessLabel}
|
||||
</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" className="w-max max-w-[calc(100vw-2rem)] text-left leading-relaxed">
|
||||
{t(isFull ? "thread.composer.workspace.fullDescription" : "thread.composer.workspace.defaultDescription")}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { useRef, useState, type CSSProperties, type ReactNode } from "react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import { StreamingLabelSheen } from "@/components/MessageBubble";
|
||||
import { formControlFocusClassName } from "@/components/ui/form-control";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
@@ -53,7 +54,10 @@ export function ActivityStep({
|
||||
data-testid="activity-line"
|
||||
tabIndex={typeof label === "string" ? 0 : undefined}
|
||||
aria-label={detail && typeof label === "string" ? `${label}, ${detail}` : undefined}
|
||||
className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap"
|
||||
className={cn(
|
||||
"flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap",
|
||||
formControlFocusClassName,
|
||||
)}
|
||||
>
|
||||
<StreamingLabelSheen
|
||||
active={active && animateLabel}
|
||||
|
||||
@@ -91,6 +91,8 @@ export function modelPresetOptionsFromSettings(
|
||||
return {
|
||||
name,
|
||||
model: preset.model,
|
||||
contextWindowTokens: preset.context_window_tokens,
|
||||
reasoningEffort: preset.reasoning_effort,
|
||||
provider: preset.resolved_provider || preset.provider,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -14,6 +14,11 @@ interface ComboboxNavigationOptions {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
interface ActiveOption {
|
||||
value: string | null;
|
||||
source: "initial" | "keyboard" | "pointer";
|
||||
}
|
||||
|
||||
export function useComboboxNavigation({
|
||||
open,
|
||||
values,
|
||||
@@ -22,17 +27,23 @@ export function useComboboxNavigation({
|
||||
onClose,
|
||||
}: ComboboxNavigationOptions) {
|
||||
const listboxId = React.useId();
|
||||
const [activeValue, setActiveValue] = React.useState<string | null>(null);
|
||||
const [activeOption, setActiveOption] = React.useState<ActiveOption>({ value: null, source: "initial" });
|
||||
const activeValue = !open || (activeOption.source === "pointer" && activeOption.value === null)
|
||||
? null
|
||||
: activeOption.value && values.includes(activeOption.value)
|
||||
? activeOption.value
|
||||
: selectedValue && values.includes(selectedValue)
|
||||
? selectedValue
|
||||
: values[0] ?? null;
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open) {
|
||||
setActiveValue(null);
|
||||
return;
|
||||
}
|
||||
setActiveValue((current) => {
|
||||
if (current && values.includes(current)) return current;
|
||||
if (selectedValue && values.includes(selectedValue)) return selectedValue;
|
||||
return values[0] ?? null;
|
||||
setActiveOption((current) => {
|
||||
if (open && current.value && values.includes(current.value)) return current;
|
||||
const value = open
|
||||
? selectedValue && values.includes(selectedValue) ? selectedValue : values[0] ?? null
|
||||
: null;
|
||||
return current.value === value && current.source === "initial"
|
||||
? current : { value, source: "initial" };
|
||||
});
|
||||
}, [open, selectedValue, values]);
|
||||
|
||||
@@ -40,17 +51,17 @@ export function useComboboxNavigation({
|
||||
const activeOptionId = activeIndex >= 0 ? `${listboxId}-option-${activeIndex}` : undefined;
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!activeOptionId) return;
|
||||
if (!activeOptionId || activeOption.source !== "keyboard") return;
|
||||
const option = document.getElementById(activeOptionId);
|
||||
option?.scrollIntoView?.({ block: "nearest" });
|
||||
}, [activeOptionId]);
|
||||
}, [activeOptionId, activeOption.source]);
|
||||
|
||||
const move = (offset: number) => {
|
||||
if (!values.length) return;
|
||||
const nextIndex = activeIndex < 0
|
||||
? offset > 0 ? 0 : values.length - 1
|
||||
: (activeIndex + offset + values.length) % values.length;
|
||||
setActiveValue(values[nextIndex]);
|
||||
setActiveOption({ value: values[nextIndex], source: "keyboard" });
|
||||
};
|
||||
|
||||
const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
@@ -102,9 +113,17 @@ export function useComboboxNavigation({
|
||||
id: `${listboxId}-option-${index}`,
|
||||
role: "option" as const,
|
||||
"aria-selected": value === activeValue,
|
||||
"data-highlighted": value === activeValue ? "" : undefined,
|
||||
"data-highlighted": value === activeValue && activeOption.source === "keyboard" ? "" : undefined,
|
||||
tabIndex: -1,
|
||||
onPointerMove: () => setActiveValue(value),
|
||||
onPointerMove: (event: React.PointerEvent<HTMLButtonElement>) => {
|
||||
if (event.pointerType === "touch") return;
|
||||
setActiveOption((current) => current.value === value && current.source === "pointer"
|
||||
? current : { value, source: "pointer" });
|
||||
},
|
||||
onPointerLeave: () => {
|
||||
setActiveOption((current) => current.source === "pointer" && current.value === value
|
||||
? { value: null, source: "pointer" } : current);
|
||||
},
|
||||
onClick: () => onSelect(value),
|
||||
};
|
||||
};
|
||||
@@ -122,7 +141,7 @@ const ComboboxOption = React.forwardRef<
|
||||
className={cn(
|
||||
floatingItemClassName,
|
||||
floatingItemFocusClassName,
|
||||
"w-full cursor-default text-left data-[highlighted]:bg-muted/85 data-[highlighted]:text-foreground",
|
||||
"w-full cursor-default text-left settings-hover data-[highlighted]:bg-[var(--control-hover-fill)] data-[highlighted]:text-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -10,10 +10,10 @@ export const modalOverlayClassName =
|
||||
"fixed inset-0 z-50 bg-black/25 backdrop-blur-[8px] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:fill-mode-forwards data-[state=open]:fade-in-0";
|
||||
|
||||
export const modalSurfaceClassName =
|
||||
"bg-background text-foreground shadow-[0_12px_36px_rgba(15,23,42,0.12)] dark:bg-popover dark:shadow-[0_18px_44px_rgba(0,0,0,0.32)]";
|
||||
"outline-none bg-background text-foreground shadow-[0_12px_36px_rgba(15,23,42,0.12)] dark:bg-popover dark:shadow-[0_18px_44px_rgba(0,0,0,0.32)]";
|
||||
|
||||
export const floatingSurfaceClassName =
|
||||
`${floatingSurfaceVisualClassName} z-50 overflow-x-hidden overflow-y-auto overscroll-contain scrollbar-thin scrollbar-track-transparent`;
|
||||
`${floatingSurfaceVisualClassName} z-50 overflow-x-hidden overflow-y-auto overscroll-contain scrollbar-thin`;
|
||||
|
||||
export const floatingSurfaceMotionClassName =
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0";
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip-primitives";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function HoverHint({ content, children, enabled = true, side = "top", align = "center", sideOffset, contentClassName }: {
|
||||
content: React.ReactNode;
|
||||
children: React.ReactElement;
|
||||
enabled?: boolean;
|
||||
side?: React.ComponentPropsWithoutRef<typeof TooltipContent>["side"];
|
||||
align?: React.ComponentPropsWithoutRef<typeof TooltipContent>["align"];
|
||||
sideOffset?: number;
|
||||
contentClassName?: string;
|
||||
}) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip open={enabled && open} onOpenChange={(next) => setOpen(enabled && next)}>
|
||||
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
||||
<TooltipContent side={side} align={align} sideOffset={sideOffset}
|
||||
className={cn("max-w-[min(28rem,calc(100vw-2rem))] whitespace-pre-wrap break-words", contentClassName)}>
|
||||
{content}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,19 @@ import * as React from "react";
|
||||
import { formControlFocusClassName } from "@/components/ui/form-control";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
|
||||
type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
|
||||
variant?: "default" | "search";
|
||||
};
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
({ className, type, variant = "default", ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"touch-text-input flex h-10 w-full rounded-full border border-input bg-background px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
||||
formControlFocusClassName,
|
||||
variant === "search" || type === "search"
|
||||
? "focus:outline-none" : formControlFocusClassName,
|
||||
className,
|
||||
)}
|
||||
ref={ref}
|
||||
@@ -23,4 +26,9 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
const SearchInput = React.forwardRef<HTMLInputElement, Omit<InputProps, "variant">>(
|
||||
(props, ref) => <Input {...props} ref={ref} variant="search" />,
|
||||
);
|
||||
SearchInput.displayName = "SearchInput";
|
||||
|
||||
export { Input, SearchInput };
|
||||
@@ -9,6 +9,7 @@ import { cn } from "@/lib/utils";
|
||||
import { useFloatingPortal } from "@/components/ui/floating-portal";
|
||||
|
||||
const Popover = PopoverPrimitive.Root;
|
||||
const PopoverAnchor = PopoverPrimitive.Anchor;
|
||||
const PopoverTrigger = PopoverPrimitive.Trigger;
|
||||
|
||||
interface PopoverContentProps
|
||||
@@ -41,6 +42,7 @@ PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
||||
|
||||
export {
|
||||
Popover,
|
||||
PopoverAnchor,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import { ControlChevron } from "@/components/ui/control-chevron";
|
||||
|
||||
export const Select = SelectPrimitive.Root;
|
||||
export const SelectValue = SelectPrimitive.Value;
|
||||
export const SelectSeparator = SelectPrimitive.Separator;
|
||||
|
||||
export const SelectTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||||
@@ -24,7 +25,7 @@ SelectTrigger.displayName = "SelectTrigger";
|
||||
|
||||
export function SelectContent({ children, ...props }: Pick<
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>,
|
||||
"children" | "onPointerUpCapture" | "onPointerDownOutside" | "onKeyDownCapture" | "onEscapeKeyDown"
|
||||
"children" | "onPointerUpCapture" | "onPointerDownOutside" | "onKeyDownCapture" | "onEscapeKeyDown" | "onCloseAutoFocus"
|
||||
>) {
|
||||
const container = useFloatingPortal();
|
||||
return (
|
||||
|
||||
@@ -29,7 +29,7 @@ const SheetOverlay = React.forwardRef<
|
||||
SheetOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
const sheetVariants = cva(
|
||||
"fixed z-50 flex flex-col gap-4 bg-background transition ease-in-out",
|
||||
"fixed z-50 flex flex-col gap-4 bg-background outline-none transition ease-in-out",
|
||||
{
|
||||
variants: {
|
||||
side: {
|
||||
@@ -99,7 +99,7 @@ const SheetContent = React.forwardRef<
|
||||
{showCloseButton ? (
|
||||
<DialogPrimitive.Close
|
||||
className={cn(
|
||||
"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity",
|
||||
"absolute right-4 top-4 rounded-mark opacity-70 ring-offset-background transition-opacity",
|
||||
"hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||
"disabled:pointer-events-none",
|
||||
closeButtonClassName,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import * as React from "react";
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
|
||||
import { floatingSurfaceElevationClassName } from "@/components/ui/floating-surface";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function TooltipProvider(props: Omit<React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Provider>, "delayDuration" | "skipDelayDuration">) {
|
||||
return <TooltipPrimitive.Provider {...props} delayDuration={500} skipDelayDuration={0} />;
|
||||
}
|
||||
const Tooltip = TooltipPrimitive.Root;
|
||||
const TooltipTrigger = TooltipPrimitive.Trigger;
|
||||
|
||||
const TooltipContent = React.forwardRef<
|
||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
floatingSurfaceElevationClassName,
|
||||
"z-50 overflow-hidden rounded-control px-3 py-1.5 text-xs animate-in fade-in-0 zoom-in-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</TooltipPrimitive.Portal>
|
||||
));
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
||||
|
||||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
||||
@@ -1,32 +1,3 @@
|
||||
import * as React from "react";
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
|
||||
import { floatingSurfaceElevationClassName } from "@/components/ui/floating-surface";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function TooltipProvider(props: Omit<React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Provider>, "delayDuration" | "skipDelayDuration">) {
|
||||
return <TooltipPrimitive.Provider {...props} delayDuration={500} skipDelayDuration={0} />;
|
||||
}
|
||||
const Tooltip = TooltipPrimitive.Root;
|
||||
const TooltipTrigger = TooltipPrimitive.Trigger;
|
||||
|
||||
const TooltipContent = React.forwardRef<
|
||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
floatingSurfaceElevationClassName,
|
||||
"z-50 overflow-hidden rounded-control px-3 py-1.5 text-xs animate-in fade-in-0 zoom-in-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</TooltipPrimitive.Portal>
|
||||
));
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
||||
|
||||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
||||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip-primitives";
|
||||
export { HoverHint } from "@/components/ui/hover-hint";
|
||||
export { TruncatedTextTooltip } from "@/components/ui/truncated-text-tooltip";
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { HoverHint } from "@/components/ui/hover-hint";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function TruncatedTextTooltip({ text, className, ...props }: {
|
||||
text: string;
|
||||
} & Omit<React.ComponentPropsWithoutRef<"span">, "children" | "title">) {
|
||||
const ref = React.useRef<HTMLSpanElement>(null);
|
||||
const [truncated, setTruncated] = React.useState(false);
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element) return;
|
||||
const measure = () => setTruncated(element.scrollWidth > element.clientWidth);
|
||||
measure();
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(element);
|
||||
let mounted = true;
|
||||
void document.fonts.ready.then(() => { if (mounted) measure(); });
|
||||
return () => { mounted = false; observer.disconnect(); };
|
||||
}, [text]);
|
||||
|
||||
return (
|
||||
<HoverHint content={text} enabled={truncated}>
|
||||
<span {...props} ref={ref} className={cn("min-w-0 truncate", className)}>{text}</span>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,12 +31,7 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { HoverHint } from "@/components/ui/tooltip";
|
||||
import {
|
||||
createWorkbenchLayoutGeometry,
|
||||
resizeHandleRatio,
|
||||
@@ -174,8 +169,7 @@ function HeaderIconButton({
|
||||
onClick: () => void;
|
||||
}) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<HoverHint content={disabled ? disabledLabel ?? label : label} side="bottom">
|
||||
<span className="inline-flex">
|
||||
<Button
|
||||
type="button"
|
||||
@@ -189,9 +183,7 @@ function HeaderIconButton({
|
||||
<Icon className="h-4 w-4" aria-hidden />
|
||||
</Button>
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">{disabled ? disabledLabel ?? label : label}</TooltipContent>
|
||||
</Tooltip>
|
||||
</HoverHint>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -690,7 +682,6 @@ export function PaneWorkbench({
|
||||
&& "[--thread-header-position:relative]",
|
||||
)}
|
||||
>
|
||||
<TooltipProvider>
|
||||
{chrome ? (
|
||||
<header className="pointer-events-none inset-x-0 top-0 z-30 shrink-0 [position:var(--thread-header-position,absolute)]">
|
||||
<div
|
||||
@@ -738,8 +729,13 @@ export function PaneWorkbench({
|
||||
headerActions,
|
||||
})}
|
||||
{chrome && panes.length > 1 && !compact ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<HoverHint
|
||||
enabled={active}
|
||||
side="top"
|
||||
content={t("workbench.movePaneHint", {
|
||||
defaultValue: "Drag to move, or use the arrow keys.",
|
||||
})}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={active ? 0 : -1}
|
||||
@@ -772,15 +768,7 @@ export function PaneWorkbench({
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
{active ? (
|
||||
<TooltipContent side="top">
|
||||
{t("workbench.movePaneHint", {
|
||||
defaultValue: "Drag to move, or use the arrow keys.",
|
||||
})}
|
||||
</TooltipContent>
|
||||
) : null}
|
||||
</Tooltip>
|
||||
</HoverHint>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
@@ -844,7 +832,6 @@ export function PaneWorkbench({
|
||||
/>
|
||||
</footer>
|
||||
) : null}
|
||||
</TooltipProvider>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user