* feat: desktop revamp * feat: refactor system monitor * fix linter CI * remove unused import component * added responsive and resizeable component * responsive and resizeable local server page * finalize responsive and resizeable component * fix scroll custom ui * remove react scroll to bottom from modal troubleshoot * fix modal troubleshoot ui * fix setting gpu list * text area custom scroll bar * fix padding message input * cleanup classname * update inference engine model dropdown * update loader style * update quick ask ui * prepare theme provider * update dark theme * remove update hotkey list model and navigation * fix: cleanup hardcode classname * fix: update feedback * Set native theme electron * update destop ui revamp from feedback * update button icon component insider icon chat input message * update model dropdown ui * update tranaparent baclground * update logo model provider * fix: set background material acrylic support to blur background windows * fix: update tranparent left and right panel * fix: linter CI * update app using frameless window * styling custom style minimize, maximize and close app * temporary hidden maximize window * fix: responsive left and right panel * fix: enable click outside when leftpanel responsive * fix: remove unused import * update transparent variable css windows * fix: ui import model * feat: Support Theme system (#2946) * feat: update support theme system * update select component * feat: add theme folder in root project * fix: padding left and right center panel * fix: update padding left and right * chore: migrate themes * fix: rmdirsync error * chore: update gitignore * fix: cp recursive * fix: files electron package json * fix: migration * fix: update fgit ignore --------- Co-authored-by: Louis <louis@jan.ai> * fix: update feedback missing state when refrash app * fix: error test CI * chore: refactor useLoadThemes * chore: cleanup unused vars * fix: revert back menubar windows * fix minor ui * fix: minor ui --------- Co-authored-by: Louis <louis@jan.ai>
231 lines
7.3 KiB
TypeScript
231 lines
7.3 KiB
TypeScript
/* eslint-disable @typescript-eslint/naming-convention */
|
|
|
|
import { Fragment, useEffect, useState } from 'react'
|
|
|
|
import { Accept, useDropzone } from 'react-dropzone'
|
|
|
|
import { useAtomValue, useSetAtom } from 'jotai'
|
|
|
|
import { UploadCloudIcon } from 'lucide-react'
|
|
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
import CenterPanelContainer from '@/containers/CenterPanelContainer'
|
|
import GenerateResponse from '@/containers/Loader/GenerateResponse'
|
|
import ModelReload from '@/containers/Loader/ModelReload'
|
|
import ModelStart from '@/containers/Loader/ModelStart'
|
|
import { fileUploadAtom } from '@/containers/Providers/Jotai'
|
|
import { snackbar } from '@/containers/Toast'
|
|
|
|
import { activeModelAtom } from '@/hooks/useActiveModel'
|
|
import { queuedMessageAtom, reloadModelAtom } from '@/hooks/useSendChatMessage'
|
|
|
|
import ChatBody from '@/screens/Thread/ThreadCenterPanel/ChatBody'
|
|
|
|
import ChatInput from './ChatInput'
|
|
import RequestDownloadModel from './RequestDownloadModel'
|
|
|
|
import { experimentalFeatureEnabledAtom } from '@/helpers/atoms/AppConfig.atom'
|
|
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
|
|
|
|
import {
|
|
engineParamsUpdateAtom,
|
|
isGeneratingResponseAtom,
|
|
} from '@/helpers/atoms/Thread.atom'
|
|
|
|
const renderError = (code: string) => {
|
|
switch (code) {
|
|
case 'multiple-upload':
|
|
return 'Currently, we only support 1 attachment at the same time'
|
|
|
|
case 'retrieval-off':
|
|
return 'Turn on Retrieval in Assistant Settings to use this feature'
|
|
|
|
case 'file-invalid-type':
|
|
return 'We do not support this file type'
|
|
|
|
default:
|
|
return 'Oops, something error, please try again.'
|
|
}
|
|
}
|
|
|
|
const ThreadCenterPanel = () => {
|
|
const [dragRejected, setDragRejected] = useState({ code: '' })
|
|
const setFileUpload = useSetAtom(fileUploadAtom)
|
|
const experimentalFeature = useAtomValue(experimentalFeatureEnabledAtom)
|
|
const activeThread = useAtomValue(activeThreadAtom)
|
|
|
|
const acceptedFormat: Accept = activeThread?.assistants[0].model.settings
|
|
.vision_model
|
|
? {
|
|
'application/pdf': ['.pdf'],
|
|
'image/jpeg': ['.jpeg'],
|
|
'image/png': ['.png'],
|
|
'image/jpg': ['.jpg'],
|
|
}
|
|
: {
|
|
'application/pdf': ['.pdf'],
|
|
}
|
|
|
|
const { getRootProps, isDragReject } = useDropzone({
|
|
noClick: true,
|
|
multiple: false,
|
|
accept: acceptedFormat,
|
|
|
|
onDragOver: (e) => {
|
|
// Retrieval file drag and drop is experimental feature
|
|
if (!experimentalFeature) return
|
|
if (
|
|
e.dataTransfer.items.length === 1 &&
|
|
((activeThread?.assistants[0].tools &&
|
|
activeThread?.assistants[0].tools[0]?.enabled) ||
|
|
activeThread?.assistants[0].model.settings.vision_model)
|
|
) {
|
|
setDragOver(true)
|
|
} else if (
|
|
activeThread?.assistants[0].tools &&
|
|
!activeThread?.assistants[0].tools[0]?.enabled
|
|
) {
|
|
setDragRejected({ code: 'retrieval-off' })
|
|
} else {
|
|
setDragRejected({ code: 'multiple-upload' })
|
|
}
|
|
},
|
|
onDragLeave: () => setDragOver(false),
|
|
onDrop: (files, rejectFiles) => {
|
|
// Retrieval file drag and drop is experimental feature
|
|
if (!experimentalFeature) return
|
|
if (
|
|
!files ||
|
|
files.length !== 1 ||
|
|
rejectFiles.length !== 0 ||
|
|
(activeThread?.assistants[0].tools &&
|
|
!activeThread?.assistants[0].tools[0]?.enabled &&
|
|
!activeThread?.assistants[0].model.settings.vision_model)
|
|
)
|
|
return
|
|
const imageType = files[0]?.type.includes('image')
|
|
setFileUpload([{ file: files[0], type: imageType ? 'image' : 'pdf' }])
|
|
setDragOver(false)
|
|
},
|
|
onDropRejected: (e) => {
|
|
if (
|
|
activeThread?.assistants[0].tools &&
|
|
!activeThread?.assistants[0].tools[0]?.enabled
|
|
) {
|
|
setDragRejected({ code: 'retrieval-off' })
|
|
} else {
|
|
setDragRejected({ code: e[0].errors[0].code })
|
|
}
|
|
setDragOver(false)
|
|
},
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (dragRejected.code) {
|
|
snackbar({
|
|
description: renderError(dragRejected.code),
|
|
type: 'error',
|
|
})
|
|
}
|
|
setTimeout(() => {
|
|
if (dragRejected.code) {
|
|
setDragRejected({ code: '' })
|
|
}
|
|
}, 2000)
|
|
}, [dragRejected.code])
|
|
|
|
const engineParamsUpdate = useAtomValue(engineParamsUpdateAtom)
|
|
const [dragOver, setDragOver] = useState(false)
|
|
|
|
const queuedMessage = useAtomValue(queuedMessageAtom)
|
|
const reloadModel = useAtomValue(reloadModelAtom)
|
|
|
|
const activeModel = useAtomValue(activeModelAtom)
|
|
|
|
const isGeneratingResponse = useAtomValue(isGeneratingResponseAtom)
|
|
|
|
return (
|
|
<CenterPanelContainer>
|
|
<div
|
|
className="relative flex h-full w-full flex-col outline-none"
|
|
{...getRootProps()}
|
|
>
|
|
{dragOver && (
|
|
<div className="absolute z-50 mx-auto h-full w-full p-8 backdrop-blur-lg">
|
|
<div
|
|
className={twMerge(
|
|
'flex h-full w-full items-center justify-center rounded-lg border border-dashed border-[hsla(var(--primary-bg))]',
|
|
isDragReject && 'border-[hsla(var(--destructive-bg))]'
|
|
)}
|
|
>
|
|
<div className="mx-auto w-1/2 text-center">
|
|
<div className="mx-auto inline-flex h-12 w-12 items-center justify-center rounded-full">
|
|
<UploadCloudIcon
|
|
size={24}
|
|
className="text-[hsla(var(--primary-bg))]"
|
|
/>
|
|
</div>
|
|
<div className="mt-4 text-[hsla(var(--primary-bg))]">
|
|
<h6 className="font-bold">
|
|
{isDragReject
|
|
? `Currently, we only support 1 attachment at the same time with ${
|
|
activeThread?.assistants[0].model.settings
|
|
.vision_model
|
|
? 'PDF, JPEG, JPG, PNG'
|
|
: 'PDF'
|
|
} format`
|
|
: 'Drop file here'}
|
|
</h6>
|
|
{!isDragReject && (
|
|
<p className="mt-2">
|
|
{activeThread?.assistants[0].model.settings.vision_model
|
|
? 'PDF, JPEG, JPG, PNG'
|
|
: 'PDF'}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className="flex h-full w-full flex-col justify-between">
|
|
{activeThread ? (
|
|
<div className="flex h-full w-full overflow-x-hidden">
|
|
<ChatBody />
|
|
</div>
|
|
) : (
|
|
<RequestDownloadModel />
|
|
)}
|
|
|
|
{!engineParamsUpdate && <ModelStart />}
|
|
|
|
{reloadModel && (
|
|
<Fragment>
|
|
<ModelReload />
|
|
<div className="mb-2 text-center">
|
|
<span className="text-[hsla(var(--text-secondary)]">
|
|
Model is reloading to apply new changes.
|
|
</span>
|
|
</div>
|
|
</Fragment>
|
|
)}
|
|
|
|
{queuedMessage && !reloadModel && (
|
|
<div className="mb-2 text-center">
|
|
<span className="text-[hsla(var(--text-secondary)]">
|
|
Message will be sent once the model has started
|
|
</span>
|
|
</div>
|
|
)}
|
|
|
|
{activeModel && isGeneratingResponse && <GenerateResponse />}
|
|
<ChatInput />
|
|
</div>
|
|
</div>
|
|
</CenterPanelContainer>
|
|
)
|
|
}
|
|
|
|
export default ThreadCenterPanel
|