2023-09-29 22:51:54 +00:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import * as React from 'react'
|
2023-10-24 15:36:08 +00:00
|
|
|
import Link from 'next/link'
|
2023-12-08 04:40:45 +00:00
|
|
|
import { compare } from 'compare-versions'
|
|
|
|
|
import { has } from 'lodash-es'
|
|
|
|
|
|
|
|
|
|
import { WorkerKind } from '@/lib/gql/generates/graphql'
|
2023-10-26 00:48:18 +00:00
|
|
|
import { useHealth } from '@/lib/hooks/use-health'
|
2023-10-29 06:30:35 +00:00
|
|
|
import { ReleaseInfo, useLatestRelease } from '@/lib/hooks/use-latest-release'
|
2023-11-22 10:53:36 +00:00
|
|
|
import { useWorkers } from '@/lib/hooks/use-workers'
|
2023-12-08 17:49:10 +00:00
|
|
|
import { useAuthenticatedSession } from '@/lib/tabby/auth'
|
2023-12-08 04:40:45 +00:00
|
|
|
import { cn } from '@/lib/utils'
|
|
|
|
|
import { buttonVariants } from '@/components/ui/button'
|
|
|
|
|
import { IconGitHub, IconNotice } from '@/components/ui/icons'
|
|
|
|
|
|
2023-12-07 06:11:40 +00:00
|
|
|
import { ThemeToggle } from './theme-toggle'
|
2023-09-29 22:51:54 +00:00
|
|
|
|
|
|
|
|
export function Header() {
|
2023-12-08 17:49:10 +00:00
|
|
|
// Ensure login status.
|
|
|
|
|
useAuthenticatedSession()
|
|
|
|
|
|
2023-10-29 22:56:57 +00:00
|
|
|
const { data } = useHealth()
|
2023-11-22 10:53:36 +00:00
|
|
|
const workers = useWorkers(data)
|
|
|
|
|
const isChatEnabled = has(workers, WorkerKind.Chat)
|
2023-10-29 22:56:57 +00:00
|
|
|
const version = data?.version?.git_describe
|
|
|
|
|
const { data: latestRelease } = useLatestRelease()
|
|
|
|
|
const newVersionAvailable = isNewVersionAvailable(version, latestRelease)
|
2023-10-26 00:48:18 +00:00
|
|
|
|
2023-09-29 22:51:54 +00:00
|
|
|
return (
|
2023-12-08 17:52:09 +00:00
|
|
|
<header className="sticky top-0 z-50 flex h-16 w-full shrink-0 items-center justify-between border-b bg-gradient-to-b from-background/10 via-background/50 to-background/80 px-4 backdrop-blur-xl">
|
2023-09-30 01:20:38 +00:00
|
|
|
<div className="flex items-center">
|
|
|
|
|
<ThemeToggle />
|
2023-10-24 15:36:08 +00:00
|
|
|
<Link href="/" className={cn(buttonVariants({ variant: 'link' }))}>
|
2023-10-30 07:29:50 +00:00
|
|
|
Dashboard
|
2023-10-24 15:36:08 +00:00
|
|
|
</Link>
|
2023-10-29 22:56:57 +00:00
|
|
|
{isChatEnabled && (
|
|
|
|
|
<Link
|
|
|
|
|
href="/playground"
|
|
|
|
|
className={cn(buttonVariants({ variant: 'link' }))}
|
|
|
|
|
>
|
|
|
|
|
Playground
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
2023-09-30 01:20:38 +00:00
|
|
|
</div>
|
2023-09-29 22:51:54 +00:00
|
|
|
<div className="flex items-center justify-end space-x-2">
|
2023-10-29 22:56:57 +00:00
|
|
|
{newVersionAvailable && (
|
|
|
|
|
<a
|
|
|
|
|
target="_blank"
|
|
|
|
|
href="https://github.com/TabbyML/tabby/releases/latest"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className={buttonVariants({ variant: 'ghost' })}
|
|
|
|
|
>
|
|
|
|
|
<IconNotice className="text-yellow-600 dark:text-yellow-400" />
|
|
|
|
|
<span className="ml-2 hidden md:flex">
|
|
|
|
|
New version ({latestRelease?.name}) available
|
|
|
|
|
</span>
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
2023-09-29 22:51:54 +00:00
|
|
|
<a
|
|
|
|
|
target="_blank"
|
|
|
|
|
href="https://github.com/TabbyML/tabby"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className={cn(buttonVariants({ variant: 'outline' }))}
|
|
|
|
|
>
|
|
|
|
|
<IconGitHub />
|
2023-10-29 22:56:57 +00:00
|
|
|
<span className="ml-2 hidden md:flex">GitHub</span>
|
2023-09-29 22:51:54 +00:00
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
)
|
2023-10-29 06:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isNewVersionAvailable(version?: string, latestRelease?: ReleaseInfo) {
|
|
|
|
|
try {
|
2023-10-29 22:56:57 +00:00
|
|
|
return version && latestRelease && compare(latestRelease.name, version, '>')
|
2023-10-29 06:30:35 +00:00
|
|
|
} catch (err) {
|
|
|
|
|
// Handle invalid semver
|
2023-10-29 22:56:57 +00:00
|
|
|
console.warn(err)
|
|
|
|
|
return true
|
2023-10-29 06:30:35 +00:00
|
|
|
}
|
|
|
|
|
}
|