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
dashboard: models nav dropdown + Cmd/Ctrl+K command palette
Tashfeen5ce45b867a08
diff --git a/client/src/App.tsx b/client/src/App.tsxindex e7bea814..533594d3 100644--- a/client/src/App.tsx+++ b/client/src/App.tsx@@ -1,7 +1,7 @@import { useEffect, useState, type ReactNode } from 'react'import { BrowserRouter, Routes, Route, Navigate, NavLink, Link, useLocation, useNavigate } from 'react-router-dom'import { MutationCache, QueryClient, QueryClientProvider } from '@tanstack/react-query'-import { Languages, Menu, MoreHorizontal, Moon, Sun } from 'lucide-react'+import { ChevronDown, Languages, Menu, MoreHorizontal, Moon, Search, Sun } from 'lucide-react'import { buttonVariants } from '@/components/ui/button'import {DropdownMenu,@@ -17,6 +17,7 @@ import {DropdownMenuTrigger,} from '@/components/ui/dropdown-menu'import { AuthGate } from '@/components/auth-gate'+import { CommandPalette, openCommandPalette } from '@/components/command-palette'import { ErrorBoundary } from '@/components/error-boundary'import { Toaster } from '@/components/toaster'import { I18nProvider, useI18n, SUPPORTED_LOCALES, type Locale } from '@/i18n'@@ -56,6 +57,19 @@ const navItems = [{ to: '/premium', labelKey: 'nav.premium' },]+// The five modality pages behind "Models"; surfaced in the nav dropdown and+// the mobile submenu so Fusion/Embeddings/Image/Audio are discoverable without+// first landing on the chat table.+const modelItems = [+ { to: '/models/chat', labelKey: 'models.chatModelsTab' },+ { to: '/models/embeddings', labelKey: 'models.embeddingsTab' },+ { to: '/models/image', labelKey: 'models.imageTab' },+ { to: '/models/audio', labelKey: 'models.audioTab' },+ { to: '/models/fusion', labelKey: 'models.fusionTab' },+]++const isMac = typeof navigator !== 'undefined' && /mac/i.test(navigator.platform)+function getPreferredDarkMode() {if (typeof window === 'undefined') {return false@@ -172,16 +186,48 @@ function Navbar() {className="ml-10 hidden items-center gap-6 md:flex"style={isDesktopApp ? ({ WebkitAppRegion: 'no-drag' } as React.CSSProperties) : undefined}>- {navItems.map((item) => (- <NavItem key={item.to} to={item.to}>- {t(item.labelKey)}- </NavItem>- ))}+ {navItems.map((item) =>+ item.to === '/models' ? (+ // Split control: the label navigates, the chevron reveals the+ // five modality pages hiding behind "Models".+ <div key={item.to} className="flex items-center gap-0.5">+ <NavItem to={item.to}>{t(item.labelKey)}</NavItem>+ <DropdownMenu>+ <DropdownMenuTrigger+ aria-label={t('nav.modelsMenu')}+ className="rounded-md p-1 text-muted-foreground transition-colors hover:text-foreground"+ >+ <ChevronDown className="size-3.5" />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start" className="w-44">+ {modelItems.map((m) => (+ <DropdownMenuItem key={m.to} onClick={() => navigate(m.to)}>+ {t(m.labelKey)}+ </DropdownMenuItem>+ ))}+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ ) : (+ <NavItem key={item.to} to={item.to}>+ {t(item.labelKey)}+ </NavItem>+ ),+ )}</nav><divclassName="ml-auto hidden items-center gap-1 md:flex"style={isDesktopApp ? ({ WebkitAppRegion: 'no-drag' } as React.CSSProperties) : undefined}>+ <button+ type="button"+ onClick={openCommandPalette}+ aria-label={t('palette.title')}+ className={buttonVariants({ variant: 'ghost', size: 'sm' })}+ >+ <Search className="size-3.5" />+ <kbd className="text-[10px] text-muted-foreground">{isMac ? '⌘K' : 'Ctrl K'}</kbd>+ </button><DropdownMenu><DropdownMenuTriggerclassName={buttonVariants({ variant: 'ghost', size: 'icon' })}@@ -214,15 +260,32 @@ function Navbar() {</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}- >- {t(item.labelKey)}- </DropdownMenuItem>- ))}+ {navItems.map((item) =>+ item.to === '/models' ? (+ <DropdownMenuSub key={item.to}>+ <DropdownMenuSubTrigger+ className={location.pathname.startsWith('/models') ? 'bg-accent text-accent-foreground font-medium' : undefined}+ >+ {t(item.labelKey)}+ </DropdownMenuSubTrigger>+ <DropdownMenuSubContent>+ {modelItems.map((m) => (+ <DropdownMenuItem key={m.to} onClick={() => navigate(m.to)}>+ {t(m.labelKey)}+ </DropdownMenuItem>+ ))}+ </DropdownMenuSubContent>+ </DropdownMenuSub>+ ) : (+ <DropdownMenuItem+ key={item.to}+ onClick={() => navigate(item.to)}+ className={isActiveRoute(item.to) ? 'bg-accent text-accent-foreground font-medium' : undefined}+ >+ {t(item.labelKey)}+ </DropdownMenuItem>+ ),+ )}</DropdownMenuGroup><DropdownMenuSeparator /><DropdownMenuGroup>@@ -283,6 +346,7 @@ function App() {</PageBoundary></main><Toaster />+ <CommandPalette /></div></AuthGate></BrowserRouter>diff --git a/client/src/components/command-palette.tsx b/client/src/components/command-palette.tsxnew file mode 100644index 00000000..444b81fa--- /dev/null+++ b/client/src/components/command-palette.tsx@@ -0,0 +1,287 @@+import { useCallback, useEffect, useMemo, useRef, useState } from 'react'+import { useNavigate } from 'react-router-dom'+import { useQuery } from '@tanstack/react-query'+import {+ AudioLines,+ Boxes,+ ChartColumn,+ Copy,+ Image as ImageIcon,+ KeyRound,+ Layers,+ MessageSquare,+ Moon,+ Search,+ Sparkles,+ SquareTerminal,+ Zap,+} from 'lucide-react'+import { apiFetch } from '@/lib/api'+import { toast } from '@/lib/toast'+import { apiBaseUrl } from '@/components/api-usage'+import { useI18n } from '@/i18n'+import type { FallbackEntry } from '@/pages/FallbackPage'++// Open the palette from anywhere (navbar button); same custom-event idiom as+// UNAUTHORIZED_EVENT in lib/api.ts.+export const COMMAND_PALETTE_EVENT = 'freellmapi:command-palette'+export function openCommandPalette() {+ window.dispatchEvent(new CustomEvent(COMMAND_PALETTE_EVENT))+}++interface Command {+ id: string+ group: 'pages' | 'actions' | 'models'+ label: string+ keywords: string+ icon: React.ComponentType<{ className?: string }>+ run: () => void+}++// Cmd+K / Ctrl+K palette: jump to any page or model, toggle theme, copy the+// unified key or base URL. Zero-dep overlay; list is keyboard-driven+// (arrows + Enter) with proper listbox semantics.+export function CommandPalette() {+ const { t } = useI18n()+ const navigate = useNavigate()+ const [open, setOpen] = useState(false)+ const [query, setQuery] = useState('')+ const [active, setActive] = useState(0)+ const openRef = useRef(false)+ const inputRef = useRef<HTMLInputElement>(null)+ const listRef = useRef<HTMLDivElement>(null)++ // Reset happens on show (not in an effect watching `open`): the palette+ // always opens blank with the first row active.+ const show = useCallback(() => {+ openRef.current = true+ setQuery('')+ setActive(0)+ setOpen(true)+ // Focus after the overlay paints.+ requestAnimationFrame(() => inputRef.current?.focus())+ }, [])+ const hide = useCallback(() => {+ openRef.current = false+ setOpen(false)+ }, [])++ useEffect(() => {+ function onKey(e: KeyboardEvent) {+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {+ e.preventDefault()+ if (openRef.current) hide()+ else show()+ } else if (e.key === 'Escape' && openRef.current) {+ hide()+ }+ }+ window.addEventListener('keydown', onKey)+ window.addEventListener(COMMAND_PALETTE_EVENT, show)+ return () => {+ window.removeEventListener('keydown', onKey)+ window.removeEventListener(COMMAND_PALETTE_EVENT, show)+ }+ }, [show, hide])++ // Model index + unified key load lazily, only while the palette is open.+ const { data: entries = [] } = useQuery<FallbackEntry[]>({+ queryKey: ['fallback'],+ queryFn: () => apiFetch('/api/fallback'),+ enabled: open,+ })+ const { data: keyData } = useQuery<{ apiKey: string }>({+ queryKey: ['unified-key'],+ queryFn: () => apiFetch('/api/settings/api-key'),+ enabled: open,+ })++ const commands = useMemo<Command[]>(() => {+ const go = (to: string) => () => navigate(to)+ const pages: Command[] = [+ { id: 'p-chat', group: 'pages', label: t('models.chatModelsTab'), keywords: 'models chat routing fallback', icon: MessageSquare, run: go('/models/chat') },+ { id: 'p-embeddings', group: 'pages', label: t('models.embeddingsTab'), keywords: 'models embeddings vectors', icon: Layers, run: go('/models/embeddings') },+ { id: 'p-image', group: 'pages', label: t('models.imageTab'), keywords: 'models image generation', icon: ImageIcon, run: go('/models/image') },+ { id: 'p-audio', group: 'pages', label: t('models.audioTab'), keywords: 'models audio speech tts', icon: AudioLines, run: go('/models/audio') },+ { id: 'p-fusion', group: 'pages', label: t('models.fusionTab'), keywords: 'models fusion synthesis panel judge', icon: Zap, run: go('/models/fusion') },+ { id: 'p-playground', group: 'pages', label: t('nav.playground'), keywords: 'playground test chat try', icon: SquareTerminal, run: go('/playground') },+ { id: 'p-keys', group: 'pages', label: t('nav.keys'), keywords: 'keys providers api tokens', icon: KeyRound, run: go('/keys') },+ { id: 'p-analytics', group: 'pages', label: t('nav.analytics'), keywords: 'analytics usage stats savings latency', icon: ChartColumn, run: go('/analytics') },+ { id: 'p-premium', group: 'pages', label: t('nav.premium'), keywords: 'premium catalog license subscription', icon: Sparkles, run: go('/premium') },+ ]+ const actions: Command[] = [+ {+ id: 'a-theme',+ group: 'actions',+ label: t('palette.toggleTheme'),+ keywords: 'theme dark light mode toggle',+ icon: Moon,+ run: () => {+ const next = !document.documentElement.classList.contains('dark')+ document.documentElement.classList.toggle('dark', next)+ try { localStorage.setItem('theme', next ? 'dark' : 'light') } catch { /* ignore */ }+ },+ },+ {+ id: 'a-copy-key',+ group: 'actions',+ label: t('setup.copyKey'),+ keywords: 'copy api key unified token',+ icon: Copy,+ run: () => {+ if (!keyData?.apiKey) return+ void navigator.clipboard?.writeText(keyData.apiKey)+ toast.success(t('setup.copiedKey'))+ },+ },+ {+ id: 'a-copy-url',+ group: 'actions',+ label: t('setup.copyUrl'),+ keywords: 'copy base url endpoint',+ icon: Copy,+ run: () => {+ void navigator.clipboard?.writeText(apiBaseUrl())+ toast.success(t('setup.copiedUrl'))+ },+ },+ ]+ // One entry per logical model (configured providers only).+ const seen = new Set<string>()+ const models: Command[] = []+ for (const e of entries) {+ if (e.keyCount === 0) continue+ const canonical = e.canonicalId ?? e.modelId+ if (seen.has(canonical)) continue+ seen.add(canonical)+ const label = e.groupLabel ?? e.displayName+ models.push({+ id: `m-${canonical}`,+ group: 'models',+ label,+ keywords: `${canonical} ${e.modelId} ${e.platform}`,+ icon: Boxes,+ run: go(`/models/chat/${encodeURIComponent(canonical)}`),+ })+ }+ return [...pages, ...actions, ...models]+ }, [entries, keyData, navigate, t])++ const filtered = useMemo(() => {+ const q = query.trim().toLowerCase()+ if (!q) return commands.filter(c => c.group !== 'models').concat(commands.filter(c => c.group === 'models').slice(0, 5))+ const matches = commands.filter(c => c.label.toLowerCase().includes(q) || c.keywords.toLowerCase().includes(q))+ // Pages/actions first, then at most 8 model hits so the list stays scannable.+ return matches.filter(c => c.group !== 'models').concat(matches.filter(c => c.group === 'models').slice(0, 8))+ }, [commands, query])++ useEffect(() => {+ const el = listRef.current?.querySelector(`[data-index="${active}"]`)+ el?.scrollIntoView({ block: 'nearest' })+ }, [active])++ if (!open) return null++ function runCommand(cmd: Command) {+ hide()+ cmd.run()+ }++ function onListKeyDown(e: React.KeyboardEvent) {+ if (e.key === 'ArrowDown') {+ e.preventDefault()+ setActive(a => Math.min(a + 1, filtered.length - 1))+ } else if (e.key === 'ArrowUp') {+ e.preventDefault()+ setActive(a => Math.max(a - 1, 0))+ } else if (e.key === 'Enter' && filtered[active]) {+ e.preventDefault()+ runCommand(filtered[active])+ }+ }++ const groups: { key: Command['group']; labelKey: string }[] = [+ { key: 'pages', labelKey: 'palette.groupPages' },+ { key: 'actions', labelKey: 'palette.groupActions' },+ { key: 'models', labelKey: 'palette.groupModels' },+ ]++ let flatIndex = -1++ return (+ <div+ className="fixed inset-0 z-[70] flex items-start justify-center bg-black/40 px-4 pt-[18vh] backdrop-blur-[2px]"+ onMouseDown={e => {+ if (e.target === e.currentTarget) hide()+ }}+ >+ <div+ role="dialog"+ aria-modal="true"+ aria-label={t('palette.title')}+ className="w-full max-w-lg overflow-hidden rounded-2xl border bg-popover shadow-2xl animate-in fade-in zoom-in-95 duration-150"+ onKeyDown={onListKeyDown}+ >+ <div className="flex items-center gap-2.5 border-b px-3.5">+ <Search className="size-4 shrink-0 text-muted-foreground" />+ <input+ ref={inputRef}+ value={query}+ onChange={e => {+ setQuery(e.target.value)+ setActive(0)+ }}+ placeholder={t('palette.placeholder')}+ aria-label={t('palette.placeholder')}+ role="combobox"+ aria-expanded="true"+ aria-controls="command-palette-list"+ aria-activedescendant={filtered[active] ? `cmd-${filtered[active].id}` : undefined}+ className="h-11 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"+ />+ <kbd className="rounded border px-1.5 py-0.5 text-[10px] text-muted-foreground">esc</kbd>+ </div>+ <div ref={listRef} id="command-palette-list" role="listbox" className="max-h-80 overflow-y-auto p-1.5">+ {filtered.length === 0 && (+ <p className="px-3 py-8 text-center text-sm text-muted-foreground">{t('palette.empty')}</p>+ )}+ {groups.map(g => {+ const items = filtered.filter(c => c.group === g.key)+ if (items.length === 0) return null+ return (+ <div key={g.key} className="mb-1 last:mb-0">+ <p className="px-2.5 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70">+ {t(g.labelKey)}+ </p>+ {items.map(cmd => {+ flatIndex += 1+ const index = flatIndex+ const isActive = index === active+ const Icon = cmd.icon+ return (+ <button+ key={cmd.id}+ id={`cmd-${cmd.id}`}+ type="button"+ role="option"+ aria-selected={isActive}+ data-index={index}+ onMouseEnter={() => setActive(index)}+ onClick={() => runCommand(cmd)}+ className={`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-sm transition-colors ${+ isActive ? 'bg-muted text-foreground' : 'text-muted-foreground'+ }`}+ >+ <Icon className="size-4 shrink-0" />+ <span className="min-w-0 flex-1 truncate">{cmd.label}</span>+ </button>+ )+ })}+ </div>+ )+ })}+ </div>+ </div>+ </div>+ )+}diff --git a/client/src/i18n/locales/en.json b/client/src/i18n/locales/en.jsonindex 5ca15ac1..66fe2f35 100644--- a/client/src/i18n/locales/en.json+++ b/client/src/i18n/locales/en.json@@ -12,7 +12,8 @@"switchDark": "Switch to dark theme","language": "Change language","switchToChinese": "Switch to Chinese",- "switchToEnglish": "Switch to English"+ "switchToEnglish": "Switch to English",+ "modelsMenu": "Browse model types"},"auth": {"createYourAccount": "Create your account",@@ -497,5 +498,14 @@"copyUrl": "Copy base URL","copiedKey": "API key copied to clipboard","copiedUrl": "Base URL copied to clipboard"+ },+ "palette": {+ "title": "Command palette",+ "placeholder": "Search pages, models, actions…",+ "empty": "No results",+ "groupPages": "Pages",+ "groupActions": "Actions",+ "groupModels": "Models",+ "toggleTheme": "Toggle dark mode"}}diff --git a/client/src/i18n/locales/es.json b/client/src/i18n/locales/es.jsonindex 9cfeea60..61bbfc8e 100644--- a/client/src/i18n/locales/es.json+++ b/client/src/i18n/locales/es.json@@ -12,7 +12,8 @@"switchDark": "Cambiar al tema oscuro","language": "Cambiar idioma","switchToChinese": "Cambiar a chino",- "switchToEnglish": "Cambiar a inglés"+ "switchToEnglish": "Cambiar a inglés",+ "modelsMenu": "Explorar tipos de modelos"},"auth": {"createYourAccount": "Crea tu cuenta",@@ -418,5 +419,14 @@"copyUrl": "Copiar URL base","copiedKey": "Clave API copiada al portapapeles","copiedUrl": "URL base copiada al portapapeles"+ },+ "palette": {+ "title": "Paleta de comandos",+ "placeholder": "Buscar páginas, modelos, acciones…",+ "empty": "Sin resultados",+ "groupPages": "Páginas",+ "groupActions": "Acciones",+ "groupModels": "Modelos",+ "toggleTheme": "Alternar modo oscuro"}}diff --git a/client/src/i18n/locales/fr.json b/client/src/i18n/locales/fr.jsonindex 8e98b059..f3375fd0 100644--- a/client/src/i18n/locales/fr.json+++ b/client/src/i18n/locales/fr.json@@ -12,7 +12,8 @@"switchDark": "Passer au thème sombre","language": "Changer de langue","switchToChinese": "Passer au chinois",- "switchToEnglish": "Passer à l'anglais"+ "switchToEnglish": "Passer à l'anglais",+ "modelsMenu": "Parcourir les types de modèles"},"auth": {"createYourAccount": "Créez votre compte",@@ -418,5 +419,14 @@"copyUrl": "Copier l'URL de base","copiedKey": "Clé API copiée dans le presse-papiers","copiedUrl": "URL de base copiée dans le presse-papiers"+ },+ "palette": {+ "title": "Palette de commandes",+ "placeholder": "Rechercher des pages, modèles, actions…",+ "empty": "Aucun résultat",+ "groupPages": "Pages",+ "groupActions": "Actions",+ "groupModels": "Modèles",+ "toggleTheme": "Basculer le mode sombre"}}diff --git a/client/src/i18n/locales/it.json b/client/src/i18n/locales/it.jsonindex 5e4e2111..4c560e4e 100644--- a/client/src/i18n/locales/it.json+++ b/client/src/i18n/locales/it.json@@ -12,7 +12,8 @@"switchDark": "Passa al tema scuro","language": "Cambia lingua","switchToChinese": "Passa al cinese",- "switchToEnglish": "Passa all'inglese"+ "switchToEnglish": "Passa all'inglese",+ "modelsMenu": "Sfoglia i tipi di modello"},"auth": {"createYourAccount": "Crea il tuo account",@@ -439,5 +440,14 @@"copyUrl": "Copia URL di base","copiedKey": "Chiave API copiata negli appunti","copiedUrl": "URL di base copiato negli appunti"+ },+ "palette": {+ "title": "Palette dei comandi",+ "placeholder": "Cerca pagine, modelli, azioni…",+ "empty": "Nessun risultato",+ "groupPages": "Pagine",+ "groupActions": "Azioni",+ "groupModels": "Modelli",+ "toggleTheme": "Attiva/disattiva la modalità scura"}}diff --git a/client/src/i18n/locales/pt-BR.json b/client/src/i18n/locales/pt-BR.jsonindex 20c0468a..a8a49daa 100644--- a/client/src/i18n/locales/pt-BR.json+++ b/client/src/i18n/locales/pt-BR.json@@ -12,7 +12,8 @@"switchDark": "Mudar para o tema escuro","language": "Alterar idioma","switchToChinese": "Mudar para chinês",- "switchToEnglish": "Mudar para inglês"+ "switchToEnglish": "Mudar para inglês",+ "modelsMenu": "Explorar tipos de modelo"},"auth": {"createYourAccount": "Crie sua conta",@@ -418,5 +419,14 @@"copyUrl": "Copiar URL base","copiedKey": "Chave de API copiada para a área de transferência","copiedUrl": "URL base copiada para a área de transferência"+ },+ "palette": {+ "title": "Paleta de comandos",+ "placeholder": "Buscar páginas, modelos, ações…",+ "empty": "Sem resultados",+ "groupPages": "Páginas",+ "groupActions": "Ações",+ "groupModels": "Modelos",+ "toggleTheme": "Alternar modo escuro"}}diff --git a/client/src/i18n/locales/zh-CN.json b/client/src/i18n/locales/zh-CN.jsonindex ec0667c2..1f585bd0 100644--- a/client/src/i18n/locales/zh-CN.json+++ b/client/src/i18n/locales/zh-CN.json@@ -12,7 +12,8 @@"switchDark": "切换到深色主题","language": "切换语言","switchToChinese": "切换到中文",- "switchToEnglish": "Switch to English"+ "switchToEnglish": "Switch to English",+ "modelsMenu": "浏览模型类型"},"auth": {"createYourAccount": "创建账号",@@ -441,5 +442,14 @@"copyUrl": "复制基础 URL","copiedKey": "API 密钥已复制到剪贴板","copiedUrl": "基础 URL 已复制到剪贴板"+ },+ "palette": {+ "title": "命令面板",+ "placeholder": "搜索页面、模型、操作…",+ "empty": "无结果",+ "groupPages": "页面",+ "groupActions": "操作",+ "groupModels": "模型",+ "toggleTheme": "切换深色模式"}}