Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

refactor: migrate chat sidebar and UI components to modular sidebar framework, some minor UI tweaks (sidebar, lines)

shine1idea9cf1911a7
diff --git a/frontend/src/components/assistant-ui/thread.tsx b/frontend/src/components/assistant-ui/thread.tsx
index d29967b4455..6ec6022ff0f 100644
--- a/frontend/src/components/assistant-ui/thread.tsx
+++ b/frontend/src/components/assistant-ui/thread.tsx
@@ -66,7 +66,7 @@ export const Thread: FC<{ hideComposer?: boolean; hideWelcome?: boolean }> = ({
}}
/>
- <ThreadPrimitive.ViewportFooter className="aui-thread-viewport-footer sticky bottom-0 mx-auto mt-auto flex w-full max-w-(--thread-max-width) flex-col gap-4 overflow-visible rounded-t-3xl pb-4 md:pb-6">
+ <ThreadPrimitive.ViewportFooter className="aui-thread-viewport-footer sticky bottom-0 mx-auto mt-auto flex w-full max-w-(--thread-max-width) flex-col gap-4 overflow-visible rounded-t-3xl pb-4 md:pb-4">
<ThreadScrollToBottom />
<AuiIf condition={({ thread }) => !thread.isEmpty}>
{!hideComposer && <ComposerAnimated />}
diff --git a/frontend/src/components/ui/sidebar.tsx b/frontend/src/components/ui/sidebar.tsx
new file mode 100644
index 00000000000..6a4a6e5f89c
--- /dev/null
+++ b/frontend/src/components/ui/sidebar.tsx
@@ -0,0 +1,702 @@
+"use client"
+
+import * as React from "react"
+import { cva, type VariantProps } from "class-variance-authority"
+import { Slot } from "radix-ui"
+
+import { cn } from "@/lib/utils"
+import { Button } from "@/components/ui/button"
+import { Input } from "@/components/ui/input"
+import { Separator } from "@/components/ui/separator"
+import {
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
+} from "@/components/ui/sheet"
+import { Skeleton } from "@/components/ui/skeleton"
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/ui/tooltip"
+import { useIsMobile } from "@/hooks/use-mobile"
+import { HugeiconsIcon } from "@hugeicons/react"
+import { SidebarLeftIcon } from "@hugeicons/core-free-icons"
+
+const SIDEBAR_COOKIE_NAME = "sidebar_state"
+const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
+const SIDEBAR_WIDTH = "16rem"
+const SIDEBAR_WIDTH_MOBILE = "18rem"
+const SIDEBAR_WIDTH_ICON = "3rem"
+const SIDEBAR_KEYBOARD_SHORTCUT = "b"
+
+type SidebarContextProps = {
+ state: "expanded" | "collapsed"
+ open: boolean
+ setOpen: (open: boolean) => void
+ openMobile: boolean
+ setOpenMobile: (open: boolean) => void
+ isMobile: boolean
+ toggleSidebar: () => void
+}
+
+const SidebarContext = React.createContext<SidebarContextProps | null>(null)
+
+function useSidebar() {
+ const context = React.useContext(SidebarContext)
+ if (!context) {
+ throw new Error("useSidebar must be used within a SidebarProvider.")
+ }
+
+ return context
+}
+
+function SidebarProvider({
+ defaultOpen = true,
+ open: openProp,
+ onOpenChange: setOpenProp,
+ className,
+ style,
+ children,
+ ...props
+}: React.ComponentProps<"div"> & {
+ defaultOpen?: boolean
+ open?: boolean
+ onOpenChange?: (open: boolean) => void
+}) {
+ const isMobile = useIsMobile()
+ const [openMobile, setOpenMobile] = React.useState(false)
+
+ // This is the internal state of the sidebar.
+ // We use openProp and setOpenProp for control from outside the component.
+ const [_open, _setOpen] = React.useState(defaultOpen)
+ const open = openProp ?? _open
+ const setOpen = React.useCallback(
+ (value: boolean | ((value: boolean) => boolean)) => {
+ const openState = typeof value === "function" ? value(open) : value
+ if (setOpenProp) {
+ setOpenProp(openState)
+ } else {
+ _setOpen(openState)
+ }
+
+ // This sets the cookie to keep the sidebar state.
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
+ },
+ [setOpenProp, open]
+ )
+
+ // Helper to toggle the sidebar.
+ const toggleSidebar = React.useCallback(() => {
+ return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
+ }, [isMobile, setOpen, setOpenMobile])
+
+ // Adds a keyboard shortcut to toggle the sidebar.
+ React.useEffect(() => {
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (
+ event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
+ (event.metaKey || event.ctrlKey)
+ ) {
+ event.preventDefault()
+ toggleSidebar()
+ }
+ }
+
+ window.addEventListener("keydown", handleKeyDown)
+ return () => window.removeEventListener("keydown", handleKeyDown)
+ }, [toggleSidebar])
+
+ // We add a state so that we can do data-state="expanded" or "collapsed".
+ // This makes it easier to style the sidebar with Tailwind classes.
+ const state = open ? "expanded" : "collapsed"
+
+ const contextValue = React.useMemo<SidebarContextProps>(
+ () => ({
+ state,
+ open,
+ setOpen,
+ isMobile,
+ openMobile,
+ setOpenMobile,
+ toggleSidebar,
+ }),
+ [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
+ )
+
+ return (
+ <SidebarContext.Provider value={contextValue}>
+ <div
+ data-slot="sidebar-wrapper"
+ style={
+ {
+ "--sidebar-width": SIDEBAR_WIDTH,
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
+ ...style,
+ } as React.CSSProperties
+ }
+ className={cn(
+ "group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
+ className
+ )}
+ {...props}
+ >
+ {children}
+ </div>
+ </SidebarContext.Provider>
+ )
+}
+
+function Sidebar({
+ side = "left",
+ variant = "sidebar",
+ collapsible = "offcanvas",
+ className,
+ children,
+ dir,
+ ...props
+}: React.ComponentProps<"div"> & {
+ side?: "left" | "right"
+ variant?: "sidebar" | "floating" | "inset"
+ collapsible?: "offcanvas" | "icon" | "none"
+}) {
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
+
+ if (collapsible === "none") {
+ return (
+ <div
+ data-slot="sidebar"
+ className={cn(
+ "bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
+ className
+ )}
+ {...props}
+ >
+ {children}
+ </div>
+ )
+ }
+
+ if (isMobile) {
+ return (
+ <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
+ <SheetContent
+ dir={dir}
+ data-sidebar="sidebar"
+ data-slot="sidebar"
+ data-mobile="true"
+ className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
+ style={
+ {
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
+ } as React.CSSProperties
+ }
+ side={side}
+ >
+ <SheetHeader className="sr-only">
+ <SheetTitle>Sidebar</SheetTitle>
+ <SheetDescription>Displays the mobile sidebar.</SheetDescription>
+ </SheetHeader>
+ <div className="flex h-full w-full flex-col">{children}</div>
+ </SheetContent>
+ </Sheet>
+ )
+ }
+
+ return (
+ <div
+ className="group peer text-sidebar-foreground hidden md:block"
+ data-state={state}
+ data-collapsible={state === "collapsed" ? collapsible : ""}
+ data-variant={variant}
+ data-side={side}
+ data-slot="sidebar"
+ >
+ {/* This is what handles the sidebar gap on desktop */}
+ <div
+ data-slot="sidebar-gap"
+ className={cn(
+ "transition-[width] duration-200 ease-linear relative w-(--sidebar-width) bg-transparent",
+ "group-data-[collapsible=offcanvas]:w-0",
+ "group-data-[side=right]:rotate-180",
+ variant === "floating" || variant === "inset"
+ ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
+ )}
+ />
+ <div
+ data-slot="sidebar-container"
+ data-side={side}
+ className={cn(
+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex",
+ // Adjust the padding for floating and inset variants.
+ variant === "floating" || variant === "inset"
+ ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
+ className
+ )}
+ {...props}
+ >
+ <div
+ data-sidebar="sidebar"
+ data-slot="sidebar-inner"
+ className="bg-sidebar group-data-[variant=floating]:ring-sidebar-border group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 flex size-full flex-col"
+ >
+ {children}
+ </div>
+ </div>
+ </div>
+ )
+}
+
+function SidebarTrigger({
+ className,
+ onClick,
+ ...props
+}: React.ComponentProps<typeof Button>) {
+ const { toggleSidebar } = useSidebar()
+
+ return (
+ <Button
+ data-sidebar="trigger"
+ data-slot="sidebar-trigger"
+ variant="ghost"
+ size="icon-sm"
+ className={cn(className)}
+ onClick={(event) => {
+ onClick?.(event)
+ toggleSidebar()
+ }}
+ {...props}
+ >
+ <HugeiconsIcon icon={SidebarLeftIcon} strokeWidth={2} />
+ <span className="sr-only">Toggle Sidebar</span>
+ </Button>
+ )
+}
+
+function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
+ const { toggleSidebar } = useSidebar()
+
+ return (
+ <button
+ data-sidebar="rail"
+ data-slot="sidebar-rail"
+ aria-label="Toggle Sidebar"
+ tabIndex={-1}
+ onClick={toggleSidebar}
+ title="Toggle Sidebar"
+ className={cn(
+ "hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",
+ "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
+ "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
+ "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
+ return (
+ <main
+ data-slot="sidebar-inset"
+ className={cn(
+ "bg-background md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2 relative flex w-full flex-1 flex-col",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarInput({
+ className,
+ ...props
+}: React.ComponentProps<typeof Input>) {
+ return (
+ <Input
+ data-slot="sidebar-input"
+ data-sidebar="input"
+ className={cn("bg-background h-8 w-full shadow-none", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="sidebar-header"
+ data-sidebar="header"
+ className={cn("gap-2 p-2 flex flex-col", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="sidebar-footer"
+ data-sidebar="footer"
+ className={cn("gap-2 p-2 flex flex-col", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarSeparator({
+ className,
+ ...props
+}: React.ComponentProps<typeof Separator>) {
+ return (
+ <Separator
+ data-slot="sidebar-separator"
+ data-sidebar="separator"
+ className={cn("bg-sidebar-border mx-2 w-auto", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="sidebar-content"
+ data-sidebar="content"
+ className={cn(
+ "no-scrollbar gap-2 flex min-h-0 flex-1 flex-col overflow-auto group-data-[collapsible=icon]:overflow-hidden",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="sidebar-group"
+ data-sidebar="group"
+ className={cn(
+ "p-2 relative flex w-full min-w-0 flex-col",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarGroupLabel({
+ className,
+ asChild = false,
+ ...props
+}: React.ComponentProps<"div"> & { asChild?: boolean }) {
+ const Comp = asChild ? Slot.Root : "div"
+
+ return (
+ <Comp
+ data-slot="sidebar-group-label"
+ data-sidebar="group-label"
+ className={cn(
+ "text-sidebar-foreground/70 ring-sidebar-ring h-8 rounded-md px-2 text-xs font-medium transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 flex shrink-0 items-center outline-hidden [&>svg]:shrink-0",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarGroupAction({
+ className,
+ asChild = false,
+ ...props
+}: React.ComponentProps<"button"> & { asChild?: boolean }) {
+ const Comp = asChild ? Slot.Root : "button"
+
+ return (
+ <Comp
+ data-slot="sidebar-group-action"
+ data-sidebar="group-action"
+ className={cn(
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 w-5 rounded-md p-0 focus-visible:ring-2 [&>svg]:size-4 flex aspect-square items-center justify-center outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 md:after:hidden [&>svg]:shrink-0",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarGroupContent({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="sidebar-group-content"
+ data-sidebar="group-content"
+ className={cn("text-sm w-full", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
+ return (
+ <ul
+ data-slot="sidebar-menu"
+ data-sidebar="menu"
+ className={cn("gap-1 flex w-full min-w-0 flex-col", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
+ return (
+ <li
+ data-slot="sidebar-menu-item"
+ data-sidebar="menu-item"
+ className={cn("group/menu-item relative", className)}
+ {...props}
+ />
+ )
+}
+
+const sidebarMenuButtonVariants = cva(
+ "ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-accent-foreground gap-2 rounded-lg corner-squircle p-2 text-left text-sm transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! focus-visible:ring-2 data-active:font-medium peer/menu-button flex w-full items-center overflow-hidden outline-hidden group/menu-button disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&_svg]:size-4 [&_svg]:shrink-0",
+ {
+ variants: {
+ variant: {
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
+ outline: "bg-background hover:bg-sidebar-accent hover:text-sidebar-accent-foreground shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
+ },
+ size: {
+ default: "h-9 text-sm",
+ sm: "h-8 text-xs",
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ size: "default",
+ },
+ }
+)
+
+function SidebarMenuButton({
+ asChild = false,
+ isActive = false,
+ variant = "default",
+ size = "default",
+ tooltip,
+ className,
+ ...props
+}: React.ComponentProps<"button"> & {
+ asChild?: boolean
+ isActive?: boolean
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>
+} & VariantProps<typeof sidebarMenuButtonVariants>) {
+ const Comp = asChild ? Slot.Root : "button"
+ const { isMobile, state } = useSidebar()
+
+ const button = (
+ <Comp
+ data-slot="sidebar-menu-button"
+ data-sidebar="menu-button"
+ data-size={size}
+ data-active={isActive}
+ className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
+ {...props}
+ />
+ )
+
+ if (!tooltip) {
+ return button
+ }
+
+ if (typeof tooltip === "string") {
+ tooltip = {
+ children: tooltip,
+ }
+ }
+
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
+ <TooltipContent
+ side="right"
+ align="center"
+ hidden={state !== "collapsed" || isMobile}
+ {...tooltip}
+ />
+ </Tooltip>
+ )
+}
+
+function SidebarMenuAction({
+ className,
+ asChild = false,
+ showOnHover = false,
+ ...props
+}: React.ComponentProps<"button"> & {
+ asChild?: boolean
+ showOnHover?: boolean
+}) {
+ const Comp = asChild ? Slot.Root : "button"
+
+ return (
+ <Comp
+ data-slot="sidebar-menu-action"
+ data-sidebar="menu-action"
+ className={cn(
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 aspect-square w-5 rounded-md p-0 peer-data-[size=default]/menu-button:top-2 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 focus-visible:ring-2 [&>svg]:size-4 flex items-center justify-center outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 md:after:hidden [&>svg]:shrink-0",
+ showOnHover &&
+ "peer-data-active/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-open:opacity-100 md:opacity-0",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarMenuBadge({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="sidebar-menu-badge"
+ data-sidebar="menu-badge"
+ className={cn(
+ "text-sidebar-foreground peer-hover/menu-button:text-sidebar-accent-foreground peer-data-active/menu-button:text-sidebar-accent-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 rounded-md px-1 text-xs font-medium peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 flex items-center justify-center tabular-nums select-none group-data-[collapsible=icon]:hidden",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function SidebarMenuSkeleton({
+ className,
+ showIcon = false,
+ ...props
+}: React.ComponentProps<"div"> & {
+ showIcon?: boolean
+}) {
+ // Random width between 50 to 90%.
+ const [width] = React.useState(() => {
+ return `${Math.floor(Math.random() * 40) + 50}%`
+ })
+
+ return (
+ <div
+ data-slot="sidebar-menu-skeleton"
+ data-sidebar="menu-skeleton"
+ className={cn("h-8 gap-2 rounded-md px-2 flex items-center", className)}
+ {...props}
+ >
+ {showIcon && (
+ <Skeleton
+ className="size-4 rounded-md"
+ data-sidebar="menu-skeleton-icon"
+ />
+ )}
+ <Skeleton
+ className="h-4 max-w-(--skeleton-width) flex-1"
+ data-sidebar="menu-skeleton-text"
+ style={
+ {
+ "--skeleton-width": width,
+ } as React.CSSProperties
+ }
+ />
+ </div>
+ )
+}
+
+function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
+ return (
+ <ul
+ data-slot="sidebar-menu-sub"
+ data-sidebar="menu-sub"
+ className={cn("border-sidebar-border mx-3.5 translate-x-px gap-1 border-l px-2.5 py-0.5 group-data-[collapsible=icon]:hidden flex min-w-0 flex-col", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarMenuSubItem({
+ className,
+ ...props
+}: React.ComponentProps<"li">) {
+ return (
+ <li
+ data-slot="sidebar-menu-sub-item"
+ data-sidebar="menu-sub-item"
+ className={cn("group/menu-sub-item relative", className)}
+ {...props}
+ />
+ )
+}
+
+function SidebarMenuSubButton({
+ asChild = false,
+ size = "md",
+ isActive = false,
+ className,
+ ...props
+}: React.ComponentProps<"a"> & {
+ asChild?: boolean
+ size?: "sm" | "md"
+ isActive?: boolean
+}) {
+ const Comp = asChild ? Slot.Root : "a"
+
+ return (
+ <Comp
+ data-slot="sidebar-menu-sub-button"
+ data-sidebar="menu-sub-button"
+ data-size={size}
+ data-active={isActive}
+ className={cn(
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground h-7 gap-2 rounded-md px-2 focus-visible:ring-2 data-[size=md]:text-sm data-[size=sm]:text-xs [&>svg]:size-4 flex min-w-0 -translate-x-px items-center overflow-hidden outline-hidden group-data-[collapsible=icon]:hidden disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:shrink-0",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+export {
+ Sidebar,
+ SidebarContent,
+ SidebarFooter,
+ SidebarGroup,
+ SidebarGroupAction,
+ SidebarGroupContent,
+ SidebarGroupLabel,
+ SidebarHeader,
+ SidebarInput,
+ SidebarInset,
+ SidebarMenu,
+ SidebarMenuAction,
+ SidebarMenuBadge,
+ SidebarMenuButton,
+ SidebarMenuItem,
+ SidebarMenuSkeleton,
+ SidebarMenuSub,
+ SidebarMenuSubButton,
+ SidebarMenuSubItem,
+ SidebarProvider,
+ SidebarRail,
+ SidebarSeparator,
+ SidebarTrigger,
+ useSidebar,
+}
diff --git a/frontend/src/features/chat/chat-page.tsx b/frontend/src/features/chat/chat-page.tsx
index ae8ef18ead7..76f39f97a76 100644
--- a/frontend/src/features/chat/chat-page.tsx
+++ b/frontend/src/features/chat/chat-page.tsx
@@ -3,11 +3,18 @@ import {
ModelSelector,
} from "@/components/assistant-ui/model-selector";
import { Thread } from "@/components/assistant-ui/thread";
-import { Settings04Icon, SidebarLeft01Icon } from "@hugeicons/core-free-icons";
+import {
+ SidebarProvider,
+ SidebarTrigger,
+ useSidebar,
+} from "@/components/ui/sidebar";
+import { cn } from "@/lib/utils";
+import { Settings04Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
-import { AnimatePresence, motion } from "motion/react";
import {
+ type CSSProperties,
type ReactElement,
+ type ReactNode,
memo,
useCallback,
useEffect,
@@ -116,9 +123,9 @@ const CompareContent = memo(function CompareContent({
return (
<CompareHandlesProvider handlesRef={handlesRef}>
<div className="flex min-h-0 flex-1 flex-col">
- <div className="grid min-h-0 flex-1 grid-cols-2 gap-3 px-3">
+ <div className="grid min-h-0 flex-1 grid-cols-2 px-0">
<div className="flex min-h-0 flex-col">
- <div className="border-b px-3 py-1.5">
+ <div className=" px-3 py-1.5">
<span className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
Base Model
</span>
@@ -135,8 +142,8 @@ const CompareContent = memo(function CompareContent({
</div>
</div>
<div className="flex min-h-0 flex-col">
- <div className="border-b border-primary/30 px-3 py-1.5">
- <span className="text-[10px] font-semibold uppercase tracking-wider text-primary">
+ <div className=" text-end px-3 py-1.5">
+ <span className="text-[10px] font-semibold uppercase tracking-wider text-primary">
Fine-tuned (LoRA)
</span>
</div>
@@ -160,9 +167,40 @@ const CompareContent = memo(function CompareContent({
);
});
+function InlineSidebar({
+ children,
+ side = "left",
+}: {
+ children: ReactNode;
+ side?: "left" | "right";
+}) {
+ const { state } = useSidebar();
+ const collapsed = state === "collapsed";
+ return (
+ <div
+ className="group shrink-0 h-full"
+ data-state={state}
+ data-collapsible={collapsed ? "offcanvas" : ""}
+ data-side={side}
+ >
+ <aside
+ data-sidebar="sidebar"
+ className={cn(
+ "bg-sidebar text-sidebar-foreground h-full overflow-hidden transition-[width] duration-200 ease-linear",
+ !collapsed && (side === "left" ? "border-r border-sidebar-border" : "border-l border-sidebar-border"),
+ collapsed ? "w-0" : "w-(--sidebar-width)",
+ )}
+ >
+ <div className="flex h-full w-(--sidebar-width) flex-col">
+ {children}
+ </div>
+ </aside>
+ </div>
+ );
+}
+
export function ChatPage(): ReactElement {
const [view, setView] = useState<ChatView>({ mode: "single" });
- const [sidebarOpen, setSidebarOpen] = useState(false);
const [settingsOpen, setSettingsOpen] = useState(false);
const [inferenceParams, setInferenceParams] = useState<InferenceParams>(
defaultInferenceParams,
@@ -186,42 +224,28 @@ export function ChatPage(): ReactElement {
);
return (
- <div className="relative mx-auto flex h-[calc(100vh-4rem)] max-w-7xl px-6">
- {/* animated left sidebar */}
- <AnimatePresence>
- {sidebarOpen && (
- <motion.aside
- initial={{ width: 0, opacity: 0 }}
- animate={{ width: 208, opacity: 1 }}
- exit={{ width: 0, opacity: 0 }}
- transition={{ duration: 0.2, ease: "easeInOut" }}
- className="flex h-full shrink-0 flex-col overflow-hidden border-r border-border/40 bg-muted/50"
- >
- <ThreadSidebar
- view={view}
- onSelect={setView}
- onNewThread={() => setView({ mode: "single" })}
- onNewCompare={() =>
- setView({ mode: "compare", pairId: crypto.randomUUID() })
- }
- />
- </motion.aside>
- )}
- </AnimatePresence>
+ <SidebarProvider
+ defaultOpen={false}
+ className="!min-h-0 h-[calc(100vh-4rem)] max-w-7xl mx-auto px-4"
+ style={{ "--sidebar-width": "14rem", "--sidebar-width-icon": "3rem" } as CSSProperties}
+ >
+ <InlineSidebar>
+ <ThreadSidebar
+ view={view}
+ onSelect={setView}
+ onNewThread={() => setView({ mode: "single" })}
+ onNewCompare={() =>
+ setView({ mode: "compare", pairId: crypto.randomUUID() })
+ }
+ />
+ </InlineSidebar>
{/* main chat area */}
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
{/* top bar */}
- <div className="flex h-11 shrink-0 items-center ">
+ <div className="flex h-11 shrink-0 items-center px-2">
<div className="flex items-center gap-1.5">
- <button
- type="button"
- onClick={() => setSidebarOpen((o) => !o)}
- className="flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
- title={sidebarOpen ? "Close sidebar" : "Open sidebar"}
- >
- <HugeiconsIcon icon={SidebarLeft01Icon} className="size-5" />
- </button>
+ <SidebarTrigger />
<ModelSelector
models={models}
value={inferenceParams.checkpoint}
@@ -231,16 +255,14 @@ export function ChatPage(): ReactElement {
/>
</div>
<div className="flex-1" />
- {!settingsOpen && (
- <button
- type="button"
- onClick={() => setSettingsOpen(true)}
- className="flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
- title="Inference settings"
- >
- <HugeiconsIcon icon={Settings04Icon} className="size-5" />
- </button>
- )}
+ <button
+ type="button"
+ onClick={() => setSettingsOpen((o) => !o)}
+ className="flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
+ title="Inference settings"
+ >
+ <HugeiconsIcon icon={Settings04Icon} className="size-5" />
+ </button>
</div>
{view.mode === "single" ? (
@@ -256,10 +278,9 @@ export function ChatPage(): ReactElement {
{/* inline settings panel on right */}
<ChatSettingsPanel
open={settingsOpen}
- onClose={() => setSettingsOpen(false)}
params={inferenceParams}
onParamsChange={setInferenceParams}
/>
- </div>
+ </SidebarProvider>
);
}
diff --git a/frontend/src/features/chat/chat-settings-sheet.tsx b/frontend/src/features/chat/chat-settings-sheet.tsx
index 8fcc4cc0428..0b006c4e781 100644
--- a/frontend/src/features/chat/chat-settings-sheet.tsx
+++ b/frontend/src/features/chat/chat-settings-sheet.tsx
@@ -11,7 +11,6 @@ import { Slider } from "@/components/ui/slider";
import { Textarea } from "@/components/ui/textarea";
import {
ArrowDown01Icon,
- Cancel01Icon,
Delete02Icon,
EngineIcon,
FloppyDiskIcon,
@@ -21,7 +20,8 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { AnimatePresence, motion } from "motion/react";
-import { type ReactNode, useState } from "react";
+import type { ReactNode } from "react";
+import { useState } from "react";
// --- Types & defaults ---
@@ -170,14 +170,12 @@ function CollapsibleSection({
interface ChatSettingsPanelProps {
open: boolean;
- onClose: () => void;
params: InferenceParams;
onParamsChange: (params: InferenceParams) => void;
}
export function ChatSettingsPanel({
open,
- onClose,
params,
onParamsChange,
}: ChatSettingsPanelProps) {
@@ -219,15 +217,10 @@ export function ChatSettingsPanel({
}
return (
- <AnimatePresence>
- {open && (
- <motion.aside
- initial={{ width: 0, opacity: 0 }}
- animate={{ width: 272, opacity: 1 }}
- exit={{ width: 0, opacity: 0 }}
- transition={{ duration: 0.2, ease: "easeInOut" }}
- className="flex h-full shrink-0 flex-col overflow-hidden border-l border-border/40 bg-muted/50"
- >
+ <aside
+ className={`shrink-0 h-full overflow-hidden bg-sidebar transition-[width] duration-200 ease-linear ${open ? "w-[17rem] border-l border-sidebar-border" : "w-0"}`}
+ >
+ <div className="flex h-full w-[17rem] flex-col">
{/* header */}
<div className="flex items-center gap-2 px-3 py-2">
<HugeiconsIcon
@@ -237,13 +230,6 @@ export function ChatSettingsPanel({
<span className="flex-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
Advanced Configuration
</span>
- <button
- type="button"
- onClick={onClose}
- className="flex items-center justify-center rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent"
- >
- <HugeiconsIcon icon={Cancel01Icon} className="size-3.5" />
- </button>
</div>
<div className="flex-1 overflow-y-auto px-1.5">
@@ -396,8 +382,7 @@ export function ChatSettingsPanel({
</p>
</CollapsibleSection>
</div>
- </motion.aside>
- )}
- </AnimatePresence>
+ </div>
+ </aside>
);
}
diff --git a/frontend/src/features/chat/thread-sidebar.tsx b/frontend/src/features/chat/thread-sidebar.tsx
index 8527704c7dc..f1db67651c1 100644
--- a/frontend/src/features/chat/thread-sidebar.tsx
+++ b/frontend/src/features/chat/thread-sidebar.tsx
@@ -1,14 +1,19 @@
import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/components/ui/dropdown-menu";
+ SidebarContent,
+ SidebarGroup,
+ SidebarGroupContent,
+ SidebarGroupLabel,
+ SidebarHeader,
+ SidebarMenu,
+ SidebarMenuAction,
+ SidebarMenuButton,
+ SidebarMenuItem,
+ SidebarSeparator,
+} from "@/components/ui/sidebar";
import {
- ChatAdd01Icon,
+ ColumnInsertIcon,
Delete02Icon,
- Message02Icon,
- MessageMultiple01Icon,
+ PencilEdit02Icon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { db, useLiveQuery } from "./db";
@@ -16,7 +21,7 @@ import type { ChatView, ThreadRecord } from "./types";
interface SidebarItem {
type: "single" | "compare";
- id: string; // threadId for single, pairId for compare
+ id: string;
title: string;
createdAt: number;
}
@@ -69,7 +74,6 @@ export function ThreadSidebar({
[],
);
const items = groupThreads(allThreads ?? []);
-
const activeId = view.mode === "single" ? view.threadId : view.pairId;
function viewForItem(item: SidebarItem): ChatView {
@@ -83,7 +87,10 @@ export function ThreadSidebar({
await db.messages.where("threadId").equals(item.id).delete();
await db.threads.delete(item.id);
} else {
- const paired = await db.threads.where("pairId").equals(item.id).toArray();
+ const paired = await db.threads
+ .where("pairId")
+ .equals(item.id)
+ .toArray();
for (const t of paired) {
await db.messages.where("threadId").equals(t.id).delete();
await db.threads.delete(t.id);
@@ -96,74 +103,59 @@ export function ThreadSidebar({
return (
<>
- <div className="flex items-center px-3 pt-2.5 pb-1.5">
- <span className="flex-1 text-xs font-medium text-foreground">
- Chats
- </span>
- <DropdownMenu>
- <DropdownMenuTrigger asChild={true}>
- <button
- type="button"
- className="flex items-center justify-center rounded-md p-1 text-muted-foreground hover:bg-accent transition-colors"
- title="New chat"
- >
- <HugeiconsIcon icon={ChatAdd01Icon} className="size-4" />
- </button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem onClick={onNewThread}>
- <HugeiconsIcon icon={Message02Icon} className="size-4" />
- New Chat
- </DropdownMenuItem>
- <DropdownMenuItem onClick={onNewCompare}>
- <HugeiconsIcon icon={MessageMultiple01Icon} className="size-4" />
- Compare Mode
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- <div className="mx-2 border-t border-border/40" />
-
- <div className="flex-1 overflow-y-auto p-1.5 space-y-0.5">
- {items.map((item) => (
- <div
- key={item.id}
- role="button"
- tabIndex={0}
- onClick={() => onSelect(viewForItem(item))}
- onKeyDown={(e) => {
- if (e.key === "Enter" || e.key === " ") {
- e.preventDefault();
- onSelect(viewForItem(item));
- }
- }}
- className={`group flex w-full cursor-pointer items-center gap-2 rounded-lg corner-squircle px-2.5 py-1.5 text-left text-sm transition-colors hover:bg-accent ${
- activeId === item.id ? "bg-accent" : ""
- }`}
- >
- <span className="flex-1 truncate">{item.title}</span>
- <button
- type="button"
- onClick={(e) => {
- e.stopPropagation();
- handleDelete(item);
- }}
- className="rounded p-0.5 opacity-0 group-hover:opacity-100 hover:bg-muted transition-opacity"
- title="Delete"
- >
- <HugeiconsIcon
- icon={Delete02Icon}
- className="size-3 text-muted-foreground"
- />
- </button>
- </div>
- ))}
- {items.length === 0 && (
- <p className="px-2 py-4 text-center text-xs text-muted-foreground">
- No threads yet
- </p>
- )}
- </div>
+ <SidebarHeader>
+ <span className="text-sm font-semibold">Playground</span>
+ </SidebarHeader>
+ <SidebarContent>
+ <SidebarGroup>
+ <SidebarGroupContent>
+ <SidebarMenu>
+ <SidebarMenuItem>
+ <SidebarMenuButton onClick={onNewThread}>
+ <HugeiconsIcon icon={PencilEdit02Icon} />
+ <span>New Chat</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ <SidebarMenuItem>
+ <SidebarMenuButton onClick={onNewCompare}>
+ <HugeiconsIcon icon={ColumnInsertIcon} />
+ <span>Compare</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ </SidebarMenu>
+ </SidebarGroupContent>
+ </SidebarGroup>
+ <SidebarSeparator />
+ <SidebarGroup className="flex-1">
+ <SidebarGroupLabel>Your Chats</SidebarGroupLabel>
+ <SidebarGroupContent>
+ <SidebarMenu>
+ {items.map((item) => (
+ <SidebarMenuItem key={item.id}>
+ <SidebarMenuButton
+ isActive={activeId === item.id}
+ onClick={() => onSelect(viewForItem(item))}
+ >
+ <span>{item.title}</span>
+ </SidebarMenuButton>
+ <SidebarMenuAction
+ showOnHover
+ onClick={() => handleDelete(item)}
+ title="Delete"
+ >
+ <HugeiconsIcon icon={Delete02Icon} />
+ </SidebarMenuAction>
+ </SidebarMenuItem>
+ ))}
+ </SidebarMenu>
+ {items.length === 0 && (
+ <p className="px-2 py-4 text-center text-xs text-muted-foreground">
+ No threads yet
+ </p>
+ )}
+ </SidebarGroupContent>
+ </SidebarGroup>
+ </SidebarContent>
</>
);
}
diff --git a/frontend/src/hooks/use-mobile.ts b/frontend/src/hooks/use-mobile.ts
new file mode 100644
index 00000000000..2b0fe1dfef3
--- /dev/null
+++ b/frontend/src/hooks/use-mobile.ts
@@ -0,0 +1,19 @@
+import * as React from "react"
+
+const MOBILE_BREAKPOINT = 768
+
+export function useIsMobile() {
+ const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
+
+ React.useEffect(() => {
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
+ const onChange = () => {
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
+ }
+ mql.addEventListener("change", onChange)
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
+ return () => mql.removeEventListener("change", onChange)
+ }, [])
+
+ return !!isMobile
+}
diff --git a/frontend/src/index.css b/frontend/src/index.css
index 53ae3aefeab..3347ab0c1d7 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -276,6 +276,37 @@
}
}
+/* Minimal scrollbar — thumb only, no track */
+* {
+ scrollbar-width: thin;
+ scrollbar-color: transparent transparent;
+}
+*:hover {
+ scrollbar-color: oklch(0.6 0 0 / 0.3) transparent;
+}
+.dark *:hover {
+ scrollbar-color: oklch(0.5 0 0 / 0.35) transparent;
+}
+
+/* Webkit (Chrome, Safari, Edge) */
+::-webkit-scrollbar {
+ width: 6px;
+ height: 6px;
+}
+::-webkit-scrollbar-track {
+ background: transparent;
+}
+::-webkit-scrollbar-thumb {
+ background: transparent;
+ border-radius: 9999px;
+}
+*:hover::-webkit-scrollbar-thumb {
+ background: oklch(0.6 0 0 / 0.3);
+}
+.dark *:hover::-webkit-scrollbar-thumb {
+ background: oklch(0.5 0 0 / 0.35);
+}
+
/*---break---*/
@layer base {
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index dc4ab597767..6b0b63b6043 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -1,6 +1,13 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
+if (!crypto.randomUUID) {
+ crypto.randomUUID = () =>
+ "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) =>
+ (+c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))).toString(16),
+ ) as `${string}-${string}-${string}-${string}-${string}`;
+}
+
import "./index.css";
import { App } from "./app/app";