7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(ui): early theme script, mobile hamburger nav, page-header wrap (#178)
Tazrif Raimb4e48c097888
diff --git a/client/index.html b/client/index.htmlindex c5428bfd..4e493902 100644--- a/client/index.html+++ b/client/index.html@@ -4,6 +4,17 @@<meta charset="UTF-8" /><link rel="icon" type="image/svg+xml" href="/favicon.svg" /><meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <script>+ try {+ const theme = localStorage.getItem('theme')+ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches+ if (theme === 'dark' || (!theme && prefersDark)) {+ document.documentElement.classList.add('dark')+ }+ } catch {+ // Keep the initial render working if localStorage is unavailable.+ }+ </script><title>FreeLLMAPI · Unified LLM Router</title></head><body>diff --git a/client/src/App.tsx b/client/src/App.tsxindex 7568bc95..ff85f89b 100644--- a/client/src/App.tsx+++ b/client/src/App.tsx@@ -1,7 +1,16 @@import { useEffect, useState } from 'react'-import { BrowserRouter, Routes, Route, Navigate, NavLink, Link } from 'react-router-dom'+import { BrowserRouter, Routes, Route, Navigate, NavLink, Link, useLocation, useNavigate } from 'react-router-dom'import { QueryClient, QueryClientProvider } from '@tanstack/react-query'-import { Button } from '@/components/ui/button'+import { Menu, Moon, Sun } from 'lucide-react'+import { Button, buttonVariants } from '@/components/ui/button'+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from '@/components/ui/dropdown-menu'import { AuthGate } from '@/components/auth-gate'import { logout } from '@/lib/api'import KeysPage from '@/pages/KeysPage'@@ -12,6 +21,22 @@ import AnalyticsPage from '@/pages/AnalyticsPage'const queryClient = new QueryClient()+const navItems = [+ { to: '/models', label: 'Models' },+ { to: '/playground', label: 'Playground' },+ { to: '/keys', label: 'Keys' },+ { to: '/analytics', label: 'Analytics' },+]++function getPreferredDarkMode() {+ if (typeof window === 'undefined') {+ return false+ }++ const stored = localStorage.getItem('theme')+ return stored === 'dark' || (!stored && window.matchMedia('(prefers-color-scheme: dark)').matches)+}+function NavItem({ to, children }: { to: string; children: React.ReactNode }) {return (<NavLink@@ -29,33 +54,33 @@ function NavItem({ to, children }: { to: string; children: React.ReactNode }) {)}-function DarkModeToggle() {- const [dark, setDark] = useState(() =>- typeof window !== 'undefined' && document.documentElement.classList.contains('dark')- )+function useDarkMode() {+ const [dark, setDark] = useState(getPreferredDarkMode)useEffect(() => {- const stored = localStorage.getItem('theme')- if (stored === 'dark' || (!stored && window.matchMedia('(prefers-color-scheme: dark)').matches)) {- document.documentElement.classList.add('dark')- setDark(true)- }- }, [])+ document.documentElement.classList.toggle('dark', dark)+ }, [dark])function toggle() {- const next = !dark- setDark(next)- document.documentElement.classList.toggle('dark', next)- localStorage.setItem('theme', next ? 'dark' : 'light')+ setDark((current) => {+ const next = !current+ localStorage.setItem('theme', next ? 'dark' : 'light')+ return next+ })}+ return { dark, toggle }+}++function DarkModeToggle({ dark, onToggle }: { dark: boolean; onToggle: () => void }) {return (- <Button variant="ghost" size="sm" onClick={toggle} aria-label="Toggle theme">- {dark ? (- <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>- ) : (- <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>- )}+ <Button+ variant="ghost"+ size="sm"+ onClick={onToggle}+ aria-label={dark ? 'Switch to light theme' : 'Switch to dark theme'}+ >+ {dark ? <Sun /> : <Moon />}</Button>)}@@ -69,27 +94,75 @@ function Brand() {)}+function Navbar() {+ const { dark, toggle } = useDarkMode()+ const location = useLocation()+ const navigate = useNavigate()++ function isActiveRoute(to: string) {+ return location.pathname === to+ }++ return (+ <header className="sticky top-0 z-40 border-b bg-background/80 backdrop-blur">+ <div className="mx-auto flex max-w-6xl items-center px-4 sm:px-6">+ <Brand />+ <nav className="ml-10 hidden items-center gap-6 md:flex">+ {navItems.map((item) => (+ <NavItem key={item.to} to={item.to}>+ {item.label}+ </NavItem>+ ))}+ </nav>+ <div className="ml-auto hidden items-center gap-1 md:flex">+ <DarkModeToggle dark={dark} onToggle={toggle} />+ <Button variant="ghost" size="sm" onClick={() => logout()}>+ Sign out+ </Button>+ </div>+ <div className="ml-auto md:hidden">+ <DropdownMenu>+ <DropdownMenuTrigger+ className={buttonVariants({ variant: 'ghost', size: 'icon' })}+ aria-label="Open navigation menu"+ >+ <Menu />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-52">+ <DropdownMenuGroup>+ {navItems.map((item) => (+ <DropdownMenuItem+ key={item.to}+ onClick={() => navigate(item.to)}+ className={isActiveRoute(item.to) ? 'bg-accent text-accent-foreground font-medium' : undefined}+ >+ {item.label}+ </DropdownMenuItem>+ ))}+ </DropdownMenuGroup>+ <DropdownMenuSeparator />+ <DropdownMenuGroup>+ <DropdownMenuItem onClick={toggle} className="justify-between">+ <span>Theme</span>+ {dark ? <Sun /> : <Moon />}+ </DropdownMenuItem>+ <DropdownMenuItem onClick={() => logout()}>Sign out</DropdownMenuItem>+ </DropdownMenuGroup>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ </div>+ </header>+ )+}+function App() {return (<QueryClientProvider client={queryClient}><BrowserRouter basename={import.meta.env.BASE_URL}><AuthGate><div className="min-h-screen bg-background">- <header className="sticky top-0 z-40 bg-background/80 backdrop-blur border-b">- <div className="max-w-6xl mx-auto px-6 flex items-center">- <Brand />- <nav className="flex items-center gap-6 ml-10">- <NavItem to="/models">Models</NavItem>- <NavItem to="/playground">Playground</NavItem>- <NavItem to="/keys">Keys</NavItem>- <NavItem to="/analytics">Analytics</NavItem>- </nav>- <div className="ml-auto py-2 flex items-center gap-1">- <DarkModeToggle />- <Button variant="ghost" size="sm" onClick={() => logout()}>Sign out</Button>- </div>- </div>- </header>+ <Navbar /><main className="max-w-6xl mx-auto px-6 py-8"><Routes><Route path="/" element={<Navigate to="/models/chat" replace />} />diff --git a/client/src/components/page-header.tsx b/client/src/components/page-header.tsxindex 2c61ef3f..70c690f4 100644--- a/client/src/components/page-header.tsx+++ b/client/src/components/page-header.tsx@@ -12,7 +12,7 @@ export function PageHeader({divider?: boolean}) {return (- <div className={`flex items-end justify-between gap-6 mb-6 ${divider ? 'pb-6 border-b' : ''}`}>+ <div className={`flex flex-wrap md:flex-nowrap items-end justify-between gap-6 mb-6 ${divider ? 'pb-6 border-b' : ''}`}><div className="min-w-0"><h1 className="text-2xl font-semibold tracking-tight">{title}</h1>{description && (diff --git a/client/src/components/ui/dropdown-menu.tsx b/client/src/components/ui/dropdown-menu.tsxnew file mode 100644index 00000000..0a2970aa--- /dev/null+++ b/client/src/components/ui/dropdown-menu.tsx@@ -0,0 +1,266 @@+import * as React from "react"+import { Menu as MenuPrimitive } from "@base-ui/react/menu"++import { cn } from "@/lib/utils"+import { ChevronRightIcon, CheckIcon } from "lucide-react"++function DropdownMenu({ ...props }: MenuPrimitive.Root.Props) {+ return <MenuPrimitive.Root data-slot="dropdown-menu" {...props} />+}++function DropdownMenuPortal({ ...props }: MenuPrimitive.Portal.Props) {+ return <MenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />+}++function DropdownMenuTrigger({ ...props }: MenuPrimitive.Trigger.Props) {+ return <MenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />+}++function DropdownMenuContent({+ align = "start",+ alignOffset = 0,+ side = "bottom",+ sideOffset = 4,+ className,+ ...props+}: MenuPrimitive.Popup.Props &+ Pick<+ MenuPrimitive.Positioner.Props,+ "align" | "alignOffset" | "side" | "sideOffset"+ >) {+ return (+ <MenuPrimitive.Portal>+ <MenuPrimitive.Positioner+ className="isolate z-50 outline-none"+ align={align}+ alignOffset={alignOffset}+ side={side}+ sideOffset={sideOffset}+ >+ <MenuPrimitive.Popup+ data-slot="dropdown-menu-content"+ className={cn("z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95", className )}+ {...props}+ />+ </MenuPrimitive.Positioner>+ </MenuPrimitive.Portal>+ )+}++function DropdownMenuGroup({ ...props }: MenuPrimitive.Group.Props) {+ return <MenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />+}++function DropdownMenuLabel({+ className,+ inset,+ ...props+}: MenuPrimitive.GroupLabel.Props & {+ inset?: boolean+}) {+ return (+ <MenuPrimitive.GroupLabel+ data-slot="dropdown-menu-label"+ data-inset={inset}+ className={cn(+ "px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",+ className+ )}+ {...props}+ />+ )+}++function DropdownMenuItem({+ className,+ inset,+ variant = "default",+ ...props+}: MenuPrimitive.Item.Props & {+ inset?: boolean+ variant?: "default" | "destructive"+}) {+ return (+ <MenuPrimitive.Item+ data-slot="dropdown-menu-item"+ data-inset={inset}+ data-variant={variant}+ className={cn(+ "group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",+ className+ )}+ {...props}+ />+ )+}++function DropdownMenuSub({ ...props }: MenuPrimitive.SubmenuRoot.Props) {+ return <MenuPrimitive.SubmenuRoot data-slot="dropdown-menu-sub" {...props} />+}++function DropdownMenuSubTrigger({+ className,+ inset,+ children,+ ...props+}: MenuPrimitive.SubmenuTrigger.Props & {+ inset?: boolean+}) {+ return (+ <MenuPrimitive.SubmenuTrigger+ data-slot="dropdown-menu-sub-trigger"+ data-inset={inset}+ className={cn(+ "flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className+ )}+ {...props}+ >+ {children}+ <ChevronRightIcon className="ml-auto" />+ </MenuPrimitive.SubmenuTrigger>+ )+}++function DropdownMenuSubContent({+ align = "start",+ alignOffset = -3,+ side = "right",+ sideOffset = 0,+ className,+ ...props+}: React.ComponentProps<typeof DropdownMenuContent>) {+ return (+ <DropdownMenuContent+ data-slot="dropdown-menu-sub-content"+ className={cn("w-auto min-w-24 rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}+ align={align}+ alignOffset={alignOffset}+ side={side}+ sideOffset={sideOffset}+ {...props}+ />+ )+}++function DropdownMenuCheckboxItem({+ className,+ children,+ checked,+ inset,+ ...props+}: MenuPrimitive.CheckboxItem.Props & {+ inset?: boolean+}) {+ return (+ <MenuPrimitive.CheckboxItem+ data-slot="dropdown-menu-checkbox-item"+ data-inset={inset}+ className={cn(+ "relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className+ )}+ checked={checked}+ {...props}+ >+ <span+ className="pointer-events-none absolute right-2 flex items-center justify-center"+ data-slot="dropdown-menu-checkbox-item-indicator"+ >+ <MenuPrimitive.CheckboxItemIndicator>+ <CheckIcon+ />+ </MenuPrimitive.CheckboxItemIndicator>+ </span>+ {children}+ </MenuPrimitive.CheckboxItem>+ )+}++function DropdownMenuRadioGroup({ ...props }: MenuPrimitive.RadioGroup.Props) {+ return (+ <MenuPrimitive.RadioGroup+ data-slot="dropdown-menu-radio-group"+ {...props}+ />+ )+}++function DropdownMenuRadioItem({+ className,+ children,+ inset,+ ...props+}: MenuPrimitive.RadioItem.Props & {+ inset?: boolean+}) {+ return (+ <MenuPrimitive.RadioItem+ data-slot="dropdown-menu-radio-item"+ data-inset={inset}+ className={cn(+ "relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className+ )}+ {...props}+ >+ <span+ className="pointer-events-none absolute right-2 flex items-center justify-center"+ data-slot="dropdown-menu-radio-item-indicator"+ >+ <MenuPrimitive.RadioItemIndicator>+ <CheckIcon+ />+ </MenuPrimitive.RadioItemIndicator>+ </span>+ {children}+ </MenuPrimitive.RadioItem>+ )+}++function DropdownMenuSeparator({+ className,+ ...props+}: MenuPrimitive.Separator.Props) {+ return (+ <MenuPrimitive.Separator+ data-slot="dropdown-menu-separator"+ className={cn("-mx-1 my-1 h-px bg-border", className)}+ {...props}+ />+ )+}++function DropdownMenuShortcut({+ className,+ ...props+}: React.ComponentProps<"span">) {+ return (+ <span+ data-slot="dropdown-menu-shortcut"+ className={cn(+ "ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",+ className+ )}+ {...props}+ />+ )+}++export {+ DropdownMenu,+ DropdownMenuPortal,+ DropdownMenuTrigger,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuLabel,+ DropdownMenuItem,+ DropdownMenuCheckboxItem,+ DropdownMenuRadioGroup,+ DropdownMenuRadioItem,+ DropdownMenuSeparator,+ DropdownMenuShortcut,+ DropdownMenuSub,+ DropdownMenuSubTrigger,+ DropdownMenuSubContent,+}diff --git a/client/src/pages/KeysPage.tsx b/client/src/pages/KeysPage.tsxindex 366d562b..e520405d 100644--- a/client/src/pages/KeysPage.tsx+++ b/client/src/pages/KeysPage.tsx@@ -402,7 +402,7 @@ export default function KeysPage() {<section><h2 className="text-sm font-medium mb-3">Add a provider key</h2>- <form onSubmit={handleSubmit} className="flex flex-wrap items-end gap-3 rounded-3xl border p-4 bg-card">+ <form onSubmit={handleSubmit} className="flex flex-wrap gap-3 rounded-3xl border p-4 bg-card"><div className="space-y-1.5"><Label className="text-xs">Platform</Label><Select value={platform} onValueChange={(v) => setPlatform(v as Platform)}>@@ -449,16 +449,18 @@ export default function KeysPage() {</div><div className="space-y-1.5"><Label className="text-xs">Label</Label>- <Input- value={label}- onChange={e => setLabel(e.target.value)}- placeholder="optional"- className="w-[160px]"- />+ <div className="flex flex-wrap items-center space-x-3">+ <Input+ value={label}+ onChange={e => setLabel(e.target.value)}+ placeholder="optional"+ className="w-[160px]"+ />+ <Button type="submit" size="sm" disabled={!platform || (!isKeyless && !apiKey) || (needsAccountId && !accountId) || addKey.isPending}>+ {addKey.isPending ? 'Adding…' : isKeyless ? 'Enable' : 'Add key'}+ </Button>+ </div></div>- <Button type="submit" size="sm" disabled={!platform || (!isKeyless && !apiKey) || (needsAccountId && !accountId) || addKey.isPending}>- {addKey.isPending ? 'Adding…' : isKeyless ? 'Enable' : 'Add key'}- </Button></form>{addKey.isError && (<p className="text-destructive text-xs mt-2">{(addKey.error as Error).message}</p>