2025-03-17 16:58:22 -07:00
'use client' ;
2024-11-05 14:16:27 +03:00
2025-03-17 16:58:22 -07:00
import Link from 'next/link' ;
import { useRouter } from 'next/navigation' ;
import { useWindowSize } from 'usehooks-ts' ;
2024-10-24 16:35:51 -04:00
2025-03-17 16:58:22 -07:00
import { ModelSelector } from '@/components/model-selector' ;
import { SidebarToggle } from '@/components/sidebar-toggle' ;
import { Button } from '@/components/ui/button' ;
import { PlusIcon , VercelIcon } from './icons' ;
import { useSidebar } from './ui/sidebar' ;
import { memo } from 'react' ;
import { Tooltip , TooltipContent , TooltipTrigger } from './ui/tooltip' ;
import { VisibilityType , VisibilitySelector } from './visibility-selector' ;
2024-10-31 15:39:07 +05:30
2024-12-06 13:36:56 +03:00
function PureChatHeader ( {
chatId ,
selectedModelId ,
selectedVisibilityType ,
isReadonly ,
} : {
chatId : string ;
selectedModelId : string ;
selectedVisibilityType : VisibilityType ;
isReadonly : boolean ;
} ) {
2024-11-06 22:10:15 +03:00
const router = useRouter ( ) ;
2024-11-05 14:16:27 +03:00
const { open } = useSidebar ( ) ;
const { width : windowWidth } = useWindowSize ( ) ;
2024-10-24 16:35:51 -04:00
return (
2024-11-05 14:16:27 +03:00
< header className = "flex sticky top-0 bg-background py-1.5 items-center px-2 md:px-2 gap-2" >
2024-10-24 16:35:51 -04:00
< SidebarToggle / >
2024-12-06 13:36:56 +03:00
2024-11-05 14:16:27 +03:00
{ ( ! open || windowWidth < 768 ) && (
2024-12-04 18:20:35 +03:00
< Tooltip >
< TooltipTrigger asChild >
< Button
variant = "outline"
className = "order-2 md:order-1 md:px-2 px-2 md:h-fit ml-auto md:ml-0"
onClick = { ( ) = > {
2025-03-17 16:58:22 -07:00
router . push ( '/' ) ;
2024-12-04 18:20:35 +03:00
router . refresh ( ) ;
} }
>
< PlusIcon / >
< span className = "md:sr-only" > New Chat < / span >
< / Button >
< / TooltipTrigger >
< TooltipContent > New Chat < / TooltipContent >
< / Tooltip >
2024-11-05 14:16:27 +03:00
) }
2024-12-06 13:36:56 +03:00
{ ! isReadonly && (
< ModelSelector
selectedModelId = { selectedModelId }
className = "order-1 md:order-2"
/ >
) }
{ ! isReadonly && (
< VisibilitySelector
chatId = { chatId }
selectedVisibilityType = { selectedVisibilityType }
className = "order-1 md:order-3"
/ >
) }
2024-11-05 14:16:27 +03:00
< Button
2024-11-06 19:12:46 +03:00
className = "bg-zinc-900 dark:bg-zinc-100 hover:bg-zinc-800 dark:hover:bg-zinc-200 text-zinc-50 dark:text-zinc-900 hidden md:flex py-1.5 px-2 h-fit md:h-[34px] order-4 md:ml-auto"
2024-11-05 14:16:27 +03:00
asChild
>
< Link
2025-03-21 21:18:56 -07:00
href = { ` https://vercel.com/new/clone?repository-url=https://github.com/vercel/ai-chatbot&env=AUTH_SECRET&envDescription=Learn more about how to get the API Keys for the application&envLink=https://github.com/vercel/ai-chatbot/blob/main/.env.example&demo-title=AI Chatbot&demo-description=An Open-Source AI Chatbot Template Built With Next.js and the AI SDK by Vercel.&demo-url=https://chat.vercel.ai&products=[{"type":"integration","protocol":"ai","productSlug":"grok","integrationSlug":"xai"},{"type":"integration","protocol":"ai","productSlug":"api-key","integrationSlug":"groq"},{"type":"integration","protocol":"storage","productSlug":"neon","integrationSlug":"neon"},{"type":"blob"}] ` }
2024-11-05 14:16:27 +03:00
target = "_noblank"
>
< VercelIcon size = { 16 } / >
Deploy with Vercel
< / Link >
< / Button >
2024-10-24 16:35:51 -04:00
< / header >
) ;
}
2024-12-03 17:49:38 +03:00
export const ChatHeader = memo ( PureChatHeader , ( prevProps , nextProps ) = > {
return prevProps . selectedModelId === nextProps . selectedModelId ;
} ) ;