* chore: initial new FE setup * chore: update namespace text-left-panel foreground variable * chore: enable dynamic mainview color * chore: remove greetings new chat * chore: fix chat input style * chore: simplify hook useAppearance * chore: enable internationalization * chore: prepare vn locale * chore: keyboardshortcut layout * chore: update keyboard shortcut exclude pathname * chore: update state active setting route * chore: fix update theme by system * chore: handle dynamic primary color * chore: fix left panel navigation active state and styled item privacy analytic * chore: reorder general setting being a first * chore: add function reset appearance * chore: update scrollbar * chore: update delete thread with dialog confirmation * chore: update state dialog inside dropdown menu * chore: wip thread detail or chat page * chore: wip model dropdown * chore: prepare model dropdown select * chore: update model providers setting * chore: show provider on model dropdown based isActive toogle * chore: update layout model provider * chore: update state active on storage * chore: update gap of item dropdown model * chore: update select model base on id * chore: update edit model capabilities * chore: add dialog to add model * chore: update sheet for model setting * chore: add sheet setting each model * chore: make dynamic syntax highlight * chore: fix menu setting appearance theme * chore: markdown render support emoji * chore: markdown support latex * chore: change codeblock default theme * chore: update ui codeblock * chore: custom render link taget new window * chore: fix copy button codeblock * chore: update accent and desctructive color * chore: setup user chat message * chore: prepare some page settings * chore: simple list extension and prepare mcp, local api, and hardware * chore: mcp-serve * chore: MCP server UI * chore: update local api server config * chore: adjust chat input * chore: update local api server log * chore: prepare hub page * chore: remove help page * chore: update mock * chore: prepare http proxy setting UI * chore: adjust local api server and title every action * fix: chore FE package (#4962) * fix: update command which referred to non-existent web app * fix: added commented out macos platform for now * fix: remove the platform name as macos * fix: remove unnecessary line for platform name in HeaderPage component * fix: update dev script to specify port 3000 for Vite * feat: model providers and chat completion * enhancement: threads performance * fix: thread content update * chore: clean up threads * fix: performance issue with streaming and state loop * fix: streaming * fix: react markdow * feat: extension manager * chore: add nodePolyfills include path * chore: improve performance avoid unhandle rejection * chore: update pre margin bottom * chore: swith thread should be deafult scroll to bottom * chore: wip scroll to bottom * chore: add model loader * chore: add platform utils * feat: threads functionality * chore: setup toaster * chore: persist threads deletion * fix: create thread with new message * chore: create new thread should change route path * chore: navigate after delet dialog thread * chore: thread favorites and orders * chore: dismiss deleting modal on delete * chore: remove undefined properties * chore: remove deprecated run step * chore: fix delete thread * chore: create empty thread content on started streaming * chore: correct messages store key * chore: stuck at generating state * chore: preapre chat toolbar * chore: introduce in-memory app state * chore: update extensions migration logic * chore: remove redundant extensions migration gate * chore: message toolbar user and assistant * chore: add logo gemini * feat: remote providers with model capabilities * chore: maintain provider settings * chore: move speed token into chat input * chore: temp harcoded model loader * chore: make chat text selectable and truncate model list * chore: update shortcut UI * Feat/implement threads (#4977) * chore: add fuse.js library for enhanced search functionality * feat: implement thread filtering with Fuse.js for improved search capabilities * fix: update the fuseOptions * feat: add search functionality to LeftPanel and refactor thread retrieval logic * refactor: optimize thread filtering and improve search functionality in LeftPanel * fix: more edits * refactor: remove duplicate import of useAppState in StreamingContent component * chore: update navigate after delete all thread * chore: pass prop speedToken from new chat input * chore: persist provider general settings * chore: styling search left panel * chore: cleanup margin * chore: update size icon * chore: improve chat input * chore: imprve list markdown * chore: animate border * feat: local model provider work * chore: persist manually added model * chore: prepare download management ui and show version on general setting * chore: improve pre tag * chore: remove buton install extension and improve light theme download * chore: add missing hardware information handler * chore: cleanup small ui * chore: update default provider settings * fix: missing fs commands * chore: correct provider models * chore: prepare delete model * chore: handle thinking block * chore: fix conditional message toolbar * chore: pophover download select none * enhancement: add prune mode * chore: model settings * chore: bump engine version tauri * chore: update style thinking * chore: add indicator and toogle mcp server * chore: wip hub * chore: update model settings * chore: mvp hub * chore: add function rename title * chore: update function delete message * chore: update rename title * chore: update model settings * chore: persist MCP configs * refactor: clean up utils * chore: add tools to completion request * chore: clean up * chore: ignore assets --------- Co-authored-by: Ivan Leo <ivanleomk@gmail.com> Co-authored-by: Louis <louis@jan.ai>
256 lines
8.1 KiB
TypeScript
256 lines
8.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/naming-convention */
|
|
|
|
import { createContext, memo, 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 { useTollCallPromiseModal } from '@/containers/ToolCallApprovalModal'
|
|
|
|
import { useTollCallPromiseModal } from '@/containers/ToolCallApprovalModal'
|
|
|
|
import { activeModelAtom } from '@/hooks/useActiveModel'
|
|
import { reloadModelAtom } from '@/hooks/useSendChatMessage'
|
|
|
|
import ChatBody from '@/screens/Thread/ThreadCenterPanel/ChatBody'
|
|
|
|
import { uploader } from '@/utils/file'
|
|
|
|
import ChatInput from './ChatInput'
|
|
import RequestDownloadModel from './RequestDownloadModel'
|
|
|
|
import { experimentalFeatureEnabledAtom } from '@/helpers/atoms/AppConfig.atom'
|
|
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
|
|
import { chatWidthAtom } from '@/helpers/atoms/Setting.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.'
|
|
}
|
|
}
|
|
|
|
interface ChatContextType {
|
|
showApprovalModal:
|
|
| ((toolName: string, threadId: string) => Promise<unknown>)
|
|
| undefined
|
|
}
|
|
|
|
export const ChatContext = createContext<ChatContextType>({
|
|
showApprovalModal: undefined,
|
|
})
|
|
|
|
const ThreadCenterPanel = () => {
|
|
const [dragRejected, setDragRejected] = useState({ code: '' })
|
|
const setFileUpload = useSetAtom(fileUploadAtom)
|
|
const experimentalFeature = useAtomValue(experimentalFeatureEnabledAtom)
|
|
const activeThread = useAtomValue(activeThreadAtom)
|
|
const activeAssistant = useAtomValue(activeAssistantAtom)
|
|
const chatWidth = useAtomValue(chatWidthAtom)
|
|
const upload = uploader()
|
|
const acceptedFormat: Accept = activeAssistant?.model.settings?.mmproj
|
|
? {
|
|
'application/pdf': ['.pdf'],
|
|
'image/jpeg': ['.jpeg'],
|
|
'image/png': ['.png'],
|
|
'image/jpg': ['.jpg'],
|
|
}
|
|
: {
|
|
'application/pdf': ['.pdf'],
|
|
}
|
|
const { showModal, PromiseModal } = useTollCallPromiseModal()
|
|
|
|
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 &&
|
|
((activeAssistant?.tools && activeAssistant?.tools[0]?.enabled) ||
|
|
activeAssistant?.model.settings?.mmproj)
|
|
) {
|
|
setDragOver(true)
|
|
} else if (
|
|
activeAssistant?.tools &&
|
|
!activeAssistant?.tools[0]?.enabled
|
|
) {
|
|
setDragRejected({ code: 'retrieval-off' })
|
|
} else {
|
|
setDragRejected({ code: 'multiple-upload' })
|
|
}
|
|
},
|
|
onDragLeave: () => setDragOver(false),
|
|
onDrop: async (files, rejectFiles) => {
|
|
// Retrieval file drag and drop is experimental feature
|
|
if (!experimentalFeature) return
|
|
if (
|
|
!files ||
|
|
files.length !== 1 ||
|
|
rejectFiles.length !== 0 ||
|
|
(activeAssistant?.tools &&
|
|
!activeAssistant?.tools[0]?.enabled &&
|
|
!activeAssistant?.model.settings?.mmproj)
|
|
)
|
|
return
|
|
const imageType = files[0]?.type.includes('image')
|
|
if (imageType) {
|
|
setFileUpload({ file: files[0], type: 'image' })
|
|
} else {
|
|
upload.addFile(files[0])
|
|
upload.upload().then((data) => {
|
|
setFileUpload({
|
|
file: files[0],
|
|
type: imageType ? 'image' : 'pdf',
|
|
id: data?.successful?.[0]?.response?.body?.id,
|
|
name: data?.successful?.[0]?.response?.body?.filename,
|
|
})
|
|
})
|
|
}
|
|
setDragOver(false)
|
|
},
|
|
onDropRejected: (e) => {
|
|
if (activeAssistant?.tools && !activeAssistant?.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 reloadModel = useAtomValue(reloadModelAtom)
|
|
|
|
const activeModel = useAtomValue(activeModelAtom)
|
|
|
|
const isGeneratingResponse = useAtomValue(isGeneratingResponseAtom)
|
|
|
|
return (
|
|
<ChatContext.Provider
|
|
value={{
|
|
showApprovalModal: showModal,
|
|
}}
|
|
>
|
|
<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 ${
|
|
activeAssistant?.model.settings?.mmproj
|
|
? 'PDF, JPEG, JPG, PNG'
|
|
: 'PDF'
|
|
} format`
|
|
: 'Drop file here'}
|
|
</h6>
|
|
{!isDragReject && (
|
|
<p className="mt-2">
|
|
{activeAssistant?.model.settings?.mmproj
|
|
? 'PDF, JPEG, JPG, PNG'
|
|
: 'PDF'}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div
|
|
className={twMerge('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 && <ModelReload />}
|
|
|
|
{activeModel && isGeneratingResponse && <GenerateResponse />}
|
|
<div
|
|
className={twMerge(
|
|
'mx-auto w-full',
|
|
chatWidth === 'compact' && 'max-w-[700px]'
|
|
)}
|
|
>
|
|
<ChatInput />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</CenterPanelContainer>
|
|
<PromiseModal />
|
|
</ChatContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default memo(ThreadCenterPanel)
|