An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor: replace model selector with shadcn combobox
Yoshiki Miurad341aaa554ec
diff --git a/app/globals.css b/app/globals.cssindex e7f71728..3da32f90 100644--- a/app/globals.css+++ b/app/globals.css@@ -33,6 +33,16 @@--ring: 0 0% 89.8%;--radius: 0.5rem;++ --chart-1: 12 76% 61%;++ --chart-2: 173 58% 39%;++ --chart-3: 197 37% 24%;++ --chart-4: 43 74% 66%;++ --chart-5: 27 87% 67%;}.dark {@@ -63,6 +73,11 @@--border: 0 0% 14.9%;--input: 0 0% 14.9%;--ring: 0 0% 14.9%;+ --chart-1: 220 70% 50%;+ --chart-2: 160 60% 45%;+ --chart-3: 30 80% 55%;+ --chart-4: 280 65% 60%;+ --chart-5: 340 75% 55%;}}diff --git a/bun.lockb b/bun.lockbindex 00802ea0..20cfbb3d 100755Binary files a/bun.lockb and b/bun.lockb differdiff --git a/components.json b/components.jsonindex 1e879bc7..d9ef0ae5 100644--- a/components.json+++ b/components.json@@ -12,6 +12,10 @@},"aliases": {"components": "@/components",- "utils": "@/lib/utils"- }+ "utils": "@/lib/utils",+ "ui": "@/components/ui",+ "lib": "@/lib",+ "hooks": "@/hooks"+ },+ "iconLibrary": "lucide"}\ No newline at end of filediff --git a/components/model-selector.tsx b/components/model-selector.tsxindex b9f66d9c..887279ac 100644--- a/components/model-selector.tsx+++ b/components/model-selector.tsx@@ -1,19 +1,21 @@'use client'-import {- Select,- SelectContent,- SelectGroup,- SelectItem,- SelectLabel,- SelectTrigger,- SelectValue-} from './ui/select'-import Image from 'next/image'import { Model, models } from '@/lib/types/models'-import { createModelId } from '@/lib/utils'import { getCookie, setCookie } from '@/lib/utils/cookies'+import { Check, ChevronsUpDown } from 'lucide-react'+import Image from 'next/image'import { useEffect, useState } from 'react'+import { createModelId } from '../lib/utils'+import { Button } from './ui/button'+import {+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList+} from './ui/command'+import { Popover, PopoverContent, PopoverTrigger } from './ui/popover'function groupModelsByProvider(models: Model[]) {return models.reduce((groups, model) => {@@ -27,6 +29,7 @@ function groupModelsByProvider(models: Model[]) {}export function ModelSelector() {+ const [open, setOpen] = useState(false)const [selectedModelId, setSelectedModelId] = useState<string>('')useEffect(() => {@@ -36,53 +39,88 @@ export function ModelSelector() {}}, [])- const handleModelChange = (id: string) => {- if (!id) return-+ const handleModelSelect = (id: string) => {+ setSelectedModelId(id === selectedModelId ? '' : id)setCookie('selected-model', id)- setSelectedModelId(id)+ setOpen(false)}const groupedModels = groupModelsByProvider(models)+ const selectedModel = models.find(m => createModelId(m) === selectedModelId)return (- <div className="absolute -top-8 left-2">- <Select- name="model"- value={selectedModelId}- onValueChange={handleModelChange}- >- <SelectTrigger className="mr-2 h-7 text-xs border-none shadow-none focus:ring-0">- <SelectValue placeholder="Select model" />- </SelectTrigger>- <SelectContent className="max-h-[300px] overflow-y-auto">- {Object.entries(groupedModels).map(([provider, models]) => (- <SelectGroup key={provider}>- <SelectLabel className="text-xs sticky top-0 bg-background z-10">- {provider}- </SelectLabel>- {models.map(model => (- <SelectItem- key={createModelId(model)}- value={createModelId(model)}- className="py-2"- >- <div className="flex items-center space-x-1">- <Image- src={`/providers/logos/${model.providerId}.svg`}- alt={model.provider}- width={18}- height={18}- className="bg-white rounded-full border"- />- <span className="text-xs font-medium">{model.name}</span>- </div>- </SelectItem>+ <div className="absolute -top-11 left-0">+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <Button+ variant="outline"+ role="combobox"+ aria-expanded={open}+ className="text-sm border-none rounded-full shadow-none focus:ring-0"+ >+ {selectedModel ? (+ <div className="flex items-center space-x-1">+ <Image+ src={`/providers/logos/${selectedModel.providerId}.svg`}+ alt={selectedModel.provider}+ width={18}+ height={18}+ className="bg-white rounded-full border"+ />+ <span className="text-xs font-medium">+ {selectedModel.name}+ </span>+ </div>+ ) : (+ 'Select model'+ )}+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-72 p-0" align="start">+ <Command>+ <CommandInput placeholder="Search models..." />+ <CommandList>+ <CommandEmpty>No model found.</CommandEmpty>+ {Object.entries(groupedModels).map(([provider, models]) => (+ <CommandGroup key={provider} heading={provider}>+ {models.map(model => {+ const modelId = createModelId(model)+ return (+ <CommandItem+ key={modelId}+ value={modelId}+ onSelect={handleModelSelect}+ className="flex justify-between"+ >+ <div className="flex items-center space-x-2">+ <Image+ src={`/providers/logos/${model.providerId}.svg`}+ alt={model.provider}+ width={18}+ height={18}+ className="bg-white rounded-full border"+ />+ <span className="text-xs font-medium">+ {model.name}+ </span>+ </div>+ <Check+ className={`h-4 w-4 ${+ selectedModelId === modelId+ ? 'opacity-100'+ : 'opacity-0'+ }`}+ />+ </CommandItem>+ )+ })}+ </CommandGroup>))}- </SelectGroup>- ))}- </SelectContent>- </Select>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover></div>)}diff --git a/components/ui/command.tsx b/components/ui/command.tsxnew file mode 100644index 00000000..59a26452--- /dev/null+++ b/components/ui/command.tsx@@ -0,0 +1,153 @@+"use client"++import * as React from "react"+import { type DialogProps } from "@radix-ui/react-dialog"+import { Command as CommandPrimitive } from "cmdk"+import { Search } from "lucide-react"++import { cn } from "@/lib/utils"+import { Dialog, DialogContent } from "@/components/ui/dialog"++const Command = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive>+>(({ className, ...props }, ref) => (+ <CommandPrimitive+ ref={ref}+ className={cn(+ "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",+ className+ )}+ {...props}+ />+))+Command.displayName = CommandPrimitive.displayName++const CommandDialog = ({ children, ...props }: DialogProps) => {+ return (+ <Dialog {...props}>+ <DialogContent className="overflow-hidden p-0 shadow-lg">+ <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">+ {children}+ </Command>+ </DialogContent>+ </Dialog>+ )+}++const CommandInput = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Input>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>+>(({ className, ...props }, ref) => (+ <div className="flex items-center border-b px-3" cmdk-input-wrapper="">+ <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />+ <CommandPrimitive.Input+ ref={ref}+ className={cn(+ "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",+ className+ )}+ {...props}+ />+ </div>+))++CommandInput.displayName = CommandPrimitive.Input.displayName++const CommandList = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.List>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.List+ ref={ref}+ className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}+ {...props}+ />+))++CommandList.displayName = CommandPrimitive.List.displayName++const CommandEmpty = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Empty>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>+>((props, ref) => (+ <CommandPrimitive.Empty+ ref={ref}+ className="py-6 text-center text-sm"+ {...props}+ />+))++CommandEmpty.displayName = CommandPrimitive.Empty.displayName++const CommandGroup = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Group>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Group+ ref={ref}+ className={cn(+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",+ className+ )}+ {...props}+ />+))++CommandGroup.displayName = CommandPrimitive.Group.displayName++const CommandSeparator = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Separator>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Separator+ ref={ref}+ className={cn("-mx-1 h-px bg-border", className)}+ {...props}+ />+))+CommandSeparator.displayName = CommandPrimitive.Separator.displayName++const CommandItem = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Item>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Item+ ref={ref}+ className={cn(+ "relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",+ className+ )}+ {...props}+ />+))++CommandItem.displayName = CommandPrimitive.Item.displayName++const CommandShortcut = ({+ className,+ ...props+}: React.HTMLAttributes<HTMLSpanElement>) => {+ return (+ <span+ className={cn(+ "ml-auto text-xs tracking-widest text-muted-foreground",+ className+ )}+ {...props}+ />+ )+}+CommandShortcut.displayName = "CommandShortcut"++export {+ Command,+ CommandDialog,+ CommandInput,+ CommandList,+ CommandEmpty,+ CommandGroup,+ CommandItem,+ CommandShortcut,+ CommandSeparator,+}diff --git a/components/ui/dialog.tsx b/components/ui/dialog.tsxindex 5509e2dd..01ff19c7 100644--- a/components/ui/dialog.tsx+++ b/components/ui/dialog.tsx@@ -1,10 +1,10 @@-'use client'+"use client"-import * as React from 'react'-import * as DialogPrimitive from '@radix-ui/react-dialog'-import { X } from 'lucide-react'+import * as React from "react"+import * as DialogPrimitive from "@radix-ui/react-dialog"+import { X } from "lucide-react"-import { cn } from '@/lib/utils'+import { cn } from "@/lib/utils"const Dialog = DialogPrimitive.Root@@ -21,7 +21,7 @@ const DialogOverlay = React.forwardRef<<DialogPrimitive.Overlayref={ref}className={cn(- 'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",className)}{...props}@@ -38,7 +38,7 @@ const DialogContent = React.forwardRef<<DialogPrimitive.Contentref={ref}className={cn(- 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",className)}{...props}@@ -59,13 +59,13 @@ const DialogHeader = ({}: React.HTMLAttributes<HTMLDivElement>) => (<divclassName={cn(- 'flex flex-col space-y-1.5 text-center sm:text-left',+ "flex flex-col space-y-1.5 text-center sm:text-left",className)}{...props}/>)-DialogHeader.displayName = 'DialogHeader'+DialogHeader.displayName = "DialogHeader"const DialogFooter = ({className,@@ -73,13 +73,13 @@ const DialogFooter = ({}: React.HTMLAttributes<HTMLDivElement>) => (<divclassName={cn(- 'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",className)}{...props}/>)-DialogFooter.displayName = 'DialogFooter'+DialogFooter.displayName = "DialogFooter"const DialogTitle = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Title>,@@ -88,7 +88,7 @@ const DialogTitle = React.forwardRef<<DialogPrimitive.Titleref={ref}className={cn(- 'text-lg font-semibold leading-none tracking-tight',+ "text-lg font-semibold leading-none tracking-tight",className)}{...props}@@ -102,7 +102,7 @@ const DialogDescription = React.forwardRef<>(({ className, ...props }, ref) => (<DialogPrimitive.Descriptionref={ref}- className={cn('text-sm text-muted-foreground', className)}+ className={cn("text-sm text-muted-foreground", className)}{...props}/>))@@ -118,5 +118,5 @@ export {DialogHeader,DialogFooter,DialogTitle,- DialogDescription+ DialogDescription,}diff --git a/components/ui/popover.tsx b/components/ui/popover.tsxnew file mode 100644index 00000000..a0ec48be--- /dev/null+++ b/components/ui/popover.tsx@@ -0,0 +1,31 @@+"use client"++import * as React from "react"+import * as PopoverPrimitive from "@radix-ui/react-popover"++import { cn } from "@/lib/utils"++const Popover = PopoverPrimitive.Root++const PopoverTrigger = PopoverPrimitive.Trigger++const PopoverContent = React.forwardRef<+ React.ElementRef<typeof PopoverPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>+>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (+ <PopoverPrimitive.Portal>+ <PopoverPrimitive.Content+ ref={ref}+ align={align}+ sideOffset={sideOffset}+ className={cn(+ "z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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",+ className+ )}+ {...props}+ />+ </PopoverPrimitive.Portal>+))+PopoverContent.displayName = PopoverPrimitive.Content.displayName++export { Popover, PopoverTrigger, PopoverContent }diff --git a/package.json b/package.jsonindex 959ff79f..5efcc291 100644--- a/package.json+++ b/package.json@@ -19,9 +19,10 @@"@radix-ui/react-avatar": "^1.0.4","@radix-ui/react-checkbox": "^1.0.4","@radix-ui/react-collapsible": "^1.0.3",- "@radix-ui/react-dialog": "^1.0.5",+ "@radix-ui/react-dialog": "^1.1.5","@radix-ui/react-dropdown-menu": "^2.0.6","@radix-ui/react-label": "^2.0.2",+ "@radix-ui/react-popover": "^1.1.5","@radix-ui/react-select": "^2.1.2","@radix-ui/react-separator": "^1.0.3","@radix-ui/react-slider": "^1.1.2",@@ -31,13 +32,14 @@"@tailwindcss/typography": "^0.5.12","@upstash/redis": "^1.34.0","ai": "^4.1.0",- "class-variance-authority": "^0.7.0",- "clsx": "^2.1.0",+ "class-variance-authority": "^0.7.1",+ "clsx": "^2.1.1",+ "cmdk": "1.0.0","embla-carousel-react": "^8.0.0","exa-js": "^1.0.12","jsdom": "^22.1.0","katex": "^0.16.10",- "lucide-react": "^0.363.0",+ "lucide-react": "^0.474.0","next": "^15.1.3","next-themes": "^0.3.0","node-html-parser": "^6.1.13",@@ -54,7 +56,7 @@"remark-gfm": "^3.0.1","remark-math": "^5.1.1","sonner": "^1.4.41",- "tailwind-merge": "^2.2.2",+ "tailwind-merge": "^2.6.0","tailwindcss-animate": "^1.0.7","zod": "^3.23.8"},diff --git a/tailwind.config.ts b/tailwind.config.tsindex 68c971ee..0fbbe6f1 100644--- a/tailwind.config.ts+++ b/tailwind.config.ts@@ -11,72 +11,90 @@ const config = {],prefix: "",theme: {- container: {- center: true,- padding: "2rem",- screens: {- "2xl": "1400px",- },- },- extend: {- colors: {- border: "hsl(var(--border))",- input: "hsl(var(--input))",- ring: "hsl(var(--ring))",- background: "hsl(var(--background))",- foreground: "hsl(var(--foreground))",- primary: {- DEFAULT: "hsl(var(--primary))",- foreground: "hsl(var(--primary-foreground))",- },- secondary: {- DEFAULT: "hsl(var(--secondary))",- foreground: "hsl(var(--secondary-foreground))",- },- destructive: {- DEFAULT: "hsl(var(--destructive))",- foreground: "hsl(var(--destructive-foreground))",- },- muted: {- DEFAULT: "hsl(var(--muted))",- foreground: "hsl(var(--muted-foreground))",- },- accent: {- DEFAULT: "hsl(var(--accent))",- foreground: "hsl(var(--accent-foreground))",- },- popover: {- DEFAULT: "hsl(var(--popover))",- foreground: "hsl(var(--popover-foreground))",- },- card: {- DEFAULT: "hsl(var(--card))",- foreground: "hsl(var(--card-foreground))",- },- },- borderRadius: {- lg: "var(--radius)",- md: "calc(var(--radius) - 2px)",- sm: "calc(var(--radius) - 4px)",- },- keyframes: {- "accordion-down": {- from: { height: "0" },- to: { height: "var(--radix-accordion-content-height)" },- },- "accordion-up": {- from: { height: "var(--radix-accordion-content-height)" },- to: { height: "0" },- },- },- animation: {- "accordion-down": "accordion-down 0.2s ease-out",- "accordion-up": "accordion-up 0.2s ease-out",- },- fontFamily: {- sans: ["var(--font-sans)", ...fontFamily.sans],- },- },+ container: {+ center: true,+ padding: '2rem',+ screens: {+ '2xl': '1400px'+ }+ },+ extend: {+ colors: {+ border: 'hsl(var(--border))',+ input: 'hsl(var(--input))',+ ring: 'hsl(var(--ring))',+ background: 'hsl(var(--background))',+ foreground: 'hsl(var(--foreground))',+ primary: {+ DEFAULT: 'hsl(var(--primary))',+ foreground: 'hsl(var(--primary-foreground))'+ },+ secondary: {+ DEFAULT: 'hsl(var(--secondary))',+ foreground: 'hsl(var(--secondary-foreground))'+ },+ destructive: {+ DEFAULT: 'hsl(var(--destructive))',+ foreground: 'hsl(var(--destructive-foreground))'+ },+ muted: {+ DEFAULT: 'hsl(var(--muted))',+ foreground: 'hsl(var(--muted-foreground))'+ },+ accent: {+ DEFAULT: 'hsl(var(--accent))',+ foreground: 'hsl(var(--accent-foreground))'+ },+ popover: {+ DEFAULT: 'hsl(var(--popover))',+ foreground: 'hsl(var(--popover-foreground))'+ },+ card: {+ DEFAULT: 'hsl(var(--card))',+ foreground: 'hsl(var(--card-foreground))'+ },+ chart: {+ '1': 'hsl(var(--chart-1))',+ '2': 'hsl(var(--chart-2))',+ '3': 'hsl(var(--chart-3))',+ '4': 'hsl(var(--chart-4))',+ '5': 'hsl(var(--chart-5))'+ }+ },+ borderRadius: {+ lg: 'var(--radius)',+ md: 'calc(var(--radius) - 2px)',+ sm: 'calc(var(--radius) - 4px)'+ },+ keyframes: {+ 'accordion-down': {+ from: {+ height: '0'+ },+ to: {+ height: 'var(--radix-accordion-content-height)'+ }+ },+ 'accordion-up': {+ from: {+ height: 'var(--radix-accordion-content-height)'+ },+ to: {+ height: '0'+ }+ }+ },+ animation: {+ 'accordion-down': 'accordion-down 0.2s ease-out',+ 'accordion-up': 'accordion-up 0.2s ease-out'+ },+ fontFamily: {+ sans: [+ 'var(--font-sans)',+ ...fontFamily.sans+ ]+ }+ }},plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")],} satisfies Config;